deepmd.infer package

Submodule containing all the implemented potentials.

class deepmd.infer.DeepDipole(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str
class deepmd.infer.DeepEval(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | AutoBatchSize = False)[source]

Bases: object

Common methods for DeepPot, DeepWFC, DeepPolar, …

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

auto_batch_sizebool or int or AutomaticBatchSize, default: False

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval_typeebd()

Evaluate output of type embedding network by using this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval_typeebd() ndarray[source]

Evaluate output of type embedding network by using this model.

Returns:
np.ndarray

The output of type embedding network. The shape is [ntypes, o_size], where ntypes is the number of types, and o_size is the number of nodes in the output layer.

Raises:
KeyError

If the model does not enable type embedding.

See also

deepmd.utils.type_embed.TypeEmbedNet

The type embedding network.

Examples

Get the output of type embedding network of graph.pb:

>>> from deepmd.infer import DeepPotential
>>> dp = DeepPotential('graph.pb')
>>> dp.eval_typeebd()
load_prefix: str
make_natoms_vec(atom_types: ndarray, mixed_type: bool = False) ndarray[source]

Make the natom vector used by deepmd-kit.

Parameters:
atom_types

The type of atoms

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
natoms

The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: number of local atoms natoms[1]: total number of atoms held by this processor natoms[i]: 2 <= i < Ntypes+2, number of type i atoms

property model_type: str

Get type of model.

:type:str

property model_version: str

Get version of model.

Returns:
str

version of model

static reverse_map(vec: ndarray, imap: List[int]) ndarray[source]

Reverse mapping of a vector according to the index map.

Parameters:
vec

Input vector. Be of shape [nframes, natoms, -1]

imap

Index map. Be of shape [natoms]

Returns:
vec_out

Reverse mapped vector.

property sess: Session

Get TF session.

static sort_input(coord: ndarray, atom_type: ndarray, sel_atoms: List[int] | None = None, mixed_type: bool = False)[source]

Sort atoms in the system according their types.

Parameters:
coord

The coordinates of atoms. Should be of shape [nframes, natoms, 3]

atom_type

The type of atoms Should be of shape [natoms]

sel_atoms

The selected atoms by type

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
coord_out

The coordinates after sorting

atom_type_out

The atom types after sorting

idx_map

The index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]

sel_atom_type

Only output if sel_atoms is not None The sorted selected atom types

sel_idx_map

Only output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.

class deepmd.infer.DeepGlobalPolar(model_file: str, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filestr

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = False, fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None) ndarray[source]

Evaluate the model.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Not used in this model

fparam

Not used in this model

aparam

Not used in this model

efield

Not used in this model

Returns:
tensor

The returned tensor If atomic == False then of size nframes x variable_dof else of size nframes x natoms x variable_dof

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str
class deepmd.infer.DeepPolar(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str
class deepmd.infer.DeepPot(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | AutoBatchSize = True)[source]

Bases: DeepEval

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

auto_batch_sizebool or int or AutomaticBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Examples

>>> from deepmd.infer import DeepPot
>>> import numpy as np
>>> dp = DeepPot('graph.pb')
>>> 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]
>>> e, f, v = dp.eval(coord, cell, atype)

where e, f and v are predicted energy, force and virial of the system, respectively.

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the energy, force and virial by using this DP.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

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

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Unsupported in this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = False, fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None, mixed_type: bool = False) Tuple[ndarray, ...][source]

Evaluate the energy, force and virial by using this DP.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Calculate the atomic energy and virial

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
energy

The system energy.

force

The force on each atom

virial

The virial

atom_energy

The atomic energy. Only returned when atomic == True

atom_virial

The atomic virial. Only returned when atomic == True

eval_descriptor(coords: ndarray, cells: ndarray, atom_types: List[int], fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None, mixed_type: bool = False) array[source]

Evaluate descriptors by using this DP.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
descriptor

Descriptors.

get_dim_aparam() int[source]

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

get_dim_fparam() int[source]

Get the number (dimension) of frame parameters of this DP.

get_ntypes() int[source]

Get the number of atom types of this model.

get_rcut() float[source]

