-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgenerate_spectra.py
More file actions
1962 lines (1676 loc) · 149 KB
/
Copy pathgenerate_spectra.py
File metadata and controls
1962 lines (1676 loc) · 149 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
from scipy import integrate
import time
import sys
import os
import numpy as np
import math
import cmath
from numba import config
import scipy.integrate
import scipy.interpolate
import spec_pkg.constants.constants as const
from spec_pkg.GBOM import FC2DES
from spec_pkg.GBOM import gbom
from spec_pkg.GBOM import extract_model_params_gaussian as gaussian_params
from spec_pkg.GBOM import extract_model_params_from_terachem as terachem_params
from spec_pkg.GBOM import hessian_to_GBOM as hess_to_gbom
from spec_pkg.linear_spectrum import linear_spectrum
from spec_pkg.nonlinear_spectrum import twoDES
from spec_pkg.solvent_model import solvent_model
from spec_pkg.cumulant import md_traj
from spec_pkg.cumulant import extract_MD_params_terachem as terachem_params_MD
from spec_pkg.params import params
from spec_pkg.Morse import morse
from spec_pkg.Morse import morse_2DES
# TODO ##########################################################################
# 1) Write simulation information to stdout (what calculation is done, how it #
# progresses etc. #
# 2) Expand the GBOM_MD type approaches. E-ZTFC fits in that framework, as do #
# a variety of other approaches. #
# 3) Make sure the input file format works smoothly with the GBOM batch format #
# ie the case where we have multiple GBOMs to average over (this could #
# be the E-FTFC type approach or other approaches). Make sure that we #
# can specify different amounts of frozen solvent environment per GBOM #
# 4) Interface with more electronic structure codes #
# 5) PIMD version of GBOM approaches? #
# 6) PIMD-bead version of MDtraj data type #
# 7) Expand nonlinear spectroscopy. Speed up 3rd order cumulant 2DES. Laser #
# pulse shapes as user defined input #
# 8) Curvilinear coordinates instead of normal mode coordinates for the GBOM #
# which will help with large amplitude motion for low frequency modes #
# that tend to break the Condon approximation #
# 9) Cumulant approach is only valid if energy gap fluctuations are Gaussian #
# We need to implement a measure of Gaussian-ness for the energy gap flucts #
# of the GBOM and calulate it in the beginning. #
#################################################################################
def print_banner(stdout):
stdout.write('\n')
stdout.write(' ###########################################################'+'\n')
stdout.write(' ###########################################################'+'\n')
stdout.write(' # __ __ _ ____ _ ____ #'+'\n')
stdout.write(r' # | \/ | ___ | / ___| ____ ___ ___| | _| _ \ _ __ #'+'\n')
stdout.write(r' # | |\/| |/ _ \| \___ \| ._ \ / _ \/ __| |/ / |_) | | | | #'+'\n')
stdout.write(' # | | | | (_) | |___) | |_) | __/ (__| <| __/| |_| | #'+'\n')
stdout.write(r' # |_| |_|\___/|_|____/| .__/ \___|\___|_|\_\_| \__, | #'+'\n')
stdout.write(' # |_| |___/ #'+'\n')
stdout.write(' ###########################################################'+'\n')
stdout.write(' ###########################################################'+'\n')
stdout.write(' # Version 0.1 #'+'\n')
stdout.write(' # Copyright (C) 2019-2020 Tim J. Zuehlsdorff. The source #'+'\n')
stdout.write(' # code is subject to the terms of the Mozilla Public #'+'\n')
stdout.write(' # License, v. 2.0. This program is distributed in the #'+'\n')
stdout.write(' # hope that it will be useful, but WITHOUT ANY WARRANTY. #'+'\n')
stdout.write(' # See the Mozilla Public License, v. 2.0 for details. #'+'\n')
stdout.write(' ###########################################################'+'\n')
stdout.write(' # Acknowledgements: #'+'\n')
stdout.write(' # The purpose of this code is to generate linear and non- #'+'\n')
stdout.write(' # linear optical spectra for a variety of realistic and #'+'\n')
stdout.write(' # simplified model systems in a variety of different #'+'\n')
stdout.write(' # approximations. #'+'\n')
stdout.write(' # The underlying algorithms implemented in this code are #'+'\n')
stdout.write(' # described in the following publications: #'+'\n')
stdout.write(' # 1) T. J. Zuehlsdorff, A. Montoya-Castillo, J. A. Napoli,#'+'\n')
stdout.write(' # T. E. Markland, and C. M. Isborn, J. Chem. Phys. 151 #'+'\n')
stdout.write(' # 074111 (2019). #'+'\n')
stdout.write(' # 2) T. J. Zuehlsdorff, H. Hong, L. Shi, and C. M. Isborn,#'+'\n')
stdout.write(' # J. Chem. Phys. 153, 044127 (2020). #'+'\n')
stdout.write(' # 3) T. J. Zuehlsdorff, and C. M. Isborn, J. Chem. Phys. #'+'\n')
stdout.write(' # 148, 024110 (2018). #'+'\n')
stdout.write(' # 4) T. J. Zuehlsdorff, J. A. Napoli, J. M. Milanese, T. #'+'\n')
stdout.write(' # E. Markland, and C. M. Isborn, J. Chem. Phys. 149, #'+'\n')
stdout.write(' # 024107 (2018). #'+'\n')
stdout.write(' # The code for computing Franck-Condon linear absorption #'+'\n')
stdout.write(' # and emission spectra is based on the algorithm des- #'+'\n')
stdout.write(' # cribed in: B. de Souza, F. Neese, and R. Izsak, J. #'+'\n')
stdout.write(' # Chem. Phys. 148, 034104 (2018). #'+'\n')
stdout.write(' # Part of the interface between MolSpeckPy and Terachem #'+'\n')
stdout.write(' # is based on code originally written by Ajay Khanna. #'+'\n')
stdout.write(' ###########################################################'+'\n'+'\n')
# Compute the absorption spectrum for a Morse oscillator with 2 frequencies coupled by
# a Duschinsky rotation
def compute_coupled_morse_absorption(param_list,coupled_morse,solvent,is_emission):
# first compute solvent response. This is NOT optional for the Morse oscillator, same
# as in the GBOM
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# figure out start and end values over which we compute the spectrum
# at the moment this is a Hack because we have no expression to analytically
# evaluate the average energy gap of the Morse oscillator.
E_start=param_list.E_adiabatic-param_list.spectral_window/2.0
E_end=param_list.E_adiabatic+param_list.spectral_window/2.0
# exact solution to the morse oscillator
if param_list.method=='EXACT':
coupled_morse.compute_exact_response(param_list.temperature,param_list.max_t,param_list.num_steps)
spectrum=linear_spectrum.full_spectrum(coupled_morse.exact_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_Duschinsky_coupled_exact_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
elif param_list.method=='FC_HARMONIC':
coupled_morse.compute_harmonic_FC_response_func(param_list.temperature,param_list.max_t,param_list.num_steps,False,False,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(coupled_morse.harmonic_fc_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_Duschinsky_harmonic_fc_spectrum.dat', spectrum,header='Energy (eV) Intensity (arb. units)')
# cumulant based approach:
elif param_list.method=='CUMULANT':
coupled_morse.compute_exact_corr(param_list.temperature,param_list.decay_length,param_list.num_steps*10,param_list.max_t*10.0)
np.savetxt('Morse_duschinsky_2nd_order_corr_real.dat',np.real(coupled_morse.exact_2nd_order_corr))
temp_func=np.real(coupled_morse.exact_2nd_order_corr)
temp_func[:,1]=np.imag(coupled_morse.exact_2nd_order_corr[:,1])
np.savetxt('Morse_duschinsky_2nd_order_corr_imag.dat',temp_func)
coupled_morse.compute_spectral_dens()
np.savetxt('Morse_duschinsky_spectral_dens.dat',coupled_morse.spectral_dens)
coupled_morse.compute_2nd_order_cumulant_response(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(coupled_morse.cumulant_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_Duschinsky_second_order_cumulant_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# Andres Hybrid approach
elif param_list.method=='CUMUL_FC_SEPARABLE':
# Set average energy gap for GBOM
coupled_morse.eff_gbom.calc_omega_av_qm(param_list.temperature,is_emission)
coupled_morse.compute_cumul_fc_hybrid_response_func(param_list.temperature,param_list.decay_length,param_list.max_t,param_list.num_steps,is_emission,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(coupled_morse.hybrid_cumul_fc_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_duschinsky_hybrid_cumul_harmonic_FC_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
sys.exit('Error: Unknown method '+param_list.method)
# currently the is_emission option does not work
def compute_morse_absorption(param_list,morse_oscs,solvent,is_emission):
# first compute solvent response. This is NOT optional for the Morse oscillator, same
# as in the GBOM
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# figure out start and end values over which we compute the spectrum
# at the moment this is a Hack because we have no expression to analytically
# evaluate the average energy gap of the Morse oscillator.
E_start=param_list.E_adiabatic-param_list.spectral_window/2.0
E_end=param_list.E_adiabatic+param_list.spectral_window/2.0
# exact solution to the morse oscillator
if param_list.method=='EXACT':
morse_oscs.compute_total_exact_response(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.herzberg_teller)
spectrum=linear_spectrum.full_spectrum(morse_oscs.total_exact_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_exact_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# The effective FC spectrum for this oscillator
elif param_list.method=='FC_HARMONIC':
morse_oscs.compute_harmonic_FC_response_func(param_list.temperature,param_list.max_t,param_list.num_steps,False,False,param_list.stdout) # NO emission and No Herzberg-Teller implemented at the moment
spectrum=linear_spectrum.full_spectrum(morse_oscs.harmonic_fc_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_harmonic_fc_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# cumulant based approach:
elif param_list.method=='CUMULANT':
morse_oscs.compute_total_corr_func_exact(param_list.temperature,param_list.decay_length,param_list.max_t*10.0,param_list.num_steps*10)
np.savetxt('Morse_oscs_2nd_order_corr_real.dat',np.real(morse_oscs.exact_2nd_order_corr))
temp_func=np.real(morse_oscs.exact_2nd_order_corr)
temp_func[:,1]=np.imag(morse_oscs.exact_2nd_order_corr[:,1])
np.savetxt('Morse_oscs_2nd_order_corr_imag.dat',temp_func)
morse_oscs.compute_spectral_dens()
np.savetxt('Morse_oscs_spectral_dens.dat',morse_oscs.spectral_dens)
morse_oscs.compute_2nd_order_cumulant_response(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.stdout,param_list.herzberg_teller)
spectrum=linear_spectrum.full_spectrum(morse_oscs.cumulant_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_second_order_cumulant_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# Andres Hybrid approach
elif param_list.method=='CUMUL_FC_SEPARABLE':
# Set average energy gap for GBOM
morse_oscs.eff_gbom.calc_omega_av_qm(param_list.temperature,is_emission)
morse_oscs.compute_cumul_fc_hybrid_response_func(param_list.temperature,param_list.decay_length,param_list.max_t,param_list.num_steps,is_emission,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(morse_oscs.hybrid_cumul_fc_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Morse_hybrid_cumul_harmonic_FC_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# nothing else implemented yet. However, in the future, we could have
# a 2nd order cumulant approach by analytically evaluating classical or
# quantum correlation functions.
else:
sys.exit('Error: Unknown method '+param_list.method)
# specific routines:
# compute absorption spectra and print them if chromophore model is defined purely a single GBOM
def compute_GBOM_absorption(param_list,GBOM_chromophore,solvent,is_emission):
# first compute solvent response
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# if this is an emission calculation, need to reset some standard gbom parameters:
if is_emission:
GBOM_chromophore.set_emission_variables()
# figure out start and end value for the spectrum.
if param_list.exact_corr:
GBOM_chromophore.calc_omega_av_qm(param_list.temperature,is_emission)
E_start=GBOM_chromophore.omega_av_qm-param_list.spectral_window/2.0
E_end=GBOM_chromophore.omega_av_qm+param_list.spectral_window/2.0
else:
GBOM_chromophore.calc_omega_av_cl(param_list.temperature,is_emission)
E_start=GBOM_chromophore.omega_av_cl-param_list.spectral_window/2.0
E_end=GBOM_chromophore.omega_av_cl+param_list.spectral_window/2.0
# Set an additional solvent emission shift if requried
if is_emission and param_list.add_emission_shift:
if param_list.exact_corr:
GBOM_chromophore.omega_av_qm=GBOM_chromophore.omega_av_qm-2.0*solvent.reorg
else:
GBOM_chromophore.omega_av_cl=GBOM_chromophore.omega_av_cl-2.0*solvent.reorg
E_start=E_start-2.0*solvent.reorg
E_end=E_end-2.0*solvent.reorg
if param_list.method=='ENSEMBLE':
GBOM_chromophore.calc_ensemble_response(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.qm_wigner_dist,is_emission,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.ensemble_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.qm_wigner_dist:
np.savetxt(param_list.GBOM_root+'_ensemble_spectrum_qm_wigner_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_ensemble_spectrum_boltzmann_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
elif param_list.method=='FC':
GBOM_chromophore.calc_fc_response(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.herzberg_teller,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.fc_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt(param_list.GBOM_root+'_FC_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
elif param_list.method=='EZTFC':
GBOM_chromophore.calc_eztfc_response(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.qm_wigner_dist,is_emission,param_list.herzberg_teller,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.eztfc_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.qm_wigner_dist:
np.savetxt(param_list.GBOM_root+'_EZTFC_spectrum_qm_wigner_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_EZTFC_spectrum_boltzmann_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
elif param_list.method=='CUMULANT':
if param_list.exact_corr:
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,False,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_exact_corr.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
# only compute third order cumulant if needed
if param_list.third_order:
GBOM_chromophore.calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
if param_list.cumulant_nongaussian_prefactor:
#generate ensemble spectra to extract statistics as was done in the GBOM scan
GBOM_chromophore.calc_ensemble_response(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.qm_wigner_dist,is_emission,param_list.stdout)
ensemble_spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.ensemble_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
y = ensemble_spectrum[:,1]
x = ensemble_spectrum[:,0]
y[np.where(y < 0.001)] = 0
vol = scipy.integrate.simpson(y, ensemble_spectrum[:,0], ensemble_spectrum[1,0] - ensemble_spectrum[0,0])
y_normalized = y/vol
mean = scipy.integrate.simpson(x*y_normalized,x, dx= x[1] - x[0])
var = scipy.integrate.simpson((x-mean)**2*y_normalized, x, dx=x[1]-x[0])
skew = scipy.integrate.simpson(((x-mean)**3 * y_normalized) ,x, dx= x[1] - x[0])/ (var**(3/2))
kurtosis = scipy.integrate.simpson(y_normalized * (x-mean)**4 / var**2, x, x[1] - x[0]) - 3
#build spline and predict prefactor, rescale g_3 exact
cofs = [0.5704207280544358,0.5121728697163654,0.19152366513038535,14.037923420679276,1.9225644473520938
,1.731540247289854,-0.2850403241337555,0.27133579735792684,-1.1394462432833181,1.2203032510849585, -0.48192256127602257, 0.30922580126562926,-3.5581880060082836,0.5262346303535038, 0.20572744884039815, 0.12231112351678848]
tx = [-0.45615384615384613,-0.45615384615384613,-0.45615384615384613,-0.45615384615384613,1.086923076923077,1.086923076923077
, 1.086923076923077,1.086923076923077]
ty = [-0.08476923076923078, -0.08476923076923078, -0.08476923076923078,-0.08476923076923078,1.6819999999999997,1.6819999999999997,1.6819999999999997,1.6819999999999997]
tck = (tx,ty,cofs,3,3)
spline = scipy.interpolate.SmoothBivariateSpline._from_tck(tck)
prefactor = spline(skew, kurtosis)
if prefactor < 0:
prefactor = 0
if prefactor > 1:
prefactor = 1
GBOM_chromophore.g3_exact[:,1] = prefactor * GBOM_chromophore.g3_exact[:,1]
#check if we're interpolating or extrapolating
p1,p2,p3,p4,p5 = [-0.5, 0.5],[0.1, -0.1],[0.1, 0.5],[0.66, 1.7],[1.1,1.7]
interpolate = False
C1,C2 = ((p5[1] - p2[1])/(p5[0] - p2[0])**2) * (skew - p2[0])**2 + p2[1], ((p4[1] - p3[1])/(p4[0] - p3[0])**2) * (skew - p3[0])**2 + p3[1]
if p1[0] <= skew and skew <= p3[0]:
if C1 <= kurtosis and kurtosis <= p1[1]:
interpolate = True
if p3[0] <= skew and skew <= p4[0]:
if C1<= kurtosis and kurtosis <= C2:
interpolate = True
if p4[0] <= skew and skew <= p5[0]:
if C1 <= kurtosis and kurtosis <= p4[1]:
interpolate = True
if interpolate:
print("PREFACTOR: ", prefactor, " SKEW: ", skew, " KURTOSIS: ", kurtosis, " VALUE LIES IN SAMPLED REGION")
else:
print("PREFACTOR: ", prefactor, " SKEW: ", skew, " KURTOSIS: ", kurtosis, " WARNING! VALUE LIES OUTSIDE OF SAMPLED REGION. THIS IS AN ESTIMATE")
else:
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,True,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_harmonic_qcf.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_chromophore.calc_g3_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
# Check if I need HT term:
if param_list.herzberg_teller:
GBOM_chromophore.compute_HT_term(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.decay_length,param_list.exact_corr,param_list.third_order,param_list.ht_dipole_dipole_only,is_emission,param_list.stdout)
GBOM_chromophore.calc_cumulant_response(param_list.third_order,param_list.exact_corr,is_emission,param_list.herzberg_teller)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.cumulant_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.exact_corr:
np.savetxt(param_list.GBOM_root+'_cumulant_spectrum_exact_corr.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_cumulant_spectrum_harmonic_qcf.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# now also print out resonance raman.
rr_spectrum=np.zeros((GBOM_chromophore.spectral_dens.shape[0],GBOM_chromophore.spectral_dens.shape[1]))
for i in range(GBOM_chromophore.spectral_dens.shape[0]):
rr_spectrum[i,0]=GBOM_chromophore.spectral_dens[i,0]
rr_spectrum[i,1]=GBOM_chromophore.spectral_dens[i,0]**2.0*GBOM_chromophore.spectral_dens[i,1]
if param_list.exact_corr:
np.savetxt(param_list.GBOM_root+'_resonance_raman_exact_corr.dat', rr_spectrum)
else:
np.savetxt(param_list.GBOM_root+'_resonance_raman_harmonic_qcf.dat', rr_spectrum)
# do all approaches, including qm wigner sampling and exact and approximate
# quantum correlation functions for the cumulant approach
elif param_list.method=='ALL':
GBOM_chromophore.calc_ensemble_response(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.qm_wigner_dist,is_emission,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.ensemble_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.qm_wigner_dist:
np.savetxt(param_list.GBOM_root+'_ensemble_spectrum_qm_wigner_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_ensemble_spectrum_boltzmann_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
GBOM_chromophore.calc_fc_response(param_list.temperature,param_list.num_steps,param_list.max_t, is_emission,param_list.herzberg_teller,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.fc_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt(param_list.GBOM_root+'_FC_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
GBOM_chromophore.calc_eztfc_response(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.qm_wigner_dist,is_emission,param_list.herzberg_teller,param_list.stdout)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.eztfc_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.qm_wigner_dist:
np.savetxt(param_list.GBOM_root+'_EZTFC_spectrum_qm_wigner_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_EZTFC_spectrum_boltzmann_dist.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
if param_list.exact_corr:
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,False,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_exact_corr.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
# only compute third order cumulant if needed
if param_list.third_order:
GBOM_chromophore.calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
else:
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,True,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_harmonic_qcf.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_chromophore.calc_g3_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list,g3_cutoff,param_list.stdout)
GBOM_chromophore.calc_cumulant_response(param_list.third_order,param_list.exact_corr, is_emission,param_list.herzberg_teller)
spectrum=linear_spectrum.full_spectrum(GBOM_chromophore.cumulant_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if param_list.exact_corr:
np.savetxt(param_list.GBOM_root+'_cumulant_spectrum_exact_corr.dat', spectrum,header='Energy (eV) Intensity (arb. units)')
else:
np.savetxt(param_list.GBOM_root+'_cumulant_spectrum_harmonic_qcf.dat', spectrum,header='Energy (eV) Intensity (arb. units)')
# now also print out resonance raman.
rr_spectrum=np.zeros((GBOM_chromophore.spectral_dens.shape[0],GBOM_chromophore.spectral_dens.shape[1]))
for i in range(GBOM_chromophore.spectral_dens.shape[0]):
rr_spectrum[i,0]=GBOM_chromophore.spectral_dens[i,0]
rr_spectrum[i,1]=GBOM_chromophore.spectral_dens[i,0]**2.0*GBOM_chromophore.spectral_dens[i,1]
if param_list.exact_corr:
np.savetxt(param_list.GBOM_root+'_resonance_raman_exact_corr.dat', rr_spectrum)
else:
np.savetxt(param_list.GBOM_root+'_resonance_raman_harmonic_qcf.dat', rr_spectrum)
else:
sys.exit('Error: Unknown method '+param_list.method)
# compute absorption spectra when chromophore model is given by a batch of GBOMS
def compute_GBOM_batch_absorption(param_list,GBOM_batch,solvent,is_emission):
# first compute solvent response
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# Now make sure that we have only a single average spectral window for the GBOM batch.
# also set the correct omega_av.
icount=0
average_Egap=0.0
while icount<GBOM_batch.num_gboms:
# figure out start and end value for the spectrum.
if param_list.exact_corr:
GBOM_batch.gboms[icount].calc_omega_av_qm(param_list.temperature,is_emission)
average_Egap=average_Egap+GBOM_batch.gboms[icount].omega_av_qm
else:
GBOM_batch.gboms[icount].calc_omega_av_cl(param_list.temperature,is_emission)
average_Egap=average_Egap+GBOM_batch.gboms[icount].omega_av_cl
icount=icount+1
average_Egap=average_Egap/(1.0*GBOM_batch.num_gboms)
E_start=average_Egap-param_list.spectral_window/2.0
E_end=average_Egap+param_list.spectral_window/2.0
if param_list.method=='FC':
# Compute FC response for all elements in the GBOM batch
icount=0
spectrum=np.zeros((param_list.num_steps,2))
while icount<GBOM_batch.num_gboms:
GBOM_batch.gboms[icount].calc_fc_response(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.herzberg_teller,param_list.stdout)
temp_spectrum=linear_spectrum.full_spectrum(GBOM_batch.gboms[icount].fc_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if icount==0:
spectrum=spectrum+temp_spectrum
else:
spectrum[:,1]=spectrum[:,1]+temp_spectrum[:,1]
icount=icount+1
spectrum[:,1]=spectrum[:,1]/(1.0*GBOM_batch.num_gboms)
np.savetxt(param_list.GBOM_root+'_E_FTFC_spectrum.dat', spectrum,header='Energy (eV) Intensity (arb. units)')
# cumulant spectrum for all elements in the GBOM batch. The result is the summed spectrum
elif param_list.method=='CUMULANT':
icount=0
spectrum=np.zeros((param_list.num_steps,2))
while icount<GBOM_batch.num_gboms:
if param_list.exact_corr:
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_batch.gboms[icount].calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
# only compute third order cumulant if needed
if param_list.third_order:
GBOM_batch.gboms[icount].calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
else:
GBOM_batch.gboms[icount].calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_batch.gboms[icount].calc_g3_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
GBOM_batch.gboms[icount].calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,param_list.exact_corr,is_emission)
GBOM_batch.gboms[icount].calc_cumulant_response(param_list.third_order,param_list.exact_corr,is_emission)
temp_spectrum=linear_spectrum.full_spectrum(GBOM_batch.gboms[icount].cumulant_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
if icount==0:
sd=GBOM_batch.gboms[icount].spectral_dens
spectrum=temp_spectrum
else:
sd[:,1]=sd[:,1]+GBOM_batch.gboms[icount].spectral_dens[:,1]
spectrum[:,1]=spectrum[:,1]+temp_spectrum[:,1]
icount=icount+1
sd[:,1]=sd[:,1]/(1.0*GBOM_batch.num_gboms)
np.savetxt(param_list.GBOM_root+'_av_spectral_dens.dat',sd)
spectrum[:,1]=spectrum[:,1]/(1.0*GBOM_batch.num_gboms)
np.savetxt(param_list.GBOM_root+'_E_cumulant_spectrum.dat', spectrum,header='Energy (eV) Intensity (arb. units)')
# compute an AVERAGE g2 and g3 and place that on the average energy gap of all GBOMs. This is
# equivalent of averaging the spectral density over different instances of the GBOM and then just
# computing a single, effective response function.
elif param_list.method=='CUMULANT_AV':
# get list of adiabatic energies and dipole moms.
energy_dipole=np.zeros((1,1))
if os.path.exists(param_set.E_opt_path):
energy_dipole=np.genfromtxt(param_set.E_opt_path)
else:
sys.exit('Error: Requested an Eopt_avCUMULANT type calculation but did not provide optimized vertical energy gaps and dipoles')
Eopt=energy_dipole[:,0]/const.Ha_to_eV
# compute average energy
Eopt_av=np.sum(Eopt)/(1.0*Eopt.shape[0])
Eopt_fluct=Eopt-Eopt_av # fluctuation of Eopt energies around common mean.
average_Eadiab=0.0
average_E00=0.0 # E00 and Eadiab are not the same.
for icount in range(GBOM_batch.num_gboms):
average_Eadiab=average_Eadiab+GBOM_batch.gboms[icount].E_adiabatic
average_E00=average_E00+GBOM_batch.gboms[icount].E_adiabatic+0.5*np.sum(GBOM_batch.gboms[icount].freqs_ex)-0.5*np.sum(GBOM_batch.gboms[icount].freqs_gs)
average_Eadiab=average_Eadiab/(1.0*GBOM_batch.num_gboms)
average_E00=average_E00/(1.0*GBOM_batch.num_gboms)
average_Egap=0.0
icount=0
while icount<GBOM_batch.num_gboms:
# Set E_00 to zero and calculate the lineshape function and energy gap. This
# guarantees that all cumulant spectra start at the same 0-0 transition
# Then reset gboms.omega_av and recompute it for 0-0 transitions set to zero.
# Then compute lineshape function for that setup. This will generate a cumulant
# spectrum with the 0-0 transition shifted to 0
GBOM_batch.gboms[icount].E_adiabatic=0.0
if param_set.exact_corr:
average_Egap=average_Egap+GBOM_batch.gboms[icount].omega_av_qm
GBOM_batch.gboms[icount].omega_av_qm=0.0
else:
average_Egap=average_Egap+GBOM_batch.gboms[icount].omega_av_cl
GBOM_batch.gboms[icount].omega_av_cl=0.0
icount=icount+1
average_Egap=average_Egap/(1.0*GBOM_batch.num_gboms)
delta_E_opt_E_adiab=Eopt_av-average_Eadiab # The average E_adiab value should be unchanged in Eopt_avFTFC
E_start=average_Egap-param_set.spectral_window/2.0
E_end=average_Egap+param_set.spectral_window/2.0
# NOW overwrite E_adiabatic and dipole moment for all GBOMS. Make sure that all GBOM's have a consistent 0-0 transition equal to average_E00
icount=0
while icount<GBOM_batch.num_gboms:
# convert from the constant E_00 to
GBOM_batch.gboms[icount].E_adiabatic=average_E00-0.5*np.sum(GBOM_batch.gboms[icount].freqs_ex)+0.5*np.sum(GBOM_batch.gboms[icount].freqs_gs)
#GBOM_batch.gboms[icount].E_adiabatic=average_E00
GBOM_batch.gboms[icount].dipole_mom=energy_dipole[icount,1]
# recompute corrected average energy gap:
if param_list.exact_corr:
GBOM_batch.gboms[icount].calc_omega_av_qm(param_list.temperature,is_emission)
else:
GBOM_batch.gboms[icount].calc_omega_av_cl(param_list.temperature,is_emission)
icount=icount+1
# now compute average response function. Important: Average response function, NOT lineshape function
average_response=np.zeros((param_list.num_steps,2),dtype=complex)
icount=0
while icount<GBOM_batch.num_gboms:
if param_list.exact_corr:
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_batch.gboms[icount].calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
# only compute third order cumulant if needed
if param_list.third_order:
GBOM_batch.gboms[icount].calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
else:
GBOM_batch.gboms[icount].calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_batch.gboms[icount].calc_g3_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
# build average response function:
for j in range(average_response.shape[0]):
if param_list.exact_corr:
average_response[j,0]=GBOM_batch.gboms[icount].g2_exact[j,0]
if param_list.third_order:
average_response[j,1]=average_response[j,1]+GBOM_batch.gboms[icount].dipole_mom*cmath.exp(-GBOM_batch.gboms[icount].g2_exact[j,1]-GBOM_batch.gboms[icount].g3_exact[j,1])
else:
average_response[j,1]=average_response[j,1]+GBOM_batch.gboms[icount].dipole_mom*cmath.exp(-GBOM_batch.gboms[icount].g2_exact[j,1])
else:
average_response[j,0]=GBOM_batch.gboms[icount].g2_cl[j,0]
if param_list.third_order:
average_response[j,1]=average_response[j,1]+GBOM_batch.gboms[icount].dipole_mom*cmath.exp(-GBOM_batch.gboms[icount].g2_cl[j,1]-GBOM_batch.gboms[icount].g3_cl[j,1])
else:
average_response[j,1]=average_response[j,1]+GBOM_batch.gboms[icount].dipole_mom*cmath.exp(-GBOM_batch.gboms[icount].g2_cl[j,1])
icount=icount+1
# now average:
average_response[:,1]=average_response[:,1]/(1.0*GBOM_batch.num_gboms)
# now build spectrum.
spectrum=np.zeros((average_response.shape[0],2))
for icount in range(GBOM_batch.num_gboms):
eff_response_func=average_response
for jcount in range(eff_response_func.shape[0]):
eff_response_func[jcount,1]=eff_response_func[jcount,1]*cmath.exp(1j*(Eopt_av-Eopt[icount])*eff_response_func[jcount,0]/math.pi)
temp_spectrum=linear_spectrum.full_spectrum(eff_response_func,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
np.savetxt('Eopt_spec_snapshot'+str(icount)+'.dat',temp_spectrum, header='Energy (eV) Intensity (arb. units)')
if icount==0:
spectrum=temp_spectrum
else:
spectrum[:,0]=temp_spectrum[:,0]
spectrum[:,1]=spectrum[:,1]+temp_spectrum[:,1]
spectrum[:,1]=spectrum[:,1]/(1.0*GBOM_batch.num_gboms)
np.savetxt(param_list.GBOM_root+'_Eopt_avcumulant_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
sys.exit('Unknown method for GBOM_BATCH linear spectrum: '+param_list.method)
# same as GBOM_MD absorption, but this time we have a batch of GBOMs
def compute_hybrid_GBOM_batch_MD_absorption(param_list,MDtraj,GBOM_batch,solvent,is_emission):
# first check if we need a solvent model:
if param_list.is_solvent:
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# now fix energy range
E_start=MDtraj.mean-param_list.spectral_window/2.0
E_end=MDtraj.mean+param_list.spectral_window/2.0
# initialize GBOM:
# if this is an emission calculation, need to reset some standard gbom parameters:
if is_emission:
for i in range(param_list.num_gboms):
GBOM_batch.gboms[i].set_emission_variables()
if param_list.exact_corr:
for i in range(param_list.num_gboms):
GBOM_batch.gboms[i].calc_omega_av_qm(param_list.temperature,is_emission)
else:
for i in range(param_list.num_gboms):
GBOM_batch.gboms[i].calc_omega_av_cl(param_list.temperature,is_emission)
print('omega av cl')
print(GBOM_batch.gboms[i].omega_av_cl)
# Andres 2nd order cumulant GBOM approach assuming that the energy gap operator is
# fully separable
if param_list.method=='CUMUL_FC_SEPARABLE':
# first compute 2nd order cumulant response for MD trajectory
MDtraj.calc_2nd_order_corr()
MDtraj.calc_spectral_dens(param_list.temperature_MD)
np.savetxt(param_list.MD_root+'MD_spectral_density.dat', MDtraj.spectral_dens)
MDtraj.calc_g2(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.stdout)
if param_list.third_order:
MDtraj.calc_3rd_order_corr(param_list.corr_length_3rd,param_list.stdout)
# technically, in 3rd order cumulant, can have 2 different temperatures again. one at
# which the MD was performed and one at wich the spectrum is simulated. Fix this...
MDtraj.calc_g3(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.low_freq_cutoff,param_list.g3_cutoff,param_list.stdout)
MDtraj.calc_cumulant_response(True,is_emission,False)
else:
MDtraj.calc_cumulant_response(False,is_emission,False)
# calculate 2nd order divergence for MD trajectory:
MDtraj.calc_2nd_order_divergence()
# Now compute 2nd order cumulant g2 for GBOM
if param_list.exact_corr:
for i in range(param_list.num_gboms):
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_batch.gboms[i].calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,False,is_emission)
#np.savetxt(param_list.GBOM_root+'_spectral_density_exact_corr.dat', GBOM_chromophore.spectral_dens)
GBOM_batch.gboms[i].calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
# check if this is a 3rd order cumulant calculation
if param_list.third_order:
GBOM_batch.gboms[i].calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
else:
for i in range(param_list.num_gboms):
GBOM_batch.gboms[i].calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,True,is_emission)
#np.savetxt(param_list.GBOM_root+'_spectral_density_exact_corr.dat', GBOM_chromophore.spectral_dens)
GBOM_batch.gboms[i].calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_batch.gboms[i].calc_g3_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
# calculate FC and 2nd order cumulant response functions for GBOM
for i in range(param_list.num_gboms):
GBOM_batch.gboms[i].calc_cumulant_response(param_list.third_order,param_list.exact_corr,is_emission,param_list.herzberg_teller)
GBOM_batch.gboms[i].calc_fc_response(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.herzberg_teller,param_list.stdout)
# compute 2nd order cumulant divergence:
GBOM_batch.gboms[i].calc_2nd_order_divergence(param_list.temperature,param_list.exact_corr)
# now build effective response function. What about dipole moment? Where does it come from? MD or GBOM? If condon approx is valid
# it doesnt matter
eff_response=np.zeros((MDtraj.cumulant_response.shape[0],2),dtype=complex)
eff_response[:,0]=MDtraj.cumulant_response[:,0]
num_gboms_averaged=0
for j in range(param_list.num_gboms):
# can i average over this GBOM? Check
# print('Divergence GBOM, Divergence MDtraj')
# print(GBOM_batch.gboms[j].second_order_divergence, MDtraj.second_order_divergence)
#if GBOM_batch.gboms[j].second_order_divergence<MDtraj.second_order_divergence:
num_gboms_averaged=num_gboms_averaged+1
for icount in range(eff_response.shape[0]):
# protect against divide by 0
if abs(GBOM_batch.gboms[j].cumulant_response[icount,1].real)>10e-30:
eff_response[icount,1]=eff_response[icount,1]+MDtraj.cumulant_response[icount,1]*GBOM_batch.gboms[j].fc_response[icount,1]/GBOM_batch.gboms[j].cumulant_response[icount,1]
else:
eff_response[icount,1]=eff_response[icount,1]+MDtraj.cumulant_response[icount,1]
eff_response[:,1]=eff_response[:,1]/(1.0*num_gboms_averaged)
# now we can compute the linear spectrum based on eff_response
# no need for solvent model. This is taken care of in the MD trajectory
if param_list.is_solvent:
spectrum=linear_spectrum.full_spectrum(eff_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
else:
spectrum=linear_spectrum.full_spectrum(eff_response,np.zeros((1,1)),param_list.num_steps,E_start,E_end,False,is_emission,param_list.stdout)
np.savetxt(param_list.GBOM_root+'_cumul_FC_separable_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
sys.exit('Error: Method '+param_list.method+' does not work with a mixed GBOM MD model.')
# compute absorption spectra when chromophore model is given by both GBOM batch and MD batch
# this is mainly relevant for E-ZTFC and related methods defined by ANDRES
def compute_hybrid_GBOM_MD_absorption(param_list,MDtraj,GBOM_chromophore,solvent,is_emission):
# first check if we need a solvent model:
if param_list.is_solvent:
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# now fix energy range
E_start=MDtraj.mean-param_list.spectral_window/2.0
E_end=MDtraj.mean+param_list.spectral_window/2.0
# initialize GBOM:
# if this is an emission calculation, need to reset some standard gbom parameters:
if is_emission:
GBOM_chromophore.set_emission_variables()
if param_list.exact_corr:
GBOM_chromophore.calc_omega_av_qm(param_list.temperature,is_emission)
else:
GBOM_chromophore.calc_omega_av_cl(param_list.temperature,is_emission)
# Andres 2nd order cumulant GBOM approach assuming that the energy gap operator is
# fully separable
if param_list.method=='CUMUL_FC_SEPARABLE':
# first compute 2nd order cumulant response for MD trajectory
MDtraj.calc_2nd_order_corr()
MDtraj.calc_spectral_dens(param_list.temperature_MD)
np.savetxt(param_list.MD_root+'MD_spectral_density.dat', MDtraj.spectral_dens)
MDtraj.calc_g2(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.stdout)
if param_list.third_order:
MDtraj.calc_3rd_order_corr(param_list.corr_length_3rd,param_list.stdout)
# technically, in 3rd order cumulant, can have 2 different temperatures again. one at
# which the MD was performed and one at wich the spectrum is simulated. Fix this...
MDtraj.calc_g3(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.low_freq_cutoff,param_list.g3_cutoff,param_list.stdout)
MDtraj.calc_cumulant_response(True,is_emission,False)
else:
MDtraj.calc_cumulant_response(False,is_emission,False)
# Now compute 2nd order cumulant g2 for GBOM
if param_list.exact_corr:
# spectral density not needed for calculation purposes in the GBOM. just print it out anyway for analysis
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,False,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_exact_corr.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_chromophore.calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
else:
GBOM_chromophore.calc_spectral_dens(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.decay_length,True,is_emission)
np.savetxt(param_list.GBOM_root+'_spectral_density_harmonic_qcf.dat', GBOM_chromophore.spectral_dens)
GBOM_chromophore.calc_g2_cl(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.stdout)
if param_list.third_order:
GBOM_chromophore.calc_g3_qm(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.four_phonon_term,param_list.g3_cutoff,param_list.stdout)
# calculate FC and 2nd order cumulant response functions for GBOM
GBOM_chromophore.calc_cumulant_response(param_list.third_order,param_list.exact_corr,is_emission,param_list.herzberg_teller)
GBOM_chromophore.calc_fc_response(param_list.temperature,param_list.num_steps,param_list.max_t,is_emission,param_list.herzberg_teller,param_list.stdout)
# now build effective response function
# HACK... DIVIDE OUT A CERTAIN PART OF THE LINESHAPE FUNCTION --> LONG TIMESCALE DIVERGENCE
GBOM_chromophore.calc_2nd_order_divergence(param_list.temperature,param_list.exact_corr)
print(GBOM_chromophore.second_order_divergence)
print(GBOM_chromophore.cumulant_response[1,:])
for icount in range(GBOM_chromophore.cumulant_response.shape[0]):
GBOM_chromophore.cumulant_response[icount,1]=GBOM_chromophore.cumulant_response[icount,1]*cmath.exp(GBOM_chromophore.second_order_divergence*GBOM_chromophore.cumulant_response[icount,0]**2.0)
eff_response=GBOM_chromophore.fc_response
for icount in range(eff_response.shape[0]):
eff_response[icount,1]=eff_response[icount,1]*MDtraj.cumulant_response[icount,1]/GBOM_chromophore.cumulant_response[icount,1]
# now we can compute the linear spectrum based on eff_response
if param_list.is_solvent:
spectrum=linear_spectrum.full_spectrum(eff_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
else:
spectrum=linear_spectrum.full_spectrum(eff_response,np.zeros((1,1)),param_list.num_steps,E_start,E_end,False,is_emission,param_list.stdout)
np.savetxt(param_list.GBOM_root+'_cumul_FC_separable_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
sys.exit('Error: Method '+param_list.method+' does not work with a mixed GBOM MD model.')
# compute absorption spectrum from pure MD input
# Solvent degrees of freedom are optional here. They can be added to provide additional
# Broadening but in principle all broadening should originate from the MD.
# Note that a pure MD trajectory can only be used to compute Ensemble or cumulant spectrum
def compute_MD_absorption(param_list,MDtraj,solvent,is_emission):
# first check if we need a solvent model:
if param_list.is_solvent:
solvent.calc_spectral_dens(param_list.num_steps)
solvent.calc_g2_solvent(param_list.temperature,param_list.num_steps,param_list.max_t,param_list.stdout)
solvent.calc_solvent_response(is_emission)
# now fix energy range
E_start=MDtraj.mean-param_list.spectral_window/2.0
E_end=MDtraj.mean+param_list.spectral_window/2.0
# now check if this is a cumulant or a classical ensemble calculation
if param_list.method=='CUMULANT':
MDtraj.calc_2nd_order_corr()
MDtraj.calc_spectral_dens(param_list.temperature_MD)
np.savetxt(param_list.MD_root+'MD_spectral_density.dat', MDtraj.spectral_dens)
MDtraj.calc_g2(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.stdout)
# check if we need to compute HT corrections:
if param_list.herzberg_teller:
print('COMPUTING HERZBERG TELLER TERM')
MDtraj.calc_ht_correction(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.corr_length_3rd,param_list.low_freq_cutoff,param_list.third_order,param_list.gs_reference_dipole,param_list.ht_dipole_dipole_only,is_emission,param_list.stdout)
print('Renormalized dipole mom vs standard dipole mom:')
print(np.dot(MDtraj.dipole_mom_av,MDtraj.dipole_mom_av),MDtraj.dipole_renorm**2.0, np.dot(MDtraj.dipole_reorg,MDtraj.dipole_reorg))
if param_list.third_order:
MDtraj.calc_3rd_order_corr(param_list.corr_length_3rd,param_list.stdout)
# technically, in 3rd order cumulant, can have 2 different temperatures again. one at
# which the MD was performed and one at wich the spectrum is simulated. Fix this...
MDtraj.calc_g3(param_list.temperature,param_list.max_t,param_list.num_steps,param_list.low_freq_cutoff,param_list.g3_cutoff,param_list.stdout)
if param_list.cumulant_nongaussian_prefactor:
#generate ensemble spectra to extract statistics as was done in the GBOM scan
MDtraj.calc_ensemble_response(param_list.max_t,param_list.num_steps)
if param_list.is_solvent:
ensemble_spectrum=linear_spectrum.full_spectrum(MDtraj.ensemble_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
else:
ensemble_spectrum=linear_spectrum.full_spectrum(MDtraj.ensemble_response,np.zeros((1,1)),param_list.num_steps,E_start,E_end,False,is_emission,param_list.stdout)
y = ensemble_spectrum[:,1]
x = ensemble_spectrum[:,0]
y[np.where(y < 0.001)] = 0
vol = scipy.integrate.simpson(y, ensemble_spectrum[:,0], ensemble_spectrum[1,0] - ensemble_spectrum[0,0])
y_normalized = y/vol
mean = scipy.integrate.simpson(x*y_normalized,x, dx= x[1] - x[0])
var = scipy.integrate.simpson((x-mean)**2*y_normalized, x, dx=x[1]-x[0])
skew = scipy.integrate.simpson(((x-mean)**3 * y_normalized) ,x, dx= x[1] - x[0])/ (var**(3/2))
kurtosis = scipy.integrate.simpson(y_normalized * (x-mean)**4 / var**2, x, x[1] - x[0]) - 3
#build spline and predict prefactor, rescale g_3 exact
cofs = [0.5704207280544358,0.5121728697163654,0.19152366513038535,14.037923420679276,1.9225644473520938
,1.731540247289854,-0.2850403241337555,0.27133579735792684,-1.1394462432833181,1.2203032510849585, -0.48192256127602257, 0.30922580126562926,-3.5581880060082836,0.5262346303535038, 0.20572744884039815, 0.12231112351678848]
tx = [-0.45615384615384613,-0.45615384615384613,-0.45615384615384613,-0.45615384615384613,1.086923076923077,1.086923076923077
, 1.086923076923077,1.086923076923077]
ty = [-0.08476923076923078, -0.08476923076923078, -0.08476923076923078,-0.08476923076923078,1.6819999999999997,1.6819999999999997,1.6819999999999997,1.6819999999999997]
tck = (tx,ty,cofs,3,3)
spline = scipy.interpolate.SmoothBivariateSpline._from_tck(tck)
prefactor = spline(skew, kurtosis)
if prefactor < 0:
prefactor = 0
if prefactor > 1:
prefactor = 1
MDtraj.g3[:,1] = prefactor * MDtraj.g3[:,1]
#check if we're interpolating or extrapolating
p1,p2,p3,p4,p5 = [-0.5, 0.5],[0.1, -0.1],[0.1, 0.5],[0.66, 1.7],[1.1,1.7]
interpolate = False
C1,C2 = ((p5[1] - p2[1])/(p5[0] - p2[0])**2) * (skew - p2[0])**2 + p2[1], ((p4[1] - p3[1])/(p4[0] - p3[0])**2) * (skew - p3[0])**2 + p3[1]
if p1[0] <= skew and skew <= p3[0]:
if C1 <= kurtosis and kurtosis <= p1[1]:
interpolate = True
if p3[0] <= skew and skew <= p4[0]:
if C1<= kurtosis and kurtosis <= C2:
interpolate = True
if p4[0] <= skew and skew <= p5[0]:
if C1 <= kurtosis and kurtosis <= p4[1]:
interpolate = True
if interpolate:
print("PREFACTOR: ", prefactor, " SKEW: ", skew, " KURTOSIS: ", kurtosis, " VALUE LIES IN SAMPLED REGION")
else:
print("PREFACTOR: ", prefactor, " SKEW: ", skew, " KURTOSIS: ", kurtosis, " WARNING! VALUE LIES OUTSIDE OF SAMPLED REGION. THIS IS AN ESTIMATE")
MDtraj.calc_cumulant_response(True,is_emission,param_list.herzberg_teller)
else:
MDtraj.calc_cumulant_response(False,is_emission,param_list.herzberg_teller)
# compute linear spectrum
if param_list.is_solvent:
spectrum=linear_spectrum.full_spectrum(MDtraj.cumulant_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
else:
# set solvent response to a zero dummy vector
spectrum=linear_spectrum.full_spectrum(MDtraj.cumulant_response,np.zeros((1,1)),param_list.num_steps,E_start,E_end,False,is_emission,param_list.stdout)
np.savetxt(param_list.MD_root+'MD_cumulant_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
# DO THIS LAST! CURRENTLY THIS OVERWRITES SD.
# Also print raman intensity:
resonance_raman=np.zeros((MDtraj.spectral_dens.shape[0],MDtraj.spectral_dens.shape[1]))
for i in range(resonance_raman.shape[0]):
resonance_raman[i,0]=MDtraj.spectral_dens[i,0]
resonance_raman[i,1]=MDtraj.spectral_dens[i,1]*MDtraj.spectral_dens[i,0]**2.0
np.savetxt(param_list.MD_root+'MD_resonance_raman.dat', resonance_raman)
# now do ensemble approach
elif param_list.method=='ENSEMBLE':
MDtraj.calc_ensemble_response(param_list.max_t,param_list.num_steps)
if param_list.is_solvent:
spectrum=linear_spectrum.full_spectrum(MDtraj.ensemble_response,solvent.solvent_response,param_list.num_steps,E_start,E_end,True,is_emission,param_list.stdout)
else:
# set solvent response to a zero dummy vector
spectrum=linear_spectrum.full_spectrum(MDtraj.ensemble_response,np.zeros((1,1)),param_list.num_steps,E_start,E_end,False,is_emission,param_list.stdout)
np.savetxt(param_list.MD_root+'MD_ensemble_spectrum.dat', spectrum, header='Energy (eV) Intensity (arb. units)')
else:
sys.exit('Error: Method '+param_list.method+' does not work with a pure MD based model. Set Method to ENSEMBLE or CUMULANT.')
# main driver #
# start timer.
start_time=time.time()
input_file=sys.argv[1]
if len(sys.argv)<3:
num_cores=1
else:
num_cores=int(sys.argv[2])
config.NUMBA_NUM_THREADS=num_cores
# parse input values
if os.path.exists(input_file):
param_set=params.params(input_file)
else:
sys.exit('Error: Could not find input file')
print('PARAMSET: NUM_FROZEN_ATOMS')
print(param_set.num_frozen_atoms)
print_banner(param_set.stdout)
param_set.stdout.write('Successfully parsed the input file!'+'\n')
param_set.stdout.write('Now starting spectrum calculation'+'\n')
# set up solvent model:
if param_set.is_solvent:
solvent_mod=solvent_model.solvent_model(param_set.solvent_reorg,param_set.solvent_cutoff_freq)
param_set.stdout.write('Created solvent model!'+'\n')
param_set.stdout.write('Solvent reorg: '+str(param_set.solvent_reorg)+' Ha'+'\n')
param_set.stdout.write('Cutoff frequency: '+str(param_set.solvent_cutoff_freq)+' Ha'+'\n')
# set up chromophore model
# pure GBOM model.
if param_set.model=='GBOM' or param_set.model=='MD_GBOM':
param_set.stdout.write('\n'+'Requested a GBOM model calculation with parameter: MODEL '+param_set.model+'\n'+'Constructing a GBOM model.'+'\n')
# sanity check:
if param_set.num_modes==0:
param_set.stdout.write('Error: Model GBOM requested but number of normal modes in the system is not set!')
sys.exit('Error: Model GBOM requested but number of normal modes in the system is not set!')
# single GBOM
if param_set.num_gboms==1:
param_set.stdout.write('This is a calculation involving only a single GBOM model with '+str(param_set.num_modes)+' normal modes.'+'\n')
# GBOM root is given. This means user requests reading params from Gaussian or Terachem
if param_set.GBOM_root!='':
if param_set.GBOM_input_code=='GAUSSIAN':
# build list of frozen atoms:
# CURRENTLY ONLY IMPLEMENTED FOR GAUSSIAN WITH HPMODES, NO HT EFFECTS AND SINGLE GBOM
if param_set.is_vertical_gradient:
param_set.stdout.write('Attempting to compute vertical gradinet GBOM model from the following Gaussian output files: '+'\n')
param_set.stdout.write(param_set.GBOM_root+'_gs.log'+'\t'+'\t'+param_set.GBOM_root+'_grad.log'+'\t'+'\n')
freqs_gs,freqs_ex,K,J=gaussian_params.construct_vertical_gradient_model(param_set.GBOM_root+'_gs.log',param_set.GBOM_root+'_grad.log',param_set.num_modes)
# need to implement adiabatic energy from vertical gradient and fix dipole mom to harmonic part.
param_set.E_adiabatic=gaussian_params.extract_adiabatic_freq(param_set.GBOM_root+'_vibronic.log') # for now just supply vibronic file
else:
param_set.stdout.write('Attempting to compute GBOM model from the following Gaussian output files: '+'\n')
param_set.stdout.write(param_set.GBOM_root+'_gs.log'+'\t'+param_set.GBOM_root+'_ex.log'+'\t'+param_set.GBOM_root+'_vibronic.log'+'\t'+'\n')
freqs_gs=gaussian_params.extract_normal_mode_freqs(param_set.GBOM_root+'_gs.log',param_set.num_modes)
freqs_ex=gaussian_params.extract_normal_mode_freqs(param_set.GBOM_root+'_ex.log',param_set.num_modes)
K=gaussian_params.extract_Kmat(param_set.GBOM_root+'_vibronic.log',param_set.num_modes)
J=np.zeros((freqs_gs.shape[0],freqs_gs.shape[0]))
if param_set.no_dusch:
counter=0
while counter<freqs_ex.shape[0]:
J[counter,counter]=1.0
counter=counter+1
param_set.dipole_mom=gaussian_params.extract_transition_dipole(param_set.GBOM_root+'_ex.log',param_set.target_excited_state)
param_set.E_adiabatic=gaussian_params.extract_adiabatic_freq(param_set.GBOM_root+'_vibronic.log')
else:
J=gaussian_params.extract_duschinsky_mat(param_set.GBOM_root+'_vibronic.log',param_set.num_modes)
param_set.dipole_mom=gaussian_params.extract_transition_dipole(param_set.GBOM_root+'_ex.log',param_set.target_excited_state)
param_set.E_adiabatic=gaussian_params.extract_adiabatic_freq(param_set.GBOM_root+'_vibronic.log')
# if requested, remove low frequency vibrational modes:
if param_set.freq_cutoff_gbom>0.0:
for i in range(freqs_gs.shape[0]):
if freqs_gs[i]<param_set.freq_cutoff_gbom:
freqs_ex[i]=freqs_gs[i]
J[i,:]=0.0
J[:,i]=0.0
J[i,i]=1.0
K[i]=0.0
GBOM=gbom.gbom(freqs_gs,freqs_ex,J,K,param_set.E_adiabatic,param_set.dipole_mom,param_set.stdout)
if param_set.herzberg_teller: