@@ -85,7 +85,7 @@ def _density_fit(mf, auxbasis=None, with_df=None, only_dfj=False):
85
85
Examples:
86
86
'''
87
87
88
- assert isinstance (mf , scf . hf .SCF )
88
+ assert isinstance (mf , hf .SCF )
89
89
90
90
if with_df is None :
91
91
if isinstance (mf , dhf .UHF ):
@@ -110,7 +110,8 @@ def _density_fit(mf, auxbasis=None, with_df=None, only_dfj=False):
110
110
dfmf = _DFHF (mf , with_df , only_dfj )
111
111
return lib .set_class (dfmf , (_DFHF , mf .__class__ ))
112
112
113
- class _DFHF (df_jk ._DFHF ):
113
+ from gpu4pyscf .lib import utils
114
+ class _DFHF :
114
115
'''
115
116
Density fitting SCF class
116
117
Attributes for density-fitting SCF:
@@ -121,8 +122,8 @@ class _DFHF(df_jk._DFHF):
121
122
with_df : DF object
122
123
Set mf.with_df = None to switch off density fitting mode.
123
124
'''
124
-
125
- from gpu4pyscf . lib . utils import to_cpu , to_gpu , device
125
+ to_gpu = utils . to_gpu
126
+ device = utils . device
126
127
127
128
_keys = {'rhoj' , 'rhok' , 'disp' , 'screen_tol' }
128
129
@@ -181,20 +182,23 @@ def nuc_grad_method(self):
181
182
raise NotImplementedError ()
182
183
183
184
def Hessian (self ):
184
- from pyscf .dft .rks import KohnShamDFT
185
- if isinstance (self , scf .rhf .RHF ):
186
- from gpu4pyscf .df .hessian import rhf , rks
185
+ from gpu4pyscf .dft .rks import KohnShamDFT
186
+ if isinstance (self , hf .RHF ):
187
187
if isinstance (self , KohnShamDFT ):
188
- return rks .Hessian (self )
188
+ from gpu4pyscf .df .hessian import rks as rks_hess
189
+ return rks_hess .Hessian (self )
189
190
else :
190
- return rhf . Hessian ( self )
191
- else :
192
- from gpu4pyscf . df . hessian import uhf , uks
191
+ from gpu4pyscf . df . hessian import rhf as rhf_hess
192
+ return rhf_hess . Hessian ( self )
193
+ elif isinstance ( self , uhf . UHF ):
193
194
if isinstance (self , KohnShamDFT ):
194
- return uks .Hessian (self )
195
+ from gpu4pyscf .df .hessian import uks as uks_hess
196
+ return uks_hess .Hessian (self )
195
197
else :
196
- return uhf .Hessian (self )
197
-
198
+ from gpu4pyscf .df .hessian import uhf as uhf_hess
199
+ return uhf_hess .Hessian (self )
200
+ else :
201
+ raise NotImplementedError
198
202
@property
199
203
def auxbasis (self ):
200
204
return getattr (self .with_df , 'auxbasis' , None )
@@ -207,7 +211,7 @@ def get_veff(self, mol=None, dm=None, dm_last=None, vhf_last=0, hermi=1):
207
211
if dm is None : dm = self .make_rdm1 ()
208
212
209
213
# for DFT
210
- if isinstance (self , scf . hf .KohnShamDFT ):
214
+ if isinstance (self , rks .KohnShamDFT ):
211
215
if dm .ndim == 2 :
212
216
return rks .get_veff (self , dm = dm )
213
217
elif dm .ndim == 3 :
@@ -234,33 +238,11 @@ def get_veff(self, mol=None, dm=None, dm_last=None, vhf_last=0, hermi=1):
234
238
else :
235
239
raise NotImplementedError ("Please check the dimension of the density matrix, it should not reach here." )
236
240
237
- """
238
- def energy_tot(self, dm=None, h1e=None, vhf=None):
239
- '''
240
- compute tot energy
241
- '''
242
- nuc = self.energy_nuc()
243
- e_tot = self.energy_elec(dm, h1e, vhf)[0] + nuc
244
- self.scf_summary['nuc'] = nuc.real
245
- return e_tot
246
- """
247
- '''
248
241
def to_cpu (self ):
249
242
obj = self .undo_df ().to_cpu ().density_fit ()
250
- keys = dir(obj)
251
- obj.__dict__.update(self.__dict__)
252
- for key in set(dir(self)).difference(keys):
253
- print(key)
254
- delattr(obj, key)
255
-
256
- for key in keys:
257
- val = getattr(obj, key)
258
- if isinstance(val, cupy.ndarray):
259
- setattr(obj, key, cupy.asnumpy(val))
260
- elif hasattr(val, 'to_cpu'):
261
- setattr(obj, key, val.to_cpu())
262
- return obj
263
- '''
243
+ print (type (obj ))
244
+ return utils .to_cpu (self , obj )
245
+
264
246
265
247
def get_jk (dfobj , dms_tag , hermi = 1 , with_j = True , with_k = True , direct_scf_tol = 1e-14 , omega = None ):
266
248
'''
0 commit comments