atomate.utils package¶
Subpackages¶
Submodules¶
atomate.utils.database module¶
-
class
atomate.utils.database.CalcDb(host, port, database, collection, user, password)¶ Bases:
object-
__init__(host, port, database, collection, user, password)¶
-
build_indexes(indexes=None, background=True)¶ Build the indexes.
- Args:
- indexes (list): list of single field indexes to be built. background (bool): Run in the background or not.
-
classmethod
from_db_file(db_file, admin=True)¶ Create MMDB from database file. File requires host, port, database, collection, and optionally admin_user/readonly_user and admin_password/readonly_password
- Args:
- db_file (str): path to the file containing the credentials admin (bool): whether to use the admin user
- Returns:
- MMDb object
-
insert(d, update_duplicates=True)¶ Insert the task document ot the database collection.
- Args:
- d (dict): task document update_duplicates (bool): whether to update the duplicates
-
reset()¶
-
atomate.utils.fileio module¶
-
class
atomate.utils.fileio.FileClient(filesystem=None, private_key=u'~/.ssh/id_rsa')¶ Bases:
objectA client for performing many file operations while being agnostic of whether those operations are happening locally or via SSH
-
__init__(filesystem=None, private_key=u'~/.ssh/id_rsa')¶ - Args:
- filesystem (str): remote filesystem, e.g. username@remote_host.
- If None, use local
- private_key (str): path to the private key file (for remote
- connections only). Note: passwordless ssh login must be setup
-
abspath(path)¶ return the absolute path
- Args:
- path (str): path to get absolute string of
-
copy(src, dest)¶ Copy from source to destination.
- Args:
- src (str): source full path dest (str): destination file full path
-
static
exists(sftp, path)¶ os.path.exists() for paramiko’s SCP object
- Args:
- sftp (SFTPClient): path (str): path to check existence of
-
static
get_ssh_connection(username, host, private_key)¶ Connect to the remote host via paramiko using the private key. If the host key is not present it will be added automatically.
- Args:
username (str): host (str):
private_key (str): path to private key file
- Returns:
- SSHClient
-
glob(path)¶ return the glob
- Args:
- path (str): path to glob
-
listdir(ldir)¶ Get the directory listing from either the local or remote filesystem.
- Args:
- ldir (str): full path to the directory
- Returns:
- iterator of filenames
-
atomate.utils.utils module¶
-
atomate.utils.utils.append_fw_wf(orig_wf, fw_wf)¶ Add the given firework or workflow to the end of the provided workflow. If there are multiple leaf nodes the newly added firework/workflow will depend on all of them.
- Args:
- orig_wf (Workflow): The original workflow object. fw_wf (Firework/Workflow): The firework or workflow object to be appended to orig_wf.
-
atomate.utils.utils.env_chk(val, fw_spec, strict=True, default=None)¶ env_chk() is a way to set different values for a property depending on the worker machine. For example, you might have slightly different executable names or scratch directories on different machines.
env_chk() works using the principles of the FWorker env in FireWorks.
This helper method translates string “val” that looks like this: “>>ENV_KEY<<” to the contents of: fw_spec[“_fw_env”][ENV_KEY]
Otherwise, the string “val” is interpreted literally and passed-through as is.
The fw_spec[“_fw_env”] is in turn set by the FWorker. For more details, see: https://pythonhosted.org/FireWorks/worker_tutorial.html
Since the fw_env can be set differently for each FireWorker, one can use this method to translate a single “val” into multiple possibilities, thus achieving different behavior on different machines.
- Args:
val: any value, with “>><<” notation reserved for special env lookup values fw_spec: (dict) fw_spec where one can find the _fw_env keys strict (bool): if True, errors if env format (>><<) specified but cannot be found in fw_spec default: if val is None or env cannot be found in non-strict mode,
return default
-
atomate.utils.utils.get_fws_and_tasks(workflow, fw_name_constraint=None, task_name_constraint=None)¶ Helper method: given a workflow, returns back the fw_ids and task_ids that match name constraints. Used in developing multiple powerups.
- Args:
- workflow (Workflow): Workflow fw_name_constraint (str): a constraint on the FW name task_name_constraint (str): a constraint on the task name
- Returns:
- a list of tuples of the form (fw_id, task_id) of the RunVasp-type tasks
-
atomate.utils.utils.get_logger(name, level=10, format=u'%(asctime)s %(levelname)s %(name)s %(message)s', stream=<open file '<stdout>', mode 'w'>)¶
-
atomate.utils.utils.get_meta_from_structure(structure)¶
-
atomate.utils.utils.get_mongolike(d, key)¶ Grab a dict value using dot-notation like “a.b.c” from dict {“a”:{“b”:{“c”: 3}}} Args:
d (dict): the dictionary to search key (str): the key we want to grab with dot notation, e.g., “a.b.c”- Returns:
- value from desired dict (whatever is stored at the desired key)
-
atomate.utils.utils.get_wf_from_spec_dict(structure, wfspec)¶ Load a WF from a structure and a spec dict. This allows simple custom workflows to be constructed quickly via a YAML file.
- Args:
structure (Structure): An input structure object. wfspec (dict): A dict specifying workflow. A sample of the dict in
YAML format for the usual MP workflow is given as follows:
``` fireworks: - fw: atomate.vasp.fireworks.core.OptimizeFW - fw: atomate.vasp.fireworks.core.StaticFW
- params:
- parents: 0
fw: atomate.vasp.fireworks.core.NonSCFUniformFW params:
parents: 1
fw: atomate.vasp.fireworks.core.NonSCFLineFW params:
parents: 1
- common_params:
- db_file: db.json $vasp_cmd: $HOME/opt/vasp
name: bandstructure metadata:
tag: testing_workflowThe fireworks key is a list of Fireworks; it is expected that all such Fireworks have “structure” as the first argument and other optional arguments following that. Each Firework is specified via “fw”: <explicit path>.
You can pass arguments into the constructor using the special keyword params, which is a dict. Any param starting with a $ will be expanded using environment variables.If multiple fireworks share the same params, you can use common_params to specify a common set of arguments that are passed to all fireworks. Local params take precedent over global params.
Another special keyword is parents, which provides the indices of the parents of that particular Firework in the list. This allows you to link the Fireworks into a logical workflow.
Finally, name is used to set the Workflow name (structure formula + name) which can be helpful in record keeping.
- Returns:
- Workflow
-
atomate.utils.utils.load_class(modulepath, classname)¶ Load and return the class from the given module.
- Args:
- modulepath (str): dotted path to the module. eg: “pymatgen.io.vasp.sets” classname (str): name of the class to be loaded.
- Returns:
- class
-
atomate.utils.utils.remove_fws(orig_wf, fw_ids)¶ Remove the fireworks corresponding to the input firework ids and update the workflow i.e the parents of the removed fireworks become the parents of the children fireworks (only if the children dont have any other parents).
- Args:
- orig_wf (Workflow): The original workflow object. fw_ids (list): list of fw ids to remove.
- Returns:
- Workflow : the new updated workflow.