Skip to content

Commit

Permalink
Fix vasp potentials for GenericMasters
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed Apr 19, 2024
1 parent cd7bb5c commit 77143d2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pyiron_atomistics/vasp/base.py
Expand Up @@ -134,7 +134,12 @@ def structure(self, structure):
"""
GenericDFTJob.structure.fset(self, structure)
if structure is not None:
if structure is not None and any(
[
el not in self._potential._potential_dict.keys()
for el in set(structure.get_chemical_symbols())
]
):
self._potential = VaspPotentialSetter(
element_lst=structure.get_species_symbols().tolist()
)
Expand Down Expand Up @@ -772,12 +777,17 @@ def to_dict(self):
job_dict = super().to_dict()
job_dict.update({"input/" + k: v for k, v in self._structure_to_dict().items()})
job_dict.update({"input/" + k: v for k, v in self.input.to_dict().items()})
job_dict["input/potential_dict"] = self._potential.to_dict()
return job_dict

def from_dict(self, job_dict):
super().from_dict(job_dict=job_dict)
self._structure_from_dict(job_dict=job_dict)
self.input.from_dict(input_dict=job_dict["input"])
if "potential_dict" in job_dict["input"].keys():
self._potential.from_dict(
potential_dict=job_dict["input"]["potential_dict"]
)

def to_hdf(self, hdf=None, group_name=None):
"""
Expand Down
7 changes: 6 additions & 1 deletion pyiron_atomistics/vasp/interactive.py
Expand Up @@ -42,7 +42,12 @@ def structure(self):
@structure.setter
def structure(self, structure):
GenericInteractive.structure.fset(self, structure)
if structure is not None:
if structure is not None and any(
[
el not in self._potential._potential_dict.keys()
for el in set(structure.get_chemical_symbols())
]
):
self._potential = VaspPotentialSetter(
element_lst=structure.get_species_symbols().tolist()
)
Expand Down
4 changes: 4 additions & 0 deletions pyiron_atomistics/vasp/potential.py
Expand Up @@ -263,6 +263,10 @@ def __setattr__(self, key, value):
def to_dict(self):
return self._potential_dict

def from_dict(self, potential_dict):
for key, value in potential_dict.items():
self._potential_dict[key] = value

def __repr__(self):
return self._potential_dict.__repr__()

Expand Down
7 changes: 7 additions & 0 deletions tests/vasp/test_vasp.py
Expand Up @@ -60,6 +60,13 @@ def tearDownClass(cls):
def setUp(self):
self.job.structure = None

def test_potential_set(self):
job_pot = self.project.create_job("Vasp", "potential")
job_pot.structure = CrystalStructure("Fe", BravaisBasis="bcc", a=2.83)
job_pot.potential["Fe"] = "Fe_sv_GW"
job_pot.structure = CrystalStructure("Fe", BravaisBasis="bcc", a=2.9)
self.assertEqual(str(job_pot.potential), str({"Fe": "Fe_sv_GW"}))

def test_list_potentials(self):
self.assertRaises(ValueError, self.job.list_potentials)
self.assertEqual(sorted([
Expand Down

0 comments on commit 77143d2

Please sign in to comment.