Main

This module is the main part of the Amp package.

Module contents

class amp.Amp(descriptor, model, label='amp', dblabel=None, cores=None, envcommand=None, logging=True, atoms=None)[source]

Bases: Calculator, object

Atomistic Machine-Learning Potential (Amp) ASE calculator

Parameters:
  • descriptor (object) – Class representing local atomic environment.

  • model (object) – Class representing the regression model. Can be only NeuralNetwork for now. Input arguments for NeuralNetwork are hiddenlayers, activation, weights, and scalings; for more information see docstring for the class NeuralNetwork.

  • label (str) – Default prefix/location used for all files. Setting to None disables logging.

  • dblabel (str, None, or False) – Prefix/location for fingerprint database files (neighborlists, fingerprints, fingerprint derivatives). If None, defaults to label. Set to False to disable all disk writes and keep fingerprints only in memory, discarding each image’s data as soon as it is used; this is the default when loading via Amp.load() since inference and MD runs rarely revisit the same image. A shared string path lets multiple calculator instances reuse the same on-disk cache.

  • cores (int) – Can specify cores to use for parallel training; if None, will determine from environment

  • envcommand (string) – For parallel processing across nodes, a command can be supplied here to load the appropriate environment before starting workers.

  • logging (boolean) – Option to turn off logging; e.g., to speed up force calls.

  • atoms (object) – ASE atoms objects with positions, symbols, energy, and forces in ASE format.

calculate(atoms, properties, system_changes)[source]

Calculation of the energy of system and forces of all atoms. If charge learning mode is applied, calculation of the atomic charges of all atoms also is performed

property cores

Get or set the cores for the parallel environment.

Parameters:

cores (int or dictionary) – Parallel configuration. If cores is an integer, parallelizes over this many processes on machine localhost. cores can also be a dictionary of the type {‘node324’: 16, ‘node325’: 16}. If not specified, tries to determine from environment, using amp.utilities.assign_cores.

property descriptor

Get or set the atomic descriptor.

Parameters:

descriptor (object) – Class instance representing the local atomic environment.

implemented_properties: list[str] = ['energy', 'forces', 'charges']

Properties calculator can handle (energy, forces, …)

property label
classmethod load(file, Descriptor=None, Model=None, dblabel=False, **kwargs)[source]

Attempts to load calculators and return a new instance of Amp.

Only a filename or file-like object is required, in typical cases.

If using a home-rolled descriptor or model, also supply uninstantiated classes to those models, as in Model=MyModel. (Not as Model=MyModel()!)

Additional keyword arguments (such as label) are fed through to Amp.

Parameters:
  • file (str) – Name of the file to load data from.

  • Descriptor (object) – Class representing local atomic environment.

  • Model (object) – Class representing the regression model.

  • dblabel (str, None, or False) – Database label; defaults to ‘False’ here, meaning fingerprints, etc., are not saved to disk (typically preferred for inference)

property model

Get or set the machine-learning model.

Parameters:

model (object) – Class instance representing the regression model.

save(filename, overwrite=False)[source]

Saves the calculator in a way that it can be re-opened with load.

Parameters:
  • filename (str) – File object or path to the file to write to.

  • overwrite (bool) – If an output file with the same name exists, overwrite it.

set(**kwargs)[source]

Function to set parameters.

For now, this doesn’t do anything as all parameters are within the model and descriptor.

train(images, overwrite=False, max_attempts=1)[source]

Fits the model to the training images.

Parameters:
  • images (list or str) – List of ASE atoms objects with positions, symbols, energies, and forces in ASE format. This is the training set of data. This can also be the path to an ASE trajectory (.traj) or database (.db) file. Energies can be obtained from any reference, e.g. DFT calculations.

  • overwrite (bool) – If an output file with the same name exists, overwrite it.

  • max_attempts (int) – Maximum number of training attempts. If training does not converge, the model weights (including packed biases) are reset to new random values and training is retried. The first attempt always uses whatever weights are currently on the model (e.g., from a loaded checkpoint); randomization only applies to subsequent attempts. Fingerprints are computed only once and reused across attempts. Default is 1 (no retries).

amp.get_git_commit(ampdirectory)[source]

Attempts to get the last git commit from the amp directory.

amp.importhelper(importname)[source]

Manually compiled list of available modules.

This is to prevent the execution of arbitrary (potentially malicious) code.

However, since there is an eval statement in string2dict maybe this is silly.