uf3.forcefield.calculator.UFCalculator

class UFCalculator(model: uf3.regression.least_squares.WeightedLinearModel)[source]

Bases: ase.calculators.calculator.Calculator

ASE Calculator for energies, forces, and stresses using a fit UF potential. Optionally compute elastic constants and phonon spectra.

Basic calculator implementation.

restart: str

Prefix for restart file. May contain a directory. Default is None: don’t restart.

ignore_bad_restart_file: bool

Deprecated, please do not use. Passing more than one positional argument to Calculator() is deprecated and will stop working in the future. Ignore broken or missing restart file. By default, it is an error if the restart file is missing or broken.

directory: str or PurePath

Working directory in which to read and write files and perform calculations.

label: str

Name used for all files. Not supported by all calculators. May contain a directory, but please use the directory parameter for that instead.

atoms: Atoms object

Optional Atoms object to which the calculator will be attached. When restarting, atoms will get its positions and unit-cell updated from file.

Methods

band_structure

Create band-structure object for plotting.

calculate

Do the calculation.

calculate_numerical_forces

Calculate numerical forces using finite difference.

calculate_numerical_stress

Calculate numerical stress using finite difference.

calculate_properties

This method is experimental; currently for internal use.

calculation_required

Check if a calculation is required.

check_state

Check for any system changes since last calculation.

export_properties

get_atoms

get_charges

get_default_parameters

get_dipole_moment

get_elastic_constants

Compute elastic constants.

get_forces

Return the forces in a configuration.

get_magnetic_moment

get_magnetic_moments

Calculate magnetic moments projected onto atoms.

get_phonon_data

Compute phonon spectra using Phonopy.

get_potential_energies

get_potential_energy

Evaluate the total energy of a configuration.

get_property

Get the named property.

get_stress

Return the (numerical) stress.

get_stresses

the calculator should return intensive stresses, i.e., such that stresses.sum(axis=0) == stress

read

Read atoms, parameters and calculated properties from output file.

read_atoms

relax_fmax

Minimize maximum force using ASE's QuasiNewton optimizer.

reset

Clear all information from old calculation.

set

Set parameters like set(key1=value1, key2=value2, ...).

set_label

Set label and convert label to directory and prefix.

todict

Attributes

chemical_system

coefficients

default_parameters

Default parameters

degree

directory

discard_results_on_any_change

Whether we purge the results following any change in the set() method.

element_list

ignored_changes

Properties of Atoms which we ignore for the purposes of cache

implemented_properties

Properties calculator can handle (energy, forces, ...)

interactions_map

knot_subintervals

label

partition_sizes

r_cut

r_max_map

r_min_map

band_structure()

Create band-structure object for plotting.

calculate(atoms=None, properties=['energy'], system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'])

Do the calculation.

properties: list of str

List of what needs to be calculated. Can be any combination of ‘energy’, ‘forces’, ‘stress’, ‘dipole’, ‘charges’, ‘magmom’ and ‘magmoms’.

system_changes: list of str

List of what has changed since last calculation. Can be any combination of these six: ‘positions’, ‘numbers’, ‘cell’, ‘pbc’, ‘initial_charges’ and ‘initial_magmoms’.

Subclasses need to implement this, but can ignore properties and system_changes if they want. Calculated properties should be inserted into results dictionary like shown in this dummy example:

self.results = {'energy': 0.0,
                'forces': np.zeros((len(atoms), 3)),
                'stress': np.zeros(6),
                'dipole': np.zeros(3),
                'charges': np.zeros(len(atoms)),
                'magmom': 0.0,
                'magmoms': np.zeros(len(atoms))}

The subclass implementation should first call this implementation to set the atoms attribute and create any missing directories.

calculate_numerical_forces(atoms, d=0.001)

Calculate numerical forces using finite difference.

All atoms will be displaced by +d and -d in all directions.

calculate_numerical_stress(atoms, d=1e-06, voigt=True)

Calculate numerical stress using finite difference.

calculate_properties(atoms, properties)

This method is experimental; currently for internal use.

calculation_required(atoms: ase.atoms.Atoms, quantities: List) bool[source]

Check if a calculation is required.

check_state(atoms, tol=1e-15)

Check for any system changes since last calculation.

get_elastic_constants(atoms: ase.atoms.Atoms, n: int = 5, d: float = 1.0) List[source]

Compute elastic constants.

Parameters
  • atoms (ase.Atoms) – configuration of interest.

  • n (int) – number of distortions to sample for fitting.

  • d (float) – maximum displacement in percent.

Returns

elastic constants.

Return type

results (list)

get_forces(atoms: Optional[ase.atoms.Atoms] = None) numpy.ndarray[source]

Return the forces in a configuration.

get_magnetic_moments(atoms=None)

Calculate magnetic moments projected onto atoms.

get_phonon_data(atoms: ase.atoms.Atoms, n_super: int = 5, disp: float = 0.05) Tuple[Any, Dict, Dict][source]

Compute phonon spectra using Phonopy.

Parameters
  • atoms (ase.Atoms) – configuration of interest.

  • n_super (int) – size of supercell, i.e. # images in each direction.

  • disp (float) – magnitude of displacement in percent.

get_potential_energy(atoms: Optional[ase.atoms.Atoms] = None, force_consistent: Optional[bool] = None) float[source]

Evaluate the total energy of a configuration.

get_property(name, atoms=None, allow_calculation=True)

Get the named property.

get_stress(atoms: Optional[ase.atoms.Atoms] = None, **kwargs) numpy.ndarray[source]

Return the (numerical) stress.

get_stresses(atoms=None)

the calculator should return intensive stresses, i.e., such that stresses.sum(axis=0) == stress

read(label)

Read atoms, parameters and calculated properties from output file.

Read result from self.label file. Raise ReadError if the file is not there. If the file is corrupted or contains an error message from the calculation, a ReadError should also be raised. In case of succes, these attributes must set:

atoms: Atoms object

The state of the atoms from last calculation.

parameters: Parameters object

The parameter dictionary.

results: dict

Calculated properties like energy and forces.

The FileIOCalculator.read() method will typically read atoms and parameters and get the results dict by calling the read_results() method.

relax_fmax(geom: ase.atoms.Atoms, fmax: float = 0.05, relax_cell: bool = True, verbose: bool = False, timeout: float = 60.0, **kwargs) ase.atoms.Atoms[source]

Minimize maximum force using ASE’s QuasiNewton optimizer.

reset()

Clear all information from old calculation.

set(**kwargs)

Set parameters like set(key1=value1, key2=value2, …).

A dictionary containing the parameters that have been changed is returned.

Subclasses must implement a set() method that will look at the chaneged parameters and decide if a call to reset() is needed. If the changed parameters are harmless, like a change in verbosity, then there is no need to call reset().

The special keyword ‘parameters’ can be used to read parameters from a file.

set_label(label)

Set label and convert label to directory and prefix.

Examples:

  • label=’abc’: (directory=’.’, prefix=’abc’)

  • label=’dir1/abc’: (directory=’dir1’, prefix=’abc’)

  • label=None: (directory=’.’, prefix=None)