ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
lcao_deepks.h
Go to the documentation of this file.
1#ifndef LCAO_DEEPKS_H
2#define LCAO_DEEPKS_H
3
4#ifdef __MLALGO
5
6#include "deepks_basic.h"
7#include "deepks_param.h"
8#include "deepks_vdelta.h"
10#include "source_base/matrix.h"
16
17#include <torch/script.h>
18#include <torch/torch.h>
19
35// caoyu add 2021-03-29
36// wenfei modified 2022-1-5
37//
38template <typename T>
40{
41
42 //-------------------
43 // public variables
44 //-------------------
45 public:
47 double E_delta = 0.0;
49 double e_delta_band = 0.0;
50
53 std::vector<std::vector<T>> V_delta;
54
55 //-------------------
56 // private variables
57 //-------------------
58 // private:
59 public: // change to public to reconstuct the code, 2024-07-22 by mohan
60 DeePKS_Param deepks_param; // parameters for DeePKS
61
62 bool init_pdm = false; // for DeePKS NSCF calculation, set init_pdm to skip the calculation of pdm in SCF iteration
63
64 // deep neural network module that provides corrected Hamiltonian term and
65 // related derivatives. Used in cal_edelta_gedm.
66 torch::jit::script::Module model_deepks;
67
68 // saves <phi(0)|alpha(R)> and its derivatives
69 // index 0 for itself and index 1-3 for derivatives over x,y,z
70 std::vector<hamilt::HContainer<double>*> phialpha;
71
72 // density matrix in real space
74
75 // projected density matrix
76 // [tot_Inl][2l+1][2l+1], here l is corresponding to inl;
77 // [nat][nlm*nlm] for equivariant version
78 std::vector<torch::Tensor> pdm;
79
81 double** gedm = nullptr; //[tot_Inl][(2l+1)*(2l+1)]
82
83 // magnetization-channel (rho_up - rho_dn) counterparts, used only for nspin=2
85 std::vector<torch::Tensor> pdm_mag;
86 double** gedm_mag = nullptr;
87
88 // functions for hr status: 1. get value; 2. set value;
90 {
91 return this->hr_cal;
92 }
93 void set_hr_cal(bool cal)
94 {
95 this->hr_cal = cal;
96 }
97
98 //-------------------
99 // lcao_deepks.cpp
100 //-------------------
101
102 // This file contains constructor and destructor of the class LCAO_deepks,
103 // as well as subroutines for initializing and releasing relevant data structures
104
105 // Other than the constructor and the destructor, it contains 3 types of subroutines:
106 // 1. subroutines that are related to calculating descriptors:
107 // - init : allocates some arrays
108 // - init_index : records the index (inl)
109 // 2. subroutines that are related to V_delta:
110 // - allocate_V_delta : allocates V_delta; if calculating force, it also allocates F_delta
111
112 public:
113 explicit LCAO_Deepks();
114 ~LCAO_Deepks();
115
118 void init(const LCAO_Orbitals& orb,
119 const int nat,
120 const int ntype,
121 const int nks,
122 const Parallel_Orbitals& pv_in,
123 std::vector<int> na,
124 std::ofstream& ofs);
125
127 void allocate_V_delta(const int nat, const int nks = 1);
128
130 void init_dmr(const UnitCell& ucell,
131 const LCAO_Orbitals& orb,
132 const Parallel_Orbitals& pv,
133 const Grid_Driver& GridD);
134
136 void dpks_cal_e_delta_band(const std::vector<std::vector<T>>& dm, const int nks);
137
138 private:
139 // flag of HR status,
140 // true : HR should be calculated
141 // false : HR has been calculated
142 bool hr_cal = true;
143
144 // arrange index of descriptor in all atoms
145 void init_index(const int ntype,
146 const int nat,
147 std::vector<int> na,
148 const int tot_inl,
149 const LCAO_Orbitals& orb,
150 std::ofstream& ofs);
151
152 const Parallel_Orbitals* pv = nullptr;
153};
154
155#endif
156#endif
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
double E_delta
(Unit: Ry) Correction energy provided by NN
Definition lcao_deepks.h:47
void allocate_V_delta(const int nat, const int nks=1)
Allocate memory for correction to Hamiltonian.
Definition lcao_deepks.cpp:194
void init_index(const int ntype, const int nat, std::vector< int > na, const int tot_inl, const LCAO_Orbitals &orb, std::ofstream &ofs)
Definition lcao_deepks.cpp:154
void set_hr_cal(bool cal)
Definition lcao_deepks.h:93
hamilt::HContainer< double > * dm_r_mag
Definition lcao_deepks.h:84
torch::jit::script::Module model_deepks
Definition lcao_deepks.h:66
void init(const LCAO_Orbitals &orb, const int nat, const int ntype, const int nks, const Parallel_Orbitals &pv_in, std::vector< int > na, std::ofstream &ofs)
Definition lcao_deepks.cpp:50
LCAO_Deepks()
Definition lcao_deepks.cpp:10
double ** gedm
dE/dD, autograd from loaded model(E: Ry)
Definition lcao_deepks.h:81
void dpks_cal_e_delta_band(const std::vector< std::vector< T > > &dm, const int nks)
a temporary interface for cal_e_delta_band
Definition lcao_deepks.cpp:290
std::vector< hamilt::HContainer< double > * > phialpha
Definition lcao_deepks.h:70
std::vector< torch::Tensor > pdm
Definition lcao_deepks.h:78
hamilt::HContainer< double > * dm_r
Definition lcao_deepks.h:73
~LCAO_Deepks()
Definition lcao_deepks.cpp:20
double e_delta_band
(Unit: Ry)
Definition lcao_deepks.h:49
std::vector< torch::Tensor > pdm_mag
Definition lcao_deepks.h:85
int get_hr_cal()
Definition lcao_deepks.h:89
DeePKS_Param deepks_param
Definition lcao_deepks.h:60
bool init_pdm
Definition lcao_deepks.h:62
double ** gedm_mag
Definition lcao_deepks.h:86
const Parallel_Orbitals * pv
Definition lcao_deepks.h:152
std::vector< std::vector< T > > V_delta
Definition lcao_deepks.h:53
void init_dmr(const UnitCell &ucell, const LCAO_Orbitals &orb, const Parallel_Orbitals &pv, const Grid_Driver &GridD)
Initialize the dm_r container.
Definition lcao_deepks.cpp:240
bool hr_cal
Definition lcao_deepks.h:142
Definition orb_read.h:18
Definition parallel_orbitals.h:16
Provide the basic information about unitcell.
Definition unitcell.h:16
Definition hcontainer.h:147
Grid_Driver class for neighbor search interface.
Definition deepks_param.h:11