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.
@@ -0,0 +1,1191 @@
1
+ from .Utilities import *
2
+ import pandas as pd
3
+ import numpy as np
4
+ import math, time
5
+ import io
6
+ def run_step3(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
+ template_dir = dict_of_simulation['template_dir']
13
+
14
+ N_cis = int(dict_of_simulation['N_cis'])
15
+
16
+ # charges on donor
17
+ charge_on_frags = get_charge_on_Donor(qc_dir, project +"_"+ caseid, N_cis)
18
+ charges_on_donor = []
19
+ for line in charge_on_frags:
20
+ splitted_charges = line.split()
21
+ charges_on_donor.append(float(splitted_charges[1]))
22
+ print(charges_on_donor)
23
+
24
+
25
+ # find locally excited states
26
+ LE_fragment = dict_of_simulation['LE_fragment']
27
+ DA_type = dict_of_simulation['DA_type']
28
+ CT_donor_fragments = dict_of_simulation['CT_donor_fragments']
29
+ CT_acceptor_fragments = dict_of_simulation['CT_acceptor_fragments']
30
+ Max_CT_states = dict_of_simulation['Max_CT_states']
31
+ CT_amount_threshold = dict_of_simulation['CT_amount_threshold']
32
+ OS_threshold = dict_of_simulation['OS_threshold']
33
+ LE_position_threshold = dict_of_simulation['LE_position_threshold']
34
+ CT_type = dict_of_simulation['CT_type']
35
+ Include_bCT_states = dict_of_simulation['Include_bCT_states']
36
+
37
+
38
+ # Load the theodore results
39
+ test_results = load_Theo_summary(qc_dir, DA_type)
40
+ # extract energy and excited state
41
+ if DA_type == 'DBA' and Max_CT_states == "2":
42
+ State_list, Ene_list = Find_CT_states_DBA(test_results, LE_fragment,CT1_thres=CT_amount_threshold,OSthres=OS_threshold)
43
+ elif DA_type == 'DA':
44
+ # , CT_dQ_D, CT_donor_charge, bdCT_list
45
+ State_list, Ene_list, CT_deltaQ_onD, CT_Donor_charge, bdCT_list = Find_CT_states_DA(test_results, LE_fragment, charges_on_donor, Max_CT_states, Include_bCT_states, POSthres=LE_position_threshold, OSthres=OS_threshold, CT_thres=CT_amount_threshold)
46
+
47
+ # get total number of atoms
48
+ N_atom = dict_of_simulation['N_atom']
49
+ # get the output name
50
+ out_name = project + '_' + caseid
51
+ # coupling for different states
52
+ coupling_list = []
53
+ N_cis = dict_of_simulation['N_cis']
54
+ Solvent_dir = dict_of_simulation['solvent_dir']
55
+
56
+
57
+ # calculate the diabatic coupling
58
+ for ind, name in enumerate(State_list):
59
+ for ind2, name2 in enumerate(State_list):
60
+ if ind > ind2 :
61
+ #print(name, name2)
62
+ coupling_list.append(get_coupling(qc_dir,out_name,State_list[name],State_list[name2],N_cis))
63
+ print("State_list",State_list,"coupling_list",coupling_list)
64
+ # get charge
65
+ charge_name = dict_of_simulation['charge_type'] #'Mulliken'
66
+ # Solvent = dict_of_simulation['Solvent']
67
+ # Solvent_ad = dict_of_simulation['solvent_dir']
68
+
69
+ # Solvent_name = dict_of_simulation['solvent_name']
70
+ # Solute_name = dict_of_simulation['solute_name']
71
+ # Solute_name1 = 'TRI'
72
+
73
+ BoxLength=dict_of_simulation['MD_box_length']
74
+ COM = int(BoxLength)/2
75
+
76
+ DA_type = dict_of_simulation['DA_type']
77
+ D_range = dict_of_simulation['D_range']
78
+ B_range = dict_of_simulation['B_range']
79
+ A_range = dict_of_simulation['A_range']
80
+ A1_range = dict_of_simulation['A1_range']
81
+ A2_range = dict_of_simulation['A2_range']
82
+ CT_donor_fragment = dict_of_simulation['CT_donor_fragments']
83
+ CT_acceptor_fragment = dict_of_simulation['CT_acceptor_fragments']
84
+
85
+ solute_resname = dict_of_simulation['solute_resname']
86
+ solvent_resname = dict_of_simulation['solvent_resname']
87
+ solute_N_atom = dict_of_simulation['solute_N_atom']
88
+ solvent_N_atom = dict_of_simulation['solvent_N_atom']
89
+ solvent_dir = dict_of_simulation['solvent_dir']
90
+ solvent_N_mole = dict_of_simulation['solvent_N_mole']
91
+ solute_dir = dict_of_simulation['solute_dir']
92
+
93
+
94
+ # THF_number= dict_of_simulation['solvent_nres']
95
+ N_cis = int(dict_of_simulation['N_cis'])
96
+ N_atom = int(dict_of_simulation['N_atom'])
97
+ force_field_name='gaff'
98
+ charge_file= qc_dir+ '/charge0.txt'
99
+
100
+ zeros = np.zeros(N_atom, dtype=int)
101
+ np.savetxt(charge_file, zeros)
102
+
103
+ Solvent_name = ""
104
+ if len(solvent_resname.split()) == 2:
105
+ Solvent_name = solvent_resname.split()[0] + solvent_resname.split()[1]
106
+ elif len(solvent_resname.split()) == 1:
107
+ Solvent_name = solvent_resname
108
+
109
+ if CT_type == "inter":
110
+ info = construct_prmtop_inter(template_dir, qc_dir, caseid, project,
111
+ D_range,A_range,B_range,CT_acceptor_fragment,CT_acceptor_fragment,
112
+ solute_dir,solvent_dir,solute_resname,solvent_resname,solvent_N_mole,
113
+ BoxLength, COM, force_field_name, N_cis, charge_file)
114
+
115
+ else:
116
+ info = construct_prmtop_intra(template_dir, qc_dir, caseid, project,
117
+ D_range,A_range,B_range,CT_acceptor_fragment,CT_acceptor_fragment,
118
+ solute_dir,solvent_dir,solute_resname,solvent_resname,solvent_N_mole,
119
+ BoxLength, COM, force_field_name, N_cis, charge_file)
120
+
121
+ ## construct FF excited states
122
+ charge_file_prefix = project+'_'+caseid
123
+ mulliken_log_file_dir = qc_dir +'/mulliken'
124
+
125
+ Solvent_name = ""
126
+ if len(solvent_resname.split(",")) == 2:
127
+ Solvent_name = solvent_resname.split(',')[0] + solvent_resname.split(',')[1]
128
+ elif len(solvent_resname.split(',')) == 1:
129
+ Solvent_name = solvent_resname
130
+
131
+ old_top = qc_dir + charge_file_prefix + '_' + Solvent_name +'.prmtop'
132
+ charge_ad = qc_dir
133
+
134
+ new_name_top = charge_file_prefix+'_' +Solvent_name+'_GR'
135
+ new_top_dir = md_dir
136
+ print("State List",State_list)
137
+ QChem_version = dict_of_simulation['QChem_version']
138
+ print("N_atom ", N_atom)
139
+ #replace_charge_to_prmtop(N_atom_triad, new_top_dir, old_top, charge_file, new_name_top)
140
+ for ind, name in enumerate(State_list):
141
+ charge_file = qc_dir+'/charge_'+name+'_'+charge_file_prefix+'.txt'
142
+ get_charges(N_atom, State_list[name], name, mulliken_log_file_dir, charge_ad,
143
+ charge_file_prefix,charge_file_prefix, charge_name, D_range, B_range, A_range, QChem_version)
144
+ new_name_top = charge_file_prefix+'_'+Solvent_name+'_'+name
145
+ replace_charge_to_prmtop(N_atom, new_top_dir, old_top, charge_file, new_name_top)
146
+ print(Ene_list)
147
+ print('jobinfo',job_info,len(job_info))
148
+
149
+ job_info[i]['Ene_list']= Ene_list
150
+ job_info[i]['State_list'] = State_list
151
+ job_info[i]['coupling_list'] = coupling_list
152
+
153
+ stroutput = "\n\n"
154
+ stroutput = stroutput + "STEP 3: ConstructFF\n\n"
155
+ stroutput = stroutput + "Input: " + qc_dir
156
+ stroutput = stroutput + " " + out_name + ".out\n"
157
+ stroutput = stroutput + " " + out_name + ".fchk\n"
158
+ stroutput = stroutput + " "+ qc_dir + "/mulliken/" + out_name + ".out\n"
159
+ stroutput = stroutput + " "+ qc_dir + "tden_summ_fchk.txt\n"
160
+ stroutput = stroutput + " "+ qc_dir + "tden_summ_tddft.txt\n"
161
+ stroutput = stroutput + " "+ qc_dir + "packmol.inp\n"
162
+ stroutput = stroutput + " "+ qc_dir + "tleap.in\n\n"
163
+ stroutput = stroutput + "Job submit script: " + qc_dir + "construct_prmtop_"+ CT_type +".sh\n\n"
164
+ stroutput = stroutput + "Output: " + qc_dir + "\n"
165
+ stroutput = stroutput + " "+ qc_dir + "leap.log"
166
+ stroutput = stroutput + " "+ qc_dir + "FCD_coupling_raw.txt"
167
+ for ind, name in enumerate(State_list):
168
+ charge_file = qc_dir+'/charge_'+name+'_'+charge_file_prefix+'.txt'
169
+ stroutput = stroutput + " " + chargefile_list + ".txt\n"
170
+
171
+ stroutput = stroutput + " "+old_top
172
+ for ind, name in enumerate(State_list):
173
+ new_name_top = charge_file_prefix+'_'+Solvent_name+'_'+name
174
+ stroutput = stroutput + " " + new_name_top + ".txt\n"
175
+ stroutput = stroutput + qc_dir + charge_file_prefix + '_' + Solvent_name +'.inpcrd \n'
176
+ stroutput = stroutput + "\n\n\n"
177
+ stroutput = stroutput + ">>> Summary of calculation:\n\n"
178
+ stroutput = stroutput + ">>> >>> State characteristic analysis (TheoDORE)\n"
179
+ s = io.StringIO()
180
+ test_results.to_csv(s)
181
+ stroutput = stroutput + s.getvalue()
182
+ stroutput = stroutput + "\n\n"
183
+
184
+ stroutput = stroutput + ">>> >>> States of intersts in CT considered for Marcus rates \n"
185
+
186
+ stroutput = stroutput + "State,Energies (eV) \n"
187
+ for ind, name in (State_list):
188
+ stroutput = stroutput + name + "," + str(Ene_list[ind]) + '\n'
189
+
190
+ stroutput = stroutput + ">>> >>> CT States: Charge Transfer Amounts \n"
191
+
192
+ if CT_type == "DA":
193
+ stroutput = stroutput + "State,dQ_D (eV),Q_D \n"
194
+ for ind, name in (State_list):
195
+ if ind > 1: # CT_deltaQ_onD, CT_Donor_charge, bdCT_list
196
+ stroutput = stroutput + name + "," + str(CT_deltaQ_onD[ind-2]) +"," +str(CT_Donor_charge[ind-2]) + "\n"
197
+
198
+ stroutput = stroutput + "\n"
199
+ stroutput = stroutput + ">>> >>> CT States: Charge Transfer Amounts \n"
200
+ for line in bdCT_list:
201
+ stroutput = stroutput + "\n"
202
+ stroutput = stroutput + "\n >>> >>> FCD Coupling in eV \n"
203
+
204
+ fcdcpind = 0
205
+ for ind1, name in (State_list):
206
+ # stroutput = stroutput + name +
207
+ for ind2, name2 in (State_list):
208
+ if ind1 > ind2 :
209
+ if ind1 > 0 and ind2 > 0:
210
+ stroutput = stroutput + name + name2 + ":" + str(coupling_list[fcdcpind]) + "\n"
211
+ fcdcpind += 1
212
+ stroutput = stroutput + '\n\n'
213
+ stroutput = stroutput + "#######################################################\n"
214
+ write_to_output(i, job_control, dict_of_simulation, stroutput)
215
+ return job_control
216
+
217
+ def load_Theo_summary(filedir, DA_type):
218
+ """
219
+ This function load a theodore tddft and fchk analysis summary and create a CT state characteristic summary DataFrame
220
+ usage:
221
+ ----------
222
+ filedir= '/xspace/db4271/ST_Rate/data/QC_Calc/testdir/triad_cc_Linear_BNL_30states_w157'
223
+ one need to change the theo_summ according to the DA_type
224
+
225
+ """
226
+ file_tddft=f'{filedir}/tden_summ_tddft.txt'
227
+ file_fchk=f'{filedir}/tden_summ_fchk.txt'
228
+ file_ehFrag=f'{filedir}/ehFrag.txt'
229
+ theo_tddft=pd.read_table(file_tddft, skiprows= [1],delim_whitespace=True )
230
+ theo_fchk=pd.read_table(file_fchk, skiprows= [1], delim_whitespace=True )
231
+ theo_ehFrag=pd.read_table(file_ehFrag, skiprows= [1], delim_whitespace=True )
232
+ if DA_type == 'DA':
233
+ theo_summ = pd.concat([theo_tddft[['state','dE(eV)','f']],
234
+ theo_fchk[['Om','POS','PR','CT','COH', 'CTnt', 'PRNTO','Z_HE','RMSeh']],
235
+ theo_ehFrag[['H_1','E_1','H_2','E_2']]],axis=1)
236
+ elif DA_type == "DBA":
237
+ theo_summ = pd.concat([theo_tddft[['state','dE(eV)','f']],
238
+ theo_fchk[['Om','POS','PR','CT','COH', 'CTnt', 'PRNTO','Z_HE','RMSeh']],
239
+ theo_ehFrag[['H_1','E_1','H_2','E_2','H_3','E_3']]],axis=1)
240
+ return theo_summ
241
+
242
+ def Find_CT_states_DBA(data, LE_fragment, POSthres=0.2, OSthres= 0.1, CT1_thres=0.5, CT2_thres=0.05, verbose=True):
243
+ """
244
+ Algorithm to find the best LE, CT1 and CT2 states
245
+ LE_fragment defines the locally excited fragments in triad or dyad; int; for triad case; LE_fragment=2 for porphyrin excited state
246
+
247
+ OSthres: threshold of the Oscillator Strength (OS)
248
+ POSthres: thereshold of the POS (averaged position)
249
+ CT1_thres: threshold of the charge transfer from C to PC60
250
+
251
+ return
252
+ list of CT states final decision, and the corresponding energies
253
+ """
254
+
255
+ ################ Finding LE State ###########################
256
+ energy_list= list(data['dE(eV)'])
257
+ LE_fragment = int(LE_fragment)
258
+ if LE_fragment != 1 and LE_fragment !=2 :
259
+ print('Error: LE should be on the first or the second fragment in you defined theodore analysis')
260
+ return -1
261
+ else:
262
+ pass
263
+
264
+ POS_list , POS_sorted= sort_and_index(df=data, column_name='POS')
265
+ LE_list=[]
266
+ P_LE_index=[]
267
+ high_OS=[]
268
+ high_OS_index=[]
269
+ PR_NTO_GOOD=[]
270
+ LE_energy_list=[]
271
+ # Criteria 1: POS
272
+ for i in range(len(POS_sorted)):
273
+ diff_POS = abs((POS_sorted[i]-LE_fragment))
274
+ if diff_POS <= POSthres :
275
+ #print("diff_POS = ", diff_POS)
276
+ # screen for state with local excitation on the LE_fragment
277
+ LE_list.append(POS_sorted[i])
278
+ POS_candidate_list = list(data['POS'])
279
+ P_LE_index.append(POS_candidate_list.index(POS_sorted[i]))
280
+ #print("PI_candidate", POS_sorted[i])
281
+
282
+ # Criteria 2: Oscillation strength
283
+ for j in P_LE_index :
284
+ f_list = list(data['f'])
285
+ if f_list[j] > float(OSthres): # The state is an absorption state
286
+ high_OS.append(f_list[j])
287
+ high_OS_index.append(high_OS.index(f_list[j]))
288
+ #pi_state_candidate = (np.min(LE_list)) # based on lowest excitation porphyrin
289
+ LE_state_candidate = (np.max(high_OS)) # based on oscillator strength
290
+ LE_state = f_list.index(LE_state_candidate) +1 # +1 to convert python indexing to real electronic state
291
+
292
+ # Criteria 3: Lowest lying PI-PI state, aborted
293
+ #for k in high_OS_index :
294
+ # pi_energy_list.append(energy_list[k])
295
+ # pi_state_candidate = (np.min(pi_energy_list))
296
+ # pi_state = energy_list.index(pi_state_candidate) +1 # +1 for index to real state
297
+
298
+
299
+
300
+
301
+
302
+ LE_energy = energy_list[LE_state -1] # -1 for real state index to index
303
+ if verbose == True:
304
+ print('P_LE: ',LE_list)
305
+ print('P_LE_index: ',P_LE_index)
306
+ print('high_OS: ',high_OS)
307
+ print('high_OS_index: ',high_OS_index)
308
+ print('GOOD_PR_NTO: ',PR_NTO_GOOD)
309
+ print('LE_energy = ',LE_energy, ' eV')
310
+ else :
311
+ print('LE_energy = ',LE_energy, ' eV')
312
+ print('--------------------------------')
313
+ ################ Finding CT1 State ###########################
314
+
315
+ CT_net_list , CT_net_sorted= sort_and_index(df=data, column_name='CTnt')
316
+ CT_net_candidate=[]
317
+ CT_net_index=[]
318
+ CT1_energy_list=[]
319
+
320
+ # Criteria 1: CTnet
321
+ for i in range(len(CT_net_sorted)):
322
+ # diff_CT_net = abs(CT_net_sorted[i]+1) # because CT_net_sorted[i] is all negative value
323
+ diff_CT_net = abs(CT_net_sorted[i])
324
+ if diff_CT_net >= float(CT1_thres) :
325
+ # if diff_CT_net <=CT1_thres :
326
+ #print("diff_CT_net = ", diff_CT_net)
327
+ CT_net_candidate.append(CT_net_sorted[i])
328
+ CT_net_candidate_list = list(data['CTnt'])
329
+ CT_net_index.append(CT_net_candidate_list.index(CT_net_sorted[i]))
330
+ #print("PI_candidate", POS_sorted[i])
331
+
332
+ # Criteria 2: argmin(CT1_energy-PI_energy)
333
+ LECT1_gap = []
334
+ LECT1_ind = []
335
+ for j in CT_net_index:
336
+ if j != LE_state - 1:
337
+ CT1_energy = abs(energy_list[j] - LE_energy)
338
+ # print('CT1_energy : ', CT1_energy, j)
339
+ LECT1_gap .append(CT1_energy)
340
+ CT1_index = energy_list.index(energy_list[j])
341
+ CT1_energy_list.append(energy_list[CT1_index])
342
+ LECT1_ind . append(j)
343
+
344
+ # CT1_candidate = np.min(CT1_energy_list)
345
+ CT1_gap_min = np.min(LECT1_gap)
346
+ # CT1_state= energy_list.index(CT1_candidate) +1 # +1 for index to real state
347
+ CT1_state = LECT1_ind[LECT1_gap.index(CT1_gap_min)] + 1 # for readable results
348
+ # print('CT1STATE ',CT1_state)
349
+ CT1_energy = energy_list[CT1_state -1] # -1 for real state to index
350
+
351
+ if verbose == True:
352
+ print('CT1 ', CT1_state)
353
+ print('CT1_net: ',CT_net_candidate)
354
+ print('CT1_net_index: ',CT_net_index)
355
+ print('CT1_energy: ',CT1_energy_list)
356
+ print ('CT1_energy:',CT1_energy, ' eV')
357
+ else :
358
+ print ('CT1_energy:',CT1_energy, ' eV')
359
+ print('--------------------------------')
360
+ ################ Finding CT2 State ###########################
361
+ CT_list , CT_sorted= sort_and_index(df=data, column_name='CT')
362
+ CT_candidate=[]
363
+ CT_index=[]
364
+ CT2_energy_list=[]
365
+
366
+ # # Criteria 1: CT value
367
+
368
+ # empty list prevention # do while loop
369
+ target =1 # 1.1 # main target is CT value = 1 , add buffer to start the while loop
370
+ bottom_lim = 0.95
371
+ for i in range(len(CT_sorted)):
372
+ tol1 = target - CT2_thres
373
+ tol2 = target + CT2_thres
374
+ if (target <= CT_sorted[i] and CT_sorted[i] < tol2) or (target >= CT_sorted[i] and CT_sorted[i] > tol1):
375
+ CT_candidate.append(CT_sorted[i])
376
+ CT_candidate_list = list(data['CT'])
377
+ CT_index.append(CT_candidate_list.index(CT_sorted[i]))
378
+ # while (len(CT_index) < 1) and target > bottom_lim:
379
+ # target = target - 0.01 # refine the search slowly
380
+ # for i in range(len(CT_sorted)):
381
+ # diff_CT = abs(CT_sorted[i]-target) # that is CT value closest to 1
382
+ # print(i,CT_sorted[i],diff_CT)
383
+ # if diff_CT <= CT2_thres :
384
+ # print(CT2_thres,'THRES 2')
385
+ # #print("diff_CT = ", diff_CT)
386
+ # CT_candidate.append(CT_sorted[i])
387
+ # CT_candidate_list = list(data['CT'])
388
+ # CT_index.append(CT_candidate_list.index(CT_sorted[i]))
389
+
390
+
391
+ # Criteria 2: argmin(CT2_energy-PI_energy)
392
+ for j in CT_index:
393
+ CT2_energy = abs(energy_list[j] - LE_energy)
394
+ #print('CT2_energy : ', CT2_energy)
395
+ CT2_index = energy_list.index(energy_list[j])
396
+ CT2_energy_list.append(energy_list[CT2_index])
397
+ # consider selecting maximum CT ???
398
+
399
+ # Creteria 3:
400
+
401
+
402
+
403
+ CT2_candidate = np.min(CT2_energy_list)
404
+ CT2_state= energy_list.index(CT2_candidate) +1 # +1 for index to real state
405
+ CT2_energy = energy_list[CT2_state -1] # -1 for real state to index
406
+ if verbose == True :
407
+ print('CT2: ',CT_candidate)
408
+ print('CT2_index: ',CT_index)
409
+ print('CT2_energy: ',CT2_energy_list)
410
+ print ('CT2_energy:',CT2_energy, ' eV')
411
+ else :
412
+ print ('CT2_energy:',CT2_energy , ' eV')
413
+
414
+ print('--------------------------------')
415
+ print('FINAL DECISION')
416
+ print("The LE state is :", LE_state)
417
+ print("The CT1 state is :", CT1_state)
418
+ print("The CT2 state is :", CT2_state)
419
+
420
+ result = {'GR': 0, 'LE': LE_state, 'CT1':CT1_state, 'CT2': CT2_state}
421
+ energies =[0, LE_energy,CT1_energy, CT2_energy] # list of energy in eV
422
+ return result, energies
423
+
424
+ def Find_CT_states_DA(data, LE_fragment, charge_frag_list, Max_CT_states, Include_bCT_states, POSthres=0.2, OSthres= 0.1, CT_thres=0.5,verbose=True):
425
+ """
426
+ Algorithm to find the LE and CT states
427
+ LE_fragment defines the locally excited fragments in triad or dyad; int; for triad case; LE_fragment=2 for porphyrin excited state
428
+
429
+ OSthres: threshold of the Oscillator Strength (OS)
430
+ POSthres: thereshold of the POS (averaged position)
431
+ CT1_thres: threshold of the charge transfer from C to PC60
432
+
433
+ return
434
+ list of CT states final decision, and the corresponding energies
435
+ """
436
+ # Need to load quantum chemistry results
437
+
438
+ ################ Finding LE State ###########################
439
+ energy_list= list(data['dE(eV)'])
440
+ LE_fragment = int(LE_fragment)
441
+ if LE_fragment != 1 and LE_fragment !=2 :
442
+ print('Error: LE should be on the first or the second fragment in you defined theodore analysis')
443
+ return -1
444
+ else:
445
+ pass
446
+
447
+ POS_list , POS_sorted= sort_and_index(df=data, column_name='POS')
448
+ LE_list=[]
449
+ P_LE_index=[]
450
+ high_OS=[]
451
+ high_OS_index=[]
452
+ PR_NTO_GOOD=[]
453
+ LE_energy_list=[]
454
+ POSthres = float(POSthres)
455
+
456
+
457
+ if Include_bCT_states == "initial":
458
+ print("Consider bCT as a bright state")
459
+ elif Include_bCT_states == "final":
460
+ print("Consider bCT as a dark state")
461
+ elif Include_bCT_states == "initial_or_final":
462
+ print("I dont care ")
463
+
464
+ # Criteria 1: POS
465
+ for i in range(len(POS_sorted)):
466
+ diff_POS = abs((POS_sorted[i]-LE_fragment))
467
+ # print(POSthres, type(POSthres))
468
+ if diff_POS <= POSthres :
469
+ #print("diff_POS = ", diff_POS)
470
+ # screen for state with local excitation on the LE_fragment
471
+ LE_list.append(POS_sorted[i])
472
+ POS_candidate_list = list(data['POS'])
473
+ P_LE_index.append(POS_candidate_list.index(POS_sorted[i]))
474
+ # print("PI_candidate", POS_sorted[i])
475
+
476
+
477
+
478
+
479
+ # Criteria 1: Q_D amount
480
+
481
+ ####################### CT DECISION ACCORDING TO Q_D ####################################################
482
+ # determine CT states according to Q_D and energy ordering + Max_CT_states to determine the CT states
483
+ ########################################################################################################@
484
+ CT_candidate = []
485
+ bdCT_list = []
486
+ OS_list = list(data['f'])
487
+ OSthres = float(OSthres)
488
+ for i in range(len(charge_frag_list)):
489
+ # select the CT states: 1. dark (small OS), 2. CT (quite amound of charges on D segment in FCD calculation)
490
+ if charge_frag_list[i] > float(CT_thres): #and OS_list[i] < OSthres :
491
+ #if Include_bCT_states == "initial":
492
+ CT_candidate.append(i)
493
+ #elif Include_bCT_states == "initial_or_final":
494
+ if OS_list[i] < OSthres:
495
+ bdCT_list.append('d')
496
+ else:
497
+ bdCT_list.append('b')
498
+ if Include_bCT_states == "initial" and OS_list[i] >= OSthres :
499
+ bdCT_list = bdCT_list[:-1]
500
+ CT_candidate = CT_candidate[:-1]
501
+
502
+ #CT_candidate.append(i)
503
+
504
+ ######################## BRIGHT STATE DECISION ##################################################################
505
+
506
+ # Criteria 2: Oscillation strength
507
+ for j in P_LE_index :
508
+ f_list = list(data['f']) #
509
+ if f_list[j] > OSthres: # The state is an absorption state
510
+ if Include_bCT_states == "initial" or Include_bCT_states == "initial_or_final":
511
+ high_OS.append(f_list[j])
512
+ high_OS_index.append(high_OS.index(f_list[j]))
513
+ elif Include_bCT_states == "final": # bCT as CT states
514
+ if charge_frag_list[high_OS.index(f_list[j])] <= float(CT_thres):
515
+ high_OS.append(f_list[j])
516
+ high_OS_index.append(high_OS.index(f_list[j]))
517
+ # high_OS_index.append(high_OS.index(f_list[j]))
518
+ if len(high_OS) == 0:
519
+ raise RuntimeError("bCT is the only bright state within the OSthreshold, revise your fucking input accordingly")
520
+
521
+ # DECIDE LE State
522
+ LE_state_candidate = (np.max(high_OS)) # based on oscillator strength
523
+ LE_state = f_list.index(LE_state_candidate) +1 # +1 to convert python indexing to real electronic state
524
+ LE_energy = energy_list[LE_state -1] # -1 for real state to index
525
+
526
+ if verbose == True:
527
+ print('P_LE: ',LE_state_candidate)
528
+ print('P_LE_index: ',P_LE_index)
529
+ print('high_OS: ',high_OS)
530
+ print('high_OS_index: ',high_OS_index)
531
+ print('LE_energy = ',LE_energy, ' eV')
532
+ print('bdCT', bdCT_list)
533
+ else :
534
+ print('LE_energy = ',LE_energy, ' eV')
535
+ print('bdCT', bdCT_list)
536
+ print('--------------------------------')
537
+
538
+
539
+
540
+
541
+
542
+
543
+ # print(type(charge_frag_list[0]),Max_CT_states.type)
544
+
545
+
546
+
547
+ Max_CT_states = int(Max_CT_states)
548
+ # Criteria 2: energy ordering
549
+ if len(CT_candidate) < Max_CT_states:
550
+ print('The number of CT states is less than the maximum number of CT states is '+len(CT_candidate))
551
+ CT_state_order = CT_candidate
552
+ else:
553
+ CT_state_order = CT_candidate[0:Max_CT_states]
554
+ # get homosapiens readable format for CT states
555
+ CT_states = []
556
+
557
+ for i in CT_state_order:
558
+ CT_states.append(i+1) # +1 to convert python indexing to real electronic state
559
+ # get energy of CT states in eV
560
+ CT_energy_list=[]
561
+ for i in CT_state_order:
562
+ CT_energy_list.append(energy_list[i])
563
+
564
+ # get the charge of CT states on donor segment
565
+ CT_donor_charge = []
566
+ for i in CT_state_order:
567
+ CT_donor_charge.append(charge_frag_list[i])
568
+
569
+ # get the charge charge on the donor segment for different CT states
570
+ # dQ_D = Q_D of the i-th CT state - Q_D of the LE state
571
+
572
+ CT_dQ_D = []
573
+ for i in CT_state_order:
574
+ CT_dQ_D.append(charge_frag_list[i] - charge_frag_list[LE_state-1])
575
+
576
+
577
+
578
+
579
+ if verbose == True:
580
+ print('CT_states: ',CT_states)
581
+ print('CT_donor_charge: ',CT_donor_charge)
582
+ print('CT_dQ_D: ',CT_dQ_D)
583
+ print('CT_energy_list in eV: ',CT_energy_list)
584
+ # print('CT1_net: ',CT_net_candidate)
585
+ # print('CT1_net_index: ',CT_net_index)
586
+ #print('CT1_energy: ',CT_energy_list)
587
+ #print ('CT1_energy:',CT1_energy, ' eV')
588
+
589
+ else :
590
+ print ('CT_states', CT_states)
591
+ print ('CT_energy_list in eV: ',CT_energy_list)
592
+ #print ('CT1_energy:',CT1_energy, ' eV')
593
+ print('--------------------------------')
594
+
595
+
596
+ print('---------------------------------------------------------')
597
+ print('FINAL DECISION')
598
+ print("The CT states are :", CT_states)
599
+ print("The CT states are :", CT_energy_list)
600
+ #@print("The CT2 state is :", CT2_state)
601
+
602
+ result = {'GR' : 0, 'LE': LE_state}
603
+ for ind, state in enumerate(CT_states):
604
+ result['CT'+str(ind+1)] = state
605
+ # result = {'GR': 0, 'LE': LE_state, 'CT1':CT1_state, 'CT2': CT2_state}
606
+ energies =[0, LE_energy] # list of energy in eV
607
+ for ct_ene in CT_energy_list:
608
+ energies.append(ct_ene)
609
+ return result, energies, CT_dQ_D, CT_donor_charge, bdCT_list
610
+
611
+
612
+
613
+ def get_charges(N, STATE, CASE, filedir, charge_dir, name, prefname, charge_type, Drange, Brange, Arange, QChem_version, scaling = None , verbose = True):
614
+
615
+ """
616
+ N: number of atoms
617
+ STATE: get Mulliken charges of the STATEth singlet state from QCHEM output file
618
+ filedir: qchem.out at filedir, where contains the Q-Chem charge calculation
619
+ output charge saved to filedir/prefname.txt
620
+
621
+ name.log is the quantum cheistry output results containing charges
622
+ preface
623
+
624
+ scaling would either be None (default) or "AMBER"
625
+ Usage :
626
+ -----------------------
627
+ N=207
628
+ STATE=18 , index based on qchem output list.
629
+ CASE='PI'
630
+ name='gmm_cc_xy_0'
631
+ charge_dir='/xspace/db4271/ST_Rate/data/QC_Calc/gmm_cc_xy/gmm_cc_xy_0_BNL_25states_w157/mulliken_charge'
632
+
633
+ ###
634
+ get_charges(N,STATE,CASE,charge_dir,name)
635
+
636
+ -------------------------------------
637
+ More details
638
+
639
+ scaling = "AMBER"
640
+ hartree2kcalmol = 627.51
641
+ Angs2Bohr = 0.5291772
642
+ # in Amber.parm E(in Kcal/mol) = ( q1 * q2 ) /r(in Angs)
643
+ # q in electron charge unit
644
+ Scale=np.sqrt(hartree2kcalmol*Angs2Bohr) # scaling for amber formatted charge
645
+
646
+ """
647
+ ordersD = np.fromstring(Drange, dtype=int, sep='-')#Drange.split(',')
648
+ ordersA = np.fromstring(Arange, dtype=int, sep='-') #
649
+ ordersB = np.fromstring(Brange, dtype=int, sep='-')#D
650
+ systemSeg = ''
651
+ if len(ordersB) == 0:
652
+ if ordersA[1] + ordersD[1] - ordersA[0] - ordersD[0] + 2 == N:
653
+ systemSeg = systemSeg + 'DA'
654
+ else:
655
+ systemSeg
656
+
657
+ if ordersD[1] > ordersA[1]:
658
+ systemSeg = 'AD'
659
+ else:
660
+ systemSeg = 'DA'
661
+
662
+ print('sysseg', systemSeg)
663
+ output_file= f'{filedir}/{name}.out'
664
+ print(output_file)
665
+ #Reading line by line from the output file
666
+ lines = []
667
+ with open(output_file) as f:
668
+ lines = f.readlines()
669
+ #print(lines[-11])
670
+ if QChem_version == '4':
671
+ skip = -11
672
+ elif QChem_version == '6':
673
+ skip = -7
674
+ qchem4int = -11
675
+ qchem6int = -7
676
+ while (lines[skip] != ' * Thank you very much for using Q-Chem. Have a nice day. *\n'):
677
+ print(lines[skip])
678
+ time.sleep(1)
679
+ with open(output_file) as f:
680
+ lines = f.readlines()
681
+
682
+ #Find section of interest
683
+ if charge_type == 'Mulliken':
684
+ if STATE == 0:
685
+ keywords_to_find = ' Ground-State Mulliken Net Atomic Charges\n'
686
+ elif STATE < 10:
687
+ keywords_to_find = ' TDA Excited State '+ str(STATE) +': Mulliken Net Atomic Charges\n'
688
+ else:
689
+ keywords_to_find = ' TDA Excited State '+ str(STATE) +': Mulliken Net Atomic Charges\n'
690
+ else:
691
+ raise Exception(charge_type + ' are NOT defined in CTRAMER' )
692
+ return -1
693
+
694
+ # capture the section
695
+ count = 0
696
+ lines_after_title=3 # this is QCHEM 4.4. formatted mulliken charge
697
+ my_charge_section=[]
698
+ for line in lines:
699
+ count += 1
700
+ if line == keywords_to_find :
701
+ start = count -1 # to include the title too
702
+ end = count + lines_after_title + N
703
+ print('start = ', start+4)
704
+ print('end = ',end)
705
+ contents=lines[start+4:end]
706
+ #print(contents)
707
+ charge_data = contents
708
+ ############################################################
709
+ savefile = f'{charge_dir}/charge_{CASE}_S{str(STATE)}.txt'
710
+ savefile2 = f'{charge_dir}/charge_{CASE}_'+prefname+'.txt'
711
+
712
+ with open(savefile, "w") as output:
713
+ #for row in contents:
714
+ # output.write(str(row) + '\n')
715
+ if systemSeg == "AD":
716
+ for i in range(ordersD[1] - ordersD[0] + 1):
717
+ output.write(str(i+1) + ' ' + str(charge_data[i+ordersA[1]-ordersA[0]+1]) + '\n')
718
+ for i in range(ordersA[1] - ordersA[0] + 1):
719
+ output.write(str(i+1+ordersD[1]-ordersD[0]+1) + ' ' + str(charge_data[i]) + '\n')
720
+ else:
721
+ for ind, row in enumerate(charge_data):
722
+ output.write(str(ind+1) + ' ' + str(row) + '\n')
723
+
724
+ Qchem_ver = 6
725
+ if Qchem_ver == 6:
726
+ charge_table= pd.read_table(savefile, skiprows= 0, delim_whitespace=True,names=["Order", "No_Atom", "Atoms", '(a.u.)'] )
727
+ print(charge_table.columns)
728
+ else:
729
+ charge_table= pd.read_table(savefile, skiprows= 0, delim_whitespace=True,names=["Order", "No_Atom", "Atoms", '(a.u.)'] )
730
+
731
+ hartree2kcalmol = 627.51
732
+ Angs2Bohr = 0.5291772
733
+ # in Amber.parm E(in Kcal/mol) = ( q1 * q2 ) /r(in Angs)
734
+ # q in electron charge unit
735
+ Scale=np.sqrt(hartree2kcalmol*Angs2Bohr) # scaling for amber formatted charge
736
+
737
+ charge_data=charge_table['(a.u.)']#[1:]
738
+ with open(savefile2, "w") as output:
739
+ count = 0
740
+ if systemSeg == "AD":
741
+ for ind, row in enumerate(charge_data):
742
+ output.write(str(ind+1) + ' ' + str(row) + '\n')
743
+ #for i in range(ordersD[1] - ordersD[0] + 1):
744
+ # output.write(str(i+1) + ' ' + str(charge_data[i+ordersA[1]-ordersA[0]+1]) + '\n')
745
+ #for i in range(ordersA[1] - ordersA[0] + 1):
746
+ # output.write(str(i+1+ordersD[1]-ordersD[0]+1) + ' ' + str(charge_data[i]) + '\n')
747
+ else:
748
+ for ind, row in enumerate(charge_data):
749
+ output.write(str(ind+1) + ' ' + str(row) + '\n')
750
+ #for ind, row in enumerate(charge_data):
751
+ # count += 1
752
+ # if scaling == "AMBER" :
753
+ # output.write(str(count) + ' ' + str(row*Scale) + '\n')
754
+ # else:
755
+ # output.write(str(count) + ' ' + str(row) + '\n')
756
+ if verbose == True :
757
+ print('The charges have been saved to the following two files:')
758
+ print(savefile)
759
+ print(savefile2)
760
+
761
+ def replace_charge_to_prmtop(No_Atoms, newfiledir, old_prmtop, charge_file, new_name):
762
+ """
763
+ Currently work for replacing charge to prmtop up to 4 Case
764
+
765
+ usage:
766
+
767
+ filedir='/xspace/db4271/ST_Rate/data/QC_Calc/gmm_cc_xy/gmm_cc_xy_0_BNL_25states_w157/mulliken_charge'
768
+ case_name='gmm_cc_xy_0_THF'
769
+ No_Atoms = 207
770
+ charge_list =['GR','PI','CT1','CT2']
771
+ old_prmtop = f'{filedir}/{case_name}.prmtop'
772
+ #---------------------------------------------------------------
773
+ replace_charge_to_prmtop(No_Atoms, filedir, case_name,old_prmtop, charge_list)
774
+
775
+ """
776
+
777
+ hartree2kcalmol = 627.51
778
+ Angs2Bohr = 0.5291772
779
+ # in Amber.parm E(in Kcal/mol) = ( q1 * q2 ) /r(in Angs)
780
+ # q in electron charge unit
781
+ Scale=np.sqrt(hartree2kcalmol*Angs2Bohr) # scaling for amber formatted charge
782
+
783
+ #rounding up
784
+ nrow = math.ceil(No_Atoms/5) # in amber charge section are divided into 5 columns
785
+
786
+ ######### Defining input output file
787
+
788
+ new_prmtop=f'{newfiledir}/{new_name}.prmtop'
789
+ print(new_prmtop)
790
+ #[f'{filedir}/{case_name}_{charge_list[0]}.prmtop',
791
+ #f'{filedir}/{case_name}_{charge_list[1]}.prmtop',
792
+ #f'{filedir}/{case_name}_{charge_list[2]}.prmtop',
793
+ #f'{filedir}/{case_name}_{charge_list[3]}.prmtop']
794
+ chargefile = charge_file
795
+ #[f'{filedir}/charge_{charge_list[0]}.txt',
796
+ #f'{filedir}/charge_{charge_list[1]}.txt',
797
+ #f'{filedir}/charge_{charge_list[2]}.txt',
798
+ #f'{filedir}/charge_{charge_list[3]}.txt']
799
+ #charge_top = {charge_list[0] :new_prmtop[0], charge_list[1] :new_prmtop[1],charge_list[2]:new_prmtop[2],charge_list[3]:new_prmtop[3]}
800
+ #charge_file = {charge_list[0] :chargefile_list[0],charge_list[1] :chargefile_list[1],charge_list[2]:chargefile_list[2],charge_list[3]:chargefile_list[3]}
801
+ #########################33
802
+ #Scanning old_prmtop
803
+
804
+
805
+ ochg = []
806
+ inprm = open(old_prmtop,'r')
807
+ #print ('\n open input prmtop =',old_prmtop)
808
+
809
+ lines = inprm.readlines()
810
+ m=0
811
+ for line in lines:
812
+ res1 = re.findall(r'%FLAG CHARGE',line)
813
+ if res1 !=[]:
814
+ n=lines.index(line)
815
+ m = n
816
+ #print(m)
817
+
818
+ for i in range(m+2,m+2+nrow):
819
+ tt=lines[i].split()
820
+ for i in range(len(tt)):
821
+ ochg.append(float(tt[i]))
822
+
823
+ #print('.prmtop to be replaced =', old_prmtop)
824
+ #################################################
825
+
826
+ #for i in charge_list:
827
+ #print('replacing charge with charge on ', i , 'state')
828
+
829
+ inchg=np.loadtxt(charge_file,unpack=True,usecols=[1])
830
+
831
+ new_prmtop = new_prmtop
832
+ #print('new .prmtop file =', new_prmtop)
833
+
834
+ outprm=open(new_prmtop,'w')
835
+ #========replace charge==========
836
+ for i in range(No_Atoms):
837
+ ochg[i]=inchg[i]*Scale
838
+
839
+ n0=0
840
+ for i in range(len(lines)):
841
+ if i>m+1 and i<m+2+nrow:
842
+ for n in range(5):
843
+ k=n0*5+n
844
+ outprm.write('{:16.8E}'.format(ochg[k]))
845
+ n0 +=1
846
+ # print(n0)
847
+ outprm.write('\n')
848
+ else:
849
+ outprm.write('{}'.format(lines[i]))
850
+ print(new_prmtop+', the new prmtop is generated ')
851
+
852
+ def get_coupling(qchem_output_dir,name, state1, state2, Nstate):
853
+ Nstate = int(Nstate)
854
+ """
855
+ acquiring FCD coupling for state of interest
856
+
857
+ """
858
+
859
+ output_file= f'{qchem_output_dir}/{name}.out'
860
+ outCoup = f'{qchem_output_dir}/{name}_coupling.out'
861
+
862
+ #Reading line by line from the output file
863
+ lines = []
864
+ with open(output_file) as f:
865
+ lines = f.readlines()
866
+
867
+
868
+ contents = []
869
+ count = 0
870
+ keywords_to_find = ' FCD Couplings Between Singlet Excited States\n'
871
+
872
+ # total pairwise combination (N) = n_factorial/(n_min_r_factorial * 2); n = Nstate
873
+ N = int(math.factorial(Nstate) / (2 * math.factorial(Nstate-2)))
874
+ # print(N)
875
+ skip_header = 3
876
+ include_footer = 7
877
+ #N = 310 # resolve this total number of lines
878
+ for line in lines:
879
+ count += 1
880
+ if line == keywords_to_find :
881
+ start = count + skip_header # to include the title too
882
+ end = count + N + skip_header
883
+
884
+ #print('start = ', start)
885
+ #print('end = ',end)
886
+ contents=lines[start:end]
887
+ raw_start =start - skip_header
888
+ raw_end = end -skip_header + include_footer
889
+ raw_contents = lines[raw_start:raw_end]
890
+ # ############################################################
891
+ savefile = f'{qchem_output_dir}/FCD_coupling_raw.txt'
892
+ #savefile2 = f'{filedir}/FCD_coupling_{CASE}.txt'
893
+
894
+ with open(savefile, "w") as output:
895
+ for row in contents:
896
+ output.write(str(row) + '\n')
897
+ test_table= pd.read_table(savefile, header=None,delim_whitespace=True )
898
+ a = state1
899
+ b = state2
900
+ coupling = [] # FCD coupling squared
901
+ for i in range(len(test_table)):
902
+ #column[0,1,2,3,4,5,6,7] = state A, state B , x, y , z, FCD Coupling(ev),
903
+ if test_table[0][i] == a and test_table[1][i] == b :
904
+ c = test_table[5][i]
905
+ print("coupling coefficient in eV between state ", a, " and " , b , " : ", c)
906
+ print("coupling^2 coefficient between state ", a, " and " , b , " : ", c*c)
907
+ coupling.append(c)
908
+ elif test_table[0][i] == b and test_table[1][i] == a :
909
+ c = test_table[5][i]
910
+ print("coupling coefficient in eV between state ", a, " and " , b , " : ", c)
911
+ print("coupling^2 coefficient between state ", a, " and " , b , " : ", c*c)
912
+ coupling.append(c)
913
+ return coupling
914
+
915
+
916
+ def construct_prmtop_inter(template_dir,running_dir,testing_str,case,Drange,Arange,Brange,
917
+ CT_donor_fragments,CT_acceptor_fragment,
918
+ solute_dir,solvent_dir,
919
+ solute_resname,solvent_resname,solvent_num,
920
+ box_size,center_of_mass,force_field_type,N_cis,charge_file, dependency=''):
921
+ """
922
+ Create prmtop template with net zero charge
923
+ 1. prepare the pdb file by their own in the target running folder first
924
+
925
+ template_dir: slrum script template for the project
926
+ running_dir: where to run this quantum chemistry jobs and prepare the force field
927
+ testing_str: a string containing several space separated values utilized as part of the name of quantum chemistry jobs
928
+ case: name to specify the purpose or subject of calculation like `triad`
929
+ solvent_dir: solvent related quantum chemistry calculation results and structure files
930
+ solvent_name: name abbriviation of the solvent, usually 3 captial letters
931
+ solute_name: name abbriviation of the solute, usually short and understandable
932
+
933
+ solvent_num: number of solvent, int
934
+ box_size: length of cubic simulation box, unit in A
935
+ center_of_mass: center of mass of the solute with 3-D vector coordinate (center_of_mass,center_of_mass,center_of_mass), unit in A
936
+ force_field_type: name of the force field utilized to describe the system
937
+ charge_file: zero-charge file or state-dependent charge file utilized to constrcut the FF
938
+
939
+ N_cis: number of singlets are calculated, int
940
+ case: series name for the calculation
941
+
942
+ This function prepare and submit prmtop construction job based on a construct_prmtop_template.sh
943
+
944
+ other parameter to control the construc prmptop such as solvent type, no of solvent molecule
945
+ box size , etc will be included in next update
946
+
947
+ check the template for platform and cluster specific parameters
948
+ in the next release the cluster control can be performed from external function ctr.job_submit_setup()
949
+ """
950
+
951
+ construct_prmtop_file = shell_copy_template(template_dir,running_dir, filename='construct_prmtop_inter')
952
+ os.chdir(running_dir)
953
+ QC_DIR = f'{running_dir}'
954
+ if len(solute_dir.split(",")) == 1:
955
+ A_dir = solute_dir
956
+ D_dir = solute_dir
957
+ elif len(solute_dir.split(",")) == 2:
958
+ D_dir = solute_dir.split(",")[0]
959
+ A_dir = solute_dir.split(",")[1]
960
+ if len(solvent_dir.split(",")) == 1:
961
+ a_dir = solvent_dir
962
+ d_dir = solvent_dir
963
+ elif len(solvent_dir.split(",")) == 2:
964
+ d_dir = solvent_dir.split(",")[0]
965
+ a_dir = solvent_dir.split(",")[1]
966
+ # d_dir = solvent_dir.split(",")[0]
967
+ # a_dir = solvent_dir.split(",")[1]
968
+
969
+ if len(solute_resname.split(",")) == 2:
970
+ D_res = solute_resname.split(",")[0]
971
+ A_res = solute_resname.split(",")[1]
972
+ if len(solvent_resname.split(",")) == 2:
973
+ d_res = solvent_resname.split(",")[0]
974
+ a_res = solvent_resname.split(",")[1]
975
+
976
+ solvent_name = d_res + a_res
977
+ solute_name = solute_name1 = solute_resname
978
+ sed_inplace(construct_prmtop_file,'WORKDIR=','WORKDIR='+QC_DIR)
979
+ sed_inplace(construct_prmtop_file,'SRCDIR=','SRCDIR='+template_dir)
980
+ sed_inplace(construct_prmtop_file,'RUNDIR=','RUNDIR='+QC_DIR)
981
+ sed_inplace(construct_prmtop_file,'system=','system='+case+'_')
982
+ sed_inplace(construct_prmtop_file,'GIVEN_STRUC=','GIVEN_STRUC='+ testing_str)
983
+
984
+ sed_inplace(construct_prmtop_file,"D_resname=","D_resname="+D_res)
985
+ sed_inplace(construct_prmtop_file,"A_resname=","A_resname="+A_res)
986
+ sed_inplace(construct_prmtop_file,"d_resname=","d_resname="+d_res)
987
+ sed_inplace(construct_prmtop_file,"a_resname=","a_resname="+a_res)
988
+
989
+ sed_inplace(construct_prmtop_file,"D_dir=","D_dir="+D_dir)
990
+ sed_inplace(construct_prmtop_file,"A_dir=","A_dir="+A_dir)
991
+ sed_inplace(construct_prmtop_file,"d_dir=","d_dir="+d_dir)
992
+ sed_inplace(construct_prmtop_file,"a_dir=","a_dir="+a_dir)
993
+
994
+ sed_inplace(construct_prmtop_file,'forcefield=gaff','forcefield='+force_field_type)
995
+ sed_inplace(construct_prmtop_file,'box_side=60','box_side='+str(box_size))
996
+
997
+ sed_inplace(construct_prmtop_file,'solvent_mol=2700','solvent_mol='+str(solvent_num))
998
+ sed_inplace(construct_prmtop_file,'solvent_dir=','solvent_dir='+solvent_dir)
999
+ sed_inplace(construct_prmtop_file,'solvent=','solvent='+solvent_name)
1000
+
1001
+ sed_inplace(construct_prmtop_file,'com=30','com='+str(center_of_mass))
1002
+ sed_inplace(construct_prmtop_file,'chargefile=','chargefile='+charge_file)
1003
+ sed_inplace(construct_prmtop_file,'code=','code='+solute_name)
1004
+ sed_inplace(construct_prmtop_file,'solute=','solute='+solute_name1)
1005
+
1006
+ sed_inplace(construct_prmtop_file,'STATE_NUM=','STATE_NUM='+str(N_cis))
1007
+
1008
+ os.chdir(running_dir)
1009
+ # if dependency == '':
1010
+ # data = os.popen('sbatch construct_prmtop_flexible.sh').read()
1011
+ # else :
1012
+ # data = os.popen('sbatch --dependency=afterok:'+dependency+ ' construct_prmtop_flexible.sh').read()
1013
+ data = os.popen('sh construct_prmtop_inter.sh').read()
1014
+ #os.chdir(basedir)
1015
+ return data
1016
+
1017
+ def construct_prmtop_intra(template_dir,running_dir,testing_str,case,Drange,Arange,Brange,
1018
+ CT_donor_fragments,CT_acceptor_fragment,
1019
+ solute_dir,solvent_dir,
1020
+ solute_resname,solvent_resname,solvent_num,
1021
+ box_size,center_of_mass,force_field_type,N_cis,charge_file, dependency=''):
1022
+ """
1023
+ Create prmtop template with net zero charge
1024
+ 1. prepare the pdb file by their own in the target running folder first
1025
+
1026
+ template_dir: slrum script template for the project
1027
+ running_dir: where to run this quantum chemistry jobs and prepare the force field
1028
+ testing_str: a string containing several space separated values utilized as part of the name of quantum chemistry jobs
1029
+ case: name to specify the purpose or subject of calculation like `triad`
1030
+ solvent_dir: solvent related quantum chemistry calculation results and structure files
1031
+ solvent_name: name abbriviation of the solvent, usually 3 captial letters
1032
+ solute_name: name abbriviation of the solute, usually short and understandable
1033
+
1034
+ solvent_num: number of solvent, int
1035
+ box_size: length of cubic simulation box, unit in A
1036
+ center_of_mass: center of mass of the solute with 3-D vector coordinate (center_of_mass,center_of_mass,center_of_mass), unit in A
1037
+ force_field_type: name of the force field utilized to describe the system
1038
+ charge_file: zero-charge file or state-dependent charge file utilized to constrcut the FF
1039
+
1040
+ N_cis: number of singlets are calculated, int
1041
+ case: series name for the calculation
1042
+
1043
+ This function prepare and submit prmtop construction job based on a construct_prmtop_template.sh
1044
+
1045
+ other parameter to control the construc prmptop such as solvent type, no of solvent molecule
1046
+ box size , etc will be included in next update
1047
+
1048
+ check the template for platform and cluster specific parameters
1049
+ in the next release the cluster control can be performed from external function ctr.job_submit_setup()
1050
+ """
1051
+
1052
+ construct_prmtop_file = shell_copy_template(template_dir,running_dir, filename='construct_prmtop_intra')
1053
+ os.chdir(running_dir)
1054
+ QC_DIR = f'{running_dir}'
1055
+ if len(solute_dir.split(",")) == 1:
1056
+ A_dir = solute_dir
1057
+ D_dir = solute_dir
1058
+ elif len(solute_dir.split(",")) == 2:
1059
+ D_dir = solute_dir.split(",")[0]
1060
+ A_dir = solute_dir.split(",")[1]
1061
+ if len(solvent_dir.split(",")) == 1:
1062
+ a_dir = solvent_dir
1063
+ d_dir = solvent_dir
1064
+ elif len(solvent_dir.split(",")) == 2:
1065
+ d_dir = solvent_dir.split(",")[0]
1066
+ a_dir = solvent_dir.split(",")[1]
1067
+ # d_dir = solvent_dir.split(",")[0]
1068
+ # a_dir = solvent_dir.split(",")[1]
1069
+
1070
+ if len(solute_resname.split(",")) == 2:
1071
+ D_res = solute_resname.split(",")[0]
1072
+ A_res = solute_resname.split(",")[1]
1073
+ elif len(solute_resname.split(",")) == 1:
1074
+ D_res = solute_resname
1075
+ A_res = ''
1076
+
1077
+ if len(solvent_resname.split(",")) == 2:
1078
+ d_res = solvent_resname.split(",")[0]
1079
+ a_res = solvent_resname.split(",")[1]
1080
+ elif len(solvent_resname.split(",")) == 1:
1081
+ d_res = solvent_resname
1082
+ a_res = ''
1083
+
1084
+ solvent_name = d_res + a_res
1085
+ solute_name = solute_name1 = solute_resname
1086
+ sed_inplace(construct_prmtop_file,'WORKDIR=','WORKDIR='+QC_DIR)
1087
+ sed_inplace(construct_prmtop_file,'SRCDIR=','SRCDIR='+template_dir)
1088
+ sed_inplace(construct_prmtop_file,'RUNDIR=','RUNDIR='+QC_DIR)
1089
+ sed_inplace(construct_prmtop_file,'system=','system='+case+'_')
1090
+ sed_inplace(construct_prmtop_file,'GIVEN_STRUC=','GIVEN_STRUC='+ testing_str)
1091
+
1092
+ sed_inplace(construct_prmtop_file,"D_resname=","D_resname="+D_res)
1093
+ sed_inplace(construct_prmtop_file,"A_resname=","A_resname="+A_res)
1094
+ sed_inplace(construct_prmtop_file,"d_resname=","d_resname="+d_res)
1095
+ sed_inplace(construct_prmtop_file,"a_resname=","a_resname="+a_res)
1096
+
1097
+ sed_inplace(construct_prmtop_file,"D_dir=","D_dir="+D_dir)
1098
+ sed_inplace(construct_prmtop_file,"A_dir=","A_dir="+A_dir)
1099
+ sed_inplace(construct_prmtop_file,"d_dir=","d_dir="+d_dir)
1100
+ sed_inplace(construct_prmtop_file,"a_dir=","a_dir="+a_dir)
1101
+
1102
+ sed_inplace(construct_prmtop_file,'forcefield=gaff','forcefield='+force_field_type)
1103
+ sed_inplace(construct_prmtop_file,'box_side=60','box_side='+str(box_size))
1104
+
1105
+ sed_inplace(construct_prmtop_file,'solvent_mol=2700','solvent_mol='+str(solvent_num))
1106
+ sed_inplace(construct_prmtop_file,'solvent_dir=','solvent_dir='+solvent_dir)
1107
+ sed_inplace(construct_prmtop_file,'solvent=','solvent='+solvent_name)
1108
+
1109
+ sed_inplace(construct_prmtop_file,'com=30','com='+str(center_of_mass))
1110
+ sed_inplace(construct_prmtop_file,'chargefile=','chargefile='+charge_file)
1111
+ sed_inplace(construct_prmtop_file,'code=','code='+solute_name)
1112
+ sed_inplace(construct_prmtop_file,'solute=','solute='+solute_name1)
1113
+
1114
+ sed_inplace(construct_prmtop_file,'STATE_NUM=','STATE_NUM='+str(N_cis))
1115
+
1116
+ os.chdir(running_dir)
1117
+ # if dependency == '':
1118
+ # data = os.popen('sbatch construct_prmtop_flexible.sh').read()
1119
+ # else :
1120
+ # data = os.popen('sbatch --dependency=afterok:'+dependency+ ' construct_prmtop_flexible.sh').read()
1121
+ data = os.popen('sh construct_prmtop_intra.sh').read()
1122
+ #os.chdir(basedir)
1123
+ return data # return
1124
+
1125
+ def get_charge_on_Donor(qchem_output_dir, name, Nstate):
1126
+ output_file= f'{qchem_output_dir}/{name}.out'
1127
+ str_to_find = ' Fragment Charges of Singlet Excited State with Nuclear Charges\n'
1128
+ #Reading line by line from the output file
1129
+ with open(output_file) as f:
1130
+ lines = f.readlines()
1131
+ start,end = 0,0
1132
+ for line in lines:
1133
+ if line == str_to_find :
1134
+ start = lines.index(line)+4
1135
+ end = lines.index(line)+Nstate+4
1136
+ data = lines[start:end]
1137
+ return data
1138
+
1139
+
1140
+ import pickle
1141
+
1142
+ def main_ConstructFF():
1143
+ dict_of_simulation = parse_input()
1144
+ # prepare for quantum chemistry simulation
1145
+ work_dir = dict_of_simulation['work_dir']
1146
+ # where we have the structure directory
1147
+ structure_dir = dict_of_simulation['structure_dir']
1148
+ # load the project folder
1149
+ project = dict_of_simulation['project']
1150
+ # get case id for the simulation
1151
+ caseid = dict_of_simulation['caseid']
1152
+ # get job list
1153
+ case_id_list = separate_idlist(caseid)
1154
+ # get list of job control token
1155
+ job_control = init_job_control(case_id_list)
1156
+ job_info = init_job_info(case_id_list)
1157
+ startime = time.time
1158
+ print("SubmitQC begins at "+str(startime))
1159
+ # print("Input parameters ")
1160
+ # print(simulation_parameter)
1161
+ for ind, ctr_ele in enumerate(job_control):
1162
+ print(ind, job_control)
1163
+ run_step3(ind, job_control, dict_of_simulation,job_info)
1164
+
1165
+
1166
+
1167
+ print(job_info)
1168
+ # write list to binary file
1169
+ def write_list(a_list):
1170
+ # store list in binary file so 'wb' mode
1171
+ with open(work_dir+'/listfile', 'wb') as fp:
1172
+ pickle.dump(a_list, fp)
1173
+ print('Done writing list into a binary file')
1174
+
1175
+ # Read list to memory
1176
+ def read_list():
1177
+ # for reading also binary mode is important
1178
+ with open(work_dir+'/listfile', 'rb') as fp:
1179
+ n_list = pickle.load(fp)
1180
+ return n_list
1181
+
1182
+
1183
+ write_list(job_info)
1184
+ job_info1 = read_list()
1185
+ print('info1 \n', job_info1)
1186
+ # run_submitQC(simulation_parameter)
1187
+ end_time = time.time
1188
+ print("SubmitQC ends at "+str(end_time))
1189
+
1190
+ if __name__ == "__main__":
1191
+ main_ConstructFF()