-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_analyses.py
1289 lines (997 loc) · 55.7 KB
/
run_analyses.py
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
# Script to run Eyring Model analyses
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from tqdm import tqdm
from scipy.interpolate import CubicSpline
from scipy.stats import truncnorm
import statsmodels.api as sm
from eyring_model import EyringModel, Path
# Define global constants
global kB
kB = 1.380649 * 10**-23 # Boltzmann (m^2 kg / s^2 K)
global h
h = 6.62607 * 10**-34 # Planck (m^2 kg / s)
global R
R = 1.9858775 * 10**-3 # universal gas (kcal / mol K)
def parallel_pores(dH_barrier, dS_barrier, dH_sigma, dS_sigma, n_paths=2000, n_jumps=200, T=300, multi=True, output='figs/hist_effective_individual_barriers_no_penalty.pdf'):
print(f'\nCalculating effective barriers and fractions of permeability for {n_paths} paths through the membrane...')
fig, ax = plt.subplots(3,1, figsize=(7.25,3.55), sharex=True)
# ALL MEMBRANE BARRIERS EQUAL
model_equal = EyringModel(T=T)
dist = 'equal'
params = {'mu' : np.array([dH_barrier, dS_barrier])}
print(f'\tfor equal barriers:')
# plot the membrane barrier distribution for each pore, overlapping
effective_barriers = np.zeros(n_paths)
all_barriers = []
for n in tqdm(range(n_paths)):
model_equal.add_Path(n_jumps=n_jumps, area=model_equal.area/n_paths)
model_equal.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
effective_barriers[n] = model_equal.paths[n].calculate_effective_barrier()
[all_barriers.append(b) for b in model_equal.paths[n].membrane_barriers]
sns.histplot(all_barriers, edgecolor='black', ax=ax[0], stat='density', color='tab:gray', alpha=0.5, label='individual barriers', linewidth=0.5)
permeability = model_equal.calculate_permeability()
effective_barrier_equal = model_equal.calculate_effective_barrier()
std_equal = np.std(all_barriers)
mean_equal = np.mean(all_barriers)
# save data as pandas DataFrame
df_equal = pd.DataFrame()
df_equal['pores'] = np.arange(1,n_paths+1)
df_equal['permeability'] = model_equal.permeabilities
df_equal['effective_barriers'] = effective_barriers
df_equal['permeability_percent'] = model_equal.permeabilities / model_equal.permeabilities.sum() * 100
df_equal.sort_values('permeability_percent', ascending=False, inplace=True)
df_equal['flux_fraction'] = df_equal['permeability_percent'].cumsum() / 100
df_equal['pore_fraction'] = np.arange(1,n_paths+1) / n_paths
df_equal.loc[len(df_equal.index)] = [0,0,0,0,0,0] # add zero row for ROC curve
sns.histplot(effective_barriers, color='tab:gray', linewidth=1, ax=ax[0],
stat='density', alpha=1, fill=False, label='single path effective barriers')
# NORMAL DISTRIBUTION OF BARRIERS
model_norm = EyringModel(T=T)
dist = 'normal'
params = {'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sigma**2,0],
[0,dS_sigma**2]])}
print(f'\tfor normal barriers:')
# plot the membrane barrier distribution for each pore, overlapping
effective_barriers = np.zeros(n_paths)
all_barriers = []
for n in tqdm(range(n_paths)):
model_norm.add_Path(n_jumps=n_jumps, area=model_norm.area/n_paths)
model_norm.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
effective_barriers[n] = model_norm.paths[n].calculate_effective_barrier()
[all_barriers.append(b) for b in model_norm.paths[n].membrane_barriers]
sns.histplot(all_barriers, binwidth=1, edgecolor='black', ax=ax[1], stat='density', color='tab:blue', alpha=0.5, label='individual barriers', linewidth=0.5)
permeability = model_norm.calculate_permeability()
effective_barrier_norm = model_norm.calculate_effective_barrier()
std_norm = np.std(all_barriers)
mean_norm = np.mean(all_barriers)
# save data as pandas DataFrame
df_norm = pd.DataFrame()
df_norm['pores'] = np.arange(1,n_paths+1)
df_norm['permeability'] = model_norm.permeabilities
df_norm['effective_barriers'] = effective_barriers
df_norm['permeability_percent'] = model_norm.permeabilities / model_norm.permeabilities.sum() * 100
df_norm.sort_values('permeability_percent', ascending=False, inplace=True)
df_norm['flux_fraction'] = df_norm['permeability_percent'].cumsum() / 100
df_norm['pore_fraction'] = np.arange(1,n_paths+1) / n_paths
df_norm.loc[len(df_norm.index)] = [0,0,0,0,0,0] # add zero row for ROC curve
sns.histplot(effective_barriers, binwidth=1, color='tab:blue', linewidth=1, ax=ax[1],
stat='density', alpha=1, fill=False, label='single path effective barriers')
# EXPONENTIAL DISTRIBUTION OF BARRIERS
model_exp = EyringModel(T=T)
dist = 'exponential'
params = {'beta' : np.array([dH_barrier, dS_barrier])}
print(f'\tfor exponential barriers:')
# plot the membrane barrier distribution for each pore, overlapping
effective_barriers = np.zeros(n_paths)
all_barriers = []
for n in tqdm(range(n_paths)):
model_exp.add_Path(n_jumps=n_jumps, area=model_exp.area/n_paths)
model_exp.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
effective_barriers[n] = model_exp.paths[n].calculate_effective_barrier()
[all_barriers.append(b) for b in model_exp.paths[n].membrane_barriers]
sns.histplot(all_barriers, binwidth=1, edgecolor='black', ax=ax[2], stat='density', color='tab:orange', alpha=0.5, label='individual barriers', linewidth=0.5)
permeability = model_exp.calculate_permeability()
effective_barrier_exp = model_exp.calculate_effective_barrier()
std_exp = np.std(all_barriers)
mean_exp = np.mean(all_barriers)
# save data as pandas DataFrame
df_exp = pd.DataFrame()
df_exp['pores'] = np.arange(1,n_paths+1)
df_exp['permeability'] = model_exp.permeabilities
df_exp['effective_barriers'] = effective_barriers
df_exp['permeability_percent'] = model_exp.permeabilities / model_exp.permeabilities.sum() * 100
df_exp.sort_values('permeability_percent', ascending=False, inplace=True)
df_exp['flux_fraction'] = df_exp['permeability_percent'].cumsum() / 100
df_exp['pore_fraction'] = np.arange(1,n_paths+1) / n_paths
df_exp.loc[len(df_exp.index)] = [0,0,0,0,0,0] # add zero row for ROC curve
sns.histplot(effective_barriers, binwidth=1, color='tab:orange', linewidth=1, ax=ax[2],
stat='density', alpha=1, fill=False, label='single path effective barriers')
# PLOTTING
# plot the effective barrier
ax[0].axvline(effective_barrier_equal, ls='dashed', c='k', label='$\Delta G_{eff}^{\ddag}$', lw=1)
ax[0].legend(frameon=False)
ax[0].set_ylabel('Density')
ax[1].axvline(effective_barrier_norm, ls='dashed', c='k', label='$\Delta G_{eff}^{\ddag}$', lw=1)
ax[1].legend(frameon=False)
ax[1].set_ylabel('Density')
ax[2].axvline(effective_barrier_exp, ls='dashed', c='k', label='$\Delta G_{eff}^{\ddag}$', lw=1)
ax[2].legend(frameon=False)
ax[2].set_ylabel('Density')
ax[2].set_xlabel('$\Delta G_{m,i,j}^{\ddag}$ (kcal/mol)')
ax[2].set_xlim(0,100)
plt.savefig(output)
print(f'Means: {mean_equal} (equal), {mean_norm} (normal), {mean_exp} (exponential)')
print(f'Standard deviations: {std_equal} (equal), {std_norm} (normal), {std_exp} (exponential)')
print(f'Effective barriers: {effective_barrier_equal} (equal) {effective_barrier_norm} (normal), {effective_barrier_exp} (exponential)')
plt.show()
return model_equal, model_norm, model_exp
def compare_effective_barriers(dH_barrier, dS_barrier, dH_sigma, dS_sigma, T=300, multi=True, seed=None, plot=True, verbose=False):
if verbose:
print(f'\nComparing effective barriers for a single path through the membrane...')
fig, ax = plt.subplots(1,1, figsize=(7.25,1.95))
dG_eff = np.zeros(2)
dG_eff_kT = np.zeros(2)
# Generate normally distributed barriers
dist = 'normal'
params = {'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sigma**2,0],
[0,dS_sigma**2]])}
model = Path(T=T, n_jumps=200)
model.generate_membrane_barriers(dist=dist, multi=multi, dist_params=params, seed=seed)
dG_eff[0] = model.calculate_effective_barrier()
if plot:
sns.histplot(model.membrane_barriers, color='tab:blue', stat='probability', edgecolor='k', binwidth=1, bins=50, alpha=0.5, ax=ax, label='normal barriers', linewidth=0.5)
ymin, ymax = plt.ylim()
ax.axvline(dG_eff[0], ls='dashed', c='tab:blue')
ax.text(dG_eff[0]*1.05, ymax*0.9, '$\Delta G_{eff}^{\ddag}$', color='tab:blue')
barriers = model.membrane_barriers
barriers_kT = barriers[barriers >= barriers.max() - R*T]
model.membrane_barriers = barriers_kT
model.n_jumps = len(barriers_kT)
model.generate_jump_distribution(dist_params={'mu' : 2})
dG_eff_kT[0] = model.calculate_effective_barrier()
dG_eff_kT[0] = barriers_kT.mean()
if verbose:
print('Normally distributed underlying barriers:')
print(f'\tEffective barrier, all barriers = {dG_eff[0]:.6f}')
print(f'\tEffective barrier, kT-cutoff barriers = {dG_eff_kT[0]:.6f}\n')
# Generate exponentially distributed barriers
dist = 'exponential'
params = {'beta' : np.array([dH_barrier, dS_barrier])}
model = Path(T=T)
model.generate_membrane_barriers(dist=dist, multi=multi, dist_params=params, seed=seed)
dG_eff[1] = model.calculate_effective_barrier()
if plot:
sns.histplot(model.membrane_barriers, color='tab:orange', stat='probability', edgecolor='k', binwidth=1, bins=50, alpha=0.5, ax=ax, label='exponential barriers', linewidth=0.5)
ymin, ymax = plt.ylim()
ax.axvline(dG_eff[1], ls='dashed', c='tab:orange')
ax.text(dG_eff[1]*1.01, ymax*0.9, '$\Delta G_{eff}^{\ddag}$', color='tab:orange')
barriers = model.membrane_barriers
barriers_kT = barriers[barriers >= barriers.max() - R*T]
model.membrane_barriers = barriers_kT
model.n_jumps = len(barriers_kT)
model.generate_jump_distribution(dist_params={'mu' : 2})
dG_eff_kT[1] = model.calculate_effective_barrier()
if verbose:
print('Normally distributed underlying barriers:')
print(f'\tEffective barrier, all barriers = {dG_eff[1]:.6f}')
print(f'\tEffective barrier, kT-cutoff barriers = {dG_eff_kT[1]:.6f}\n')
# formatting
if plot:
ax.set_xlabel('$\Delta G_{m,j}^{\ddag}$ (kcal/mol)')
ax.set_ylabel('Density')
ax.set_xlim(0,)
plt.legend(loc='center', frameon=False, ncol=1)
fig.savefig('figs/effective_barrier_distribution_comparison.pdf')
plt.show()
plt.close()
return dG_eff, dG_eff_kT
def plot_paths(n, dH_barrier, dS_barrier, dH_sigma, dS_sigma, T=300, multi=True, seeds=[None]):
print(f'\nPlotting {n} realizations of barrier paths through the membrane...')
# fig, ax = plt.subplots(n,1, figsize=(12.8,n*2+3.5), sharex=True, sharey=True)
fig, ax = plt.subplots(n,1, figsize=(7.25,1.95), sharex=True, sharey=True)
for i in range(n):
# instantiate the model and generate barriers
dist = 'normal'
params = {
'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sigma**2,0],
[0,dS_sigma**2]])
}
model = Path(T=T, n_jumps=200)
model.generate_membrane_barriers(dist=dist, multi=multi, dist_params=params, seed=seeds[i])
dG_eff = model.calculate_effective_barrier()
# get jumps and barriers for plotting
jumps = model.jump_lengths[100:].cumsum()
barriers = model.membrane_barriers[100:]
# create a cubic spline so the barrier profile is smooth
path_spline = CubicSpline(jumps, barriers, bc_type='natural')
xs = np.linspace(0, jumps.max(), num=2000)
ys = path_spline(xs)
# plot the path
if n > 1:
ax[i].plot(xs, ys, color='tab:blue', alpha=1, label='normal barriers')
ax[i].axhline(dG_eff, c='tab:blue', ls='dashed')
ax[i].text(model.lam, dG_eff+2, '$\Delta G_{eff}^{\ddag}$', ha='right', color='tab:blue')
else:
ax.plot(xs, ys, color='tab:blue', alpha=1, label='normal barriers')
ax.axhline(dG_eff, c='tab:blue', ls='dashed')
ax.text(model.lam, dG_eff+2, '$\Delta G_{eff}^{\ddag}$', ha='right', color='tab:blue')
# repeat for exponentially distributed barriers
dist = 'exponential'
params = {'beta' : np.array([dH_barrier, dS_barrier])}
model = Path(T=T, n_jumps=200)
model.generate_membrane_barriers(dist=dist, multi=multi, dist_params=params, seed=seeds[i])
dG_eff = model.calculate_effective_barrier()
jumps = model.jump_lengths[100:].cumsum()
barriers = model.membrane_barriers[100:]
path_spline = CubicSpline(jumps, barriers, bc_type='natural')
xs = np.linspace(0, jumps.max(), num=2000)
ys = path_spline(xs)
if n > 1:
ax[i].plot(xs, ys, color='tab:orange', alpha=0.75, label='exponential barriers')
ax[i].axhline(dG_eff, c='tab:orange', ls='dashed')
ax[i].text(model.lam, dG_eff+2, '$\Delta G_{eff}^{\ddag}$', ha='right', color='tab:orange')
ax[i].set_ylabel('$\Delta G_{m,j}^{\ddag}$ (kcal/mol)')
ax[i].legend(loc='upper right', ncol=2,
frameon=False, borderpad=0.2)
ax[i].set_ylim(0,dG_eff*1.2)
else:
ax.plot(xs, ys, color='tab:orange', alpha=0.75, label='exponential barriers')
ax.axhline(dG_eff, c='tab:orange', ls='dashed')
ax.text(model.lam, dG_eff+2, '$\Delta G_{eff}^{\ddag}$', ha='right', color='tab:orange')
ax.set_ylabel('$\Delta G_{m,j}^{\ddag}$ (kcal/mol)')
ax.legend(loc='upper right', ncol=2,
frameon=False, borderpad=0.2)
ax.set_ylim(0,dG_eff*1.2)
# some overall formatting
if n > 1:
ax[i].set_xlim(-9*model.lam,)
ax[i].set_xlabel('Transport Coordinate ($\mathrm{\AA}$)')
else:
ax.set_xlim(-9*model.lam,)
ax.set_xlabel('Transport Coordinate ($\mathrm{\AA}$)')
plt.savefig('figs/barrier_profile_1_path.pdf')
plt.show()
def compare_jump_lengths(dH_barrier, dS_barrier, n_paths, delta=400, T=300, multi=True):
dist = 'equal'
params = params = {'mu' : np.array([dH_barrier, dS_barrier])}
lambdas = [1,2,3,4,5,6,7,8,9,10] # list of jump lengths to compare
n_replicates = 10
fig, ax = plt.subplots(1,1, figsize=(6,6))
# fig, ax1 = plt.subplots(3,1, figsize=(6,6), sharex=True)
print(f'\nComparing effective barriers for distributions of jump lengths with mean overall thickness {delta} Angstroms...')
# Jump lengths EQUAL
print(f'\tfor equal dsitribution:')
jump_dist = 'equal'
effective_barriers = np.zeros((len(lambdas),2))
for i,lam in tqdm(enumerate(lambdas)):
deltas = []
lam_barriers = np.zeros(n_replicates)
for r in range(n_replicates):
model = EyringModel(T=T)
n_jumps_mu = delta / lam
n_jumps_sig = 3
# add all parallel paths
for n in range(n_paths):
jump_params = {'mu' : lam}
n_jumps = int(np.random.default_rng().normal(loc=n_jumps_mu, scale=n_jumps_sig))
model.add_Path(n_jumps=n_jumps, lam=lam)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
model.paths[n].generate_jump_distribution(dist=jump_dist, dist_params=jump_params)
[deltas.append(d) for d in model.deltas]
lam_barriers[r] = model.calculate_effective_barrier()
effective_barriers[i,0] = lam_barriers.mean()
effective_barriers[i,1] = lam_barriers.std()
# sns.histplot(deltas, edgecolor='black', ax=ax1[0], stat='density', color='tab:gray', alpha=0.75)
ax.errorbar(lambdas, effective_barriers[:,0], yerr=effective_barriers[:,1], c='tab:gray', label='equal', fmt='o')
# ax.plot(lambdas, effective_barriers[:,0], c='tab:gray', label='equal')
# ax.fill_between(lambdas, effective_barriers[:,0]-effective_barriers[:,1], effective_barriers[:,0]+effective_barriers[:,1], alpha=0.25, color='tab:gray')
print(f'Effective barrier changes from {effective_barriers[0,0]:.4f} +/- {effective_barriers[0,1]:.4f} to {effective_barriers[-1,0]:.4f} +/- {effective_barriers[-1,1]:.4f} as mean jump length increases from {lambdas[0]} to {lambdas[-1]}')
# Jump lengths NORMAL
print(f'\tfor normal distribution:')
jump_dist = 'normal'
for i,lam in tqdm(enumerate(lambdas)):
deltas = []
lam_barriers = np.zeros(n_replicates)
for r in range(n_replicates):
model = EyringModel(T=T)
n_jumps_mu = delta / lam
n_jumps_sig = 3
# add all parallel paths
for n in range(n_paths):
jump_params = {'mu' : lam, 'sigma' : lam/4}
n_jumps = int(np.random.default_rng().normal(loc=n_jumps_mu, scale=n_jumps_sig))
model.add_Path(n_jumps=n_jumps, lam=lam)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
model.paths[n].generate_jump_distribution(dist=jump_dist, dist_params=jump_params)
[deltas.append(d) for d in model.deltas]
lam_barriers[r] = model.calculate_effective_barrier()
effective_barriers[i,0] = lam_barriers.mean()
effective_barriers[i,1] = lam_barriers.std()
# sns.histplot(deltas, edgecolor='black', ax=ax1[1], stat='density', color='tab:blue', alpha=0.75)
ax.errorbar(lambdas, effective_barriers[:,0], yerr=effective_barriers[:,1], c='tab:blue', label='normal', fmt='o')
# ax.plot(lambdas, effective_barriers[:,0], c='tab:blue', label='normal')
# ax.fill_between(lambdas, effective_barriers[:,0]-effective_barriers[:,1], effective_barriers[:,0]+effective_barriers[:,1], alpha=0.25, color='tab:blue')
print(f'Effective barrier changes from {effective_barriers[0,0]:.4f} +/- {effective_barriers[0,1]:.4f} to {effective_barriers[-1,0]:.4f} +/- {effective_barriers[-1,1]:.4f} as mean jump length increases from {lambdas[0]} to {lambdas[-1]}')
# Jump lengths EXPONENTIAL
jump_dist = 'exponential'
print(f'\tfor exponential distribution:')
for i,lam in tqdm(enumerate(lambdas)):
deltas = []
lam_barriers = np.zeros(n_replicates)
for r in range(n_replicates):
model = EyringModel(T=T)
n_jumps_mu = delta / lam
n_jumps_sig = 3
# add all parallel paths
for n in range(n_paths):
jump_params = {'beta' : lam}
n_jumps = int(np.random.default_rng().normal(loc=n_jumps_mu, scale=n_jumps_sig))
model.add_Path(n_jumps=n_jumps, lam=lam)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
model.paths[n].generate_jump_distribution(dist=jump_dist, dist_params=jump_params)
[deltas.append(d) for d in model.deltas]
lam_barriers[r] = model.calculate_effective_barrier()
effective_barriers[i,0] = lam_barriers.mean()
effective_barriers[i,1] = lam_barriers.std()
# sns.histplot(deltas, edgecolor='black', ax=ax1[2], stat='density', color='tab:orange', alpha=0.75)
ax.errorbar(lambdas, effective_barriers[:,0], yerr=effective_barriers[:,1], c='tab:orange', label='exponential', fmt='o')
# ax.plot(lambdas, effective_barriers[:,0], c='tab:orange', label='exponential')
# ax.fill_between(lambdas, effective_barriers[:,0]-effective_barriers[:,1], effective_barriers[:,0]+effective_barriers[:,1], alpha=0.25, color='tab:orange')
print(f'Effective barrier changes from {effective_barriers[0,0]:.4f} +/- {effective_barriers[0,1]:.4f} to {effective_barriers[-1,0]:.4f} +/- {effective_barriers[-1,1]:.4f} as mean jump length increases from {lambdas[0]} to {lambdas[-1]}')
ax.set_xlabel('Mean jumpth length ($\mathrm{\AA}$)')
ax.set_ylabel('$\Delta G_{eff}^{\ddag}$ (kcal/mol)')
ax.set_xticks(np.arange(11))
ax.set_xlim(0,10)
ax.legend(fontsize=16)
# ax1[2].set_xlabel('membrane thickness ($\r{A}$)')
plt.savefig('figs/jump_length_effects.png')
plt.show()
def estimate_dH_dS(dH_barrier, dS_barrier, dH_sigma, dS_sigma, n_paths, area=1e7, plot=False):
print(f'\nEstimating the effective enthalpic and entropic barriers...')
multi = True
temps = np.array([250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350])
dG_eff = np.zeros(len(temps))
P = np.zeros(len(temps))
X = np.zeros(len(temps))
Y = np.zeros(len(temps))
max_barriers_norm = np.zeros((len(temps),n_paths,2))
max_barriers_exp = np.zeros((len(temps),n_paths,2))
hist_alpha = 0.5
error_alpha = 0.1
fig, ax = plt.subplots(2,3, figsize=(7.25,5.5), sharex=False, sharey=True)
# MULTIVARIATE NORMAL
print('\nNORMALLY DISTRIBUTED:')
params = {
'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sigma**2,0],
[0,dS_sigma**2]])
}
dist = 'normal'
all_dH = []
all_dS = []
all_dG = []
for i, T in tqdm(enumerate(temps)):
model = EyringModel(T=T, A=area)
for n in range(n_paths):
model.add_Path(n_jumps=200, lam=10)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
max_barriers_norm[i,n,:] = np.array([model.paths[n].enthalpic_barriers.max(), model.paths[n].entropic_barriers.min()])
if plot:
[all_dH.append(b) for b in model.paths[n].enthalpic_barriers]
[all_dS.append(-T*b) for b in model.paths[n].entropic_barriers]
if T == 300:
[all_dG.append(b) for b in model.paths[n].membrane_barriers]
P[i] = model.calculate_permeability() / 60 / 60 / 1000 * 10**9 * 10
dG_eff[i] = model.calculate_effective_barrier()
lam = model.get_lambda()
delta = np.array(model.deltas).mean()
X[i] = 1 / T
Y[i] = np.log(P[i]*h*delta / (kB*T*lam**2))
sns.histplot(all_dH, ax=ax[0,0], stat='probability', alpha=hist_alpha, facecolor='tab:blue', edgecolor=None)
sns.histplot(all_dS, ax=ax[0,1], stat='probability', alpha=hist_alpha, facecolor='tab:blue', edgecolor=None)
sns.histplot(all_dG, ax=ax[0,2], stat='probability', alpha=hist_alpha, facecolor='tab:blue', edgecolor=None)
dHm = model.paths[n].enthalpic_barriers.mean()
dSm = model.paths[n].entropic_barriers.mean()
dGm = model.paths[n].membrane_barriers.mean()
print(f'\nSingle path dH: {dHm}')
print(f'Single path dS: {dSm} or -T dS at {T} K: {-T*dSm}')
print(f'Single path dG: {dGm}')
print(f'Many path contribution R ln(sum(A_i/A)): {R*np.log(np.sum(model.areas) / model.area)} or -RT ln(sum(A_i/A)) at 300 K: {-R*300*np.log(np.sum(model.areas) / model.area)}')
avg_dH = np.mean(all_dH)
avg_dS = np.mean(all_dS)
avg_dG = np.mean(all_dG)
sem_dH = np.std(all_dH) / np.sqrt(np.size(all_dH))
sem_dS = np.std(all_dS) / np.sqrt(np.size(all_dS))
sem_dG = np.std(all_dG) / np.sqrt(np.size(all_dG))
print(f'\nAverage dH: {avg_dH} +/- {sem_dH}')
print(f'Average dS: {avg_dS} +/- {sem_dS}')
print(f'Average dG: {avg_dG} +/- {sem_dG}')
A = sm.add_constant(X)
ols = sm.OLS(Y, A)
results = ols.fit()
b, m = results.params
be, me = results.bse
eff_dH = np.array([-m*R, me*R]) # estimate, error
eff_dS = -300*np.array([b*R, be*R])
# eff_dG = np.array([eff_dH[0]-300*eff_dS[0], np.sqrt(eff_dH[1]**2 + (300*eff_dS[1])**2)])
eff_dG = np.array([eff_dH[0]+eff_dS[0], np.sqrt(eff_dH[1]**2 + (eff_dS[1])**2)])
print(f'\ndH_eff : {eff_dH[0]} +/- {eff_dH[1]}')
print(f'dS_eff : {eff_dS[0]} +/- {eff_dS[1]} or -T dS_eff at 300 K: {-300*eff_dS[0]} +/- {300*eff_dS[1]}')
print(f'dG_eff at 300 K from averaged effective barriers: {dG_eff.mean()} or from dH_eff and dS_eff: {eff_dG[0]} +/- {eff_dG[1]}')
A = sm.add_constant(X)
ols = sm.OLS(np.log(P), A)
results = ols.fit()
b, m = results.params
be, me = results.bse
print(f'\nArrhenius barrier to permeability: {-m*R} kcal/mol')
print(f'Arrhenius barrier calculated from enthalpic barrier: {eff_dH[0]} kcal/mol')
print(f'Arrhenius prefactor: {np.exp(b)} A/s')
print(f'Arrhenius prefactor calculated from entropic barrier: {lam**2/delta * kB*300/h * np.exp(eff_dS[0]/R)} A/s')
res = np.hstack((eff_dH, eff_dS, eff_dG))
if plot:
# plot effective, single path, mean barriers
ax[0,0].set_title('Normally distributed $\Delta H_{m,i,j}^{\ddag}$', fontsize=8)
ax[0,1].set_title('Normally distributed $-T \Delta S_{m,i,j}^{\ddag}$', fontsize=8)
# ax[0,2].set_title('$\Delta G_{M,i,j}^{\ddag}$ at 300 K from normal $\Delta H_{M,i,j}^{\ddag}$ and $\Delta S_{M,i,j}^{\ddag}$', fontsize=8)
ax[0,2].set_title('$\Delta G_{m,i,j}^{\ddag}$ at 300 K', fontsize=8)
ax[0,0].axvline(eff_dH[0], ls='dashed', c='k', label='$\Delta H_{eff}^{\ddag}$', lw=1)
ax[0,0].axvspan(eff_dH[0] - eff_dH[1], eff_dH[0] + eff_dH[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[0,0].axvline(avg_dH, ls='dashed', c='red', label='mean', lw=1)
ax[0,0].axvspan(avg_dH - sem_dH, avg_dH + sem_dH, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[0,1].axvline(eff_dS[0], ls='dashed', c='k', label='$-T \Delta S_{eff}^{\ddag}$', lw=1)
ax[0,1].axvspan(eff_dS[0] - eff_dS[1], eff_dS[0] + eff_dS[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[0,1].axvline(avg_dS, ls='dashed', c='red', label='mean', lw=1)
ax[0,1].axvspan(avg_dS - sem_dS, avg_dS + sem_dS, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[0,2].axvline(eff_dG[0], ls='dashed', c='k', label='$\Delta G_{eff}^{\ddag}$', lw=1)
ax[0,2].axvspan(eff_dG[0] - eff_dG[1], eff_dG[0] + eff_dG[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[0,2].axvline(avg_dG, ls='dashed', c='red', label='mean', lw=1)
ax[0,2].axvspan(avg_dG - sem_dG, avg_dG + sem_dG, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[0,0].set_ylabel('Density')
ax[0,1].set_ylabel(None)
ax[0,2].set_ylabel(None)
ax[0,0].set_xlim(0,)
ax[0,1].set_xlim(0,)
ax[0,2].set_xlim(0,)
# ax[0,0].tick_params('y', labelrotation=45)
# ax[0,1].tick_params('y', labelrotation=45)
# ax[0,2].tick_params('y', labelrotation=45)
ax[0,0].legend(frameon=False, ncol=1)
ax[0,1].legend(frameon=False, ncol=1)
ax[0,2].legend(frameon=False, ncol=1)
df1 = pd.DataFrame()
df1['distribution'] = ['multi-variate normal']*len(temps)
df1['temperature'] = temps
df1['permeability'] = P
df1['effective free energy'] = dG_eff
df1['1/T'] = X
df1['ln(P/T)'] = Y
fig1, ax1 = plt.subplots(1,1, figsize=(8,8))
ax1 = sns.regplot(x='1/T', y='ln(P/T)', data=df1, ax=ax1)
# MULTIPLE EXPONENTIALS
print('\nEXPONENTIALLY DISTRIBUTED:')
params = {'beta' : np.array([dH_barrier, dS_barrier])}
dist = 'exponential'
all_dH = []
all_dS = []
all_dG = []
for i, T in tqdm(enumerate(temps)):
model = EyringModel(T=T, A=area)
for n in range(n_paths):
model.add_Path(n_jumps=200, lam=10)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
max_barriers_exp[i,n,:] = np.array([model.paths[n].enthalpic_barriers.max(), model.paths[n].entropic_barriers.min()])
if plot:
[all_dH.append(b) for b in model.paths[n].enthalpic_barriers]
[all_dS.append(-T*b) for b in model.paths[n].entropic_barriers]
if T == 300:
[all_dG.append(b) for b in model.paths[n].membrane_barriers]
dG_eff[i] = model.calculate_effective_barrier()
P[i] = model.calculate_permeability() / 60 / 60 / 1000 * 10**9 * 10
lam = model.get_lambda()
delta = np.array(model.deltas).mean()
X[i] = 1 / T
Y[i] = np.log(P[i]*h*delta / (kB*T*lam**2))
sns.histplot(all_dH, ax=ax[1,0], stat='probability', alpha=hist_alpha, facecolor='tab:orange', edgecolor=None)
sns.histplot(all_dS, ax=ax[1,1], stat='probability', alpha=hist_alpha, facecolor='tab:orange', edgecolor=None)
sns.histplot(all_dG, ax=ax[1,2], stat='probability', alpha=hist_alpha, facecolor='tab:orange', edgecolor=None)
dHm = model.paths[n].enthalpic_barriers.mean()
dSm = model.paths[n].entropic_barriers.mean()
dGm = model.paths[n].membrane_barriers.mean()
print(f'\nSingle path dH: {dHm}')
print(f'Single path dS: {dSm} or -TdS at {T} K: {-T*dSm}')
print(f'Single path dG: {dGm}')
print(f'Many path contribution R ln(sum(A_i/A)): {R*np.log(np.sum(model.areas) / model.area)} or -RT ln(sum(A_i/A)) at 300 K: {-R*300*np.log(np.sum(model.areas) / model.area)}')
avg_dH = np.mean(all_dH)
avg_dS = np.mean(all_dS)
avg_dG = np.mean(all_dG)
sem_dH = np.std(all_dH) / np.sqrt(np.size(all_dH))
sem_dS = np.std(all_dS) / np.sqrt(np.size(all_dS))
sem_dG = np.std(all_dG) / np.sqrt(np.size(all_dG))
print(f'\nAverage dH: {avg_dH} +/- {sem_dH}')
print(f'Average dS: {avg_dS} +/- {sem_dS}')
print(f'Average dG: {avg_dG} +/- {sem_dG}')
A = sm.add_constant(X)
ols = sm.OLS(Y, A)
results = ols.fit()
b, m = results.params
be, me = results.bse
eff_dH = np.array([-m*R, me*R]) # estimate, error
eff_dS = -300*np.array([b*R, be*R])
# eff_dG = np.array([eff_dH[0]-300*eff_dS[0], np.sqrt(eff_dH[1]**2 + (300*eff_dS[1])**2)])
eff_dG = np.array([eff_dH[0]+eff_dS[0], np.sqrt(eff_dH[1]**2 + (eff_dS[1])**2)])
print(f'\ndH_eff : {eff_dH[0]} +/- {eff_dH[1]}')
print(f'dS_eff : {eff_dS[0]} +/- {eff_dS[1]} or -T dS_eff at 300 K: {-300*eff_dS[0]} +/- {300*eff_dS[1]}')
print(f'dG_eff at 300 K from averaged effective barriers: {dG_eff.mean()} or from dH_eff and dS_eff: {eff_dG[0]} +/- {eff_dG[1]}')
A = sm.add_constant(X)
ols = sm.OLS(np.log(P), A)
results = ols.fit()
b, m = results.params
be, me = results.bse
print(f'\nArrhenius barrier to permeability: {-m*R} kcal/mol')
print(f'Arrhenius barrier calculated from enthalpic barrier: {eff_dH[0]} kcal/mol')
print(f'Arrhenius prefactor: {np.exp(b)} A/s')
print(f'Arrhenius prefactor calculated from entropic barrier: {lam**2/delta * kB*300/h * np.exp(eff_dS[0]/R)} A/s')
df2 = pd.DataFrame()
df2['distribution'] = ['multiple exponentials']*len(temps)
df2['temperature'] = temps
df2['permeability'] = P
df2['effective free energy'] = dG_eff
df2['1/T'] = X
df2['ln(P/T)'] = Y
fig2, ax2 = plt.subplots(1,1, figsize=(8,8))
ax2 = sns.regplot(x='1/T', y='ln(P/T)', data=df2, ax=ax2)
if plot:
# plot effective, single path, mean barriers
ax[1,0].set_title('Exponentially distributed $\Delta H_{m,i,j}^{\ddag}$', fontsize=8)
ax[1,1].set_title('Exponentially distributed $-T \Delta S_{m,i,j}^{\ddag}$', fontsize=8)
# ax[1,2].set_title('$\Delta G_{M,i,j}^{\ddag}$ at 300 K from exponential $\Delta H_{M,i,j}^{\ddag}$ and $\Delta S_{M,i,j}^{\ddag}$', fontsize=8)
ax[1,2].set_title('$\Delta G_{m,i,j}^{\ddag}$ at 300 K', fontsize=8)
ax[1,0].axvline(eff_dH[0], ls='dashed', c='k', label='$\Delta H_{eff}^{\ddag}$', lw=1)
ax[1,0].axvspan(eff_dH[0] - eff_dH[1], eff_dH[0] + eff_dH[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[1,0].axvline(avg_dH, ls='dashed', c='red', label='mean', lw=1)
ax[1,0].axvspan(avg_dH - sem_dH, avg_dH + sem_dH, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[1,1].axvline(eff_dS[0], ls='dashed', c='k', label='$-T \Delta S_{eff}^{\ddag}$', lw=1)
ax[1,1].axvspan(eff_dS[0] - eff_dS[1], eff_dS[0] + eff_dS[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[1,1].axvline(avg_dS, ls='dashed', c='red', label='mean', lw=1)
ax[1,1].axvspan(avg_dS - sem_dS, avg_dS + sem_dS, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[1,2].axvline(eff_dG[0], ls='dashed', c='k', label='$\Delta G_{eff}^{\ddag}$', lw=1)
ax[1,2].axvspan(eff_dG[0] - eff_dG[1], eff_dG[0] + eff_dG[1], facecolor='k', edgecolor=None, alpha=error_alpha)
ax[1,2].axvline(avg_dG, ls='dashed', c='red', label='mean', lw=1)
ax[1,2].axvspan(avg_dG - sem_dG, avg_dG + sem_dG, facecolor='red', edgecolor=None, alpha=error_alpha)
ax[1,0].set_xlim(0,25)
ax[1,1].set_xlim(0,60)
ax[1,2].set_xlim(0,60)
ax[1,0].set_xlabel('$\Delta H_{m,i,j}^{\ddag}$ (kcal/mol)')
ax[1,1].set_xlabel('$-T \Delta S_{m,i,j}^{\ddag}$ (kcal/mol)')
ax[1,2].set_xlabel('$\Delta G_{m,i,j}^{\ddag}$ (kcal/mol)')
ax[1,0].set_ylabel('Density')
ax[1,1].set_ylabel(None)
ax[1,2].set_ylabel(None)
# ax[1,0].tick_params('y', labelrotation=45)
# ax[1,1].tick_params('y', labelrotation=45)
# ax[1,2].tick_params('y', labelrotation=45)
ax[1,0].legend(frameon=False, ncol=1)
ax[1,1].legend(frameon=False, ncol=1)
ax[1,2].legend(frameon=False, ncol=1)
if plot:
# plot maximum barriers
fig3, ax3 = plt.subplots(2,2, figsize=(14,10), sharex=True)
paths = np.arange(1, n_paths+1)
for i, T in enumerate(temps):
# plot the max enthalpies for a given temperature
ax3[0,0].scatter(paths, max_barriers_norm[i,:,0], s=2, alpha=0.1, facecolor='tab:blue')
ax3[1,0].scatter(paths, max_barriers_exp[i,:,0], s=2, alpha=0.1, facecolor='tab:orange')
# plot the max entropies for a given temperature
ax3[0,1].scatter(paths, max_barriers_norm[i,:,1], s=2, alpha=0.1, facecolor='tab:blue')
ax3[1,1].scatter(paths, max_barriers_exp[i,:,1], s=2, alpha=0.1, facecolor='tab:orange')
# formatting
ax3[1,0].set_xlabel('Paths', fontsize=16)
ax3[1,1].set_xlabel('Paths', fontsize=16)
ax3[0,0].set_ylabel('$\Delta H_{m,i,max}^{\ddag}$ (kcal/mol)', fontsize=16)
ax3[0,1].set_ylabel('$\Delta S_{m,i,max}^{\ddag}$ (kcal/mol/K)', fontsize=16)
ax3[1,0].set_ylabel('$\Delta H_{m,i,max}^{\ddag}$ (kcal/mol)', fontsize=16)
ax3[1,1].set_ylabel('$\Delta S_{m,i,max}^{\ddag}$ (kcal/mol/K)', fontsize=16)
ax3[1,0].set_title('Exponentially distributed $\Delta H_{m,i,j}^{\ddag}$', fontsize=16)
ax3[1,1].set_title('Exponentially distributed $\Delta S_{m,i,j}^{\ddag}$', fontsize=16)
ax3[0,0].set_title('Normally distributed $\Delta H_{m,i,j}^{\ddag}$', fontsize=16)
ax3[0,1].set_title('Normally distributed $\Delta S_{m,i,j}^{\ddag}$', fontsize=16)
fig.savefig('figs/dH_dS_distributions.pdf')
plt.show()
def show_maximums(dH_barrier, dS_barrier, dH_sigma, dS_sigma, T=300, multi=True):
print(f'\nShowing maximum barriers across parallel paths...')
title_dict = {'family' : 'Helvetica', 'size' : 8}
n_paths = 2000
fig1, ax1 = plt.subplots(1,1, figsize=(3.55,3.55/2))
fig3, ax3 = plt.subplots(1,1, figsize=(3.55,3.55/2))
# NORMAL DISTRIBUTION OF BARRIERS
model = EyringModel(T=T)
dist = 'normal'
params = {'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sigma**2,0],
[0,dS_sigma**2]])}
print(f'\tfor normal barriers:')
# generate barriers and save the maximum barriers
max_barriers = np.zeros(n_paths)
for n in tqdm(range(n_paths)):
model.add_Path(area=model.area/n_paths)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
max_barriers[n] = model.paths[n].membrane_barriers.max()
effective_barrier = model.calculate_effective_barrier()
# plot the maximum barriers for arbitrarily numbered paths, plot effective barrier
paths = np.arange(1, n_paths+1)
ax1.scatter(paths, max_barriers, edgecolors='k', s=10, lw=0.5)
ax1.axhline(effective_barrier, ls='dashed', c='k')
xmin, xmax = ax1.get_xlim()
ymin, ymax = ax1.get_ylim()
ax1.text(xmax*0.75, effective_barrier-1, '$\Delta G_{eff}^{\ddag}$')
# formatting
ax1.set_ylabel('$\Delta G_{m,i,max}^{\ddag}$ (kcal/mol)')
ax1.set_ylim(ymin-1, ymax)
ax1.set_title('$\Delta H^{\ddag}_{m,i,j}$, $\Delta S^{\ddag}_{m,i,j}$ normally distributed', fontdict=title_dict)
ax3.hist(max_barriers, edgecolor='k', bins=50, lw=0.5, density=True, facecolor='tab:blue')
ax3.axvline(effective_barrier, ls='dashed', c='k')
ax3.text(effective_barrier+0.4, 0.3, '$\Delta G_{eff}^{\ddag}$')
# ax3.set_xlabel('Maximum $\Delta G_{M,i,j}^{\ddag}$ along path $i$ (kcal/mol)')
ax3.set_ylabel('Probability')
ax3.set_title('$\Delta H^{\ddag}_{m,i,j}$, $\Delta S^{\ddag}_{m,i,j}$ normally distributed', fontdict=title_dict)
fig3.savefig('figs/maximum_barriers_normal.pdf')
# EXPONENTIAL DISTRIBUTION OF BARRIERS
fig2, ax2 = plt.subplots(1,1, figsize=(3.55,3.55/2))
fig4, ax4 = plt.subplots(1,1, figsize=(3.55,3.55/2))
model = EyringModel(T=T)
dist = 'exponential'
params = {'beta' : np.array([dH_barrier, dS_barrier])}
print(f'\tfor exponential barriers:')
# generate barriers and save maximum barriers
max_barriers = np.zeros(n_paths)
for n in tqdm(range(n_paths)):
model.add_Path(area=model.area/n_paths)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
max_barriers[n] = model.paths[n].membrane_barriers.max()
effective_barrier = model.calculate_effective_barrier()
# plot maximum barriers and effective barrier
paths = np.arange(1, n_paths+1)
ax2.scatter(paths, max_barriers, edgecolors='k', c='tab:orange', s=10, lw=0.5)
ax2.axhline(effective_barrier, ls='dashed', c='k')
xmin, xmax = ax2.get_xlim()
ymin, ymax = ax2.get_ylim()
ax2.text(xmax*0.75, effective_barrier-8, '$\Delta G_{eff}^{\ddag}$')
# formatting
ax2.set_ylabel('$\Delta G_{m,i,max}^{\ddag}$ (kcal/mol)')
ax2.set_ylim(ymin-10, ymax)
ax2.set_title('$\Delta H^{\ddag}_{m,i,j}$, $\Delta S^{\ddag}_{m,i,j}$ exponentially distributed', fontdict=title_dict)
ax2.set_xlabel('Paths')
ax4.hist(max_barriers, edgecolor='k', bins=50, lw=0.5, density=True, facecolor='tab:orange')
ax4.axvline(effective_barrier, ls='dashed', c='k')
ax4.text(effective_barrier+2, 0.035, '$\Delta G_{eff}^{\ddag}$')
xmin, xmax = ax4.get_xlim()
ax4.set_xlim(xmin, 125)
ax4.set_xlabel('Maximum $\Delta G_{m,i,j}^{\ddag}$ along path $i$ (kcal/mol)')
ax4.set_ylabel('Probability')
ax4.set_title('$\Delta H^{\ddag}_{m,i,j}$, $\Delta S^{\ddag}_{m,i,j}$ exponentially distributed', fontdict=title_dict)
fig4.savefig('figs/maximum_barriers_exponential.pdf')
plt.show()
def fixed_jump_length(dH_barrier, dS_barrier, n_paths=2000, T=300, multi=True):
dist = 'equal'
params = params = {'mu' : np.array([dH_barrier, dS_barrier])}
lam = 10 # fixed 10 Angstrom jump length
n_jumps = np.array([10,20,30,40,50,100,200,300,400,500,1000]) # changing number of jumps
permeabilities = np.zeros(len(n_jumps))
deltas = np.zeros(len(n_jumps))
effective_barriers = np.zeros(len(n_jumps))
for i,nj in tqdm(enumerate(n_jumps)):
model = EyringModel(T=T)
# add all parallel paths
for n in range(n_paths):
model.add_Path(n_jumps=nj, lam=lam)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
permeabilities[i] = model.calculate_permeability()
deltas[i] = np.array(model.deltas).mean()
effective_barriers[i] = model.calculate_effective_barrier()
df = pd.DataFrame()
df['jumps'] = n_jumps
df['permeability'] = permeabilities
df['thickness'] = deltas
df['effective_barriers'] = effective_barriers
sns.scatterplot(data=df, x='jumps', y='effective_barriers')
plt.show()
sns.scatterplot(data=df, x='thickness', y='permeability')
plt.show()
def barrier_variance(dH_barrier, dS_barrier, n_paths=2000, T=300):
multi = True
dist = 'normal'
# sigs = np.array([0.0001, 0.001, 0.01, 0.05, 0.1, 0.5, 1, 1.5, 2, 2.5, 3, 4, 5, 10])
dH_sigs = np.array([0.0001, 0.001, 0.01, 0.05, 0.1, 0.5, 1, 1.5, 2, 2.5, 3, 4, 5, 6, 7, 8, 9, 10])
dS_sigs = dH_sigs / T
# dS_sigs = np.array([10e-5, 10e-4, 5e-4, 1e-4, 5e-3, 1e-3, 0.05, 0.01, 0.1, 0.5, 0.75, 0.9])
n_sigs = len(dH_sigs)*len(dS_sigs)
# save data per path for ROC curves
perm_per_path = np.zeros(n_paths*n_sigs)
perm_percent = np.zeros(n_paths*n_sigs)
models_dH = np.zeros(n_paths*n_sigs)
models_dS = np.zeros(n_paths*n_sigs)
models = np.zeros(n_paths*n_sigs)
# save data for overall model
effective_barriers = np.zeros(n_sigs)
permeabilities = np.zeros(n_sigs)
max_barriers = np.zeros(n_sigs)
max_enthalpies = np.zeros(n_sigs)
max_entropies = np.zeros(n_sigs)
dH_sigmas = np.zeros(n_sigs)
dS_sigmas = np.zeros(n_sigs)
i = 0
for dH_sig in tqdm(dH_sigs):
for dS_sig in dS_sigs:
model = EyringModel(T=T)
params = {'mu' : np.array([dH_barrier, dS_barrier]),
'cov' : np.array([[dH_sig**2,0],
[0,dS_sig**2]])}
dH_max = -10e8
dS_max = -10e8
dG_max = -10e8
for n in range(n_paths):
model.add_Path(lam=10, area=model.area/n_paths)
model.paths[n].generate_membrane_barriers(dist=dist, multi=multi, dist_params=params)
dH_max = max(dH_max, model.paths[n].enthalpic_barriers.max())
dS_max = max(dS_max, model.paths[n].entropic_barriers.max())
dG_max = max(dG_max, model.paths[n].membrane_barriers.max())
dH_sigmas[i] = dH_sig
dS_sigmas[i] = dS_sig
effective_barriers[i] = model.calculate_effective_barrier()
permeabilities[i] = model.calculate_permeability()
max_barriers[i] = dG_max
max_enthalpies[i] = dH_max
max_entropies[i] = dS_max
perm_per_path[i*n_paths:(i+1)*n_paths] = model.permeabilities
perm_percent[i*n_paths:(i+1)*n_paths] = model.permeabilities / model.permeabilities.sum() * 100
models_dH[i*n_paths:(i+1)*n_paths] = dH_sig
models_dS[i*n_paths:(i+1)*n_paths] = dS_sig
models[i*n_paths:(i+1)*n_paths] = i+1
i += 1
df_roc = pd.DataFrame()
df_roc['paths'] = np.arange(1,n_paths+1).tolist()*n_sigs
df_roc['permeability'] = perm_per_path
df_roc['permeability percent'] = perm_percent
df_roc['dH sigma'] = models_dH
df_roc['dS sigma'] = models_dS
df_roc['model'] = models
df_roc.to_csv('barrier_variance_ROC.csv', index=False)
df = pd.DataFrame()
df['dH sigma'] = dH_sigmas
df['dS sigma'] = dS_sigmas
df['effective barrier'] = effective_barriers
df['permeability'] = permeabilities
df['max barrier'] = max_barriers
df['max enthalpic barrier'] = max_enthalpies
df['max entropic barrier'] = max_entropies
df.to_csv('barrier_variance.csv', index=False)
def vary_everything(n_jumps_mu, jump_dist, jump_params, barrier_dist, barrier_params, n_paths=4, n_jumps_sig=3, T=300, plot=True):
# generate a model with full variation in barriers, number of jumps, jump lengths
model = EyringModel(T=T)