Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: Unify previous directory Maker API #593

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions src/atomate2/amset/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
def make(
self,
settings: dict,
prev_amset_dir: str | Path = None,
prev_dir: str | Path = None,
wavefunction_dir: str | Path = None,
deformation_dir: str | Path = None,
bandstructure_dir: str | Path = None,
Expand All @@ -54,7 +54,7 @@
----------
settings : dict
Amset settings.
prev_amset_dir : str or Path
prev_dir : str or Path
A previous AMSET calculation directory to copy output files from. The
previous directory is also used to check for transport convergence.
wavefunction_dir : str or Path
Expand All @@ -66,14 +66,12 @@
band_structure_data.json).
"""
# copy previous inputs
from_prev = prev_amset_dir is not None
if prev_amset_dir is not None:
copy_amset_files(prev_amset_dir)
from_prev = prev_dir is not None

Check warning on line 69 in src/atomate2/amset/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/amset/jobs.py#L69

Added line #L69 was not covered by tests
if prev_dir is not None:
copy_amset_files(prev_dir)

Check warning on line 71 in src/atomate2/amset/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/amset/jobs.py#L71

Added line #L71 was not covered by tests
else:
if bandstructure_dir is None:
raise ValueError(
"Either prev_amset_dir or bandstructure_dir must be set"
)
raise ValueError("Either prev_dir or bandstructure_dir must be set")

Check warning on line 74 in src/atomate2/amset/jobs.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/amset/jobs.py#L74

Added line #L74 was not covered by tests

copy_amset_files(bandstructure_dir)

Expand Down Expand Up @@ -116,7 +114,7 @@
if self.resubmit and not converged:
replace = self.make(
{"interpolation_factor": settings.get("interpolation_factor", 10) + 5},
prev_amset_dir=task_doc.dir_name,
prev_dir=task_doc.dir_name,
)

return Response(output=task_doc, replace=replace)
4 changes: 2 additions & 2 deletions src/atomate2/common/flows/defect.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def make(
struct2,
distortions=self.distortions,
static_maker=self.static_maker,
prev_vasp_dir=dir1,
prev_dir=dir1,
add_name="q1",
add_info={"relaxed_uuid": relax1.uuid, "distorted_uuid": relax2.uuid},
)
Expand All @@ -120,7 +120,7 @@ def make(
struct1,
distortions=self.distortions,
static_maker=self.static_maker,
prev_vasp_dir=dir2,
prev_dir=dir2,
add_name="q2",
add_info={"relaxed_uuid": relax2.uuid, "distorted_uuid": relax1.uuid},
)
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/common/flows/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def make(
----------
structure : .Structure
A pymatgen structure.
prev_vasp_dir : str or Path or None
prev_dir : str or Path or None
A previous vasp calculation directory to use for copying outputs.
equilibrium_stress : tuple of tuple of float
The equilibrium stress of the (relaxed) structure, if known.
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/common/jobs/defect.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def spawn_energy_curve_calcs(
distorted_structure: Structure,
distortions: Iterable[float],
static_maker: StaticMaker,
prev_vasp_dir: str | Path | None = None,
prev_dir: str | Path | None = None,
add_name: str = "",
add_info: dict | None = None,
) -> Response:
Expand Down Expand Up @@ -108,7 +108,7 @@ def spawn_energy_curve_calcs(
)
# add all the distorted structures
for i, d_struct in enumerate(distorted_structures):
static_job = static_maker.make(d_struct, prev_vasp_dir=prev_vasp_dir)
static_job = static_maker.make(d_struct, prev_dir=prev_dir)
suffix = f" {i}" if add_name == "" else f" {add_name} {i}"

# write some provenances data in info.json file
Expand Down
8 changes: 4 additions & 4 deletions src/atomate2/common/jobs/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def run_phonon_displacements(
structure: Structure,
supercell_matrix,
phonon_maker: BaseVaspMaker | ForceFieldStaticMaker = None,
prev_vasp_dir: str | Path = None,
prev_dir: str | Path = None,
) -> Flow:
"""
Run phonon displacements.
Expand All @@ -268,7 +268,7 @@ def run_phonon_displacements(
supercell matrix for meta data
phonon_maker : .BaseVaspMaker
A VaspMaker to use to generate the elastic relaxation jobs.
prev_vasp_dir : str or Path or None
prev_dir : str or Path or None
A previous vasp calculation directory to use for copying outputs.
"""
if phonon_maker is None:
Expand All @@ -282,8 +282,8 @@ def run_phonon_displacements(
}

for i, displacement in enumerate(displacements):
if prev_vasp_dir is not None:
phonon_job = phonon_maker.make(displacement, prev_vasp_dir=prev_vasp_dir)
if prev_dir is not None:
phonon_job = phonon_maker.make(displacement, prev_dir=prev_dir)
else:
phonon_job = phonon_maker.make(displacement)
phonon_job.append_name(f" {i + 1}/{len(displacements)}")
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def parse_additional_json(dir_name: Path) -> dict[str, Any]:
additional_json = {}
for filename in dir_name.glob("*.json*"):
key = filename.name.split(".")[0]
# ignore FW.json(.gz) so jobflow doesn't try to parse prev_vasp_dir
# ignore FW.json(.gz) so jobflow doesn't try to parse prev_dir
# OutputReferences was causing atomate2 MP workflows to fail with ValueError:
# Could not resolve reference 7f5a7f14-464c-4a5b-85f9-8d11b595be3b not in store
# or cache contact @janosh in case of questions
Expand Down
44 changes: 18 additions & 26 deletions src/atomate2/cp2k/flows/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,27 @@
relax_maker1: Maker = field(default_factory=RelaxMaker)
relax_maker2: Maker = field(default_factory=RelaxMaker)

def make(
self, structure: Structure, prev_cp2k_dir: str | Path | None = None
) -> Flow:
def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow:
"""
Create a flow with two chained relaxations.

Parameters
----------
structure : .Structure
A pymatgen structure object.
prev_cp2k_dir : str or Path or None
prev_dir : str or Path or None
A previous Cp2k calculation directory to copy output files from.

Returns
-------
Flow
A flow containing two relaxations.
"""
relax1 = self.relax_maker1.make(structure, prev_cp2k_dir=prev_cp2k_dir)
relax1 = self.relax_maker1.make(structure, prev_dir=prev_dir)
relax1.name += " 1"

relax2 = self.relax_maker2.make(
relax1.output.structure, prev_cp2k_dir=relax1.output.dir_name
relax1.output.structure, prev_dir=relax1.output.dir_name
)
relax2.name += " 2"

Expand Down Expand Up @@ -114,33 +112,31 @@
static_maker: Maker = field(default_factory=StaticMaker)
bs_maker: Maker = field(default_factory=NonSCFMaker)

def make(
self, structure: Structure, prev_cp2k_dir: str | Path | None = None
) -> Flow:
def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow:
"""
Create a band structure flow.

Parameters
----------
structure : Structure
A pymatgen structure object.
prev_cp2k_dir : str or Path or None
prev_dir : str or Path or None
A previous VASP calculation directory to copy output files from.

Returns
-------
Flow
A band structure flow.
"""
static_job = self.static_maker.make(structure, prev_cp2k_dir=prev_cp2k_dir)
static_job = self.static_maker.make(structure, prev_dir=prev_dir)

Check warning on line 131 in src/atomate2/cp2k/flows/core.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/cp2k/flows/core.py#L131

Added line #L131 was not covered by tests
jobs = [static_job]

outputs = {}
bandstructure_type = self.bandstructure_type
if bandstructure_type in ("both", "uniform"):
uniform_job = self.bs_maker.make(
static_job.output.structure,
prev_cp2k_dir=static_job.output.dir_name,
prev_dir=static_job.output.dir_name,
mode="uniform",
)
uniform_job.name += " uniform"
Expand All @@ -154,7 +150,7 @@
if bandstructure_type in ("both", "line"):
line_job = self.bs_maker.make(
static_job.output.structure,
prev_cp2k_dir=static_job.output.dir_name,
prev_dir=static_job.output.dir_name,
mode="line",
)
line_job.name += " line"
Expand Down Expand Up @@ -192,27 +188,25 @@
relax_maker: Maker = field(default_factory=DoubleRelaxMaker)
band_structure_maker: Maker = field(default_factory=BandStructureMaker)

def make(
self, structure: Structure, prev_cp2k_dir: str | Path | None = None
) -> Flow:
def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow:
"""
Run a relaxation and then calculate the uniform and line mode band structures.

Parameters
----------
structure: .Structure
A pymatgen structure object.
prev_cp2k_dir : str or Path or None
prev_dir : str or Path or None
A previous CP2K calculation directory to copy output files from.

Returns
-------
Flow
A relax and band structure flow.
"""
relax_job = self.relax_maker.make(structure, prev_cp2k_dir=prev_cp2k_dir)
relax_job = self.relax_maker.make(structure, prev_dir=prev_dir)

Check warning on line 207 in src/atomate2/cp2k/flows/core.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/cp2k/flows/core.py#L207

Added line #L207 was not covered by tests
bs_flow = self.band_structure_maker.make(
relax_job.output.structure, prev_cp2k_dir=relax_job.output.dir_name
relax_job.output.structure, prev_dir=relax_job.output.dir_name
)

return Flow([relax_job, bs_flow], bs_flow.output, name=self.name)
Expand Down Expand Up @@ -265,17 +259,15 @@
updates, self.hybrid_maker.input_set_generator.user_input_settings
)

def make(
self, structure: Structure, prev_cp2k_dir: str | Path | None = None
) -> Job:
def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Job:
"""
Make a hybrid flow.

Parameters
----------
structure: .Structure
A pymatgen structure object.
prev_cp2k_dir : str or Path or None
prev_dir : str or Path or None
A previous CP2K calculation directory to copy output files from.

Returns
Expand All @@ -285,13 +277,13 @@
"""
jobs = []
if self.initialize_with_pbe:
initialization = self.pbe_maker.make(structure, prev_cp2k_dir)
initialization = self.pbe_maker.make(structure, prev_dir)

Check warning on line 280 in src/atomate2/cp2k/flows/core.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/cp2k/flows/core.py#L280

Added line #L280 was not covered by tests
jobs.append(initialization)
hyb = self.hybrid_maker.make(
initialization.output.structure if self.initialize_with_pbe else structure,
prev_cp2k_dir=initialization.output.dir_name
prev_dir=initialization.output.dir_name
if self.initialize_with_pbe
else prev_cp2k_dir,
else prev_dir,
)
jobs.append(hyb)
return Flow(jobs, output=hyb.output, name=self.name)
Expand Down
10 changes: 5 additions & 5 deletions src/atomate2/cp2k/jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@

@cp2k_job
def make(
self, structure: Structure, prev_cp2k_dir: str | Path | None = None
self, structure: Structure, prev_dir: str | Path | None = None
) -> Response:
"""
Run a CP2K calculation.
Expand All @@ -138,7 +138,7 @@
----------
structure : Structure
A pymatgen structure object.
prev_vasp_dir : str or Path or None
prev_dir : str or Path or None
A previous CP2K calculation directory to copy output files from.
"""
# Apply transformations if they are present
Expand All @@ -155,9 +155,9 @@
self.write_additional_data.setdefault("transformations:json", t_json)

# copy previous inputs
from_prev = prev_cp2k_dir is not None
if prev_cp2k_dir is not None:
copy_cp2k_outputs(prev_cp2k_dir, **self.copy_cp2k_kwargs)
from_prev = prev_dir is not None
if prev_dir is not None:
copy_cp2k_outputs(prev_dir, **self.copy_cp2k_kwargs)

Check warning on line 160 in src/atomate2/cp2k/jobs/base.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/cp2k/jobs/base.py#L160

Added line #L160 was not covered by tests

# write cp2k input files
self.write_input_set_kwargs["from_prev"] = from_prev
Expand Down
12 changes: 6 additions & 6 deletions src/atomate2/cp2k/jobs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
def make(
self,
structure: Structure,
prev_cp2k_dir: str | Path | None,
prev_dir: str | Path | None,
mode: str = "uniform",
) -> None:
"""
Expand All @@ -310,7 +310,7 @@
----------
structure : .Structure
A pymatgen structure object.
prev_vasp_dir : str or Path or None
prev_dir : str or Path or None
A previous CP2K calculation directory to copy output files from.
mode : str
Type of band structure calculation. Options are:
Expand All @@ -325,7 +325,7 @@
# copy previous inputs
self.copy_cp2k_kwargs.setdefault("additional_cp2k_files", ("wfn",))

return super().make.original(self, structure, prev_cp2k_dir)
return super().make.original(self, structure, prev_dir)

Check warning on line 328 in src/atomate2/cp2k/jobs/core.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/cp2k/jobs/core.py#L328

Added line #L328 was not covered by tests


@dataclass
Expand Down Expand Up @@ -376,7 +376,7 @@
def make(
self,
structure: Structure,
prev_cp2k_dir: str | Path | None = None,
prev_dir: str | Path | None = None,
) -> None:
"""
Run a transmuter Cp2k job.
Expand All @@ -385,7 +385,7 @@
----------
structure : Structure
A pymatgen structure object.
prev_vasp_dir : str or Path or None
prev_dir : str or Path or None
A previous Cp2k calculation directory to copy output files from.
"""
transformations = get_transformations(
Expand All @@ -399,7 +399,7 @@
tjson = transmuter.transformed_structures[-1]
self.write_additional_data.setdefault("transformations:json", tjson)

return super().make.original(self, structure, prev_cp2k_dir)
return super().make.original(self, structure, prev_dir)


@dataclass
Expand Down
Loading
Loading