Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a new BFGS optimizer, used for geometry relaxation #5467

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cf1d4cf
bfgs
19hello Nov 12, 2024
710c6ce
bfgs1
19hello Nov 12, 2024
37461e5
Update bfgs method
19hello Nov 15, 2024
8baf4e8
Merge branch 'develop' of https://gitee.com/deepmodeling/abacus-devel…
19hello Nov 15, 2024
1899f53
bfgs_trad
19hello Nov 15, 2024
2c4cb0a
new bfgs method
19hello Nov 15, 2024
e5c4282
new bfgs_trad method
19hello Nov 15, 2024
97211a5
new bfgs_trad
19hello Nov 17, 2024
12f8b4a
Merge branch 'develop' into mybfgs
19hello Nov 17, 2024
39f9cb1
bfgs2
19hello Nov 17, 2024
ef98545
bfgs_trad3
19hello Nov 17, 2024
d8dfacb
bfgs_trad2
19hello Nov 18, 2024
af4ea04
bfgs_trad
19hello Nov 18, 2024
7bb9786
bfgs_trad
19hello Nov 18, 2024
4c75875
bfgs_trad
19hello Nov 18, 2024
978dae0
Merge branch 'develop' into mybfgs
19hello Nov 18, 2024
d5b1c14
bfgs_trad
19hello Nov 18, 2024
e2c386f
Merge branch 'mybfgs' of https://github.com/19hello/myrepo into mybfgs
19hello Nov 18, 2024
73a8136
bfgs_trad
19hello Nov 18, 2024
ca6e24e
Merge branch 'develop' of https://github.com/deepmodeling/abacus-deve…
19hello Nov 19, 2024
a02316b
bfgs_trad
19hello Nov 19, 2024
cc0b5ed
bfgs_trad
19hello Nov 20, 2024
55ee2c0
bfgs_trad
19hello Nov 20, 2024
8e9f2d8
bfgs_trad
19hello Nov 20, 2024
9c3c405
bfgs_trad
19hello Nov 21, 2024
caac72a
Use force_ev_thr to judge optimization
19hello Nov 23, 2024
12d607e
remove 108_PW_RE_MB_NEW
19hello Nov 25, 2024
c4a9719
Add determine whether an atom is movable code and modify the value of…
19hello Nov 29, 2024
7166b1b
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,995 changes: 1,995 additions & 0 deletions SiH2-3et-relax/H.ccECP.upf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not add new file, this file is too large

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@19hello
for SiH2 example, you can attach it as zip file under the corresponding issue, but not in source-code

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've delete SiH2-3et-relax

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@19hello After you resolve this comment, please mark them as resolved

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions SiH2-3et-relax/INPUT
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
INPUT_PARAMETERS
# Created by Atomic Simulation Enviroment
suffix abacus
calculation relax
relax_method bfgs_trad
relax_nmax 50
nspin 2
nupdown 2
symmetry 0
dft_functional PBE
basis_type pw
ecutwfc 100
scf_thr 1e-07
scf_nmax 50
gamma_only True
smearing_method gauss
smearing_sigma 0.01
mixing_type broyden
mixing_beta 0.2
mixing_beta_mag 0.8
mixing_gg0 1.5
mixing_gg0_mag 0
ks_solver dav
cal_force 1
ntype 2
orbital_dir .
4 changes: 4 additions & 0 deletions SiH2-3et-relax/KPT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
K_POINTS
0
Gamma
1 1 1 0 0 0
5 changes: 5 additions & 0 deletions SiH2-3et-relax/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
conda create -n ase-abacus python=3.10
conda activate ase-abacus
git clone https://gitlab.com/1041176461/ase-abacus.git
cd ase-abacus
pip install .
30 changes: 30 additions & 0 deletions SiH2-3et-relax/STRU
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ATOMIC_SPECIES
Si 28.085 Si.ccECP.upf
H 1.008 H.ccECP.upf

NUMERICAL_ORBITAL
Si_gga_7au_100Ry_2s2p1d.orb
H_gga_6au_100Ry_2s1p.orb

