Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. #import psi4
  2. #import numpy as np
  3.  
  4.  
  5. molecule wat {
  6. symmetry c1
  7. no_reorient
  8. O -1.769142 -0.076181 -0.000000
  9. H -2.065745 0.837492 0.000000
  10. H -0.809034 0.001317 -0.000000
  11. --
  12. O 1.283899 0.088882 0.000000
  13. H 1.580006 -0.425760 0.756361
  14. H 1.580006 -0.425760 -0.756361
  15. }
  16.  
  17. set basis 3-21G
  18. #set print 3
  19. method='scf'
  20. set guess sad
  21. set maxiter 0
  22. set fail_on_maxiter false
  23. set scf_type df
  24. #set S_ORTHOGONALIZATION canonical
  25.  
  26. wat.fix_com(True)
  27. wat.fix_orientation(True)
  28.  
  29. print "== monomer A =="
  30. molA=wat.extract_subsets(1)
  31. A_e_scf, Awfn = energy(method, molecule=molA, return_wfn=True)
  32. print A_e_scf
  33.  
  34. A_occ = np.array(Awfn.Ca_subset("SO", "OCC").to_array())
  35. A_virt = np.array(Awfn.Ca_subset("SO", "VIR").to_array())
  36. Anocc=A_occ.shape[1]
  37. Amo=A_occ.shape[0]
  38. Anvirt=A_virt.shape[1]
  39. #print Anocc, Anvirt,Amo
  40. Aeigen=np.array( Awfn.epsilon_a().to_array() )
  41.  
  42.  
  43. print "== monomer B =="
  44.  
  45. molB=wat.extract_subsets(2)
  46.  
  47. B_e_scf, Bwfn = energy(method, molecule=molB, return_wfn=True)
  48. print B_e_scf
  49.  
  50. B_occ = np.array(Bwfn.Ca_subset("SO", "OCC").to_array())
  51. B_virt = np.array(Bwfn.Ca_subset("SO", "VIR").to_array())
  52. Bnocc=B_occ.shape[1]
  53. Bnvirt=B_virt.shape[1]
  54. Bmo=B_occ.shape[0]
  55. Beigen=np.array( Bwfn.epsilon_a().to_array() )
  56.  
  57. print "= promo wfn =="
  58. clean()
  59. ABnmo=Anocc+Bnocc+Anvirt+Bnvirt
  60. AB=np.zeros((ABnmo,ABnmo))
  61. ABeigen=np.zeros(ABnmo)
  62. ABwfn = core.Wavefunction.build(wat, core.get_global_option('BASIS'))
  63.  
  64.  
  65. # merge MOs and eigenvalues
  66. cnt=0
  67. for i in range(Anocc):
  68. ABeigen[cnt]=Aeigen[i]
  69. for j in range(Amo):
  70. AB[j][cnt]=A_occ[j][i]
  71. cnt+=1
  72.  
  73. for i in range(Bnocc):
  74. ABeigen[cnt]=Beigen[i]
  75. for j in range(Bmo):
  76. AB[j+Amo][cnt]=B_occ[j][i]
  77. cnt+=1
  78.  
  79. for i in range(Anvirt):
  80. ABeigen[cnt]=Aeigen[Anocc+i]
  81. for j in range(Amo):
  82. AB[j][cnt]=A_virt[j][i]
  83. cnt+=1
  84.  
  85. for i in range(Bnvirt):
  86. ABeigen[cnt]=Beigen[Bnocc+i]
  87. for j in range(Bmo):
  88. AB[j+Amo][cnt]=B_virt[j][i]
  89. cnt+=1
  90.  
  91.  
  92.  
  93. # build new wfn object and set MOs as guess
  94. AB_Ca=core.Matrix.from_array(AB)
  95.  
  96. AB_Ca.print_out()
  97.  
  98. ref_wfn = scf_wavefunction_factory("scf", ABwfn, core.get_option('SCF', 'REFERENCE'))
  99. core.set_legacy_wavefunction(ref_wfn)
  100. ref_wfn.guess_Ca(AB_Ca) # this defines also the occupation :(
  101. ABnocc=[Anocc+Bnocc]
  102. ABoccpi=core.Dimension.from_list(ABnocc)
  103. ref_wfn.force_doccpi(Aoccpi+Boccpi) # not found
  104. ref_wfn.reset_occ(True) # seems to be overwritten later hf.initialize()
  105. molden(ref_wfn,filename='api.molden')
  106.  
  107. print " == numpy SCF =="
  108. # MANUAL HF
  109.  
  110. mints = psi4.core.MintsHelper(ref_wfn.basisset())
  111. S = np.asarray(mints.ao_overlap())
  112.  
  113. # Get nbf and ndocc for closed shell molecules
  114. nbf = S.shape[0]
  115. ndocc = ref_wfn.nalpha()
  116.  
  117. print('Number of occupied orbitals: %d' % ndocc)
  118. print('Number of basis functions: %d' % nbf)
  119.  
  120. # Compute required quantities for SCF
  121. V = np.asarray(mints.ao_potential())
  122. T = np.asarray(mints.ao_kinetic())
  123. I = np.asarray(mints.ao_eri())
  124.  
  125. Enuc = wat.nuclear_repulsion_energy()
  126.  
  127.  
  128. # Build H_core
  129. H = T + V
  130.  
  131. # Orthogonalizer A = S^(-1/2) using Psi4's matrix power.
  132. #A = mints.ao_overlap()
  133. #A.power(-0.5, 1.e-16)
  134. #A = np.asarray(A)
  135.  
  136.  
  137. # non-orthonormalized fragment MO density and its energy
  138. C = AB
  139. Cocc = C[:, :ndocc]
  140. D = np.einsum('pi,qi->pq', Cocc, Cocc)
  141.  
  142. # Build fock matrix
  143. J = np.einsum('pqrs,rs->pq', I, D)
  144. K = np.einsum('prqs,rs->pq', I, D)
  145. F = H + J * 2 - K
  146.  
  147. # SCF energy and update
  148. SCF_E = np.einsum('pq,pq->', F + H, D) + Enuc
  149. print SCF_E
  150.  
  151.  
  152. #==============
  153. print " == psi4 SCF =="
  154. AB_e_scf = ref_wfn.compute_energy()
  155. print "ESCF(initial) =", AB_e_scf
Add Comment
Please, Sign In to add comment