kthpanor / echem

eChem: Jupyter book on theoretical chemistry
https://kthpanor.github.io/echem/
89 stars 20 forks source link

Issue on page /docs/tutorials/uv_vis_analysis.html #8

Closed giammi56 closed 1 year ago

giammi56 commented 1 year ago

The notebook contains an output error that I can reproduce directly:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In [3], line 2
      1 # Perform SCF calculation
----> 2 scf_gs = gator.run_scf(struct, basis)
      4 # Calculate the 6 lowest eigenstates
      5 adc_res = gator.run_adc(struct, basis, scf_gs, method="adc3", singlets=6)

File ~/anaconda3/envs/echem/lib/python3.9/site-packages/gator/gatorutils.py:123, in run_scf(mol, basis, **kwargs)
    121 else:
    122     valstr += 'NOT converged in '
--> 123 valstr += '{:d} iterations.'.format(scf_drv.num_iter)
    124 print(valstr, file=sys.stdout)
    125 if scf_drv.is_converged:

AttributeError: 'ScfRestrictedDriver' object has no attribute 'num_iter'

which implies that adc_res cannot be defined: NameError: name 'adc_res' is not defined

The output before the error is the following:

Self Consistent Field Driver Setup                                            
                                           ====================================                                           

                   Wave Function Model             : Spin-Restricted Hartree-Fock                                         
                   Initial Guess Model             : Superposition of Atomic Densities                                    
                   Convergence Accelerator         : Two Level Direct Inversion of Iterative Subspace                     
                   Max. Number of Iterations       : 50                                                                   
                   Max. Number of Error Vectors    : 10                                                                   
                   Convergence Threshold           : 1.0e-06                                                              
                   ERI Screening Scheme            : Cauchy Schwarz + Density                                             
                   ERI Screening Mode              : Dynamic                                                              
                   ERI Screening Threshold         : 1.0e-12                                                              
                   Linear Dependence Threshold     : 1.0e-06                                                              

* Info * Nuclear repulsion energy: 1979.0094508606 a.u.                                                                   

* Info * Overlap matrix computed in 0.01 sec.                                                                             

* Info * Kinetic energy matrix computed in 0.01 sec.                                                                      

* Info * Nuclear potential matrix computed in 0.66 sec.                                                                   

* Info * Orthogonalization matrix computed in 0.04 sec.                                                                   

* Info * SAD initial guess computed in 0.03 sec.                                                                          

* Info * Starting Reduced Basis SCF calculation...                                                                        
* Info * ...done. SCF energy in reduced basis set: -3370.054418065419 a.u. Time: 111.15 sec.                              

* Info * Overlap matrix computed in 0.01 sec.                                                                             

* Info * Kinetic energy matrix computed in 0.01 sec.                                                                      

* Info * Nuclear potential matrix computed in 0.58 sec.                                                                   

