Skip to content

Commit

Permalink
Merge pull request #1 from JuDFTteam/develop
Browse files Browse the repository at this point in the history
Release ``0.2.0``
  • Loading branch information
janssenhenning authored Oct 23, 2021
2 parents 1cbfd2f + a3c1276 commit 80f9778
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ venv.bak/
.spyderproject
.spyproject

# VSCode
.vscode/

# Rope project settings
.ropeproject

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/fleur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .fleurinput import FleurInput

__all__ = ("FleurInput",)
__version__ = "0.1.1"
__version__ = "0.2.0"
125 changes: 125 additions & 0 deletions pymatgen/io/fleur/tests/test_fleurinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={},
Expand All @@ -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",
Expand Down

0 comments on commit 80f9778

Please sign in to comment.