Commit 75e8cf2b authored by hebrewsnabla's avatar hebrewsnabla
Browse files

allow rohf in check_stab

parent 5a84851f
......@@ -130,10 +130,22 @@ def mix(xyz, bas, charge=0, conv='loose', cycle=5, skipstb=False, xc=None):
#mf_mix.kernel(dm)
return mf_mix
def check_uhf2(mf):
ss, s = mf.spin_square()
spin = mf.mol.spin
if abs(s - 1 - spin) > 0.01:
is_uhf = True
else:
is_uhf = False
#mf = mf.to_rhf()
return is_uhf, mf
def check_stab(mf_mix, newton=False, res=False):
if res:
stab = stability.rhf_internal
is_uhf, mf_mix = autocas.check_uhf(mf_mix)
if mf_mix.mol.spin is not 0:
stab = stability.rohf_internal
is_uhf, mf_mix = check_uhf2(mf_mix)
if is_uhf:
raise ValueError('UHF/UKS wavefunction detected. RHF/RKS is required for res=True')
else:
......@@ -153,7 +165,7 @@ def check_stab(mf_mix, newton=False, res=False):
if not stable:
raise RuntimeError('Stablility Opt failed after %d attempts.' % cyc)
if not mf_mix.converged:
print('Warning: UHF finally not converged')
print('Warning: SCF finally not converged')
mf_mix.mo_coeff = mo
return mf_mix
......
......@@ -71,3 +71,32 @@ def uhf_internal(mf, with_symmetry=True, verbose=None):
mo = mf.mo_coeff
stable = True
return mo, stable
def rohf_internal(mf, with_symmetry=True, verbose=None):
log = logger.new_logger(mf, verbose)
log.note('**** checking ROHF/ROKS internal stability ...')
g, hop, hdiag = newton_ah.gen_g_hop_rohf(mf, mf.mo_coeff, mf.mo_occ,
with_symmetry=with_symmetry)
hdiag *= 2
stable = True
def precond(dx, e, x0):
hdiagd = hdiag - e
hdiagd[abs(hdiagd)<1e-8] = 1e-8
return dx/hdiagd
def hessian_x(x): # See comments in function rhf_internal
return hop(x).real * 2
x0 = numpy.zeros_like(g)
x0[g!=0] = 1. / hdiag[g!=0]
if not with_symmetry: # allow to break point group symmetry
x0[numpy.argmin(hdiag)] = 1
e, v = lib.davidson(hessian_x, x0, precond, tol=1e-4, verbose=log)
if e < -1e-5:
log.note('ROHF wavefunction has an internal instability.')
mo = _rotate_mo(mf.mo_coeff, mf.mo_occ, v)
stable = False
else:
log.note('ROHF wavefunction is stable in the internal stability analysis')
mo = mf.mo_coeff
return mo, stable
#INFO: **** input file is /share/home/srwang/pyAutoMR/examples/guess/09-V2-ROKS.py ****
from pyscf import gto, dft
from automr import guess
#mf=guess.from_fch_simp("v2.fchk", xc='pbe0')
#mf2.verbose=9
#mf2.stability()
mol = gto.Mole(atom='''V 0.0 0.0 0.0; V 0.0 0.0 1.77''', basis='def2-tzvp', spin=2)
mol.verbose = 4
mol.build()
mf = dft.ROKS(mol)
mf.xc = 'pbe0'
mf.kernel()
mf2 = guess.check_stab(mf, newton=True, res=True)
#INFO: ******************** input file end ********************
System: uname_result(system='Linux', node='xn01', release='3.10.0-1127.el7.x86_64', version='#1 SMP Tue Feb 18 16:39:12 EST 2020', machine='x86_64', processor='x86_64') Threads 32
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0]
numpy 1.17.2 scipy 1.4.1
Date: Wed Sep 15 15:17:47 2021
PySCF version 1.7.6a1
PySCF path /share/home/srwang/pyscf/pyscf
GIT ORIG_HEAD 80f71dfe77ac5f9caae26788acf76446987635bd
GIT HEAD ref: refs/heads/master
GIT master branch 80f71dfe77ac5f9caae26788acf76446987635bd
[ENV] PYSCF_EXT_PATH /share/home/srwang/pyscf_ext/fciqmc:
[CONFIG] conf_file /share/home/srwang/.pyscf_conf.py
[INPUT] verbose = 4
[INPUT] num. atoms = 2
[INPUT] num. electrons = 46
[INPUT] charge = 0
[INPUT] spin (= nelec alpha-beta = 2S) = 2
[INPUT] symmetry False subgroup None
[INPUT] Mole.unit = angstrom
[INPUT] 1 V 0.000000000000 0.000000000000 0.000000000000 AA 0.000000000000 0.000000000000 0.000000000000 Bohr
[INPUT] 2 V 0.000000000000 0.000000000000 1.770000000000 AA 0.000000000000 0.000000000000 3.344815240480 Bohr
nuclear repulsion = 158.155222924678
number of shells = 30
number of NR pGTOs = 184
number of NR cGTOs = 90
basis = def2-tzvp
ecp = {}
CPU time: 1.06
******** <class 'pyscf.dft.roks.ROKS'> ********
method = ROKS-ROHF-RHF
initial guess = minao
damping factor = 0
level_shift factor = 0
DIIS = <class 'pyscf.scf.diis.CDIIS'>
diis_start_cycle = 1
diis_space = 8
SCF conv_tol = 1e-09
SCF conv_tol_grad = None
SCF max_cycles = 50
direct_scf = True
direct_scf_tol = 1e-13
chkfile to save SCF result = /share/home/srwang/pyAutoMR/examples/guess/tmpye_85lf9
max_memory 4000 MB (current use 106 MB)
num. doubly occ = 22 num. singly occ = 2
XC functionals = pbe0
small_rho_cutoff = 1e-07
radial grids:
Treutler-Ahlrichs [JCP 102, 346 (1995); DOI:10.1063/1.469408] (M4) radial grids
becke partition: Becke, JCP 88, 2547 (1988); DOI:10.1063/1.454033
pruning grids: <function nwchem_prune at 0x2b8c151e88c0>
grids dens level: 3
symmetrized grids: False
atomic radii adjust function: <function treutler_atomic_radii_adjust at 0x2b8c151e8d40>
Set gradient conv threshold to 3.16228e-05
tot grids = 40848
init E= -1887.4437206509
HOMO = -0.344033083169891 LUMO = -0.302790090111784
cycle= 1 E= -1886.85256286426 delta_E= 0.591 |g|= 1.55 |ddm|= 1.98
HOMO = 0.106097645521978 LUMO = 0.129323457302906
cycle= 2 E= -1878.58335408898 delta_E= 8.27 |g|= 4.5 |ddm|= 10.5
WARN: HOMO -0.227147925211421 >= LUMO -0.315653591353059
cycle= 3 E= -1886.70417523799 delta_E= -8.12 |g|= 1.45 |ddm|= 10.5
WARN: HOMO 0.0545172986871908 >= LUMO -0.247864510735232
cycle= 4 E= -1887.13161787539 delta_E= -0.427 |g|= 0.389 |ddm|= 3.94
WARN: HOMO -0.0924341208078712 >= LUMO -0.135127150243461
cycle= 5 E= -1887.32343762469 delta_E= -0.192 |g|= 0.256 |ddm|= 4.44
WARN: HOMO -0.0922501940641812 >= LUMO -0.121624412537163
cycle= 6 E= -1887.33795995139 delta_E= -0.0145 |g|= 0.112 |ddm|= 0.564
WARN: HOMO -0.0918467816387551 >= LUMO -0.111969299487016
cycle= 7 E= -1887.34224458198 delta_E= -0.00428 |g|= 0.0558 |ddm|= 0.286
WARN: HOMO -0.0899279611200648 >= LUMO -0.109860674289789
cycle= 8 E= -1887.34356138162 delta_E= -0.00132 |g|= 0.00509 |ddm|= 0.0903
WARN: HOMO -0.0890797880496118 >= LUMO -0.109560408210578
cycle= 9 E= -1887.34361835001 delta_E= -5.7e-05 |g|= 0.00407 |ddm|= 0.0554
WARN: HOMO -0.0892381382266698 >= LUMO -0.109585360223636
cycle= 10 E= -1887.34363904571 delta_E= -2.07e-05 |g|= 0.00344 |ddm|= 0.0387
WARN: HOMO -0.089336146908494 >= LUMO -0.109740427598864
cycle= 11 E= -1887.34366978436 delta_E= -3.07e-05 |g|= 0.00182 |ddm|= 0.0429
WARN: HOMO -0.0894133394799783 >= LUMO -0.11000925925318
cycle= 12 E= -1887.34364450922 delta_E= 2.53e-05 |g|= 0.00159 |ddm|= 0.0356
WARN: HOMO -0.0895779833434172 >= LUMO -0.110031745025601
cycle= 13 E= -1887.3437025027 delta_E= -5.8e-05 |g|= 0.00552 |ddm|= 0.0743
WARN: HOMO -0.0895603005513019 >= LUMO -0.110435347994682
cycle= 14 E= -1887.34362193603 delta_E= 8.06e-05 |g|= 0.000803 |ddm|= 0.152
WARN: HOMO -0.0895439705522502 >= LUMO -0.110376855437796
cycle= 15 E= -1887.34362203752 delta_E= -1.01e-07 |g|= 0.000425 |ddm|= 0.00385
WARN: HOMO -0.0895231061204559 >= LUMO -0.110298025322043
cycle= 16 E= -1887.34362207022 delta_E= -3.27e-08 |g|= 6.08e-05 |ddm|= 0.00185
WARN: HOMO -0.0895227733813892 >= LUMO -0.110285080899865
cycle= 17 E= -1887.34362207278 delta_E= -2.56e-09 |g|= 2.08e-05 |ddm|= 0.000235
WARN: HOMO -0.0895239362301562 >= LUMO -0.110287145467374
cycle= 18 E= -1887.3436220739 delta_E= -1.12e-09 |g|= 5.99e-06 |ddm|= 0.000206
WARN: HOMO -0.089523950035947 >= LUMO -0.110287338023122
cycle= 19 E= -1887.34362207406 delta_E= -1.7e-10 |g|= 3.54e-06 |ddm|= 0.000155
WARN: HOMO -0.0895240911455198 >= LUMO -0.11028876186082
Extra cycle E= -1887.34362207409 delta_E= -2.16e-11 |g|= 7.59e-06 |ddm|= 5.09e-05
converged SCF energy = -1887.34362207409
**** checking ROHF/ROKS internal stability ...
nelec by numeric integration = [24. 22.]
CPU time for vxc 2.51 sec, wall time 0.08 sec
tol 0.0001 toloose 0.01
max_cycle 50 max_space 12 max_memory 2000 incore True
davidson 0 1 |r|= 1.16 e= [0.16634] max|de|= 0.166 lindep= 0.928
davidson 1 2 |r|= 1.25 e= [0.164805] max|de|= -0.00154 lindep= 0.337
davidson 2 3 |r|= 0.32 e= [0.021412] max|de|= -0.143 lindep= 0.558
davidson 3 4 |r|= 0.0955 e= [-0.078534] max|de|= -0.0999 lindep= 0.943
davidson 4 5 |r|= 0.0804 e= [-0.081792] max|de|= -0.00326 lindep= 0.837
davidson 5 6 |r|= 0.0311 e= [-0.082994] max|de|= -0.0012 lindep= 0.855
davidson 6 7 |r|= 0.0141 e= [-0.083161] max|de|= -0.000166 lindep= 0.753
root 0 converged |r|= 0.00901 e= -0.08323409530037865 max|de|= -7.34e-05
converged 7 8 |r|= 0.00901 e= [-0.083234] max|de|= -7.34e-05
ROHF wavefunction has an internal instability.
******** <class 'pyscf.dft.roks.ROKS'> ********
method = ROKS-ROHF-RHF
initial guess = minao
damping factor = 0
level_shift factor = 0
DIIS = <class 'pyscf.scf.diis.CDIIS'>
diis_start_cycle = 1
diis_space = 8
SCF conv_tol = 1e-09
SCF conv_tol_grad = None
SCF max_cycles = 50
direct_scf = True
direct_scf_tol = 1e-13
chkfile to save SCF result = /share/home/srwang/pyAutoMR/examples/guess/tmpye_85lf9
max_memory 4000 MB (current use 517 MB)
num. doubly occ = 22 num. singly occ = 2
XC functionals = pbe0
small_rho_cutoff = 1e-07
radial grids:
Treutler-Ahlrichs [JCP 102, 346 (1995); DOI:10.1063/1.469408] (M4) radial grids
becke partition: Becke, JCP 88, 2547 (1988); DOI:10.1063/1.454033
pruning grids: <function nwchem_prune at 0x2b8c151e88c0>
grids dens level: 3
symmetrized grids: False
atomic radii adjust function: <function treutler_atomic_radii_adjust at 0x2b8c151e8d40>
******** <class 'pyscf.dft.roks.ROKS'> Newton solver flags ********
SCF tol = 1e-09
conv_tol_grad = None
max. SCF cycles = 50
direct_scf = True
direct_scf_tol = 1e-13
chkfile to save SCF result = /share/home/srwang/pyAutoMR/examples/guess/tmpye_85lf9
max_cycle_inner = 12
max_stepsize = 0.05
ah_start_tol = 1e+09
ah_level_shift = 0
ah_conv_tol = 1e-12
ah_lindep = 1e-14
ah_start_cycle = 1
ah_max_cycle = 40
ah_grad_trust_region = 2.5
kf_interval = 4
kf_trust_region = 5
canonicalization = True
max_memory 4000 MB (current use 518 MB)
Set conv_tol_grad to 3.16228e-05
HOMO = -0.0481587200300841 LUMO = -0.0242986134371701
Initial guess E= -1887.19159424044 |g|= 0.863251
macro= 0 E= -1887.3442643807 delta_E= -0.15267 |g|= 0.439671 3 KF 16 JK
macro= 1 E= -1887.37865103842 delta_E= -0.0343867 |g|= 0.0649978 3 KF 22 JK
macro= 2 E= -1887.38357246214 delta_E= -0.00492142 |g|= 0.0471351 4 KF 23 JK
macro= 3 E= -1887.39933988377 delta_E= -0.0157674 |g|= 0.0626682 3 KF 21 JK
macro= 4 E= -1887.41070755056 delta_E= -0.0113677 |g|= 0.0645542 3 KF 20 JK
macro= 5 E= -1887.41226814988 delta_E= -0.0015606 |g|= 0.00951895 4 KF 20 JK
macro= 6 E= -1887.41230549769 delta_E= -3.73478e-05 |g|= 7.1052e-05 3 KF 17 JK
macro= 7 E= -1887.41230570057 delta_E= -2.02876e-07 |g|= 0.000154602 1 KF 5 JK
macro= 8 E= -1887.41230612892 delta_E= -4.2835e-07 |g|= 3.45764e-05 3 KF 18 JK
macro= 9 E= -1887.41230615285 delta_E= -2.39299e-08 |g|= 7.40086e-05 1 KF 7 JK
macro= 10 E= -1887.41230615285 delta_E= 1.59162e-12 |g|= 8.34857e-06 1 KF 2 JK
Canonicalize SCF orbitals
macro X = 11 E=-1887.41230615285 |g|= 8.34857e-06 total 30 KF 183 JK
converged SCF energy = -1887.41230615285
**** checking ROHF/ROKS internal stability ...
nelec by numeric integration = [24. 22.]
CPU time for vxc 2.46 sec, wall time 0.08 sec
tol 0.0001 toloose 0.01
max_cycle 50 max_space 12 max_memory 2000 incore True
davidson 0 1 |r|= 2.01 e= [0.71667] max|de|= 0.717 lindep= 0.992
davidson 1 2 |r|= 1.68 e= [0.687289] max|de|= -0.0294 lindep= 0.838
davidson 2 3 |r|= 1.18 e= [0.670004] max|de|= -0.0173 lindep= 0.96
davidson 3 4 |r|= 0.504 e= [0.509608] max|de|= -0.16 lindep= 0.828
davidson 4 5 |r|= 0.665 e= [0.352973] max|de|= -0.157 lindep= 0.943
davidson 5 6 |r|= 0.191 e= [0.125228] max|de|= -0.228 lindep= 0.996
davidson 6 7 |r|= 0.26 e= [0.062482] max|de|= -0.0627 lindep= 0.907
davidson 7 8 |r|= 0.243 e= [0.036609] max|de|= -0.0259 lindep= 0.873
davidson 8 9 |r|= 0.215 e= [0.015931] max|de|= -0.0207 lindep= 0.799
davidson 9 10 |r|= 0.114 e= [0.006705] max|de|= -0.00923 lindep= 0.79
davidson 10 11 |r|= 0.0873 e= [0.002218] max|de|= -0.00449 lindep= 0.766
davidson 11 12 |r|= 0.0294 e= [0.000698] max|de|= -0.00152 lindep= 0.902
davidson 12 1 |r|= 0.0294 e= [0.000698] max|de|= -2.52e-16 lindep= 1
davidson 13 2 |r|= 0.0201 e= [0.000538] max|de|= -0.00016 lindep= 0.959
davidson 14 3 |r|= 0.0151 e= [0.000494] max|de|= -4.46e-05 lindep= 0.869
root 0 converged |r|= 0.00948 e= 0.000409548433971921 max|de|= -8.43e-05
converged 15 4 |r|= 0.00948 e= [0.00041] max|de|= -8.43e-05
ROHF wavefunction is stable in the internal stability analysis
from pyscf import gto, dft
from automr import guess
#mf=guess.from_fch_simp("v2.fchk", xc='pbe0')
#mf2.verbose=9
#mf2.stability()
mol = gto.Mole(atom='''V 0.0 0.0 0.0; V 0.0 0.0 1.77''', basis='def2-tzvp', spin=2)
mol.verbose = 4
mol.build()
mf = dft.ROKS(mol)
mf.xc = 'pbe0'
mf.kernel()
mf2 = guess.check_stab(mf, newton=True, res=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment