def test_get_endpoint_dist(self): ep0 = Structure.from_file(get_path("POSCAR_ep0", dirname="io_files")) ep1 = Structure.from_file(get_path("POSCAR_ep1", dirname="io_files")) distances = get_endpoint_dist(ep0, ep1) self.assertAlmostEqual(max(distances), 6.3461081051543893, 7) self.assertEqual(min(distances), 0.0)
def run_task(self, fw_spec): label = self["label"] assert label in ["parent", "ep0", "ep1"] or "neb" in label, "Unknown label!" d_img = float(self.get("d_img", 0.7)) # Angstrom wf_name = fw_spec["wf_name"] src_dir = os.path.abspath(".") dest_dir = os.path.join(fw_spec["_fw_env"]["run_dest_root"], wf_name, label) shutil.copytree(src_dir, dest_dir) # Update fw_spec based on the type of calculations. if "neb" in label: # Update all relaxed images. subs = glob.glob("[0-2][0-9]") nimages = len(subs) concar_list = ["{:02}/CONTCAR".format(i) for i in range(nimages)[1:-1]] images = [Structure.from_file(contcar) for contcar in concar_list] # Update the two ending "images". images.insert(0, Structure.from_file("00/POSCAR")) images.append(Structure.from_file("{:02}/POSCAR".format(nimages - 1))) images = [s.as_dict() for s in images] neb = fw_spec.get("neb") neb.append(images) update_spec = {"neb": neb, "_queueadapter": {"nnodes": str(len(images) - 2), "nodes": str(len(images) - 2)}} # Use neb walltime if it is in fw_spec if fw_spec["neb_walltime"] is not None: update_spec["_queueadapter"].update({"walltime": fw_spec.get("neb_walltime")}) elif label in ["ep0", "ep1"]: # Update relaxed endpoint structures. file = glob.glob("CONTCAR*")[0] ep = Structure.from_file(file, False) # One endpoint if fw_spec.get("incar_images"): # "incar_images": pre-defined image number. update_spec = {label: ep.as_dict(), "_queueadapter": {"nnodes": fw_spec["incar_images"], "nodes": fw_spec["incar_images"]}} else: # Calculate number of images if "IMAGES" tag is not provided. index = int(label[-1]) ep_1_dict = fw_spec.get("ep{}".format(1 - index)) # Another endpoint try: ep_1 = Structure.from_dict(ep_1_dict) except: ep_1 = ep_1_dict max_dist = max(get_endpoint_dist(ep, ep_1)) nimages = round(max_dist / d_img) or 1 update_spec = {label: ep, "_queueadapter": {"nnodes": int(nimages), "nodes": int(nimages)}} # Use neb walltime if it is in fw_spec if fw_spec["neb_walltime"] is not None: update_spec["_queueadapter"].update({"walltime": fw_spec.get("neb_walltime")}) else: # label == "parent" f = glob.glob("CONTCAR*")[0] s = Structure.from_file(f, False) ep0, ep1 = get_endpoints_from_index(s, fw_spec["site_indices"]) update_spec = {"parent": s.as_dict(), "ep0": ep0.as_dict(), "ep1": ep1.as_dict()} # Clear current directory. for d in os.listdir(src_dir): try: os.remove(os.path.join(src_dir, d)) except: shutil.rmtree(os.path.join(src_dir, d)) return FWAction(update_spec=update_spec)
def run_task(self, fw_spec): label = self["label"] assert label in ["parent", "ep0", "ep1" ] or "neb" in label, "Unknown label!" d_img = float(self.get("d_img", 0.7)) # Angstrom wf_name = fw_spec["wf_name"] src_dir = os.path.abspath(".") dest_dir = os.path.join(fw_spec["_fw_env"]["run_dest_root"], wf_name, label) shutil.copytree(src_dir, dest_dir) # Update fw_spec based on the type of calculations. if "neb" in label: # Update all relaxed images. subs = glob.glob("[0-2][0-9]") nimages = len(subs) concar_list = [ "{:02}/CONTCAR".format(i) for i in range(nimages)[1:-1] ] images = [Structure.from_file(contcar) for contcar in concar_list] # Update the two ending "images". images.insert(0, Structure.from_file("00/POSCAR")) images.append( Structure.from_file("{:02}/POSCAR".format(nimages - 1))) images = [s.as_dict() for s in images] neb = fw_spec.get("neb") neb.append(images) update_spec = { "neb": neb, "_queueadapter": { "nnodes": str(len(images) - 2), "nodes": str(len(images) - 2) } } # Use neb walltime if it is in fw_spec if fw_spec["neb_walltime"] is not None: update_spec["_queueadapter"].update( {"walltime": fw_spec.get("neb_walltime")}) elif label in ["ep0", "ep1"]: # Update relaxed endpoint structures. file = glob.glob("CONTCAR*")[0] ep = Structure.from_file(file, False) # One endpoint if fw_spec.get("incar_images" ): # "incar_images": pre-defined image number. update_spec = { label: ep.as_dict(), "_queueadapter": { "nnodes": fw_spec["incar_images"], "nodes": fw_spec["incar_images"] } } else: # Calculate number of images if "IMAGES" tag is not provided. index = int(label[-1]) ep_1_dict = fw_spec.get( "ep{}".format(1 - index)) # Another endpoint try: ep_1 = Structure.from_dict(ep_1_dict) except: ep_1 = ep_1_dict max_dist = max(get_endpoint_dist(ep, ep_1)) nimages = round(max_dist / d_img) or 1 update_spec = { label: ep, "_queueadapter": { "nnodes": int(nimages), "nodes": int(nimages) } } # Use neb walltime if it is in fw_spec if fw_spec["neb_walltime"] is not None: update_spec["_queueadapter"].update( {"walltime": fw_spec.get("neb_walltime")}) else: # label == "parent" f = glob.glob("CONTCAR*")[0] s = Structure.from_file(f, False) ep0, ep1 = get_endpoints_from_index(s, fw_spec["site_indices"]) update_spec = { "parent": s.as_dict(), "ep0": ep0.as_dict(), "ep1": ep1.as_dict() } # Clear current directory. for d in os.listdir(src_dir): try: os.remove(os.path.join(src_dir, d)) except: shutil.rmtree(os.path.join(src_dir, d)) return FWAction(update_spec=update_spec)