Skip to content

Commit

Permalink
add orbital_rotation argument to slater determinant one rdm
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Oct 30, 2023
1 parent c15f3c5 commit c59fbd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions python/ffsim/states/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def hartree_fock_state(norb: int, nelec: tuple[int, int]) -> np.ndarray:
def slater_determinant_one_rdm(
norb: int,
occupied_orbitals: tuple[Sequence[int], Sequence[int]],
orbital_rotation: np.ndarray | None = None,
spin_summed: bool = True,
) -> np.ndarray:
"""Return the one-particle reduced density matrix of a Slater determinant.
Expand All @@ -155,6 +156,9 @@ def slater_determinant_one_rdm(
rdm_a[(alpha_orbitals, alpha_orbitals)] = 1
if len(beta_orbitals):
rdm_b[(beta_orbitals, beta_orbitals)] = 1
if orbital_rotation is not None:
rdm_a = orbital_rotation.conj() @ rdm_a @ orbital_rotation.T
rdm_b = orbital_rotation.conj() @ rdm_b @ orbital_rotation.T
if spin_summed:
return rdm_a + rdm_b
return scipy.linalg.block_diag(rdm_a, rdm_b)
Expand Down
14 changes: 11 additions & 3 deletions tests/states/states_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,21 @@ def test_slater_determinant_one_rdm(
occ_a, occ_b = occupied_orbitals
nelec = len(occ_a), len(occ_b)

vec = ffsim.slater_determinant(norb, occupied_orbitals)
rng = np.random.default_rng()
orbital_rotation = ffsim.random.random_unitary(norb, seed=rng)

vec = ffsim.slater_determinant(
norb, occupied_orbitals, orbital_rotation=orbital_rotation
)
rdm = ffsim.slater_determinant_one_rdm(
norb, occupied_orbitals, spin_summed=spin_summed
norb,
occupied_orbitals,
orbital_rotation=orbital_rotation,
spin_summed=spin_summed,
)
expected = ffsim.rdm(vec, norb, nelec, spin_summed=spin_summed)

np.testing.assert_allclose(rdm, expected)
np.testing.assert_allclose(rdm, expected, atol=1e-12)


def test_indices_to_strings():
Expand Down

0 comments on commit c59fbd1

Please sign in to comment.