Configurations

The MFF package uses training and testing data extracted from .xyz files. The mff.configurations module contains the function carve_confs which is used to save .npy files containing local atomic environments, the forces acting on the central atoms of these local atomic environments and, if present, the energy associated with the snapshot the local environment has been extracted from. To extract local atomic environments, forces, energies and a list of all the elements contained in an ase atoms object:

from ase.io import read
from mff.configurations import carve_confs
traj = read(filename, format='extxyz')
elements, confs, forces, energies = carve_confs(traj, r_cut, n_data)

where r_cut specifies the cutoff radius that will be applied to extract local atomic environments containing all atomis within r_cut from the central one, and n_data specifies the total number of local atomic environments to extract.

exception mff.configurations.MissingData
mff.configurations.carve_from_snapshot(atoms, r_cut, forces_label=None, energy_label=None, atoms_ind=None)

Extract atomic configurations, the forces acting on the central atoms os said configurations, and the local energy values associated to a single atoms object.

Parameters
  • atoms (ase atoms object) – Ase atoms file, opened with ase.io.read

  • atoms_ind (list) – indexes of the atoms for which a conf is created

  • r_cut (float) – Cutoff to use when carving out atomic environments

  • forces_label (str) – Name of the force label in the trajectory file, if None default is “forces”

  • energy_label (str) – Name of the energy label in the trajectory file, if None default is “energy”

Returns

List of M by 5 numpy arrays, where M is the number of atoms within

r_cut from the central one. The first 3 components are positions w.r.t the central atom in Angstroms, the fourth is the atomic number of the central atom, the fifth the atomic number of each atom.

forces (array): x,y,z components of the force acting on the central atom in eV/Angstrom energies (array): value of the local atomic energy in eV

Return type

confs (list of arrays)

mff.configurations.generate(traj, r_cut, forces_label=None, energy_label=None)

Extract atomic configurations, the forces acting on the central atoms os said configurations, and the local energy values associeated.

Parameters
  • traj (ase atoms object) – Ase trajectory file, opened with ase.io.read

  • r_cut (float) – Cutoff to use when carving out atomic environments

  • forces_label (str) – Name of the force label in the trajectory file, if None default is “forces”

  • energy_label (str) – Name of the energy label in the trajectory file, if None default is “energy”

Returns

Structure containing, for each snapshot in the trajectory,

the forces, energy, and local atomic configurations for that snapshot’s atoms

Return type

data (dictionary)

mff.configurations.generate_and_save(path, r_cut, forces_label=None, energy_label=None, index=':')

Generate the data dictionary and save it to the same location. :param path: Name and position of trajectory file :type path: Path or string :param r_cut: Cutoff used :type r_cut: float :param forces_label: Name of the force label in the trajectory file, if None default is “forces” :type forces_label: str :param energy_label: Name of the energy label in the trajectory file, if None default is “energy” :type energy_label: str :param index: Indexes indicating which snapshots to use from the traj file :type index: str

Returns

Structure containing, for each snapshot in the trajectory,

the forces, energy, and local atomic configurations for that snapshot’s atoms. Obtained from generate

Return type

data (dict)

mff.configurations.load(path, r_cut)

Load data saved with save

Parameters
  • path (Path or string) – Name and position of file to load data from

  • r_cut (float) – Cutoff used

Returns

Structure containing, for each snapshot in the trajectory,

the forces, energy, and local atomic configurations for that snapshot’s atoms. Obtained from generate

Return type

data (dict)

mff.configurations.load_and_unpack(path, r_cut)

Load data saved with save and unpack it with unpak

Parameters
  • path (Path or string) – Name and position of file to load data from

  • r_cut (float) – Cutoff used

Returns

Atomic numbers of all atomic species present in the dataset confs (list of arrays): List of M by 5 numpy arrays, where M is the number of atoms within

r_cut from the central one. The first 3 components are positions w.r.t the central atom in Angstroms, the fourth is the atomic number of the central atom, the fifth the atomic number of each atom.

forces (array): x,y,z components of the force acting on the central atom in eV/Angstrom energies (array): value of the total energy in eV global_confs (list of lists of arrays): list containing lists of configurations, grouped together

so that local atomic environments taken from the same snapshot are in the same group.

Return type

elements (list)

mff.configurations.save(path, r_cut, data)

Save data extracted with generate to a file with a iven cutoff

Parameters
  • path (Path or string) – Name and position of file to save data to

  • r_cut (float) – Cutoff used

  • data (dict) – Structure containing, for each snapshot in the trajectory, the forces, energy, and local atomic configurations for that snapshot’s atoms. Obtained from generate

mff.configurations.unpack(data)
From a data dictionary, generate elements, configurations, forces, energies and

global configurations to be used by the GP module.

Parameters

data (dict) – Structure containing, for each snapshot in the trajectory, the forces, energy, and local atomic configurations for that snapshot’s atoms. Obtained from generate

Returns

Atomic numbers of all atomic species present in the dataset confs (list of arrays): List of M by 5 numpy arrays, where M is the number of atoms within

r_cut from the central one. The first 3 components are positions w.r.t the central atom in Angstroms, the fourth is the atomic number of the central atom, the fifth the atomic number of each atom.

forces (array): x,y,z components of the force acting on the central atom in eV/Angstrom energies (array): value of the total energy in eV global_confs (list of lists of arrays): list containing lists of configurations, grouped together

so that local atomic environments taken from the same snapshot are in the same group.

Return type

elements (list)