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