ipsuite.utils package

Submodules

ipsuite.utils.ase_sim module

Utils that help running simulations with ASE.

ipsuite.utils.ase_sim.freeze_copy_atoms(atoms) Atoms[source]
ipsuite.utils.ase_sim.freeze_copy_atoms(atoms: list) list[Atoms]
ipsuite.utils.ase_sim.get_box_from_density(data: list[list[Atoms]], count: list[int], density: float) list[float][source]

Get the box size from the molar volume.

Attributes

data: list[list[ase.Atoms]]

List of list of atoms objects. The last atoms object is used to compute the molar volume.

count: list[int]

Number of molecules for each entry in data.

density: float

Density of the system in kg/m^3.

ipsuite.utils.ase_sim.get_density_from_atoms(atoms: Atoms) float[source]

Compute the density of the atoms in kg/m3.

ipsuite.utils.ase_sim.get_desc(temperature: float, total_energy: float)[source]

TQDM description.

ipsuite.utils.ase_sim.get_energy(atoms: Atoms) Tuple[float, float][source]

Compute the temperature and the total energy.

Parameters

atoms: ase.Atoms

Atoms objects for which energy will be calculated

Returns

temperature: float

temperature of the system

np.squeeze(total): float

total energy of the system

ipsuite.utils.combine module

Helpers to work with inputs from multiple nodes.

class ipsuite.utils.combine.ExcludeIds(data: list | dict, ids: list | dict)[source]

Bases: object

Remove entries from a dataset.

data: list | dict
get_clean_data(flatten: bool = False) list[source]

Remove the ‘ids’ from the ‘data’.

get_original_ids(ids: list, per_key: bool = False) list[source]

Shift the ‘ids’ such that they are valid for the initial data.

ids: list | dict
property ids_as_list: list
ipsuite.utils.combine.get_flat_data_from_dict(data: dict, silent_ignore: bool = False) list[source]

Flatten a dictionary of lists into a single list.

Parameters

datadict

Dictionary of lists.

silent_ignorebool, optional

If True, the function will return the input if it is not a dictionary. If False, it will raise a TypeError.

Example

>>> data = {'a': [1, 2, 3], 'b': [4, 5, 6]}
>>> get_flat_data_from_dict(data)
[1, 2, 3, 4, 5, 6]
ipsuite.utils.combine.get_ids_per_key(data: dict, ids: list, silent_ignore: bool = False) Dict[str, list][source]

Get the ids per key from a dictionary of lists.

Parameters

datadict

Dictionary of lists.

idslist

List of ids. The ids are assumed to be taken from the flattened ‘get_flat_data_from_dict(data)’ data. If the ids aren’t sorted, they will be sorted.

silent_ignorebool, optional

If True, the function will return the input if it is not a dictionary. If False, it will raise a TypeError.

Example

>>> data = {'a': [1, 2, 3], 'b': [4, 5, 6]}
>>> get_ids_per_key(data, [0, 1, 3, 5])
{'a': [0, 1], 'b': [0, 2]}

ipsuite.utils.helpers module

ipsuite helper modules.

ipsuite.utils.helpers.check_duplicate_keys(dict_a: dict, dict_b: dict, log: Logger) None[source]

Check if a key of dict_a is present in dict_b and then log a warning.

ipsuite.utils.helpers.get_deps_if_node(obj, attribute: str)[source]

Apply getdeps if obj is subclass/instance of a Node.

Parameters

obj: any

Any object that is either a Node or not.

attribute: str

Name of the attribute to get.

Returns

Either the requested attribute if obj is a Node. Otherwise, it will return the obj itself.

ipsuite.utils.helpers.lower_dict(d)[source]
ipsuite.utils.helpers.setup_ase()[source]

Add uncertainty keys to ASE all properties.

ipsuite.utils.logs module

Logging Setup for the ipsuite package.

ipsuite.utils.logs.setup_logging(name) None[source]

Configure logging for the ipsuite package.

ipsuite.utils.md module

ipsuite.utils.md.get_energy_terms(atoms: Atoms) Tuple[float, float, float][source]

Returns total, kinetic and potentials energy terms. Useful for seeing whether the total energy is conserved in an NVE simulation.

Parameters

atoms: ase.Atoms

Atoms objects for which energy will be calculated

Returns

etot: float

total energy per atom

ekin: float

kinetic energy per atom

epot: float

potential energy per atom

ipsuite.utils.metrics module

Utils for computing metrics.

ipsuite.utils.metrics.calculate_l_p_norm(y_true: ndarray, y_pred: ndarray, p: int = 2)[source]

Calculate the mean of the l_p_norm of given data.

\[l_{p} = \frac{1}{N} \sum_{i}^{N} \left| x_{i} - x_{i}^{\text{true}}\right|^{p}.\]

Parameters

y_true: np.ndarray

reference values with shape (b,)

y_pred: np.ndarray

values to compare reference with shape (b,)

p: int

order of the Lp norm

Returns

mean: float

mean of the lp norm of the given data.

ipsuite.utils.metrics.get_angles(vec1, vec2) ndarray[source]

Compute the angle between two vectors.

ipsuite.utils.metrics.get_full_metrics(true: ndarray, prediction: ndarray) dict[source]

Calculate metrics for a given true and predicted value.

ipsuite.utils.metrics.get_u_vecs(vector)[source]

Get unit vectors from a vector array.

ipsuite.utils.metrics.maximum_error(y_true, y_pred)[source]

Calculate the maximum error.

ipsuite.utils.metrics.mean_absolute_error(data_a, data_b)[source]

Calculate the mean absolute error.

ipsuite.utils.metrics.mean_squared_error(data_a, data_b)[source]

Calculate the mean squared error between data_ids.

ipsuite.utils.metrics.relative_rmse(true, pred)[source]

Calculate the relative root mean squared error between data_ids.

ipsuite.utils.metrics.root_mean_squared_error(data_a, data_b)[source]

Calculate the root mean squared error between data_ids.

Module contents

ipsuite utils module.