Skip to content

Commit

Permalink
minor changes for function and argument names
Browse files Browse the repository at this point in the history
  • Loading branch information
HanmeiTang committed Mar 17, 2017
1 parent 9c3c9d8 commit 33ae84c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 73 deletions.
26 changes: 14 additions & 12 deletions atomate/vasp/fireworks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

from atomate.common.firetasks.glue_tasks import PassCalcLocs
from atomate.vasp.firetasks.glue_tasks import CopyVaspOutputs, PassEpsilonTask, \
PassNormalmodesTask, TransferNEBTask
PassNormalmodesTask
from atomate.vasp.firetasks.neb_tasks import TransferNEBTask
from atomate.vasp.firetasks.parse_outputs import VaspToDbTask, BoltztrapToDBTask
from atomate.vasp.firetasks.run_calc import RunVaspCustodian, RunBoltztrap
from atomate.vasp.firetasks.write_inputs import *
from atomate.vasp.firetasks.neb_tasks import WriteNEBFromImages, WriteNEBFromEndpoints


class OptimizeFW(Firework):
Expand Down Expand Up @@ -389,7 +391,7 @@ def __init__(self, spec, label, vasp_input_set=None, user_incar_settings=None,
"""
Args:
spec (dict): Specification of the job to run.
label (str): "ini" (parent), "ep0" or "ep1", st_label will be used in PassCalcLocs name.
label (str): "init" (parent), "ep0" or "ep1", st_label will be used in PassCalcLocs name.
vasp_input_set (VaspInputSet): Input set to use.
user_incar_settings (dict): Additional INCAR settings.
vasp_cmd (str): Command to run vasp.
Expand All @@ -399,9 +401,9 @@ def __init__(self, spec, label, vasp_input_set=None, user_incar_settings=None,
"""
# Get structure from spec
cust_args = cust_args or {}
assert label in ["ini", "ep0", "ep1"]
if label == "ini":
structure_dict = spec["ini"]
assert label in ["init", "ep0", "ep1"]
if label == "init":
structure_dict = spec["init"]
else: # label in ["ep0", "ep1"]
index = int(label[-1])
structure_dict = spec["eps"][index]
Expand All @@ -411,7 +413,7 @@ def __init__(self, spec, label, vasp_input_set=None, user_incar_settings=None,
if vasp_input_set is None:
incar = user_incar_settings or {}
vasp_input_set = MITRelaxSet(structure, user_incar_settings=incar) \
if label == 'ini' \
if label == 'init' \
else MVLCINEBEndPointSet(structure, user_incar_settings=incar)

write_ep_task = WriteVaspFromIOSet(structure=structure, output_dir=".",
Expand All @@ -436,7 +438,7 @@ class NEBFW(Firework):

# TODO: These tags are not used.... maybe in spec
def __init__(self, spec, neb_label, from_images=True, user_incar_settings=None,
sort_tol=None, image_dist=None, interp_method="linear",
sort_tol=None, dimages=None, interp_method="IDPP",
vasp_cmd=">>vasp_cmd<<", gamma_vasp_cmd=">>gamma_vasp_cmd<<",
cust_args=None, **kwargs):
"""
Expand All @@ -448,10 +450,10 @@ def __init__(self, spec, neb_label, from_images=True, user_incar_settings=None,
user_incar_settings (dict): Additional INCAR settings.
sort_tol (float): Distance tolerance (in Angstrom) used to match the atomic indices
between start and end structures. If it is set 0, then no sorting will be performed.
image_dist (float): distance in Angstrom, used in calculating number of images.
dimages (float): distance in Angstrom, used in calculating number of images.
Default 0.7 Angstrom.
interp_method (str): method to do image interpolation from two endpoints.
Choose from ["linear"], default "linear".
Choose from ["IDPP", "linear"], default "IDPP".
vasp_cmd (str): Command to run vasp using mpi program.
gamma_vasp_cmd (str): Command to run vasp gamma.
cust_args (dict): Other kwargs that are passed to RunVaspCustodian.
Expand All @@ -475,9 +477,9 @@ def __init__(self, spec, neb_label, from_images=True, user_incar_settings=None,
except:
encpoints = structures_dict
write_neb_task = WriteNEBFromEndpoints(endpoints=encpoints,
user_incar_settings=user_incar_settings,
output_dir=output_dir, sort_tol=sort_tol,
image_dist=image_dist, interp_method=interp_method)
user_incar_settings=user_incar_settings,
output_dir=output_dir, sort_tol=sort_tol,
dimages=dimages, interp_method=interp_method)

# Task 2: Run NEB using Custodian
run_neb_task = RunVaspCustodian(vasp_cmd=vasp_cmd, gamma_vasp_cmd=gamma_vasp_cmd,
Expand Down
4 changes: 2 additions & 2 deletions atomate/vasp/powerups.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from atomate.utils.utils import get_meta_from_structure, get_fws_and_tasks, update_wf
from atomate.vasp.firetasks.glue_tasks import CheckStability, CheckBandgap
from atomate.vasp.firetasks.run_calc import RunVaspCustodian, RunVaspDirect, RunVaspFake, \
RunNEBVaspFake
from atomate.vasp.firetasks.run_calc import RunVaspCustodian, RunVaspDirect, RunVaspFake
from atomate.vasp.firetasks.neb_tasks import RunNEBVaspFake
from atomate.vasp.firetasks.write_inputs import ModifyIncar
from atomate.vasp.config import ADD_NAMEFILE, SCRATCH_DIR, ADD_MODIFY_INCAR, GAMMA_VASP_CMD

Expand Down
62 changes: 31 additions & 31 deletions atomate/vasp/workflows/base/neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from fireworks.core.firework import Workflow

from atomate.vasp.fireworks.core import NEBFW, NEBRelaxationFW
from atomate.vasp.firetasks.glue_tasks import TransferNEBTask
from atomate.utils.utils import get_logger

__author__ = "Hanmei Tang, Iek-Heng Chu"
Expand All @@ -24,21 +23,22 @@
"vasp_cmd": ">>vasp_cmd<<",
"gamma_vasp_cmd": ">>gamma_vasp_cmd<<",
"mpi_command": {"command": "mpirun", "np_tag": "-np"},
"ppn": "24",
"ppn": "24", # todo : delete
"db_file": ">>db_file<<",
"_category": "",
"idpp_species": None,
"_queueadapter": {"nnodes": 1},
"source_dir": os.getcwd(),
"dest_dir": os.getcwd(),
"structure": None,
"path_sites": [],
"ini": {},
"init": {},
"eps": [{}, {}],
"neb": [[{}]]
}


def _update_spec_from_inputs(spec=None, wf_name=None, structure=None, ini=None, path_sites=None,
def _update_spec_from_inputs(spec=None, wf_name=None, structure=None, init=None, path_sites=None,
endpoints=None, images=None):
"""
Update spec according to inputs. spec pass complete structure information.
Expand All @@ -48,7 +48,7 @@ def _update_spec_from_inputs(spec=None, wf_name=None, structure=None, ini=None,
wf_name (str): a descriptive name.
structure (dict): perfect cell structure.
path_sites ([int, int]): Indicating pathway site indexes.
ini (dict): perfect cell supercell structure.
init (dict): perfect cell supercell structure.
endpoints ([dict]): list of endpoint structures.
images ([s0_dict, s1_dict, ...]): list of image_dict, including the two endpoints.
"""
Expand All @@ -60,14 +60,14 @@ def _update_spec_from_inputs(spec=None, wf_name=None, structure=None, ini=None,
assert isinstance(structure, dict)
s["structure"] = structure

if ini is not None:
assert isinstance(ini, dict)
s["ini"] = ini
if init is not None:
assert isinstance(init, dict)
s["init"] = init

if path_sites is not None:
assert isinstance(path_sites, list) and len(path_sites) == 2, "path_sites should be a list!"
s["path_sites"] = path_sites
st = structure or ini
st = structure or init
if st is not None:
ep0, ep1 = get_endpoints_from_index(Structure.from_dict(st), path_sites)
endpoints = [ep0.as_dict(), ep1.as_dict()]
Expand All @@ -93,8 +93,7 @@ def _update_spec_from_inputs(spec=None, wf_name=None, structure=None, ini=None,
return s


# TODO: Enable setting using >>my_vasp_cmd<<
def _get_mpi_command(spec, vasp):
def _get_command(spec, vasp):
"""
A convenience method to get neb command using mpi program:
E.g.: 'mpirun -np 48 vasp'
Expand Down Expand Up @@ -122,33 +121,33 @@ def _get_mpi_command(spec, vasp):

def _get_incar(mode, user_incar_settings=None):
"""
Get user_incar_settings for every step (ini, endpoints and NEB).
Get user_incar_settings for every step (init, endpoints and NEB).
Args:
mode (str): choose from "parent", "endpoints", "NEB"
"parent": [parent_dict, endpoints_dict, neb_dict1, neb_dict2, ...]
"endpoints": [endpoints_dict, neb_dict1, neb_dict2, ...]
"NEB": [neb_dict1, neb_dict2, ...]
user_incar_settings (dict): list of dict to be parsed.
user_incar_settings ([dict]): list of dict to be parsed.
Returns:
user_incar_settings (dict):
(uis_ini, uis_ep, uis_neb), in which uis_ini and uis_ep are dict and uis_neb is a
(uis_init, uis_ep, uis_neb), in which uis_init and uis_ep are dict and uis_neb is a
list of dict.
"""
# Validate input type
assert mode in ["parent", "endpoints", "NEB"]
assert isinstance(user_incar_settings, dict)
assert isinstance(user_incar_settings, dict) # todo:
if mode == "parent":
assert len(user_incar_settings) >= 3
elif mode == "endpoints":
assert len(user_incar_settings) >= 2
else: # mode == "NEB"
assert len(user_incar_settings) >= 1

uis_ini = user_incar_settings.get("parent", {})
uis_init = user_incar_settings.get("parent", {})
uis_ep = user_incar_settings.get("endpoints", {})
uis_neb = user_incar_settings["NEB"]

return uis_ini, uis_ep, uis_neb
return uis_init, uis_ep, uis_neb


def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,
Expand All @@ -175,7 +174,7 @@ def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,

# Get INCARs
mode = "endpoints" if is_optimized else "parent"
uis_ini = _get_incar(mode, user_incar_settings)[0]
uis_init = _get_incar(mode, user_incar_settings)[0] # todo: user_incar_settings should be a list
uis_ep = _get_incar(mode, user_incar_settings)[1]
uis_neb = _get_incar(mode, user_incar_settings)[2]
neb_round = len(uis_neb)
Expand All @@ -189,8 +188,8 @@ def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,
endpoints=endpoints_dict)

# Get mpi vasp command
vasp_cmd = _get_mpi_command(spec, "std")
gamma_vasp_cmd = _get_mpi_command(spec, "gam")
vasp_cmd = _get_command(spec, "std")
gamma_vasp_cmd = _get_command(spec, "gam")

# Get neb fireworks.
neb_fws = []
Expand All @@ -210,9 +209,9 @@ def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,
rlx_fws[1]: [neb_fws[0]]}
else: # Start from perfect structure
spec = _update_spec_from_inputs(spec, structure=structure.as_dict(), wf_name=wf_name,
ini=structure.as_dict(), path_sites=path_sites)
vasp_cmd = _get_mpi_command(spec, "std")
gamma_vasp_cmd = _get_mpi_command(spec, "gam")
init=structure.as_dict(), path_sites=path_sites)
vasp_cmd = _get_command(spec, "std")
gamma_vasp_cmd = _get_command(spec, "gam")

# Get neb fireworks.
neb_fws = []
Expand All @@ -224,7 +223,7 @@ def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,

rlx_fws = [NEBRelaxationFW(spec=spec, label=label, vasp_input_set=None,
user_incar_settings=incar)
for label, incar in zip(["ini", "ep0", "ep1"], [uis_ini, uis_ep, uis_ep])]
for label, incar in zip(["init", "ep0", "ep1"], [uis_init, uis_ep, uis_ep])]

