atomate.utils package


atomate.utils.database module

class atomate.utils.database.CalcDb(host, port, database, collection, user, password)

Bases: object

__init__(host, port, database, collection, user, password)

Initialize self. See help(type(self)) for accurate signature.

build_indexes(indexes=None, background=True)

Build the indexes.

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

db_file (str): path to the file containing the credentials admin (bool): whether to use the admin user
MMDb object
insert(d, update_duplicates=True)

Insert the task document ot the database collection.

d (dict): task document update_duplicates (bool): whether to update the duplicates

atomate.utils.fileio module

class atomate.utils.fileio.FileClient(filesystem=None, private_key='~/.ssh/id_rsa')

Bases: object

A client for performing many file operations while being agnostic of whether those operations are happening locally or via SSH

__init__(filesystem=None, private_key='~/.ssh/id_rsa')
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

return the absolute path

path (str): path to get absolute string of
copy(src, dest)

Copy from source to destination.

src (str): source full path dest (str): destination file full path
static exists(path)

os.path.exists() for paramiko’s SCP object

sftp (SFTPClient): path (str): path to check existence of
static get_ssh_connection(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.


username (str): host (str):

private_key (str): path to private key file


return the glob

path (str): path to glob

Get the directory listing from either the local or remote filesystem.

ldir (str): full path to the directory
iterator of filenames

atomate.utils.testing module

class atomate.utils.testing.AtomateTest(methodName='runTest')



Returns pymongo collection


Returns pymongo db connection.


Create scratch directory(removes the old one if there is one) and change to it. Also initialize launchpad.


Remove the scratch directory and teardown the test db.

atomate.utils.utils module

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:

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.


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_database(config_file=None, settings=None, admin=False, **kwargs)
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.

workflow (Workflow): Workflow fw_name_constraint (str): a constraint on the FW name task_name_constraint (str): a constraint on the task name
a list of tuples of the form (fw_id, task_id) of the RunVasp-type tasks
atomate.utils.utils.get_logger(name, level=10, log_format='%(asctime)s %(levelname)s %(name)s %(message)s', stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)
atomate.utils.utils.get_mongolike(d, key)

Retrieve 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 retrieve with dot notation, e.g., “a.b.c”
value from desired dict (whatever is stored at the desired key)

Returns the URI path for a directory. This allows files hosted on different file servers to have distinct locations. Args:

A directory name.
Full URI path, e.g.,
atomate.utils.utils.get_wf_from_spec_dict(structure, wfspec, common_param_updates=None)

Load a WF from a structure and a spec dict. This allows simple custom workflows to be constructed quickly via a YAML file.


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

parents: 0
  • fw: atomate.vasp.fireworks.core.NonSCFUniformFW params:

    parents: 1

  • fw: atomate.vasp.fireworks.core.NonSCFLineFW params:

    parents: 1

db_file: db.json $vasp_cmd: $HOME/opt/vasp

name: bandstructure metadata:

tag: testing_workflow


The 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.

common_param_updates (dict): A dict specifying any user-specified updates to common_params

atomate.utils.utils.load_class(modulepath, classname)

Load and return the class from the given module.

modulepath (str): dotted path to the module. eg: “” classname (str): name of the class to be loaded.
atomate.utils.utils.recursive_get_result(d, result)

Function that gets designated keys or values of d (i. e. those that start with “d>>” or “a>>”) from the corresponding entry in result_dict, similar to FireWorks recursive_deserialize.

Note that the plain “>>” notation will get a key from the result.as_dict() object and may use MongoDB dot notation, while “a>>” will get an attribute of the object.


Getting a dict key from a VaspRun instance:
recursive_get_result({“stress”:”>>output.ionic_steps.-1.stress”}, vasprun) –> {“stress”:[[0.2, 0, 0], [0, 0.3, 0], [0, 0, 0.3]]}
Getting an attribute from a vasprun:
recursive_get_result({“epsilon”:”a>>epsilon_static”, vasprun} –> {“epsilon”:-3.4}
atomate.utils.utils.recursive_update(d, u)

Recursive updates d with values from u Args:

d (dict): dict to update u (dict): updates to propogate

Module contents