16
16
from pyscf import gto , scf , df , dft
17
17
from pyscf .data .nist import BOHR
18
18
from pyscf import mcpdft
19
+ from pyscf .fci .addons import _unpack_nelec
19
20
import unittest
20
21
21
22
def diatomic (atom1 , atom2 , r , fnal , basis , ncas , nelecas , nstates ,
@@ -34,7 +35,8 @@ def diatomic (atom1, atom2, r, fnal, basis, ncas, nelecas, nstates,
34
35
#if spin is not None: smult = spin+1
35
36
#else: smult = (mol.nelectron % 2) + 1
36
37
#mc.fcisolver = csf_solver (mol, smult=smult)
37
- if spin is None : spin = mol .nelectron % 2
38
+ neleca , nelecb = _unpack_nelec (nelecas , spin = spin )
39
+ spin = neleca - nelecb
38
40
ss = spin * (spin + 2 )* 0.25
39
41
mc = mc .multi_state ([1.0 / float (nstates ),]* nstates , 'cms' )
40
42
mc .fix_spin_ (ss = ss , shift = 1 )
@@ -189,26 +191,34 @@ def test_grad_lih_cms2ftlda22_sto3g_df (self):
189
191
def test_rohf_sanity (self ):
190
192
mc_grad = diatomic ('Li' , 'H' , 1.8 , 'ftLDA,VWN3' , '6-31g' , 4 , 2 , 2 , symmetry = True ,
191
193
cas_irrep = {'A1' : 4 }, spin = 2 )
192
- de_ref = [- 0.039806 ,- 0.024193 ]
194
+ mc_grad_ref = diatomic ('Li' , 'H' , 1.8 , 'ftLDA,VWN3' , '6-31g' , 4 , (2 ,0 ), 2 ,
195
+ symmetry = True , cas_irrep = {'A1' : 4 })
196
+ de_num_ref = [- 0.039806 ,- 0.024193 ]
193
197
# Numerical from this software
194
198
# PySCF commit: bee0ce288a655105e27fcb0293b203939b7aecc9
195
199
# PySCF-forge commit: 50bc1da117ced9613948bee14a99a02c7b2c5769
196
200
for i in range (2 ):
197
201
with self .subTest (state = i ):
198
202
de = mc_grad .kernel (state = i ) [1 ,0 ] / BOHR
199
- self .assertAlmostEqual (de , de_ref [i ], 4 )
203
+ self .assertAlmostEqual (de , de_num_ref [i ], 4 )
204
+ de_ref = mc_grad_ref .kernel (state = i ) [1 ,0 ] / BOHR
205
+ self .assertAlmostEqual (de , de_ref , 6 )
200
206
201
207
def test_dfrohf_sanity (self ):
202
208
mc_grad = diatomic ('Li' , 'H' , 1.8 , 'ftLDA,VWN3' , '6-31g' , 4 , 2 , 2 , symmetry = True ,
203
209
density_fit = True , cas_irrep = {'A1' : 4 }, spin = 2 )
204
- de_ref = [- 0.039721 ,- 0.024139 ]
210
+ mc_grad_ref = diatomic ('Li' , 'H' , 1.8 , 'ftLDA,VWN3' , '6-31g' , 4 , (2 ,0 ), 2 ,
211
+ symmetry = True , density_fit = True , cas_irrep = {'A1' : 4 })
212
+ de_num_ref = [- 0.039721 ,- 0.024139 ]
205
213
# Numerical from this software
206
214
# PySCF commit: bee0ce288a655105e27fcb0293b203939b7aecc9
207
215
# PySCF-forge commit: 50bc1da117ced9613948bee14a99a02c7b2c5769
208
216
for i in range (2 ):
209
217
with self .subTest (state = i ):
210
218
de = mc_grad .kernel (state = i ) [1 ,0 ] / BOHR
211
- self .assertAlmostEqual (de , de_ref [i ], 4 )
219
+ self .assertAlmostEqual (de , de_num_ref [i ], 4 )
220
+ de_ref = mc_grad_ref .kernel (state = i ) [1 ,0 ] / BOHR
221
+ self .assertAlmostEqual (de , de_ref , 6 )
212
222
213
223
if __name__ == "__main__" :
214
224
print ("Full Tests for CMS-PDFT gradients of diatomic molecules" )
0 commit comments