Calculators¶
The interface¶
Calculator ¶
Bases: ABC
Computes energies, forces and virials of systems.
Implementations set cutoff, elements and implemented and
define compute. mdapy.calculators.testing.check_calculator
tests any implementation.
Attributes:
| Name | Type | Description |
|---|---|---|
cutoff |
float64
|
Interaction cutoff in Å; a neighbor list for |
elements |
tuple of str or None
|
Elements the calculator handles, or None for any. |
implemented |
frozenset of str
|
The properties |
compute
abstractmethod
¶
Computes properties of a system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms, with the columns the calculator needs (usually
|
required |
properties
|
iterable of str
|
The properties to compute; others may be computed too. |
('energy', 'forces')
|
neighbors
|
NeighborList
|
A neighbor list of this system with at least |
None
|
Returns:
| Type | Description |
|---|---|
CalculatorResult
|
At least the requested properties. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If a property is not implemented, or the neighbor list does not fit the system. |
MissingProperty
|
If the system lacks a column the calculator needs. |
CalculatorResult
dataclass
¶
CalculatorResult(energy=None, atomic_energies=None, forces=None, virial=None, atomic_virials=None, volume=None)
Bases: Result
What a calculator computed for a system; unrequested values are None.
Attributes:
| Name | Type | Description |
|---|---|---|
energy |
float64 or None
|
Total energy in eV. |
atomic_energies |
ndarray or None
|
(N,) float64 energies in eV; they sum to |
forces |
ndarray or None
|
(N, 3) float64 forces in eV/Å. |
virial |
ndarray or None
|
(3, 3) float64 virial in eV, positive under compression. |
atomic_virials |
ndarray or None
|
(N, 3, 3) float64 virials in eV; they sum to |
volume |
float64 or None
|
Volume of the box in ų, which gives |
attach ¶
The system with these values as columns and information.
forces, atomic_energies and atomic_virials become
columns; energy and virial become entries of info.
check_calculator ¶
check_calculator(calculator, system, *, displacement=0.0001, rtol=1e-06, atol=1e-06, atoms=3, seed=0)
Checks that a calculator is consistent with itself and with physics.
The checks are: atomic energies and atomic virials sum to the energy and the virial; forces and the virial agree with finite differences of the energy; translation, rotation and reordering of the atoms change nothing beyond rotating vectors; a doubled cell has twice the energy (for systems periodic along a); and a neighbor list given to the calculator gives the same result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calculator
|
Calculator
|
The calculator. |
required |
system
|
System
|
A small system, a few dozen atoms, that the calculator handles. |
required |
displacement
|
float64
|
Step in Å (and strain step) of the finite differences. |
0.0001
|
rtol
|
float64
|
Relative and absolute tolerances of the comparisons, in the units of each quantity. |
1e-06
|
atol
|
float64
|
Relative and absolute tolerances of the comparisons, in the units of each quantity. |
1e-06
|
atoms
|
int32
|
Number of atoms whose forces are checked by finite differences. |
3
|
seed
|
int32
|
Seed of the random rotation, translation and atom choice. |
0
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If a check fails; the message names it and the largest deviation. |
Native¶
EAM ¶
Bases: Calculator
Embedded atom method potential, in the LAMMPS eam/alloy (setfl) form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or PathLike
|
The potential file. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
path |
str or None
|
The file the potential was read from, None for a built one. |
elements |
tuple of str or None
|
The elements of the potential, in the order of the file; None for an average-atom potential, which handles atoms of any element. |
masses |
ndarray
|
(E,) float64, their masses in amu; the mass of the average atom for an average-atom potential. |
cutoff |
float64
|
Cutoff radius in Å. |
zhou
classmethod
¶
The potential of Zhou, Johnson and Wadley for elements, tabulated as the LAMMPS tool tools/eam_database does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
elements
|
sequence of str
|
Any of Cu, Ag, Au, Ni, Pd, Pt, Al, Pb, Fe, Mo, Ta, W, Mg, Co, Ti, Zr and Cr. |
required |
nr
|
int32
|
Number of points of the tables in distance and in density. Default 2000. |
2000
|
nrho
|
int32
|
Number of points of the tables in distance and in density. Default 2000. |
2000
|
Returns:
| Type | Description |
|---|---|
EAM
|
The potential, written to a file with |
average ¶
The average-atom potential of an alloy of the elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
concentrations
|
mapping or sequence of float64
|
The fraction of each element, by element or in the order of
|
required |
Returns:
| Type | Description |
|---|---|
EAM
|
A potential in which every atom is the average atom, whatever its
element. |
write ¶
Writes the potential as a LAMMPS eam/alloy (setfl) file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or PathLike
|
The file to write; it reads back to the same tables. |
required |
NEP ¶
Bases: Calculator
Neuroevolution potential of a GPUMD nep.txt file (nep4, nep4_zbl).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or PathLike
|
The potential file. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
elements |
tuple of str
|
The elements of the potential, in the order of the file. |
cutoff |
float64
|
The largest cutoff radius in Å. |
descriptors ¶
The descriptors of each atom, scaled as the network sees them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms, with an |
required |
neighbors
|
NeighborList
|
A neighbor list of this system with at least |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(N, dim) float64 descriptors: the radial ones, then the angular ones by l and n, then the four-body and five-body ones by n. |
Interfaces¶
LAMMPS ¶
Bases: Calculator
An interaction of LAMMPS, defined by its commands, as a calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pair
|
str
|
The LAMMPS commands of the interaction, such as |
required |
elements
|
sequence of str
|
The element of each LAMMPS atom type, from type 1. |
required |
commands
|
str
|
LAMMPS commands run before |
''
|
cmdargs
|
sequence of str
|
Command-line arguments of LAMMPS, such as |
()
|
cutoff
|
float64
|
The largest cutoff of the interaction in Å; asked from LAMMPS when not given, which LAMMPS older than 30 Sep 2026 cannot tell. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
elements |
tuple of str
|
The element of each atom type. |
cutoff |
float64
|
The largest cutoff of the interaction in Å. |
Raises:
| Type | Description |
|---|---|
InvalidParameter
|
If LAMMPS rejects the commands, or cannot tell the cutoff when it is not given. |
ImportError
|
If the LAMMPS Python module is not installed. |
compute ¶
Computes properties of a system with LAMMPS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms, with an |
required |
properties
|
iterable of str
|
The properties to compute; all are computed. |
('energy', 'forces')
|
neighbors
|
NeighborList
|
Not used: LAMMPS searches its own neighbors. |
None
|
Returns:
| Type | Description |
|---|---|
CalculatorResult
|
Every property. |
VASP ¶
VASP(incar=None, *, kpoints=None, potcars=None, setups=None, command=None, directory='vasp', restart=True)
Bases: Calculator
Energies, forces and virials from VASP: each call writes POSCAR, INCAR, KPOINTS and POTCAR, runs VASP with a command and reads its OUTCAR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
incar
|
mapping
|
INCAR tags, such as |
None
|
kpoints
|
sequence of int32
|
A Gamma-centered mesh of k-points, three numbers. Default none: VASP then takes KSPACING from the INCAR. |
None
|
potcars
|
str or path - like
|
The folder of the POTCARs, one folder per element or setup, such as
|
None
|
setups
|
mapping
|
The POTCAR of an element when not its symbol, such as
|
None
|
command
|
str
|
The shell command that runs VASP in the directory, as in a job
script, such as
|
None
|
directory
|
str or path - like
|
Where VASP runs, made when missing. Default |
'vasp'
|
restart
|
bool
|
Keep WAVECAR and CHGCAR between calls, so that VASP starts from the last wave functions, as in a minimization. Default True. |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
cutoff |
float64
|
0: VASP needs no neighbor list. |
compute ¶
Runs VASP on a system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
System
|
The atoms, with an |
required |
properties
|
iterable of str
|
The properties to return: energy (the free energy TOTEN), forces and virial; VASP computes them all. |
('energy', 'forces')
|
neighbors
|
NeighborList
|
Not used. |
None
|
Returns:
| Type | Description |
|---|---|
CalculatorResult
|
The energy, forces and virial of the system, its atoms in their order. |
Raises:
| Type | Description |
|---|---|
CalculationFailed
|
If VASP stops with an error or leaves no converged result. |