Skip to content

Commit 42e5f1a

Browse files
committed
clang-format
1 parent 0ca3c5f commit 42e5f1a

File tree

12 files changed

+259
-238
lines changed

12 files changed

+259
-238
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,18 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
504504
// DeePKS force
505505
if (PARAM.inp.deepks_out_labels) // not parallelized yet
506506
{
507-
const std::string file_ftot = PARAM.globalv.global_out_dir +
508-
(PARAM.inp.deepks_out_labels == 1 ? "deepks_ftot.npy" : "deepks_force.npy");
507+
const std::string file_ftot = PARAM.globalv.global_out_dir
508+
+ (PARAM.inp.deepks_out_labels == 1 ? "deepks_ftot.npy" : "deepks_force.npy");
509509
LCAO_deepks_io::save_matrix2npy(file_ftot, fcs, GlobalV::MY_RANK); // Hartree/Bohr, F_tot
510510

511-
if (PARAM.inp.deepks_out_labels==1)
511+
if (PARAM.inp.deepks_out_labels == 1)
512512
{
513513
const std::string file_fbase = PARAM.globalv.global_out_dir + "deepks_fbase.npy";
514514
if (PARAM.inp.deepks_scf)
515515
{
516-
LCAO_deepks_io::save_matrix2npy(file_fbase, fcs - fvnl_dalpha, GlobalV::MY_RANK); // Hartree/Bohr, F_base
516+
LCAO_deepks_io::save_matrix2npy(file_fbase,
517+
fcs - fvnl_dalpha,
518+
GlobalV::MY_RANK); // Hartree/Bohr, F_base
517519
}
518520
else
519521
{
@@ -690,15 +692,15 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
690692
#ifdef __DEEPKS
691693
if (PARAM.inp.deepks_out_labels) // not parallelized yet
692694
{
693-
if (PARAM.inp.deepks_out_labels==1)
695+
if (PARAM.inp.deepks_out_labels == 1)
694696
{
695697
const std::string file_stot = PARAM.globalv.global_out_dir + "deepks_stot.npy";
696698
LCAO_deepks_io::save_matrix2npy(file_stot,
697699
scs,
698700
GlobalV::MY_RANK,
699701
ucell.omega,
700702
'U'); // change to energy unit Ry when printing, S_tot;
701-
703+
702704
const std::string file_sbase = PARAM.globalv.global_out_dir + "deepks_sbase.npy";
703705
if (PARAM.inp.deepks_scf)
704706
{
@@ -710,16 +712,17 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
710712
}
711713
else
712714
{
713-
LCAO_deepks_io::save_matrix2npy(file_sbase, scs, GlobalV::MY_RANK, ucell.omega, 'U'); // sbase = stot
715+
LCAO_deepks_io::save_matrix2npy(file_sbase,
716+
scs,
717+
GlobalV::MY_RANK,
718+
ucell.omega,
719+
'U'); // sbase = stot
714720
}
715721
}
716-
else if (PARAM.inp.deepks_out_labels==2)
722+
else if (PARAM.inp.deepks_out_labels == 2)
717723
{
718724
const std::string file_stot = PARAM.globalv.global_out_dir + "deepks_stress.npy";
719-
LCAO_deepks_io::save_matrix2npy(file_stot,
720-
scs,
721-
GlobalV::MY_RANK,
722-
ucell.omega,
725+
LCAO_deepks_io::save_matrix2npy(file_stot, scs, GlobalV::MY_RANK, ucell.omega,
723726
'F'); // flat mode
724727
}
725728
}

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_allocate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void DeePKS_init(const UnitCell& ucell,
1818
{
1919
ModuleBase::TITLE("LCAO_domain", "DeePKS_init");
2020
// preparation for DeePKS
21-
if (PARAM.inp.deepks_out_labels==1 || PARAM.inp.deepks_scf)
21+
if (PARAM.inp.deepks_out_labels == 1 || PARAM.inp.deepks_scf)
2222
{
2323
// allocate relevant data structures for calculating descriptors
2424
std::vector<int> na;

source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
6060

6161
// Note : update PDM and all other quantities with the current dm
6262
// DeePKS PDM and descriptor
63-
if (PARAM.inp.deepks_out_labels==1 || PARAM.inp.deepks_scf)
63+
if (PARAM.inp.deepks_out_labels == 1 || PARAM.inp.deepks_scf)
6464
{
6565
// this part is for integrated test of deepks
6666
// so it is printed no matter even if deepks_out_labels is not used
@@ -81,13 +81,13 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
8181
rank);
8282

8383
LCAO_deepks_io::save_npy_d(nat,
84-
des_per_atom,
85-
inlmax,
86-
inl2l,
87-
PARAM.inp.deepks_equiv,
88-
descriptor,
89-
PARAM.globalv.global_out_dir,
90-
rank); // libnpy needed
84+
des_per_atom,
85+
inlmax,
86+
inl2l,
87+
PARAM.inp.deepks_equiv,
88+
descriptor,
89+
PARAM.globalv.global_out_dir,
90+
rank); // libnpy needed
9191

9292
if (PARAM.inp.deepks_scf)
9393
{
@@ -135,11 +135,11 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
135135
}
136136

137137
// Energy Part
138-
const std::string file_etot = PARAM.globalv.global_out_dir +
139-
(PARAM.inp.deepks_out_labels == 1 ? "deepks_etot.npy" : "deepks_energy.npy");
138+
const std::string file_etot = PARAM.globalv.global_out_dir
139+
+ (PARAM.inp.deepks_out_labels == 1 ? "deepks_etot.npy" : "deepks_energy.npy");
140140
LCAO_deepks_io::save_npy_e(etot, file_etot, rank);
141141

142-
if (PARAM.inp.deepks_out_labels ==1)
142+
if (PARAM.inp.deepks_out_labels == 1)
143143
{
144144
const std::string file_ebase = PARAM.globalv.global_out_dir + "deepks_ebase.npy";
145145
if (PARAM.inp.deepks_scf)
@@ -154,12 +154,10 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
154154
}
155155
}
156156

157-
158157
// Force Part
159158
if (PARAM.inp.cal_force)
160159
{
161-
if (PARAM.inp.deepks_scf
162-
&& PARAM.inp.deepks_out_labels == 1 // don't need these when deepks_out_labels == 2
160+
if (PARAM.inp.deepks_scf && PARAM.inp.deepks_out_labels == 1 // don't need these when deepks_out_labels == 2
163161
&& !PARAM.inp.deepks_equiv) // training with force label not supported by equivariant version now
164162
{
165163
torch::Tensor gdmx;
@@ -182,8 +180,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
182180
// Stress Part
183181
if (PARAM.inp.cal_stress)
184182
{
185-
if (PARAM.inp.deepks_scf
186-
&& PARAM.inp.deepks_out_labels == 1 // don't need these when deepks_out_labels == 2
183+
if (PARAM.inp.deepks_scf && PARAM.inp.deepks_out_labels == 1 // don't need these when deepks_out_labels == 2
187184
&& !PARAM.inp.deepks_equiv) // training with stress label not supported by equivariant version now
188185
{
189186
torch::Tensor gdmepsl;
@@ -214,11 +211,12 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
214211
o_tot(iks, 0) = ekb(iks, nocc) - ekb(iks, nocc - 1);
215212
}
216213

217-
const std::string file_otot = PARAM.globalv.global_out_dir +
218-
(PARAM.inp.deepks_out_labels == 1 ? "deepks_otot.npy" : "deepks_orbital.npy");
214+
const std::string file_otot
215+
= PARAM.globalv.global_out_dir
216+
+ (PARAM.inp.deepks_out_labels == 1 ? "deepks_otot.npy" : "deepks_orbital.npy");
219217
LCAO_deepks_io::save_matrix2npy(file_otot, o_tot, rank); // Unit: Hartree
220218

221-
if (PARAM.inp.deepks_out_labels == 1)// don't need these when deepks_out_labels == 2
219+
if (PARAM.inp.deepks_out_labels == 1) // don't need these when deepks_out_labels == 2
222220
{
223221
if (PARAM.inp.deepks_scf)
224222
{
@@ -241,20 +239,20 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
241239
// calculate and save orbital_precalc: [nks,NAt,NDscrpt]
242240
torch::Tensor orbital_precalc;
243241
DeePKS_domain::cal_orbital_precalc<TK, TH>(dm_bandgap,
244-
lmaxd,
245-
inlmax,
246-
nat,
247-
nks,
248-
inl2l,
249-
kvec_d,
250-
phialpha,
251-
gevdm,
252-
inl_index,
253-
ucell,
254-
orb,
255-
*ParaV,
256-
GridD,
257-
orbital_precalc);
242+
lmaxd,
243+
inlmax,
244+
nat,
245+
nks,
246+
inl2l,
247+
kvec_d,
248+
phialpha,
249+
gevdm,
250+
inl_index,
251+
ucell,
252+
orb,
253+
*ParaV,
254+
GridD,
255+
orbital_precalc);
258256
DeePKS_domain::cal_o_delta<TK, TH>(dm_bandgap, *h_delta, o_delta, *ParaV, nks, nspin);
259257

260258
// save obase and orbital_precalc
@@ -270,7 +268,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
270268
LCAO_deepks_io::save_matrix2npy(file_obase, o_tot, rank); // no scf, o_tot=o_base
271269
} // end deepks_scf == 0
272270
} // end deepks_out_labels == 1
273-
} // end bandgap label
271+
} // end bandgap label
274272

275273
// not add deepks_out_labels = 2 for HR yet
276274
// H(R) matrix part, for HR, base will not be calculated since they are HContainer objects
@@ -338,11 +336,12 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
338336
std::vector<TH> h_tot(nks);
339337
DeePKS_domain::get_h_tot<TK, TH, TR>(*ParaV, p_ham, h_tot, nlocal, nks, 'H');
340338

341-
const std::string file_htot = PARAM.globalv.global_out_dir +
342-
(PARAM.inp.deepks_out_labels == 1 ? "deepks_htot.npy" : "deepks_hamiltonian.npy");
339+
const std::string file_htot
340+
= PARAM.globalv.global_out_dir
341+
+ (PARAM.inp.deepks_out_labels == 1 ? "deepks_htot.npy" : "deepks_hamiltonian.npy");
343342
LCAO_deepks_io::save_npy_h<TK, TH>(h_tot, file_htot, nlocal, nks, rank);
344343

345-
if (PARAM.inp.deepks_out_labels == 1)// don't need these when deepks_out_labels == 2
344+
if (PARAM.inp.deepks_out_labels == 1) // don't need these when deepks_out_labels == 2
346345
{
347346
if (PARAM.inp.deepks_scf)
348347
{
@@ -370,29 +369,39 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
370369
{
371370
torch::Tensor v_delta_precalc;
372371
DeePKS_domain::cal_v_delta_precalc<TK>(nlocal,
372+
lmaxd,
373+
inlmax,
374+
nat,
375+
nks,
376+
inl2l,
377+
kvec_d,
378+
phialpha,
379+
gevdm,
380+
inl_index,
381+
ucell,
382+
orb,
383+
*ParaV,
384+
GridD,
385+
v_delta_precalc);
386+
387+
const std::string file_vdpre = PARAM.globalv.global_out_dir + "deepks_vdpre.npy";
388+
LCAO_deepks_io::save_tensor2npy<TK>(file_vdpre, v_delta_precalc, rank);
389+
}
390+
else if (PARAM.inp.deepks_v_delta == 2) // v_delta_precalc storage method 2
391+
{
392+
torch::Tensor phialpha_out;
393+
DeePKS_domain::prepare_phialpha<TK>(nlocal,
373394
lmaxd,
374395
inlmax,
375396
nat,
376397
nks,
377-
inl2l,
378398
kvec_d,
379399
phialpha,
380-
gevdm,
381-
inl_index,
382400
ucell,
383401
orb,
384402
*ParaV,
385403
GridD,
386-
v_delta_precalc);
387-
388-
const std::string file_vdpre = PARAM.globalv.global_out_dir + "deepks_vdpre.npy";
389-
LCAO_deepks_io::save_tensor2npy<TK>(file_vdpre, v_delta_precalc, rank);
390-
}
391-
else if (PARAM.inp.deepks_v_delta == 2) // v_delta_precalc storage method 2
392-
{
393-
torch::Tensor phialpha_out;
394-
DeePKS_domain::prepare_phialpha<
395-
TK>(nlocal, lmaxd, inlmax, nat, nks, kvec_d, phialpha, ucell, orb, *ParaV, GridD, phialpha_out);
404+
phialpha_out);
396405
const std::string file_phialpha = PARAM.globalv.global_out_dir + "deepks_phialpha.npy";
397406
LCAO_deepks_io::save_tensor2npy<TK>(file_phialpha, phialpha_out, rank);
398407

@@ -407,8 +416,8 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
407416
const std::string file_hbase = PARAM.globalv.global_out_dir + "deepks_hbase.npy";
408417
LCAO_deepks_io::save_npy_h<TK, TH>(h_tot, file_hbase, nlocal, nks, rank);
409418
}
410-
}// end deepks_out_labels == 1
411-
} // end v_delta label
419+
} // end deepks_out_labels == 1
420+
} // end v_delta label
412421

413422
} // end deepks_out_labels
414423

@@ -427,11 +436,16 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
427436

428437
if (PARAM.inp.deepks_v_delta > 0)
429438
{
430-
//prepare for overlap.npy, very much like h_tot except for p_ham->getSk()
439+
// prepare for overlap.npy, very much like h_tot except for p_ham->getSk()
431440
std::vector<TH> s_tot(nks);
432441
DeePKS_domain::get_h_tot<TK, TH, TR>(*ParaV, p_ham, s_tot, nlocal, nks, 'S');
433442
const std::string file_stot = PARAM.globalv.global_out_dir + "deepks_overlap.npy";
434-
LCAO_deepks_io::save_npy_h<TK, TH>(s_tot, file_stot, nlocal, nks, rank, 1.0);// don't need unit_scale for overlap
443+
LCAO_deepks_io::save_npy_h<TK, TH>(s_tot,
444+
file_stot,
445+
nlocal,
446+
nks,
447+
rank,
448+
1.0); // don't need unit_scale for overlap
435449
}
436450
}
437451

source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void LCAO_deepks_io::save_matrix2npy(const std::string& file_name,
216216
shape[0] = nr;
217217
shape[1] = nc;
218218
}
219-
else if (mode == 'F') //flat
219+
else if (mode == 'F') // flat
220220
{
221221
size = nr * nc;
222222
shape.resize(1);
@@ -275,7 +275,8 @@ void LCAO_deepks_io::save_tensor2npy(const std::string& file_name, const torch::
275275
{
276276
return;
277277
}
278-
using T_tensor = typename std::conditional<std::is_same<T, std::complex<double>>::value, c10::complex<double>, T>::type;
278+
using T_tensor =
279+
typename std::conditional<std::is_same<T, std::complex<double>>::value, c10::complex<double>, T>::type;
279280
const int dim = tensor.dim();
280281
std::vector<long unsigned> shape(dim);
281282
for (int i = 0; i < dim; i++)

source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace LCAO_deepks_io
3232
/// 4. save_matrix2npy : ModuleBase::matrix -> .npy, for force, stress and orbital
3333
/// 5. save_tensor2npy : torch::Tensor -> .npy, for precalculation variables
3434

35-
/// Ry2Hartree : convert Ry to Hartree, for energy, force, stress, orbital and Hamiltonian, which is consistent with deepks-kit.
36-
/// Used in save_npy_e, save_npy_h and save_matrix2npy by default
35+
/// Ry2Hartree : convert Ry to Hartree, for energy, force, stress, orbital and Hamiltonian, which is consistent with
36+
/// deepks-kit. Used in save_npy_e, save_npy_h and save_matrix2npy by default
3737
constexpr double Ry2Hartree = 0.5;
3838

3939
/// print density matrices

source/module_hamilt_lcao/module_deepks/deepks_basic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#ifdef __DEEPKS
66
#include "deepks_basic.h"
77

8-
#include "module_base/timer.h"
98
#include "module_base/atom_in.h"
9+
#include "module_base/timer.h"
1010
#include "module_parameter/parameter.h"
1111

1212
// d(Descriptor) / d(projected density matrix)
@@ -237,7 +237,7 @@ void DeePKS_domain::check_gedm(const int inlmax, const std::vector<int>& inl2l,
237237
}
238238
}
239239

240-
void DeePKS_domain::prepare_atom(const UnitCell& ucell,torch::Tensor& atom_out)
240+
void DeePKS_domain::prepare_atom(const UnitCell& ucell, torch::Tensor& atom_out)
241241
{
242242
int nat = ucell.nat;
243243
atom_out = torch::zeros({nat, 4}, torch::TensorOptions().dtype(torch::kFloat64));
@@ -259,7 +259,7 @@ void DeePKS_domain::prepare_atom(const UnitCell& ucell,torch::Tensor& atom_out)
259259
}
260260
}
261261
}
262-
void DeePKS_domain::prepare_box(const UnitCell& ucell,torch::Tensor& box_out)
262+
void DeePKS_domain::prepare_box(const UnitCell& ucell, torch::Tensor& box_out)
263263
{
264264
box_out = torch::zeros({9}, torch::TensorOptions().dtype(torch::kFloat64));
265265

0 commit comments

Comments
 (0)