Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
original_wf (Workflow): original workflow
fw_name_constraint (str): Only apply changes to FWs where fw_name contains this substring.
For example, use custodian only for certain runs, or set job_type to
"double_relaxation_run" only for structure optimization run, or set different
handler_group for different runs.
custodian_params (dict): A dict of parameters for RunVaspCustodian. e.g., use it to set
a "scratch_dir" or "handler_group".
"""
custodian_params = custodian_params if custodian_params else {}
wf_dict = original_wf.to_dict()
vasp_fws_and_tasks = get_fws_and_tasks(original_wf, fw_name_constraint=fw_name_constraint,
task_name_constraint="RunVasp")
for idx_fw, idx_t in vasp_fws_and_tasks:
if "vasp_cmd" not in custodian_params:
custodian_params["vasp_cmd"] = wf_dict["fws"][idx_fw]["spec"]["_tasks"][idx_t]["vasp_cmd"]
wf_dict["fws"][idx_fw]["spec"]["_tasks"][idx_t] = RunVaspCustodian(**custodian_params).to_dict()
return Workflow.from_dict(wf_dict)
a str value, grabs a previous calculation output by name. If False/None, will create
new static calculation using the provided structure.
db_file (str): Path to file specifying db credentials.
parents (Firework): Parents of this particular Firework. FW or list of FWS.
\*\*kwargs: Other kwargs that are passed to Firework.__init__.
"""
t = []
override_default_vasp_params = override_default_vasp_params or {}
vasp_input_set = vasp_input_set or MPStaticSet(structure, **override_default_vasp_params)
if prev_calc_loc:
t.append(CopyVaspOutputs(calc_loc=prev_calc_loc, contcar_to_poscar=True))
t.append(WriteVaspFromIOSet(structure=structure, vasp_input_set=vasp_input_set))
if previous_structure:
t.append(PreviousStructureTask())
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, auto_npar=">>auto_npar<<"))
t.append(SaveStructureTask())
t.append(PassCalcLocs(name=name))
t.append(VaspToDb(db_file=db_file, additional_fields={"task_label": name}))
name = f'{structure.formula.replace(" ", "")}-{name}'
super(StaticFW, self).__init__(t, parents=parents, name=name, **kwargs)
\*\*kwargs: Other kwargs that are passed to Firework.__init__.
"""
override_default_vasp_params = override_default_vasp_params or {}
vasp_input_set = vasp_input_set or MPRelaxSet(structure,
force_gamma=force_gamma,
**override_default_vasp_params)
if vasp_input_set.incar["ISIF"] in (0, 1, 2, 7) and job_type == "double_relaxation":
warnings.warn(
"A double relaxation run might not be appropriate with ISIF {}".format(
vasp_input_set.incar["ISIF"]))
t = []
t.append(WriteVaspFromIOSet(structure=structure,
vasp_input_set=vasp_input_set))
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, job_type=job_type,
max_force_threshold=max_force_threshold,
ediffg=ediffg,
auto_npar=auto_npar,
half_kpts_first_relax=half_kpts_first_relax))
t.append(PassCalcLocs(name=name))
t.append(
VaspToDb(db_file=db_file, additional_fields={"task_label": name}))
super(OptimizeFW, self).__init__(t, parents=parents, name="{}-{}".
format(
structure.composition.reduced_formula, name),
**kwargs)
t.append(WriteVaspSOCFromPrev(prev_calc_dir=".", magmom=magmom,
saxis=saxis))
elif parents and copy_vasp_outputs:
t.append(CopyVaspOutputs(calc_loc=True, additional_files=["CHGCAR"],
contcar_to_poscar=True))
t.append(WriteVaspSOCFromPrev(prev_calc_dir=".", magmom=magmom,
saxis=saxis))
elif structure:
vasp_input_set = MPSOCSet(structure)
t.append(WriteVaspFromIOSet(structure=structure,
vasp_input_set=vasp_input_set))
else:
raise ValueError("Must specify structure or previous calculation.")
t.extend(
[RunVaspCustodian(vasp_cmd=vasp_cmd, auto_npar=">>auto_npar<<"),
PassCalcLocs(name=name),
VaspToDb(db_file=db_file, additional_fields={"task_label": name})])
super(SOCFW, self).__init__(t, parents=parents, name=fw_name, **kwargs)
fw1 = MDFW(structure=structure, start_temp=temperature, end_temp=temperature, nsteps=run_steps,
name=name + "_" + str(spawn_count), vasp_input_set=vasp_input_set, db_file=db_file,
vasp_cmd=vasp_cmd, wall_time=run_time, override_default_vasp_params=override_default_vasp_params,
**optional_MDWF_params)
_steps += run_steps
spawn_count += 1
fw_list.append(fw1)
while _steps < target_steps:
_name = (name + "_" + str(spawn_count))
t = []
t.append(CopyVaspOutputs(calc_loc=True, contcar_to_poscar=True, additional_files=["XDATCAR", "OSZICAR", "DOSCAR"]))
if spawn_count == 1:
if copy_calcs:
t.append(CopyCalsHome(calc_home=calc_home, run_name=name + "_0"))
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, gamma_vasp_cmd=">>gamma_vasp_cmd<<",
handler_group="md", wall_time=run_time, gzip_output=False))
if copy_calcs:
t.append(CopyCalsHome(calc_home=calc_home, run_name=_name))
t.append(PassCalcLocs(name=_name))
new_fw = Firework(tasks=t, name=_name, parents=[fw_list[spawn_count-1]], spec=priority_spec)
_steps += run_steps
spawn_count += 1
fw_list.append(new_fw)
return fw_list
fw1 = MDFW(structure=structure, start_temp=temperature, end_temp=temperature, nsteps=run_steps,
name=name + "_" + str(spawn_count), vasp_input_set=vasp_input_set, db_file=db_file,
vasp_cmd=vasp_cmd, wall_time=run_time, copy_vasp_outputs=False, override_default_vasp_params=override_default_vasp_params,
**optional_MDWF_params)
_steps += run_steps
spawn_count += 1
fw_list.append(fw1)
while _steps < target_steps:
_name = (name + "_" + str(spawn_count))
t = []
t.append(CopyVaspOutputs(calc_loc=True, contcar_to_poscar=True, additional_files=["XDATCAR", "OSZICAR", "DOSCAR"]))
if spawn_count == 1:
if copy_calcs:
t.append(CopyCalsHome(calc_home=calc_home, run_name=name + "_0"))
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, gamma_vasp_cmd=">>gamma_vasp_cmd<<",
handler_group="md", wall_time=run_time, gzip_output=False))
if copy_calcs:
t.append(CopyCalsHome(calc_home=calc_home, run_name=_name))
t.append(PassCalcLocs(name=_name))
new_fw = Firework(tasks=t, name=_name, parents=[fw_list[spawn_count-1]], spec=priority_spec)
_steps += run_steps
spawn_count += 1
fw_list.append(new_fw)
return fw_list
def get_mdfw(start_temp, end_temp, nsteps, vasp_cmd, wall_time, name, copy_calcs, calc_home, db_file, snap_num, parents=[],
priority_spec={}, start_copy=False, relax=False, diffusion=False):
t = []
if start_copy:
t.append(CopyVaspOutputs(calc_loc=True, contcar_to_poscar=True, additional_files=["XDATCAR", "OSZICAR", "DOSCAR"]))
if copy_calcs:
t.append(
CopyCalsHome(calc_home=os.path.join(calc_home, name), run_name="cool_" + str(end_temp)))
t.append(CopyVaspOutputs(calc_loc=True, contcar_to_poscar=True, additional_files=["XDATCAR", "OSZICAR", "DOSCAR"]))
t.append(WriteSetTask(start_temp=start_temp, end_temp=end_temp, nsteps=nsteps))
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, gamma_vasp_cmd=">>gamma_vasp_cmd<<",
handler_group="md", wall_time=wall_time, gzip_output=False))
t.append(PassCalcLocs(name=name + "_cool_" + str(end_temp)))
if copy_calcs:
t.append(
CopyCalsHome(calc_home=os.path.join(calc_home, name), run_name="cool_" + str(end_temp)))
if relax:
t.append(RelaxStaticTask(copy_calcs=copy_calcs, calc_home=calc_home, db_file=db_file, snap_num=snap_num,
priority_spec=priority_spec))
if diffusion:
t.append(DiffusionTask(copy_calcs=copy_calcs, calc_home=calc_home, db_file=db_file, snap_num=snap_num,
priority_spec=priority_spec))
return Firework(t, name=name + "_cool_" + str(end_temp), parents=parents, spec=priority_spec)
parse_eigen=True,
mod_spec_key="normalmodes"))
else:
name = "raman_{}_{} {}".format(str(mode), str(displacement),
name)
key = "{}_{}".format(mode, displacement).replace('-',
'm').replace(
'.', 'd')
pass_fw = pass_vasp_result(
pass_dict={"mode": mode, "displacement": displacement,
"epsilon": "a>>epsilon_static"},
mod_spec_key="raman_epsilon->" + key,
parse_eigen=True)
t.extend([WriteNormalmodeDisplacedPoscar(mode=mode,
displacement=displacement),
RunVaspCustodian(vasp_cmd=vasp_cmd), pass_fw])
else:
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd))
t.extend([PassCalcLocs(name=name),
VaspToDb(db_file=db_file,
additional_fields={"task_label": name})])
super(LepsFW, self).__init__(t, parents=parents, name="{}-{}".format(
structure.composition.reduced_formula, name), **kwargs)
"""
override_default_vasp_params = override_default_vasp_params or {}
vasp_input_set = vasp_input_set or MPRelaxSet(
structure, force_gamma=force_gamma, **override_default_vasp_params)
t = []
if prev_calc_loc:
additional_files = kwargs.get("additional_files", [])
if "additional_files" in kwargs.keys():
del kwargs["additional_files"]
t.append(CopyVaspOutputs(calc_loc=prev_calc_loc, contcar_to_poscar=True, additional_files=additional_files))
t.append(WriteVaspFromIOSet(structure=structure,
vasp_input_set=vasp_input_set))
if previous_structure:
t.append(PreviousStructureTask())
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, job_type=job_type,
max_force_threshold=max_force_threshold,
ediffg=ediffg,
auto_npar=auto_npar,
half_kpts_first_relax=half_kpts_first_relax,
handler_group=handler_group))
t.append(PassCalcLocs(name=name))
t.append(SaveStructureTask())
if insert_db:
t.append(VaspToDb(db_file=db_file, additional_fields={"task_label": name}))
name = f'{structure.formula.replace(" ", "")}-{name}'
super(OptimizeFW, self).__init__(t, parents=parents, name=name, **kwargs)
copy_vasp_outputs (bool): Whether to copy outputs from previous run. Defaults to True.
db_file (string): Path to file specifying db credentials.
parents (Firework): Parents of this particular Firework. FW or list of FWS.
\*\*kwargs: Other kwargs that are passed to Firework.__init__.
"""
override_default_vasp_params = override_default_vasp_params or {}
vasp_input_set = vasp_input_set or MPMDSet(structure, start_temp=start_temp,
end_temp=end_temp, nsteps=nsteps,
**override_default_vasp_params)
t = []
t.append(WriteVaspFromIOSet(structure=structure, vasp_input_set=vasp_input_set))
if previous_structure:
t.append(PreviousStructureTask())
t.append(RunVaspCustodian(vasp_cmd=vasp_cmd, gamma_vasp_cmd=">>gamma_vasp_cmd<<",
handler_group="md", wall_time=wall_time))
t.append(PassCalcLocs(name=name))
if save_structure:
t.append(SaveStructureTask())
name = f'{structure.formula.replace(" ", "")}-{name}'
if insert_db:
t.append(VaspMDToDb(db_file=db_file, additional_fields={"task_label": name},
defuse_unsuccessful=False, md_structures=True))
super(MDFW, self).__init__(t, parents=parents, name=name, **kwargs)