Skip to content

Commit

Permalink
Remove properties from abivars dict as this breaks the interface with… (
Browse files Browse the repository at this point in the history
#3642)

* Remove properties from abivars dict as this breaks the interface with Abinit

* Fix test_to_from_abivars

* Fix typo

* tweak comments

---------

Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
gmatteo and janosh authored Feb 23, 2024
1 parent 5ce2ae1 commit daf42d2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions pymatgen/io/abinit/abiobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def structure_from_abivars(cls=None, *args, **kwargs) -> Structure:
validate_proximity=False,
to_unit_cell=False,
coords_are_cartesian=coords_are_cartesian,
properties=kwargs.get("properties"),
)


Expand Down Expand Up @@ -251,7 +250,6 @@ def structure_to_abivars(
"typat": typat,
"znucl": znucl_type,
"xred": x_red,
"properties": structure.properties,
}

# Add info on the lattice.
Expand Down
4 changes: 4 additions & 0 deletions pymatgen/io/abinit/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,7 @@ def to_str(self, verbose=0, title=None, **kwargs):
if title is not None:
return "\n".join([marquee(title, mark="="), header_str])
return header_str

# to_string alias required for backwards compatibility
# PLEASE DO NOT REMOVE THIS LINE AS THIS API HAS BEEN AROUND FOR SEVERAL YEARS
to_string = to_str
9 changes: 7 additions & 2 deletions tests/core/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,14 @@ def test_default_dict_attrs(self):

def test_to_from_abivars(self):
"""Test as_dict, from_dict with fmt == abivars."""
dct = self.struct.as_dict(fmt="abivars")
# Properties are not supported if fmt="abivars" as its not a serialization protocol
# but a format that allows one to get a dict with the abinit variables defining the structure.
struct = self.struct.copy()
struct.properties = {}
dct = struct.as_dict(fmt="abivars")
assert "properties" not in dct
s2 = Structure.from_dict(dct, fmt="abivars")
assert s2 == self.struct
assert s2 == struct
assert isinstance(s2, Structure)

def test_to_from_file_str(self):
Expand Down
1 change: 1 addition & 0 deletions tests/io/abinit/test_abiobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_znucl_typat(self):
assert_array_equal(enf_vars["znucl"], enforce_znucl)
assert_array_equal(enf_vars["typat"], enforce_typat)
assert_array_equal(def_vars["xred"], enf_vars["xred"])
assert "properties" not in enf_vars

assert [s.symbol for s in species_by_znucl(gan)] == ["Ga", "N"]

Expand Down
2 changes: 2 additions & 0 deletions tests/io/abinit/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ def test_api(self):
assert head.foo == 1
assert str(head)
assert head.to_str(verbose=2, title="title")
# PLEASE DO NOT REMOVE THIS LINE AS THIS API HAS BEEN AROUND FOR SEVERAL YEARS,
assert head.to_string(verbose=2, title="title")

0 comments on commit daf42d2

Please sign in to comment.