Skip to content

Commit

Permalink
Merge pull request #534 from materialsproject/fix-gh-533
Browse files Browse the repository at this point in the history
CP2K use `calcs_reversed[0]` instead of `calcs_reversed[-1]` to not reverse again
  • Loading branch information
janosh authored Sep 27, 2023
2 parents 3c16799 + 7010032 commit 8c15179
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
25 changes: 12 additions & 13 deletions src/atomate2/cp2k/schemas/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,27 +374,26 @@ def from_directory(
if cp2k_objects:
included_objects = list(cp2k_objects)

if isinstance(calcs_reversed[-1].output.structure, Structure):
if isinstance(calcs_reversed[0].output.structure, Structure):
attr = "from_structure"
dat = {
"structure": calcs_reversed[-1].output.structure,
"meta_structure": calcs_reversed[-1].output.structure,
"structure": calcs_reversed[0].output.structure,
"meta_structure": calcs_reversed[0].output.structure,
"include_structure": True,
}
elif isinstance(calcs_reversed[-1].output.structure, Molecule):
elif isinstance(calcs_reversed[0].output.structure, Molecule):
attr = "from_molecule"
dat = {
"structure": calcs_reversed[-1].output.structure,
"meta_structure": calcs_reversed[-1].output.structure,
"molecule": calcs_reversed[-1].output.structure,
"structure": calcs_reversed[0].output.structure,
"meta_structure": calcs_reversed[0].output.structure,
"molecule": calcs_reversed[0].output.structure,
"include_molecule": True,
}

doc = getattr(cls, attr)(**dat)
ddict = doc.dict()
data = {
"structure": calcs_reversed[-1].output.structure,
"meta_structure": calcs_reversed[-1].output.structure,
"structure": calcs_reversed[0].output.structure,
"meta_structure": calcs_reversed[0].output.structure,
"dir_name": dir_name,
"calcs_reversed": calcs_reversed,
"analysis": analysis,
Expand All @@ -405,16 +404,16 @@ def from_directory(
"icsd_id": icsd_id,
"tags": tags,
"author": author,
"completed_at": calcs_reversed[-1].completed_at,
"completed_at": calcs_reversed[0].completed_at,
"input": InputSummary.from_cp2k_calc_doc(calcs_reversed[0]),
"output": OutputSummary.from_cp2k_calc_doc(calcs_reversed[-1]),
"output": OutputSummary.from_cp2k_calc_doc(calcs_reversed[0]),
"state": _get_state(calcs_reversed, analysis),
"entry": cls.get_entry(calcs_reversed),
"run_stats": _get_run_stats(calcs_reversed),
"cp2k_objects": cp2k_objects,
"included_objects": included_objects,
}
doc = cls(**ddict)
doc = cls(**doc.dict())
doc = doc.copy(update=data)
return doc.copy(update=additional_fields)

Expand Down
16 changes: 8 additions & 8 deletions src/atomate2/forcefields/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ForceFieldRelaxMaker(Maker):
name : str
The job name.
force_field_name : str
The name of the forcefield.
The name of the force field.
relax_cell : bool
Whether to allow the cell shape/volume to change during relaxation.
steps : int
Expand All @@ -65,7 +65,7 @@ class ForceFieldRelaxMaker(Maker):
@job(output_schema=ForceFieldTaskDocument)
def make(self, structure: Structure):
"""
Perform a relaxation of a structure using a forcefield.
Perform a relaxation of a structure using a force field.
Parameters
----------
Expand Down Expand Up @@ -116,7 +116,7 @@ class ForceFieldStaticMaker(ForceFieldRelaxMaker):
@job(output_schema=ForceFieldTaskDocument)
def make(self, structure: Structure):
"""
Perform a static evaluation using a forcefield.
Perform a static evaluation using a force field.
Parameters
----------
Expand Down Expand Up @@ -153,7 +153,7 @@ class CHGNetRelaxMaker(ForceFieldRelaxMaker):
Parameters
----------
force_field_name : str
The name of the forcefield.
The name of the force field.
relax_cell : bool
Whether to allow the cell shape/volume to change during relaxation.
steps : int
Expand Down Expand Up @@ -217,7 +217,7 @@ class M3GNetRelaxMaker(ForceFieldRelaxMaker):
name : str
The job name.
force_field_name : str
The name of the forcefield.
The name of the force field.
relax_cell : bool
Whether to allow the cell shape/volume to change during relaxation.
steps : int
Expand Down Expand Up @@ -269,7 +269,7 @@ class M3GNetStaticMaker(ForceFieldStaticMaker):
name : str
The job name.
force_field_name : str
The name of the forcefield.
The name of the force field.
task_document_kwargs : dict
Additional keyword args passed to :obj:`.ForceFieldTaskDocument()`.
"""
Expand Down Expand Up @@ -307,7 +307,7 @@ class GAPRelaxMaker(ForceFieldRelaxMaker):
name : str
The job name.
force_field_name : str
The name of the forcefield.
The name of the force field.
relax_cell : bool
Whether to allow the cell shape/volume to change during relaxation.
steps : int
Expand Down Expand Up @@ -359,7 +359,7 @@ class GAPStaticMaker(ForceFieldStaticMaker):
name : str
The job name.
force_field_name : str
The name of the forcefield.
The name of the force field.
task_document_kwargs : dict
Additional keyword args passed to :obj:`.ForceFieldTaskDocument()`.
potential_args_str: str
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/forcefields/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def from_ase_compatible_result(
Parameters
----------
forcefield_name : str
Name of the forcefield used.
Name of the force field used.
result : dict
The outputted results from the task.
relax_cell : bool
Expand Down
3 changes: 3 additions & 0 deletions tests/cp2k/jobs/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def test_relax_maker(tmp_path, mock_cp2k, basis_and_potential, si_structure):
assert isinstance(output1, TaskDocument)
assert output1.output.energy == approx(-193.39161102270234)
assert len(output1.calcs_reversed[0].output.ionic_steps) == 1
assert output1.calcs_reversed[0].output.structure.lattice.abc == approx(
si_structure.lattice.abc
)


def test_transmuter(tmp_path, mock_cp2k, basis_and_potential, si_structure):
Expand Down

0 comments on commit 8c15179

Please sign in to comment.