Skip to content

Commit 1730f29

Browse files
committed
added tests to check spacegroup conversions
1 parent 3d47747 commit 1730f29

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/io/test_ase.py

+33
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,21 @@ def test_get_atoms_from_structure_dyn():
104104
ase_mask = c.mask if isinstance(c, ase.constraints.FixCartesian) else [True, True, True]
105105
assert len(c.index) == len([mask for mask in sel_dyn if np.array_equal(mask, ~np.array(ase_mask))])
106106

107+
def test_get_atoms_from_structure_spacegroup():
108+
# Get structure with space group dictionary in properties
109+
space_group_info = STRUCTURE.get_space_group_info()
110+
STRUCTURE.properties["spacegroup"] = {"number": space_group_info[1], "setting": 1}
111+
112+
# Convert to atoms and check that structure was not modified
113+
atoms = AseAtomsAdaptor.get_atoms(STRUCTURE)
114+
assert isinstance(STRUCTURE.properties["spacegroup"], dict)
115+
assert isinstance(atoms.info["spacegroup"], ase.spacegroup.Spacegroup)
116+
117+
# Check that space group matches
118+
assert atoms.info["spacegroup"].no == STRUCTURE.properties["spacegroup"]["number"]
119+
assert atoms.info["spacegroup"].setting == STRUCTURE.properties["spacegroup"]["setting"]
120+
121+
107122

108123
def test_get_atoms_from_molecule():
109124
mol = Molecule.from_file(XYZ_STRUCTURE)
@@ -216,6 +231,24 @@ def test_get_structure_dyn(select_dyn):
216231

217232
assert len(ase_atoms) == len(structure)
218233

234+
def test_get_structure_spacegroup():
235+
# set up Atoms object with spacegroup information
236+
a = 4.05
237+
atoms = ase.spacegroup.crystal(
238+
"Al", [(0, 0, 0)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]
239+
)
240+
assert "spacegroup" in atoms.info
241+
assert isinstance(atoms.info["spacegroup"], ase.spacegroup.Spacegroup)
242+
243+
# Test that get_structure does not mutate atoms
244+
structure = AseAtomsAdaptor.get_structure(atoms)
245+
assert isinstance(atoms.info["spacegroup"], ase.spacegroup.Spacegroup)
246+
assert isinstance(structure.properties["spacegroup"], dict)
247+
248+
# Test that spacegroup info matches
249+
assert atoms.info["spacegroup"].no == structure.properties["spacegroup"]["number"]
250+
assert atoms.info["spacegroup"].setting == structure.properties["spacegroup"]["setting"]
251+
219252

220253
def test_get_molecule():
221254
atoms = ase.io.read(XYZ_STRUCTURE)

0 commit comments

Comments
 (0)