From 8c9edbf34ffa09c701286d2441fe73c9e80bc0e1 Mon Sep 17 00:00:00 2001 From: kirk0830 <67682086+kirk0830@users.noreply.github.com> Date: Mon, 25 Dec 2023 11:13:05 +0800 Subject: [PATCH] Refactor: update toWannier90 interface with `psi_initializer_nao` (#3371) * produce wrong results, will debug * implement lcao_in_pw * debug compile error of unittest * ecutwfc 20 is not compatible with mpirun -np 4, dont know why * add unittest for newly-added lcao_in_pw specific HSolver::solve * correct index of psig when passing values * initialize bx by and bz of INPUT so that elimiate undefined behavior * correct psi_initializer, allocate appropriate memory for psi. Delete redundant code in psi_initializer_nao * - avoid initial scf converting psig to psi when lcao_in_pw, - add normalization of psig when init_wfc = nao - correct timer of diagH_subspace_init function * add MPI reduce and add unit test on nspin = 4 case * repair hsolverPW::solve * repair paw part of lcao_in_pw specific HSolverPW::solve * update towannier90 interface with psi_initializer * recover the LCAO macro * update unittest of input_test * correct unittest --------- Co-authored-by: Zhao Tianqi Co-authored-by: dyzheng --- docs/advanced/input_files/input-main.md | 6 +- .../ABACUS_towannier90_lcao_in_pw/INPUT | 18 + .../ABACUS_towannier90_lcao_in_pw/INPUT-nscf | 18 + .../ABACUS_towannier90_lcao_in_pw/INPUT-scf | 11 + .../ABACUS_towannier90_lcao_in_pw/KPT | 67 ++ .../ABACUS_towannier90_lcao_in_pw/KPT-nscf | 67 ++ .../ABACUS_towannier90_lcao_in_pw/KPT-scf | 4 + .../ABACUS_towannier90_lcao_in_pw/STRU | 21 + .../diamond.nnkp | 623 ++++++++++++++++++ .../ABACUS_towannier90_lcao_in_pw/diamond.win | 96 +++ .../hamilt_lcaodft/local_orbital_wfc.cpp | 10 +- source/module_io/input.cpp | 28 +- source/module_io/test/input_test.cpp | 13 +- source/module_io/to_wannier90_lcao_in_pw.cpp | 90 +-- source/module_io/to_wannier90_lcao_in_pw.h | 21 +- source/module_psi/psi_initializer.cpp | 51 +- source/module_psi/psi_initializer.h | 3 +- 17 files changed, 1039 insertions(+), 108 deletions(-) create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-nscf create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-scf create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-nscf create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-scf create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/STRU create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.nnkp create mode 100644 examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.win diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index f7eafed9cf..c9a6c1c5be 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -75,9 +75,9 @@ - [mixing\_gg0](#mixing_gg0) - [mixing\_gg0\_mag](#mixing_gg0_mag) - [mixing\_gg0\_min](#mixing_gg0_min) + - [mixing\_angle](#mixing_angle) - [mixing\_tau](#mixing_tau) - [mixing\_dftu](#mixing_dftu) - - [mixing\_angle](#mixing_angle) - [gamma\_only](#gamma_only) - [printe](#printe) - [scf\_nmax](#scf_nmax) @@ -876,7 +876,7 @@ calculations. - **Description**: Choose the basis set. - **pw**: Using plane-wave basis set only. - **lcao**: Using localized atomic orbital sets. - - **lcao_in_pw**: (Unavailable currently, it will be fixed in future versions) Expand the localized atomic set in plane-wave basis. + - **lcao_in_pw**: Expand the localized atomic set in plane-wave basis, non-self-consistent field calculation not tested. - **Default**: pw ### ks_solver @@ -2746,7 +2746,7 @@ These variables are used to control berry phase and wannier90 interface paramete - **Type**: Integer - **Description**: Only available on LCAO basis, using different methods to generate "\*.mmn" file and "\*.amn" file. - - 1: Calculated using the LCOA-in-PW method, the calculation accuracy can be improved by increasing `ecutwfc` to maintain consistency with the pw basis set results. + - 1: Calculated using the `lcao_in_pw` method, the calculation accuracy can be improved by increasing `ecutwfc` to maintain consistency with the pw basis set results. - 2: The overlap between atomic orbitals is calculated using grid integration. The radial grid points are generated using the Gauss-Legendre method, while the spherical grid points are generated using the Lebedev-Laikov method. - **Default**: 1 diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT new file mode 100644 index 0000000000..bd326e7944 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT @@ -0,0 +1,18 @@ +INPUT_PARAMETERS + +pseudo_dir ../../../tests/PP_ORB +orbital_dir ../../../tests/PP_ORB +ntype 1 +ecutwfc 50 +nbands 12 +calculation nscf +scf_nmax 50 +pw_diag_thr 1.0e-12 +scf_thr 1.0e-15 +init_chg file +symmetry 0 +towannier90 1 +wannier_method 1 +nnkpfile diamond.nnkp +basis_type lcao + diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-nscf b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-nscf new file mode 100644 index 0000000000..bd326e7944 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-nscf @@ -0,0 +1,18 @@ +INPUT_PARAMETERS + +pseudo_dir ../../../tests/PP_ORB +orbital_dir ../../../tests/PP_ORB +ntype 1 +ecutwfc 50 +nbands 12 +calculation nscf +scf_nmax 50 +pw_diag_thr 1.0e-12 +scf_thr 1.0e-15 +init_chg file +symmetry 0 +towannier90 1 +wannier_method 1 +nnkpfile diamond.nnkp +basis_type lcao + diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-scf b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-scf new file mode 100644 index 0000000000..91d87fa7e0 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/INPUT-scf @@ -0,0 +1,11 @@ +INPUT_PARAMETERS + +pseudo_dir ../../../tests/PP_ORB +orbital_dir ../../../tests/PP_ORB +ntype 1 +ecutwfc 50 +calculation scf +scf_thr 1e-13 +out_chg 1 +basis_type lcao_in_pw +ks_solver lapack diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT new file mode 100644 index 0000000000..cfb553c097 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT @@ -0,0 +1,67 @@ +K_POINTS +64 +Direct +0.0000 0.0000 0.0000 0.0156250 +0.0000 0.2500 0.0000 0.0156250 +0.0000 0.5000 0.0000 0.0156250 +0.0000 0.7500 0.0000 0.0156250 +0.2500 0.0000 0.0000 0.0156250 +0.2500 0.2500 0.0000 0.0156250 +0.2500 0.5000 0.0000 0.0156250 +0.2500 0.7500 0.0000 0.0156250 +0.5000 0.0000 0.0000 0.0156250 +0.5000 0.2500 0.0000 0.0156250 +0.5000 0.5000 0.0000 0.0156250 +0.5000 0.7500 0.0000 0.0156250 +0.7500 0.0000 0.0000 0.0156250 +0.7500 0.2500 0.0000 0.0156250 +0.7500 0.5000 0.0000 0.0156250 +0.7500 0.7500 0.0000 0.0156250 +0.0000 0.0000 0.2500 0.0156250 +0.0000 0.2500 0.2500 0.0156250 +0.0000 0.5000 0.2500 0.0156250 +0.0000 0.7500 0.2500 0.0156250 +0.2500 0.0000 0.2500 0.0156250 +0.2500 0.2500 0.2500 0.0156250 +0.2500 0.5000 0.2500 0.0156250 +0.2500 0.7500 0.2500 0.0156250 +0.5000 0.0000 0.2500 0.0156250 +0.5000 0.2500 0.2500 0.0156250 +0.5000 0.5000 0.2500 0.0156250 +0.5000 0.7500 0.2500 0.0156250 +0.7500 0.0000 0.2500 0.0156250 +0.7500 0.2500 0.2500 0.0156250 +0.7500 0.5000 0.2500 0.0156250 +0.7500 0.7500 0.2500 0.0156250 +0.0000 0.0000 0.5000 0.0156250 +0.0000 0.2500 0.5000 0.0156250 +0.0000 0.5000 0.5000 0.0156250 +0.0000 0.7500 0.5000 0.0156250 +0.2500 0.0000 0.5000 0.0156250 +0.2500 0.2500 0.5000 0.0156250 +0.2500 0.5000 0.5000 0.0156250 +0.2500 0.7500 0.5000 0.0156250 +0.5000 0.0000 0.5000 0.0156250 +0.5000 0.2500 0.5000 0.0156250 +0.5000 0.5000 0.5000 0.0156250 +0.5000 0.7500 0.5000 0.0156250 +0.7500 0.0000 0.5000 0.0156250 +0.7500 0.2500 0.5000 0.0156250 +0.7500 0.5000 0.5000 0.0156250 +0.7500 0.7500 0.5000 0.0156250 +0.0000 0.0000 0.7500 0.0156250 +0.0000 0.2500 0.7500 0.0156250 +0.0000 0.5000 0.7500 0.0156250 +0.0000 0.7500 0.7500 0.0156250 +0.2500 0.0000 0.7500 0.0156250 +0.2500 0.2500 0.7500 0.0156250 +0.2500 0.5000 0.7500 0.0156250 +0.2500 0.7500 0.7500 0.0156250 +0.5000 0.0000 0.7500 0.0156250 +0.5000 0.2500 0.7500 0.0156250 +0.5000 0.5000 0.7500 0.0156250 +0.5000 0.7500 0.7500 0.0156250 +0.7500 0.0000 0.7500 0.0156250 +0.7500 0.2500 0.7500 0.0156250 +0.7500 0.5000 0.7500 0.0156250 +0.7500 0.7500 0.7500 0.0156250 diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-nscf b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-nscf new file mode 100644 index 0000000000..cfb553c097 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-nscf @@ -0,0 +1,67 @@ +K_POINTS +64 +Direct +0.0000 0.0000 0.0000 0.0156250 +0.0000 0.2500 0.0000 0.0156250 +0.0000 0.5000 0.0000 0.0156250 +0.0000 0.7500 0.0000 0.0156250 +0.2500 0.0000 0.0000 0.0156250 +0.2500 0.2500 0.0000 0.0156250 +0.2500 0.5000 0.0000 0.0156250 +0.2500 0.7500 0.0000 0.0156250 +0.5000 0.0000 0.0000 0.0156250 +0.5000 0.2500 0.0000 0.0156250 +0.5000 0.5000 0.0000 0.0156250 +0.5000 0.7500 0.0000 0.0156250 +0.7500 0.0000 0.0000 0.0156250 +0.7500 0.2500 0.0000 0.0156250 +0.7500 0.5000 0.0000 0.0156250 +0.7500 0.7500 0.0000 0.0156250 +0.0000 0.0000 0.2500 0.0156250 +0.0000 0.2500 0.2500 0.0156250 +0.0000 0.5000 0.2500 0.0156250 +0.0000 0.7500 0.2500 0.0156250 +0.2500 0.0000 0.2500 0.0156250 +0.2500 0.2500 0.2500 0.0156250 +0.2500 0.5000 0.2500 0.0156250 +0.2500 0.7500 0.2500 0.0156250 +0.5000 0.0000 0.2500 0.0156250 +0.5000 0.2500 0.2500 0.0156250 +0.5000 0.5000 0.2500 0.0156250 +0.5000 0.7500 0.2500 0.0156250 +0.7500 0.0000 0.2500 0.0156250 +0.7500 0.2500 0.2500 0.0156250 +0.7500 0.5000 0.2500 0.0156250 +0.7500 0.7500 0.2500 0.0156250 +0.0000 0.0000 0.5000 0.0156250 +0.0000 0.2500 0.5000 0.0156250 +0.0000 0.5000 0.5000 0.0156250 +0.0000 0.7500 0.5000 0.0156250 +0.2500 0.0000 0.5000 0.0156250 +0.2500 0.2500 0.5000 0.0156250 +0.2500 0.5000 0.5000 0.0156250 +0.2500 0.7500 0.5000 0.0156250 +0.5000 0.0000 0.5000 0.0156250 +0.5000 0.2500 0.5000 0.0156250 +0.5000 0.5000 0.5000 0.0156250 +0.5000 0.7500 0.5000 0.0156250 +0.7500 0.0000 0.5000 0.0156250 +0.7500 0.2500 0.5000 0.0156250 +0.7500 0.5000 0.5000 0.0156250 +0.7500 0.7500 0.5000 0.0156250 +0.0000 0.0000 0.7500 0.0156250 +0.0000 0.2500 0.7500 0.0156250 +0.0000 0.5000 0.7500 0.0156250 +0.0000 0.7500 0.7500 0.0156250 +0.2500 0.0000 0.7500 0.0156250 +0.2500 0.2500 0.7500 0.0156250 +0.2500 0.5000 0.7500 0.0156250 +0.2500 0.7500 0.7500 0.0156250 +0.5000 0.0000 0.7500 0.0156250 +0.5000 0.2500 0.7500 0.0156250 +0.5000 0.5000 0.7500 0.0156250 +0.5000 0.7500 0.7500 0.0156250 +0.7500 0.0000 0.7500 0.0156250 +0.7500 0.2500 0.7500 0.0156250 +0.7500 0.5000 0.7500 0.0156250 +0.7500 0.7500 0.7500 0.0156250 diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-scf b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-scf new file mode 100644 index 0000000000..1de1e15c0f --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/KPT-scf @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +12 12 12 0 0 0 diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/STRU b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/STRU new file mode 100644 index 0000000000..96bfb06a13 --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/STRU @@ -0,0 +1,21 @@ +ATOMIC_SPECIES +C 12.000 C.LDA.UPF + +NUMERICAL_ORBITAL +C_lda_8.0au_100Ry_2s2p1d.orb + +LATTICE_CONSTANT +6.1 + +LATTICE_VECTORS +-0.5 0.0 0.5 + 0.0 0.5 0.5 +-0.5 0.5 0.0 + +ATOMIC_POSITIONS +Direct +C +0.0 +2 + 0.875 0.875 0.875 0 0 0 + 0.125 0.125 0.125 0 0 0 diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.nnkp b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.nnkp new file mode 100644 index 0000000000..227577aa3c --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.nnkp @@ -0,0 +1,623 @@ +File written on 27Aug2023 at 11:41:45 + +calc_only_A : F + +begin real_lattice + -1.6139900 0.0000000 1.6139900 + 0.0000000 1.6139900 1.6139900 + -1.6139900 1.6139900 0.0000000 +end real_lattice + +begin recip_lattice + -1.9464759 -1.9464759 1.9464759 + 1.9464759 1.9464759 1.9464759 + -1.9464759 1.9464759 -1.9464759 +end recip_lattice + +begin kpoints + 64 + 0.00000000 0.00000000 0.00000000 + 0.00000000 0.25000000 0.00000000 + 0.00000000 0.50000000 0.00000000 + 0.00000000 0.75000000 0.00000000 + 0.25000000 0.00000000 0.00000000 + 0.25000000 0.25000000 0.00000000 + 0.25000000 0.50000000 0.00000000 + 0.25000000 0.75000000 0.00000000 + 0.50000000 0.00000000 0.00000000 + 0.50000000 0.25000000 0.00000000 + 0.50000000 0.50000000 0.00000000 + 0.50000000 0.75000000 0.00000000 + 0.75000000 0.00000000 0.00000000 + 0.75000000 0.25000000 0.00000000 + 0.75000000 0.50000000 0.00000000 + 0.75000000 0.75000000 0.00000000 + 0.00000000 0.00000000 0.25000000 + 0.00000000 0.25000000 0.25000000 + 0.00000000 0.50000000 0.25000000 + 0.00000000 0.75000000 0.25000000 + 0.25000000 0.00000000 0.25000000 + 0.25000000 0.25000000 0.25000000 + 0.25000000 0.50000000 0.25000000 + 0.25000000 0.75000000 0.25000000 + 0.50000000 0.00000000 0.25000000 + 0.50000000 0.25000000 0.25000000 + 0.50000000 0.50000000 0.25000000 + 0.50000000 0.75000000 0.25000000 + 0.75000000 0.00000000 0.25000000 + 0.75000000 0.25000000 0.25000000 + 0.75000000 0.50000000 0.25000000 + 0.75000000 0.75000000 0.25000000 + 0.00000000 0.00000000 0.50000000 + 0.00000000 0.25000000 0.50000000 + 0.00000000 0.50000000 0.50000000 + 0.00000000 0.75000000 0.50000000 + 0.25000000 0.00000000 0.50000000 + 0.25000000 0.25000000 0.50000000 + 0.25000000 0.50000000 0.50000000 + 0.25000000 0.75000000 0.50000000 + 0.50000000 0.00000000 0.50000000 + 0.50000000 0.25000000 0.50000000 + 0.50000000 0.50000000 0.50000000 + 0.50000000 0.75000000 0.50000000 + 0.75000000 0.00000000 0.50000000 + 0.75000000 0.25000000 0.50000000 + 0.75000000 0.50000000 0.50000000 + 0.75000000 0.75000000 0.50000000 + 0.00000000 0.00000000 0.75000000 + 0.00000000 0.25000000 0.75000000 + 0.00000000 0.50000000 0.75000000 + 0.00000000 0.75000000 0.75000000 + 0.25000000 0.00000000 0.75000000 + 0.25000000 0.25000000 0.75000000 + 0.25000000 0.50000000 0.75000000 + 0.25000000 0.75000000 0.75000000 + 0.50000000 0.00000000 0.75000000 + 0.50000000 0.25000000 0.75000000 + 0.50000000 0.50000000 0.75000000 + 0.50000000 0.75000000 0.75000000 + 0.75000000 0.00000000 0.75000000 + 0.75000000 0.25000000 0.75000000 + 0.75000000 0.50000000 0.75000000 + 0.75000000 0.75000000 0.75000000 +end kpoints + +begin projections + 8 + 0.87500 0.87500 0.87500 0 1 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.87500 0.87500 0.87500 1 1 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.87500 0.87500 0.87500 1 2 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.87500 0.87500 0.87500 1 3 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.12500 0.12500 0.12500 0 1 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.12500 0.12500 0.12500 1 1 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.12500 0.12500 0.12500 1 2 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 + 0.12500 0.12500 0.12500 1 3 1 + 0.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.00 +end projections + +begin nnkpts + 8 + 1 2 0 0 0 + 1 5 0 0 0 + 1 17 0 0 0 + 1 22 0 0 0 + 1 49 0 0 -1 + 1 4 0 -1 0 + 1 13 -1 0 0 + 1 64 -1 -1 -1 + 2 1 0 0 0 + 2 3 0 0 0 + 2 6 0 0 0 + 2 18 0 0 0 + 2 23 0 0 0 + 2 50 0 0 -1 + 2 14 -1 0 0 + 2 61 -1 0 -1 + 3 2 0 0 0 + 3 4 0 0 0 + 3 7 0 0 0 + 3 19 0 0 0 + 3 24 0 0 0 + 3 51 0 0 -1 + 3 15 -1 0 0 + 3 62 -1 0 -1 + 4 3 0 0 0 + 4 8 0 0 0 + 4 20 0 0 0 + 4 1 0 1 0 + 4 21 0 1 0 + 4 52 0 0 -1 + 4 16 -1 0 0 + 4 63 -1 0 -1 + 5 1 0 0 0 + 5 6 0 0 0 + 5 9 0 0 0 + 5 21 0 0 0 + 5 26 0 0 0 + 5 53 0 0 -1 + 5 8 0 -1 0 + 5 52 0 -1 -1 + 6 2 0 0 0 + 6 5 0 0 0 + 6 7 0 0 0 + 6 10 0 0 0 + 6 22 0 0 0 + 6 27 0 0 0 + 6 49 0 0 -1 + 6 54 0 0 -1 + 7 3 0 0 0 + 7 6 0 0 0 + 7 8 0 0 0 + 7 11 0 0 0 + 7 23 0 0 0 + 7 28 0 0 0 + 7 50 0 0 -1 + 7 55 0 0 -1 + 8 4 0 0 0 + 8 7 0 0 0 + 8 12 0 0 0 + 8 24 0 0 0 + 8 5 0 1 0 + 8 25 0 1 0 + 8 51 0 0 -1 + 8 56 0 0 -1 + 9 5 0 0 0 + 9 10 0 0 0 + 9 13 0 0 0 + 9 25 0 0 0 + 9 30 0 0 0 + 9 57 0 0 -1 + 9 12 0 -1 0 + 9 56 0 -1 -1 + 10 6 0 0 0 + 10 9 0 0 0 + 10 11 0 0 0 + 10 14 0 0 0 + 10 26 0 0 0 + 10 31 0 0 0 + 10 53 0 0 -1 + 10 58 0 0 -1 + 11 7 0 0 0 + 11 10 0 0 0 + 11 12 0 0 0 + 11 15 0 0 0 + 11 27 0 0 0 + 11 32 0 0 0 + 11 54 0 0 -1 + 11 59 0 0 -1 + 12 8 0 0 0 + 12 11 0 0 0 + 12 16 0 0 0 + 12 28 0 0 0 + 12 9 0 1 0 + 12 29 0 1 0 + 12 55 0 0 -1 + 12 60 0 0 -1 + 13 9 0 0 0 + 13 14 0 0 0 + 13 29 0 0 0 + 13 1 1 0 0 + 13 18 1 0 0 + 13 61 0 0 -1 + 13 16 0 -1 0 + 13 60 0 -1 -1 + 14 10 0 0 0 + 14 13 0 0 0 + 14 15 0 0 0 + 14 30 0 0 0 + 14 2 1 0 0 + 14 19 1 0 0 + 14 57 0 0 -1 + 14 62 0 0 -1 + 15 11 0 0 0 + 15 14 0 0 0 + 15 16 0 0 0 + 15 31 0 0 0 + 15 3 1 0 0 + 15 20 1 0 0 + 15 58 0 0 -1 + 15 63 0 0 -1 + 16 12 0 0 0 + 16 15 0 0 0 + 16 32 0 0 0 + 16 4 1 0 0 + 16 13 0 1 0 + 16 59 0 0 -1 + 16 64 0 0 -1 + 16 17 1 1 0 + 17 1 0 0 0 + 17 18 0 0 0 + 17 21 0 0 0 + 17 33 0 0 0 + 17 38 0 0 0 + 17 20 0 -1 0 + 17 29 -1 0 0 + 17 16 -1 -1 0 + 18 2 0 0 0 + 18 17 0 0 0 + 18 19 0 0 0 + 18 22 0 0 0 + 18 34 0 0 0 + 18 39 0 0 0 + 18 13 -1 0 0 + 18 30 -1 0 0 + 19 3 0 0 0 + 19 18 0 0 0 + 19 20 0 0 0 + 19 23 0 0 0 + 19 35 0 0 0 + 19 40 0 0 0 + 19 14 -1 0 0 + 19 31 -1 0 0 + 20 4 0 0 0 + 20 19 0 0 0 + 20 24 0 0 0 + 20 36 0 0 0 + 20 17 0 1 0 + 20 37 0 1 0 + 20 15 -1 0 0 + 20 32 -1 0 0 + 21 5 0 0 0 + 21 17 0 0 0 + 21 22 0 0 0 + 21 25 0 0 0 + 21 37 0 0 0 + 21 42 0 0 0 + 21 4 0 -1 0 + 21 24 0 -1 0 + 22 1 0 0 0 + 22 6 0 0 0 + 22 18 0 0 0 + 22 21 0 0 0 + 22 23 0 0 0 + 22 26 0 0 0 + 22 38 0 0 0 + 22 43 0 0 0 + 23 2 0 0 0 + 23 7 0 0 0 + 23 19 0 0 0 + 23 22 0 0 0 + 23 24 0 0 0 + 23 27 0 0 0 + 23 39 0 0 0 + 23 44 0 0 0 + 24 3 0 0 0 + 24 8 0 0 0 + 24 20 0 0 0 + 24 23 0 0 0 + 24 28 0 0 0 + 24 40 0 0 0 + 24 21 0 1 0 + 24 41 0 1 0 + 25 9 0 0 0 + 25 21 0 0 0 + 25 26 0 0 0 + 25 29 0 0 0 + 25 41 0 0 0 + 25 46 0 0 0 + 25 8 0 -1 0 + 25 28 0 -1 0 + 26 5 0 0 0 + 26 10 0 0 0 + 26 22 0 0 0 + 26 25 0 0 0 + 26 27 0 0 0 + 26 30 0 0 0 + 26 42 0 0 0 + 26 47 0 0 0 + 27 6 0 0 0 + 27 11 0 0 0 + 27 23 0 0 0 + 27 26 0 0 0 + 27 28 0 0 0 + 27 31 0 0 0 + 27 43 0 0 0 + 27 48 0 0 0 + 28 7 0 0 0 + 28 12 0 0 0 + 28 24 0 0 0 + 28 27 0 0 0 + 28 32 0 0 0 + 28 44 0 0 0 + 28 25 0 1 0 + 28 45 0 1 0 + 29 13 0 0 0 + 29 25 0 0 0 + 29 30 0 0 0 + 29 45 0 0 0 + 29 17 1 0 0 + 29 34 1 0 0 + 29 12 0 -1 0 + 29 32 0 -1 0 + 30 9 0 0 0 + 30 14 0 0 0 + 30 26 0 0 0 + 30 29 0 0 0 + 30 31 0 0 0 + 30 46 0 0 0 + 30 18 1 0 0 + 30 35 1 0 0 + 31 10 0 0 0 + 31 15 0 0 0 + 31 27 0 0 0 + 31 30 0 0 0 + 31 32 0 0 0 + 31 47 0 0 0 + 31 19 1 0 0 + 31 36 1 0 0 + 32 11 0 0 0 + 32 16 0 0 0 + 32 28 0 0 0 + 32 31 0 0 0 + 32 48 0 0 0 + 32 20 1 0 0 + 32 29 0 1 0 + 32 33 1 1 0 + 33 17 0 0 0 + 33 34 0 0 0 + 33 37 0 0 0 + 33 49 0 0 0 + 33 54 0 0 0 + 33 36 0 -1 0 + 33 45 -1 0 0 + 33 32 -1 -1 0 + 34 18 0 0 0 + 34 33 0 0 0 + 34 35 0 0 0 + 34 38 0 0 0 + 34 50 0 0 0 + 34 55 0 0 0 + 34 29 -1 0 0 + 34 46 -1 0 0 + 35 19 0 0 0 + 35 34 0 0 0 + 35 36 0 0 0 + 35 39 0 0 0 + 35 51 0 0 0 + 35 56 0 0 0 + 35 30 -1 0 0 + 35 47 -1 0 0 + 36 20 0 0 0 + 36 35 0 0 0 + 36 40 0 0 0 + 36 52 0 0 0 + 36 33 0 1 0 + 36 53 0 1 0 + 36 31 -1 0 0 + 36 48 -1 0 0 + 37 21 0 0 0 + 37 33 0 0 0 + 37 38 0 0 0 + 37 41 0 0 0 + 37 53 0 0 0 + 37 58 0 0 0 + 37 20 0 -1 0 + 37 40 0 -1 0 + 38 17 0 0 0 + 38 22 0 0 0 + 38 34 0 0 0 + 38 37 0 0 0 + 38 39 0 0 0 + 38 42 0 0 0 + 38 54 0 0 0 + 38 59 0 0 0 + 39 18 0 0 0 + 39 23 0 0 0 + 39 35 0 0 0 + 39 38 0 0 0 + 39 40 0 0 0 + 39 43 0 0 0 + 39 55 0 0 0 + 39 60 0 0 0 + 40 19 0 0 0 + 40 24 0 0 0 + 40 36 0 0 0 + 40 39 0 0 0 + 40 44 0 0 0 + 40 56 0 0 0 + 40 37 0 1 0 + 40 57 0 1 0 + 41 25 0 0 0 + 41 37 0 0 0 + 41 42 0 0 0 + 41 45 0 0 0 + 41 57 0 0 0 + 41 62 0 0 0 + 41 24 0 -1 0 + 41 44 0 -1 0 + 42 21 0 0 0 + 42 26 0 0 0 + 42 38 0 0 0 + 42 41 0 0 0 + 42 43 0 0 0 + 42 46 0 0 0 + 42 58 0 0 0 + 42 63 0 0 0 + 43 22 0 0 0 + 43 27 0 0 0 + 43 39 0 0 0 + 43 42 0 0 0 + 43 44 0 0 0 + 43 47 0 0 0 + 43 59 0 0 0 + 43 64 0 0 0 + 44 23 0 0 0 + 44 28 0 0 0 + 44 40 0 0 0 + 44 43 0 0 0 + 44 48 0 0 0 + 44 60 0 0 0 + 44 41 0 1 0 + 44 61 0 1 0 + 45 29 0 0 0 + 45 41 0 0 0 + 45 46 0 0 0 + 45 61 0 0 0 + 45 33 1 0 0 + 45 50 1 0 0 + 45 28 0 -1 0 + 45 48 0 -1 0 + 46 25 0 0 0 + 46 30 0 0 0 + 46 42 0 0 0 + 46 45 0 0 0 + 46 47 0 0 0 + 46 62 0 0 0 + 46 34 1 0 0 + 46 51 1 0 0 + 47 26 0 0 0 + 47 31 0 0 0 + 47 43 0 0 0 + 47 46 0 0 0 + 47 48 0 0 0 + 47 63 0 0 0 + 47 35 1 0 0 + 47 52 1 0 0 + 48 27 0 0 0 + 48 32 0 0 0 + 48 44 0 0 0 + 48 47 0 0 0 + 48 64 0 0 0 + 48 36 1 0 0 + 48 45 0 1 0 + 48 49 1 1 0 + 49 33 0 0 0 + 49 50 0 0 0 + 49 53 0 0 0 + 49 1 0 0 1 + 49 6 0 0 1 + 49 52 0 -1 0 + 49 61 -1 0 0 + 49 48 -1 -1 0 + 50 34 0 0 0 + 50 49 0 0 0 + 50 51 0 0 0 + 50 54 0 0 0 + 50 2 0 0 1 + 50 7 0 0 1 + 50 45 -1 0 0 + 50 62 -1 0 0 + 51 35 0 0 0 + 51 50 0 0 0 + 51 52 0 0 0 + 51 55 0 0 0 + 51 3 0 0 1 + 51 8 0 0 1 + 51 46 -1 0 0 + 51 63 -1 0 0 + 52 36 0 0 0 + 52 51 0 0 0 + 52 56 0 0 0 + 52 49 0 1 0 + 52 4 0 0 1 + 52 47 -1 0 0 + 52 64 -1 0 0 + 52 5 0 1 1 + 53 37 0 0 0 + 53 49 0 0 0 + 53 54 0 0 0 + 53 57 0 0 0 + 53 5 0 0 1 + 53 10 0 0 1 + 53 36 0 -1 0 + 53 56 0 -1 0 + 54 33 0 0 0 + 54 38 0 0 0 + 54 50 0 0 0 + 54 53 0 0 0 + 54 55 0 0 0 + 54 58 0 0 0 + 54 6 0 0 1 + 54 11 0 0 1 + 55 34 0 0 0 + 55 39 0 0 0 + 55 51 0 0 0 + 55 54 0 0 0 + 55 56 0 0 0 + 55 59 0 0 0 + 55 7 0 0 1 + 55 12 0 0 1 + 56 35 0 0 0 + 56 40 0 0 0 + 56 52 0 0 0 + 56 55 0 0 0 + 56 60 0 0 0 + 56 53 0 1 0 + 56 8 0 0 1 + 56 9 0 1 1 + 57 41 0 0 0 + 57 53 0 0 0 + 57 58 0 0 0 + 57 61 0 0 0 + 57 9 0 0 1 + 57 14 0 0 1 + 57 40 0 -1 0 + 57 60 0 -1 0 + 58 37 0 0 0 + 58 42 0 0 0 + 58 54 0 0 0 + 58 57 0 0 0 + 58 59 0 0 0 + 58 62 0 0 0 + 58 10 0 0 1 + 58 15 0 0 1 + 59 38 0 0 0 + 59 43 0 0 0 + 59 55 0 0 0 + 59 58 0 0 0 + 59 60 0 0 0 + 59 63 0 0 0 + 59 11 0 0 1 + 59 16 0 0 1 + 60 39 0 0 0 + 60 44 0 0 0 + 60 56 0 0 0 + 60 59 0 0 0 + 60 64 0 0 0 + 60 57 0 1 0 + 60 12 0 0 1 + 60 13 0 1 1 + 61 45 0 0 0 + 61 57 0 0 0 + 61 62 0 0 0 + 61 49 1 0 0 + 61 13 0 0 1 + 61 44 0 -1 0 + 61 64 0 -1 0 + 61 2 1 0 1 + 62 41 0 0 0 + 62 46 0 0 0 + 62 58 0 0 0 + 62 61 0 0 0 + 62 63 0 0 0 + 62 50 1 0 0 + 62 14 0 0 1 + 62 3 1 0 1 + 63 42 0 0 0 + 63 47 0 0 0 + 63 59 0 0 0 + 63 62 0 0 0 + 63 64 0 0 0 + 63 51 1 0 0 + 63 15 0 0 1 + 63 4 1 0 1 + 64 43 0 0 0 + 64 48 0 0 0 + 64 60 0 0 0 + 64 63 0 0 0 + 64 1 1 1 1 + 64 52 1 0 0 + 64 61 0 1 0 + 64 16 0 0 1 +end nnkpts + +begin exclude_bands + 0 +end exclude_bands diff --git a/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.win b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.win new file mode 100644 index 0000000000..675745083d --- /dev/null +++ b/examples/interface_wannier90/ABACUS_towannier90_lcao_in_pw/diamond.win @@ -0,0 +1,96 @@ +num_bands = 12 +num_wann = 8 + +Begin Projections +C:s;px;py;pz +End Projections + +dis_num_iter = 5000 +num_iter = 5000 +num_print_cycles = 50 + +wannier_plot=.true. +wannier_plot_supercell = 3 +wvfn_formatted = .true. + +guiding_centres = .true. + +begin atoms_frac +C 0.875 0.875 0.875 +C 0.125 0.125 0.125 +end atoms_frac + +begin unit_cell_cart +-1.613990 0.000000 1.613990 + 0.000000 1.613990 1.613990 +-1.613990 1.613990 0.000000 +end unit_cell_cart + +mp_grid : 4 4 4 + +begin kpoints +0.0000 0.0000 0.0000 0.0156250 +0.0000 0.2500 0.0000 0.0156250 +0.0000 0.5000 0.0000 0.0156250 +0.0000 0.7500 0.0000 0.0156250 +0.2500 0.0000 0.0000 0.0156250 +0.2500 0.2500 0.0000 0.0156250 +0.2500 0.5000 0.0000 0.0156250 +0.2500 0.7500 0.0000 0.0156250 +0.5000 0.0000 0.0000 0.0156250 +0.5000 0.2500 0.0000 0.0156250 +0.5000 0.5000 0.0000 0.0156250 +0.5000 0.7500 0.0000 0.0156250 +0.7500 0.0000 0.0000 0.0156250 +0.7500 0.2500 0.0000 0.0156250 +0.7500 0.5000 0.0000 0.0156250 +0.7500 0.7500 0.0000 0.0156250 +0.0000 0.0000 0.2500 0.0156250 +0.0000 0.2500 0.2500 0.0156250 +0.0000 0.5000 0.2500 0.0156250 +0.0000 0.7500 0.2500 0.0156250 +0.2500 0.0000 0.2500 0.0156250 +0.2500 0.2500 0.2500 0.0156250 +0.2500 0.5000 0.2500 0.0156250 +0.2500 0.7500 0.2500 0.0156250 +0.5000 0.0000 0.2500 0.0156250 +0.5000 0.2500 0.2500 0.0156250 +0.5000 0.5000 0.2500 0.0156250 +0.5000 0.7500 0.2500 0.0156250 +0.7500 0.0000 0.2500 0.0156250 +0.7500 0.2500 0.2500 0.0156250 +0.7500 0.5000 0.2500 0.0156250 +0.7500 0.7500 0.2500 0.0156250 +0.0000 0.0000 0.5000 0.0156250 +0.0000 0.2500 0.5000 0.0156250 +0.0000 0.5000 0.5000 0.0156250 +0.0000 0.7500 0.5000 0.0156250 +0.2500 0.0000 0.5000 0.0156250 +0.2500 0.2500 0.5000 0.0156250 +0.2500 0.5000 0.5000 0.0156250 +0.2500 0.7500 0.5000 0.0156250 +0.5000 0.0000 0.5000 0.0156250 +0.5000 0.2500 0.5000 0.0156250 +0.5000 0.5000 0.5000 0.0156250 +0.5000 0.7500 0.5000 0.0156250 +0.7500 0.0000 0.5000 0.0156250 +0.7500 0.2500 0.5000 0.0156250 +0.7500 0.5000 0.5000 0.0156250 +0.7500 0.7500 0.5000 0.0156250 +0.0000 0.0000 0.7500 0.0156250 +0.0000 0.2500 0.7500 0.0156250 +0.0000 0.5000 0.7500 0.0156250 +0.0000 0.7500 0.7500 0.0156250 +0.2500 0.0000 0.7500 0.0156250 +0.2500 0.2500 0.7500 0.0156250 +0.2500 0.5000 0.7500 0.0156250 +0.2500 0.7500 0.7500 0.0156250 +0.5000 0.0000 0.7500 0.0156250 +0.5000 0.2500 0.7500 0.0156250 +0.5000 0.5000 0.7500 0.0156250 +0.5000 0.7500 0.7500 0.0156250 +0.7500 0.0000 0.7500 0.0156250 +0.7500 0.2500 0.7500 0.0156250 +0.7500 0.5000 0.7500 0.0156250 +0.7500 0.7500 0.7500 0.0156250 +end kpoints diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.cpp index bbbb7e456b..d78adb5fc2 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.cpp @@ -223,7 +223,7 @@ void Local_Orbital_wfc::wfc_2d_to_grid(const int istep, const ModuleBase::matrix& wg) { ModuleBase::TITLE(" Local_Orbital_wfc", "wfc_2d_to_grid"); - ModuleBase::timer::tick(" Local_Orbital_wfc","wfc_2d_to_grid"); + ModuleBase::timer::tick("Local_Orbital_wfc","wfc_2d_to_grid"); const Parallel_Orbitals* pv = this->ParaV; const int inc = 1; @@ -319,7 +319,7 @@ void Local_Orbital_wfc::wfc_2d_to_grid(const int istep, delete[] ctot; } delete[] work; - ModuleBase::timer::tick(" Local_Orbital_wfc","wfc_2d_to_grid"); + ModuleBase::timer::tick("Local_Orbital_wfc","wfc_2d_to_grid"); } void Local_Orbital_wfc::wfc_2d_to_grid(const int istep, @@ -331,8 +331,8 @@ void Local_Orbital_wfc::wfc_2d_to_grid(const int istep, const ModuleBase::matrix& wg, const std::vector>& kvec_c) { - ModuleBase::TITLE(" Local_Orbital_wfc", "wfc_2d_to_grid"); - ModuleBase::timer::tick(" Local_Orbital_wfc","wfc_2d_to_grid"); + ModuleBase::TITLE("Local_Orbital_wfc", "wfc_2d_to_grid"); + ModuleBase::timer::tick("Local_Orbital_wfc","wfc_2d_to_grid"); const Parallel_Orbitals* pv = this->ParaV; const int inc = 1; @@ -430,6 +430,6 @@ void Local_Orbital_wfc::wfc_2d_to_grid(const int istep, delete[] ctot; } delete[] work; - ModuleBase::timer::tick(" Local_Orbital_wfc","wfc_2d_to_grid"); + ModuleBase::timer::tick("Local_Orbital_wfc","wfc_2d_to_grid"); } #endif \ No newline at end of file diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index 7fa04172a7..2a2d7707f8 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -3958,9 +3958,33 @@ void Input::Check(void) if (towannier90) { - if (basis_type != "pw" && basis_type != "lcao") + if (basis_type == "lcao_in_pw") { - ModuleBase::WARNING_QUIT("Input", "to use towannier90, please set basis_type = pw or lcao"); + /* + Developer's notes: on the repair of lcao_in_pw + + lcao_in_pw is a special basis_type, for scf calculation, it follows workflow of pw, + but for nscf the toWannier90 calculation, the interface is in ESolver_KS_LCAO_elec, + therefore lcao_in_pw for towannier90 calculation follows lcao. + + In the future lcao_in_pw will have its own ESolver. + + 2023/12/22 use new psi_initializer to expand numerical atomic orbitals, ykhuang + */ + basis_type = "lcao"; + wannier_method = 1; // it is the way to call toWannier90_lcao_in_pw + #ifdef __ELPA + ks_solver = "genelpa"; + #else + ks_solver = "scalapack_gvx"; + #endif + } + else + { + if ((basis_type != "pw")&&(basis_type != "lcao")) + { + ModuleBase::WARNING_QUIT("Input", "to use towannier90, please set basis_type = pw, lcao or lcao_in_pw"); + } } if (calculation != "nscf") { diff --git a/source/module_io/test/input_test.cpp b/source/module_io/test/input_test.cpp index 2bf6c52182..02e69b98b8 100644 --- a/source/module_io/test/input_test.cpp +++ b/source/module_io/test/input_test.cpp @@ -1523,12 +1523,13 @@ TEST_F(InputTest, Check) INPUT.berry_phase = 0; // INPUT.towannier90 = 1; - INPUT.basis_type = "lcao_in_pw"; - INPUT.ks_solver = "lapack"; - testing::internal::CaptureStdout(); - EXPECT_EXIT(INPUT.Check(),::testing::ExitedWithCode(0), ""); - output = testing::internal::GetCapturedStdout(); - EXPECT_THAT(output,testing::HasSubstr("to use towannier90, please set basis_type = pw or lcao")); + // due to the repair of lcao_in_pw, original warning has been deprecated, 2023/12/23, ykhuang + // INPUT.basis_type = "lcao_in_pw"; + // INPUT.ks_solver = "lapack"; + // testing::internal::CaptureStdout(); + // EXPECT_EXIT(INPUT.Check(),::testing::ExitedWithCode(0), ""); + // output = testing::internal::GetCapturedStdout(); + // EXPECT_THAT(output,testing::HasSubstr("to use towannier90, please set basis_type = pw or lcao")); INPUT.basis_type = "pw"; INPUT.ks_solver = "cg"; // diff --git a/source/module_io/to_wannier90_lcao_in_pw.cpp b/source/module_io/to_wannier90_lcao_in_pw.cpp index 046ffcc0ef..14a8dd4e40 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.cpp +++ b/source/module_io/to_wannier90_lcao_in_pw.cpp @@ -8,6 +8,7 @@ #include "module_base/parallel_reduce.h" #include "binstream.h" +#include "module_psi/psi_initializer_nao.h" #ifdef __LCAO toWannier90_LCAO_IN_PW::toWannier90_LCAO_IN_PW( const bool &out_wannier_mmn, @@ -39,6 +40,19 @@ void toWannier90_LCAO_IN_PW::calculate( { this->ParaV = pv; + Structure_Factor* sf_ptr = const_cast(&sf); + ModulePW::PW_Basis_K* wfcpw_ptr = const_cast(wfcpw); + #ifdef __MPI + this->psi_init_ = new psi_initializer_nao, psi::DEVICE_CPU>( + sf_ptr, wfcpw_ptr, &(GlobalC::ucell), &(GlobalC::Pkpoints)); + #else + this->psi_init_ = new psi_initializer_nao, psi::DEVICE_CPU>( + sf_ptr, wfcpw_ptr, &(GlobalC::ucell)); + #endif + this->psi_init_->set_orbital_files(GlobalC::ucell.orbital_fn); + this->psi_init_->initialize_only_once(); + this->psi_init_->cal_ovlp_flzjlq(); + this->psi_init_->allocate(true); read_nnkp(kv); if (GlobalV::NSPIN == 2) @@ -107,14 +121,15 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( // Orbital projection to plane wave ModuleBase::realArray table_local(GlobalC::ucell.ntype, GlobalC::ucell.nmax_total, GlobalV::NQX); - Wavefunc_in_pw::make_table_q(GlobalC::ORB.orbital_file, table_local); + //Wavefunc_in_pw::make_table_q(GlobalC::ORB.orbital_file, table_local); for (int ik = 0; ik < num_kpts; ik++) { int npw = kv.ngk[ik]; ModuleBase::ComplexMatrix orbital_in_G(GlobalV::NLOCAL, npwx*GlobalV::NPOL); // Wavefunc_in_pw::produce_local_basis_in_pw(ik, wfcpw, sf, orbital_in_G, table_local); - produce_local_basis_in_pw(ik, wfcpw, sf, orbital_in_G, table_local); + //produce_local_basis_in_pw(ik, wfcpw, sf, orbital_in_G, table_local); + nao_G_expansion(ik, wfcpw, orbital_in_G); ModuleBase::ComplexMatrix lcao_wfc_global; get_lcao_wfc_global_ik(ik, psi_in, lcao_wfc_global); @@ -196,70 +211,23 @@ psi::Psi>* toWannier90_LCAO_IN_PW::get_unk_from_lcao( return unk_inLcao; } -void toWannier90_LCAO_IN_PW::produce_local_basis_in_pw( +void toWannier90_LCAO_IN_PW::nao_G_expansion( const int& ik, - const ModulePW::PW_Basis_K* wfc_basis, - const Structure_Factor& sf, - ModuleBase::ComplexMatrix& psi, - const ModuleBase::realArray& table_local + const ModulePW::PW_Basis_K* wfcpw, + ModuleBase::ComplexMatrix& psi ) { - ModuleBase::TITLE("toWannier90_LCAO_IN_PW", "produce_local_basis_in_pw"); - assert(ik >= 0); - const int npw = wfc_basis->npwk[ik]; - const int total_lm = (GlobalC::ucell.lmax + 1) * (GlobalC::ucell.lmax + 1); - ModuleBase::matrix ylm(total_lm, npw); - - ModuleBase::Vector3* gk = new ModuleBase::Vector3[npw]; - for (int ig = 0; ig < npw; ig++) - { - gk[ig] = wfc_basis->getgpluskcar(ik, ig); - } - - ModuleBase::YlmReal::Ylm_Real(total_lm, npw, gk, ylm); - - double* flq = new double[npw]; - int iwall = 0; - for (int it = 0; it < GlobalC::ucell.ntype; it++) + int npwx = wfcpw->npwk_max; + psi::Psi>* psig = this->psi_init_->cal_psig(ik); + int nbands = GlobalV::NLOCAL; + int nbasis = npwx*GlobalV::NPOL; + for (int ib = 0; ib < nbands; ib++) { - for (int ia = 0; ia < GlobalC::ucell.atoms[it].na; ia++) + for (int ig = 0; ig < nbasis; ig++) { - std::complex* sk = sf.get_sk(ik, it, ia, wfc_basis); - int ic = 0; - for (int L = 0; L < GlobalC::ucell.atoms[it].nwl + 1; L++) - { - std::complex lphase = pow(ModuleBase::NEG_IMAG_UNIT, L); // mohan 2010-04-19 - for (int N = 0; N < GlobalC::ucell.atoms[it].l_nchi[L]; N++) - { - for (int ig = 0; ig < npw; ig++) - { - flq[ig] = ModuleBase::PolyInt::Polynomial_Interpolation(table_local, - it, - ic, - GlobalV::NQX, - GlobalV::DQ, - gk[ig].norm() * GlobalC::ucell.tpiba); - } - - for (int m = 0; m < 2 * L + 1; m++) - { - const int lm = L * L + m; - for (int ig = 0; ig < npw; ig++) - { - psi(iwall, ig) = lphase * sk[ig] * ylm(lm, ig) * flq[ig]; - } - ++iwall; - } - - ++ic; - } // end for N - } // end for L - delete[] sk; - } // end for ia - } // end for it - - delete[] flq; - delete[] gk; + psi(ib, ig) = psig[0](ik, ib, ig); + } + } } void toWannier90_LCAO_IN_PW::get_lcao_wfc_global_ik( diff --git a/source/module_io/to_wannier90_lcao_in_pw.h b/source/module_io/to_wannier90_lcao_in_pw.h index 40adcc5c22..7c4bde9ddb 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.h +++ b/source/module_io/to_wannier90_lcao_in_pw.h @@ -17,7 +17,6 @@ #include "module_base/matrix.h" #include "module_base/matrix3.h" #include "module_cell/klist.h" -#include "module_hamilt_lcao/hamilt_lcaodft/wavefunc_in_pw.h" #include "module_psi/psi.h" #include "module_basis/module_ao/ORB_table_phi.h" @@ -39,6 +38,7 @@ #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" #include "module_hamilt_lcao/module_gint/grid_technique.h" +#include "module_psi/psi_initializer.h" class toWannier90_LCAO_IN_PW : public toWannier90_PW { @@ -79,20 +79,29 @@ class toWannier90_LCAO_IN_PW : public toWannier90_PW protected: const Parallel_Orbitals* ParaV; + /// @brief psi initializer for expanding nao in planewave basis + psi_initializer, psi::DEVICE_CPU>* psi_init_; + /// @brief get Bloch function from LCAO wavefunction + /// @param psi_in + /// @param wfcpw [in] data carrier, storing planewave basis number and k information + /// @param sf [in] computational methods instance, structure factor calculator + /// @param kv [in] data carrier, storing kpoints information + /// @return psi::Psi>* psi::Psi>* get_unk_from_lcao( const psi::Psi>& psi_in, const ModulePW::PW_Basis_K* wfcpw, const Structure_Factor& sf, const K_Vectors& kv ); - - void produce_local_basis_in_pw( + /// @brief expand numerical atomic orbital (nao) in planewave basis at specific k point + /// @param ik [in] index of kpoint + /// @param wfc_basis [in] data carrier, storing planewave basis number and k information + /// @param psi [out] data carrier, storing the expanded wavefunction + void nao_G_expansion( const int& ik, const ModulePW::PW_Basis_K* wfc_basis, - const Structure_Factor& sf, - ModuleBase::ComplexMatrix& psi, - const ModuleBase::realArray& table_local + ModuleBase::ComplexMatrix& psi ); void get_lcao_wfc_global_ik(const int ik, const psi::Psi>& psi_in, ModuleBase::ComplexMatrix &lcao_wfc_global); diff --git a/source/module_psi/psi_initializer.cpp b/source/module_psi/psi_initializer.cpp index 749081c4f2..bae76b3730 100644 --- a/source/module_psi/psi_initializer.cpp +++ b/source/module_psi/psi_initializer.cpp @@ -33,7 +33,7 @@ psi_initializer::~psi_initializer() } template -psi::Psi>* psi_initializer::allocate() +psi::Psi>* psi_initializer::allocate(bool only_psig) { ModuleBase::timer::tick("psi_initializer", "allocate"); /* @@ -50,14 +50,14 @@ psi::Psi>* psi_initializer::allocate() } int prefactor = 1; int nbands_actual = 0; - if(GlobalV::init_wfc == "random") + if(this->method == "random") { nbands_actual = GlobalV::NBANDS; this->nbands_complem = 0; } else { - if(GlobalV::init_wfc.substr(0, 6) == "atomic") + if(this->method.substr(0, 6) == "atomic") { if(this->p_ucell->natomwfc >= GlobalV::NBANDS) { @@ -70,7 +70,7 @@ psi::Psi>* psi_initializer::allocate() this->nbands_complem = GlobalV::NBANDS - this->p_ucell->natomwfc; } } - else if(GlobalV::init_wfc.substr(0, 3) == "nao") + else if(this->method.substr(0, 3) == "nao") { /* previously GlobalV::NLOCAL is used here, however it is wrong. GlobalV::NLOCAL is fixed to 9*nat. @@ -120,19 +120,34 @@ psi::Psi>* psi_initializer::allocate() 1 : this->pw_wfc->nks; int nbasis_actual = this->pw_wfc->npwk_max * GlobalV::NPOL; psi::Psi>* psi_out = nullptr; - psi_out = new psi::Psi>( - nkpts_actual, - GlobalV::NBANDS, // because no matter what, the wavefunction finally needed has GlobalV::NBANDS bands - nbasis_actual, - this->pw_wfc->npwk); - /* - WARNING: this will cause DIRECT MEMORY LEAK, psi is not properly deallocated - */ + if(!only_psig) + { + psi_out = new psi::Psi>( + nkpts_actual, + GlobalV::NBANDS, // because no matter what, the wavefunction finally needed has GlobalV::NBANDS bands + nbasis_actual, + this->pw_wfc->npwk); + /* + WARNING: this will cause DIRECT MEMORY LEAK, psi is not properly deallocated + */ + const size_t memory_cost_psi = + nkpts_actual* + GlobalV::NBANDS * this->pw_wfc->npwk_max * GlobalV::NPOL* + sizeof(std::complex); + std::cout << " MEMORY FOR PSI PER PROCESSOR (MB) : " << double(memory_cost_psi)/1024.0/1024.0 << std::endl; + ModuleBase::Memory::record("Psi_PW", memory_cost_psi); + } this->psig = new psi::Psi( nkpts_actual, nbands_actual, nbasis_actual, this->pw_wfc->npwk); + const size_t memory_cost_psig = + nkpts_actual* + nbands_actual * this->pw_wfc->npwk_max * GlobalV::NPOL* + sizeof(T); + std::cout << " MEMORY FOR AUXILLARY PSI PER PROCESSOR (MB) : " << double(memory_cost_psig)/1024.0/1024.0 << std::endl; + GlobalV::ofs_running << "Allocate memory for psi and psig done.\n" << "Print detailed information of dimension of psi and psig:\n" << "psi: (" << nkpts_actual << ", " << GlobalV::NBANDS << ", " << nbasis_actual << ")\n" @@ -144,18 +159,6 @@ psi::Psi>* psi_initializer::allocate() << "nbasis_actual = " << nbasis_actual << "\n" << "npwk_max = " << this->pw_wfc->npwk_max << "\n" << "npol = " << GlobalV::NPOL << "\n"; - - const size_t memory_cost_psi = - nkpts_actual* - GlobalV::NBANDS * this->pw_wfc->npwk_max * GlobalV::NPOL* - sizeof(std::complex); - std::cout << " MEMORY FOR PSI PER PROCESSOR (MB) : " << double(memory_cost_psi)/1024.0/1024.0 << std::endl; - const size_t memory_cost_psig = - nkpts_actual* - nbands_actual * this->pw_wfc->npwk_max * GlobalV::NPOL* - sizeof(T); - std::cout << " MEMORY FOR AUXILLARY PSI PER PROCESSOR (MB) : " << double(memory_cost_psig)/1024.0/1024.0 << std::endl; - ModuleBase::Memory::record("Psi_PW", memory_cost_psi); ModuleBase::Memory::record("PsiG_PW", memory_cost_psig); ModuleBase::timer::tick("psi_initializer", "allocate"); return psi_out; diff --git a/source/module_psi/psi_initializer.h b/source/module_psi/psi_initializer.h index 9cf548a7a7..17f2baf3c5 100644 --- a/source/module_psi/psi_initializer.h +++ b/source/module_psi/psi_initializer.h @@ -62,9 +62,10 @@ class psi_initializer // shared methods /// @brief allocate memory for psi + /// @param only_psig if true, only allocate memory for psig, not psi /// @return pointer to psi, memory allocated /// @note whether use template for psig or not, it is std::complex because psi is. - psi::Psi>* allocate(); + psi::Psi>* allocate(bool only_psig = false); /// @brief get method of initializing psi /// @return the method