diff --git a/.gitignore b/.gitignore index b6e4761..371a3cc 100644 --- a/.gitignore +++ b/.gitignore @@ -114,6 +114,9 @@ venv.bak/ .spyderproject .spyproject +# VSCode +.vscode/ + # Rope project settings .ropeproject diff --git a/README.rst b/README.rst index a799828..c729666 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ Writing inpgen input back out #Adding some additional LAPW parameters fleur_inp.write_file('inp_new', parameters={'comp': {'kmax': 4.5}}) -Using from pymatgen ``Structure`` object (Not yet integrated) +Usage from pymatgen ``Structure`` object .. code-block:: python diff --git a/pymatgen/io/fleur/__init__.py b/pymatgen/io/fleur/__init__.py index a61fb88..b0872c6 100644 --- a/pymatgen/io/fleur/__init__.py +++ b/pymatgen/io/fleur/__init__.py @@ -6,4 +6,4 @@ from .fleurinput import FleurInput __all__ = ("FleurInput",) -__version__ = "0.1.1" +__version__ = "0.2.0" diff --git a/pymatgen/io/fleur/tests/test_fleurinput.py b/pymatgen/io/fleur/tests/test_fleurinput.py index 51b75f3..3a4c5a9 100644 --- a/pymatgen/io/fleur/tests/test_fleurinput.py +++ b/pymatgen/io/fleur/tests/test_fleurinput.py @@ -3,6 +3,7 @@ Tests of the FleurInput class """ from pathlib import Path +from tempfile import TemporaryDirectory from pymatgen.util.testing import PymatgenTest from pymatgen.io.fleur import FleurInput @@ -171,3 +172,127 @@ def test_inpgen_file_roundtrip(self): print(original) print(res) self.assertTrue(self.assertStrContentEqual(original, res)) + + +class FleurInputStructureIntegrationTest(PymatgenTest): + + TEST_FILES_DIR = TEST_FILES_DIR + + def test_inpgen_from_string(self): + """ + Test that the inpgen file is correctly parsed with teh from_str method of Structure + """ + + with open(TEST_FILES_DIR / "inp_test", "r") as f: + content = f.read() + + s = Structure.from_str(content, fmt="fleur-inpgen") + + param = 5.130606429 + lattice = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]] + + self.assertArrayAlmostEqual(lattice, s.lattice.matrix.tolist()) + self.assertEqual(atoms, [site.specie.symbol for site in s]) + self.assertArrayAlmostEqual(fraccoords, [site.frac_coords.tolist() for site in s]) + + def test_fleur_xml_from_string(self): + """ + Test that the fleur xml file is correctly parsed with the from_str method of Structure + """ + + with open(TEST_FILES_DIR / "inp.xml", "rb") as f: + content = f.read() + + s = Structure.from_str(content, fmt="fleur") + + param = 5.1306085 + lattice = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.125, 0.125, 0.125], [-0.125, -0.125, -0.125]] + + self.assertArrayAlmostEqual(lattice, s.lattice.matrix.tolist()) + self.assertEqual(atoms, [site.specie.symbol for site in s]) + self.assertArrayAlmostEqual(fraccoords, [site.frac_coords.tolist() for site in s]) + + def test_structure_to_inpgen_str(self): + """ + Test that the to method of Structure produces the right output for the inpgen format + """ + + param = 5.130606429 + cell = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]] + + struc = Structure(Lattice(cell), atoms, fraccoords) + + expected_inpgen_content = """\ + Si2 +&input cartesian=F / + 0.000000000 5.130606429 5.130606429 + 5.130606429 0.000000000 5.130606429 + 5.130606429 5.130606429 0.000000000 + 1.0000000000 + 1.000000000 1.000000000 1.000000000 + + 2 + 14 0.0000000000 0.0000000000 0.0000000000 + 14 0.2500000000 0.2500000000 0.2500000000 + """ + + self.assertTrue(self.assertStrContentEqual(expected_inpgen_content, struc.to(fmt="fleur-inpgen"))) + + def test_structure_from_file_inpgen(self): + """ + Test that the from_file method reads the inpgen input correctly + """ + + s = Structure.from_file(TEST_FILES_DIR / "inp_test") + + param = 5.130606429 + lattice = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]] + + self.assertArrayAlmostEqual(lattice, s.lattice.matrix.tolist()) + self.assertEqual(atoms, [site.specie.symbol for site in s]) + self.assertArrayAlmostEqual(fraccoords, [site.frac_coords.tolist() for site in s]) + + def test_structure_from_file_inpgen_alternate_name(self): + """ + Test that the from_file method reads the inpgen input correctly + """ + + with open(TEST_FILES_DIR / "inp_test", "r") as f: + content = f.read() + + with TemporaryDirectory() as td: + with open(Path(td) / "aiida.in", "w") as f: + f.write(content) + s = Structure.from_file(Path(td) / "aiida.in") + + param = 5.130606429 + lattice = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]] + + self.assertArrayAlmostEqual(lattice, s.lattice.matrix.tolist()) + self.assertEqual(atoms, [site.specie.symbol for site in s]) + self.assertArrayAlmostEqual(fraccoords, [site.frac_coords.tolist() for site in s]) + + def test_structure_from_file_xml(self): + """ + Test that the XML file from fleur is correctly read in with the from_file method + """ + s = Structure.from_file(TEST_FILES_DIR / "inp.xml") + + param = 5.1306085 + lattice = [[0, param, param], [param, 0, param], [param, param, 0]] + atoms = ["Si", "Si"] + fraccoords = [[0.125, 0.125, 0.125], [-0.125, -0.125, -0.125]] + + self.assertArrayAlmostEqual(lattice, s.lattice.matrix.tolist()) + self.assertEqual(atoms, [site.specie.symbol for site in s]) + self.assertArrayAlmostEqual(fraccoords, [site.frac_coords.tolist() for site in s]) diff --git a/setup.py b/setup.py index 9a06dff..ddd3984 100644 --- a/setup.py +++ b/setup.py @@ -17,9 +17,9 @@ setup( name="pymatgen-io-fleur", packages=find_namespace_packages(include=["pymatgen.io.*"]), - version="0.1.1", + version="0.2.0", install_requires=[ - "pymatgen>=2022.0.3", + "pymatgen>=2022.0.15", "masci-tools>=0.5.0", ], extras_require={}, @@ -36,6 +36,7 @@ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License",