Skip to content

Commit

Permalink
pyscf systems: add explicit test for unit management
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-o-marsh committed Dec 12, 2023
1 parent 24363ad commit f597fbb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/rascaline/rascaline/systems/pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def cell(self):
return cell
else:
# assume bohrs, correct this
return pyscf.data.nist.BOHS * np.asarray(cell)
return pyscf.data.nist.BOHR * np.asarray(cell)
else:
return np.zeros((3, 3), float)

Expand Down
24 changes: 24 additions & 0 deletions python/rascaline/tests/systems/pyscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,27 @@ def test_pbc_data():
np.array([[0, 0, 0], [1, 1, 1]], dtype=float),
rtol=1e-14,
)


def test_explicit_units():
import pyscf.pbc

cell = np.array([[2, 0, 0], [0, 2, 1], [0, 0, 2]], dtype=float)

at1 = pyscf.pbc.gto.Cell(
atom="H 0 0 0; H 1 1 1",
a=cell,
unit="Angstrom",
).build()
at2 = pyscf.pbc.gto.Cell(
atom=[("H", at1.atom_coord(0)), ("H", at1.atom_coord(1))],
a=cell / pyscf.data.nist.BOHR,
unit="Bohr",
).build()
at1 = PyscfSystem(at1)
at2 = PyscfSystem(at2)

assert np.allclose(at1.positions(), at2.positions())
assert np.allclose(at1.positions(), np.array([[0, 0, 0], [1, 1, 1]], dtype=float))
assert np.allclose(at1.cell(), at2.cell())
assert np.allclose(at1.cell(), cell)

0 comments on commit f597fbb

Please sign in to comment.