API¶
Rules and sessions¶
-
class
mona.
Rule
(corofunc)[source]¶ Decorator that turns a coroutine function into a rule.
A rule is a callable that generates a task instead of actually calling the coroutine.
Parameters: corofunc – a coroutine function -
add_extra_arg
(factory)[source]¶ Register an extra argument factory.
Parameters: factory – callable that returns an extra argument that will be appended to the arguments passed when creating a task.
-
corofunc
¶ Coroutine function associated with the rule.
-
-
coroutine
mona.
run_process
(*args, ncores=None, **kwargs)[source]¶ Create a subprocess.
Wrapper around
asyncio.create_subprocess_exec()
that handles errors and whose behavior can be modified by session plugins.Parameters: - args (str) – arguments of the subprocess
- ncores (int) – number of cores that should be taken by the process
- kwargs – all other keyword arguments are passed to
create_subprocess_exec()
.PIPE
is passed to stdin and stdout keyword arguments by default.
Return the standard output as bytes if no error output was generated or a tuple of bytes containing standard and error outputs.
-
coroutine
mona.
run_shell
(cmd, ncores=None, **kwargs)[source]¶ Execute a command in a shell.
Wrapper around
asyncio.create_subprocess_shell()
that handles errors and whose behavior can be modified by session plugins.Parameters: - cmd (str) – a shell command to be executed
- ncores (int) – number of cores that should be taken by the process
- kwargs – all other keyword arguments are passed to
create_subprocess_shell()
.PIPE
is passed to stdin and stdout keyword arguments by default.
Return the standard output as bytes if no error output was generated or a tuple of bytes containing standard and error outputs.
-
coroutine
mona.
run_thread
(func, *args)[source]¶ Run a callable in a new thread.
Wrapper around
asyncio.AbstractEventLoop.run_in_executor()
whose behavior can be modified by session plugins.Parameters: - func – a callable
- args – positional arguments to the callable.
Return the result of the callable.
-
class
mona.
Session
(plugins=None, warn=True)[source]¶ A context manager in which tasks can be created.
Parameters: - plugins – session plugins to load. This is equivalent to calling each plugin with the created session as an argument
- warn (bool) – warn at the end of session if some created tasks were not executed and no tasks were explicitly filtered
-
create_task
(corofunc, *args, **kwargs)[source]¶ Create a new task.
Parameters: - corofunc – a coroutine function to be executed
- args – arguments to the coroutine
- kwargs – keyword arguments passed to
Task
-
eval
(*args, **kwargs)[source]¶ Blocking version of
eval_async()
.
-
coroutine
eval_async
(obj, depth=False, priority=(RESULTS, EXECUTE, TRAVERSE), exception_handler=None, task_filter=None, limit=None)[source]¶ Evaluate an object by running all tasks it references.
This includes all newly created tasks that are referenced indirectly.
Parameters: - obj – any hashable object
- depth (bool) – traverse DAG depth-first if true, breadth-first otherwise
- priority (tuple) – prioritize steps in DAG traversal in order
- exception_handler – callable that accepts a task and an exception it raised and returns True if the exception should be ignored
- task_filter – callable that accepts a task and returns True if the task should be executed
- limit (int) – limit of the number of executed task
Return the evaluated object.
-
run_task
(task)[source]¶ Run a task.
Parameters: task – task to run Return the result of the task’s coroutine function or it’s hashed instance if hashable.
-
running_task
¶ Currently running task.
-
storage
¶ General-purpose dictionary-based storage.
Session plugins¶
-
class
mona.plugins.
Cache
(db, write='eager', full_restore=False)[source]¶ Plugin that caches tasks and objects in a session to an SQLite database.
-
db
¶ Database connection.
-
Files¶
-
class
mona.files.
File
(path, content)[source]¶ Represents a file located at an abstract relative path.
Users should create instances by one of the classmethod constructors documented below rather than directly.
-
content
¶ Content as bytes or its hash.
-
classmethod
from_path
(path, root=None, *, keep=True)[source]¶ Create a file from a physical file.
Parameters: - path – the path of the physical file. Also a basis for the abstract path of the file instance.
- root – If given, the abstract path will be created from the
physical path taken relative to the root. If not given,
the
path
argument must be relative. - keep (bool) – whether the physical file should kept or destroyed
-
classmethod
from_str
(path, content)[source]¶ Create a file from a string or bytes.
Parameters: - path – the abstract path of the created file instance
- content – the content of the file
-
name
¶ Equivalent to
path.name
.
-
path
¶ Abstract path to the file.
-
stem
¶ Equivalent to
path.stem
.
-
Directory tasks¶
Scientific calculations¶
Molecular and crystal geometries¶
-
class
mona.sci.geomlib.
Atom
(species, coord, **flags)[source]¶ Represents a single atom.
Parameters: - species – atom type
- coord – atom coordinate
-
covalent_radius
¶ Covalent radius.
-
mass
¶ Atom mass.
-
number
¶ Atom number.
-
class
mona.sci.geomlib.
Molecule
(atoms, **flags)[source]¶ Represents a molecule.
Parameters: atoms – atoms -
centers
¶ Iterate over atoms.
-
cms
¶ Center of mass.
-
coords
¶ Coordinates.
-
dumps
(fmt)¶ Default object formatter.
-
formula
¶ Formula.
-
classmethod
from_coords
(species, coords, **flags)[source]¶ Alternative constructor.
Parameters: - species – atom types
- coords – coordinates
-
inertia
¶ Inertia tensor.
-
mass
¶ Molecular mass.
-
numbers
¶ Atom numbers.
-
species
¶ Atom types.
-
xyz
¶ Coordinates as a numpy array.
-
-
class
mona.sci.geomlib.
Crystal
(atoms, lattice, **flags)[source]¶ Represents a crystal. Inherits from
Molecule
.Parameters: - atoms – atoms
- lattice – lattice vectors
-
abc
¶ Latice vectors as a numpy array.
-
classmethod
from_coords
(species, coords, lattice, **flags)[source]¶ Alternative constructor.
Parameters: - species – atom types
- coords – coordinates
- lattice – lattice vectors
FHI-aims¶
-
class
mona.sci.aims.
Aims
[source]¶ Task factory that creates an FHI-aims directory task.
The creation of a task is handeld by a series of plugins that process keyword arguments passed to the instance of
Aims
to generatecontrol.in
andgeometry.in
. The default plugins are created with no extra arguments. Custom plugins can be registered by calling them with theAims
instance as an argument.Aims tasks require two prerequisites to function:
mona_aims
executable inPATH
, which runs Aims and accepts these environment variables:MONA_AIMS
specifies the Aims executable to run.MONA_NCORES
specifies the number of processor cores to run Aims with.
AIMS_SPECIES_DEFAULTS
environment variable that points to thespecies_defaults
Aims directory.
-
__call__
(*, label=None, **kwargs)[source]¶ Create an Aims task.
Parameters: - kwargs – keyword arguments processed by plugins
- label – passed to
dir_task()
Existing keywords (some are generated by plugins, see below):
atoms
: List of two-tuples of a species and a coordinate.geom
: Instance ofMolecule
.species_specs
: List of species specifications.tags
: Dictionary of tags forcontrol.in
.aims
: Aims executable, must be present inPATH
.check
: Whether task should error out on abnormal Aims exit.ncores
: Number of cores to use, all available if not given.
-
plugin_factories
= [<class 'mona.sci.aims.aims.Atoms'>, <class 'mona.sci.aims.aims.SpeciesDefaults'>, <class 'mona.sci.aims.aims.Control'>, <class 'mona.sci.aims.aims.Geom'>, <class 'mona.sci.aims.aims.Script'>]¶ List of plugins run in this order.
-
class
mona.sci.aims.
Atoms
[source]¶ Aims plugin handling geometry.
Keywords processed:
atoms
. Keywords added:geom
.
-
class
mona.sci.aims.
SpeciesDefaults
(mod=None)[source]¶ Aims plugin handling species specifications.
Parameters: mod – Callable that is passed the species specifications for modification. Keywords added:
species_specs
. Keywords used:geom
,species_defaults
.
-
class
mona.sci.aims.
Control
[source]¶ Aims plugin generating
control.in
.Keywords processed:
species_specs
,tags
. Keywords added:control.in
.
-
class
mona.sci.aims.
Geom
[source]¶ Aims plugin generating
geometry.in
.Keywords processed:
geom
. Keywords added:geometry.in
.
-
class
mona.sci.aims.
Script
[source]¶ Aims plugin generating script for the Aims taks.
Keywords processed:
aims
,check
. Keywords added:script
.
-
mona.sci.aims.
parse_aims
(*args, **kwargs)[source]¶ Create a task that parses outputs of FHI-aims calculations.
The task takes the output of
mona.sci.aims.Aims
as an input and returns a dictionary of parsed results as output.
Futures and tasks¶
The following classes are not intended for direct use by the end user, but are part of the versioned public API neverthless.