def _verify_inputs(self): user_lobsterin = Lobsterin.from_file(os.path.join(os.getcwd(), "lobsterin")) # Check lobsterin if self.get("check_lobsterin", True): ref_lobsterin = Lobsterin.from_file( os.path.join(self["ref_dir"], "inputs", "lobsterin") ) params_to_check = self.get("params_to_check", []) for p in params_to_check: if user_lobsterin.get(p, None) != ref_lobsterin.get(p, None): raise ValueError("lobsterin value of {} is inconsistent!".format(p)) logger.info("RunLobsterFake: verified inputs successfully")
def setUpClass(cls): cls.ref_lobsterin = Lobsterin.from_file( os.path.join( module_dir, "./../../test_files", "lobster", "Lobsterinputs", "lobsterin", )) cls.ref_lobsterin2 = Lobsterin.from_file( os.path.join(module_dir, "./../../test_files", "lobster", "lobsterins", "lobsterin2")) cls.vasp_dir = os.path.join(module_dir, "./../../test_files", "lobster", "VASP_calc_for_Lobster")
def test_ioset_explicit(self): for fn in ["POSCAR.gz", "POTCAR.gz", "INCAR.gz"]: shutil.copy2(os.path.join(self.vasp_dir, fn), ".") ft = WriteLobsterinputfromIO( poscar_path="POSCAR.gz", potcar_path="POTCAR.gz", incar_path="INCAR.gz", option="standard", ) ft = load_object(ft.to_dict()) # simulate database insertion ft.run_task({}) self.assertEqual(Lobsterin.from_file("lobsterin"), self.ref_lobsterin)
def test_ioset_settings(self): for fn in ["POSCAR.gz", "POTCAR.gz", "INCAR.gz"]: shutil.copy2(os.path.join(self.vasp_dir, fn), ".") # user supplied lobsterin inputs ft = WriteLobsterinputfromIO( poscar_path="POSCAR.gz", potcar_path="POTCAR.gz", incar_path="INCAR.gz", option="standard", user_lobsterin_settings={"COHPEndEnergy": 10.0}, ) ft = load_object(ft.to_dict()) # simulate database insertion ft.run_task({}) self.assertEqual(Lobsterin.from_file("lobsterin"), self.ref_lobsterin2)
def run_task(self, fw_spec): vasp_calc_dir = self.get("calc_dir", None) vasp_calc_loc = ( get_calc_loc(self["calc_loc"], fw_spec["calc_locs"]) if self.get("calc_loc") else {} ) # get the directory that contains the Lobster dir to parse current_dir = os.getcwd() # parse the Lobster directory logger.info("PARSING DIRECTORY: {}".format(current_dir)) task_doc = {} struct = Structure.from_file(self._find_gz_file("POSCAR")) Lobsterout_here = Lobsterout(self._find_gz_file("lobsterout")) task_doc["output"] = Lobsterout_here.get_doc() Lobsterin_here = Lobsterin.from_file(self._find_gz_file("lobsterin")) task_doc["input"] = Lobsterin_here try: Lobsterin_orig = Lobsterin.from_file(self._find_gz_file("lobsterin.orig")) task_doc["orig_input"] = Lobsterin_orig except ValueError: pass # save custodian details if os.path.exists("custodian.json"): task_doc["custodian"] = loadfn("custodian.json") additional_fields = self.get("additional_fields", {}) if additional_fields: task_doc.update(additional_fields) task_doc.update(get_meta_from_structure(struct)) if vasp_calc_dir != None: task_doc["vasp_dir_name"] = vasp_calc_dir else: task_doc["vasp_dir_name"] = vasp_calc_loc["path"] task_doc["dir_name"] = current_dir # Check for additional keys to set based on the fw_spec if self.get("fw_spec_field"): task_doc.update(fw_spec[self.get("fw_spec_field")]) task_doc["state"] = "successful" task_doc = jsanitize(task_doc) # get the database connection db_file = env_chk(self.get("db_file"), fw_spec) # db insertion or taskdoc dump if not db_file: with open("task_lobster.json", "w") as f: f.write(json.dumps(task_doc, default=DATETIME_HANDLER)) else: db = VaspCalcDb.from_db_file(db_file, admin=True) db.collection = db.db["lobster"] additional_outputs = self.get("additional_outputs", None) if additional_outputs: for filename in additional_outputs: fs_id = None if os.path.isfile(filename): fs_id = put_file_in_gridfs( filename, db, collection_name="lobster_files", compress=True ) elif os.path.isfile(filename + ".gz"): fs_id = put_file_in_gridfs( filename + ".gz", db, collection_name="lobster_files", compress=False, compression_type="zlib", ) if fs_id: key_name = filename.split(".")[0].lower() + "_id" task_doc[key_name] = fs_id db.insert(task_doc) return FWAction()