deepmd.dpmodel package

class deepmd.dpmodel.DPModel(*args, **kwargs)[source]

Bases: CM, BaseModel

Methods

__call__(*args, **kwargs)

Forward pass in NumPy implementation.

atomic_output_def()

Get the output def of the atomic model.

call(coord, atype[, box, fparam, aparam, ...])

Return model prediction.

call_lower(extended_coord, extended_atype, nlist)

Return model prediction.

deserialize(data)

Deserialize the model.

do_grad_(var_name, base)

Tell if the output variable var_name is differentiable.

do_grad_c([var_name])

Tell if the output variable var_name is c_differentiable.

do_grad_r([var_name])

Tell if the output variable var_name is r_differentiable.

fitting_output_def()

Get the output def of the fitting net.

format_nlist(extended_coord, extended_atype, ...)

Format the neighbor list.

forward_atomic(extended_coord, ...[, ...])

Models' atomic predictions.

get_class_by_type(class_type)

Get the class by the plugin type.

get_dim_aparam()

Get the number (dimension) of atomic parameters of this atomic model.

get_dim_fparam()

Get the number (dimension) of frame parameters of this atomic model.

get_nnei()

Returns the total number of selected neighboring atoms in the cut-off radius.

get_nsel()

Returns the total number of selected neighboring atoms in the cut-off radius.

get_ntypes()

Get the number of atom types.

get_plugins()

Get all the registered plugins.

get_rcut()

Get the cut-off radius.

get_sel()

Get the neighbor selection.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map.

input_type_cast(coord[, box, fparam, aparam])

Cast the input data to global float type.

is_aparam_nall()

Check whether the shape of atomic parameters is (nframes, nall, ndim).

mixed_types()

If true, the model 1.

model_output_def()

Get the output def for the model.

model_output_type()

Get the output type for the model.

output_type_cast(model_ret, input_prec)

Convert the model output to the input prec.

register(key)

Register a descriptor plugin.

update_sel(global_jdata, local_jdata)

Update the selection and perform neighbor statistics.

forward_common_atomic

get_model_def_script

reinit_atom_exclude

reinit_pair_exclude

serialize

model_def_script: str
classmethod update_sel(global_jdata: dict, local_jdata: dict)[source]

Update the selection and perform neighbor statistics.

Parameters
global_jdatadict

The global data, containing the training section

local_jdatadict

The local data refer to the current class

class deepmd.dpmodel.FittingOutputDef(var_defs: List[OutputVariableDef])[source]

Bases: object

Defines the shapes and other properties of the fitting network outputs.

It is assume that the fitting network output variables for each local atom. This class defines all the outputs.

Parameters
var_defs

List of output variable definitions.

Methods

get_data

keys

get_data() Dict[str, OutputVariableDef][source]
keys()[source]
class deepmd.dpmodel.ModelOutputDef(fit_defs: FittingOutputDef)[source]

Bases: object

Defines the shapes and other properties of the model outputs.

The model reduce and differentiate fitting outputs if applicable. If a variable is named by foo, then the reduced variable is called foo_redu, the derivative w.r.t. coordinates is called foo_derv_r and the derivative w.r.t. cell is called foo_derv_c.

Parameters
fit_defs

Definition for the fitting net output

Methods

get_data

keys

keys_derv_c

keys_derv_c_redu

keys_derv_r

keys_hess_r

keys_outp

keys_redu

get_data(key: str) Dict[str, OutputVariableDef][source]
keys()[source]
keys_derv_c()[source]
keys_derv_c_redu()[source]
keys_derv_r()[source]
keys_hess_r()[source]
keys_outp()[source]
keys_redu()[source]
class deepmd.dpmodel.NativeOP[source]

Bases: ABC

The unit operation of a native model.

Methods

__call__(*args, **kwargs)

Forward pass in NumPy implementation.

call(*args, **kwargs)

Forward pass in NumPy implementation.

abstract call(*args, **kwargs)[source]

Forward pass in NumPy implementation.

class deepmd.dpmodel.OutputVariableDef(name: str, shape: List[int], reduciable: bool = False, r_differentiable: bool = False, c_differentiable: bool = False, atomic: bool = True, category: int = 0, r_hessian: bool = False)[source]

