Skip to content

Commit bb39b73

Browse files
authored
Merge pull request #111 from benrich37/missing-unit-conversion
Missing bohr->angstrom conversion for special case lattices
2 parents f57657a + c87aeb0 commit bb39b73

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/pymatgen/io/jdftx/inputs.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,10 @@ def _infile_to_pmg_lattice(jdftxinfile: JDFTXInfile) -> Lattice:
14701470

14711471

14721472
def _infile_special_format_to_pmg_lattice(jdftxinfile: JDFTXInfile) -> Lattice:
1473-
jl = jdftxinfile["lattice"]
1473+
jl = jdftxinfile["lattice"].copy()
1474+
for key in ["a", "b", "c"]:
1475+
if key in jl and isinstance(jl[key], float):
1476+
jl[key] *= bohr_to_ang
14741477
if "modification" in jl:
14751478
raise NotImplementedError("Special case lattices with modification not implemented yet")
14761479
# Second boolean to check if latt-scale was passed but does nothing

tests/io/jdftx/test_jdftxinfile.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from pymatgen.core.structure import Site, Structure
11+
from pymatgen.core.units import bohr_to_ang
1112
from pymatgen.io.jdftx.inputs import JDFTXInfile, JDFTXStructure, selective_dynamics_site_prop_to_jdftx_interpretable
1213
from pymatgen.io.jdftx.jdftxinfile_default_inputs import antoinePvap, default_inputs
1314
from pymatgen.io.jdftx.jdftxinfile_master_format import get_tag_object
@@ -571,6 +572,7 @@ def test_lattice_writing(value_str: str):
571572
)
572573
def test_jdftxstructure_lattice_conversion(value_str: str):
573574
test_vars = ["a", "b", "c", "alpha", "beta", "gamma"]
575+
conv_vars = ["a", "b", "c"]
574576
mft_lattice_tag = get_tag_object("lattice")
575577
assert mft_lattice_tag is not None
576578
i = mft_lattice_tag.get_format_index_for_str_value("lattice", value_str)
@@ -584,7 +586,10 @@ def test_jdftxstructure_lattice_conversion(value_str: str):
584586
structure = infile.to_pmg_structure(infile)
585587
for var in test_vars:
586588
if var in parsed_tag:
587-
assert_same_value(float(getattr(structure.lattice, var)), float(parsed_tag[var]))
589+
should_be = parsed_tag[var]
590+
if var in conv_vars:
591+
should_be *= bohr_to_ang
592+
assert_same_value(float(getattr(structure.lattice, var)), float(should_be))
588593

589594

590595
def test_jdftxinfile_comparison():

0 commit comments

Comments
 (0)