deepmd.infer.model_devi#
Functions#
Calculate model deviation of force. | |
| Calculate model deviation of total energy per atom. |
| Calculate model deviation of virial. |
| Write output of model deviation. |
| Check whether type maps are identical. |
| Python interface to calculate model deviation. |
| Make model deviation calculation. |
Module Contents#
- deepmd.infer.model_devi.calc_model_devi_f(fs: numpy.ndarray, real_f: numpy.ndarray | None = None, relative: float | None = None, atomic: Literal[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]
- deepmd.infer.model_devi.calc_model_devi_f(fs: numpy.ndarray, real_f: numpy.ndarray | None = None, relative: float | None = None, atomic: bool = False) tuple[numpy.ndarray, Ellipsis]
Calculate model deviation of force.
- Parameters:
- fs
numpy.ndarray
size of n_models x n_frames x n_atoms x 3
- real_f
numpy.ndarray
orNone
real force, size of n_frames x n_atoms x 3. If given, the RMS real error is calculated instead.
- relative
float
, 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
- fs
- Returns:
- max_devi_f
numpy.ndarray
maximum deviation of force in all atoms
- min_devi_f
numpy.ndarray
minimum deviation of force in all atoms
- avg_devi_f
numpy.ndarray
average deviation of force in all atoms
- fs_devi
numpy.ndarray
deviation of force in all atoms, returned if atomic=True
- max_devi_f
- 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:
- es
numpy.ndarray
size of `n_models x n_frames x 1
- real_e
numpy.ndarray
real energy, size of n_frames x 1. If given, the RMS real error is calculated instead.
- es
- Returns:
- max_devi_e
numpy.ndarray
maximum deviation of energy
- max_devi_e
- 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:
- vs
numpy.ndarray
size of n_models x n_frames x 9
- real_v
numpy.ndarray
real virial, size of n_frames x 9. If given, the RMS real error is calculated instead.
- relative
float
, 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.
- vs
- Returns:
- max_devi_v
numpy.ndarray
maximum deviation of virial in 9 elements
- min_devi_v
numpy.ndarray
minimum deviation of virial in 9 elements
- avg_devi_v
numpy.ndarray
average deviation of virial in 9 elements
- max_devi_v
- 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:
- devi
numpy.ndarray
the first column is the steps index
- fname
str
the file name to dump
- header
str
, default=”” the header to dump
- atomicbool, default:
False
whether atomic model deviation is printed
- devi
- 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:
- coord
numpy.ndarray
, n_frames x n_atoms x 3 Coordinates of system to calculate
- box
numpy.ndarray
orNone
, n_frames x 3 x 3 Box to specify periodic boundary condition. If None, no pbc will be used
- atype
numpy.ndarray
, n_atoms x 1 Atom types
- models
list
of
DeepPot
models
Models used to evaluate deviation
- fname
str
orNone
File to dump results, default None
- frequency
int
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
- fparam
numpy.ndarray
frame specific parameters
- aparam
numpy.ndarray
atomic specific parameters
- real_data
dict
,optional
real data to calculate RMS real error
- atomicbool, default:
False
If True, calculate the force model deviation of each atom.
- relative
float
, 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_v
float
, 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.
- coord
- Returns:
- model_devi
numpy.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.
- model_devi
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, 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:
- models
list
A list of paths of models to use for making model deviation
- system
str
The path of system to make model deviation calculation
- output
str
The output file for model deviation results
- frequency
int
The number of steps that elapse between writing coordinates in a trajectory by a MD engine (such as Gromacs / LAMMPS). This parameter 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.
- relative
float
, 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_v
float
, 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.
- models