Bases: object

Defines the shape and other properties of the one output variable.

It is assume that the fitting network output variables for each local atom. This class defines one output variable, including its name, shape, reducibility and differentiability.

Parameters
name

Name of the output variable. Notice that the xxxx_redu, xxxx_derv_c, xxxx_derv_r are reserved names that should not be used to define variables.

shape

The shape of the variable. e.g. energy should be [1], dipole should be [3], polarizabilty should be [3,3].

reduciable

If the variable is reduced.

r_differentiable

If the variable is differentiated with respect to coordinates of atoms. Only reduciable variable are differentiable. Negative derivative w.r.t. coordinates will be calcualted. (e.g. force)

c_differentiable

If the variable is differentiated with respect to the cell tensor (pbc case). Only reduciable variable are differentiable. Virial, the transposed negative gradient with cell tensor times cell tensor, will be calculated, see eq 40 JCP 159, 054801 (2023).

atomicbool

If the variable is defined for each atom.

categoryint

The category of the output variable.

hessianbool

If hessian is requred

deepmd.dpmodel.fitting_check_output(cls)[source]

Check if the output of the Fitting is consistent with the definition.

Two methods are assumed to be provided by the Fitting: 1. Fitting.output_def that gives the output definition. 2. Fitting.__call__ defines the forward path of the fitting.

deepmd.dpmodel.get_deriv_name(name: str) Tuple[str, str][source]
deepmd.dpmodel.get_hessian_name(name: str) str[source]
deepmd.dpmodel.get_reduce_name(name: str) str[source]
deepmd.dpmodel.model_check_output(cls)[source]

Check if the output of the Model is consistent with the definition.

Two methods are assumed to be provided by the Model: 1. Model.output_def that gives the output definition. 2. Model.__call__ that defines the forward path of the model.

Subpackages

Submodules

deepmd.dpmodel.common module

deepmd.dpmodel.common.GLOBAL_ENER_FLOAT_PRECISION

alias of float64

deepmd.dpmodel.common.GLOBAL_NP_FLOAT_PRECISION

alias of float64

class deepmd.dpmodel.common.NativeOP[source]

Bases: ABC

The unit operation of a native model.

Methods

__call__(*args, **kwargs)

Forward pass in NumPy implementation.

call(*args, **kwargs)

Forward pass in NumPy implementation.

abstract call(*args, **kwargs)[source]

Forward pass in NumPy implementation.

deepmd.dpmodel.output_def module

class deepmd.dpmodel.output_def.FittingOutputDef(var_defs: List[OutputVariableDef])[source]

Bases: object

Defines the shapes and other properties of the fitting network outputs.

It is assume that the fitting network output variables for each local atom. This class defines all the outputs.

Parameters
var_defs

List of output variable definitions.

Methods

get_data

keys

get_data() Dict[str, OutputVariableDef][source]
keys()[source]
class deepmd.dpmodel.output_def.ModelOutputDef(fit_defs: FittingOutputDef)[source]

Bases: object

Defines the shapes and other properties of the model outputs.

The model reduce and differentiate fitting outputs if applicable. If a variable is named by foo, then the reduced variable is called foo_redu, the derivative w.r.t. coordinates is called foo_derv_r and the derivative w.r.t. cell is called foo_derv_c.

Parameters
fit_defs

Definition for the fitting net output

Methods

get_data

keys

keys_derv_c

keys_derv_c_redu

keys_derv_r

keys_hess_r

keys_outp

keys_redu

get_data(key: str) Dict[str, OutputVariableDef][source]
keys()[source]
keys_derv_c()[source]
keys_derv_c_redu()[source]
keys_derv_r()[source]
keys_hess_r()[source]
keys_outp()[source]
keys_redu()[source]
class deepmd.dpmodel.output_def.OutputVariableCategory(value)[source]

Bases: IntEnum

Defines the category of the output variable.

DERV_C = 4

Atomic component of the virial, see PRB 104, 224202 (2021)

DERV_C_REDU = 5

