Class DeepSpin#

Inheritance Relationships#

Base Type#

Class Documentation#

class DeepSpin : public deepmd::DeepBaseModel#

Deep Potential to automatically switch backends.

Unnamed Group

template<typename VALUETYPE>
void compute(ENERGYTYPE &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Evaluate the energy, force, magnetic force and virial by using this DP with spin input.

Parameters:
  • ener – [out] The system energy.

  • force – [out] The force on each atom.

  • force_mag – [out] The magnetic force on each atom.

  • virial – [out] The virial.

  • coord – [in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • spin – [in] The spins of atoms, [0, 0, 0] if no spin. The array should be of size nframes x natoms x 3.

  • atype – [in] The atom types. The list should contain natoms ints.

  • box – [in] The cell of the region. The array should be of size nframes x 9.

  • fparam – [in] 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 – [in] 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.

  • charge_spin – [in] The charge/spin parameter. The array can be of size nframes x dim_chg_spin. dim_chg_spin. Then all frames are assumed to be provided with the same charge_spin. Leave it empty to use the model’s stored default_chg_spin.

template<typename VALUETYPE>
void compute(std::vector<ENERGYTYPE> &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Unnamed Group

template<typename VALUETYPE>
void compute(ENERGYTYPE &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Evaluate the energy, force, magnetic force and virial by using this DP with spin input.

Parameters:
  • ener – [out] The system energy.

  • force – [out] The force on each atom.

  • force_mag – [out] The magnetic force on each atom.

  • virial – [out] The virial.

  • coord – [in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • spin – [in] The spins of atoms, [0, 0, 0] if no spin. The array should be of size nframes x natoms x 3.

  • atype – [in] The atom types. The list should contain natoms ints.

  • box – [in] The cell of the region. The array should be of size nframes x 9.

  • nghost – [in] The number of ghost atoms.

  • inlist – [in] The input neighbour list.

  • ago – [in] Update the internal neighbour list if ago is 0.

  • fparam – [in] 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 – [in] 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.

  • charge_spin – [in] The charge/spin parameter. The array can be of size nframes x dim_chg_spin. dim_chg_spin. Then all frames are assumed to be provided with the same charge_spin. Leave it empty to use the model’s stored default_chg_spin.

template<typename VALUETYPE>
void compute(std::vector<ENERGYTYPE> &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Unnamed Group

template<typename VALUETYPE>
void compute(ENERGYTYPE &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, std::vector<VALUETYPE> &atom_energy, std::vector<VALUETYPE> &atom_virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial by using this DP with spin input.

Parameters:
  • ener – [out] The system energy.

  • force – [out] The force on each atom.

  • force_mag – [out] The magnetic force on each atom.

  • virial – [out] The virial.

  • atom_energy – [out] The atomic energy.

  • atom_virial – [out] The atomic virial.

  • coord – [in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • spin – [in] The spins of atoms, [0, 0, 0] if no spin. The array should be of size nframes x natoms x 3.

  • atype – [in] The atom types. The list should contain natoms ints.

  • box – [in] The cell of the region. The array should be of size nframes x 9.

  • fparam – [in] 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 – [in] 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.

  • charge_spin – [in] The charge/spin parameter. The array can be of size nframes x dim_chg_spin. dim_chg_spin. Then all frames are assumed to be provided with the same charge_spin. Leave it empty to use the model’s stored default_chg_spin.

template<typename VALUETYPE>
void compute(std::vector<ENERGYTYPE> &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, std::vector<VALUETYPE> &atom_energy, std::vector<VALUETYPE> &atom_virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Unnamed Group

template<typename VALUETYPE>
void compute(ENERGYTYPE &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, std::vector<VALUETYPE> &atom_energy, std::vector<VALUETYPE> &atom_virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const int nghost, const InputNlist &lmp_list, const int &ago, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Evaluate the energy, force, magnetic force, virial, atomic energy, and atomic virial by using this DP with spin input.

Parameters:
  • ener – [out] The system energy.

  • force – [out] The force on each atom.

  • force_mag – [out] The magnetic force on each atom.

  • virial – [out] The virial.

  • atom_energy – [out] The atomic energy.

  • atom_virial – [out] The atomic virial.

  • coord – [in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • spin – [in] The spins of atoms, [0, 0, 0] if no spin. The array should be of size nframes x natoms x 3.

  • atype – [in] The atom types. The list should contain natoms ints.

  • box – [in] The cell of the region. The array should be of size nframes x 9.

  • nghost – [in] The number of ghost atoms.

  • lmp_list – [in] The input neighbour list.

  • ago – [in] Update the internal neighbour list if ago is 0.

  • fparam – [in] 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 – [in] 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.

  • charge_spin – [in] The charge/spin parameter. The array can be of size nframes x dim_chg_spin. dim_chg_spin. Then all frames are assumed to be provided with the same charge_spin. Leave it empty to use the model’s stored default_chg_spin.

template<typename VALUETYPE>
void compute(std::vector<ENERGYTYPE> &ener, std::vector<VALUETYPE> &force, std::vector<VALUETYPE> &force_mag, std::vector<VALUETYPE> &virial, std::vector<VALUETYPE> &atom_energy, std::vector<VALUETYPE> &atom_virial, const std::vector<VALUETYPE> &coord, const std::vector<VALUETYPE> &spin, const std::vector<int> &atype, const std::vector<VALUETYPE> &box, const int nghost, const InputNlist &lmp_list, const int &ago, const std::vector<VALUETYPE> &fparam = std::vector<VALUETYPE>(), const std::vector<VALUETYPE> &aparam = std::vector<VALUETYPE>(), const std::vector<double> &charge_spin = std::vector<double>())#

Public Functions

DeepSpin()#

DP constructor without initialization.

virtual ~DeepSpin()#
DeepSpin(const std::string &model, const int &gpu_rank = 0, const std::string &file_content = "")#

DP constructor with initialization.

Parameters:
  • model – [in] The name of the frozen model file.

  • gpu_rank – [in] The GPU rank. Default is 0.

  • file_content – [in] The content of the model file. If it is not empty, DP will read from the string instead of the file.

void init(const std::string &model, const int &gpu_rank = 0, const std::string &file_content = "")#

Initialize the DP.

Parameters:
  • model – [in] The name of the frozen model file.

  • gpu_rank – [in] The GPU rank. Default is 0.

  • file_content – [in] The content of the model file. If it is not empty, DP will read from the string instead of the file.

int dim_chg_spin() const#

Get dimension of the charge/spin condition inputs.

Returns:

The dimension of charge_spin; 0 when the model does not support charge/spin conditioning.

void set_charge_spin(const std::vector<double> &charge_spin)#

Fix the charge/spin condition served for the rest of the run.

Parameters:

charge_spin – [in] The condition, of length dim_chg_spin().

std::vector<bool> get_use_spin() const#

Get the per-type use_spin flags.

Returns:

A vector of booleans indicating which atom types have spin enabled.

bool uses_canonical_graph_inference() const#

Whether the loaded artifact uses the compact canonical graph ABI.

bool uses_native_spin_scheme() const#

Whether the loaded artifact is served under the native spin scheme rather than the virtual-atom scheme.

void compute_canonical_graph_gpu(double *d_atom_energy, double *d_force, double *d_force_mag, double *d_atom_virial, const std::int64_t *d_atype, const std::uint32_t *d_source, const float *d_edge_vec, const std::int64_t *d_destination_row_ptr, const std::int64_t *d_source_row_ptr, const std::uint32_t *d_source_order, const float *d_spin, const int nloc, const int nall_nodes, const std::int64_t edge_storage)#

Fully device-resident inference for a compact canonical native-spin artifact.

The native-spin twin of DeepPot::compute_canonical_graph_gpu: the same dual-CSR compact schema plus the per-node moment, and the magnetic force among the outputs. All pointers reference accelerator memory on the model device and every output is written device-to-device. edge_storage is the allocated edge capacity; the physical edge count is the last entry of d_destination_row_ptr and the tail beyond it is ignored.

Parameters:
  • d_atom_energy – [out] Per-atom energy, [nloc].

  • d_force – [out] Per-node force, [nall_nodes * 3] row-major.

  • d_force_mag – [out] Per-node magnetic force, [nall_nodes * 3] row-major.

  • d_atom_virial – [out] Per-node virial, [nall_nodes * 9] row-major.

  • d_atype – [in] Per-node atom types, [nall_nodes].

  • d_source – [in] Source-node index per edge, [edge_storage].

  • d_edge_vec – [in] Destination-major edge vectors, [edge_storage * 3].

  • d_destination_row_ptr – [in] Destination CSR offsets, [nall_nodes + 1].

  • d_source_row_ptr – [in] Source CSR offsets, [nall_nodes + 1].

  • d_source_order – [in] Source-grouped edge positions, [edge_storage].

  • d_spin – [in] Per-node magnetic moment, [nall_nodes * 3] row-major; ghost rows carry their owner’s moment.

  • nloc – [in] Number of local atoms.

  • nall_nodes – [in] Graph node count (local + ghost).

  • edge_storage – [in] Allocated edge capacity.

Protected Attributes

std::shared_ptr<deepmd::DeepSpinBackend> dp#