From 653714e4fe6914a5b9bea6eef0f44da507db1a2f Mon Sep 17 00:00:00 2001 From: Thomas Purcell Date: Wed, 11 Dec 2024 07:46:30 -0700 Subject: [PATCH 1/2] Modify FHI-aims inputs to not use species string (#4177) * Modify FHI-aims inputs to not use species string FHI-aims does not read spin from the species and that causes issues with magnetic calculations * Add the option for oxidation state to still be in species Issue is only with spin * Fix lint errors --------- Signed-off-by: Shyue Ping Ong Co-authored-by: Shyue Ping Ong --- src/pymatgen/io/aims/inputs.py | 8 +++++++- src/pymatgen/symmetry/groups.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pymatgen/io/aims/inputs.py b/src/pymatgen/io/aims/inputs.py index 8304a6eb0d5..6f370aeae21 100644 --- a/src/pymatgen/io/aims/inputs.py +++ b/src/pymatgen/io/aims/inputs.py @@ -154,16 +154,22 @@ def from_structure(cls, structure: Structure | Molecule) -> Self: content_lines.append(f"lattice_vector {lv[0]: .12e} {lv[1]: .12e} {lv[2]: .12e}") for site in structure: - element = site.species_string + element = site.species_string.split(",spin=")[0] charge = site.properties.get("charge", 0) spin = site.properties.get("magmom", None) coord = site.coords v = site.properties.get("velocity", [0.0, 0.0, 0.0]) + if isinstance(site.specie, Species) and site.specie.spin is not None: if spin is not None and spin != site.specie.spin: raise ValueError("species.spin and magnetic moments don't agree. Please only define one") spin = site.specie.spin + if isinstance(site.specie, Species) and site.specie.oxi_state is not None: + if charge is not None and charge != site.specie.oxi_state: + raise ValueError("species.oxi_state and charge don't agree. Please only define one") + charge = site.specie.oxi_state + content_lines.append(f"atom {coord[0]: .12e} {coord[1]: .12e} {coord[2]: .12e} {element}") if charge != 0: content_lines.append(f" initial_charge {charge:.12e}") diff --git a/src/pymatgen/symmetry/groups.py b/src/pymatgen/symmetry/groups.py index e6a4c762bd8..9c0f39b111e 100644 --- a/src/pymatgen/symmetry/groups.py +++ b/src/pymatgen/symmetry/groups.py @@ -18,6 +18,7 @@ from monty.design_patterns import cached_class from monty.serialization import loadfn +from pymatgen.core.operations import SymmOp from pymatgen.util.string import Stringify if TYPE_CHECKING: From da607e86f9ce8aec942067c6c1a4fda6e04915dd Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel) YANG" Date: Fri, 13 Dec 2024 06:33:14 +0800 Subject: [PATCH 2/2] Skip another failing `Phonopy` test in Windows after NumPy bumped to 2 in CI (#4224) * skip another test * fix import * update reason * what? looks like the latest monty doesn't pack reverse readline fix? * Revert "what? looks like the latest monty doesn't pack reverse readline fix?" This reverts commit b8912442b458ac6b409eaf0ae2ce423505a87218. --- tests/io/test_phonopy.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/io/test_phonopy.py b/tests/io/test_phonopy.py index 802e43049e2..0f20d54e474 100644 --- a/tests/io/test_phonopy.py +++ b/tests/io/test_phonopy.py @@ -10,12 +10,11 @@ from numpy.testing import assert_allclose, assert_array_equal from pytest import approx -from pymatgen.core import Element +from pymatgen.core import Element, Structure from pymatgen.io.phonopy import ( CompletePhononDos, PhononBandStructure, PhononBandStructureSymmLine, - Structure, get_complete_ph_dos, get_displaced_structures, get_gruneisen_ph_bs_symm_line, @@ -125,6 +124,10 @@ def test_structure_conversion(self): assert struct_pmg_round_trip.site_properties["magmom"] == struct_pmg.site_properties["magmom"] +@pytest.mark.skipif( + platform.system() == "Windows" and int(np.__version__[0]) >= 2, + reason="cannot run NP2 on windows, see PR 4224", +) @pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") class TestGetDisplacedStructures(PymatgenTest): def test_get_displaced_structures(self): @@ -157,11 +160,11 @@ def test_get_displaced_structures(self): assert os.path.isfile("test.yaml") -@pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") @pytest.mark.skipif( platform.system() == "Windows" and int(np.__version__[0]) >= 2, - reason="See https://github.com/conda-forge/phonopy-feedstock/pull/158#issuecomment-2227506701", + reason="cannot run NP2 on windows, see PR 4224", ) +@pytest.mark.skipif(Phonopy is None, reason="Phonopy not present") class TestPhonopyFromForceConstants(TestCase): def setUp(self) -> None: test_path = Path(TEST_DIR)