deepmodeling / abacus-develop

An electronic structure package based on either plane wave basis or numerical atomic orbitals.
http://abacus.ustc.edu.cn
GNU Lesser General Public License v3.0
173 stars 133 forks source link

Bug: `nupdown 0` can cause calculation failure for nspin 1 case #5297

Closed kirk0830 closed 3 weeks ago

kirk0830 commented 3 weeks ago

Describe the bug

Try the following example:

INPUT_PARAMETERS
#Parameters (1.General)
suffix                  abacus
pseudo_dir              path/to/your/ppfiles
nspin                   1
nupdown                 0
symmetry                0
dft_functional          PBE
calculation             relax

#Parameters (2.Iteration)
ecutwfc                 200
scf_thr                 1e-8
scf_nmax                50

#Parameters (3.Basis)
basis_type              pw 
gamma_only              1

#Parameters (4.Smearing)
smearing_method         fixed

#Parameters (5.Mixing)
mixing_type             broyden
mixing_beta             0.4
mixing_beta_mag         0.4 
mixing_gg0              0
mixing_gg0_mag          0

#Parameters (6.Relaxing)
force_thr_ev            0.01
relax_nmax              128

#Parameters (7.Output)
out_stru                True
out_chg                 -1
ATOMIC_SPECIES
Li 6.94 Li_ONCV_PBE-1.0.upf

LATTICE_CONSTANT
1

LATTICE_VECTORS
30 0 0
0 30 0
0 0 30

ATOMIC_POSITIONS
Cartesian_angstrom_center_xyz

Li
0
2
0.00000000 0.00000000 1.38653000
0.00000000 0.00000000 -1.38653000

Although it is unreasonable to set nupdown for nspin 1 case, this should not cause any bug, instead, ABACUS should quit with information. Plus, nspin 1 equivalent with nupdown 0, but the calculation indeed cannot proceed for more than one ionic step:

Info: Local MPI proc number: 16,OpenMP thread number: 1,Total thread number: 16,Local thread limit: 64

                              ABACUS v3.8.0

               Atomic-orbital Based Ab-initio Computation at UStc                    

                     Website: http://abacus.ustc.edu.cn/                             
               Documentation: https://abacus.deepmodeling.com/                       
                  Repository: https://github.com/abacusmodeling/abacus-develop       
                              https://github.com/deepmodeling/abacus-develop         
                      Commit: 7e6eee7ad (Tue Oct 15 17:44:49 2024 +0800)

 Fri Oct 18 10:17:21 2024
 MAKE THE DIR         : OUT.abacus/
 RUNNING WITH DEVICE  : CPU / Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Warning: the number of valence electrons in pseudopotential > 1 for Li: [He] 2s1
 Pseudopotentials with additional electrons can yield (more) accurate outcomes, but may be less efficient.
 If you're confident that your chosen pseudopotential is appropriate, you can safely ignore this warning.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 UNIFORM GRID DIM        : 288 * 288 * 288
 UNIFORM GRID DIM(BIG)   : 288 * 288 * 288
 DONE(0.392867   SEC) : SETUP UNITCELL
 DONE(0.414509   SEC) : INIT K-POINTS
 ---------------------------------------------------------
 Ion relaxation calculations
 ---------------------------------------------------------
 SPIN    KPOINTS         PROCESSORS  
 1       1               16          
 ---------------------------------------------------------
 Use plane wave basis
 ---------------------------------------------------------
 ELEMENT NATOM       XC          
 Li      2           
 ---------------------------------------------------------
 Initial plane wave basis and FFT box
 ---------------------------------------------------------
 DONE(0.571814   SEC) : INIT PLANEWAVE
 DONE(0.72349    SEC) : LOCAL POTENTIAL
 DONE(0.746749   SEC) : NON-LOCAL POTENTIAL
 MEMORY FOR PSI (MB)  : 15.9905
 DONE(0.746909   SEC) : INIT BASIS
 -------------------------------------------
 STEP OF RELAXATION : 1
 -------------------------------------------
 START CHARGE      : atomic
 DONE(2.03699    SEC) : INIT SCF
 * * * * * *
 << Start SCF iteration.
 ITER       ETOT/eV          EDIFF/eV         DRHO     TIME/s
 CG1     -6.11027882e+01   0.00000000e+00   1.5306e+01  15.05
 CG2      9.55587582e-01   6.20583758e+01   5.5100e+00   8.63
 CG3      9.55587582e-01   0.00000000e+00   1.2497e-26   6.63
 >> Leave SCF iteration.
 * * * * * *
 ETOT DIFF (eV)       : 0
 LARGEST GRAD (eV/A)  : 16.4423
 -------------------------------------------
 STEP OF RELAXATION : 2
 -------------------------------------------

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                         NOTICE                           
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 Can't find even an electron!
 CHECK IN FILE : OUT.abacus/warning.log

 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                         NOTICE                           
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
TIME STATISTICS
-----------------------------------------------------------------------------
    CLASS_NAME                NAME             TIME/s  CALLS   AVG/s  PER/%  
