Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.2.0 #1

Merged
merged 4 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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