Virial, the transposed negative gradient with cell tensor times cell tensor, see eq 40 JCP 159, 054801 (2023).

DERV_R = 2

Negative derivative w.r.t. coordinates. (e.g. force)

DERV_R_DERV_R = 10

Hession matrix, the second derivative w.r.t. coordinates.

OUT = 0

Output variable. (e.g. atom energy)

REDU = 1

Reduced output variable. (e.g. system energy)

class deepmd.dpmodel.output_def.OutputVariableDef(name: str, shape: List[int], reduciable: bool = False, r_differentiable: bool = False, c_differentiable: bool = False, atomic: bool = True, category: int = 0, r_hessian: bool = False)[source]

Bases: object

Defines the shape and other properties of the one output variable.

It is assume that the fitting network output variables for each local atom. This class defines one output variable, including its name, shape, reducibility and differentiability.

Parameters
name

Name of the output variable. Notice that the xxxx_redu, xxxx_derv_c, xxxx_derv_r are reserved names that should not be used to define variables.

shape

The shape of the variable. e.g. energy should be [1], dipole should be [3], polarizabilty should be [3,3].

reduciable

If the variable is reduced.

r_differentiable

If the variable is differentiated with respect to coordinates of atoms. Only reduciable variable are differentiable. Negative derivative w.r.t. coordinates will be calcualted. (e.g. force)

c_differentiable

If the variable is differentiated with respect to the cell tensor (pbc case). Only reduciable variable are differentiable. Virial, the transposed negative gradient with cell tensor times cell tensor, will be calculated, see eq 40 JCP 159, 054801 (2023).

atomicbool

If the variable is defined for each atom.

categoryint

The category of the output variable.

hessianbool

If hessian is requred

class deepmd.dpmodel.output_def.OutputVariableOperation(value)[source]

Bases: IntEnum

Defines the operation of the output variable.

DERV_C = 4

Derivative w.r.t. cell.

DERV_R = 2

Derivative w.r.t. coordinates.

REDU = 1

Reduce the output variable.

deepmd.dpmodel.output_def.apply_operation(var_def: OutputVariableDef, op: OutputVariableOperation) int[source]

Apply a operation to the category of a variable definition.

Parameters
var_defOutputVariableDef

The variable definition.

opOutputVariableOperation

The operation to be applied.

Returns
int

The new category of the variable definition.

Raises
ValueError

If the operation has been applied to the variable definition, and exceed the maximum limitation.

deepmd.dpmodel.output_def.check_operation_applied(var_def: OutputVariableDef, op: OutputVariableOperation) bool[source]

Check if a operation has been applied to a variable definition.

Parameters
var_defOutputVariableDef

The variable definition.

opOutputVariableOperation

The operation to be checked.

Returns
bool

True if the operation has been applied, False otherwise.

deepmd.dpmodel.output_def.check_shape(shape: List[int], def_shape: List[int])[source]

Check if the shape satisfies the defined shape.

deepmd.dpmodel.output_def.check_var(var, var_def)[source]
deepmd.dpmodel.output_def.do_derivative(def_outp_data: Dict[str, OutputVariableDef]) Tuple[Dict[str, OutputVariableDef], Dict[str, OutputVariableDef]][source]
deepmd.dpmodel.output_def.do_reduce(def_outp_data: Dict[str, OutputVariableDef]) Dict[str, OutputVariableDef][source]
deepmd.dpmodel.output_def.fitting_check_output(cls)[source]

Check if the output of the Fitting is consistent with the definition.

Two methods are assumed to be provided by the Fitting: 1. Fitting.output_def that gives the output definition. 2. Fitting.__call__ defines the forward path of the fitting.

deepmd.dpmodel.output_def.get_deriv_name(name: str) Tuple[str, str][source]
deepmd.dpmodel.output_def.get_hessian_name(name: str) str[source]
deepmd.dpmodel.output_def.get_reduce_name(name: str) str[source]
deepmd.dpmodel.output_def.model_check_output(cls)[source]

Check if the output of the Model is consistent with the definition.

Two methods are assumed to be provided by the Model: 1. Model.output_def that gives the output definition. 2. Model.__call__ that defines the forward path of the model.