Skip to content

Commit

Permalink
add test_occupants.py
Browse files Browse the repository at this point in the history
  • Loading branch information
seshasaibehara committed Jul 30, 2024
1 parent beb125b commit 0fd56db
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions python/tests/test_occupants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import os
import numpy as np
from libcasm.xtal import Occupant


def test_occupant_from_xyz(session_shared_datadir):
"""Test making xtal.Occupant.from_xyz_string()
method
Parameters
----------
shared_datadir : str
Returns
-------
None
"""

with open(
os.path.join(session_shared_datadir, "input_molecules", "water.xyz"), "r"
) as f:
water_xyz_string = f.read()

water = Occupant.from_xyz_string(water_xyz_string)

assert water.name() == "Water"

expected_atom_names = ["O", "H", "H"]
expected_atom_coords = [
np.array([0.0, 0.0, 0.11779]),
np.array([0.0, 0.75545, -0.47116]),
np.array([0.0, -0.75545, -0.47116]),
]

for atom, expected_atom_name, expected_atom_coord in zip(
water.atoms(), expected_atom_names, expected_atom_coords
):

assert atom.name() == expected_atom_name
assert np.allclose(atom.coordinate(), expected_atom_coord)

0 comments on commit 0fd56db

Please sign in to comment.