|
7 | 7 | import pytest
|
8 | 8 | from pytest import approx
|
9 | 9 |
|
| 10 | +from pymatgen.core.periodic_table import Species |
10 | 11 | from pymatgen.core.sites import PeriodicSite
|
11 | 12 | from pymatgen.core.structure import Molecule, Structure
|
12 | 13 | from pymatgen.io.cif import CifParser
|
@@ -122,6 +123,40 @@ def test_get_symmetry_dataset(self):
|
122 | 123 | ds = self.sg.get_symmetry_dataset()
|
123 | 124 | assert ds["international"] == "Pnma"
|
124 | 125 |
|
| 126 | + def test_init_cell(self): |
| 127 | + # see https://github.com/materialsproject/pymatgen/pull/3179 |
| 128 | + li2o = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Li2O.cif")) |
| 129 | + |
| 130 | + # test that magmoms are not included in spacegroup analyzer when species have no spin |
| 131 | + # or no magmom site properties are set |
| 132 | + assert all(species.spin is None for species in li2o.types_of_species) |
| 133 | + assert "magmom" not in li2o.site_properties |
| 134 | + sga = SpacegroupAnalyzer(li2o) |
| 135 | + assert len(sga._cell) == 3 # no magmoms should be added! |
| 136 | + |
| 137 | + # give a magmom to random Li site |
| 138 | + li2o[0].properties["magmom"] = 0 |
| 139 | + sga = SpacegroupAnalyzer(li2o) |
| 140 | + assert len(sga._cell) == 4 # magmoms should be added! |
| 141 | + assert sga._cell[3] == 12 * (0,) |
| 142 | + |
| 143 | + # now set spin for O only |
| 144 | + li2o = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Li2O.cif")) |
| 145 | + li2o.replace_species({"O2-": Species("O", oxidation_state=-2, spin=1)}) |
| 146 | + assert not all(species.spin is None for species in li2o.types_of_species) |
| 147 | + sga = SpacegroupAnalyzer(li2o) |
| 148 | + assert len(sga._cell) == 4 # magmoms should be added! |
| 149 | + assert sga._cell[3] == tuple( |
| 150 | + 8 |
| 151 | + * [ |
| 152 | + 0, |
| 153 | + ] |
| 154 | + + 4 |
| 155 | + * [ |
| 156 | + 1, |
| 157 | + ] |
| 158 | + ) |
| 159 | + |
125 | 160 | def test_get_symmetry(self):
|
126 | 161 | # see discussion in https://github.com/materialsproject/pymatgen/pull/2724
|
127 | 162 | Co8 = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "Co8.cif"))
|
|
0 commit comments