LATTICE_CONSTANT
1.8897261258369282

LATTICE_VECTORS
21.167088000 0.0000000000 0.0000000000
0.0000000000 21.167088000 0.0000000000
0.0000000000 0.0000000000 21.167088000

ATOMIC_POSITIONS
Direct

Si
0.0000000000
1
0.5000000000 0.4999990000 0.5047030000 1 1 1 v 0.0 0.0 0.0 mag 0.0

H
0.0000000000
2
0.5000000000 0.5610460000 0.4685160000 1 1 1 v 0.0 0.0 0.0 mag 0.0
0.5000000000 0.4389560000 0.4685160000 1 1 1 v 0.0 0.0 0.0 mag 0.0

2,720 changes: 2,720 additions & 0 deletions SiH2-3et-relax/Si.ccECP.upf
mohanchen marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions SiH2-3et-relax/SiH2-pos-fin.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
data_image0
_chemical_formula_structural SiH2
_chemical_formula_sum "Si1 H2"
_cell_length_a 21.16708843
_cell_length_b 21.16708843
_cell_length_c 21.16708843
_cell_angle_alpha 90.0
_cell_angle_beta 90.0
_cell_angle_gamma 90.0

_space_group_name_H-M_alt "P 1"
_space_group_IT_number 1

loop_
_space_group_symop_operation_xyz
'x, y, z'

loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Si Si1 1.0 0.49999992 0.49999894409649426 0.5047026224112832 1.0000
H H1 1.0 0.5000000400000001 0.5610455426063221 0.46851619853432114 1.0000
H H2 1.0 0.5000000400000001 0.4389555032963629 0.4685163190552164 1.0000
29 changes: 29 additions & 0 deletions SiH2-3et-relax/SiH2-pos-ini.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by ABACUS ModuleIO::CifParser
data_?
_symmetry_space_group_name_H-M 'P 1'
_cell_length_a 21.16708843
_cell_length_b 21.16708843
_cell_length_c 21.16708843
_cell_angle_alpha 90.00000000
_cell_angle_beta 90.00000000
_cell_angle_gamma 90.00000000
_symmetry_Int_Tables_number 1
_chemical_formula_structural SiH
_chemical_formula_sum SiH2
_cell_volume 9483.82152169
_cell_formula_units_Z 1
loop_
_symmetry_equiv_pos_site_id
_symmetry_equiv_pos_as_xyz
1 'x, y, z'
loop_
_atom_site_type_symbol
_atom_site_label
_atom_site_symmetry_multiplicity
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_occupancy
Si Si0 1 0.49999992 0.49999980 0.50526114 1.0
H H1 1 0.50000004 0.56098905 0.46823705 1.0
H H2 1 0.50000004 0.43901114 0.46823695 1.0
Empty file added SiH2-3et-relax/abacus.err
Empty file.
144 changes: 144 additions & 0 deletions SiH2-3et-relax/abacus.out
mohanchen marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@

ABACUS v3.8.1

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: 146a50931 (Mon Oct 21 16:41:35 2024 +0800)