links = {rlx_fws[0]: [rlx_fws[1], rlx_fws[2]],
rlx_fws[1]: [neb_fws[0]],
Expand All @@ -239,7 +238,7 @@ def get_wf_neb_from_structure(structure, path_sites, user_incar_settings,
return workflow


def get_wf_neb_from_endpoints(user_incar_settings, endpoints=None,
def get_wf_neb_from_endpoints(user_incar_settings, parent, endpoints=None,
is_optimized=True, wf_name=None, additional_spec=None):
"""
Get a CI-NEB workflow from given endpoints.
Expand All @@ -249,6 +248,7 @@ def get_wf_neb_from_endpoints(user_incar_settings, endpoints=None,
Args:
user_incar_settings([dict]): Additional user_incar_settings corresponded with fw
parent (Structure): parent structure.
endpoints (list[Structure]): The image structures, if None then read from spec.
is_optimized (bool): True implies the provided endpoint structures are optimized, otherwise
run endpoints relaxation before NEB.
Expand All @@ -265,17 +265,17 @@ def get_wf_neb_from_endpoints(user_incar_settings, endpoints=None,
else:
endpoints_dict = [additional_spec["ep0"], additional_spec["ep1"]]

formula = endpoints[0].composition.reduced_formula
wf_name = wf_name or datetime.utcnow().strftime('%Y-%m-%d-%H-%M-%S-%f')

mode = "NEB" if is_optimized else "endpoints"
uis_ep = _get_incar(mode, user_incar_settings)[1]
uis_neb = _get_incar(mode, user_incar_settings)[2]
neb_round = len(uis_neb)

spec = _update_spec_from_inputs(additional_spec, endpoints=endpoints_dict)
vasp_cmd = _get_mpi_command(spec, "std")
gamma_vasp_cmd = _get_mpi_command(spec, "gam")
spec = _update_spec_from_inputs(additional_spec, structure=parent.as_dict(),
endpoints=endpoints_dict)
vasp_cmd = _get_command(spec, "std")
gamma_vasp_cmd = _get_command(spec, "gam")

neb_fws = []
for n in range(neb_round):
Expand Down Expand Up @@ -332,8 +332,8 @@ def get_wf_neb_from_images(parent, user_incar_settings, images, wf_name=None, sp
images=images_dict, wf_name=wf_name)
uis_neb = _get_incar("NEB", user_incar_settings)[2]
neb_round = len(uis_neb)
vasp_cmd = _get_mpi_command(spec, "std")
gamma_vasp_cmd = _get_mpi_command(spec, "gam")
vasp_cmd = _get_command(spec, "std")
gamma_vasp_cmd = _get_command(spec, "gam")

fws = []
for n in range(neb_round):
Expand Down
31 changes: 15 additions & 16 deletions atomate/vasp/workflows/presets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def wf_thermal_expansion(structure, c=None):
return wf


def wf_nudged_elastic_band(structures, c=None, parent=None):
def wf_nudged_elastic_band(structures, parent, c=None):
"""
Nudged elastic band workflow from the given structures and config dict.
Expand All @@ -360,31 +360,29 @@ def wf_nudged_elastic_band(structures, c=None, parent=None):
Args:
structures (Structure / [Structure]): input structures
parent (Structure): parent structure.
c (dict): workflow config dict, basic format:
{"fireworks": [], "is_optimized": False, "common_params": {}}
parent (Structure): parent structure when not given.
Returns:
Workflow
"""
def get_incar(mode):
"""Get user_incar_settings for fireworks."""
uis_init, uis_ep, uis_neb = {}, {}, [{}] * neb_round

uis_ini, uis_ep, uis_neb = {}, {}, [{}] * neb_round

assert mode in [1, 2, 3, 4, 5], "Unknown mode!"
if mode == 1:
uis_ini = c["fireworks"][0].get("user_incar_settings", {})
uis_init = c["fireworks"][0].get("user_incar_settings", {})
uis_ep = c["fireworks"][1].get("user_incar_settings", {})
for i in range(neb_round):
try:
uis_neb[i] = c["fireworks"][3 + i]["user_incar_settings"]
uis_neb[i] = c["fireworks"][2 + i]["user_incar_settings"]
except:
uis_neb[i] = {}
elif mode in [2, 3]:
uis_ep = c["fireworks"][0].get("user_incar_settings", {})
for i in range(neb_round):
try:
uis_neb[i] = c["fireworks"][2 + i]["user_incar_settings"]
uis_neb[i] = c["fireworks"][1 + i]["user_incar_settings"]
except:
uis_neb[i] = {}
else:
Expand All @@ -393,7 +391,7 @@ def get_incar(mode):
uis_neb[i] = c["fireworks"][i]["user_incar_settings"]
except:
uis_neb[i] = {}
return uis_ini, uis_ep, uis_neb
return uis_init, uis_ep, uis_neb

# Structure --> [Structure]
if isinstance(structures, Structure):
Expand Down Expand Up @@ -424,15 +422,15 @@ def get_incar(mode):
assert neb_round > 0, "No NEB fireworks in config file!"
# Get mode number
if len(structures) == 1:
if not is_optimized and len(fw_list) - neb_round == 3:
if not is_optimized and len(fw_list) - neb_round == 2:
mode = 1
elif is_optimized and len(fw_list) - neb_round == 2:
elif is_optimized and len(fw_list) - neb_round == 1:
mode = 2
else:
raise ValueError("structure conflict with config file settings!")
elif len(structures) == 2:
assert isinstance(parent, Structure), "Parent structure is not provided!"
if not is_optimized and len(fw_list) - neb_round == 2:
if not is_optimized and len(fw_list) - neb_round == 1:
mode = 3
elif is_optimized and len(fw_list) - neb_round == 0:
mode = 4
Expand All @@ -442,18 +440,19 @@ def get_incar(mode):
assert isinstance(parent, Structure), "Parent structure is not provided!"
mode = 5

uis_ini, uis_ep, uis_neb = get_incar(mode)
uis_init, uis_ep, uis_neb = get_incar(mode)

user_incar_settings = {"parent": uis_ini, "endpoints": uis_ep, "NEB": uis_neb}
user_incar_settings = {"parent": uis_init, "endpoints": uis_ep, "NEB": uis_neb}

# Assign workflow using mode
if mode in [1, 2]:
wf = get_wf_neb_from_structure(structure=structures[0], path_sites=path_sites,
is_optimized=is_optimized, wf_name=wf_name,
spec=spec, user_incar_settings=user_incar_settings)
elif mode in [3, 4]:
wf = get_wf_neb_from_endpoints(endpoints=structures, is_optimized=is_optimized,
wf_name=wf_name, additional_spec=spec,
wf = get_wf_neb_from_endpoints(parent=structures[0], endpoints=structures,
is_optimized=is_optimized, wf_name=wf_name,
additional_spec=spec,
user_incar_settings=user_incar_settings)
else: # mode == 5
wf = get_wf_neb_from_images(parent, user_incar_settings, images=structures,
Expand Down
Loading

0 comments on commit 33ae84c

Please sign in to comment.