Skip to content

Commit

Permalink
Merge pull request #1304 from pyiron/lammps_potential_dict
Browse files Browse the repository at this point in the history
A workaround to fix reloading potentials with LAMMPS
  • Loading branch information
jan-janssen authored Feb 2, 2024
2 parents 75b399e + 79f9846 commit b9c5f3f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .ci_support/environment-old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- pandas =2.0.3
- phonopy =2.20.0
- pint =0.18
- pyiron_base =0.6.16
- pyiron_base =0.7.2
- pylammpsmpi =0.2.7
- pyscal =2.10.4
- scikit-learn =1.2.1
Expand Down
2 changes: 1 addition & 1 deletion .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- pandas =2.2.0
- phonopy =2.21.0
- pint =0.23
- pyiron_base =0.7.1
- pyiron_base =0.7.2
- pylammpsmpi =0.2.11
- pyscal =2.10.18
- scikit-learn =1.4.0
Expand Down
14 changes: 12 additions & 2 deletions pyiron_atomistics/lammps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,12 @@ def from_hdf(self, hdf=None, group_name=None): # TODO: group_name should be rem
self._structure_from_hdf()
self.input.from_dict(
data_dict=self._hdf5.read_dict_from_hdf(
group_paths=["input", "input/control_inp", "input/potential_inp"]
[
"input",
"input/control_inp",
"input/potential_inp",
"input/potential_inp/potential",
]
)
)

Expand Down Expand Up @@ -1082,7 +1087,12 @@ def from_hdf(self, hdf5):
"""
self.from_dict(
data_dict=hdf5.read_dict_from_hdf(
["input", "input/control_inp", "input/potential_inp"]
[
"input",
"input/control_inp",
"input/potential_inp",
"input/potential_inp/potential",
]
)
)

Expand Down
24 changes: 24 additions & 0 deletions pyiron_atomistics/lammps/potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ def get_charge(self, element_symbol):
)
raise NameError(msg) from None

def to_dict(self):
super_dict = super(LammpsPotential, self).to_dict()
if self._df is not None:
super_dict.update(
{
"potential/" + key: self._df[key].values[0]
for key in ["Config", "Filename", "Name", "Model", "Species"]
}
)
if "Citations" in self._df.columns.values:
super_dict["potential/Citations"] = self._df["Citations"].values[0]
return super_dict

def from_dict(self, obj_dict, version: str = None):
super(LammpsPotential, self).from_dict(obj_dict=obj_dict, version=version)
if "potential" in obj_dict.keys() and "Config" in obj_dict["potential"].keys():
entry_dict = {
key: [obj_dict["potential"][key]]
for key in ["Config", "Filename", "Name", "Model", "Species"]
}
if "Citations" in obj_dict["potential"].keys():
entry_dict["Citations"] = [obj_dict["potential"]["Citations"]]
self._df = pd.DataFrame(entry_dict)

def to_hdf(self, hdf, group_name=None):
if self._df is not None:
with hdf.open("potential") as hdf_pot:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"pandas==2.2.0",
"phonopy==2.21.0",
"pint==0.23",
"pyiron_base==0.7.1",
"pyiron_base==0.7.2",
"pylammpsmpi==0.2.11",
"scipy==1.12.0",
"scikit-learn==1.4.0",
Expand Down

0 comments on commit b9c5f3f

Please sign in to comment.