Thu Oct 24 12:09:59 2024
MAKE THE DIR : OUT.abacus/
RUNNING WITH DEVICE : CPU / Intel(R) Xeon(R) Platinum
UNIFORM GRID DIM : 256 * 256 * 256
UNIFORM GRID DIM(BIG) : 256 * 256 * 256
DONE(0.28622 SEC) : SETUP UNITCELL
DONE(0.286508 SEC) : INIT K-POINTS
---------------------------------------------------------
Self-consistent calculations for electrons
---------------------------------------------------------
SPIN KPOINTS PROCESSORS
2 2 16
---------------------------------------------------------
Use plane wave basis
---------------------------------------------------------
ELEMENT NATOM XC
Si 1
H 2
---------------------------------------------------------
Initial plane wave basis and FFT box
---------------------------------------------------------
DONE(0.373599 SEC) : INIT PLANEWAVE
DONE(0.725854 SEC) : LOCAL POTENTIAL
DONE(0.825578 SEC) : NON-LOCAL POTENTIAL
MEMORY FOR PSI (MB) : 30.921
DONE(0.914662 SEC) : INIT BASIS
-------------------------------------------
SELF-CONSISTENT :
-------------------------------------------
START CHARGE : atomic
DONE(3.68617 SEC) : INIT SCF
* * * * * *
<< Start SCF iteration.
ITER TMAG AMAG ETOT/eV EDIFF/eV DRHO TIME/s
DS1 2.00e+00 2.03e+00 -1.34430231e+02 0.00000000e+00 3.9191e-01 14.62
DS2 2.00e+00 2.02e+00 -1.34775372e+02 -3.45141827e-01 9.7737e-02 10.50
DS3 2.00e+00 2.02e+00 -1.35111314e+02 -3.35941751e-01 6.5112e-03 15.38
DS4 2.00e+00 2.02e+00 -1.35170475e+02 -5.91607382e-02 1.5503e-03 26.84
DS5 2.00e+00 2.02e+00 -1.35186232e+02 -1.57568707e-02 1.7038e-04 20.76
DS6 2.00e+00 2.02e+00 -1.35188302e+02 -2.07018353e-03 1.5779e-05 26.53
DS7 2.00e+00 2.02e+00 -1.35188101e+02 2.01251562e-04 5.6585e-06 13.65
DS8 2.00e+00 2.02e+00 -1.35188148e+02 -4.72056440e-05 2.2478e-07 14.42
DS9 2.00e+00 2.02e+00 -1.35188152e+02 -4.09432453e-06 7.8883e-08 12.36
DS10 2.00e+00 2.02e+00 -1.35188153e+02 -1.47620397e-06 4.3864e-09 9.45
>> Leave SCF iteration.
* * * * * *
TIME STATISTICS
-----------------------------------------------------------------------------
CLASS_NAME NAME TIME/s CALLS AVG/s PER/%
-----------------------------------------------------------------------------
total 170.93 15 11.40 100.00
Driver reading 0.02 1 0.02 0.01
Input_Conv Convert 0.00 1 0.00 0.00
Driver driver_line 170.91 1 170.91 99.99
UnitCell check_tau 0.00 1 0.00 0.00
PW_Basis_Sup setuptransform 0.06 1 0.06 0.03
PW_Basis_Sup distributeg 0.05 1 0.05 0.03
mymath heapsort 0.10 3 0.03 0.06
PW_Basis_K setuptransform 0.04 1 0.04 0.03
PW_Basis_K distributeg 0.04 1 0.04 0.02
PW_Basis setup_struc_factor 0.06 1 0.06 0.03
ppcell_vnl init 0.01 1 0.01 0.01
ppcell_vl init_vloc 0.21 1 0.21 0.12
ppcell_vnl init_vnl 0.10 1 0.10 0.06
WF_atomic init_at_1 0.09 1 0.09 0.05
wavefunc wfcinit 0.00 1 0.00 0.00
Ions opt_ions 169.89 1 169.89 99.39
ESolver_KS_PW runner 169.22 1 169.22 99.00
ESolver_KS_PW before_scf 2.77 1 2.77 1.62
H_Ewald_pw compute_ewald 0.02 1 0.02 0.01
Charge set_rho_core 0.00 1 0.00 0.00
Charge atomic_rho 1.18 2 0.59 0.69
PW_Basis_Sup recip2real 9.56 122 0.08 5.59
PW_Basis_Sup gathers_scatterp 4.46 122 0.04 2.61
Potential init_pot 2.27 1 2.27 1.33
Potential update_from_charge 23.35 11 2.12 13.66
Potential cal_fixed_v 0.09 1 0.09 0.05
PotLocal cal_fixed_v 0.09 1 0.09 0.05
Potential cal_v_eff 23.18 11 2.11 13.56
H_Hartree_pw v_hartree 2.15 11 0.20 1.26
PW_Basis_Sup real2recip 11.37 154 0.07 6.65
PW_Basis_Sup gatherp_scatters 5.94 154 0.04 3.48
PotXC cal_v_eff 20.80 11 1.89 12.17
XC_Functional v_xc 20.70 11 1.88 12.11
Potential interpolate_vrs 0.08 11 0.01 0.05
Charge_Mixing init_mixing 0.00 1 0.00 0.00
ESolver_KS_PW hamilt2density 136.57 10 13.66 79.90
HSolverPW solve 136.42 10 13.64 79.81
Nonlocal getvnl 0.47 20 0.02 0.28
pp_cell_vnl getvnl 0.47 20 0.02 0.28
Structure_Factor get_sk 0.07 28 0.00 0.04
WF_atomic atomic_wfc 0.08 2 0.04 0.05
Diago_DavSubspace diag_once 122.67 20 6.13 71.76
Diago_DavSubspace first 24.52 20 1.23 14.34
DavSubspace hpsi_func 110.08 186 0.59 64.40
Operator hPsi 109.69 186 0.59 64.17
Operator EkineticPW 0.87 186 0.00 0.51
Operator VeffPW 106.68 186 0.57 62.41
PW_Basis_K recip2real 61.85 1675 0.04 36.19
PW_Basis_K gathers_scatterp 21.52 1675 0.01 12.59
PW_Basis_K real2recip 45.62 1375 0.03 26.69
PW_Basis_K gatherp_scatters 12.75 1375 0.01 7.46
Operator NonlocalPW 2.14 186 0.01 1.25
Nonlocal add_nonlocal_pp 1.19 186 0.01 0.70
Diago_DavSubspace cal_elem 3.69 186 0.02 2.16
Diago_DavSubspace diag_zhegvx 0.13 186 0.00 0.08
Diago_DavSubspace cal_grad 93.08 166 0.56 54.46
Diago_DavSubspace check_update 0.00 166 0.00 0.00
Diago_DavSubspace last 1.52 34 0.04 0.89
Diago_DavSubspace refresh 0.48 14 0.03 0.28
ElecStatePW psiToRho 12.04 10 1.20 7.04
Charge_Mixing get_drho 2.91 10 0.29 1.70
Charge_Mixing inner_product_recip_rho 0.09 10 0.01 0.05
Charge mix_rho 3.61 9 0.40 2.11
Charge Broyden_mixing 0.58 9 0.06 0.34
Charge_Mixing inner_product_recip_hartree 0.48 72 0.01 0.28
ESolver_KS_PW after_scf 1.94 1 1.94 1.14
ModuleIO write_rhog 1.06 1 1.06 0.62
Forces cal_force_loc 0.12 1 0.12 0.07
Forces cal_force_ew 0.05 1 0.05 0.03
Forces cal_force_nl 0.12 1 0.12 0.07
FS_Nonlocal_tools cal_becp 0.06 2 0.03 0.04
FS_Nonlocal_tools cal_dbecp_f 0.06 6 0.01 0.03
Forces cal_force_cc 0.00 1 0.00 0.00
Forces cal_force_scc 0.38 1 0.38 0.22
ModuleIO write_istate_info 0.00 1 0.00 0.00
-----------------------------------------------------------------------------