-----------------------------------------------------------------------------
                   total                       33.08  15       2.21   100.00 
 Driver            reading                     0.07   1        0.07   0.20   
 Input_Conv        Convert                     0.01   1        0.01   0.03   
 Driver            driver_line                 0.00   1        0.00   0.00   
 UnitCell          check_tau                   0.00   1        0.00   0.00   
 PW_Basis_Sup      setuptransform              0.12   1        0.12   0.36   
 PW_Basis_Sup      distributeg                 0.11   1        0.11   0.34   
 mymath            heapsort                    0.10   3        0.03   0.29   
 PW_Basis_K        setuptransform              0.10   1        0.10   0.31   
 PW_Basis_K        distributeg                 0.10   1        0.10   0.31   
 PW_Basis          setup_struc_factor          0.07   2        0.03   0.20   
 ppcell_vnl        init                        0.01   1        0.01   0.03   
 ppcell_vl         init_vloc                   0.07   1        0.07   0.20   
 ppcell_vnl        init_vnl                    0.02   1        0.02   0.07   
 WF_atomic         init_at_1                   0.00   1        0.00   0.00   
 wavefunc          wfcinit                     0.00   1        0.00   0.00   
 Ions              opt_ions                    0.00   1        0.00   0.00   
 ESolver_KS_PW     runner                      31.78  2        15.89  96.06  
 ESolver_KS_PW     before_scf                  1.29   2        0.64   3.90   
 H_Ewald_pw        compute_ewald               0.03   2        0.02   0.10   
 Charge            set_rho_core                0.01   2        0.00   0.02   
 Charge            atomic_rho                  0.51   3        0.17   1.53   
 PW_Basis_Sup      recip2real                  1.63   26       0.06   4.94   
 PW_Basis_Sup      gathers_scatterp            0.70   26       0.03   2.11   
 Potential         init_pot                    1.08   1        1.08   3.27   
 Potential         update_from_charge          3.77   4        0.94   11.39  
 Potential         cal_fixed_v                 0.08   1        0.08   0.23   
 PotLocal          cal_fixed_v                 0.08   1        0.08   0.23   
 Potential         cal_v_eff                   3.68   4        0.92   11.12  
 H_Hartree_pw      v_hartree                   0.58   4        0.15   1.77   
 PW_Basis_Sup      real2recip                  1.73   32       0.05   5.23   
 PW_Basis_Sup      gatherp_scatters            0.71   32       0.02   2.14   
 PotXC             cal_v_eff                   3.06   4        0.76   9.24   
 XC_Functional     v_xc                        3.04   4        0.76   9.19   
 Potential         interpolate_vrs             0.01   4        0.00   0.04   
 Charge_Mixing     init_mixing                 0.00   1        0.00   0.00   
 ESolver_KS_PW     hamilt2density              27.02  3        9.01   81.67  
 HSolverPW         solve                       26.99  3        9.00   81.61  
 Nonlocal          getvnl                      0.06   3        0.02   0.18   
 pp_cell_vnl       getvnl                      0.06   3        0.02   0.18   
 Structure_Factor  get_sk                      0.01   4        0.00   0.02   
 DiagoIterAssist   diagH_subspace              2.65   3        0.88   8.02   
 Operator          hPsi                        22.93  293      0.08   69.33  
 Operator          EkineticPW                  0.11   293      0.00   0.34   
 Operator          VeffPW                      20.97  293      0.07   63.41  
 PW_Basis_K        recip2real                  11.44  368      0.03   34.57  
 PW_Basis_K        gathers_scatterp            3.60   368      0.01   10.89  
 PW_Basis_K        real2recip                  8.58   329      0.03   25.95  
 PW_Basis_K        gatherp_scatters            1.69   329      0.01   5.11   
 Operator          NonlocalPW                  1.84   293      0.01   5.57   
 Nonlocal          add_nonlocal_pp             0.82   293      0.00   2.49   
 DiagoIterAssist   diagH_LAPACK                0.02   3        0.01   0.06   
 DiagoCG           diag_once                   22.96  3        7.65   69.42  
 DiagoCG_New       spsi_func                   0.15   580      0.00   0.44   
 DiagoCG_New       hpsi_func                   20.45  290      0.07   61.83  
 ElecStatePW       psiToRho                    1.22   3        0.41   3.67   
 Charge_Mixing     get_drho                    0.34   3        0.11   1.02   
 Charge_Mixing     inner_product_recip_rho     0.01   3        0.00   0.03   
 Charge            mix_rho                     0.21   2        0.11   0.65   
 Charge            Broyden_mixing              0.02   2        0.01   0.06   
 Charge_Mixing     inner_product_recip_hartree 0.01   2        0.00   0.02   
 ESolver_KS_PW     after_scf                   0.18   1        0.18   0.53   
 Forces            cal_force_loc               0.09   1        0.09   0.26   
 Forces            cal_force_ew                0.03   1        0.03   0.09   
 Forces            cal_force_nl                0.04   1        0.04   0.12   
 FS_Nonlocal_tools cal_becp                    0.02   1        0.02   0.06   
 FS_Nonlocal_tools cal_dbecp_f                 0.02   3        0.01   0.06   
 Forces            cal_force_cc                0.00   1        0.00   0.00   
 Forces            cal_force_scc               0.17   1        0.17   0.51   
 Charge_Extra      extrapolate_charge          0.21   1        0.21   0.63   
-----------------------------------------------------------------------------

 See output information in : OUT.abacus/

Expected behavior

No response

To Reproduce

No response

Environment

No response

Additional Context

No response

Task list for Issue attackers (only for developers)

jinzx10 commented 3 weeks ago

This issue results from the following code snippet: Image

The current behavior is that "two_fermi" will be set to true whenever nupdown is provided, regardless of nspin. This becomes problematic when nspin = 1, as this issue reports. "two_fermi" should be set to false in this case, and an extra check should be performed to prevent a non-zero nupdown when nspin == 1.