deepmd.infer.model_devi

Module Contents

Functions

calc_model_devi_f(…)

Calculate model deviation of force.

calc_model_devi_e(→ numpy.ndarray)

Calculate model deviation of total energy per atom.

calc_model_devi_v(→ Tuple[numpy.ndarray, ...)

Calculate model deviation of virial.

write_model_devi_out(devi, fname[, header, atomic])

Write output of model deviation.

_check_tmaps(tmaps[, ref_tmap])

Check whether type maps are identical.

calc_model_devi(coord, box, atype, models[, fname, ...])

Python interface to calculate model deviation.

make_model_devi(*, models, system, set_prefix, output, ...)

Make model deviation calculation.

deepmd.infer.model_devi.calc_model_devi_f(fs: numpy.ndarray, real_f: numpy.ndarray | None = None, relative: float | None = None, atomic: Literal[False] = False) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]
deepmd.infer.model_devi.calc_model_devi_f(fs: numpy.ndarray, real_f: numpy.ndarray | None = None, relative: float | None = None, *, atomic: Literal[True]) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]

Calculate model deviation of force.

Parameters:
fsnumpy.ndarray

size of n_models x n_frames x n_atoms x 3

real_fnumpy.ndarray or None

real force, size of n_frames x n_atoms x 3. If given, the RMS real error is calculated instead.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

atomicbool, default: False

Whether return deviation of force in all atoms

Returns:
max_devi_fnumpy.ndarray

maximum deviation of force in all atoms

min_devi_fnumpy.ndarray

minimum deviation of force in all atoms

avg_devi_fnumpy.ndarray

average deviation of force in all atoms

fs_devinumpy.ndarray

deviation of force in all atoms, returned if atomic=True

deepmd.infer.model_devi.calc_model_devi_e(es: numpy.ndarray, real_e: numpy.ndarray | None = None) numpy.ndarray[source]

Calculate model deviation of total energy per atom.

Here we don’t use the atomic energy, as the decomposition of energy is arbitrary and not unique. There is no fitting target for atomic energy.

Parameters:
esnumpy.ndarray

size of `n_models x n_frames x 1

real_enumpy.ndarray

real energy, size of n_frames x 1. If given, the RMS real error is calculated instead.

Returns:
max_devi_enumpy.ndarray

maximum deviation of energy

deepmd.infer.model_devi.calc_model_devi_v(vs: numpy.ndarray, real_v: numpy.ndarray | None = None, relative: float | None = None) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Calculate model deviation of virial.

Parameters:
vsnumpy.ndarray

size of n_models x n_frames x 9

real_vnumpy.ndarray

real virial, size of n_frames x 9. If given, the RMS real error is calculated instead.

relativefloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

Returns:
max_devi_vnumpy.ndarray

maximum deviation of virial in 9 elements

min_devi_vnumpy.ndarray

minimum deviation of virial in 9 elements

avg_devi_vnumpy.ndarray

average deviation of virial in 9 elements

deepmd.infer.model_devi.write_model_devi_out(devi: numpy.ndarray, fname: str, header: str = '', atomic: bool = False)[source]

Write output of model deviation.

Parameters:
devinumpy.ndarray

the first column is the steps index

fnamestr

the file name to dump

headerstr, default=””

the header to dump

atomicbool, default: False

whether atomic model deviation is printed

deepmd.infer.model_devi._check_tmaps(tmaps, ref_tmap=None)[source]

Check whether type maps are identical.

deepmd.infer.model_devi.calc_model_devi(coord, box, atype, models, fname=None, frequency=1, mixed_type=False, fparam: numpy.ndarray | None = None, aparam: numpy.ndarray | None = None, real_data: dict | None = None, atomic: bool = False, relative: float | None = None, relative_v: float | None = None)[source]

Python interface to calculate model deviation.

Parameters:
coordnumpy.ndarray, n_frames x n_atoms x 3

Coordinates of system to calculate

boxnumpy.ndarray or None, n_frames x 3 x 3

Box to specify periodic boundary condition. If None, no pbc will be used

atypenumpy.ndarray, n_atoms x 1

Atom types

modelslist of DeepPot models

Models used to evaluate deviation

fnamestr or None

File to dump results, default None

frequencyint

Steps between frames (if the system is given by molecular dynamics engine), default 1

mixed_typebool

Whether the input atype is in mixed_type format or not

fparamnumpy.ndarray

frame specific parameters

aparamnumpy.ndarray

atomic specific parameters

real_datadict, optional

real data to calculate RMS real error

atomicbool, default: False

If True, calculate the force model deviation of each atom.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

relative_vfloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

Returns:
model_devinumpy.ndarray, n_frames x 8

Model deviation results. The first column is index of steps, the other 7 columns are max_devi_v, min_devi_v, avg_devi_v, max_devi_f, min_devi_f, avg_devi_f, devi_e.

Examples

>>> from deepmd.tf.infer import calc_model_devi
>>> from deepmd.tf.infer import DeepPot as DP
>>> import numpy as np
>>> coord = np.array([[1, 0, 0], [0, 0, 1.5], [1, 0, 3]]).reshape([1, -1])
>>> cell = np.diag(10 * np.ones(3)).reshape([1, -1])
>>> atype = [1, 0, 1]
>>> graphs = [DP("graph.000.pb"), DP("graph.001.pb")]
>>> model_devi = calc_model_devi(coord, cell, atype, graphs)
deepmd.infer.model_devi.make_model_devi(*, models: list, system: str, set_prefix: str, output: str, frequency: int, real_error: bool = False, atomic: bool = False, relative: float | None = None, relative_v: float | None = None, **kwargs)[source]

Make model deviation calculation.

Parameters:
modelslist

A list of paths of models to use for making model deviation

systemstr

The path of system to make model deviation calculation

set_prefixstr

The set prefix of the system

outputstr

The output file for model deviation results

frequencyint

The number of steps that elapse between writing coordinates in a trajectory by a MD engine (such as Gromacs / Lammps). This paramter is used to determine the index in the output file.

real_errorbool, default: False

If True, calculate the RMS real error instead of model deviation.

atomicbool, default: False

If True, calculate the force model deviation of each atom.

relativefloat, default: None

If given, calculate the relative model deviation of force. The value is the level parameter for computing the relative model deviation of the force.

relative_vfloat, default: None

If given, calculate the relative model deviation of virial. The value is the level parameter for computing the relative model deviation of the virial.

**kwargs

Arbitrary keyword arguments.