def use_fake_vasp_workshop(workflow): """ Wrapper around atomate's use_fake_vasp that will use designated directories in the workshop data store for the fake vasp in the workshop. Args: """ if workflow.name == "Si:elastic constants": runs_dir = os.path.join(module, "fake_vasp", "Si_elastic_tensor") config = { "Si-elastic deformation 0": os.path.join(runs_dir, "0"), "Si-elastic deformation 1": os.path.join(runs_dir, "1"), } return use_fake_vasp(workflow, config) elif "Al" in workflow.name or "Cr" in workflow.name: # statements of each structure struct_start = workflow.fws[0].tasks[0]["structure"] subdir_name = f"{str(struct_start.composition).replace(' ', '')}_{struct_start.lattice.matrix[0][0]:0.2f}" fw_name = ( f"{str(struct_start.composition.reduced_formula)}-structure optimization" ) # the firework will always have the same name runs_dir = os.path.join(module, "fake_vasp", "Al_Cr") config = {fw_name: os.path.join(runs_dir, subdir_name)} return use_fake_vasp(workflow, config) else: raise ValueError("Workflow {} not found".format(workflow.name))
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self.get_task_collection().find_one() self._check_run(d, mode="structure optimization") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_trackers(self): # add the workflow structure = self.struct_si my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_trackers(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp, fworker=_fworker) for x in self.lp.get_tracker_data(1): for t in x["trackers"]: self.assertGreater(len(t.content.split("\n")), 20) wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def _single_vasp_lobster(self, delete_wavecars=False, user_supplied_basis=None, fake=True): # add the workflow structure = self.struct_si my_wf = get_wf_lobster(structure=structure, c={ "vasp_cmd": VASP_CMD, "DB_FILE": None }, user_kpoints_settings={"grid_density": 100}, delete_all_wavecars=delete_wavecars, user_supplied_basis=user_supplied_basis) if fake: my_wf = use_fake_vasp(my_wf, refs_dirs_si_vasp) my_wf = use_fake_lobster(my_wf, refs_dirs_si_lobster) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) fw = self.lp.get_fw_by_id(fw_id=1) with open(os.path.join(fw.launches[-1].launch_dir, "task_lobster.json")) as f: d = json.load(f) self._check_run(d, mode="lobsternormal", database=False) wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def use_fake_vasp_workshop(workflow): """ Wrapper around atomate's use_fake_vasp that will use designated directories in the workshop data store for the fake vasp in the workshop. Args: """ runs = { "Si-structure optimization": fake_vasp_dir / "Si_structure_opt", "Si-static": fake_vasp_dir / "Si_static", "Si-nscf uniform": fake_vasp_dir / "Si_nscf_line", "Si-nscf line": fake_vasp_dir / "Si_nscf_uniform", "Si-elastic deformation 0": fake_vasp_dir / "Si_elastic_tensor" / "0", "Si-elastic deformation 1": fake_vasp_dir / "Si_elastic_tensor" / "1", } return use_fake_vasp( workflow, runs, check_incar=False, check_kpoints=False, check_poscar=False, check_potcar=False, clear_inputs=False, )
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath( os.path.join(ref_dir, "ferroelectric_wf")) bto_ref_dirs = { "_polar_relaxation": os.path.join(reference_dir, "polar_relaxation"), "_polar_static": os.path.join(reference_dir, "polar_static"), "_polar_polarization": os.path.join(reference_dir, "polar_polarization"), "_nonpolar_relaxation": os.path.join(reference_dir, "nonpolar_relaxation"), "_nonpolar_static": os.path.join(reference_dir, "nonpolar_static"), "_nonpolar_polarization": os.path.join(reference_dir, "nonpolar_polarization"), "_interpolation_1_static": os.path.join(reference_dir, "interpolation_1_static"), "_interpolation_1_polarization": os.path.join(reference_dir, "interpolation_1_polarization") } # Add test with for analysis? # Which params_to_check? return use_fake_vasp(wf, bto_ref_dirs, params_to_check=["ENCUT", "LWAVE"])
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) # add an msonable object to additional fields my_wf.fws[0].tasks[-1]['additional_fields'].update( {"test_additional_field": self.struct_si}) self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self.get_task_collection().find_one() self._check_run(d, mode="structure optimization") self._check_run(d, mode="additional field") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def get_simulated_wf(wf): f_dir = ref_dir / "ferroelectric_wf/scratch" bto_ref_dirs = { "_polar_relaxation": f_dir / "polar_relaxation", "_polar_static": f_dir / "polar_static", "_polar_polarization": f_dir / "polar_polarization", "_nonpolar_relaxation": f_dir / "nonpolar_relaxation", "_nonpolar_static": f_dir / "nonpolar_static", "_nonpolar_polarization": f_dir / "nonpolar_polarization", "_interpolation_1_static": f_dir / "interpolation_1_static", "_interpolation_1_polarization": f_dir / "interpolation_1_polarization", } wf = use_potcar_spec(wf, vasp_to_db_kwargs={ "store_volumetric_data": [], "parse_bader": False }) wf = use_fake_vasp(wf, bto_ref_dirs, params_to_check=["ENCUT", "LWAVE"], check_potcar=False) return wf
def test_bandgap_check_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files my_wf = add_bandgap_check(my_wf, check_bandgap_params={"max_gap": 0.1}, fw_name_constraint="structure optimization") self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # structure optimization should be completed self.assertEqual(self.lp.fireworks.find_one( {"name": "Si-structure optimization"}, {"state": 1})["state"], "COMPLETED") self.assertEqual(self.lp.fireworks.find_one( {"name": "Si-static"}, {"state": 1})["state"], "DEFUSED")
def test_chgcar_db_read(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "static_only.yaml", vis=MPStaticSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) # set the flags for storing charge densties my_wf.fws[0].tasks[-1]["parse_chgcar"] = True my_wf.fws[0].tasks[-1]["parse_aeccar"] = True self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self.get_task_collection().find_one() self._check_run(d, mode="static") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()])) chgcar_fs_id = d["calcs_reversed"][0]["chgcar_fs_id"] accar0_fs_id = d["calcs_reversed"][0]["aeccar0_fs_id"] accar2_fs_id = d["calcs_reversed"][0]["aeccar2_fs_id"] self.assertTrue(bool(chgcar_fs_id)) self.assertTrue(bool(accar0_fs_id)) self.assertTrue(bool(accar2_fs_id))
def test_bandgap_check_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files my_wf = add_bandgap_check(my_wf, check_bandgap_params={"max_gap": 0.1}, fw_name_constraint="structure optimization") self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=_fworker) # structure optimization should be completed self.assertEqual( self.lp.fireworks.find_one({"name": "Si-structure optimization"}, {"state": 1})["state"], "COMPLETED") self.assertEqual( self.lp.fireworks.find_one({"name": "Si-static"}, {"state": 1})["state"], "DEFUSED")
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) # add an msonable object to additional fields my_wf.fws[0].tasks[-1]['additional_fields'].update( {"test_additional_field": self.struct_si}) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp, fworker=_fworker) d = self.get_task_collection().find_one() self._check_run(d, mode="structure optimization") self._check_run(d, mode="additional field") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def vasp_emulator(wf, ref_dir="/wkshp_shared/workshop_ref_files", calc="electronic_structure"): reference_dir = os.path.join(os.path.expanduser(ref_dir), calc) params_to_check = None if calc == "electronic_structure": ref_dirs = { "structure optimization": os.path.join(reference_dir, "Si_structure_optimization"), "static": os.path.join(reference_dir, "Si_static"), "nscf uniform": os.path.join(reference_dir, "Si_nscf_uniform"), "nscf line": os.path.join(reference_dir, "Si_nscf_line") } elif calc == "elastic_tensor": ref_dirs = { "structure optimization": os.path.join(reference_dir, "1"), "elastic deformation 0": os.path.join(reference_dir, "7"), "elastic deformation 1": os.path.join(reference_dir, "6"), "elastic deformation 2": os.path.join(reference_dir, "5"), "elastic deformation 3": os.path.join(reference_dir, "4"), "elastic deformation 4": os.path.join(reference_dir, "3"), "elastic deformation 5": os.path.join(reference_dir, "2") } params_to_check=["ENCUT"] else: raise ValueError("wrong 'calc' option") return use_fake_vasp(wf, ref_dirs, params_to_check=params_to_check)
def _single_lobster_db_insertion(self, fake=True): structure = self.struct_mp my_wf = get_wf_lobster_test_basis( structure=structure, c={ "vasp_cmd": VASP_CMD, "DB_FILE": DB_FILE }, user_kpoints_settings={"grid_density": 100}, delete_all_wavecars=False) if fake: my_wf = use_fake_vasp(my_wf, ref_dirs=refs_dirs_complex_vasp) my_wf = use_fake_lobster(my_wf, ref_dirs=refs_dirs_complex_lobster) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) d = self.get_task_collection(coll_name="lobster").find_one( filter={"basis_id": 1}) self._check_run(d, mode="lobsternormal") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def _single_lobster_db_insertion(self, delete_wavecars=False, user_supplied_basis=None, fake=True): structure = self.struct_si my_wf = get_wf_lobster(structure=structure, c={ "vasp_cmd": VASP_CMD, "DB_FILE": DB_FILE }, user_kpoints_settings={"grid_density": 100}, delete_all_wavecars=delete_wavecars, user_supplied_basis=user_supplied_basis, additional_outputs=["ICOOPLIST.lobster"]) if fake: my_wf = use_fake_vasp(my_wf, refs_dirs_si_vasp) my_wf = use_fake_lobster(my_wf, refs_dirs_si_lobster) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) d = self.get_task_collection(coll_name="lobster").find_one() if delete_wavecars: self._check_run(d, mode="lobsternormal_delete_wavecars") else: self._check_run(d, mode="lobsternormal") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "adsorbate_wf")) ir_ref_dirs = {"Ir-structure optimization": os.path.join(reference_dir, "1"), "Ir-Ir_(1, 0, 0) slab optimization": os.path.join(reference_dir, "2"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 0": os.path.join(reference_dir, "3"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 1": os.path.join(reference_dir, "4"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 2": os.path.join(reference_dir, "5")} return use_fake_vasp(wf, ir_ref_dirs, params_to_check=["ENCUT", "ISIF", "IBRION"])
def _simulate_vasprun(self, wf): """ Run Fake Vasp for testing purpose.""" test_dir = os.path.abspath(os.path.join(ref_dir, "neb_wf")) neb_ref_dirs = {"parent": os.path.join(test_dir, "1"), "ep0": os.path.join(test_dir, "2"), "ep1": os.path.join(test_dir, "3"), "neb1": os.path.join(test_dir, "4"), "neb2": os.path.join(test_dir, "5")} return use_fake_vasp(wf, neb_ref_dirs, params_to_check=["ENCUT"])
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "adsorbate_wf")) ir_ref_dirs = {"Ir-structure optimization": os.path.join(reference_dir, "1"), "Ir-Ir_(1, 0, 0) slab optimization": os.path.join(reference_dir, "2"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 0": os.path.join(reference_dir, "3"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 1": os.path.join(reference_dir, "4"), "Ir-H1-Ir_(1, 0, 0) adsorbate optimization 2": os.path.join(reference_dir, "5")} return use_fake_vasp(wf, ir_ref_dirs, params_to_check=["ENCUT", "ISIF"])
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "raman_wf")) si_ref_dirs = {"structure optimization": os.path.join(reference_dir, "1"), "static dielectric": os.path.join(reference_dir, "2"), "raman_0_-0.005": os.path.join(reference_dir, "6"), "raman_0_0.005": os.path.join(reference_dir, "5"), "raman_1_-0.005": os.path.join(reference_dir, "4"), "raman_1_0.005": os.path.join(reference_dir, "3")} return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "elastic_wf")) si_ref_dirs = {"structure optimization": os.path.join(reference_dir, "1"), "elastic deformation 0": os.path.join(reference_dir, "7"), "elastic deformation 1": os.path.join(reference_dir, "6"), "elastic deformation 2": os.path.join(reference_dir, "5"), "elastic deformation 3": os.path.join(reference_dir, "4"), "elastic deformation 4": os.path.join(reference_dir, "3"), "elastic deformation 5": os.path.join(reference_dir, "2")} return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "raman_wf")) si_ref_dirs = { "structure optimization": os.path.join(reference_dir, "1"), "phonon static dielectric": os.path.join(reference_dir, "2"), "raman_0_-0.005 static dielectric": os.path.join(reference_dir, "6"), "raman_0_0.005 static dielectric": os.path.join(reference_dir, "5"), "raman_1_-0.005 static dielectric": os.path.join(reference_dir, "4"), "raman_1_0.005 static dielectric": os.path.join(reference_dir, "3"), } return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
def get_simulated_wf(wf): dirs = { "parent": wf_dir / "1", "ep0": wf_dir / "2", "ep1": wf_dir / "3", "neb1": wf_dir / "4", "neb2": wf_dir / "5", } wf = use_potcar_spec(wf) wf = use_fake_vasp(wf, dirs, params_to_check=["ENCUT"], check_potcar=False) return wf
def _simulate_vasprun(self, wf): ref_dirs = { "structure optimization": os.path.join(reference_dir, "structure_optimization"), "cs tensor": os.path.join(reference_dir, "cs"), "efg tensor": os.path.join(reference_dir, "efg") } if not VASP_CMD: wf = use_fake_vasp(wf, ref_dirs) else: wf = use_custodian(wf) return wf
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(os.path.join(ref_dir, "ferroelectric_wf")) bto_ref_dirs = {"_polar_relaxation": os.path.join(reference_dir, "polar_relaxation"), "_polar_static": os.path.join(reference_dir, "polar_static"), "_polar_polarization": os.path.join(reference_dir, "polar_polarization"), "_nonpolar_relaxation": os.path.join(reference_dir, "nonpolar_relaxation"), "_nonpolar_static": os.path.join(reference_dir, "nonpolar_static"), "_nonpolar_polarization": os.path.join(reference_dir, "nonpolar_polarization"), "_interpolation_1_static": os.path.join(reference_dir, "interpolation_1_static"), "_interpolation_1_polarization": os.path.join(reference_dir, "interpolation_1_polarization")} # Add test with for analysis? # Which params_to_check? return use_fake_vasp(wf, bto_ref_dirs, params_to_check=["ENCUT", "LWAVE"])
def _simulate_vasprun(self, wf): no_vasp_ref_dirs = {} fake_vasp_ref_dirs = {} for i in range(2, self.ndeformations+2): if os.path.exists(os.path.join(reference_dir, str(i), "inputs")): if not VASP_CMD: fake_vasp_ref_dirs["bulk_modulus deformation {}".format(i-2)] = os.path.join(reference_dir, str(i)) else: no_vasp_ref_dirs["bulk_modulus deformation {}".format(i-2)] = os.path.join(self.scratch_dir, str(i)) fake_vasp_ref_dirs["structure optimization"] = os.path.join(reference_dir, "1") new_wf = use_no_vasp(wf, no_vasp_ref_dirs) return use_fake_vasp(new_wf, fake_vasp_ref_dirs, params_to_check=["ENCUT"])
def elastic_simulator(wf, ref_dir="~/workshop_ref_files/elastic_tensor"): reference_dir = os.path.expanduser(ref_dir) si_ref_dirs = { "structure optimization": os.path.join(reference_dir, "1"), "elastic deformation 0": os.path.join(reference_dir, "7"), "elastic deformation 1": os.path.join(reference_dir, "6"), "elastic deformation 2": os.path.join(reference_dir, "5"), "elastic deformation 3": os.path.join(reference_dir, "4"), "elastic deformation 4": os.path.join(reference_dir, "3"), "elastic deformation 5": os.path.join(reference_dir, "2") } return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
def test_bandstructure_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={ "vasp_cmd": VASP_CMD, "db_file": ">>db_file<<" }) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire( self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # make sure the structure relaxation ran OK d = self.get_task_collection().find_one( {"task_label": "structure optimization"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="structure optimization") # make sure the static run ran OK d = self.get_task_collection().find_one({"task_label": "static"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="static") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf uniform"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf uniform") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf line"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf line") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def electronic_structure_simulator( wf, ref_dir="~/workshop_ref_files/electronic_structure"): reference_dir = os.path.expanduser(ref_dir) ref_dirs_si = { "structure optimization": os.path.join(reference_dir, "Si_structure_optimization"), "static": os.path.join(reference_dir, "Si_static"), "nscf uniform": os.path.join(reference_dir, "Si_nscf_uniform"), "nscf line": os.path.join(reference_dir, "Si_nscf_line") } return use_fake_vasp(wf, ref_dirs_si)
def use_fake_vasp_workshop(workflow): """ Wrapper around atomate's use_fake_vasp that will use designated directories in the workshop data store for the fake vasp in the workshop. Args: """ if workflow.name == "Si:elastic constants": runs_dir = os.path.join(module, "fake_vasp", "Si_elastic_tensor") config = { "Si-elastic deformation 0": os.path.join(runs_dir, "1"), "Si-elastic deformation 1": os.path.join(runs_dir, "2") } return use_fake_vasp(workflow, config) else: raise ValueError("Workflow {} not found".format(workflow.name))
def _simulate_vasprun(self, wf): reference_dir = os.path.abspath(self.tf_loc) if len(wf.fws) > 6: si_ref_dirs = { "structure optimization": os.path.join(reference_dir, "1"), "elastic deformation 0": os.path.join(reference_dir, "7"), "elastic deformation 1": os.path.join(reference_dir, "6"), "elastic deformation 2": os.path.join(reference_dir, "5"), "elastic deformation 3": os.path.join(reference_dir, "4"), "elastic deformation 4": os.path.join(reference_dir, "3"), "elastic deformation 5": os.path.join(reference_dir, "2") } elif len(wf.fws) == 3: si_ref_dirs = { "elastic deformation 0": os.path.join(reference_dir, "7"), "elastic deformation 1": os.path.join(reference_dir, "4") } return use_fake_vasp(wf, si_ref_dirs, params_to_check=["ENCUT"])
def _run_scan_relax(self, wf, dir_name): if not VASP_CMD: wf = use_fake_vasp(wf, { "SCAN structure optimization": os.path.join(reference_dir, dir_name) }, check_kpoints=False, check_potcar=False, clear_inputs=False, check_incar=False) else: wf = use_custodian(wf) wf = use_potcar_spec(wf) self.lp.add_wf(wf) # run the workflow rapidfire(self.lp, fworker=_fworker)
def test_single_Vasp_dbinsertion(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) d = self._get_task_collection().find_one() self._check_run(d, mode="structure optimization")
def test_single_Vasp(self): # add the workflow structure = self.struct_si my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp, fworker=_fworker) d = self.get_task_collection().find_one({"task_label": "structure optimization"}) self._check_run(d, mode="structure optimization") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_single_Vasp(self): # add the workflow structure = self.struct_si my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) fw = self.lp.get_fw_by_id(1) with open(os.path.join(fw.launches[-1].launch_dir, "task.json")) as f: d = json.load(f) self._check_run(d, mode="structure optimization")
def test_trackers(self): # add the workflow structure = self.struct_si my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_trackers(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) for x in self.lp.get_tracker_data(1): for t in x["trackers"]: self.assertGreater(len(t.content.split("\n")), 20)
def test_bandstructure_Vasp(self): # add the workflow structure = self.struct_si # instructs to use db_file set by FWorker, see env_chk my_wf = get_wf(structure, "bandstructure.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD, "db_file": ">>db_file<<"}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) my_wf = add_namefile(my_wf) # add a slug of fw-name to output files self.lp.add_wf(my_wf) # run the workflow # set the db_file variable rapidfire(self.lp, fworker=FWorker(env={"db_file": os.path.join(db_dir, "db.json")})) # make sure the structure relaxation ran OK d = self.get_task_collection().find_one({"task_label": "structure optimization"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="structure optimization") # make sure the static run ran OK d = self.get_task_collection().find_one({"task_label": "static"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="static") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf uniform"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf uniform") # make sure the uniform run ran OK d = self.get_task_collection().find_one({"task_label": "nscf line"}, sort=[("_id", DESCENDING)]) self._check_run(d, mode="nscf line") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def test_single_Vasp(self): # add the workflow structure = self.struct_si my_wf = get_wf(structure, "optimize_only.yaml", vis=MPRelaxSet(structure, force_gamma=True), common_params={"vasp_cmd": VASP_CMD}) if not VASP_CMD: my_wf = use_fake_vasp(my_wf, ref_dirs_si) else: my_wf = use_custodian(my_wf) self.lp.add_wf(my_wf) # run the workflow rapidfire(self.lp) fw = self.lp.get_fw_by_id(1) with open(os.path.join(fw.launches[-1].launch_dir, "task.json")) as f: d = json.load(f) self._check_run(d, mode="structure optimization") wf = self.lp.get_wf_by_fw_id(1) self.assertTrue(all([s == 'COMPLETED' for s in wf.fw_states.values()]))
def _run_scan_relax(self, wf, formula): if not VASP_CMD: wf = use_fake_vasp(wf, { "PBEsol structure optimization": os.path.join(reference_dir, "PBESol_pre_opt_for_SCAN_{}".format(formula)), "R2SCAN structure optimization": os.path.join(reference_dir, "SCAN_structure_optimization_{}".format(formula)) }, check_kpoints=False, check_potcar=False, clear_inputs=False, check_incar=False) else: wf = use_custodian(wf) wf = use_potcar_spec(wf) fw_ids = self.lp.add_wf(wf) # run the workflow rapidfire(self.lp, fworker=_fworker) return fw_ids
def setUp(self): super().setUp() input_output_dirs = ref_dir / "insertion_wf" names = os.walk(input_output_dirs).__next__()[1] calc_dirs = {n_: input_output_dirs / n_ for n_ in names} base_struct = Structure.from_file(wf_dir / "YPO4-static/inputs/POSCAR") sm = StructureMatcher(ltol=0.6, stol=0.6, angle_tol=9) # Run the workflow with fake vasp wf = get_ion_insertion_wf( structure=base_struct, structure_matcher=sm, working_ion="Mg", volumetric_data_type="AECCAR", db_file=db_dir / "db.json", vasp_powerups=[ { "powerup_name": "add_modify_incar", "kwargs": {"modify_incar_params": {"incar_update": {"KPAR": 8}}}, }, { "powerup_name": "use_fake_vasp", "kwargs": { "ref_dirs": calc_dirs, "check_incar": False, "check_kpoints": False, "check_poscar": False, "check_potcar": False, }, }, {"powerup_name": "use_potcar_spec", "kwargs": {}}, ], optimizefw_kwargs={"ediffg": -0.05}, ) wf_stop_early = get_ion_insertion_wf( structure=base_struct, structure_matcher=sm, working_ion="Mg", volumetric_data_type="AECCAR", db_file=db_dir / "db.json", max_inserted_atoms=1, vasp_powerups=[ { "powerup_name": "add_modify_incar", "kwargs": {"modify_incar_params": {"incar_update": {"KPAR": 8}}}, }, { "powerup_name": "use_fake_vasp", "kwargs": { "ref_dirs": calc_dirs, "check_incar": False, "check_kpoints": False, "check_poscar": False, "check_potcar": False, }, }, {"powerup_name": "use_potcar_spec", "kwargs": {}}, ], optimizefw_kwargs={"ediffg": -0.05}, ) wf = use_fake_vasp( wf, calc_dirs, check_incar=False, check_kpoints=False, check_poscar=False, check_potcar=False, ) wf = use_potcar_spec(wf) self.wf = wf wf_stop_early = use_fake_vasp( wf_stop_early, calc_dirs, check_incar=False, check_kpoints=False, check_poscar=False, check_potcar=False, ) wf_stop_early = use_potcar_spec(wf_stop_early) self.wf_stop_early = wf_stop_early