Repository: pyscf/pyscf

Issue #2200: Hessian method is not found in SCF modules
Created: 2024-05-03T21:23:35Z
The Hessian() method is injected into the SCF method. By default, the hessian module is not loaded. One have to from pyscf import hessian first for calling the Hessian() method in hf/dft modules.

Duplicate issue #2223: Some classmethods defined elsewhere cannot be called normally
Created: 2024-05-23T06:57:48Z
mf = mol.X2C_KS() does not work with an AttributeError like this

>>> from pyscf import gto
>>> mol = gto.M(atom='Li', basis='sto-3g', spin=1)
>>> mf = mol.X2C_KS()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/share/home/liuxx/miniconda3/lib/python3.12/site-packages/pyscf/gto/mole.py", line 3735, in __getattr__
    raise AttributeError(f'Mole object has no attribute {key}')
AttributeError: Mole object has no attribute X2C_KS. Did you mean: 'X2C_HF'?
though the attribute I've found is defined in 
  
    
      pyscf/pyscf/dft/__init__.py
    
    
        Lines 120 to 128
      in
      7d94887
    
  
  
    

        
          
           def X2C(mol, *args): 
        

        
          
               '''X2C Kohn-Sham''' 
        

        
          
               from pyscf.scf import dhf 
        

        
          
               from pyscf.x2c import dft 
        

        
          
               if dhf.zquatev and mol.spin == 0: 
        

        
          
                   return dft.RKS(mol, *args) 
        

        
          
               else: 
        

        
          
                   return dft.UKS(mol, *args) 
        

        
          
           gto.Mole.X2C_KS = property(X2C) 
        
    
  

.
It's worth noting that mol.X2C_KS() could be normally called without any errors raised if PySCF is manually built from source.

Similarly, mf.gen_response() in X2C-SCF approach cannot be called either, and it says there's no attribute 'gen_response' found,

>>> from pyscf import gto
>>> mol = gto.M(atom='Li', basis='sto-3g', spin=1)
>>> mf = mol.X2C()
>>> mf.kernel()

WARN: HOMO -0.0463389858396905 == LUMO -0.0463389858347049

converged SCF energy = -7.31595504150337
-7.3159550415033685
>>> mf.gen_response()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'UHF' object has no attribute 'gen_response'
while it occurs in 
  
    
      pyscf/pyscf/x2c/_response_functions.py
    
    
        Lines 23 to 31
      in
      7d94887
    
  
  
    

        
          
           def _gen_x2chf_response(mf, mo_coeff=None, mo_occ=None, 
        

        
          
                                   with_j=True, hermi=0, max_memory=None): 
        

        
          
               '''Generate a function to compute the product of X2C-HF response function 
        

        
          
               and density matrices. 
        

        
          
               ''' 
        

        
          
               return _gen_ghf_response(mf, mo_coeff, mo_occ, with_j, hermi, max_memory) 
        

        
          
            
        

        
          
           x2c.UHF.gen_response = _gen_x2chf_response 
        

        
          
           x2c.RHF.gen_response = _gen_x2chf_response 
        
    
  

.

Closing comment (2024-05-24T04:07:58Z): Pyscf employs lazy import for dft and many other modules, similar to the issue reported in #2200  .
For a quickfix, you can execute
from pyscf import gto, dft

before calling mol.X2C_KS. The symbol X2C_KS is only made available when importing dft
I'll fix this issue in next release