From b54cb0f2052bc2ed844389cdae0d3775705b4916 Mon Sep 17 00:00:00 2001 From: janssenhenning Date: Mon, 6 Sep 2021 11:27:17 +0200 Subject: [PATCH 1/4] Add tests for the integration of the FleurInput classes into pymatgen structures These will fail on the CI at the moment since these integrations are not yet part of the main package --- pymatgen/io/fleur/tests/test_fleurinput.py | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) 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]) From 1d463452dc52d77763e9053c9c3f9aeb9d66212c Mon Sep 17 00:00:00 2001 From: janssenhenning Date: Sat, 23 Oct 2021 11:24:02 +0200 Subject: [PATCH 2/4] Bump required version for pymatgen to ensure that the Fleur add-on integration is included completely --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9a06dff..3742808 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ packages=find_namespace_packages(include=["pymatgen.io.*"]), version="0.1.1", 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", From 04502a25f95c87531aeeb695cb04cfa2272060c6 Mon Sep 17 00:00:00 2001 From: janssenhenning Date: Sat, 23 Oct 2021 11:25:26 +0200 Subject: [PATCH 3/4] Adjust README --- .gitignore | 3 +++ README.rst | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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 From a3c1276062815fe94db50ebb7b752ff8444671a8 Mon Sep 17 00:00:00 2001 From: janssenhenning Date: Sat, 23 Oct 2021 11:29:28 +0200 Subject: [PATCH 4/4] Raise version number --- pymatgen/io/fleur/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/setup.py b/setup.py index 3742808..ddd3984 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ 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.15", "masci-tools>=0.5.0",