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/PyCTRAMER.py ADDED
@@ -0,0 +1,73 @@
1
+ # PyCTRAMER
2
+ #standard library import
3
+ import numpy as np
4
+ import pandas as pd
5
+ import sys
6
+
7
+ import tempfile
8
+ import parmed
9
+ from mdtraj.reporters import HDF5Reporter
10
+
11
+ import math
12
+ import os
13
+ import re
14
+ import shutil
15
+ from shutil import copyfile
16
+ import tempfile
17
+ import json
18
+ import pickle as pkl
19
+ import matplotlib
20
+ import matplotlib.pyplot as plt
21
+
22
+ import mdtraj as md
23
+ import argparse
24
+ import fileinput
25
+ import time
26
+
27
+ # SubmitQC
28
+ from .JobControl import *
29
+ from .Utilities import *
30
+
31
+
32
+ def simulate(input) :
33
+ simulation_parameter = parse_input_for_jupyter(input)
34
+ startime = time.time()
35
+ print("simulation begins at "+ time.ctime(startime) )
36
+ print("Input parameters ")
37
+ print(simulation_parameter)
38
+ run_simulation(simulation_parameter)
39
+ end_time = time.time()
40
+ print("simulation ends at "+ time.ctime(end_time) )
41
+ timecosu = end_time - startime
42
+ hour = timecosu // 3600
43
+ minute = (timecosu - hour * 3600) // 60
44
+ second = timecosu - 3600 * hour - 60 * minute
45
+ print("Computational time "+ str(hour) + " hour " + str(minute) + " minutes " + second + " second " )
46
+ return 0
47
+
48
+ def main() :
49
+ simulation_parameter = parse_input()
50
+ startime = time.time
51
+ print("simulation begins at "+str(startime ))
52
+ print("Input parameters ")
53
+ print(simulation_parameter)
54
+ run_simulation(simulation_parameter)
55
+ end_time = time.time
56
+ print("simulation ends at "+str(end_time ))
57
+ return 0
58
+
59
+ def run_simulation(dict_of_simulation):
60
+ if dict_of_simulation['workflow'] == 'Marcus':
61
+ run_Marcus(dict_of_simulation)
62
+ elif dict_of_simulation['workflow'] == 'FGR':
63
+ run_FGR(dict_of_simulation)
64
+ elif dict_of_simulation['workflow'] == 'alltheway':
65
+ run_Marcus(dict_of_simulation)
66
+ run_FGR(dict_of_simulation)
67
+ # OR define a run_all_the_way(dict_of_simulation)
68
+ else :
69
+ return 'Not defined yet'
70
+ #if __name__ == "__main__":
71
+ # main();
72
+
73
+
pyctramer/RunMD.py ADDED
@@ -0,0 +1,313 @@
1
+ from .Utilities import *
2
+ from shutil import copyfile
3
+
4
+ def run_step4(i, job_control, dict_of_simulation, job_info):
5
+ project = dict_of_simulation['project']
6
+ work_dir = dict_of_simulation['work_dir']
7
+ caseid = job_control[i]['caseid'] #caseid = str(i)
8
+ case_dir = work_dir + '/' + project +"_"+ caseid
9
+ qc_dir,md_dir = get_folder_path(case_dir)
10
+ template_dir = dict_of_simulation['template_dir']
11
+ #
12
+ platform = 'cpu'
13
+ jobtype = 'minimization'
14
+ total_traj= dict_of_simulation['N_traj']
15
+ PARM = ''
16
+ MD_dyn_state = dict_of_simulation['MD_traj_state']
17
+ MD_Donor = dict_of_simulation['MD_traj_state']
18
+ inp_dir = md_dir # dict_of_simulation['template_dir']
19
+ Solvent = dict_of_simulation['solvent_resname']
20
+ MD_dt = dict_of_simulation['MD_dt']
21
+ sample_steps = dict_of_simulation['sample_steps']
22
+ MD_temperature = dict_of_simulation["MD_temperature"]
23
+ MD_steps = dict_of_simulation["MD_steps"]
24
+
25
+ generate_MDinp(template_dir, MD_dt, MD_steps, sample_steps, MD_temperature, md_dir)
26
+
27
+ state_list_str = "'"
28
+ for info in job_info:
29
+ for state_name in info['State_list']:
30
+ state_list_str = state_list_str + state_name + ' '
31
+ state_list_str = state_list_str + "'"
32
+
33
+
34
+ jobs = []
35
+ newline = ''
36
+
37
+ jobtype = 'minimization'
38
+ platform = 'cpu'
39
+ returning_info = setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir, platform,
40
+ jobtype, project, caseid, total_traj, PARM, MD_dyn_state, MD_Donor,
41
+ Solvent, state_list_str,
42
+ continue_from=0, dependency=newline)#@newline)
43
+ print(returning_info)
44
+
45
+ if len(jobs) == 0:
46
+ dependency_at_this_step = ''
47
+ else:
48
+ dependency_at_this_step = list_to_dep_line(jobs)
49
+ find_job_id(returning_info, jobs)
50
+ dependency_at_this_step = list_to_dep_line(jobs)
51
+
52
+ jobtype = 'heat_equil_run'
53
+ platform = 'gpu'
54
+ returning_info = setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir,
55
+ platform, jobtype, project, caseid, total_traj, PARM,
56
+ MD_dyn_state, MD_Donor, Solvent,state_list_str,
57
+ continue_from=0, dependency=dependency_at_this_step) #newline)
58
+ print(returning_info)
59
+ find_job_id(returning_info, jobs)
60
+ dependency_at_this_step = list_to_dep_line(jobs)
61
+
62
+ jobtype='recalculate'
63
+ platform = 'cpu'
64
+ returning_info = setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir, platform,
65
+ jobtype, project, caseid, total_traj, PARM, MD_dyn_state,
66
+ MD_Donor, Solvent, state_list_str,
67
+ continue_from=0, dependency=dependency_at_this_step) #newline)
68
+ print(returning_info)
69
+ find_job_id(returning_info, jobs)
70
+ dependency_at_this_step = list_to_dep_line(jobs)
71
+ print(dependency_at_this_step, jobs)
72
+
73
+ # jobtype = 'energy_analysis'
74
+ jobtype = 'strip_solvent'
75
+ returning_info = setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir,
76
+ platform, jobtype, project, caseid, total_traj,
77
+ PARM, MD_dyn_state, MD_Donor, Solvent,
78
+ state_list_str, continue_from=0, dependency=dependency_at_this_step)#newline)
79
+ print(returning_info)
80
+ find_job_id(returning_info, jobs)
81
+ dependency_at_this_step = list_to_dep_line(jobs)
82
+
83
+ job_control[i]['MD_jobids'] = dependency_at_this_step
84
+
85
+ # jobtype = 'strip_solvent'
86
+ jobtype = 'energy_analysis'
87
+ returning_info = setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir, platform, jobtype, project, caseid,
88
+ total_traj, PARM, MD_dyn_state, MD_Donor, Solvent,
89
+ state_list_str,
90
+ continue_from=0, dependency=dependency_at_this_step)
91
+
92
+ find_job_id(returning_info, jobs)
93
+ stroutput = "\n\n"
94
+ stroutput = stroutput + "STEP 4: RunMD\n"
95
+ stroutput = stroutput + "Input: " + md_dir + "\n"
96
+ stroutput = stroutput + " " + md_dir + "/*.in\n"
97
+ stroutput = stroutput + "Job submit script: " + md_dir + "cpujob_control.slurm\n"
98
+ stroutput = stroutput + " " + md_dir + "gpujob_control.slurm\n"
99
+ stroutput = stroutput + " " + md_dir + "master_control.slurm\n"
100
+ stroutput = stroutput + " " + md_dir + "master_control.slurm\n"
101
+ stroutput = stroutput + "Output: " + md_dir + "\n"
102
+ stroutput = stroutput + " " + md_dir + "/Traj_"+ MD_dyn_state + "/*.out \n"
103
+
104
+
105
+ stroutput = stroutput + "<<<< Computational Details \n"
106
+
107
+ stroutput = stroutput + 'N_traj:' + total_traj + '\n'
108
+ stroutput = stroutput + 'MD_traj_state:' + MD_dyn_state + '\n'
109
+ stroutput = stroutput + 'solvent_resname:' + Solvent + '\n'
110
+ stroutput = stroutput + 'MD_dt:' + MD_dt + '\n'
111
+ stroutput = stroutput + 'sample_steps:' + sample_steps + '\n'
112
+ stroutput = stroutput + "MD_temperature:" + MD_temperature + '\n'
113
+ stroutput = stroutput + "MD_steps:" + MD_steps + '\n'
114
+ stroutput = stroutput + '\n\n'
115
+ stroutput = stroutput + "#######################################################\n"
116
+ write_to_output(i, job_control, dict_of_simulation, stroutput)
117
+
118
+ return job_control
119
+
120
+
121
+ def setup_MD_master_control(template_dir, qc_dir, md_dir, inp_dir, platform, jobtype, case, testing_string,
122
+ total_traj, PARM, MD_dyn_state, MD_Donor, Solvent,state_list, continue_from=0,dependency=''):
123
+ """
124
+ # submitQC(template_dir,running_dir,QCmethod,basis_set,testing_str,Drange,Arange,N_cis,case,basedir):
125
+
126
+ To setup a master control for the ctramer MD job.
127
+
128
+ template_dir : is slurm template directory where the master_control_template.sh and master_control.sh are located.
129
+
130
+ project_dir = main project data directory ,
131
+ the quantum chemistry data will be read from and written to project_dir/case/QC/
132
+ the molecular dynamics data will be read from and written to project_dir/case/MD/
133
+ data directory will be created in project_dir/case/QC/case_${structure_id}_PARM
134
+
135
+ MD_dyn_state: state for MD propagation, be a string
136
+ QCDir: where to store the FF file
137
+
138
+ platform = gpu or cpu
139
+ define the platform for which the job will run
140
+
141
+ jobtype = 'strip_solvent','minimization', 'heat_equil_run', 'recalculate', 'energy_analysis'
142
+ if platform == gpu only heat_equil_run can be performed
143
+
144
+ case : is the case being considered, will also be used for naming folder under the project_dir
145
+ as well as many other important file choose wisely
146
+ start,end : int, integer index for structure identification
147
+ [x,y]
148
+
149
+ PARM = string identification for the job parameter, will be used for naming.
150
+
151
+ continue_from : int, default = 0.
152
+ in almost all cases you will start from 0 , if for some reason you want to repeat some of the job,
153
+ you can start where to start with
154
+
155
+
156
+ """
157
+ #General setup for master control file
158
+ master_control_template =f'{template_dir}/master_control_general_template.sh'
159
+ master_control_file =f'{md_dir}/master_control.sh'
160
+ copyfile(master_control_template,master_control_file)
161
+
162
+ JOB_template=f'{template_dir}/{platform}job_control_template.slurm'
163
+ JOB_FILE=f'{md_dir}/{platform}job_control.slurm'
164
+ copyfile(JOB_template,JOB_FILE)
165
+ print("master_control_template,master_control_file,JOB_template,JOB_FILE",master_control_template,master_control_file,JOB_template,JOB_FILE)
166
+ # variable setting and naming
167
+ system= case+'_'
168
+
169
+ #Setting up the job content
170
+
171
+ # a lof of if functions
172
+ MD_DIR= md_dir#$ project_dir + '/' + case + '/MD/'
173
+ QC_DIR= qc_dir #project_dir + '/' + case + '/QC/'+system+'${structure}_'+PARM
174
+
175
+
176
+ if jobtype == 'strip_solvent':
177
+ job = ['yes','no','no','no','no']
178
+
179
+ elif jobtype == 'minimization':
180
+ job = ['no','yes','no','no','no']
181
+
182
+ elif jobtype == 'heat_equil_run':
183
+ job = ['no','no','yes','no','no']
184
+
185
+ elif jobtype == 'recalculate':
186
+ job = ['no','no','no','yes','no']
187
+
188
+ elif jobtype == 'energy_analysis':
189
+ job = ['no','no','no','no','yes']
190
+
191
+ else :
192
+ print('Support for other jobtype is under construction')
193
+ print(jobtype)
194
+ sed_inplace(master_control_file,'PROJECT_DIR=','PROJECT_DIR='+MD_DIR)
195
+ #sed_inplace(master_control_file,'JOBDIR=','JOBDIR='+MD_DIR)
196
+ sed_inplace(master_control_file,'SRCDIR=','SRCDIR='+ template_dir)
197
+ sed_inplace(master_control_file,'DATA_DIR=','DATA_DIR='+QC_DIR)
198
+ #sed_inplace(master_control_file,"ID_NO=", "ID_NO="+testing_string)
199
+ # sed_inplace(master_control_file,'SYSTEM=','SYSTEM='+system)
200
+ print('system ', system)
201
+ if len(Solvent.split()) > 1:
202
+ print('Solvent.split(',')[0] + Solvent.split(',')[1]', Solvent.split(',')[0] + Solvent.split(',')[1])
203
+ if len(Solvent.split(",")) == 1:
204
+ sed_inplace(master_control_file,'SOLVENT=','SOLVENT='+Solvent)
205
+ else:
206
+ sed_inplace(master_control_file,'d_resname=','d_resname='+Solvent.split(',')[0])
207
+ sed_inplace(master_control_file,'a_resname=','a_resname='+Solvent.split(',')[1])
208
+ sed_inplace(master_control_file,'SOLVENT=','SOLVENT='+ Solvent.split(',')[0] + Solvent.split(',')[1])
209
+ print('test solvent ', master_control_file)
210
+ sed_inplace(master_control_file,'system=','system='+system)
211
+ #clst.sed_inplace(master_control_file,'START=','START='+str(start))
212
+ #clst.sed_inplace(master_control_file,'END=','END='+str(end))
213
+ sed_inplace(master_control_file,'GIVEN_STRUC=','GIVEN_STRUC='+testing_string)
214
+ sed_inplace(master_control_file,'total_traj=','total_traj='+str(total_traj))
215
+ sed_inplace(master_control_file,'continue_from=','continue_from='+str(continue_from))
216
+ sed_inplace(master_control_file,'stripsolvent=','stripsolvent='+job[0])
217
+ print('platform', platform)
218
+ sed_inplace(master_control_file, 'platform=', 'platform='+ platform)
219
+ sed_inplace(master_control_file,'run_'+platform+'_min=','run_'+platform+'_min='+job[1])
220
+ sed_inplace(master_control_file,'run_gpu_MD=','run_gpu_MD='+job[2])
221
+ sed_inplace(master_control_file,'run_cpu_rec=','run_cpu_rec='+job[3])
222
+ sed_inplace(master_control_file,'run_energy_analysis=','run_energy_analysis='+job[4])
223
+ sed_inplace(master_control_file,'inpdir=','inpdir='+inp_dir)
224
+
225
+ print("md dir ", md_dir, "inp_dir", inp_dir, JOB_FILE)
226
+ # learn to use subprocess Popen etc to do this later
227
+ sed_inplace(JOB_FILE,'THE_DIR=','THE_DIR='+md_dir)
228
+ sed_inplace(JOB_FILE,'HQDIR=','HQDIR='+md_dir)
229
+ sed_inplace(JOB_FILE,'DONOR=PI','DONOR='+MD_Donor)
230
+ sed_inplace(JOB_FILE,'STATE=PI','STATE='+MD_dyn_state)
231
+ if len(Solvent.split(",")) == 1:
232
+ sed_inplace(JOB_FILE,'SOLVENT=','SOLVENT='+Solvent)
233
+ else:
234
+ sed_inplace(JOB_FILE,'d_resname=','d_resname='+Solvent.split(',')[0])
235
+ sed_inplace(JOB_FILE,'a_resname=','a_resname='+Solvent.split(',')[1])
236
+ sed_inplace(JOB_FILE,'SOLVENT=','SOLVENT='+ Solvent.split(',')[0] + Solvent.split(',')[1])
237
+ sed_inplace(JOB_FILE,'SYSTEM=','SYSTEM='+system)
238
+ sed_inplace(JOB_FILE,'MOLECULE=',"MOLECULE="+system+testing_string)
239
+ sed_inplace(JOB_FILE,"ID_NO=", "ID_NO="+testing_string)
240
+ sed_inplace(JOB_FILE,'state_list=','state_list='+state_list)
241
+ # sed_inplace(JOB_FILE, "THE_DIR=")
242
+
243
+ sed_inplace(master_control_file, 'state_list=','state_list='+state_list)
244
+
245
+ sed_inplace(master_control_file,'DEP=','DEP='+dependency)
246
+ #else:
247
+ data2 = os.popen('cat '+JOB_FILE).read()
248
+
249
+ os.chdir(md_dir)
250
+ data = os.popen('sh master_control.sh').read()
251
+
252
+
253
+
254
+ return data
255
+
256
+ def generate_MDinp(MD_inp_tempdir, MD_dt, MD_steps, sample_steps, MD_temperature, MD_running_dir) :
257
+ construct_MDinp = shell_copy_template(MD_inp_tempdir, MD_running_dir, filename='construct_MDinp')
258
+
259
+ os.chdir(MD_running_dir)
260
+ sed_inplace(construct_MDinp,'Template_Dir=', 'Template_Dir=' + MD_inp_tempdir )
261
+ sed_inplace(construct_MDinp,'Target_Dir=', 'Target_Dir=' + MD_running_dir )
262
+
263
+ sed_inplace(construct_MDinp,'MD_steps=', 'MD_steps='+ MD_steps )
264
+ sed_inplace(construct_MDinp,'MD_dt=', 'MD_dt='+ MD_dt )
265
+ sed_inplace(construct_MDinp,'sample_steps=', 'sample_steps='+ sample_steps )
266
+ sed_inplace(construct_MDinp,'MD_temperature=', 'MD_temperature='+ MD_temperature )
267
+
268
+
269
+ data = os.popen('sh construct_MDinp.sh; pwd').read()
270
+ return data
271
+
272
+
273
+
274
+ import pickle
275
+ def main_RunMD():
276
+ dict_of_simulation = parse_input()
277
+ # prepare for quantum chemistry simulation
278
+ work_dir = dict_of_simulation['work_dir']
279
+ # where we have the structure directory
280
+ structure_dir = dict_of_simulation['structure_dir']
281
+ # load the project folder
282
+ project = dict_of_simulation['project']
283
+ # get case id for the simulation
284
+ caseid = dict_of_simulation['caseid']
285
+ # get job list
286
+ case_id_list = separate_idlist(caseid)
287
+ # get list of job control token
288
+ job_control = init_job_control(case_id_list)
289
+
290
+ # job_info = init_job_info(case_id_list)
291
+ startime = time.time ()
292
+
293
+ # Read list to memory
294
+ def read_list():
295
+ # for reading also binary mode is important
296
+ with open(work_dir+'/listfile', 'rb') as fp:
297
+ n_list = pickle.load(fp)
298
+ return n_list
299
+
300
+ job_info = read_list()
301
+ print("SubmitQC begins at "+str(startime))
302
+ # print("Input parameters ")
303
+ # print(simulation_parameter)
304
+ for ind, ctr_ele in enumerate(job_control):
305
+ print(ind, job_control)
306
+ run_step4(ind, job_control, dict_of_simulation,job_info)
307
+
308
+ end_time = time.time ()
309
+ print("SubmitQC ends at "+str(end_time))
310
+
311
+
312
+ if __name__ == "__main__":
313
+ main_RunMD();
pyctramer/SpinBoson.py ADDED
@@ -0,0 +1,193 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from .Utilities import *
4
+
5
+
6
+ def run_step6(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
+ spin_boson_modes = dict_of_simulation['spin_boson_modes']
14
+ TCF_corr_length = dict_of_simulation['TCF_corr_length']
15
+ TCF_DT = dict_of_simulation['TCF_DT']
16
+ N_traj = int(dict_of_simulation['N_traj'])
17
+ MD_steps = int(dict_of_simulation['MD_steps'])
18
+ sample_steps = int(dict_of_simulation['sample_steps'])
19
+ traj_N_frames = int(MD_steps / sample_steps)
20
+ temperature = float(dict_of_simulation['MD_temperature'])
21
+
22
+ beta = 1. / (temperature * kT2au)
23
+
24
+ TCF_corr_length = float(TCF_corr_length)
25
+ spin_boson_modes = int(spin_boson_modes)
26
+ TCF_DT = float(TCF_DT)
27
+ corr_leng = int(TCF_corr_length/TCF_DT)
28
+ # print('traj_N_frame',traj_N_frames,corr_leng,TCF_corr_length,)
29
+ correctmax = 0
30
+ if job_info[i]['namemax'] == '':
31
+ energy_traj_file = dict_of_simulation['energy_traj_file'].split(",")
32
+ LE_path = energy_traj_file[0]
33
+ CT_path = energy_traj_file[1]
34
+ else:
35
+ namemax = job_info[i]['namemax']
36
+ cpmax = job_info[i]['cpmax']
37
+ ratemax = job_info[i]['ratemax']
38
+ correctmax = job_info[i]['correctmax']
39
+ max_indpair = job_info[i]['max_indpair']
40
+ LE_path = md_dir + "/Traj_"+MD_dyn_state+"/"+project +"_"+ caseid+"_E_LE_TRAJ_"+MD_dyn_state+"_NVE.dat"
41
+ CT_path = md_dir + "/Traj_"+MD_dyn_state+"/"+project +"_"+ caseid+"_E_"+namemax[1]+"_TRAJ_"+MD_dyn_state+"_NVE.dat"
42
+ kcal2eV = 0.0433641043
43
+ print('correction ', correctmax, traj_N_frames)
44
+ Ut = kcal2eV * (np.loadtxt(LE_path) - np.loadtxt(CT_path)) + correctmax
45
+
46
+ # Get Cuu(t)
47
+ Cuu = gen_Cuu(Ut, corr_leng, N_traj, traj_N_frames)
48
+ print(Cuu[0])
49
+ np.savetxt(work_dir+"/Cuu"+namemax[0]+namemax[1]+".dat",Cuu)
50
+
51
+ # Get discretized SD
52
+ w_SB = np.zeros(spin_boson_modes, dtype=float)
53
+ max_iter_SBM = 1000
54
+ tol_w_SBM = 1e-8
55
+ for i in range(spin_boson_modes):
56
+ x0 = 0.1 * cm2au
57
+ x1 = 0.5 * cm2au
58
+ iter_count = 0
59
+ while (abs(x1-x0) > tol_w_SBM):
60
+ f0 = fw(x0, i+1, TCF_DT*ps2au, Cuu, spin_boson_modes)
61
+ f1 = fw(x1, i+1, TCF_DT*ps2au, Cuu, spin_boson_modes)
62
+ x = (x0 * f1 - x1 * f0) / (f1 - f0)
63
+ x0 = x1
64
+ x1 = x
65
+ iter_count += 1
66
+ if iter_count > max_iter_SBM:
67
+ print('Warning: The frequency of mode '+ str(i+1)+ ' is not converged yet! ')
68
+ # raise RuntimeError("set larger mode number would help")
69
+ w_SB[i] = x1 # get discretized spectral density in au of tiem
70
+
71
+ Req_SB = np.zeros(spin_boson_modes)
72
+ c_SB = np.zeros(spin_boson_modes)
73
+ Er = 0.5 * beta * Cuu[0] * eV2au * eV2au
74
+ print('Er = ', Er)
75
+ for i in range(spin_boson_modes):
76
+ Req_SB[i] = np.sqrt(2. * Er / (1.*spin_boson_modes) ) / w_SB[i]
77
+ c_SB[i] = np.sqrt(Er / (2. * spin_boson_modes)) * w_SB[i]
78
+
79
+ SB_data = np.array([np.arange(1,spin_boson_modes+1,dtype=int), w_SB, c_SB, Req_SB, Req_SB]).T
80
+ np.savetxt(work_dir+"/SBM"+namemax[0]+namemax[1]+".dat",SB_data)
81
+ np.savetxt(work_dir+"/SBM"+namemax[0]+"CT.dat",SB_data)
82
+ # Get J(w)
83
+ # max frequency to be
84
+ max_freq = 1.2 * max(w_SB) * au2cm # 2500 # 2 * np.pi / (TCF_DT * ps2au) / corr_leng
85
+ print('max freq', max_freq)
86
+ dw = 0.2 # in wave number
87
+ max_w_count = int(max_freq / dw)
88
+
89
+ cont_w = 0.2 * cm2au * np.arange(max_w_count)
90
+ Jw_cont = np.zeros(max_w_count)
91
+
92
+ for ind, w in enumerate(cont_w):
93
+ Jw_cont[ind] = Jw(w, beta, TCF_DT*ps2au, Cuu)
94
+
95
+ np.savetxt(work_dir+"/Jw"+namemax[0]+namemax[1]+".dat",Jw_cont*eV2au*eV2au)
96
+
97
+ stroutput = "\n\n"
98
+ stroutput = stroutput + "STEP 6: Spinboson\n"
99
+
100
+ stroutput = stroutput + "Cuu data point number " + str(corr_leng) + ", dt = " + str(TCF_DT) + " ps\n"
101
+ stroutput = stroutput + "Jw data point number " + str(max_w_count) + ", dw = " + str(dw) + "cm^-1 \n"
102
+
103
+ stroutput = stroutput + "SpinBoson model bath parameters " + work_dir+"/SBM"+namemax[0]+"CT.dat\n"
104
+ stroutput = stroutput + "Spinboson bath headers: w_SB, c_SB, Req_SB, Req_SB \n \n \n"
105
+ stroutput = stroutput + "#######################################################\n"
106
+ write_to_output(i, job_control, dict_of_simulation, stroutput)
107
+
108
+ return jobinfo
109
+
110
+ def gen_Cuu(energy_gaps, corr_leng, Ntraj, MD_steps):
111
+ # energy_gaps = np.array(energy_gaps)
112
+ Cuut = np.zeros(corr_leng,dtype=float)
113
+ Cuu0 = np.average(energy_gaps)**2
114
+ energy_gaps = energy_gaps - np.average(energy_gaps)
115
+ print("Cuu0",Cuu0,np.std(energy_gaps)**2)
116
+ for i in range(Ntraj):
117
+ for j in range(corr_leng):
118
+ for k in range(MD_steps-j):
119
+ Cuut[j] += energy_gaps[i*MD_steps+k] * energy_gaps[i*MD_steps+k+j]
120
+ Cuut[j] /= (1.*MD_steps-1.*j-1.)
121
+ #print((1.*MD_steps-1.*j))
122
+ # print('cuu',Cuut[0],Cuu0 )
123
+ for j in range(corr_leng):
124
+ Cuut[j] /= (1. * Ntraj)
125
+ #Cuut[j] = Cuut[j] - Cuu0
126
+ # print(Cuut[0] ,Cuu0)
127
+ return Cuut
128
+
129
+
130
+
131
+ def Jw(w, beta, dt_au, Cuu):
132
+ factor = 0.25 * beta * w
133
+ size = len(Cuu)
134
+ # print('size',size, np.shape(w))
135
+ ft = Cuu * np.cos(w * np.arange(size) * dt_au) # wt
136
+ return factor * (np.sum(ft)-0.5*(ft[0]+ft[-1])) * dt_au
137
+
138
+
139
+ def fw(w, j, dt, Cuu, N):
140
+ # w in au
141
+ # j mode order
142
+ # dt in au
143
+ # Cuu in au
144
+ # N: SBM mode num
145
+ factor = 2 * N * w / np.pi / Cuu[0]
146
+ size = len(Cuu)
147
+ ft = np.zeros(size)
148
+ ft[0] = Cuu[0]
149
+ for s in range(1,size):
150
+ wt = s * dt * w
151
+ ft[s] = Cuu[s] * np.sin(wt) / wt
152
+ return factor * (np.sum(ft) - 0.5* (ft[0]+ft[-1]))*dt + 0.5 -j
153
+
154
+ import pickle
155
+ def main_SB():
156
+ dict_of_simulation = parse_input()
157
+ # prepare for quantum chemistry simulation
158
+ work_dir = dict_of_simulation['work_dir']
159
+ # where we have the structure directory
160
+ structure_dir = dict_of_simulation['structure_dir']
161
+ # load the project folder
162
+ project = dict_of_simulation['project']
163
+ # get case id for the simulation
164
+ caseid = dict_of_simulation['caseid']
165
+ # get job list
166
+ case_id_list = separate_idlist(caseid)
167
+ # get list of job control token
168
+ job_control = init_job_control(case_id_list)
169
+
170
+ # job_info = init_job_info(case_id_list)
171
+ startime = time.time ()
172
+
173
+ # Read list to memory
174
+ def read_list():
175
+ # for reading also binary mode is important
176
+ with open(work_dir+'/listfile', 'rb') as fp:
177
+ n_list = pickle.load(fp)
178
+ return n_list
179
+
180
+ job_info = read_list()
181
+ print("SubmitQC begins at "+str(startime))
182
+ # print("Input parameters ")
183
+ # print(simulation_parameter)
184
+ for ind, ctr_ele in enumerate(job_control):
185
+ print(ind, job_control)
186
+ run_step6(ind, job_control, dict_of_simulation,job_info)
187
+
188
+ end_time = time.time ()
189
+ print("SubmitQC ends at "+str(end_time))
190
+
191
+
192
+ if __name__ == "__main__":
193
+ main_SB()