On-the-Fly Training

class flare.otf.OTF(dt: float, number_of_steps: int, prev_pos_init: ndarray = None, rescale_steps: List[int] = [], rescale_temps: List[int] = [], gp: flare.gp.GaussianProcess = None, calculate_energy: bool = False, calculate_efs: bool = False, write_model: int = 0, force_only: bool = True, std_tolerance_factor: float = 1, skip: int = 0, init_atoms: List[int] = None, output_name: str = 'otf_run', max_atoms_added: int = 1, freeze_hyps: int = 10, min_steps_with_model: int = 0, update_style: str = 'add_n', update_threshold: float = None, force_source: str = 'qe', npool: int = None, mpi: str = 'srun', dft_loc: str = None, dft_input: str = None, dft_output='dft.out', dft_kwargs=None, store_dft_output: Tuple[Union[str, List[str]], str] = None, n_cpus: int = 1, **kwargs)
Trains a Gaussian process force field on the fly during
molecular dynamics.
Parameters:
  • dt (float) – MD timestep.
  • number_of_steps (int) – Number of timesteps in the training simulation.
  • prev_pos_init ([type], optional) – Previous positions. Defaults to None.
  • rescale_steps (List[int], optional) – List of frames for which the velocities of the atoms are rescaled. Defaults to [].
  • rescale_temps (List[int], optional) – List of rescaled temperatures. Defaults to [].
  • gp (gp.GaussianProcess) – Initial GP model.
  • calculate_energy (bool, optional) – If True, the energy of each frame is calculated with the GP. Defaults to False.
  • calculate_efs (bool, optional) – If True, the energy and stress of each frame is calculated with the GP. Defaults to False.
  • write_model (int, optional) – If 0, write never. If 1, write at end of run. If 2, write after each training and end of run. If 3, write after each time atoms are added and end of run. If 4, write after each training and end of run, and back up after each write.
  • force_only (bool, optional) – If True, only use forces for training. Default to False, use forces, energy and stress for training.
  • std_tolerance_factor (float, optional) – Threshold that determines when DFT is called. Specifies a multiple of the current noise hyperparameter. If the epistemic uncertainty on a force component exceeds this value, DFT is called. Defaults to 1.
  • skip (int, optional) – Number of frames that are skipped when dumping to the output file. Defaults to 0.
  • init_atoms (List[int], optional) – List of atoms from the input structure whose local environments and force components are used to train the initial GP model. If None is specified, all atoms are used to train the initial GP. Defaults to None.
  • output_name (str, optional) – Name of the output file. Defaults to ‘otf_run’.
  • max_atoms_added (int, optional) – Number of atoms added each time DFT is called. Defaults to 1.
  • freeze_hyps (int, optional) – Specifies the number of times the hyperparameters of the GP are optimized. After this many updates to the GP, the hyperparameters are frozen. Defaults to 10.
  • min_steps_with_model (int, optional) – Minimum number of steps the model takes in between calls to DFT. Defaults to 0.
  • force_source (Union[str, object], optional) – DFT code used to calculate ab initio forces during training. A custom module can be used here in place of the DFT modules available in the FLARE package. The module must contain two functions: parse_dft_input, which takes a file name (in string format) as input and returns the positions, species, cell, and masses of a structure of atoms; and run_dft_par, which takes a number of DFT related inputs and returns the forces on all atoms. Defaults to “qe”.
  • npool (int, optional) – Number of k-point pools for DFT calculations. Defaults to None.
  • mpi (str, optional) – Determines how mpi is called. Defaults to “srun”.
  • dft_loc (str) – Location of DFT executable.
  • dft_input (str) – Input file.
  • dft_output (str) – Output file.
  • dft_kwargs ([type], optional) – Additional arguments which are passed when DFT is called; keyword arguments vary based on the program (e.g. ESPRESSO vs. VASP). Defaults to None.
  • store_dft_output (Tuple[Union[str,List[str]],str], optional) – After DFT calculations are called, copy the file or files specified in the first element of the tuple to a directory specified as the second element of the tuple. Useful when DFT calculations are expensive and want to be kept for later use. The first element of the tuple can either be a single file name, or a list of several. Copied files will be prepended with the date and time with the format ‘Year.Month.Day:Hour:Minute:Second:’.
  • n_cpus (int, optional) – Number of cpus used during training. Defaults to 1.
compute_properties()

In ASE-OTF, it will be replaced by subclass method

md_step()

Take an MD step. This updates the positions of the structure.

rescale_temperature(new_pos: ndarray)

Change the previous positions to update the temperature

Parameters:new_pos (np.ndarray) – Positions of atoms in the next MD frame.
run()

Performs an on-the-fly training run.

If OTF has store_dft_output set, then the specified DFT files will be copied with the current date and time prepended in the format ‘Year.Month.Day:Hour:Minute:Second:’.

run_dft()

Calculates DFT forces on atoms in the current structure.

If OTF has store_dft_output set, then the specified DFT files will be copied with the current date and time prepended in the format ‘Year.Month.Day:Hour:Minute:Second:’.

Calculates DFT forces on atoms in the current structure.

train_gp()

Optimizes the hyperparameters of the current GP model.

update_gp(train_atoms: List[int], dft_frcs: ndarray, dft_energy: float = None, dft_stress: ndarray = None)

Updates the current GP model.

Parameters:
  • train_atoms (List[int]) – List of atoms whose local environments will be added to the training set.
  • dft_frcs (np.ndarray) – DFT forces on all atoms in the structure.
update_temperature()

Updates the instantaneous temperatures of the system.

Parameters:new_pos (np.ndarray) – Positions of atoms in the next MD frame.