matmethods.utils package¶
Subpackages¶
Submodules¶
matmethods.utils.database module¶
-
class
matmethods.utils.database.
MMDb
(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
()¶
-
matmethods.utils.fileio module¶
-
class
matmethods.utils.fileio.
FileClient
(filesystem=None, private_key=u'~/.ssh/id_rsa')¶ Bases:
object
A client that allows 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
-
matmethods.utils.utils module¶
-
matmethods.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.
-
matmethods.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 values that look like this: “>>ENV_KEY<<” to the contents of: fw_spec[“_fw_env”][ENV_KEY]
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 value 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 value cannot be found default: if val is None or env cannot be found in non-strict mode,
return default
-
matmethods.utils.utils.
get_calc_loc
(target_name, calc_locs)¶ This is a helper method that helps you pick out a certain calculation from an array of calc_locs.
- There are three modes:
- If you set target_name to a String, search for most recent calc_loc
with matching name
Otherwise, return most recent calc_loc overall
- Args:
- target_name: (bool or str) If str, will search for calc_loc with
- matching name, else use most recent calc_loc
calc_locs: (dict) The dictionary of all calc_locs
- Returns:
- (dict) dict with subkeys path, filesystem, and name
-
matmethods.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 constraints
- 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
-
matmethods.utils.utils.
get_logger
(name, level=10, format=u'%(asctime)s %(levelname)s %(name)s %(message)s', stream=<open file '<stdout>', mode 'w'>)¶
-
matmethods.utils.utils.
get_meta_from_structure
(structure)¶
-
matmethods.utils.utils.
get_mongolike
(d, key)¶
-
matmethods.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: matmethods.vasp.fireworks.core.OptimizeFW - fw: matmethods.vasp.fireworks.core.StaticFW
- params:
- parents: 0
fw: matmethods.vasp.fireworks.core.NonSCFUniformFW params:
parents: 1
fw: matmethods.vasp.fireworks.core.NonSCFLineFW params:
parents: 1
- common_params:
- db_file: db.json $vasp_cmd: $HOME/opt/vasp
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.
- Returns:
- Workflow
-
matmethods.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
-
matmethods.utils.utils.
remove_leaf_fws
(orig_wf)¶ Remove the end nodes(last fireworks) from the given workflow.
- Args:
- orig_wf (Workflow): The original workflow object.
- Returns:
- Workflow : the new updated workflow.
-
matmethods.utils.utils.
update_wf
(wf)¶ Simple helper to ensure that the powerup updates to the workflow dict has taken effect. This is needed because all the powerups that modify workflow do so on the dict representation of the workflow(or mix thereof eg: add tasks as dict to the fireworks spec etc) and for inspection the powerups rely on a mix of object and dict representations of workflow object( along with the constituent fireworks and firetasks) that are not in one to one correspondence with the updated dict representation.
- Args:
- wf (Workflow)
- Returns:
- Workflow