wfl.utils package#
Submodules#
wfl.utils.at_copy_save_results module#
- wfl.utils.at_copy_save_results.at_copy_save_results(at, properties=None, results_prefix=None)#
wfl.utils.configs module#
- wfl.utils.configs.atomization_energy(inputs, outputs, prop_prefix, prop='energy', isolated_atom_info_key='config_type', isolated_atom_info_value='default')#
Calculates atomization energy.
- Parameters
inputs (list[Atoms] or ConfigSet) – all configs, including isolated atoms
outputs (OutputSpec) – for saving structures with atomization energies
prop_prefix (str) – prefix for reading total energy (e.g. Atoms.info[f”{prop_prefix}energy”]) and saving atomization energy (Atoms.info[f”{prop_prefix}atomization_energy”])
prop (str, default "energy") – name for property to read from Atoms.info (Atoms.info[“{prop_prefix}{prop}])
isolated_atom_info_key (str, default "config_type") – key for Atoms.info to select isolated atoms by
isolated_atom_info_value (str, default "default") – value of Atoms.info[isolated_atom_info_key] to match isolated atoms on “default” matches “isolated_atom” or “IsolatedAtom”.
- wfl.utils.configs.find_isolated_atoms(inputs, outputs, isolated_atom_info_key='config_type', isolated_atom_info_value='default')#
Finds isolated atoms in among all configs.
- Parameters
inputs (list[Atoms] or ConfigSet) – all configs to search through
outputs (OutputSpec) – where to save isolated atoms to
isolated_atom_info_key (str, default "config_type") – key for Atoms.info to select isolated atoms by
isolated_atom_info_value (str, default "default") – value of Atoms.info[isolated_atom_info_key] to match isolated atoms on “default” matches “isolated_atom” or “IsolatedAtom”.
wfl.utils.convex_hull module#
- wfl.utils.convex_hull.find_hull(ps, below=True)#
find convex hull of set of points
- Parameters
ps (ndarray(n_ps, n_dim)) – array of positions in arbitrary dim space
below (bool, default True) – only return parts of hull that are “below” all of the other points, i.e. lowest values of n_dim-1 component (assumed to be energy)
- Returns
points (ndarray(n_hull_ps, n_dim)) – points on hull
indices (list(int)) – list of indices of hull points
equations (ConvexHull.equations) – equations representing convex hull simplices
simplices (list(list(int))) – list of indices in each hull simplex
- wfl.utils.convex_hull.vertical_dist_from_hull(equations, p)#
wfl.utils.file_utils module#
- wfl.utils.file_utils.clean_dir(directory, keep_files, force=False)#
Clean a run directory and keep only the specified files
- Parameters
directory (directory to be cleaned) –
keep_files (bool or list(filenames) or str) –
- What to keep in rundir when done:
list(filenames) : ONLY these filenames if they exist
True or “*” : everything - does nothing
False or None : remove everything, or anything evaluating to False in if
force (bool, default = False) – fail if directory does not exist
wfl.utils.gap_xml_tools module#
Tools for GAP xml file operations
- wfl.utils.gap_xml_tools.extract_e0(filename='GAP.xml', include_zeros=False)#
Extracts e0 values from a GAP xml file.
- Parameters
filename (path_like) – GAP xml file
include_zeros (bool) – include zero e0 values, gives a dict complete for all elements
- Returns
e0_data – symbol -> e0_value
- Return type
dict
wfl.utils.logging module#
- wfl.utils.logging.increment_active_iter(active_iter)#
- wfl.utils.logging.print_log(msg, show_time=True, logfile=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)#
- wfl.utils.logging.process_active_iter(active_iter)#
wfl.utils.misc module#
Miscellaneous utilities
This should be temporary and reorganised when there is more, or just make one utils file if there is not much.
- wfl.utils.misc.atoms_to_list(atoms)#
- wfl.utils.misc.chunks(arr, n)#
Yield successive n-sized chunks from arr
- Parameters
arr (list-like) –
n (int) – length of chunks
- Yields
arr_chunk (array_like)
- wfl.utils.misc.dict_tuple_keys_to_str(error_dict)#
Convert tuple keys to strings so Dict is JSON serializable
- Parameters
error_dict (dict) –
- Returns
error_dict_json_compatible
- Return type
dict
wfl.utils.ndim_neighbor_list module#
- wfl.utils.ndim_neighbor_list.calc_list(positions, ranges, cartesian_distance=True)#
simple and naive neighbor list in arbitrary dimensions
- Parameters
positions (ndarray(n_positions, n_dims)) – Array of positions to compute neighbors of
ranges (ndarray(n_dims)) – Ranges to use as neighbor cutoff in each dimension
cartesian_distance (bool, default True) – Calculate neighbor list using Cartesian distance (i.e. nearby hyperoval). If False, use a rectilinear prism, i.e. distance in every dimension must be less than range.
- Returns
i, j – corresponding lists of i-j neighbor pairs indices
- Return type
list(neighbor_pairs), list(neighbor_pairs)
- wfl.utils.ndim_neighbor_list.calc_list_cells(positions, ranges, Cartesian_distance=True)#
Linear scaling (at constant _density_) neighbor list in arbitrary dimensions, based on core of ase.neighborlist.neighbor_list
- Parameters
positions (ndarray(n_positions, n_dims)) – array of positions to compute neighbors of
ranges (ndarray(n_dims)) – ranges to use as neighbor cutoff in each dimension
Cartesian_distance (bool, default True) – Calculate neighbor list using Cartesian distance (i.e. nearby hyperoval). If False, use a rectilinear prism, i.e. distance in every dimension must be less than range.
- Returns
i, j – corresponding lists of i-j neighbor pairs indices
- Return type
list(neighbor_pairs), list(neighbor_pairs)
wfl.utils.parallel module#
- wfl.utils.parallel.construct_calculator_picklesafe(calculator)#
Constructs a calculator safe with multiprocessing.Pool
Trick: pass a recipe only and create the calculator in the thread created, instead of trying to pickle the entire object when creating the pool.
Taken from optimize.py:run_autopara_wrappable
- Parameters
calculator (Calculator / (initializer, args, kwargs)) – ASE calculator or routine to call to create calculator
- Returns
calculator – ase calculator object
- Return type
Calculator
wfl.utils.params module#
wfl.utils.pressure module#
- exception wfl.utils.pressure.PressureRecursionError#
Bases:
BaseException
- wfl.utils.pressure.sample_pressure(pressure, at=None, rng=None)#
Sample pressure for calculation with various modes
- Parameters
pressure (float / list / tuple) –
- Pressure, type and length defines mode as well
float: used as pressure
(“info”, dict_key): looks for dict_key in at.info, parsed same as pressure argument here
(“exponential”, float): exponential distribution, rate=1. and scaled by float given
(“normal_positive”, mean, sigma): normal distribution with (mean, sigma) thrown away if negative value drawn, max 1000 tries
(“uniform”, lower, upper): uniform distribution between bounds (lower, upper)
at (ase.Atoms, default None) – atoms object, only needed or used if mode is info
rng (numpy Generator object, default None) – random number generator to use. Only required if pressure will be generated randomly
- Returns
p
- Return type
float
wfl.utils.quip_cli_strings module#
QUIP-related string manipulations
- wfl.utils.quip_cli_strings.dict_to_quip_str(d, list_brackets='{}')#
dictionary to QUIP CLI string
- Parameters
d (dict) – descriptor key-value pairs
list_brackets (str, default '{}') – string containing open and close symbols for lists (usually ‘{}’ or ‘{{}}’)
- Returns
str
- Return type
descriptor string
wfl.utils.replace_eval_in_strs module#
Evaluation of expressions marked with _EVAL_ in strings, mainly used for interpreting config files.
- wfl.utils.replace_eval_in_strs.replace_eval_in_strs(obj, replacements, n_float_sig_figs=None)#
Replace some string beginning with _EVAL_ in nested data structures with the result of eval() on them. Any lists, tuples, and dicts will be gone through recursively and replaced with substituted contents. Any strings starting with ‘_EVAL_ ‘ will be replaced with the result of an eval() call on the remainder of the string, after replacements has been used as the kwargs of a format() call.
- Parameters
obj (python object) – data structure to go through and replace ‘_EVAL_ …’ with return value of eval()
replacements (dict) – keywords to format() call to be applied to each string before eval()
n_float_sig_figs (int) – if not None, round float output of each eval to this many significant figures
- Returns
obj – their eval() result
- Return type
python object with new lists, tuples, and dicts, with _EVAL_ strings replaced by
wfl.utils.round_sig_figs module#
Rounding floats to significant figures
- wfl.utils.round_sig_figs.round_sig_figs(value, n_sig_figs)#
Round to a certain number of significant figures
based on: https://stackoverflow.com/questions/3410976/how-to-round-a-number-to-significant-figures-in-python
- Parameters
value (float) – value to round
n_sig_figs (int) – number of significant figures
- Return type
string representation of v, rounded to n_sig_figs significant figures
wfl.utils.vol_composition_space module#
- wfl.utils.vol_composition_space.composition_space_Zs(ats)#
Elements from composition space
- Parameters
ats (list(Atoms)) –
- Returns
Zs – set of atomic numbers found, sorted
- Return type
list(int)
- wfl.utils.vol_composition_space.composition_space_coord(at, fields, composition_Zs=None)#
Calculate coordinates in vol-composition space
- Parameters
at (Atoms) –
fields (list(str)) – fields of atoms objects to find: - “_V”: volume per atom - “_x”: compositions, n_elements-1 - any at.info key which is then divided by the number of atoms
composition_Zs (list(int)) – atomic numbers of elements for composition space
- Returns
coords – coordinates, with volume and n_species-1 dimensions
- Return type
list(float)