Skip to content

Commit

Permalink
test_analyzer.py use Structure.from_file() over more verbose CifParse…
Browse files Browse the repository at this point in the history
…r.from_file()
  • Loading branch information
janosh committed Oct 6, 2023
1 parent 2506320 commit 476617e
Showing 1 changed file with 23 additions and 43 deletions.
66 changes: 23 additions & 43 deletions tests/symmetry/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from pymatgen.core.periodic_table import Species
from pymatgen.core.sites import PeriodicSite
from pymatgen.core.structure import Molecule, Structure
from pymatgen.io.cif import CifParser
from pymatgen.io.vasp.inputs import Poscar
from pymatgen.io.vasp.outputs import Vasprun
from pymatgen.symmetry.analyzer import PointGroupAnalyzer, SpacegroupAnalyzer, cluster_sites, iterative_symmetrize
Expand Down Expand Up @@ -230,8 +229,7 @@ def test_symmetrized_structure(self):

def test_find_primitive(self):
"""F m -3 m Li2O testing of converting to primitive cell."""
parser = CifParser(f"{TEST_FILES_DIR}/Li2O.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/Li2O.cif")
spga = SpacegroupAnalyzer(structure)
primitive_structure = spga.find_primitive()
assert primitive_structure.formula == "Li2 O1"
Expand All @@ -242,13 +240,11 @@ def test_find_primitive(self):
assert primitive_structure.lattice.gamma == approx(60)
assert primitive_structure.volume == approx(structure.volume / 4.0)

structure = parser.get_structures(primitive=False)[0]
structure.add_site_property("magmom", [1.0] * len(structure))
spga = SpacegroupAnalyzer(structure)
primitive_structure = spga.find_primitive(keep_site_properties=True)
assert primitive_structure.site_properties["magmom"] == [1.0] * len(primitive_structure)

structure = parser.get_structures(primitive=False)[0]
structure.add_site_property("magmom", [1.0] * len(structure))
spga = SpacegroupAnalyzer(structure)
primitive_structure = spga.find_primitive(keep_site_properties=False)
Expand All @@ -267,61 +263,55 @@ def test_get_ir_reciprocal_mesh_map(self):
grid = self.sg.get_ir_reciprocal_mesh(mesh=mesh)
full_grid, mapping = self.sg.get_ir_reciprocal_mesh_map(mesh=mesh)
assert len(np.unique(mapping)) == len(grid)
for _, i in enumerate(np.unique(mapping)):
assert full_grid[i][0] == approx(grid[_][0][0])
assert full_grid[i][1] == approx(grid[_][0][1])
assert full_grid[i][2] == approx(grid[_][0][2])
for _, idx in enumerate(np.unique(mapping)):
assert full_grid[idx][0] == approx(grid[_][0][0])
assert full_grid[idx][1] == approx(grid[_][0][1])
assert full_grid[idx][2] == approx(grid[_][0][2])

def test_get_conventional_standard_structure(self):
parser = CifParser(f"{TEST_FILES_DIR}/bcc_1927.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/bcc_1927.cif")
assert structure == structure
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == (90, 90, 90)
assert conv.lattice.lengths == approx([9.1980270633769461] * 3)

parser = CifParser(f"{TEST_FILES_DIR}/btet_1915.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/btet_1915.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == (90, 90, 90)
assert conv.lattice.a == approx(5.0615106678044235)
assert conv.lattice.b == approx(5.0615106678044235)
assert conv.lattice.c == approx(4.2327080177761687)

parser = CifParser(f"{TEST_FILES_DIR}/orci_1010.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orci_1010.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == (90, 90, 90)
assert conv.lattice.a == approx(2.9542233922299999)
assert conv.lattice.b == approx(4.6330325651443296)
assert conv.lattice.c == approx(5.373703587040775)

parser = CifParser(f"{TEST_FILES_DIR}/orcc_1003.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orcc_1003.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == (90, 90, 90)
assert conv.lattice.a == approx(4.1430033493799998)
assert conv.lattice.b == approx(31.437979757624728)
assert conv.lattice.c == approx(3.99648651)

parser = CifParser(f"{TEST_FILES_DIR}/orac_632475.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orac_632475.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == (90, 90, 90)
assert conv.lattice.lengths == approx([3.1790663399999999, 9.9032878699999998, 3.5372412099999999])

parser = CifParser(f"{TEST_FILES_DIR}/monoc_1028.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/monoc_1028.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == approx([90, 117.53832420192903, 90])
assert conv.lattice.lengths == approx([14.033435583000625, 3.96052850731, 6.8743926325200002])
parser = CifParser(f"{TEST_FILES_DIR}/hex_1170.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/hex_1170.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
conv = spga.get_conventional_standard_structure()
assert conv.lattice.angles == approx([90, 90, 120])
Expand Down Expand Up @@ -350,8 +340,7 @@ def test_get_conventional_standard_structure(self):
assert conv.site_properties.get("magmom") is None

def test_get_primitive_standard_structure(self):
parser = CifParser(f"{TEST_FILES_DIR}/bcc_1927.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/bcc_1927.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(109.47122063400001)
Expand All @@ -361,8 +350,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(7.9657251015812145)
assert prim.lattice.c == approx(7.9657251015812145)

parser = CifParser(f"{TEST_FILES_DIR}/btet_1915.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/btet_1915.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(105.015053349)
Expand All @@ -372,8 +360,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(4.1579321075608791)
assert prim.lattice.c == approx(4.1579321075608791)

parser = CifParser(f"{TEST_FILES_DIR}/orci_1010.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orci_1010.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(134.78923546600001)
Expand All @@ -383,8 +370,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(3.8428217771014852)
assert prim.lattice.c == approx(3.8428217771014852)

parser = CifParser(f"{TEST_FILES_DIR}/orcc_1003.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orcc_1003.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(90)
Expand All @@ -394,8 +380,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(15.854897098324196)
assert prim.lattice.c == approx(3.99648651)

parser = CifParser(f"{TEST_FILES_DIR}/orac_632475.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/orac_632475.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(90)
Expand All @@ -405,8 +390,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(5.2005185662155391)
assert prim.lattice.c == approx(3.5372412099999999)

parser = CifParser(f"{TEST_FILES_DIR}/monoc_1028.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/monoc_1028.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(63.579155761999999)
Expand All @@ -416,8 +400,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(7.2908007159612325)
assert prim.lattice.c == approx(6.8743926325200002)

parser = CifParser(f"{TEST_FILES_DIR}/hex_1170.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/hex_1170.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(90)
Expand All @@ -427,8 +410,7 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(3.699919902005897)
assert prim.lattice.c == approx(6.9779585500000003)

parser = CifParser(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure()
assert prim.lattice.alpha == approx(28.049186140546812)
Expand All @@ -438,15 +420,13 @@ def test_get_primitive_standard_structure(self):
assert prim.lattice.b == approx(5.9352627428399982)
assert prim.lattice.c == approx(5.9352627428399982)

parser = CifParser(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
structure.add_site_property("magmom", [1.0] * len(structure))
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure(keep_site_properties=True)
assert prim.site_properties["magmom"] == [1.0] * len(prim)

parser = CifParser(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
structure = parser.get_structures(primitive=False)[0]
structure = Structure.from_file(f"{TEST_FILES_DIR}/rhomb_3478_conv.cif")
structure.add_site_property("magmom", [1.0] * len(structure))
spga = SpacegroupAnalyzer(structure, symprec=1e-2)
prim = spga.get_primitive_standard_structure(keep_site_properties=False)
Expand Down

0 comments on commit 476617e

Please sign in to comment.