asimtools package
- asimtools.asimmodules package
- asimtools.asimmodules.active_learning package
- asimtools.asimmodules.ase_md package
- asimtools.asimmodules.benchmarking package
- asimtools.asimmodules.data package
- asimtools.asimmodules.elastic_constants package
- asimtools.asimmodules.eos package
- asimtools.asimmodules.geometry_optimization package
- asimtools.asimmodules.geometry_optimization.ase_cubic_eos_optimization module
- asimtools.asimmodules.geometry_optimization.atom_relax module
- asimtools.asimmodules.geometry_optimization.cell_relax module
- asimtools.asimmodules.geometry_optimization.optimize module
- asimtools.asimmodules.geometry_optimization.symmetric_cell_relax module
- Module contents
- asimtools.asimmodules.lammps package
- asimtools.asimmodules.mace package
- asimtools.asimmodules.phonons package
- asimtools.asimmodules.phonopy package
- asimtools.asimmodules.phonopy.forces module
- asimtools.asimmodules.phonopy.full_qha module
- asimtools.asimmodules.phonopy.generate_phonopy_displacements module
- asimtools.asimmodules.phonopy.phonon_bands_and_dos module
- asimtools.asimmodules.phonopy.phonon_bands_and_dos_from_forces module
- asimtools.asimmodules.phonopy.qha_properties module
- asimtools.asimmodules.phonopy.read_force_constants module
- asimtools.asimmodules.phonopy.thermal_properties module
- Module contents
- asimtools.asimmodules.surface_energies package
- asimtools.asimmodules.transformations package
- asimtools.asimmodules.vacancy_formation_energy package
- asimtools.asimmodules.vasp package
- asimtools.asimmodules.workflows package
- asimtools.asimmodules.workflows.calc_array module
- asimtools.asimmodules.workflows.chained module
- asimtools.asimmodules.workflows.distributed module
- asimtools.asimmodules.workflows.image_array module
- asimtools.asimmodules.workflows.iterative module
- asimtools.asimmodules.workflows.sim_array module
- asimtools.asimmodules.workflows.update_dependencies module
- asimtools.asimmodules.workflows.utils module
- Module contents
- asimtools.asimmodules.do_nothing module
- asimtools.asimmodules.singlepoint module
- Module contents
asimtools.calculators module
Tools for loading and returning ASE calculator objects for use in simulations
- asimtools.calculators.load_aqcat(calc_params)[source]
Load AQCat Calculator :param calc_params: args to pass to loader, including checkpoint_path :type calc_params: Dict :return: AQCat calculator :rtype:
fairchem.core.common.relaxation.ase_utils.patched_calc
- asimtools.calculators.load_ase_dftd3(calc_params)[source]
Load any calculator with DFTD3 correction as implemented in ASE
- Parameters:
calc_params (Dict) – Dictionary with 2 keys. First is d3_args which is passed to ase.calculators.dftd3.DFTD3 except for the dft argument. The second is dft_calc_id or dft_calc_params which loads the calculator to be wrapped.
- Returns:
ASE calculator
- Return type:
ase.calculators.calculators.Calculator
- asimtools.calculators.load_calc(calculator: Dict | None = None, calc_id: str | None = None, calc_input: Dict | None = None, calc_params: Dict | None = None)[source]
Loads a calculator using a calculator dict or legacy calc_id/calc_params arguments.
- Parameters:
calculator (Optional[Dict], optional) – Dictionary with either a
calc_idkey (to look up from the global or supplied calc_input) or acalc_paramskey (to use directly). Takes precedence over the legacy arguments if provided, defaults to Nonecalc_id (str, optional) – Deprecated — use
calculator={'calc_id': ...}instead. ID/key to use to load calculator from the supplied or global calc_input file, defaults to Nonecalc_input – calc_input dictionary, same form as calc_input yaml :type calc_input: Optional[Dict], optional
calc_params (Optional[Dict], optional) – Deprecated — use
calculator={'calc_params': ...}instead. calc_params dictionary for a single calculator, defaults to None
- Returns:
ASE calculator instance
- Return type:
ase.calculators.calculators.Calculator
- asimtools.calculators.load_chgnet(calc_params)[source]
Load CHGNet Calculator
https://chgnet.lbl.gov/#tutorials-and-docs
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
CHGNet calculator
- Return type:
chgnet.model.dynamics.CHGNetCalculator
- asimtools.calculators.load_dp(calc_params)[source]
Load Deep Potential Calculator
https://docs.deepmodeling.com/projects/deepmd/en/master/
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
DP calculator
- Return type:
deepmd.calculator.DP
- asimtools.calculators.load_espresso_profile(calc_params)[source]
Load Qunatum Espresso Calculator for ASE>3.22.1. If using older versions such as the ones available on PyPI or conda-forge, just load it as an ASE calculator. Until the new ASE version becomes an official release, we will have to have both for compatibility. The interface however remains that of ASE <=3.22.1 within ASIMTools for consistency using the command keyword
https://wiki.fysik.dtu.dk/ase/releasenotes.html
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
Espresso calculator
- Return type:
- asimtools.calculators.load_fairchem_v1(calc_params)[source]
Load any fairchemV1 calculator
- Parameters:
calc_params (Dict) – parameters to be passed to fairchem.core.OCPCalculator. Must include a key “model” that points to the model files used to instantiate the potential
- Returns:
fairchem calculator
- Return type:
fairchem.core.OCPCalculator
- asimtools.calculators.load_fairchem_v2(calc_params)[source]
Load any fairchemV1 calculator
- Parameters:
calc_params (Dict) – parameters to be passed to fairchem.core.FAIRChemCalculator. Must include a key “model” that points to the model files used to instantiate the potential
- Returns:
fairchem calculator
- Return type:
fairchem.core.FAIRChemCalculator
Examples
>>> from asimtools.calculators import load_calc >>> calc_params = { ... 'name': 'fairchem', ... 'args': { ... 'model_name': 'uma-s-1', ... 'device': 'cuda', ... 'task_name': 'oc20' # Also 'omol','omat','oc20','odac' or 'omc' ... } ... } >>> calc = load_calc(calc_params=calc_params)
- asimtools.calculators.load_m3gnet(calc_params)[source]
Load any M3GNet or MatGL calculator
- Parameters:
calc_params (Dict) – parameters to be passed to matgl.ext.ase.M3GNetCalculator. Must include a key “model” that points to the model used to instantiate the potential
- Returns:
M3GNet calculator
- Return type:
matgl.ext.ase.M3GNetCalculator
- asimtools.calculators.load_mace(calc_params)[source]
Load MACE Calculator
https://github.com/ACEsuit/mace?tab=readme-ov-file
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
MACE calculator
- Return type:
mace.calculators.mace_mp
- asimtools.calculators.load_mace_mp(calc_params)[source]
Load MACE Calculator
https://github.com/ACEsuit/mace?tab=readme-ov-file
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
MACE calculator
- Return type:
mace.calculators.mace_mp
- asimtools.calculators.load_mace_off(calc_params)[source]
Load MACE Calculator
https://github.com/ACEsuit/mace?tab=readme-ov-file
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
MACE-OFF calculator
- Return type:
mace.calculators.mace_mp
- asimtools.calculators.load_matgl(calc_params)[source]
Load any MatGL calculator
- Parameters:
calc_params (Dict) – parameters to be passed to matgl.ext.ase.PESCalculator. Must include a key “model” that points to the model used to instantiate the potential
- Returns:
MatGL calculator
- Return type:
matgl.ext.ase.PESCalculator
- asimtools.calculators.load_nequip(calc_params)[source]
Load NequIP or Allegro calculator
https://github.com/mir-group/nequip/tree/main
- Parameters:
calc_params (Dict) – args to pass to loader
- Returns:
NequIP ase calculator
- Return type:
nequip.ase.nequip_calculator.NequIPCalculator
asimtools.job module
Set of tools for handling jobs in slurm, interactively or in the teminal for a specific calculator.
Author: mkphuthi@github.com
- class asimtools.job.ChainedJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobJobs made of smaller sequential unitjobs. Note that this only works well with unit jobs. If one of the UnitJobs calls asimmodules, internally, slurm will fail to build the correct dependencies but the files will be generated appropriately, you can submit them manually
- class asimtools.job.DistributedJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobArray job object with ability to submit simultaneous jobs
- submit(**kwargs) list[int] | None[source]
Submit a job using slurm, interactively or in the current console
- submit_jobs(**kwargs) list[int] | None[source]
Submits the jobs. If submitting lots of batch jobs, we recommend using DistributedJob.submit_slurm_array
- class asimtools.job.Job(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None, asimrun_mode: bool = False)[source]
Bases:
objectAbstract class for the job object
- class asimtools.job.UnitJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobUnit job object with ability to submit a slurm/interactive job. Unit jobs run in a specific environment and if required, run a specific calculator. More complex workflows are built up of unit jobs
- asimtools.job.check_job_tree_complete(job_tree: dict, skip_failed: bool = False) tuple[bool, str][source]
Recursively check if all jobs in a job tree are complete
- asimtools.job.create_unitjob(sim_input: dict, env_input: dict, workdir: str | Path, calc_input: dict | None = None) UnitJob[source]
Helper for making a generic UnitJob object, mostly for testing
- asimtools.job.get_subjobs(workdir: Path) list[Path][source]
Get all the directories with jobs in them
- Parameters:
workdir (Path) – directory to search for subjobs
- Returns:
sorted list of subdirectory paths containing sim_input.yaml
- Return type:
list[Path]
- asimtools.job.load_job_from_directory(workdir: str | Path, asimrun_mode: bool = False) Job[source]
Loads a job from a given directory
asimtools.utils module
Utilities and helper functions for reading and writing data using set standards
- asimtools.utils.change_dict_value(dct: Dict, new_value, key_sequence: Sequence, return_copy: bool | None = True, placeholder: str | None = None) Dict[source]
Changes a value in the specified dictionary given by following the key sequence
- Parameters:
dct (Dict) – dictionary to be changed
new_value (_type_) – The new value that will replace the old one
key_sequence (Sequence) – List of keys in the order in which they access the dictionary key
return_copy (bool, optional) – Whether to return a copy only or to modify the dictionary in-place as well, defaults to True
- Returns:
The changed dictionary
- Return type:
Dict
- asimtools.utils.change_dict_values(dct: Dict, new_values: Sequence, key_sequences: Sequence, return_copy: bool = True) Dict[source]
Changes values in the specified dictionary given by following the key sequences. Key-value pairs are set in the given order
- Parameters:
dct (Dict) – dictionary to be changed
new_values (Sequence) – The new values that will replace the old one
key_sequence (Sequence) – List of list of keys in the order in which they access the dictionary key
return_copy (bool, optional) – Whether to return a copy only or to modify the dictionary in-place as well, defaults to True
- Returns:
The changed dictionary
- Return type:
Dict
- asimtools.utils.check_if_slurm_job_is_running(slurm_job_id: str | int)[source]
Checks if the slurm job with specifying job_id is running
- asimtools.utils.expand_wildcards(dct: Dict, root_path: PathLike | None = None) Dict[source]
Expands paths in a dictionary
- Parameters:
dct (Dict[str, Any]) – Dictionary to expand paths in
root_path (os.PathLike) – Root path to expand paths from
- Returns:
Dictionary with expanded paths
- Return type:
Dict[str, Any]
- asimtools.utils.find_nth(haystack: str, needle: str, n: int) int[source]
Return index of nth occurence of substring in string
- asimtools.utils.get_atoms(image_file: str | None = None, interface: str = 'ase', builder: str | None = 'bulk', atoms: Atoms | None = None, repeat: Tuple[int, int, int] | None = None, repeat_to_n_args: Dict | None = None, rattle_stdev: float | None = None, mp_id: str | None = None, user_api_key: str | None = None, return_type: str = 'ase', constraints: Sequence[dict] | None = None, **kwargs) Atoms | Structure[source]
Return an ASE Atoms or pymatgen Structure object based on specified config. This is the recommended way to load atoms objects for asimmodules.
- Parameters:
image_file (str, optional) – Path to an ASE-readable image file, defaults to None
interface (str, optional) – Whether to use “ase” or “pymatgen” to create the atoms object
builder (str, optional) – Builder to use from
ase.build, defaults to ‘bulk’. Any extra keyword arguments specified are passed to the buildatoms (Atoms, optional) –
ase.Atomsobject, defaults to Nonerepeat (Tuple[int, int, int], optional) – Number of times to repeat input to create supercell, defaults to None
rattle_stdev (float, optional) – stdev to be provided to
ase.Atoms.rattle(), or as distance topymatgen.core.structure.Structure.perturb()defaults to Nonemp_id (str, optional) – Material Project ID to fetch structure from, defaults to None
user_api_key (str, optional) – Material Project API key, must be provided to get structures from Materials Project, defaults to None
constraints (Sequence[dict], optional) – List of constraints to apply to the atoms object, currently only supports FixAtoms constraints, defaults to None
return_type – When set to ase returns a
ase.Atomsobject, when set to pymatgen returns apymatgen.core.structure.Structureobject, defaults to ‘ase’
- Returns:
One
ase.Atomsorpymatgen.core.structure.Structureinstance- Return type:
Union[Atoms, Structure]
There are three options one could use to specify and image or an atoms objects:
image_file +
**kwargsbuilder +
**kwargs.atoms
Examples
Some examples using builders from ASE. All
**kwargsare passed toase.build():>>> get_atoms(builder='molecule', name='H2O') Atoms(symbols='OH2', pbc=False) >>> get_atoms(builder='bulk', name='Cu') Atoms(symbols='Cu', pbc=True, ...) >>> get_atoms(builder='bulk', name='Ar', crystalstructure='fcc', a=3.4, cubic=True) Atoms(symbols='Ar4', pbc=True, cell=[3.4, 3.4, 3.4]) >>> get_atoms(builder='fcc100', symbol='Fe', vacuum=8, size=[4,4,5]) Atoms(symbols='Cu80', pbc=[True, True, False], ...)
You can also specify constraints to fix atoms in place, for example >>> get_atoms( # doctest: +ELLIPSIS … builder=’fcc100’, symbol=’Fe’, vacuum=8, size=[4,4,5], … constraints=[{‘constraint’: ‘FixAtoms’, ‘indices’: [0,1]}]) Atoms(symbols=’Cu80’, pbc=[True, True, False], …)
Some examples for reading an image from a file using
ase.io.read()are given below. All**kwargsare passed toase.io.read()>>> h2o = get_atoms(builder='molecule', name='H2O') >>> h2o.write('h2o.cif') >>> get_atoms(image_file='h2o.cif') Atoms(symbols='OH2', pbc=False) >>> get_atoms(image_file='h2o.cif', format='cif') Atoms(symbols='OH2', pbc=False) >>> from ase.io import write >>> molecules = [get_atoms(builder='molecule', name='H2O'), ... get_atoms(builder='molecule', name='H2')] >>> write('molecules.xyz', molecules, format='extxyz') >>> get_atoms(image_file='molecules.xyz', index=0) # Pick out one structure using indexing Atoms(symbols='OH2', pbc=False)
You can also make supercells and rattle the atoms or repeat to a target
>>> li_bulk = get_atoms(name='Li') >>> li_bulk.write('POSCAR', format='vasp') >>> get_atoms(image_file='POSCAR', repeat=[3,3,3]) Atoms(symbols='Li27', pbc=True, ...) >>> get_atoms( ... builder='bulk', name='Li', repeat=[2,2,2], rattle_stdev=0.01) Atoms(symbols='Li8', pbc=True, ...) >>> get_atoms( ... builder='bulk', name='Li', repeat_to_n_args={'n': 16, 'max_dim': 10.0}) Atoms(symbols='Li16', pbc=True, ...)
Mostly for internal use and use in asimmodules, one can specify atoms directly
>>> li_bulk = get_atoms(name='Li') >>> get_atoms(atoms=li_bulk) Atoms(symbols='Li', pbc=True, ...)
In an asimmodule, the
imageargument is always given as a dictionary, you therefore have to expand it before passing it toget_atoms>>> image = {'name': 'Pt'} >>> get_atoms(**image) Atoms(symbols='Pt', pbc=True, cell=[[0.0, 1.96, 1.96], [1.96, 0.0, 1.96], [1.96, 1.96, 0.0]])
To get a pymatgen structure object, set the return_type to “pymatgen”
>>> image = {'name': 'Pt', 'return_type': 'pymatgen'} >>> get_atoms(**image) Structure Summary Lattice ...
To download a structure from the Materials Project, you need to provide an API key, the MP ID of the structure and set the interface to ‘pymatgen’ You can also specify whether you want the primitive(default) or conventional unit cell as a keyword argument
>>> image = { ... 'mp_id': 'mp-14', 'interface': 'pymatgen', ... 'user_api_key': "USER_API_KEY", 'conventional_unit_cell': True} >>> get_atoms(**image) Structure Summary Lattice abc : 2.7718585822512662 2.7718585822512662 2.7718585822512662 ...
You can also specify a builder from pymatgen.core.structure or pymatgen.core.molecule, for example pymatgen.core.surface.Structure. The lattice paramters are passed as an ArrayLike with shape [3,3] to
pymatgen.core.lattice.Latticeor dictionary to thepymatgen.core.lattice.Lattice.from_parameters()function. >>> image = { # doctest: +ELLIPSIS … ‘builder’: ‘pymatgen.core.surface.Structure’, … ‘lattice’: {‘a’: 2.7, ‘b’: 2.7, ‘c’: 2.7, ‘alpha’: 90, ‘beta’: 90, ‘gamma’: 90}} >>> get_atoms(**image) Structure Summary Lattice abc : 2.7 2.7 2.7 …
- asimtools.utils.get_axis_lims(x: Sequence, y: Sequence, padding: float = 0.1)[source]
Get an estimate of good limits for a plot axis
- asimtools.utils.get_calc_input()[source]
Gets the global calc_input from the environment variable, then tries then
.asimtoolsdotfile- Returns:
calc_input dictionary or empty dictionary if not found
- Return type:
Dict
- asimtools.utils.get_env_input() Dict[source]
Gets the global env_input from the environment variable, then tries then
.asimtoolsdotfile. If an env_input.yaml is present in the work direcory, it takes precedence.- Returns:
env_input dictionary or empty dictionary if not found
- Return type:
Dict
- asimtools.utils.get_images(image_file: str | None = None, pattern: str | None = None, patterns: List[str] | None = None, images: Iterable[Atoms] | None = None, index: str | int = ':', skip_failed: bool = False, **kwargs) List[Atoms][source]
- Return a list of atoms objects based on the input arguments. Options
to specify are: #. image_file #. pattern #. patterns #. images
- Parameters:
image_file (str, optional) – Path to ASE-readable file with one or more images, defaults to None
pattern (str, optional) – String pattern of paths from which to search for images, defaults to None. This only gets the last image from each file as in
ase.io.read()if an index is not specified.patterns – Sequence of string patterns/paths from which to search for images, defaults to None. This only gets one image from each file as in
ase.io.read()without specifying an indeximages (Iterable[Atoms], optional) – A list of atoms objects, defaults to None
index (Union[str, int], optional) – Index to specify when using
ase.io.read(), defaults to ‘:’skip_failed (bool, optional) – Whether to raise an IO error if it fails to read any of the specified images or ignore errors, defaults to False
- Raises:
IOError – Failed to read one of the specified images
- Returns:
List of
ase.Atomsfor all images found- Return type:
List[Atoms]
There are three options one could use to specify and image or an atoms objects:
image_file + **kwargs for specifying one image file
pattern + **kwargs for specifying multiple image files with a wildcard character
patterns + **kwargs for specifying a list of patterns to match, captures the above two cases
images
Examples
Some examples for reading images selectively from an image_file. All
**kwargsare passed toase.io.read():>>> from asimtools.utils import get_atoms >>> molecules = [] >>> molecules.append(get_atoms(builder='molecule', name='H2O')) >>> molecules.append(get_atoms(builder='molecule', name='H2')) >>> molecules.append(get_atoms(builder='molecule', name='N2')) >>> write('molecules.xyz', molecules, format='extxyz') >>> get_images(image_file='molecules.xyz') [Atoms(symbols='OH2', pbc=False), ...] >>> get_images(image_file='molecules.xyz', index=':2') [Atoms(symbols='OH2', pbc=False), Atoms(symbols='H2', pbc=False)]
You can also use a wildcard (
*) by specifying the pattern argument. Notice that the files don’t have to be the same format if ASE can guess all the file formats, otherwise you can specify the format argument which should apply to all the images.>>> cu = get_atoms(name='Cu') >>> cu.write('bulk_cu.cfg') >>> fe = get_atoms(name='Fe') >>> fe.write('bulk_fe.cif') >>> pt = get_atoms(name='Pt') >>> pt.write('bulk_pt.cfg') >>> get_images(pattern='bulk*') [Atoms(symbols='Cu', ...), ...] >>> get_images(pattern='bulk*.cfg', format='cfg') [Atoms(symbols='Cu', ...), ...]
You can also specify multiple patterns
>>> get_images(patterns=['bulk*.cfg', 'bulk*.cif']) [Atoms(symbols='Cu', ...), ...]
Or you can directly pass a list of Atoms, mostly for internal use
>>> get_images(images=molecules) [Atoms(symbols='OH2', pbc=False), ...]
In an asimmodule, the
imagesargument is always given as a dictionary, you therefore have to expand it before passing it toget_images>>> images = {'pattern': 'bulk*'} >>> get_images(**images) [Atoms(symbols='Cu', ...), ...]
- asimtools.utils.get_logger(logfile='job.log', fstr='%(asctime)s |%(module)s|%(funcName)s| %(levelname)s: %(message)s', level='debug')[source]
Get the logger
- asimtools.utils.get_nth_label(string: PathLike, n: int = 1)[source]
Return nth label in a string potentially containing multiple labels, indexing starts from 0
- asimtools.utils.get_str_btn(string: str | PathLike, s1: str, s2: str, occurence: int | None = 0, start_index: int | None = 0)[source]
Returns the substring between strings s1 and s2 from string
- Parameters:
string (str) – string/path from which to extract substring
s1 (str) – substring before the desired substring, None starts from the beginning of s
s2 (str) – substring after the desired substring, None ends at the end of the string
occurence (int, optional) – which occurence to return e.g. occurence=1 returns the second time a substring is encountered, defaults to 0
start_index – first index from which to search for substring, defaults to 0
- Returns:
substring
- Return type:
_type_
- asimtools.utils.improve_plot(ax=None, fontsize=14)[source]
Apply standard formatting improvements to a matplotlib axis
- asimtools.utils.join_names(substrs: Sequence[str]) str[source]
Join multiple strings using a hyphen neatly
- asimtools.utils.parse_slice(value: str, bash: bool = False) slice[source]
Parses a
slice()from string, like start:stop:step.
- asimtools.utils.read_yaml(yaml_path: str) Dict[source]
Read a yaml file
- Parameters:
yaml_path (str) – Path to yaml file
- Returns:
Dictionary
- Return type:
Dict
- asimtools.utils.repeat_to_n(atoms: Atoms, n: int, max_dim: float = 50.0) Atoms[source]
Scale a structure to have approximately n atoms in the unit cell. The function repeats the shortest axis of the unit cell until the number of atoms >= n or the longest axis of the unit cell is > max_dim.
- Parameters:
- Raises:
ValueError – If it fails to scale the structure to n atoms
- Returns:
Scaled atoms object
- Return type:
Atoms
- asimtools.utils.strip_symbols(substr: str) str[source]
Helper function to format filenames using standard
- asimtools.utils.write_atoms(image_file: str, atoms: Atoms | list[Atoms], fmt: str = 'extxyz', write_info: bool = True, columns: Sequence | None = None, **kwargs)[source]
Writes image/images to a file. The default format is extxyz and the default columns are symbols and positions. All the images should have the same metadata
- Parameters:
image_file (str) – Path to file to write to
atoms (Atoms or list[Atoms]) – Atoms object or list of atoms objects to write
fmt (str) – Format to write, defaults to ‘extxyz’
write_info (bool) – Whether to write info, defaults to True
columns (Sequence, optional) – Columns to write, mostly for debugging, if used, specify all columns including positions, symbols etc. defaults to None,
kwargs (Any) – Extra keyword arguments passed to
ase.io.write()
- Raises:
ValueError – If the format is not supported
- Returns:
None
- Return type:
None
- asimtools.utils.write_csv_from_dict(fname: str, data: Dict, columns: Sequence | None = None, header: str = '', **kwargs) DataFrame[source]
Write a tabulated csv to a file from a dictionary. The keys will become the columns and the values will be the columns, All columns used must have the same length. kwargs are passed to
pandas.Dataframe.to_csv()- Parameters:
fname (str) – File name to be return to
data (Dict) – Dictionary to write
columns (Iterable, optional) – Keys to use as columns of csv, defaults to None
- Returns:
Pandas dataframe of results
- Return type:
pd.DataFrame
Module contents
asimtools: lightweight atomic simulation workflow manager.
- class asimtools.ChainedJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobJobs made of smaller sequential unitjobs. Note that this only works well with unit jobs. If one of the UnitJobs calls asimmodules, internally, slurm will fail to build the correct dependencies but the files will be generated appropriately, you can submit them manually
- class asimtools.DistributedJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobArray job object with ability to submit simultaneous jobs
- submit(**kwargs) list[int] | None[source]
Submit a job using slurm, interactively or in the current console
- submit_jobs(**kwargs) list[int] | None[source]
Submits the jobs. If submitting lots of batch jobs, we recommend using DistributedJob.submit_slurm_array
- class asimtools.Job(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None, asimrun_mode: bool = False)[source]
Bases:
objectAbstract class for the job object
- class asimtools.UnitJob(sim_input: dict, env_input: dict | None = None, calc_input: dict | None = None)[source]
Bases:
JobUnit job object with ability to submit a slurm/interactive job. Unit jobs run in a specific environment and if required, run a specific calculator. More complex workflows are built up of unit jobs
- asimtools.change_dict_value(dct: Dict, new_value, key_sequence: Sequence, return_copy: bool | None = True, placeholder: str | None = None) Dict[source]
Changes a value in the specified dictionary given by following the key sequence
- Parameters:
dct (Dict) – dictionary to be changed
new_value (_type_) – The new value that will replace the old one
key_sequence (Sequence) – List of keys in the order in which they access the dictionary key
return_copy (bool, optional) – Whether to return a copy only or to modify the dictionary in-place as well, defaults to True
- Returns:
The changed dictionary
- Return type:
Dict
- asimtools.change_dict_values(dct: Dict, new_values: Sequence, key_sequences: Sequence, return_copy: bool = True) Dict[source]
Changes values in the specified dictionary given by following the key sequences. Key-value pairs are set in the given order
- Parameters:
dct (Dict) – dictionary to be changed
new_values (Sequence) – The new values that will replace the old one
key_sequence (Sequence) – List of list of keys in the order in which they access the dictionary key
return_copy (bool, optional) – Whether to return a copy only or to modify the dictionary in-place as well, defaults to True
- Returns:
The changed dictionary
- Return type:
Dict
- asimtools.expand_wildcards(dct: Dict, root_path: PathLike | None = None) Dict[source]
Expands paths in a dictionary
- Parameters:
dct (Dict[str, Any]) – Dictionary to expand paths in
root_path (os.PathLike) – Root path to expand paths from
- Returns:
Dictionary with expanded paths
- Return type:
Dict[str, Any]
- asimtools.get_atoms(image_file: str | None = None, interface: str = 'ase', builder: str | None = 'bulk', atoms: Atoms | None = None, repeat: Tuple[int, int, int] | None = None, repeat_to_n_args: Dict | None = None, rattle_stdev: float | None = None, mp_id: str | None = None, user_api_key: str | None = None, return_type: str = 'ase', constraints: Sequence[dict] | None = None, **kwargs) Atoms | Structure[source]
Return an ASE Atoms or pymatgen Structure object based on specified config. This is the recommended way to load atoms objects for asimmodules.
- Parameters:
image_file (str, optional) – Path to an ASE-readable image file, defaults to None
interface (str, optional) – Whether to use “ase” or “pymatgen” to create the atoms object
builder (str, optional) – Builder to use from
ase.build, defaults to ‘bulk’. Any extra keyword arguments specified are passed to the buildatoms (Atoms, optional) –
ase.Atomsobject, defaults to Nonerepeat (Tuple[int, int, int], optional) – Number of times to repeat input to create supercell, defaults to None
rattle_stdev (float, optional) – stdev to be provided to
ase.Atoms.rattle(), or as distance topymatgen.core.structure.Structure.perturb()defaults to Nonemp_id (str, optional) – Material Project ID to fetch structure from, defaults to None
user_api_key (str, optional) – Material Project API key, must be provided to get structures from Materials Project, defaults to None
constraints (Sequence[dict], optional) – List of constraints to apply to the atoms object, currently only supports FixAtoms constraints, defaults to None
return_type – When set to ase returns a
ase.Atomsobject, when set to pymatgen returns apymatgen.core.structure.Structureobject, defaults to ‘ase’
- Returns:
One
ase.Atomsorpymatgen.core.structure.Structureinstance- Return type:
Union[Atoms, Structure]
There are three options one could use to specify and image or an atoms objects:
image_file +
**kwargsbuilder +
**kwargs.atoms
Examples
Some examples using builders from ASE. All
**kwargsare passed toase.build():>>> get_atoms(builder='molecule', name='H2O') Atoms(symbols='OH2', pbc=False) >>> get_atoms(builder='bulk', name='Cu') Atoms(symbols='Cu', pbc=True, ...) >>> get_atoms(builder='bulk', name='Ar', crystalstructure='fcc', a=3.4, cubic=True) Atoms(symbols='Ar4', pbc=True, cell=[3.4, 3.4, 3.4]) >>> get_atoms(builder='fcc100', symbol='Fe', vacuum=8, size=[4,4,5]) Atoms(symbols='Cu80', pbc=[True, True, False], ...)
You can also specify constraints to fix atoms in place, for example >>> get_atoms( # doctest: +ELLIPSIS … builder=’fcc100’, symbol=’Fe’, vacuum=8, size=[4,4,5], … constraints=[{‘constraint’: ‘FixAtoms’, ‘indices’: [0,1]}]) Atoms(symbols=’Cu80’, pbc=[True, True, False], …)
Some examples for reading an image from a file using
ase.io.read()are given below. All**kwargsare passed toase.io.read()>>> h2o = get_atoms(builder='molecule', name='H2O') >>> h2o.write('h2o.cif') >>> get_atoms(image_file='h2o.cif') Atoms(symbols='OH2', pbc=False) >>> get_atoms(image_file='h2o.cif', format='cif') Atoms(symbols='OH2', pbc=False) >>> from ase.io import write >>> molecules = [get_atoms(builder='molecule', name='H2O'), ... get_atoms(builder='molecule', name='H2')] >>> write('molecules.xyz', molecules, format='extxyz') >>> get_atoms(image_file='molecules.xyz', index=0) # Pick out one structure using indexing Atoms(symbols='OH2', pbc=False)
You can also make supercells and rattle the atoms or repeat to a target
>>> li_bulk = get_atoms(name='Li') >>> li_bulk.write('POSCAR', format='vasp') >>> get_atoms(image_file='POSCAR', repeat=[3,3,3]) Atoms(symbols='Li27', pbc=True, ...) >>> get_atoms( ... builder='bulk', name='Li', repeat=[2,2,2], rattle_stdev=0.01) Atoms(symbols='Li8', pbc=True, ...) >>> get_atoms( ... builder='bulk', name='Li', repeat_to_n_args={'n': 16, 'max_dim': 10.0}) Atoms(symbols='Li16', pbc=True, ...)
Mostly for internal use and use in asimmodules, one can specify atoms directly
>>> li_bulk = get_atoms(name='Li') >>> get_atoms(atoms=li_bulk) Atoms(symbols='Li', pbc=True, ...)
In an asimmodule, the
imageargument is always given as a dictionary, you therefore have to expand it before passing it toget_atoms>>> image = {'name': 'Pt'} >>> get_atoms(**image) Atoms(symbols='Pt', pbc=True, cell=[[0.0, 1.96, 1.96], [1.96, 0.0, 1.96], [1.96, 1.96, 0.0]])
To get a pymatgen structure object, set the return_type to “pymatgen”
>>> image = {'name': 'Pt', 'return_type': 'pymatgen'} >>> get_atoms(**image) Structure Summary Lattice ...
To download a structure from the Materials Project, you need to provide an API key, the MP ID of the structure and set the interface to ‘pymatgen’ You can also specify whether you want the primitive(default) or conventional unit cell as a keyword argument
>>> image = { ... 'mp_id': 'mp-14', 'interface': 'pymatgen', ... 'user_api_key': "USER_API_KEY", 'conventional_unit_cell': True} >>> get_atoms(**image) Structure Summary Lattice abc : 2.7718585822512662 2.7718585822512662 2.7718585822512662 ...
You can also specify a builder from pymatgen.core.structure or pymatgen.core.molecule, for example pymatgen.core.surface.Structure. The lattice paramters are passed as an ArrayLike with shape [3,3] to
pymatgen.core.lattice.Latticeor dictionary to thepymatgen.core.lattice.Lattice.from_parameters()function. >>> image = { # doctest: +ELLIPSIS … ‘builder’: ‘pymatgen.core.surface.Structure’, … ‘lattice’: {‘a’: 2.7, ‘b’: 2.7, ‘c’: 2.7, ‘alpha’: 90, ‘beta’: 90, ‘gamma’: 90}} >>> get_atoms(**image) Structure Summary Lattice abc : 2.7 2.7 2.7 …
- asimtools.get_images(image_file: str | None = None, pattern: str | None = None, patterns: List[str] | None = None, images: Iterable[Atoms] | None = None, index: str | int = ':', skip_failed: bool = False, **kwargs) List[Atoms][source]
- Return a list of atoms objects based on the input arguments. Options
to specify are: #. image_file #. pattern #. patterns #. images
- Parameters:
image_file (str, optional) – Path to ASE-readable file with one or more images, defaults to None
pattern (str, optional) – String pattern of paths from which to search for images, defaults to None. This only gets the last image from each file as in
ase.io.read()if an index is not specified.patterns – Sequence of string patterns/paths from which to search for images, defaults to None. This only gets one image from each file as in
ase.io.read()without specifying an indeximages (Iterable[Atoms], optional) – A list of atoms objects, defaults to None
index (Union[str, int], optional) – Index to specify when using
ase.io.read(), defaults to ‘:’skip_failed (bool, optional) – Whether to raise an IO error if it fails to read any of the specified images or ignore errors, defaults to False
- Raises:
IOError – Failed to read one of the specified images
- Returns:
List of
ase.Atomsfor all images found- Return type:
List[Atoms]
There are three options one could use to specify and image or an atoms objects:
image_file + **kwargs for specifying one image file
pattern + **kwargs for specifying multiple image files with a wildcard character
patterns + **kwargs for specifying a list of patterns to match, captures the above two cases
images
Examples
Some examples for reading images selectively from an image_file. All
**kwargsare passed toase.io.read():>>> from asimtools.utils import get_atoms >>> molecules = [] >>> molecules.append(get_atoms(builder='molecule', name='H2O')) >>> molecules.append(get_atoms(builder='molecule', name='H2')) >>> molecules.append(get_atoms(builder='molecule', name='N2')) >>> write('molecules.xyz', molecules, format='extxyz') >>> get_images(image_file='molecules.xyz') [Atoms(symbols='OH2', pbc=False), ...] >>> get_images(image_file='molecules.xyz', index=':2') [Atoms(symbols='OH2', pbc=False), Atoms(symbols='H2', pbc=False)]
You can also use a wildcard (
*) by specifying the pattern argument. Notice that the files don’t have to be the same format if ASE can guess all the file formats, otherwise you can specify the format argument which should apply to all the images.>>> cu = get_atoms(name='Cu') >>> cu.write('bulk_cu.cfg') >>> fe = get_atoms(name='Fe') >>> fe.write('bulk_fe.cif') >>> pt = get_atoms(name='Pt') >>> pt.write('bulk_pt.cfg') >>> get_images(pattern='bulk*') [Atoms(symbols='Cu', ...), ...] >>> get_images(pattern='bulk*.cfg', format='cfg') [Atoms(symbols='Cu', ...), ...]
You can also specify multiple patterns
>>> get_images(patterns=['bulk*.cfg', 'bulk*.cif']) [Atoms(symbols='Cu', ...), ...]
Or you can directly pass a list of Atoms, mostly for internal use
>>> get_images(images=molecules) [Atoms(symbols='OH2', pbc=False), ...]
In an asimmodule, the
imagesargument is always given as a dictionary, you therefore have to expand it before passing it toget_images>>> images = {'pattern': 'bulk*'} >>> get_images(**images) [Atoms(symbols='Cu', ...), ...]
- asimtools.get_str_btn(string: str | PathLike, s1: str, s2: str, occurence: int | None = 0, start_index: int | None = 0)[source]
Returns the substring between strings s1 and s2 from string
- Parameters:
string (str) – string/path from which to extract substring
s1 (str) – substring before the desired substring, None starts from the beginning of s
s2 (str) – substring after the desired substring, None ends at the end of the string
occurence (int, optional) – which occurence to return e.g. occurence=1 returns the second time a substring is encountered, defaults to 0
start_index – first index from which to search for substring, defaults to 0
- Returns:
substring
- Return type:
_type_
- asimtools.join_names(substrs: Sequence[str]) str[source]
Join multiple strings using a hyphen neatly
- asimtools.load_calc(calculator: Dict | None = None, calc_id: str | None = None, calc_input: Dict | None = None, calc_params: Dict | None = None)[source]
Loads a calculator using a calculator dict or legacy calc_id/calc_params arguments.
- Parameters:
calculator (Optional[Dict], optional) – Dictionary with either a
calc_idkey (to look up from the global or supplied calc_input) or acalc_paramskey (to use directly). Takes precedence over the legacy arguments if provided, defaults to Nonecalc_id (str, optional) – Deprecated — use
calculator={'calc_id': ...}instead. ID/key to use to load calculator from the supplied or global calc_input file, defaults to Nonecalc_input – calc_input dictionary, same form as calc_input yaml :type calc_input: Optional[Dict], optional
calc_params (Optional[Dict], optional) – Deprecated — use
calculator={'calc_params': ...}instead. calc_params dictionary for a single calculator, defaults to None
- Returns:
ASE calculator instance
- Return type:
ase.calculators.calculators.Calculator
- asimtools.read_yaml(yaml_path: str) Dict[source]
Read a yaml file
- Parameters:
yaml_path (str) – Path to yaml file
- Returns:
Dictionary
- Return type:
Dict
- asimtools.repeat_to_n(atoms: Atoms, n: int, max_dim: float = 50.0) Atoms[source]
Scale a structure to have approximately n atoms in the unit cell. The function repeats the shortest axis of the unit cell until the number of atoms >= n or the longest axis of the unit cell is > max_dim.
- Parameters:
- Raises:
ValueError – If it fails to scale the structure to n atoms
- Returns:
Scaled atoms object
- Return type:
Atoms
- asimtools.write_atoms(image_file: str, atoms: Atoms | list[Atoms], fmt: str = 'extxyz', write_info: bool = True, columns: Sequence | None = None, **kwargs)[source]
Writes image/images to a file. The default format is extxyz and the default columns are symbols and positions. All the images should have the same metadata
- Parameters:
image_file (str) – Path to file to write to
atoms (Atoms or list[Atoms]) – Atoms object or list of atoms objects to write
fmt (str) – Format to write, defaults to ‘extxyz’
write_info (bool) – Whether to write info, defaults to True
columns (Sequence, optional) – Columns to write, mostly for debugging, if used, specify all columns including positions, symbols etc. defaults to None,
kwargs (Any) – Extra keyword arguments passed to
ase.io.write()
- Raises:
ValueError – If the format is not supported
- Returns:
None
- Return type:
None