pyctramer 0.1.32__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyctramer/AnalyzeQC.py +249 -0
- pyctramer/ConstructFF.py +1191 -0
- pyctramer/FGR.py +238 -0
- pyctramer/JobControl.py +120 -0
- pyctramer/MarcusAA.py +297 -0
- pyctramer/PyCTRAMER.py +73 -0
- pyctramer/RunMD.py +313 -0
- pyctramer/SpinBoson.py +193 -0
- pyctramer/SubmitQC.py +256 -0
- pyctramer/Utilities.py +305 -0
- pyctramer/__init__.py +2 -0
- pyctramer/pyctramer.py +73 -0
- pyctramer-0.1.32.dist-info/METADATA +10 -0
- pyctramer-0.1.32.dist-info/RECORD +16 -0
- pyctramer-0.1.32.dist-info/WHEEL +5 -0
- pyctramer-0.1.32.dist-info/top_level.txt +1 -0
pyctramer/FGR.py
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# FGR
|
|
2
|
+
import numpy as np
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from .Utilities import *
|
|
5
|
+
|
|
6
|
+
def coth(x):
|
|
7
|
+
return 1. / np.tanh(x)
|
|
8
|
+
|
|
9
|
+
sin = np.sin
|
|
10
|
+
cos = np.cos
|
|
11
|
+
exp = np.exp
|
|
12
|
+
I = 1j
|
|
13
|
+
|
|
14
|
+
def run_step7(i, job_control, dict_of_simulation, job_info):
|
|
15
|
+
project = dict_of_simulation['project']
|
|
16
|
+
work_dir = dict_of_simulation['work_dir']
|
|
17
|
+
caseid = job_control[i]['caseid'] # caseid = str(i)
|
|
18
|
+
case_dir = work_dir + '/' + project +"_"+ caseid
|
|
19
|
+
qc_dir,md_dir = get_folder_path(case_dir)
|
|
20
|
+
template_dir = dict_of_simulation['template_dir']
|
|
21
|
+
temperature = float(dict_of_simulation['MD_temperature'])
|
|
22
|
+
beta = 1. / (temperature * kT2au)
|
|
23
|
+
MD_dyn_state = dict_of_simulation['MD_traj_state']
|
|
24
|
+
|
|
25
|
+
sbmsym = np.loadtxt(case_dir+'/H_sys.dat')
|
|
26
|
+
sbmbath = np.loadtxt(work_dir+'/SBM'+MD_dyn_state+'CT.dat')
|
|
27
|
+
omega = sbmbath[:,1]
|
|
28
|
+
req = sbmbath[:,3]
|
|
29
|
+
print(req)
|
|
30
|
+
inttt = 12
|
|
31
|
+
points = 2**inttt
|
|
32
|
+
point2 = 2**(inttt-1)
|
|
33
|
+
# interval =
|
|
34
|
+
dt_tcf_sbm = 1 #$1 #0.5 # in au
|
|
35
|
+
dw_QM = 2. * np.pi / points / dt_tcf_sbm # in au
|
|
36
|
+
w_QM = np.fft.fftfreq(points)*points*dw_QM
|
|
37
|
+
t = np.arange(points) * dt_tcf_sbm
|
|
38
|
+
dt_au = t[1] - t[0]
|
|
39
|
+
Gamma_DA = sbmsym[0,1]
|
|
40
|
+
hw_DA = sbmsym[0,0] - sbmsym[1,1]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
print(dw_QM * au2eV, 'dw in eV')
|
|
44
|
+
print('hw DA/eV', hw_DA * au2eV, ' gamma_DA', Gamma_DA*au2eV, 'Er', np.sum(omega**2*req**2)/2.*au2eV)
|
|
45
|
+
print('QM ', ApproxRates(Ct_exact,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au, 'TeraHertz' )
|
|
46
|
+
print('W0 ', ApproxRates(Ct_W0,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au, 'TeraHertz' )
|
|
47
|
+
print('Marcus-Levitch rates ', MarcusLevichRate(omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au,'THz')
|
|
48
|
+
print('CAV ', ApproxRates(Ct_CAV,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au, 'TeraHertz' )
|
|
49
|
+
print('CD ', ApproxRates(Ct_CD,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au, 'TeraHertz' )
|
|
50
|
+
print('C0 ', ApproxRates(Ct_C0,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au, 'TeraHertz' )
|
|
51
|
+
print('Marcus Rate ', MarcusRate(omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au,'THz')
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
stroutput = ""
|
|
55
|
+
stroutput = stroutput + "\n\n STEP 7 FGR \n\n Spin Boson models for Various Linearized Semiclassical Rates \n "
|
|
56
|
+
stroutput = stroutput + 'QM ' +str( ApproxRates(Ct_exact,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12 ) + " Hz \n"
|
|
57
|
+
stroutput = stroutput + 'W0 ' +str( ApproxRates(Ct_W0,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12 ) + " Hz \n"
|
|
58
|
+
stroutput = stroutput + 'Marcus-Levitch rates ' +str( MarcusLevichRate(omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12) + " Hz \n"
|
|
59
|
+
stroutput = stroutput + 'CAV ' +str( ApproxRates(Ct_CAV,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12 ) + " Hz \n"
|
|
60
|
+
stroutput = stroutput + 'CD ' +str( ApproxRates(Ct_CD,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12 ) + " Hz \n"
|
|
61
|
+
stroutput = stroutput + 'C0 ' +str( ApproxRates(Ct_C0,omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12 ) + " Hz \n"
|
|
62
|
+
stroutput = stroutput + 'Marcus Rate ' +str( MarcusRate(omega,req,beta,t,hw_DA,Gamma_DA)*ps2au*dt_au*1e12) + " Hz \n"
|
|
63
|
+
stroutput = stroutput + '\n\n'
|
|
64
|
+
stroutput = stroutput + "#######################################################\n"
|
|
65
|
+
stroutput = stroutput + "\n\nJob Ends at" + time.ctime(time.time()) + "\n"
|
|
66
|
+
write_to_output(i, job_control, dict_of_simulation, stroutput)
|
|
67
|
+
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def ApproxRates(Ct,omega,req,beta,t,hw_DA,Gamma_DA):
|
|
72
|
+
CqmDA = Ct(omega,req,beta,t,hw_DA,Gamma_DA)
|
|
73
|
+
Cqm0 = Ct(omega,req,beta,t,0,Gamma_DA)
|
|
74
|
+
dt_tcf_sbm = t[1] - t[0]
|
|
75
|
+
# rateQM = (np.sum(CqmDA) - CqmDA[0]/2. - CqmDA[-1]/2. ) * dt_tcf_sbm
|
|
76
|
+
rateQM_approach1 = (np.sum(CqmDA) - 0.5*CqmDA[0] - 0*CqmDA[-1] ) * dt_tcf_sbm * 2
|
|
77
|
+
rateQM_approach2 = np.fft.ifft(CqmDA)[0] * len(t) * 2.
|
|
78
|
+
return np.array([rateQM_approach1.real,rateQM_approach2.real])
|
|
79
|
+
|
|
80
|
+
#############################################################
|
|
81
|
+
#
|
|
82
|
+
# Ref: J. Chem. Phys. 153, 044105 (2020)
|
|
83
|
+
# Eq (26) to Eq (30)
|
|
84
|
+
#
|
|
85
|
+
#############################################################
|
|
86
|
+
|
|
87
|
+
def Ct_exact(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
88
|
+
# all in a.u.
|
|
89
|
+
hbar = 1.
|
|
90
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
91
|
+
bhw2 = 0.5 * beta * hbar * omega
|
|
92
|
+
size = len(t)
|
|
93
|
+
Ct = np.zeros(size, dtype=complex)
|
|
94
|
+
for ind, w in enumerate(omega):
|
|
95
|
+
wt = w * t
|
|
96
|
+
Ct += shift[ind] * (coth(bhw2[ind])*(1 - cos(wt)) + I*sin(wt))
|
|
97
|
+
|
|
98
|
+
# print(np.shape(Ct),np.shape(omega_DA),np.shape(I))
|
|
99
|
+
Ct += I * omega_DA * t
|
|
100
|
+
Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
101
|
+
return Ct
|
|
102
|
+
|
|
103
|
+
def Ct_W0(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
104
|
+
# all in a.u.
|
|
105
|
+
hbar = 1.
|
|
106
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
107
|
+
bhw2 = 0.5 * beta * hbar * omega
|
|
108
|
+
size = len(t)
|
|
109
|
+
Ct = np.zeros(size, dtype=complex)
|
|
110
|
+
for ind, w in enumerate(omega):
|
|
111
|
+
wt = w * t
|
|
112
|
+
Ct += shift[ind] * (coth(bhw2[ind])*wt*wt/2. + I*wt)
|
|
113
|
+
|
|
114
|
+
# print(np.shape(Ct),np.shape(omega_DA),np.shape(I))
|
|
115
|
+
Ct += I * omega_DA * t
|
|
116
|
+
Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
117
|
+
return Ct
|
|
118
|
+
|
|
119
|
+
def MarcusLevichRate(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
120
|
+
# all in a.u.
|
|
121
|
+
hbar = 1.
|
|
122
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
123
|
+
bhw2 = 0.5 * beta * hbar * omega
|
|
124
|
+
size = len(t)
|
|
125
|
+
Ct = np.zeros(size, dtype=complex)
|
|
126
|
+
a = 0.25 * np.sum(omega * omega * omega * Req * Req / np.tanh(0.5 * beta * omega * hbar) )
|
|
127
|
+
print(a, 'a parameter')
|
|
128
|
+
pref = np.sqrt(np.pi/a)
|
|
129
|
+
|
|
130
|
+
Er = 0.5 * np.sum(omega**2*Req**2)
|
|
131
|
+
DeltaE = - hbar * omega_DA
|
|
132
|
+
return Gamma_DA**2 * pref * np.exp( - (Er+DeltaE)**2/4. / a )
|
|
133
|
+
#for ind, w in enumerate(omega):
|
|
134
|
+
# wt = w * t
|
|
135
|
+
# Ct += shift[ind] * (coth(bhw2[ind])*wt*wt*2 + I*sin(wt))
|
|
136
|
+
|
|
137
|
+
# print(np.shape(Ct),np.shape(omega_DA),np.shape(I))
|
|
138
|
+
#Ct += I * omega_DA * t
|
|
139
|
+
# Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
140
|
+
# return Ct
|
|
141
|
+
def MarcusRate(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
142
|
+
hbar = 1.
|
|
143
|
+
Er = np.sum(omega**2*Req**2*0.5)
|
|
144
|
+
U = Er - omega_DA * hbar
|
|
145
|
+
return Gamma_DA ** 2 * np.sqrt(np.pi*beta / Er) * np.exp( - U**2 * beta * 0.25 / Er)
|
|
146
|
+
|
|
147
|
+
def Ct_CAV(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
148
|
+
# all in a.u.
|
|
149
|
+
hbar = 1.
|
|
150
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
151
|
+
bhw2 = 0.5 * beta * hbar * omega
|
|
152
|
+
size = len(t)
|
|
153
|
+
Ct = np.zeros(size, dtype=complex)
|
|
154
|
+
for ind, w in enumerate(omega):
|
|
155
|
+
wt = w * t
|
|
156
|
+
Ct += shift[ind] * (( 1 / bhw2[ind] )*(1 - cos(wt)) + I*sin(wt))
|
|
157
|
+
Ct += I * t * omega_DA
|
|
158
|
+
Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
159
|
+
return Ct
|
|
160
|
+
|
|
161
|
+
def Ct_CD(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
162
|
+
# all in a.u.
|
|
163
|
+
hbar = 1.
|
|
164
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
165
|
+
bhw2 = 0.5 * beta * hbar * omega
|
|
166
|
+
size = len(t)
|
|
167
|
+
Ct = np.zeros(size, dtype=complex)
|
|
168
|
+
for ind, w in enumerate(omega):
|
|
169
|
+
wt = w * t
|
|
170
|
+
Ct += shift[ind] * (( 1 / bhw2[ind] )*(1 - cos(wt)) + I*wt)
|
|
171
|
+
Ct += I * t * omega_DA
|
|
172
|
+
Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
173
|
+
return Ct
|
|
174
|
+
|
|
175
|
+
def Ct_C0(omega,Req,beta,t,omega_DA,Gamma_DA):
|
|
176
|
+
# all in a.u.
|
|
177
|
+
hbar = 1.
|
|
178
|
+
shift = -omega * Req * Req / 2. / hbar
|
|
179
|
+
|
|
180
|
+
size = len(t)
|
|
181
|
+
Ct = np.zeros(size, dtype=complex)
|
|
182
|
+
for ind, w in enumerate(omega):
|
|
183
|
+
wt = w * t
|
|
184
|
+
wttbetahbar = w * t * t / beta / hbar
|
|
185
|
+
Ct += shift[ind] * ( wttbetahbar + I * wt)
|
|
186
|
+
Ct += I * t * omega_DA
|
|
187
|
+
Ct = Gamma_DA * Gamma_DA * np.exp(Ct)
|
|
188
|
+
return Ct
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
import pickle
|
|
193
|
+
|
|
194
|
+
def main_FGR():
|
|
195
|
+
dict_of_simulation = parse_input()
|
|
196
|
+
# prepare for quantum chemistry simulation
|
|
197
|
+
work_dir = dict_of_simulation['work_dir']
|
|
198
|
+
# where we have the structure directory
|
|
199
|
+
structure_dir = dict_of_simulation['structure_dir']
|
|
200
|
+
# load the project folder
|
|
201
|
+
project = dict_of_simulation['project']
|
|
202
|
+
# get case id for the simulation
|
|
203
|
+
caseid = dict_of_simulation['caseid']
|
|
204
|
+
# get job list
|
|
205
|
+
case_id_list = separate_idlist(caseid)
|
|
206
|
+
# get list of job control token
|
|
207
|
+
job_control = init_job_control(case_id_list)
|
|
208
|
+
|
|
209
|
+
# job_info = init_job_info(case_id_list)
|
|
210
|
+
startime = time.time ()
|
|
211
|
+
|
|
212
|
+
# Read list to memory
|
|
213
|
+
def read_list():
|
|
214
|
+
# for reading also binary mode is important
|
|
215
|
+
with open(work_dir+'/listfile', 'rb') as fp:
|
|
216
|
+
n_list = pickle.load(fp)
|
|
217
|
+
return n_list
|
|
218
|
+
|
|
219
|
+
def write_list(a_list):
|
|
220
|
+
# store list in binary file so 'wb' mode
|
|
221
|
+
with open(work_dir+'/listfile', 'wb') as fp:
|
|
222
|
+
pickle.dump(a_list, fp)
|
|
223
|
+
print('Done writing list into a binary file')
|
|
224
|
+
|
|
225
|
+
job_info = read_list()
|
|
226
|
+
print("SubmitQC begins at "+str(startime))
|
|
227
|
+
# print("Input parameters ")
|
|
228
|
+
# print(simulation_parameter)
|
|
229
|
+
for ind, ctr_ele in enumerate(job_control):
|
|
230
|
+
print(ind, job_control)
|
|
231
|
+
run_step7(ind, job_control, dict_of_simulation,job_info)
|
|
232
|
+
|
|
233
|
+
write_list(job_info)
|
|
234
|
+
end_time = time.time ()
|
|
235
|
+
print("SubmitQC ends at "+str(end_time))
|
|
236
|
+
|
|
237
|
+
if __name__ == "__main__":
|
|
238
|
+
main_FGR()
|
pyctramer/JobControl.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from .SubmitQC import run_step1
|
|
2
|
+
from .AnalyzeQC import run_step2
|
|
3
|
+
from .ConstructFF import run_step3
|
|
4
|
+
from .RunMD import run_step4
|
|
5
|
+
from .MarcusAA import run_step5
|
|
6
|
+
from .SpinBoson import run_step6
|
|
7
|
+
from .FGR import run_step7
|
|
8
|
+
from .Utilities import *
|
|
9
|
+
|
|
10
|
+
def run_Marcus(dict_of_simulation):
|
|
11
|
+
# prepare for quantum chemistry simulation
|
|
12
|
+
work_dir = dict_of_simulation['work_dir']
|
|
13
|
+
# where we have the structure directory
|
|
14
|
+
structure_dir = dict_of_simulation['structure_dir']
|
|
15
|
+
# load the project folder
|
|
16
|
+
project = dict_of_simulation['project']
|
|
17
|
+
# get case id for the simulation
|
|
18
|
+
caseid = dict_of_simulation['caseid']
|
|
19
|
+
# get job list
|
|
20
|
+
case_id_list = separate_idlist(caseid)
|
|
21
|
+
# get list of job control token
|
|
22
|
+
job_control = init_job_control(case_id_list)
|
|
23
|
+
print(job_control)
|
|
24
|
+
# job infomation
|
|
25
|
+
job_info = init_job_info(case_id_list)
|
|
26
|
+
count = 0
|
|
27
|
+
while check_job_unfinished(job_control):
|
|
28
|
+
count +=1
|
|
29
|
+
job_control = check_job_status(job_control, dict_of_simulation, job_info)
|
|
30
|
+
if count % 300 ==0:
|
|
31
|
+
print(count,job_control)
|
|
32
|
+
time.sleep(1)
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def run_FGR(dict_of_simulation):
|
|
36
|
+
# prepare for quantum chemistry simulation
|
|
37
|
+
work_dir = dict_of_simulation['work_dir']
|
|
38
|
+
# where we have the structure directory
|
|
39
|
+
structure_dir = dict_of_simulation['structure_dir']
|
|
40
|
+
# load the project folder
|
|
41
|
+
project = dict_of_simulation['project']
|
|
42
|
+
# get case id for the simulation
|
|
43
|
+
caseid = dict_of_simulation['caseid']
|
|
44
|
+
# get job list
|
|
45
|
+
case_id_list = separate_idlist(caseid)
|
|
46
|
+
# get list of job control token
|
|
47
|
+
job_control = init_job_control(case_id_list)
|
|
48
|
+
print(job_control)
|
|
49
|
+
# job infomation
|
|
50
|
+
job_info = init_job_info(case_id_list)
|
|
51
|
+
count = 6
|
|
52
|
+
while check_job_unfinished(job_control):
|
|
53
|
+
count +=1
|
|
54
|
+
job_control = check_job_status(job_control, dict_of_simulation, job_info)
|
|
55
|
+
if count % 300 ==0:
|
|
56
|
+
print(count,job_control)
|
|
57
|
+
time.sleep(1)
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
def check_job_status(job_control, dict_of_simulation, job_info):
|
|
61
|
+
for i in range(len(job_control)):
|
|
62
|
+
curr_step = job_control[i]['status'][0]
|
|
63
|
+
if curr_step == 0 and job_control[i]['status'][curr_step+1] == 'unstarted':
|
|
64
|
+
if dict_of_simulation['skip_QC']=='True':
|
|
65
|
+
curr_step = 1
|
|
66
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
67
|
+
else:
|
|
68
|
+
job_control = run_step1(i,job_control,dict_of_simulation)
|
|
69
|
+
curr_step = 1
|
|
70
|
+
job_control[i]['status'][curr_step] = 'running'
|
|
71
|
+
print('curr_step',curr_step,'if current finished yet?',check_slurm_status(job_control[i]['QC_jobids']), '\n Current step is', job_control[i]['status'][curr_step])
|
|
72
|
+
|
|
73
|
+
if curr_step == 1 and job_control[i]['status'][curr_step] == 'running':
|
|
74
|
+
if check_slurm_status(job_control[i]['QC_jobids']):
|
|
75
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
76
|
+
#pass
|
|
77
|
+
else:
|
|
78
|
+
pass
|
|
79
|
+
#job_control[i]['status'][curr_step] = 'finished'
|
|
80
|
+
if dict_of_simulation['skip_QC']=='True':
|
|
81
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
82
|
+
else:
|
|
83
|
+
pass
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if curr_step == 1 and job_control[i]['status'][curr_step] == 'finished':
|
|
87
|
+
job_control = run_step2(i,job_control,dict_of_simulation)
|
|
88
|
+
curr_step = 2
|
|
89
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
90
|
+
|
|
91
|
+
if curr_step == 2 and job_control[i]['status'][curr_step] == 'finished':
|
|
92
|
+
job_control = run_step3(i,job_control,dict_of_simulation, job_info)
|
|
93
|
+
curr_step = 3
|
|
94
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
95
|
+
|
|
96
|
+
if curr_step == 3 and job_control[i]['status'][curr_step] == 'finished':
|
|
97
|
+
job_control = run_step4(i,job_control,dict_of_simulation)
|
|
98
|
+
curr_step = 4
|
|
99
|
+
job_control[i]['status'][curr_step] = 'running'
|
|
100
|
+
|
|
101
|
+
if curr_step == 4 and job_control[i]['status'][curr_step] == 'running':
|
|
102
|
+
if check_slurm_status(job_control[i]['MD_jobids']):
|
|
103
|
+
print("job_control[i]['MD_jobids']",job_control[i]['MD_jobids'])
|
|
104
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
105
|
+
else: # returning false and doing nothing in this step
|
|
106
|
+
#if round(time.time()) % 30 == 0:
|
|
107
|
+
print("MD_jobids",job_control[i]['MD_jobids'] )
|
|
108
|
+
pass
|
|
109
|
+
#else :
|
|
110
|
+
# pass
|
|
111
|
+
#pass
|
|
112
|
+
|
|
113
|
+
if curr_step == 4 and job_control[i]['status'][curr_step] == 'finished':
|
|
114
|
+
job_control = run_step5(i,job_control,dict_of_simulation,job_info)
|
|
115
|
+
curr_step = 5
|
|
116
|
+
job_control[i]['status'][curr_step] = 'finished'
|
|
117
|
+
|
|
118
|
+
job_control[i]['status'][0] = curr_step
|
|
119
|
+
|
|
120
|
+
return job_control
|
pyctramer/MarcusAA.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from .Utilities import *
|
|
4
|
+
|
|
5
|
+
#MARCUS All ATOM
|
|
6
|
+
def run_step5(i, job_control, dict_of_simulation,job_info):
|
|
7
|
+
project = dict_of_simulation['project']
|
|
8
|
+
work_dir = dict_of_simulation['work_dir']
|
|
9
|
+
caseid = job_control[i]['caseid'] # caseid = str(i)
|
|
10
|
+
case_dir = work_dir + '/' + project +"_"+ caseid
|
|
11
|
+
qc_dir,md_dir = get_folder_path(case_dir)
|
|
12
|
+
MD_dyn_state = dict_of_simulation['MD_traj_state']
|
|
13
|
+
Ene_list = job_info[i]['Ene_list']
|
|
14
|
+
State_list = job_info[i]['State_list']
|
|
15
|
+
coupling_list = job_info[i]['coupling_list']
|
|
16
|
+
system_name = project +"_"+ caseid
|
|
17
|
+
MD_temperature = dict_of_simulation["MD_temperature"]
|
|
18
|
+
temperature = float(MD_temperature)
|
|
19
|
+
charge_list = []
|
|
20
|
+
for info in job_info:
|
|
21
|
+
for state_name in info['State_list']:
|
|
22
|
+
charge_list.append(state_name)
|
|
23
|
+
# charge_list = ['PI','CT1','CT2','GR']
|
|
24
|
+
# job_info[i][]
|
|
25
|
+
|
|
26
|
+
print("md dir ", md_dir)
|
|
27
|
+
# Trajectory dir
|
|
28
|
+
traj_dir = md_dir + '/Traj_' + MD_dyn_state
|
|
29
|
+
print(traj_dir)
|
|
30
|
+
# get correction for Er
|
|
31
|
+
Correction = get_energy_correction(traj_dir,charge_list,Ene_list)
|
|
32
|
+
print("Correction ", Correction)
|
|
33
|
+
|
|
34
|
+
Coupling_list, rates, transitions_names, Er_all, dE_all = returnMarcusRate(traj_dir, MD_dyn_state,coupling_list, Correction, charge_list,temperature, system_name, ensemble='NVE')
|
|
35
|
+
print("Marcus rate ", rates)
|
|
36
|
+
f = open(case_dir + '/'+project+'_'+caseid+'ctramer.out', 'w+')
|
|
37
|
+
#result = {'GR': 0, 'PI': pi_state, 'CT1':CT1_state, 'CT2': CT2_state}
|
|
38
|
+
#energies =[0, PI_energy,CT1_energy, CT2_energy] # list of energy in eV
|
|
39
|
+
for ene in Ene_list:
|
|
40
|
+
f.write('Excited state order '+ str(ene)+'\n')
|
|
41
|
+
f.write("\n")
|
|
42
|
+
|
|
43
|
+
for ind,state in enumerate(charge_list):
|
|
44
|
+
f.write(state+' '+str(Ene_list[ind])+'\n')
|
|
45
|
+
|
|
46
|
+
f.write("\n")
|
|
47
|
+
|
|
48
|
+
f.write('Excited state energies in eV \n')
|
|
49
|
+
for ind, name in enumerate(charge_list):
|
|
50
|
+
f.write("Excited energy of the state "+name+' is '+ str(Ene_list[ind]) + ' eV. \n' )
|
|
51
|
+
f.write("\n")
|
|
52
|
+
|
|
53
|
+
#names = ['PI-CT1','PI-CT2','CT1-CT2','CT1-PI','CT2-PI','CT2-CT1']
|
|
54
|
+
#inds = [[1,2],[1,3],[2,3],[2,1],[3,1],[3,2]]
|
|
55
|
+
|
|
56
|
+
#Coupling_list = Coupling_list[3:]
|
|
57
|
+
#Coupling_list = [coupling_list[2][0],coupling_list[4][0],coupling_list[5][0]]
|
|
58
|
+
f.write('diabatic coupling in eV ')
|
|
59
|
+
for ind, coupling in enumerate(Coupling_list):
|
|
60
|
+
f.write ('Coupling between transition of '+transitions_names[ind] + ' is ' + str(coupling) + ' eV. \n ')
|
|
61
|
+
|
|
62
|
+
f.write('Rates in Hz ')
|
|
63
|
+
for ind, rate in enumerate(rates):
|
|
64
|
+
f.write ('Marcus rates at 300K between transition of '+transitions_names[ind] + ' is ' + str(rate/1e12) + ' THz. \n ')
|
|
65
|
+
f.close()
|
|
66
|
+
|
|
67
|
+
job_info[i]['transitions_names'] = transitions_names
|
|
68
|
+
job_info[i]['transitions_rates'] = rates
|
|
69
|
+
job_info[i]['Correction'] = Correction
|
|
70
|
+
job_info[i]['Coupling_list'] = Coupling_list
|
|
71
|
+
|
|
72
|
+
indmax = rates.index(max(rates))
|
|
73
|
+
namemax = transitions_names[indmax]
|
|
74
|
+
namemax = namemax.split("-")
|
|
75
|
+
cpmax = Coupling_list[indmax]
|
|
76
|
+
correctmax = -Correction['CT'+str(indmax+1)] + Correction['LE']
|
|
77
|
+
ratemax = rates[indmax]
|
|
78
|
+
max_indpair = [1,2+indmax]
|
|
79
|
+
|
|
80
|
+
job_info[i]['namemax'] = namemax
|
|
81
|
+
job_info[i]['cpmax'] = cpmax
|
|
82
|
+
job_info[i]['ratemax'] = ratemax
|
|
83
|
+
job_info[i]['correctmax'] = correctmax
|
|
84
|
+
job_info[i]['max_indpair'] = max_indpair
|
|
85
|
+
|
|
86
|
+
H_sys = np.array([[1.0,0],[0,1.0]])
|
|
87
|
+
H_sys[0][1] = H_sys[1][0] = cpmax * eV2au
|
|
88
|
+
H_sys[0][0] = 0.
|
|
89
|
+
H_sys[1][1] = dE_all[indmax] * eV2au
|
|
90
|
+
print("H_sys \n", H_sys)
|
|
91
|
+
np.savetxt(case_dir+'/H_sys.dat' ,H_sys)
|
|
92
|
+
|
|
93
|
+
stroutput = "\n"
|
|
94
|
+
stroutput = stroutput + "STEP 5: MarcusAA \n\n"
|
|
95
|
+
# stroutput
|
|
96
|
+
stroutput = stroutput + ">>>> Marcus Rates Summary \n"
|
|
97
|
+
stroutput = stroutput + "index,Excited State (eV),Correction (eV),Coupling (eV),Er (eV),DeltaE (eV),all-atom Marcus rates (Hz)\n"
|
|
98
|
+
for ind, name in enumerate(State_list):
|
|
99
|
+
if ind > 1:
|
|
100
|
+
stroutput = stroutput + name + "," + str(Ene_list[ind]) +"," + str(Correction[ind-1]) + "," + Coupling_list[ind-1] + "," + str(Er_all[ind-1]) + "," + str(dE_all[ind-1]) + "," + str(rates[ind-1]) + "\n"
|
|
101
|
+
stroutput = stroutput + "\n"
|
|
102
|
+
|
|
103
|
+
stroutput = stroutput + ">>> Target Transition \n"
|
|
104
|
+
stroutput = stroutput + "Transition: " + namemax + "\n"
|
|
105
|
+
stroutput = stroutput + "system Hamiltonian \n "
|
|
106
|
+
for i in range(H_sys):
|
|
107
|
+
for j in range(H_sys):
|
|
108
|
+
stroutput = stroutput + str(H_sys[i][j]) + " "
|
|
109
|
+
stroutput = stroutput + "\n"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
stroutput = stroutput + "Rate: " + str(ratemax) + "Hz \n"
|
|
113
|
+
|
|
114
|
+
stroutput = stroutput + "Correction: " + str(correctmax) + " eV \n"
|
|
115
|
+
stroutput = stroutput + "DeltaE: " + str(dE_all[indmax]) + " eV \n"
|
|
116
|
+
stroutput = stroutput + "E_ex: " + str(Ene_list[indmax]-1) + " eV \n"
|
|
117
|
+
stroutput = stroutput + "Couplings : " + cpmax + "eV \n"
|
|
118
|
+
stroutput = stroutput + "Er: " + str(Er_all[indmax]) + " eV \n"
|
|
119
|
+
|
|
120
|
+
stroutput = stroutput + '\n\n'
|
|
121
|
+
stroutput = stroutput + "#######################################################\n"
|
|
122
|
+
write_to_output(i, job_control, dict_of_simulation, stroutput)
|
|
123
|
+
return job_control
|
|
124
|
+
|
|
125
|
+
def get_energy_correction(filedir,charge_list,ex_energy_list):
|
|
126
|
+
"""
|
|
127
|
+
This functions extract energy correction for replacting solute energy obtained from MD
|
|
128
|
+
with the value obtained from quantum chemistry calculation
|
|
129
|
+
|
|
130
|
+
filename for MD energy in gas is assumed to be energy_gas_[STATE]_TRAJ_NVT.dat in kcal/mol
|
|
131
|
+
reported energy_correction dictionary is in eV.
|
|
132
|
+
"""
|
|
133
|
+
kcalmol2eV= 0.0433634 #0.0433634
|
|
134
|
+
energy_corr_tmp = []
|
|
135
|
+
energy_corr = {} # Uxg
|
|
136
|
+
final_energy_corr = {}
|
|
137
|
+
|
|
138
|
+
for ind, i in enumerate (charge_list):
|
|
139
|
+
filename = f'{filedir}/energy_gas_' + i + '_TRAJ_NVT.dat'
|
|
140
|
+
test_file = pd.read_table(filename,header=None)
|
|
141
|
+
energy_in_ev = test_file[0][0] * kcalmol2eV
|
|
142
|
+
energy_corr_tmp.append(energy_in_ev)
|
|
143
|
+
energy_corr[i] = energy_in_ev - energy_corr_tmp[0]
|
|
144
|
+
final_energy_corr[i] = ex_energy_list[ind] - energy_corr[i]
|
|
145
|
+
|
|
146
|
+
# getting energy gap between excited state and ground (energy_corr_tmp[0]) as obtained from MD
|
|
147
|
+
|
|
148
|
+
#energy_corr = {'GR' :energy_corr_tmp[0] - energy_corr_tmp[0],
|
|
149
|
+
# 'PI':energy_corr_tmp[1] - energy_corr_tmp[0] ,
|
|
150
|
+
# 'CT1':energy_corr_tmp[2] - energy_corr_tmp[0] ,
|
|
151
|
+
# 'CT2':energy_corr_tmp[3] - energy_corr_tmp[0] }
|
|
152
|
+
print("MD_solute energies : ", energy_corr)
|
|
153
|
+
print("exe pot: ", ex_energy_list)
|
|
154
|
+
# substracting the excitation energy obtained using MD from the energy calculated by QChem
|
|
155
|
+
#final_energy_corr = {'GR' :ex_energy_list[0] - energy_corr['GR'],
|
|
156
|
+
# 'PI':ex_energy_list[1] - energy_corr['PI'],
|
|
157
|
+
# 'CT1':ex_energy_list[2] - energy_corr['CT1'],
|
|
158
|
+
# 'CT2':ex_energy_list[3] - energy_corr['CT2']}
|
|
159
|
+
|
|
160
|
+
return final_energy_corr
|
|
161
|
+
|
|
162
|
+
def calc_k_marcus(DeltaE, Er, Gamma, T):
|
|
163
|
+
"""calculate charge transfer rate constant based on marcus theory.
|
|
164
|
+
|
|
165
|
+
Parameters:
|
|
166
|
+
------------
|
|
167
|
+
Ea :
|
|
168
|
+
Er :
|
|
169
|
+
Gamma :
|
|
170
|
+
|
|
171
|
+
return:
|
|
172
|
+
------------
|
|
173
|
+
k_M
|
|
174
|
+
|
|
175
|
+
"""
|
|
176
|
+
h = 1 * 4.135667696e-15 # h value in eV s
|
|
177
|
+
# note that hbar = h * 2 * PI
|
|
178
|
+
pi = np.pi
|
|
179
|
+
kb = 8.617333262e-5
|
|
180
|
+
# T = 300 # in kelvin
|
|
181
|
+
|
|
182
|
+
#h = 4.135667696...×10−15 eV⋅Hz−1
|
|
183
|
+
term1 = ( 2 * pi * abs(Gamma)**2 / h )
|
|
184
|
+
#term1 = abs(Gamma)**2/h
|
|
185
|
+
term2 = np.sqrt(pi /(kb * T * Er) )
|
|
186
|
+
term3 = np.exp(- (DeltaE + Er)**2 / (4 * kb * T * Er))
|
|
187
|
+
# print(term1,term2,term1*term2,term3)
|
|
188
|
+
k_M = term1 * term2 * term3
|
|
189
|
+
|
|
190
|
+
return k_M
|
|
191
|
+
|
|
192
|
+
def returnMarcusRate(traj_dir, MD_traj_state, Coupling_list, correction, state_list, temperature,system_name, ensemble='NVE'):
|
|
193
|
+
Ene_list = []
|
|
194
|
+
for name in correction:
|
|
195
|
+
Ene = np.loadtxt(traj_dir+'/'+system_name+'_E_'+name+"_TRAJ_"+MD_traj_state+'_'+ensemble+'.dat')
|
|
196
|
+
Ene *= 0.0433634 # kcal per mol to eV
|
|
197
|
+
Ene_list .append(Ene.copy() + correction[name])
|
|
198
|
+
# print(len(Ene_list))
|
|
199
|
+
# print(name, Ene_list)
|
|
200
|
+
kb = 8.617333262e-5
|
|
201
|
+
T = temperature # 300 Kelvin
|
|
202
|
+
rates_list = []
|
|
203
|
+
|
|
204
|
+
transition_pair = []
|
|
205
|
+
transition_indx = []
|
|
206
|
+
for ind, name in enumerate(state_list):
|
|
207
|
+
if ind > 1:
|
|
208
|
+
transition = state_list[1] + "-" + name
|
|
209
|
+
transition_pair.append(transition)
|
|
210
|
+
transition_indx.append([1,ind])
|
|
211
|
+
|
|
212
|
+
coupling_list = []
|
|
213
|
+
coup_util_list = []
|
|
214
|
+
cp_count = 0
|
|
215
|
+
# print(Coupling_list, "cplst")
|
|
216
|
+
for i in range(len(state_list)):
|
|
217
|
+
for j in range(len(state_list)):
|
|
218
|
+
|
|
219
|
+
if i > j:
|
|
220
|
+
#print(i,j)
|
|
221
|
+
#print(cp_count)
|
|
222
|
+
if j == 1:
|
|
223
|
+
coupling_list.append(Coupling_list[cp_count][0]) # cp_count)
|
|
224
|
+
coup_util_list.append(cp_count)
|
|
225
|
+
# print(Coupling_list[cp_count][0])
|
|
226
|
+
cp_count +=1
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
#print("Coupling_list", Coupling_list,'\n couplist ', coupling_list)
|
|
230
|
+
inds = transition_indx
|
|
231
|
+
#print(len(inds),'inds')
|
|
232
|
+
#print((2 * kb * T))
|
|
233
|
+
Er_list = []
|
|
234
|
+
dE_list = []
|
|
235
|
+
for ind, coupling in enumerate(coupling_list):
|
|
236
|
+
energy_gap = Ene_list[inds[ind][0] ] - Ene_list[inds[ind][1]]
|
|
237
|
+
U = np.average(energy_gap) # <U>
|
|
238
|
+
|
|
239
|
+
Er = np.std(energy_gap) * np.std(energy_gap) / (2 * kb * T)
|
|
240
|
+
dE = - U - Er
|
|
241
|
+
rates_list.append(calc_k_marcus(dE,Er,coupling_list[ind], T) )
|
|
242
|
+
Er_list . append(Er)
|
|
243
|
+
dE_list . append(dE)
|
|
244
|
+
print("dE ",dE, ", Er ",Er, ", coupling ", coupling_list[ind])
|
|
245
|
+
print(rates_list[ind], ' is rate of the transition ' + transition_pair[ind])
|
|
246
|
+
# max(rates_list)
|
|
247
|
+
return coupling_list, rates_list, transition_pair, Er_list, dE_list
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
import pickle
|
|
252
|
+
def main_MarcusAA():
|
|
253
|
+
dict_of_simulation = parse_input()
|
|
254
|
+
# prepare for quantum chemistry simulation
|
|
255
|
+
work_dir = dict_of_simulation['work_dir']
|
|
256
|
+
# where we have the structure directory
|
|
257
|
+
structure_dir = dict_of_simulation['structure_dir']
|
|
258
|
+
# load the project folder
|
|
259
|
+
project = dict_of_simulation['project']
|
|
260
|
+
# get case id for the simulation
|
|
261
|
+
caseid = dict_of_simulation['caseid']
|
|
262
|
+
# get job list
|
|
263
|
+
case_id_list = separate_idlist(caseid)
|
|
264
|
+
# get list of job control token
|
|
265
|
+
job_control = init_job_control(case_id_list)
|
|
266
|
+
|
|
267
|
+
# job_info = init_job_info(case_id_list)
|
|
268
|
+
startime = time.time ()
|
|
269
|
+
|
|
270
|
+
# Read list to memory
|
|
271
|
+
def read_list():
|
|
272
|
+
# for reading also binary mode is important
|
|
273
|
+
with open(work_dir+'/listfile', 'rb') as fp:
|
|
274
|
+
n_list = pickle.load(fp)
|
|
275
|
+
return n_list
|
|
276
|
+
|
|
277
|
+
def write_list(a_list):
|
|
278
|
+
# store list in binary file so 'wb' mode
|
|
279
|
+
with open(work_dir+'/listfile', 'wb') as fp:
|
|
280
|
+
pickle.dump(a_list, fp)
|
|
281
|
+
print('Done writing list into a binary file')
|
|
282
|
+
|
|
283
|
+
job_info = read_list()
|
|
284
|
+
print("SubmitQC begins at "+str(startime))
|
|
285
|
+
# print("Input parameters ")
|
|
286
|
+
# print(simulation_parameter)
|
|
287
|
+
for ind, ctr_ele in enumerate(job_control):
|
|
288
|
+
print(ind, job_control)
|
|
289
|
+
run_step5(ind, job_control, dict_of_simulation,job_info)
|
|
290
|
+
|
|
291
|
+
write_list(job_info)
|
|
292
|
+
end_time = time.time ()
|
|
293
|
+
print("SubmitQC ends at "+str(end_time))
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
if __name__ == "__main__":
|
|
297
|
+
main_MarcusAA()
|