START Time : Thu Oct 24 12:09:59 2024
FINISH Time : Thu Oct 24 12:12:50 2024
TOTAL Time : 171
SEE INFORMATION IN : OUT.abacus/
44 changes: 44 additions & 0 deletions SiH2-3et-relax/log
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this file

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

ABACUS v3.8.2

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: unknown

Fri Nov 15 08:05:02 2024
MAKE THE DIR : OUT.abacus/
RUNNING WITH DEVICE : CPU / 13th Gen Intel(R) Core(TM) i7-13700KF
UNIFORM GRID DIM : 256 * 256 * 256
UNIFORM GRID DIM(BIG) : 256 * 256 * 256
DONE(2.46674 SEC) : SETUP UNITCELL
DONE(2.71952 SEC) : INIT K-POINTS
---------------------------------------------------------
Ion relaxation calculations
---------------------------------------------------------
SPIN KPOINTS PROCESSORS THREADS
2 2 8 8
---------------------------------------------------------
Use plane wave basis
---------------------------------------------------------
ELEMENT NATOM XC
Si 1
H 2
---------------------------------------------------------
Initial plane wave basis and FFT box
---------------------------------------------------------
DONE(3.80033 SEC) : INIT PLANEWAVE
DONE(5.7434 SEC) : LOCAL POTENTIAL
DONE(5.97613 SEC) : NON-LOCAL POTENTIAL
MEMORY FOR PSI (MB) : 61.8411
DONE(6.25469 SEC) : INIT BASIS
-------------------------------------------
STEP OF ION RELAXATION : 1
-------------------------------------------
START CHARGE : atomic
DONE(26.3435 SEC) : INIT SCF
ITER TMAG AMAG ETOT/eV EDIFF/eV DRHO TIME/s
DA1 2.00e+00 2.03e+00 -1.36488047e+02 0.00000000e+00 3.9185e-01 67.66
7 changes: 7 additions & 0 deletions SiH2-3et-relax/relax.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Step Time Energy fmax
BFGS: 0 12:01:24 -135.186543 0.192194
BFGS: 1 12:04:16 -135.187369 0.131104
BFGS: 2 12:07:10 -135.188012 0.025128
BFGS: 3 12:09:58 -135.188032 0.023977
BFGS: 4 12:12:50 -135.188153 0.001422
Final structure is saved in SiH2-pos-fin.cif
71 changes: 71 additions & 0 deletions SiH2-3et-relax/relax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from ase.calculators.abacus import Abacus
from ase.calculators.abacus import AbacusProfile
from ase.io import read, write

