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"
15
16#include <torch/script.h>
17#include <torch/torch.h>
18
34// caoyu add 2021-03-29
35// wenfei modified 2022-1-5
36//
37template <typename T>
39{
40
41 //-------------------
42 // public variables
43 //-------------------
44 public:
46 double E_delta = 0.0;
48 double e_delta_band = 0.0;
49
52 std::vector<std::vector<T>> V_delta;
53
54 //-------------------
55 // private variables
56 //-------------------
57 // private:
58 public: // change to public to reconstuct the code, 2024-07-22 by mohan
59 DeePKS_Param deepks_param; // parameters for DeePKS
60
61 bool init_pdm = false; // for DeePKS NSCF calculation, set init_pdm to skip the calculation of pdm in SCF iteration
62
63 // deep neural network module that provides corrected Hamiltonian term and
64 // related derivatives. Used in cal_edelta_gedm.
65 torch::jit::script::Module model_deepks;
66
67 // saves <phi(0)|alpha(R)> and its derivatives
68 // index 0 for itself and index 1-3 for derivatives over x,y,z
69 std::vector<hamilt::HContainer<double>*> phialpha;
70
71 // density matrix in real space
73
74 // projected density matrix
75 // [tot_Inl][2l+1][2l+1], here l is corresponding to inl;
76 // [nat][nlm*nlm] for equivariant version
77 std::vector<torch::Tensor> pdm;
78
80 double** gedm = nullptr; //[tot_Inl][(2l+1)*(2l+1)]
81
82 // functions for hr status: 1. get value; 2. set value;
84 {
85 return this->hr_cal;
86 }
87 void set_hr_cal(bool cal)
88 {
89 this->hr_cal = cal;
90 }
91
92 //-------------------
93 // LCAO_deepks.cpp
94 //-------------------
95
96 // This file contains constructor and destructor of the class LCAO_deepks,
97 // as well as subroutines for initializing and releasing relevant data structures
98
99 // Other than the constructor and the destructor, it contains 3 types of subroutines:
100 // 1. subroutines that are related to calculating descriptors:
101 // - init : allocates some arrays
102 // - init_index : records the index (inl)
103 // 2. subroutines that are related to V_delta:
104 // - allocate_V_delta : allocates V_delta; if calculating force, it also allocates F_delta
105
106 public:
107 explicit LCAO_Deepks();
108 ~LCAO_Deepks();
109
112 void init(const LCAO_Orbitals& orb,
113 const int nat,
114 const int ntype,
115 const int nks,
116 const Parallel_Orbitals& pv_in,
117 std::vector<int> na,
118 std::ofstream& ofs);
119
121 void allocate_V_delta(const int nat, const int nks = 1);
122
124 void init_DMR(const UnitCell& ucell,
125 const LCAO_Orbitals& orb,
126 const Parallel_Orbitals& pv,
127 const Grid_Driver& GridD);
128
130 void dpks_cal_e_delta_band(const std::vector<std::vector<T>>& dm, const int nks);
131
132 private:
133 // flag of HR status,
134 // true : HR should be calculated
135 // false : HR has been calculated
136 bool hr_cal = true;
137
138 // arrange index of descriptor in all atoms
139 void init_index(const int ntype,
140 const int nat,
141 std::vector<int> na,
142 const int tot_inl,
143 const LCAO_Orbitals& orb,
144 std::ofstream& ofs);
145
146 const Parallel_Orbitals* pv = nullptr;
147};
148
149#endif
150#endif
Definition sltk_grid_driver.h:40
Definition LCAO_deepks.h:39
double E_delta
(Unit: Ry) Correction energy provided by NN
Definition LCAO_deepks.h:46
void allocate_V_delta(const int nat, const int nks=1)
Allocate memory for correction to Hamiltonian.
Definition LCAO_deepks.cpp:174
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:134
void set_hr_cal(bool cal)
Definition LCAO_deepks.h:87
torch::jit::script::Module model_deepks
Definition LCAO_deepks.h:65
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:39
LCAO_Deepks()
Definition LCAO_deepks.cpp:10
double ** gedm
dE/dD, autograd from loaded model(E: Ry)
Definition LCAO_deepks.h:80
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:255
std::vector< hamilt::HContainer< double > * > phialpha
Definition LCAO_deepks.h:69
std::vector< torch::Tensor > pdm
Definition LCAO_deepks.h:77
hamilt::HContainer< double > * dm_r
Definition LCAO_deepks.h:72
~LCAO_Deepks()
Definition LCAO_deepks.cpp:19
double e_delta_band
(Unit: Ry)
Definition LCAO_deepks.h:48
int get_hr_cal()
Definition LCAO_deepks.h:83
DeePKS_Param deepks_param
Definition LCAO_deepks.h:59
bool init_pdm
Definition LCAO_deepks.h:61
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:210
const Parallel_Orbitals * pv
Definition LCAO_deepks.h:146
std::vector< std::vector< T > > V_delta
Definition LCAO_deepks.h:52
bool hr_cal
Definition LCAO_deepks.h:136
Definition ORB_read.h:18
Definition parallel_orbitals.h:9
Definition unitcell.h:15
Definition hcontainer.h:144
Definition deepks_param.h:11