Get the cut-off radius of this model.

get_sel_type() List[int][source]

Unsupported in this model.

get_type_map() List[str][source]

Get the type map (element name of the atom types) of this model.

load_prefix: str
deepmd.infer.DeepPotential(model_file: str | Path, load_prefix: str = 'load', default_tf_graph: bool = False) DeepDipole | DeepGlobalPolar | DeepPolar | DeepPot | DeepWFC[source]

Factory function that will inialize appropriate potential read from model_file.

Parameters:
model_filestr

The name of the frozen model file.

load_prefixstr

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Returns:
Union[DeepDipole, DeepGlobalPolar, DeepPolar, DeepPot, DeepWFC]

one of the available potentials

Raises:
RuntimeError

if model file does not correspond to any implementd potential

class deepmd.infer.DeepWFC(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str
class deepmd.infer.DipoleChargeModifier(model_name: str, model_charge_map: List[float], sys_charge_map: List[float], ewald_h: float = 1, ewald_beta: float = 1)[source]

Bases: DeepDipole

Parameters:
model_name

The model file for the DeepDipole model

model_charge_map

Gives the amount of charge for the wfcc

sys_charge_map

Gives the amount of charge for the real atoms

ewald_h

Grid spacing of the reciprocal part of Ewald sum. Unit: A

ewald_beta

Splitting parameter of the Ewald sum. Unit: A^{-1}

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

build_fv_graph()

Build the computational graph for the force and virial inference.

eval(coord, box, atype[, eval_fv])

Evaluate the modification.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

modify_data(data)

Modify data.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

build_fv_graph() Tensor[source]

Build the computational graph for the force and virial inference.

eval(coord: ndarray, box: ndarray, atype: ndarray, eval_fv: bool = True) Tuple[ndarray, ndarray, ndarray][source]

Evaluate the modification.

Parameters:
coord

The coordinates of atoms

box

The simulation region. PBC is assumed

atype

The atom types

eval_fv

Evaluate force and virial

Returns:
tot_e

The energy modification

tot_f

The force modification

tot_v

The virial modification

load_prefix: str
modify_data(data: dict) None[source]

Modify data.

Parameters:
data

Internal data of DeepmdData. Be a dict, has the following keys - coord coordinates - box simulation box - type atom types - find_energy tells if data has energy - find_force tells if data has force - find_virial tells if data has virial - energy energy - force force - virial virial

class deepmd.infer.EwaldRecp(hh, beta)[source]

Bases: object

Evaluate the reciprocal part of the Ewald sum.

Methods

eval(coord, charge, box)

Evaluate.

eval(coord: ndarray, charge: ndarray, box: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Evaluate.

Parameters:
coord

The coordinates of atoms

charge

The atomic charge

box

The simulation region. PBC is assumed

Returns:
e

The energy

f

The force

v

The virial

deepmd.infer.calc_model_devi(coord, box, atype, models, fname=None, frequency=1)[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

Returns:
model_devinumpy.ndarray, n_frames x 7

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

Examples

>>> from deepmd.infer import calc_model_devi
>>> from deepmd.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)

Submodules

deepmd.infer.data_modifier module

class deepmd.infer.data_modifier.DipoleChargeModifier(model_name: str, model_charge_map: List[float], sys_charge_map: List[float], ewald_h: float = 1, ewald_beta: float = 1)[source]

Bases: DeepDipole

Parameters:
model_name

The model file for the DeepDipole model

model_charge_map

Gives the amount of charge for the wfcc

sys_charge_map

Gives the amount of charge for the real atoms

ewald_h

Grid spacing of the reciprocal part of Ewald sum. Unit: A

ewald_beta

Splitting parameter of the Ewald sum. Unit: A^{-1}

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

build_fv_graph()

Build the computational graph for the force and virial inference.

eval(coord, box, atype[, eval_fv])

Evaluate the modification.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

modify_data(data)

Modify data.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

build_fv_graph() Tensor[source]

Build the computational graph for the force and virial inference.

eval(coord: ndarray, box: ndarray, atype: ndarray, eval_fv: bool = True) Tuple[ndarray, ndarray, ndarray][source]

Evaluate the modification.

Parameters:
coord

The coordinates of atoms

box

The simulation region. PBC is assumed

atype

The atom types

eval_fv

Evaluate force and virial

Returns:
tot_e

The energy modification

tot_f

The force modification

tot_v

The virial modification

load_prefix: str
modify_data(data: dict) None[source]

Modify data.

Parameters:
data

Internal data of DeepmdData. Be a dict, has the following keys - coord coordinates - box simulation box - type atom types - find_energy tells if data has energy - find_force tells if data has force - find_virial tells if data has virial - energy energy - force force - virial virial

deepmd.infer.deep_dipole module

class deepmd.infer.deep_dipole.DeepDipole(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str

deepmd.infer.deep_eval module

class deepmd.infer.deep_eval.DeepEval(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | AutoBatchSize = False)[source]

Bases: object

Common methods for DeepPot, DeepWFC, DeepPolar, …

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

auto_batch_sizebool or int or AutomaticBatchSize, default: False

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval_typeebd()

Evaluate output of type embedding network by using this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval_typeebd() ndarray[source]

Evaluate output of type embedding network by using this model.

Returns:
np.ndarray

The output of type embedding network. The shape is [ntypes, o_size], where ntypes is the number of types, and o_size is the number of nodes in the output layer.

Raises:
KeyError

If the model does not enable type embedding.

See also

deepmd.utils.type_embed.TypeEmbedNet

The type embedding network.

Examples

Get the output of type embedding network of graph.pb:

>>> from deepmd.infer import DeepPotential
>>> dp = DeepPotential('graph.pb')
>>> dp.eval_typeebd()
load_prefix: str
make_natoms_vec(atom_types: ndarray, mixed_type: bool = False) ndarray[source]

Make the natom vector used by deepmd-kit.

Parameters:
atom_types

The type of atoms

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
natoms

The number of atoms. This tensor has the length of Ntypes + 2 natoms[0]: number of local atoms natoms[1]: total number of atoms held by this processor natoms[i]: 2 <= i < Ntypes+2, number of type i atoms

property model_type: str

Get type of model.

:type:str

property model_version: str

Get version of model.

Returns:
str

version of model

static reverse_map(vec: ndarray, imap: List[int]) ndarray[source]

Reverse mapping of a vector according to the index map.

Parameters:
vec

Input vector. Be of shape [nframes, natoms, -1]

imap

Index map. Be of shape [natoms]

Returns:
vec_out

Reverse mapped vector.

property sess: Session

Get TF session.

static sort_input(coord: ndarray, atom_type: ndarray, sel_atoms: List[int] | None = None, mixed_type: bool = False)[source]

Sort atoms in the system according their types.

Parameters:
coord

The coordinates of atoms. Should be of shape [nframes, natoms, 3]

atom_type

The type of atoms Should be of shape [natoms]

sel_atoms

The selected atoms by type

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
coord_out

The coordinates after sorting

atom_type_out

The atom types after sorting

idx_map

The index mapping from the input to the output. For example coord_out = coord[:,idx_map,:]

sel_atom_type

Only output if sel_atoms is not None The sorted selected atom types

sel_idx_map

Only output if sel_atoms is not None The index mapping from the selected atoms to sorted selected atoms.

deepmd.infer.deep_polar module

class deepmd.infer.deep_polar.DeepGlobalPolar(model_file: str, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filestr

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = False, fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None) ndarray[source]

Evaluate the model.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Not used in this model

fparam

Not used in this model

aparam

Not used in this model

efield

Not used in this model

Returns:
tensor

The returned tensor If atomic == False then of size nframes x variable_dof else of size nframes x natoms x variable_dof

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str
class deepmd.infer.deep_polar.DeepPolar(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str

deepmd.infer.deep_pot module

class deepmd.infer.deep_pot.DeepPot(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False, auto_batch_size: bool | int | AutoBatchSize = True)[source]

Bases: DeepEval

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

auto_batch_sizebool or int or AutomaticBatchSize, default: True

If True, automatic batch size will be used. If int, it will be used as the initial batch size.

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Examples

>>> from deepmd.infer import DeepPot
>>> import numpy as np
>>> dp = DeepPot('graph.pb')
>>> 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]
>>> e, f, v = dp.eval(coord, cell, atype)

where e, f and v are predicted energy, force and virial of the system, respectively.

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the energy, force and virial by using this DP.

eval_descriptor(coords, cells, atom_types[, ...])

Evaluate descriptors by using this DP.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

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

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Unsupported in this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = False, fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None, mixed_type: bool = False) Tuple[ndarray, ...][source]

Evaluate the energy, force and virial by using this DP.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Calculate the atomic energy and virial

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
energy

The system energy.

force

The force on each atom

virial

The virial

atom_energy

The atomic energy. Only returned when atomic == True

atom_virial

The atomic virial. Only returned when atomic == True

eval_descriptor(coords: ndarray, cells: ndarray, atom_types: List[int], fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None, mixed_type: bool = False) array[source]

Evaluate descriptors by using this DP.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

fparam

The frame parameter. The array can be of size : - nframes x dim_fparam. - dim_fparam. Then all frames are assumed to be provided with the same fparam.

aparam

The atomic parameter The array can be of size : - nframes x natoms x dim_aparam. - natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam. - dim_aparam. Then all frames and atoms are provided with the same aparam.

efield

The external field on atoms. The array should be of size nframes x natoms x 3

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
descriptor

Descriptors.

get_dim_aparam() int[source]

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

get_dim_fparam() int[source]

Get the number (dimension) of frame parameters of this DP.

get_ntypes() int[source]

Get the number of atom types of this model.

get_rcut() float[source]

Get the cut-off radius of this model.

get_sel_type() List[int][source]

Unsupported in this model.

get_type_map() List[str][source]

Get the type map (element name of the atom types) of this model.

load_prefix: str

deepmd.infer.deep_tensor module

class deepmd.infer.deep_tensor.DeepTensor(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepEval

Evaluates a tensor model.

Parameters:
model_file: str

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

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

get_dim_fparam()

Get the number (dimension) of frame parameters of this DP.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

eval(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = True, fparam: ndarray | None = None, aparam: ndarray | None = None, efield: ndarray | None = None, mixed_type: bool = False) ndarray[source]

Evaluate the model.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

If True (default), return the atomic tensor Otherwise return the global tensor

fparam

Not used in this model

aparam

Not used in this model

efield

Not used in this model

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
tensor

The returned tensor If atomic == False then of size nframes x output_dim else of size nframes x natoms x output_dim

eval_full(coords: ndarray, cells: ndarray, atom_types: List[int], atomic: bool = False, fparam: array | None = None, aparam: array | None = None, efield: array | None = None, mixed_type: bool = False) Tuple[ndarray, ...][source]

Evaluate the model with interface similar to the energy model. Will return global tensor, component-wise force and virial and optionally atomic tensor and atomic virial.

Parameters:
coords

The coordinates of atoms. The array should be of size nframes x natoms x 3

cells

The cell of the region. If None then non-PBC is assumed, otherwise using PBC. The array should be of size nframes x 9

atom_types

The atom types The list should contain natoms ints

atomic

Whether to calculate atomic tensor and virial

fparam

Not used in this model

aparam

Not used in this model

efield

Not used in this model

mixed_type

Whether to perform the mixed_type mode. If True, the input data has the mixed_type format (see doc/model/train_se_atten.md), in which frames in a system may have different natoms_vec(s), with the same nloc.

Returns:
tensor

The global tensor. shape: [nframes x nout]

force

The component-wise force (negative derivative) on each atom. shape: [nframes x nout x natoms x 3]

virial

The component-wise virial of the tensor. shape: [nframes x nout x 9]

atom_tensor

The atomic tensor. Only returned when atomic == True shape: [nframes x natoms x nout]

atom_virial

The atomic virial. Only returned when atomic == True shape: [nframes x nout x natoms x 9]

get_dim_aparam() int[source]

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

get_dim_fparam() int[source]

Get the number (dimension) of frame parameters of this DP.

get_ntypes() int[source]

Get the number of atom types of this model.

get_rcut() float[source]

Get the cut-off radius of this model.

get_sel_type() List[int][source]

Get the selected atom types of this model.

get_type_map() List[str][source]

Get the type map (element name of the atom types) of this model.

load_prefix: str
tensors = {'t_box': 't_box:0', 't_coord': 't_coord:0', 't_mesh': 't_mesh:0', 't_natoms': 't_natoms:0', 't_ntypes': 'descrpt_attr/ntypes:0', 't_ouput_dim': 'model_attr/output_dim:0', 't_rcut': 'descrpt_attr/rcut:0', 't_sel_type': 'model_attr/sel_type:0', 't_tmap': 'model_attr/tmap:0', 't_type': 't_type:0'}

deepmd.infer.deep_wfc module

class deepmd.infer.deep_wfc.DeepWFC(model_file: Path, load_prefix: str = 'load', default_tf_graph: bool = False)[source]

Bases: DeepTensor

Constructor.

Parameters:
model_filePath

The name of the frozen model file.

load_prefix: str

The prefix in the load computational graph

default_tf_graphbool

If uses the default tf graph, otherwise build a new tf graph for evaluation

Warning

For developers: DeepTensor initializer must be called at the end after self.tensors are modified because it uses the data in self.tensors dict. Do not chanage the order!

Attributes:
model_type

Get type of model.

model_version

Get version of model.

sess

Get TF session.

Methods

eval(coords, cells, atom_types[, atomic, ...])

Evaluate the model.

eval_full(coords, cells, atom_types[, ...])

Evaluate the model with interface similar to the energy model.

eval_typeebd()

Evaluate output of type embedding network by using this model.

get_dim_aparam()

Unsupported in this model.

get_dim_fparam()

Unsupported in this model.

get_ntypes()

Get the number of atom types of this model.

get_rcut()

Get the cut-off radius of this model.

get_sel_type()

Get the selected atom types of this model.

get_type_map()

Get the type map (element name of the atom types) of this model.

make_natoms_vec(atom_types[, mixed_type])

Make the natom vector used by deepmd-kit.

reverse_map(vec, imap)

Reverse mapping of a vector according to the index map.

sort_input(coord, atom_type[, sel_atoms, ...])

Sort atoms in the system according their types.

get_dim_aparam() int[source]

Unsupported in this model.

get_dim_fparam() int[source]

Unsupported in this model.

load_prefix: str

deepmd.infer.ewald_recp module

class deepmd.infer.ewald_recp.EwaldRecp(hh, beta)[source]

Bases: object

Evaluate the reciprocal part of the Ewald sum.

Methods

eval(coord, charge, box)

Evaluate.

eval(coord: ndarray, charge: ndarray, box: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Evaluate.

Parameters:
coord

The coordinates of atoms

charge

The atomic charge

box

The simulation region. PBC is assumed

Returns:
e

The energy

f

The force

v

The virial

deepmd.infer.model_devi module

deepmd.infer.model_devi.calc_model_devi(coord, box, atype, models, fname=None, frequency=1)[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

Returns:
model_devinumpy.ndarray, n_frames x 7

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

Examples

>>> from deepmd.infer import calc_model_devi
>>> from deepmd.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.calc_model_devi_e(es: ndarray)[source]
Parameters:
esnumpy.ndarray

size of `n_models x n_frames x n_atoms

deepmd.infer.model_devi.calc_model_devi_f(fs: ndarray)[source]
Parameters:
fsnumpy.ndarray

size of n_models x n_frames x n_atoms x 3

deepmd.infer.model_devi.calc_model_devi_v(vs: ndarray)[source]
Parameters:
vsnumpy.ndarray

size of n_models x n_frames x 9

deepmd.infer.model_devi.make_model_devi(*, models: list, system: str, set_prefix: str, output: str, frequency: int, **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.

**kwargs

Arbitrary keyword arguments.

deepmd.infer.model_devi.write_model_devi_out(devi: ndarray, fname: str, header: str = '')[source]
Parameters:
devinumpy.ndarray

the first column is the steps index

fnamestr

the file name to dump

headerstr, default=””

the header to dump