* Info * Orthogonalization matrix computed in 0.01 sec.                                                                   

               Iter. | Hartree-Fock Energy | Energy Change | Gradient Norm | Max. Gradient | Density Change               
               --------------------------------------------------------------------------------------------               
                  1     -3370.054429643537    0.0000000000      0.00070729      0.00008566      0.00000000                
                  2     -3370.054429753136   -0.0000001096      0.00042475      0.00003835      0.00055520                
                  3     -3370.054429785354   -0.0000000322      0.00008200      0.00000966      0.00031822                
                  4     -3370.054429786257   -0.0000000009      0.00001955      0.00000200      0.00004124                
                  5     -3370.054429786335   -0.0000000001      0.00000585      0.00000046      0.00001707                
                  6     -3370.054429786358   -0.0000000000      0.00000114      0.00000009      0.00000459                
                  7     -3370.054429786353    0.0000000000      0.00000035      0.00000002      0.00000139                

               *** SCF converged in 7 iterations. Time: 200.56 sec.                                                       

               Spin-Restricted Hartree-Fock:                                                                              
               -----------------------------                                                                              
               Total Energy                       :    -3370.0544297864 a.u.                                              
               Electronic Energy                  :    -5349.0638806470 a.u.                                              
               Nuclear Repulsion Energy           :     1979.0094508606 a.u.                                              
               ------------------------------------                                                                       
               Gradient Norm                      :        0.0000003471 a.u.                                              

               Ground State Information                                                                                   
               ------------------------                                                                                   
               Charge of Molecule            :  0.0                                                                       
               Multiplicity (2S+1)           :  1.0                                                                       
               Magnetic Quantum Number (M_S) :  0.0                                                                       

                                                 Spin Restricted Orbitals                                                 
                                                 ------------------------                                                 

               Molecular Orbital No.  95:                                                                                 
               --------------------------                                                                                 
               Occupation: 2.000 Energy:   -0.41219 a.u.                                                                  
               (   2 C   1p+1:    -0.20) (   4 C   1p+1:     0.21) (   6 C   1p+1:    -0.25)                              
               (   6 C   2p+1:    -0.16) (   8 C   1p+1:     0.24) (  12 C   1p+1:    -0.21)                              
               (  45 H   1s  :     0.15) (  45 H   2s  :     0.16)                                                        

               Molecular Orbital No.  96:                                                                                 
               --------------------------                                                                                 
               Occupation: 2.000 Energy:   -0.38375 a.u.                                                                  
               (  12 C   1p0 :     0.20) (  13 C   1p0 :    -0.21) (  14 C   1p0 :     0.25)                              
               (  15 C   1p0 :    -0.26) (  16 C   1p0 :     0.25) (  17 C   1p0 :    -0.23)                              
               (  18 C   1p0 :     0.20) (  19 C   1p0 :    -0.16)                                                        

               Molecular Orbital No.  97:                                                                                 
               --------------------------                                                                                 
               Occupation: 2.000 Energy:   -0.20817 a.u.                                                                  
               (  21 Br  2p0 :     0.27) (  21 Br  3p+1:    -0.24) (  21 Br  3p-1:    -0.31)                              
               (  21 Br  3p0 :    -0.58) (  21 Br  4p-1:    -0.20) (  21 Br  4p0 :    -0.36)                              

               Molecular Orbital No.  98:                                                                                 
               --------------------------                                                                                 
               Occupation: 2.000 Energy:   -0.20749 a.u.                                                                  
               (  21 Br  2p+1:     0.30) (  21 Br  3p+1:    -0.65) (  21 Br  3p-1:     0.20)                              
               (  21 Br  3p0 :     0.16) (  21 Br  4p+1:    -0.41)                                                        

               Molecular Orbital No.  99:                                                                                 
               --------------------------                                                                                 
               Occupation: 2.000 Energy:   -0.20740 a.u.                                                                  
               (  21 Br  2p-1:    -0.27) (  21 Br  2p0 :     0.16) (  21 Br  3p-1:     0.59)                              
               (  21 Br  3p0 :    -0.36) (  21 Br  4p-1:     0.38) (  21 Br  4p0 :    -0.22)                              

               Molecular Orbital No. 100:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.09708 a.u.                                                                  
               (   3 C   3s  :    -0.18) (   5 C   3s  :    -0.65) (   5 C   2p+1:    -0.22)                              
               (   5 C   2p0 :    -0.29) (   7 N   3s  :    -0.64) (   9 C   3s  :    -0.83)                              
               (   9 C   2p+1:    -0.18) (   9 C   2p-1:    -0.16) (   9 C   2p0 :     0.37)                              
               (  10 C   3s  :    -0.92) (  10 C   2p+1:    -0.26) (  10 C   2p-1:     0.43)                              
               (  11 C   3s  :    -0.84) (  11 C   2p+1:     0.40) (  11 C   2p-1:     0.18)                              
               (  30 H   2s  :     0.43) (  31 H   2s  :     0.42) (  36 H   2s  :     0.54)                              
               (  37 H   2s  :     0.53) (  38 H   2s  :     0.30) (  39 H   2s  :     0.50)                              
               (  40 H   2s  :     0.53) (  41 H   2s  :     0.52) (  42 H   2s  :     0.52)                              
               (  43 H   2s  :     0.35) (  44 H   2s  :     0.51)                                                        

               Molecular Orbital No. 101:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.15605 a.u.                                                                  
               (   5 C   2p+1:     0.25) (   5 C   2p0 :     0.40) (   7 N   3s  :     0.25)                              
               (   9 C   2p+1:     0.41) (   9 C   2p-1:     0.43) (   9 C   2p0 :     0.37)                              
               (  10 C   1p0 :     0.17) (  10 C   2p+1:     0.38) (  10 C   2p-1:     0.27)                              
               (  10 C   2p0 :     0.67) (  11 C   2p-1:     0.45) (  11 C   2p0 :     0.54)                              
               (  30 H   2s  :    -0.24) (  31 H   2s  :    -0.18) (  36 H   2s  :    -0.59)                              
               (  37 H   2s  :     0.89) (  39 H   2s  :    -0.42) (  40 H   2s  :     1.01)                              
               (  41 H   2s  :    -0.57) (  42 H   2s  :    -0.41) (  43 H   2s  :    -0.30)                              
               (  44 H   2s  :     0.96)                                                                                  

               Molecular Orbital No. 102:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.15950 a.u.                                                                  
               (   1 C   3s  :     0.29) (   3 C   3s  :     0.91) (   3 C   2p0 :    -0.18)                              
               (   4 C   3s  :     0.22) (   5 C   2p-1:    -0.36) (   5 C   2p0 :    -0.30)                              
               (   7 N   3s  :    -1.83) (   9 C   3s  :     1.03) (   9 C   2p+1:    -0.23)                              
               (   9 C   2p0 :     0.40) (  10 C   3s  :     0.50) (  10 C   2p+1:    -0.23)                              
               (  10 C   2p-1:     0.49) (  11 C   3s  :     1.17) (  11 C   2p+1:     0.32)                              
               (  11 C   2p-1:     0.32) (  26 H   2s  :    -0.51) (  27 H   2s  :    -0.44)                              
               (  29 H   2s  :    -0.20) (  36 H   2s  :    -0.19) (  37 H   2s  :    -0.15)                              
               (  38 H   2s  :    -0.61) (  42 H   2s  :    -0.20) (  43 H   2s  :    -0.67)                              
               (  44 H   2s  :    -0.25)                                                                                  

               Molecular Orbital No. 103:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.16252 a.u.                                                                  
               (   5 C   2p+1:     0.48) (   5 C   2p-1:     0.32) (   5 C   2p0 :    -0.45)                              
               (   9 C   2p+1:     0.41) (   9 C   2p-1:     0.28) (   9 C   2p0 :    -0.21)                              
               (  10 C   1p+1:     0.15) (  10 C   2p+1:     0.59) (  10 C   2p-1:     0.34)                              
               (  10 C   2p0 :    -0.45) (  11 C   2p+1:     0.36) (  11 C   2p0 :    -0.48)                              
               (  26 H   2s  :     0.17) (  27 H   2s  :    -0.16) (  30 H   2s  :    -0.72)                              
               (  31 H   2s  :     0.84) (  36 H   2s  :    -0.57) (  37 H   2s  :     0.15)                              
               (  39 H   2s  :     0.91) (  41 H   2s  :    -0.85) (  42 H   2s  :     0.70)                              
               (  44 H   2s  :    -0.28)                                                                                  

               Molecular Orbital No. 104:                                                                                 
               --------------------------                                                                                 
               Occupation: 0.000 Energy:    0.16916 a.u.                                                                  
               (   1 C   3s  :    -0.49) (   3 C   3s  :     0.15) (   3 C   2p0 :     0.20)                              
               (   5 C   3s  :    -0.73) (   5 C   2p+1:    -0.29) (   5 C   2p-1:     0.17)                              
               (   5 C   2p0 :    -0.21) (   7 N   3s  :     0.74) (   7 N   2p0 :    -0.26)                              
               (   9 C   3s  :    -0.38) (   9 C   1p-1:     0.17) (   9 C   2p+1:    -0.41)                              
               (   9 C   2p-1:     0.72) (   9 C   2p0 :    -0.26) (  10 C   3s  :     0.24)                              
               (  11 C   1p+1:    -0.16) (  11 C   2p+1:    -0.61) (  11 C   2p-1:     0.55)                              
               (  11 C   2p0 :    -0.32) (  22 H   2s  :     0.22) (  23 H   2s  :     0.24)                              
               (  26 H   2s  :    -0.16) (  30 H   2s  :     0.63) (  31 H   2s  :     0.54)                              
               (  36 H   2s  :     0.55) (  37 H   2s  :     0.30) (  38 H   2s  :    -0.87)                              
               (  39 H   2s  :    -0.15) (  42 H   2s  :     0.55) (  43 H   2s  :    -1.05) 
giammi56 commented 1 year ago

Digging into the issue, I have noticed that the class has the attribute defined as:

class ScfDriver:
    """
   [...]
    """

    def __init__(self, comm, ostream):
      [...]

        # iterations data
        self._iter_data = None
        self._is_converged = False
        self._scf_energy = 0.0
        self._num_iter = 0

maybe the inheritance is not working property because of the _?

recoli commented 1 year ago

Thanks for reporting the issue. This should have been fixed in https://gitlab.com/veloxchem/veloxchem and https://anaconda.org/veloxchem/veloxchem. Could you please recompile/reinstall veloxchem and try again?

giammi56 commented 1 year ago

Yes, it works fine in both cases now!