def abacus_init(fname, profile, **kwargs):
'''instantiate a instance of Abacus calculator (and bind) with
specific structures and ABACUS parameters

Parameters
----------
fname : str
The filename of the structure, can be any format that ASE supports.
For a complete list of supported formats, see:
https://wiki.fysik.dtu.dk/ase/ase/io/io.html#module-ase.io
profile : AbacusProfile
The command to run ABACUS
**kwargs : dict
The ABACUS parameters, e.g. pp, basis, etc.

Returns
-------
a : Atoms
The Atoms object with the attached ABACUS calculator
'''
a = read(fname)
pp = kwargs.pop('pp', {})
# if there is no data in pp, pops an warning
if not pp:
print('WARNING: No pseudopotential data is provided')
a.calc = Abacus(pp=pp, profile=profile, **kwargs)
return a

def relax(a, method='BFGS', fmax=0.05, max_steps=100, **kwargs):
'''relax the structure using the given method'''
if method == 'BFGS':
from ase.optimize import BFGS
dyn = BFGS(a, trajectory=None, **kwargs)
dyn.run(fmax=fmax, steps=max_steps)
else:
raise NotImplementedError(f'{method} is not supported by ASE')
return a

if __name__ == '__main__':
pp={'Si': 'Si.ccECP.upf', 'H': 'H.ccECP.upf'}
env = AbacusProfile('mpirun -np 16 /usr/local/bin/abacus')
recipe = {'suffix': 'abacus',
'pseudo_dir': '.',
'orbital_dir': '.',
'nspin': 2,
'nupdown': 2,
'symmetry': 0,
'dft_functional': 'PBE',
'ecutwfc': 100,
'scf_thr': 1e-8,
'scf_nmax': 50,
'basis_type': 'pw',
'gamma_only': True,
'smearing_method': 'fixed',
'mixing_type': 'broyden',
'mixing_beta': 0.4,
'mixing_beta_mag': 0.4,
'mixing_gg0': 0,
'mixing_gg0_mag': 0,
'ks_solver': 'dav_subspace',
'out_chg': -1}
ini = 'SiH2-pos-ini.cif'
fin = 'SiH2-pos-fin.cif'
a = abacus_init(ini, profile=env, pp=pp, **recipe)
a = relax(a, fmax=0.01, max_steps=100)
write(fin, a)
print(f'Final structure is saved in {fin}')
Loading
Loading