forked from pradiptasam/iccsdn_modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMP2.py
More file actions
74 lines (48 loc) · 1.84 KB
/
Copy pathMP2.py
File metadata and controls
74 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import os
import numpy as np
from pyscf import mp
from pyscf.lib import logger
_pythonpath = os.environ['PYTHONPATH']
_present_in_pythonpath = _pythonpath.find('iccsdn_module') >= 0
if (_present_in_pythonpath):
import PostHF
else:
from pyscf.iccsdn import PostHF
class MP2(object):
def __init__(self, mf, nfo=0, nfv=0):
self.mol = mf.mol
self.mf = mf
# self.verbose = self.mol.verbose
# self.stdout = self.mol.stdout
self.nfo = nfo
self.nfv = nfv
self.nel = self.mol.nelectron
self.e_hf = mf.e_tot
def check_mp2(self, e_mp2):
m = mp.MP2(self.mf)
if abs(m.kernel()[0]-e_mp2) <= 1E-6:
print("MP2 successfully done")
else:
print("MP2 energies differ")
def calc_mp2_energy(self):
e_mp2 = 2*np.einsum('ijab,ijab',self.t2,self.twoelecint_mo[:self.nocc,:self.nocc,self.nocc:self.nao,self.nocc:self.nao]) - np.einsum('ijab,ijba',self.t2,self.twoelecint_mo[:self.nocc,:self.nocc,self.nocc:self.nao,self.nocc:self.nao])
print("MP2 correlation energy is : "+str(e_mp2))
e_mp2_tot = self.e_hf + e_mp2
print("MP2 energy is : "+str(e_mp2_tot))
self.check_mp2(e_mp2)
def run(self):
#log = logger.Logger(self.stdout, self.verbose)
#log.warn('**** RUNING MP2 ****')
print('**** RUNING MP2 ****')
AllData = PostHF.GetIntNData(self.mf, self.nfo, self.nfv)
AllData.transform_all_ints()
self.twoelecint_mo = AllData.twoelecint_mo
self.nao = AllData.nao
self.nocc = AllData.nocc
self.nvirt = AllData.nvirt
AllData.init_guess_t2()
self.t2 = AllData.t2
self.calc_mp2_energy()
self.twoelecint_mo = None
self.t2 = None
print('**** MP2 is done ****')