-
Notifications
You must be signed in to change notification settings - Fork 1
/
manuscript_figures_macro.py
1985 lines (1513 loc) · 89 KB
/
manuscript_figures_macro.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: andreypoletaev
"""
# =============================================================================
# %% Block 1: initial imports
# =============================================================================
import os, sys, re, glob
if os.path.join(os.path.abspath(os.getcwd()), "utils") not in sys.path :
sys.path.append(os.path.join(os.path.abspath(os.getcwd()), "utils"))
import numpy as np
import pandas as pd
import hop_utils as hu
from crystal_utils import read_lmp
from scipy.optimize import curve_fit as cf
from scipy.interpolate import interp1d
from datetime import datetime as dt
from matplotlib import pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Rectangle
from batlow import cm_data
batlow_cm = LinearSegmentedColormap.from_list('batlow', cm_data)
batlow_even = LinearSegmentedColormap.from_list('batlow_even', hu.batlow_lightness_scaled(0.4,0.6))
from cycler import cycler
linecycler = cycler(linestyle=['-', '--', ':', '-.'])
markcycler = cycler(marker=['o', 's', 'v', 'd', '^'])
from itertools import cycle
markers = cycle(['o', 's', 'v', 'd', '^','D','<','>'])
lines = cycle(['-', '--', '-.', ':'])
## linear fitting
linfit = lambda x, *p : p[0] * x + p[1]
## cosmetic defaults for matplotlib plotting
plt.rc('legend', fontsize=10)
plt.rc('axes', labelsize=14)
plt.rc('axes', titlesize=14)
plt.rc('xtick', labelsize=12)
plt.rc('ytick', labelsize=12)
plt.rc('errorbar', capsize=3)
plt.rc('markers', fillstyle='none')
plt.rc("savefig", format='pdf')
## variables by which it is possible to plot
relevant_vars = ['metal','phase','T1','config','stoich','exclude','z']
## which atoms to query for species
## conductivity from bulk diffusion coefficient. Takes D_bulk [cm^2/sec], cell [AA]
## output is [Kelvin/ohm/cm] i.e. [Kelvin * siemens / cm]
## note that there is only one q in the formula because hu.kb is [eV/K]
q = 1.602e-19 ## [Coulomb] elementary charge
AA = 1e-8 ## [cm] 1 angstrom in cm
sigma_T = lambda N, cell, d_com : q * N / np.prod(np.diag(cell*AA))*d_com / hu.kb
unit_conv = 1e-4 ## [cm^2/sec] 1 AA^2/psec = 0.0001 cm^2/sec. No need to change this.
eps_0 = 8.854187e-12 ## [A^2 m^-3 kg^-1 sec^4]
T1 = 300
## dictionary of units
units = {'T1':'K', 'metal':'', 'stoich':'', 'exclude':'', 'config':'', 'z':'',
'phase':f' {T1}K'}
## shorthands for labels
bdp = r'$\beta^{\prime\prime}$'
beta = r'$\beta$'
phases = {'beta':beta, 'bdp':bdp}
# =============================================================================
# %% Block 2 : load files based on the index of conduction planes created in
# ## analysis_steadystate.py
# ## The a2_...fix files are assumed to be located in the same folders as their
# ## corresponding lammps structure files.
# =============================================================================
## database of all the hops: only combined planes matter for macro analyses.
all_planes = pd.read_csv('./sample_data/all_hop_planes.csv').query('z == "z_all"')
## flag for loading atoms
frac = False
## flag for loading CoM immediately
load_com = False
## flag for loading the output of the LAMMPS msd fix
load_r2 = False
## ===== BETA single-metal =====
## ===== BETA Ag =====
planes_to_load = all_planes.query('metal == "Ag" & config == "120_4" & T1 in [300,600,1000]')
## ===== BETA Na =====
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & stoich == "120" ')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & stoich == "120" & T1 == 300')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & stoich == "120" & T1 == 600')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & config == "120_4" & T1 in [300,600,1000]')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & config == "120_4" & T1 in [300,600]')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & config == "120_4" & T1 == 300')
# planes_to_load = all_planes.query('metal == "Na" & phase == "beta" & config == "120_1"')
## ===== BETA K =====
# planes_to_load = all_planes.query('metal == "K" & stoich == "120" & 300 < T1 < 900')
# planes_to_load = all_planes.query('metal == "K" & stoich == "120" & T1 in [300, 600]')
# planes_to_load = all_planes.query('metal == "K" & config == "120_4"')
# planes_to_load = all_planes.query('metal == "K" & config == "120_4" & T1 in [300,600,1000]')
## ===== BETA all metals together =====
# planes_to_load = all_planes.query('phase == "beta" & config == "120_4" & T1 == 1000')
# planes_to_load = all_planes.query('phase == "beta" & config == "120_4" & T1 == 600')
# planes_to_load = all_planes.query('phase == "beta" & config == "120_4" & T1 in [300,600,1000] ')
## ===== BDP =====
## ===== BDP Na =====
planes_to_load = all_planes.query('phase != "beta" & metal == "Na" & config == "unsym_0" & T1 in [230,300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Na" & config == "unsym_0" & T1 in [230,300]')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Na" & config == "unsym_0" & T1 in [300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Na" & T1 == 600')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Na" & stoich in ["unsym", "unsymLi"] & T1 in [230,300,473]')
# planes_to_load.sort_values('config', ascending=False, inplace=True)
## ===== BDP K =====
# planes_to_load = all_planes.query('phase != "beta" & metal == "K"')
# planes_to_load = all_planes.query('phase != "beta" & metal == "K" & config == "symm_1"')
# planes_to_load = all_planes.query('phase != "beta" & metal == "K" & config == "unsym_0"')
# planes_to_load = all_planes.query('phase != "beta" & metal == "K" & config == "unsym_0" & T1 in [300,600]')
# planes_to_load = all_planes.query('phase != "beta" & metal == "K" & config == "unsym_0" & T1 == 300')
# planes_to_load = all_planes.query('phase != "beta" & metal == "K" & config == "unsym_0" & T1 == 600')
# planes_to_load.sort_values('config', ascending=False, inplace=True)
## ===== BDP Ag =====
# planes_to_load = all_planes.query('phase != "beta" & metal == "Ag"')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Ag" & config == "symm_1"')
# planes_to_load = all_planes.query('phase != "beta" & metal == "Ag" & config == "unsym_0"')
# planes_to_load.sort_values('config', ascending=False, inplace=True)
## ===== BDP all metals together =====
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "symm_1" & T1 == 600')
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "symm_1" & T1 in [230,300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "unsym_0" & T1 == 300')
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "unsym_0" & T1 == 600')
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "unsym_0" & T1 in [300,600]')
# planes_to_load = all_planes.query('phase != "beta" & num_planes > 2 & config == "unsym_0" & T1 in [230,300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & metal in ["Na", "K"] & T1 in [230,300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & T1 in [230,300,473,600]')
# planes_to_load = all_planes.query('phase != "beta" & config == "unsym_0" & metal in ["Ag", "K"] & T1 in [230,300,473,600]')
# planes_to_load.sort_values('config', ascending=False, inplace=True)
## ===== both beta and doubleprime =====
# planes_to_load = all_planes.query('metal == "Na" & T1 == 300 & config in ["120_4", "unsym_0", "symm_1", "102_1"]')
# ========== automatic things below this line ==========
## make a structure for loading data
planes_dicts = []
## load macro-analysis files from the lammps non-Gaussian compute
for plane in planes_to_load.itertuples(index=False):
mm = plane.metal
T1 = plane.T1
hp = plane.hop_path
ph = plane.phase
st = plane.stoich
ex = plane.exclude
tt = plane.total_time
cn = plane.config
## load lammps structure
_, _, cell, atoms = read_lmp(plane.lammps_path, fractional=False)
a2_folder = '/'.join(plane.lammps_path.split('/')[:-1])
## load lammps r2 file for the diffusion coefficient
if load_r2 :
r2_fname = glob.glob(a2_folder+f'/a2_*{T1}K-{mm}.fix')
## load the r2 file if exactly one exists, else complain
if isinstance(r2_fname, list) and len(r2_fname) == 1:
## read the r2 file - options for fix file
this_r2 = pd.read_csv(r2_fname[0], names=['time','r2','r4','a2'],
skiprows=2, sep=' ')
this_r2.time /= 1000
this_r2.set_index('time', inplace=True)
## Look for a literature folder
lit_folder = '/'.join(a2_folder.split('/')[:-1])
print(f'\nLoaded r2 for plane {hp}')
else:
print(f'\nsomething off with plane {hp}.')
print(f'here are possible r2 outputs: {r2_fname}')
this_r2 = None
else : this_r2 = None
## the a2 fix file is LAMMPS output, csv is calculated with multiple starts
## this takes the longest-duration a2 file
a2_fnames = glob.glob(a2_folder+f'/{mm}*a2-*{T1}K*ps.csv')
## load the a2 file if exactly one exists, else complain
if a2_fnames :
if len(a2_fnames) > 1 : a2_fnames = sorted(a2_fnames, reverse=True,
key = lambda x : eval(re.split('-|_| ',x)[-1][:-6]))
# ## read the a2 file - options for fix file
# this_a2 = pd.read_csv(a2_fname[0], names=['time','r2','r4','a2'],
# skiprows=2, sep=' ')
# this_a2.time /= 1000
## read the a2 file - options for csv file
this_a2 = pd.read_csv(a2_fnames[0], sep=',').set_index('time')
## Look for a literature folder
lit_folder = '/'.join(a2_folder.split('/')[:-1])
print(f'Loaded a2: {a2_fnames[0]}')
else:
print(f'something off with plane {hp}.')
print(f'here are possible a2 outputs: {a2_fnames}')
this_a2 = None
## load the CoM trajectory if it exists
com_fname = glob.glob(a2_folder + f'/cm*{T1}K*{mm}.fix')
if isinstance(com_fname, list) and len(com_fname) == 1 and load_com:
this_com = pd.read_csv(com_fname[0],sep=' ', names=['time', 'x', 'y', 'z', 'vx', 'vy', 'vz'], skiprows=2).drop(columns=['vx','vy','vz'])
this_com.time /= 1000. ## hard-coded conversion from steps to picoseconds
this_com.set_index('time', inplace=True)
print('Loaded CoM trajectory.')
elif not load_com :
this_com = True
print('Skipping CoM trajectory.')
else :
print(f'Could not load CoM trajectory, found: {com_fname}')
this_com = None
## wrap the a2, CoM, and metadata into a dict
if (this_r2 is not None or not load_r2) and (this_a2 is not None) :
# if (this_a2 is not None) and (this_r2 is not None) and (this_com is not None) :
planes_dicts.append(dict(phase=ph, metal=mm, T1=T1, config=cn, stoich=st, exclude=ex,
a2=this_a2, lit_folder=lit_folder, com = this_com,
cell=cell, atoms=atoms, folder=a2_folder, r2=this_r2))
## make the holding structure into a dataframe
macro_planes_data = pd.DataFrame(planes_dicts)
# =============================================================================
# %% Figure 2 (and Extended Data 1-6) : (a) r2, (b) exponent of r2 vs distance,
# ## (c) dx raw, (d) dx rescaled,(e) Gs 2D color plot, (f) Gs fitting.
# ## Version "04", March 29 2021, this is in manuscript versions 07-09
# =============================================================================
## parameters:
## THIS RELIES ON LOADING PLANES ABOVE
dim = 2 ## dimension for r2, typically just 2, but 3 is possible.
guides = True ## plot guidelines in (a)
hop_length = 2.8 ## [AA] for binning dx
dx_times = [25, 25e1, 25e2, 25e3] ## time points for spectra of dx
gs_times = 2.5*np.logspace(-1,4,6) ## [ps] times for plotting spectra
rs_list = [[0.01,1.7], [0.01, 4.6]] ## use 1.7/4.6 for bdp, 1.6/4.3 for beta?
T1_dx = 300 ## for which temperature to plot dx
T1s_gs = [300,600] ## for which temperatures to plot Gs fits
cd_exclude = []
na_bdp_unsym = True ## trigger for making a broken axis for C_D(t) (Figure 2)
# ========== automatic things below this line ==========
## parameters to transform the C_D and create the broken axes
cd_break = 4.25
cd_break_top = 4.6
cd_scale = 2. # linear scaling factor; if > 1 makes transform look compressed
cd_true = 9 # value that will show up as cd_display
cd_display = 6.8 # value at which in
# linear function that calculates an underlying transformed coordinate
# given y points from real data.
# maps cd_true to cd_display; true y-value at cd_true shows up as at cd_display
cd_transform = lambda y : cd_display + (y - cd_true) / cd_scale
## new figure & counter for Gs fitting colors
fig, axes = plt.subplots(3,2, figsize=(10,12))
## make a color map for all temperature values
T1_colors = cycle([batlow_even(i) for i in np.linspace(0, 1, len(macro_planes_data.T1.unique()))])
dx_colors = cycle([batlow_even(i) for i in np.linspace(0, 1, len(dx_times))])
## one figure total
for i, plane in macro_planes_data.iterrows():
mm = plane.metal; st = plane.stoich; cn = plane.config; ph = plane.phase
ex = plane.exclude; T1 = plane.T1; folder = plane.folder
cc = next(T1_colors)
## set a legend title, and plotting labels for each curve
label = str(T1) + 'K'
leg_title = f'{mm} {phases[ph]}'
## load the 2D a2 file - leaving out the "split" files
if dim == 2 :
a2_xys = glob.glob(folder+f'/{mm}*{ex}-a2xy*{T1}K*ps.csv')
## load the a2 file if exactly one exists, else complain
if a2_xys :
if len(a2_xys) > 1 : a2_xys = sorted(a2_xys, reverse=True,
key = lambda x : eval(re.split('-|_| ',x)[-1][:-6]))
## read the a2 file - options for csv file
a2 = pd.read_csv(a2_xys[0], sep=',').set_index('time')
else : print(f'could not load a 2D a2 file for plane {mm} {cn} {T1}K')
else : a2 = plane.a2
## recalculate a2 for the right number of dimensions
a2.a2 = dim * a2.r4 / a2.r2 ** 2 / (dim+2) - 1
## load a short-time a2 file if using one
try :
a2s = pd.read_csv(folder + f'/{mm}-{st}-{ex}-a2{"xy" if dim == 2 else ""}-{T1}K-10ps.csv').set_index('time')
a2s.a2 = dim * a2s.r4 / a2s.r2 ** 2 / (dim+2) - 1
except : a2s = None
# ===== (a) r2 =====
axes[0,0].plot(a2.r2.iloc[1:], label=label, c=cc)
axes[0,0].legend(title=leg_title)
if guides and T1 == T1_dx :
if mm == 'Na' and 'unsym' in cn :
axes[0,0].plot([0.03,0.03*5], [0.07,0.07*25], c='k', lw=0.4)
axes[0,0].plot([15e2, 15e3], [2e3, 2e4], c='k', lw=0.4)
axes[0,0].plot([4e3, 4e4], [4, 4*10**0.75], c='k', lw=0.4)
elif mm == 'Na' and 'symm' in cn :
axes[0,0].plot([15e2, 15e3], [2e3, 2e4], c='k', lw=0.4)
axes[0,0].plot([25e2, 25e3], [2e1, 2e2], c='k', lw=0.4)
elif mm == 'Na' and '120_4' in cn :
axes[0,0].plot([0.03,0.03*5], [0.12,0.12*25], c='k', lw=0.4)
axes[0,0].plot([15e2, 15e3], [1.5e3, 1.5e4], c='k', lw=0.4)
axes[0,0].plot([2.5e3, 2.5e4], [5, 5*10**0.8], c='k', lw=0.4)
elif mm == 'K' and 'unsym' in cn :
axes[0,0].plot([0.03,0.03*5], [0.04,0.04*25], c='k', lw=0.4)
axes[0,0].plot([2e3, 2e4], [1.5e3, 1.5e4], c='k', lw=0.4)
axes[0,0].plot([2.5e3, 2.5e4], [7.5, 7.5*10**0.9], c='k', lw=0.4)
elif mm == 'Ag' and '120' in cn :
axes[0,0].plot([0.03,0.03*5], [0.03,0.03*25], c='k', lw=0.4)
axes[0,0].plot([3e3, 3e4], [2e3, 2e4], c='k', lw=0.4)
axes[0,0].plot([3.5e3, 3.5e4], [6, 6*10**0.75], c='k', lw=0.4)
elif mm == 'Ag' and 'unsym' in cn :
axes[0,0].plot([0.03,0.03*5], [0.02,0.02*25], c='k', lw=0.4)
axes[0,0].plot([2.5e3, 2.5e4], [1.5e3, 1.5e4], c='k', lw=0.4)
# axes[0,0].plot([2.5e3, 2.5e4], [5, 5*10**0.9], c='k', lw=0.4)
axes[0,0].plot([4e3, 4e4], [1.5, 1.5*10**0.75], c='k', lw=0.4)
elif mm == 'K' and '120' in cn :
axes[0,0].plot([0.03,0.03*5], [0.06,0.06*25], c='k', lw=0.4)
axes[0,0].plot([2e3, 4e4], [300, 300*20**0.9], c='k', lw=0.4)
axes[0,0].plot([0.04,10], [31.36, 31.36], c='k', lw=0.4, ls='--')
# ===== (b) exponent vs distance =====
fit_points = 21
p0 = [1, 0]
exp_alpha = np.array([cf(linfit, np.log10(a2.index.values[x:x+fit_points]),
np.log10(a2.r2.values[x:x+fit_points]),p0)[0][0] for x in range(10,len(a2)-fit_points)])
exp_times = a2.index.values[10+fit_points//2:-fit_points//2]
exp_rs = np.sqrt(a2.r2.values[10+fit_points//2:-fit_points//2])
# axes[0,1].plot(exp_times[exp_times >=0.8], exp_alpha[exp_times >=0.8], label=label, c=f'C{i}')
axes[0,1].plot(exp_rs[exp_times >=0.8], exp_alpha[exp_times >=0.8], label=label, c=cc)
## always plot short
try :
a2s = a2s.loc[:0.8]
exp_alpha = np.array([cf(linfit, np.log10(a2s.index.values[x:x+fit_points]),
np.log10(a2s.r2.values[x:x+fit_points]),p0)[0][0] for x in range(1,len(a2s)-fit_points)])
exp_times = a2s.index.values[1+fit_points//2:-fit_points//2]
exp_rs = np.sqrt(a2s.r2.values[1+fit_points//2:-fit_points//2])
# axes[0,1].plot(exp_times, exp_alpha, c=f'C{i}', ls='--')
axes[0,1].plot(exp_rs[exp_times <=0.8], exp_alpha[exp_times <=0.8], c=cc, ls='--')
except: pass
print(f'computed the exponent of MSD vs time for {mm} {cn} {T1}.')
axes[0,1].legend(title=leg_title, loc='lower right')
if guides:
axes[0,1].plot([0.03,3e5],[1,1], c='grey', lw=0.4, ls='--')
axes[0,1].plot([5.6,5.6],[0,2.1], c='grey', lw=0.4, ls='--')
# ===== (c) dx prep, and dx raw =====
if T1 == T1_dx:
## try loading a pre-computed dx file
dx_glob = glob.glob(plane.folder+f'/{mm}-*-dx-{T1}K*ps.csv')
dx = None
try:
dx = pd.read_csv(dx_glob[0])
dx = dx.set_index(['dx','time']).unstack().apply(lambda col: col/col.sum(), axis=0)
dx.columns = [x[1] for x in dx.columns]
except:
print(f'could not load a dx file for {mm} {cn} {T1}K')
continue
## apply binning by time intervals
time_tuples = [ (round(x*0.8), round(x*1.2)) for x in dx_times]
time_intervals = pd.IntervalIndex.from_tuples(time_tuples)
time_spectra = dx.T.groupby(pd.cut(dx.T.index,time_intervals)).agg('mean').T
## normalize each column to sum to 1
time_spectra = time_spectra / time_spectra.sum() / (time_spectra.index[1]-time_spectra.index[0])
## and rename the columns as something legible
col_names = [f'{x[0]}-{x[1]} ps' if max(x) < 1000 else f'{int(x[0])//1000}-{int(x[1])//1000} ns' for x in time_tuples]
time_spectra.rename(columns = dict(zip(time_spectra.columns,col_names)), inplace=True)
## plot each column
for col in time_spectra.columns :
xvals = time_spectra.loc[time_spectra[col] != 0].index
axes[1,0].plot(xvals, time_spectra.loc[time_spectra[col] != 0, col],
label=col, c=next(dx_colors))
axes[1,0].legend(title=leg_title + f' {T1}K')
# ===== (d) dx binned by hops and rescaled =====
if T1 == T1_dx :
## find the variances in dx to later rescale by them
col_sigmas = list()
for col, t in zip(time_spectra.columns, dx_times):
col_variance = time_spectra[col] * time_spectra.index.values **2 / time_spectra[col].sum()
col_sigma = np.sqrt(col_variance.sum())
print(f'{mm} {cn} {T1}K : {t} ps, sigma = {col_sigma:.2f} AA')
col_sigmas.append(col_sigma)
## numbers of hops from the Cartesian displacements
x_bins = (np.unique(dx.index.values // hop_length) * 2 - 1 ) * (hop_length / 2)
x_bins = np.insert(np.append(x_bins,max(x_bins)+hop_length), 0, min(x_bins)-hop_length)
## apply binning by number of hops
time_spectra = time_spectra.groupby(pd.cut(time_spectra.index,x_bins)).agg('sum')
time_spectra.index = (x_bins[:-1] + x_bins[1:])/2
## normalize each column to sum to 1
time_spectra = time_spectra / time_spectra.sum() / (time_spectra.index[1]-time_spectra.index[0])
## plot each column
for col, sigma in zip(time_spectra.columns, col_sigmas) :
xvals = time_spectra.loc[time_spectra[col] != 0].index
axes[1,1].plot(xvals/sigma,
time_spectra.loc[time_spectra[col] != 0, col]*sigma,
label=col, c=next(dx_colors))
axes[1,1].legend(title=leg_title + f' {T1}K')
## plot a Laplacian & a Gaussian as benchmarks
sigmas = np.linspace(-10, 10, 101)
gauss = np.exp(-sigmas**2/2) / sum(np.exp(-sigmas**2/2)) * len(sigmas)/(max(sigmas)-min(sigmas))
axes[1,1].plot(sigmas, gauss, c='grey', ls=':')
laplace = np.exp(-abs(sigmas)*np.sqrt(2)) / sum(np.exp(-abs(sigmas)*np.sqrt(2))) * len(sigmas)/(max(sigmas)-min(sigmas))
axes[1,1].plot(sigmas, laplace, c='k', ls=':')
# ===== (e) Gs fitting: hardcoded time bounds =====
if T1 in T1s_gs :
## try loading a pre-computed Gself file
gs = hu.load_gs(plane.folder+f'/{mm}-*-gs-{T1}K*ps.csv', 'fitting')
if gs is None: continue
for h, (rs, ls) in enumerate(zip(rs_list, ['--', '-', '-.', ':'])) :
s = gs.loc[min(rs):max(rs),0.1:5e4].sum().reset_index()
s.columns = ['time','gs']
s.set_index('time', inplace=True)
# s = s/s.max()
l = f'{label}, <{h+1} hop{"s" if h != 0 else ""}'
axes[2,0].plot(s, label = l, c=cc, ls=ls)
# ## fit and plot the fit
# try:
# s = s.loc[1:]
# popt, perr = expectation_multi_method(s, method, aggregated=True, verbose=True)
# if method == 'simple' : ax.plot(s.index.values, exp_decay(s.index.values, *popt), c='k', ls=':')
# elif method == 'stretch' : ax.plot(s.index.values, kww_decay_break(s.index.values, *popt), c='k', ls=':')
# print(f'fitting {mm} {cn} {T1} {min(rs):.1f}-{max(rs):.1f}AA : {popt[1]:.1f}±{perr[1]:.1f} ps, beta={1.00 if len(popt)<4 else popt[3]:.2f}, tstar={0 if len(popt)<4 else popt[4]:.2f}')
# except : pass
## inverse interpolating function to plot the 1/e time
int_fun = interp1d(s.gs.values, s.index.values)
try : axes[2,0].plot(int_fun(1/np.e), 1/np.e, marker='o', ls='', fillstyle='full',
mfc='yellow', mec='k', zorder=3, markersize=4)
except : print(f'for {mm} {cn} {T1}, not all radii decay to 1/e')
axes[2,0].legend(title=leg_title)
if guides: axes[2,0].plot([1e3,3e4],[1/np.e,1/np.e], c='grey', lw=0.4, ls='--')
# ===== (f) C_D(t) =====
if T1 not in cd_exclude :
start = dt.now()
svals = np.logspace(-5, 2, 4000) # if not short else np.logspace(-6,5,3000)
## Laplace transform of C_D(t)
cds = hu.fluctuation_kernel(a2, svals, dim=dim)
try: cdt = hu.stehfest_inverse(cds, a2.index.values[1:-1])
except :
print(f'could not append inverse transform for {mm} {cn} {T1}')
break
cdt = pd.DataFrame({'time':a2.index.values[1:-1],'cdt':cdt}).set_index('time')
if na_bdp_unsym : cdt = cdt.where(cdt < cd_break, cd_transform)
axes[2,1].plot(cdt.cdt.loc[0.2:a2.index.max()/3+1], label=label, c=cc)
## create the interpolator for plotting little stars based on Gs
## try loading a pre-computed Gself file
gs = hu.load_gs(plane.folder+f'/{mm}-*-gs-{T1}K*ps.csv', 'cdt', radii=rs_list)
int_fun = interp1d(cdt.index.values, cdt.cdt)
try: axes[2,1].scatter(gs, int_fun(gs), marker='o', facecolors='yellow', edgecolors='k', zorder=3, s=16)
except : print('something wrong with plotting Gs * for {mm} {cn} {T1}')
## plot short-time separately
cds_s = hu.fluctuation_kernel(a2s, np.logspace(0,4,1000), dim=dim)
cdt_s = hu.stehfest_inverse(cds_s, a2s.index.values[1:-1])
cdt_s = pd.DataFrame({'time':a2s.index.values[1:-1],'cdt':cdt_s}).set_index('time')
axes[2,1].plot(cdt_s.cdt.loc[0.0085 if (mm == 'Na' and 'unsym' in cn) else 0.005:0.2], ls='--', c=cc)
print(f'done {T1}K, time taken {(dt.now()-start).total_seconds():.2f}')
axes[2,1].plot([1e-3, 5e4], [0,0], c='grey', ls=':', lw=0.4)
axes[2,1].legend(title=leg_title, loc='upper left')
else :
print(f'skipping C_D(t) for {mm} {cn} {T1}')
## plot prettymaking
axes[0,0].set(xlim=[0.025,5e4], xscale='log', ylim=[1e-2,3e4], yscale='log',
xlabel=r'Time lag $t$, ps', ylabel=r'$\langle \overline{r^2(t)} \rangle$, $\AA^2$')
axes[0,1].set(xlim=[0.4,30], xscale='log', ylim=[0,1.05], xlabel=r'$\langle \overline{ r(t) }\rangle,~\AA$',
yticks=[0,0.2,0.4,0.6,0.8,1.], yticklabels=['0.0','0.2','0.4','0.6','0.8','1.0'],
xticks=[1,10], xticklabels=['1','10'],
ylabel=r'Exponent of $\langle \overline{ r^2(t) }\rangle$')
axes[1,0].set(xlim=[-28,28], ylim=[3e-5,None], yscale='log',
xlabel=r'$\Delta x$, $\AA$', ylabel=r'$P(\Delta x)$, $\AA^{-1}$')
axes[1,1].set(xlim=[-7,7], ylim=[1e-5,None], yscale='log',
xlabel=r'$(\Delta x)/\sigma_{\Delta x}$', ylabel=r'$P(\Delta x)$, $\sigma_{\Delta x}^{-1}$')
# axes[2,0].set(ylim=[0,13.5], xlim=[0.5,9e3], xscale='log',
# xlabel=r'Time lag $t$, ps', ylabel=r'Distance $r,~\AA$')
axes[2,0].set(xlim=[0.1,5e4], xscale='log', ylim=[0,1.04],
ylabel=r'$G_s~r^2$, a.u.', xlabel=r'Time lag $t$, ps')
axes[2,1].set(xlim=[5e-3,5e3], xscale='log',
xlabel=r'Time lag $t$, ps', ylabel=r'$C_D(t)$')
## create the broken axis
if na_bdp_unsym :
r1 = Rectangle((4.5e-3,cd_break),5.2e3,cd_break_top-cd_break, lw=0,
facecolor='w', clip_on=False, transform=axes[2,1].transData, zorder=3)
axes[2,1].add_patch(r1)
kwargs = dict(transform=axes[2,1].transData, color='k', clip_on=False, lw=0.75,zorder=4)
axes[2,1].plot(5e-3*np.array([10**-0.05,10**0.05]), [cd_break-0.05,cd_break+0.05],**kwargs)
axes[2,1].plot(5e-3*np.array([10**-0.05,10**0.05]), [cd_break_top-0.05,cd_break_top+0.05],**kwargs)
axes[2,1].plot(5e3*np.array([10**-0.05,10**0.05]), [cd_break-0.05,cd_break+0.05],**kwargs)
axes[2,1].plot(5e3*np.array([10**-0.05,10**0.05]), [cd_break_top-0.05,cd_break_top+0.05],**kwargs)
# axes[2,1].set(yticks=[0,2,4,cd_transform(10), cd_transform(15)], yticklabels=['0','2','4','10','15'])
axes[2,1].set(yticks=[0,2,4,cd_transform(6), cd_transform(8)], yticklabels=['0','2','4','6','8'])
axes[2,1].set(ylim=[-0.7,7.1])
fig.tight_layout(pad=0.5, h_pad=0.25)
# =============================================================================
# %% Figure 3 top row: spectra of conductivity
# =============================================================================
## Parameters:
start_1 = 0
start_step = 10 ## [ps] interval for sampling eMSD
durations = np.round(np.logspace(0.4,3.4),2) ## [ps] 2.5-2500 ps, 50 pts
enforce_indep = True ## make start_step >= duration, for all durations
# rs_list = [[0.01,1.7],[0.01, 4.6]] ## to plot two-hop relaxation as the Jonscher cutoff
rs_list = []
# ========== automatic things below this line ==========
## three-panel top row
fig, axes = plt.subplots(1,3, sharey=True, figsize=(12,4))
# fig, axes = plt.subplots(3,1, sharex=True, figsize=(4,9))
# ===== (a) Na-beta-doubleprime spectra vs T1 =====
## load three planes
planes_to_load = all_planes.query('metal == "Na" & config == "unsym_0" & T1 in [230,300,473]')
macro_planes_data = hu.load_macro_planes(planes_to_load).sort_values(by='T1')
colors = cycle([batlow_even(j) for j in np.linspace(0, 1, len(macro_planes_data))])
ax = axes[0]
## load and plot Na doubleprime conductivity spectra
for i, plane in macro_planes_data.iterrows():
ph = plane.phase; mm = plane.metal; cn = plane.config
st = plane.stoich; ex = plane.exclude
T1 = plane.T1; folder = plane.folder
N = len(plane.atoms.query('atom == @mm'))
cell = plane.cell
dcoms = list()
## load a pre-corrected CoM trajectory
cor = False
try:
cor_fname = glob.glob(plane.folder + f'/cm_{mm}-{st}-{ex}-{T1}K-{mm}-cor.csv')
if isinstance(cor_fname, list) and len(cor_fname) == 1 :
com = pd.read_csv(cor_fname[0]).set_index('time')
print(f'\nLoaded a corrected CoM trajectory for {mm} {cn} T1={T1}K')
cor = True
except :
com = None; continue
dtt = com.index[1]-com.index[0]
## average multiple starts
for duration in durations:
## enforce start_step >= duration
if enforce_indep and start_step < duration : start_step = duration
if com.index.max() <= duration*4 :
dcoms.append(np.nan)
continue
dr = com.loc[duration+com.index.min()::int(start_step/dtt)] - com.loc[:com.index.max()-duration:int(start_step/dtt)].values
# dr['dcom'] = (dr.x**2 + dr.y**2 + dr.z**2)/duration
dr['dcom'] = (dr.x**2 + dr.y**2 )/duration
all_dcom2 = dr.dcom.values * N / 4
dcoms.append(np.mean(all_dcom2))
## transform D_CoM to conductivity and plot it
sigmas = sigma_T(N,cell,np.array(dcoms)*unit_conv)/T1
this_marker = next(markers)
ax.plot(1e12/durations, sigmas, this_marker+next(lines), label=f'eMSD, {T1}K',
markersize=5, c=next(colors))
## plot the two-hop relaxation time
int_fun = interp1d(1e12/durations, sigmas, fill_value=1e-10, bounds_error=False)
gs = np.array(hu.load_gs(folder+f'/{mm}-*-gs-{T1}K*ps.csv', option='Funke', radii=rs_list))
ax.plot(1e12/gs, int_fun(1e12/gs), marker=this_marker, mfc='yellow', mec='k', zorder=3, ls='', fillstyle='full')
## plot literature values:
refs = {'Funke2007':52, 'Almond1984':32, 'Hoppe1991':51, 'Barker1976':44,
'Kamishima2014':30, 'Kamishima2015':31}
## Funke & Banhatti (2007) - 473K
lit6 = pd.read_csv('./production/bdp-Na/Na_unsym_Funke2007_473K_lit.csv', names=['logfreq','sigma'])
axes[0].plot(10**lit6.logfreq, (10**lit6.sigma)/473, marker='o', mec='k', ls='', zorder=0,
mfc='none', markersize=4, label=f'Ref. {refs["Funke2007"]}, 473K') ## Funke $\\it{et\ al.}$ (2007), ($Li_{Al}^{\prime\prime}$)
## Hoppe & Funke (1991) - 220K
lit2 = pd.read_csv('./production/bdp-Na/Na_unsym_Hoppe1991_220K_lit.csv', names=['logfreq','sigma'])
axes[0].plot(10**lit2.logfreq, lit2.sigma, marker='o', mec='k', ls='', zorder=0,
mfc='none', markersize=4, label=f'Ref. {refs["Hoppe1991"]}, 220K') ## Hoppe $\\it{et\ al.}$ (1991), ($Li_{Al}^{\prime\prime}$)
## Hoppe & Funke (1991) - 298K
lit5 = pd.read_csv('./production/bdp-Na/Na_unsym_Hoppe1991_298K_lit.csv', names=['logfreq','sigma'])
axes[0].plot(10**lit5.logfreq, lit5.sigma, marker='^', mec='k', ls='', zorder=0,
mfc='none', markersize=4, label=f'Ref. {refs["Hoppe1991"]}, 298K') ## Hoppe $\\it{et\ al.}$ (1991) ($Li_{Al}^{\prime\prime}$)
## Almond et al (1984) - 237K
lit1 = pd.read_csv('./production/bdp-Na/Na_unsym_Almond1984_237K_lit.csv', names=['logfreq','sigma'])
axes[0].plot(10**lit1.logfreq, lit1.sigma, marker='d', mec='k', ls='', zorder=0,
mfc='k', fillstyle='full', markersize=4, label=f'Ref. {refs["Almond1984"]}, 237K') ## Almond $\\it{et\ al.}$ (1984)
## Almond (1984) - 296K
lit3 = pd.read_csv('./production/bdp-Na/Na_unsym_Almond1984_296K_lit.csv', names=['logfreq','sigma'])
axes[0].plot(10**lit3.logfreq, lit3.sigma, marker='s', mec='k', ls='', zorder=0,
mfc='k', fillstyle='full', markersize=4, label=f'Ref. {refs["Almond1984"]}, 296K') ## Almond $\\it{et\ al.}$ (1984)
## make plot pretty
axes[0].set(xlim=[8e5,6e11], ylim=[6e-4,1.2], xscale='log', yscale='log',
xlabel=r'$\nu=1/t$, Hz', ylabel=r'$\sigma_{2D}(t;\Delta)$, S/cm')
axes[0].legend(title=r'Na $\beta^{\prime\prime}$', ncol=2, handletextpad=0.5,
handlelength=1.5, columnspacing=0.4, loc='upper left')
## add guidelines
axes[0].plot([1e6, 2e9], [6e-3, 6e-3*2000**0.15], c='grey', lw=0.4)
axes[0].plot([1e6, 2e8], [1e-3, 1e-3*200**0.15], c='grey', lw=0.4)
axes[0].plot([4e9, 4e11], [0.06*100**-0.7, 0.06], c='grey', lw=0.4)
# ===== (b) Na-beta spectra 300K =====
## load planes
planes_to_load = all_planes.query('metal == "Na" & config == "120_4" & T1 == 300')
macro_planes_data = hu.load_macro_planes(planes_to_load)
ax = axes[1]
## load and plot Na beta conductivity spectra
for i, plane in macro_planes_data.iterrows():
ph = plane.phase; mm = plane.metal; cn = plane.config
st = plane.stoich; ex = plane.exclude
T1 = plane.T1; folder = plane.folder
N = len(plane.atoms.query('atom == @mm'))
cell = plane.cell
dcoms = list()
## load a pre-corrected CoM trajectory
cor = False
try:
cor_fname = glob.glob(plane.folder + f'/cm_{mm}-{st}-{ex}-{T1}K-{mm}-cor.csv')
if isinstance(cor_fname, list) and len(cor_fname) == 1 :
com = pd.read_csv(cor_fname[0]).set_index('time')
print(f'\nLoaded a corrected CoM trajectory for {mm} {cn} T1={T1}K')
cor = True
except :
com = None; continue
dtt = com.index[1]-com.index[0]
## average multiple starts
for duration in durations:
## enforce start_step >= duration
if enforce_indep and start_step < duration : start_step = duration
if com.index.max() <= duration*4 :
dcoms.append(np.nan)
continue
dr = com.loc[duration+com.index.min()::int(start_step/dtt)] - com.loc[:com.index.max()-duration:int(start_step/dtt)].values
# dr['dcom'] = (dr.x**2 + dr.y**2 + dr.z**2)/duration
dr['dcom'] = (dr.x**2 + dr.y**2 )/duration
all_dcom2 = dr.dcom.values * N / 4
dcoms.append(np.mean(all_dcom2))
sigmas = sigma_T(N,cell,np.array(dcoms)*unit_conv)/T1
this_marker = next(markers)
ax.plot(1e12/durations, sigmas, this_marker+next(lines), label=f'eMSD, {T1}K',
markersize=5, c=batlow_even(0))
## plot the two-hop relaxation time
int_fun = interp1d(1e12/durations, sigmas, fill_value=1e-10, bounds_error=False)
gs = np.array(hu.load_gs(folder+f'/{mm}-*-gs-{T1}K*ps.csv', option='Funke', radii=rs_list))
ax.plot(1e12/gs, int_fun(1e12/gs), marker=this_marker, mfc='yellow', mec='k', zorder=3, ls='', fillstyle='full')
## plot literature values
## 2 literature datasets, Barker (1976) - 300K ## Barker $\\it{et\ al.}$ (1976)
lit1 = pd.read_csv('./production/beta-Na/Na_120_Barker1976_flux_lit.csv', names=['logfreq','sigma'])
axes[1].plot(10**lit1.logfreq, lit1.sigma, marker='D', mec='k', markersize=4, ls='', zorder=0,
mfc='none', label=f'Ref. {refs["Barker1976"]}, 300K, flux')
lit2 = pd.read_csv('./production/beta-Na/Na_120_Barker1976_melt_lit.csv', names=['logfreq','sigma'])
axes[1].plot(10**lit2.logfreq, lit2.sigma, marker='s',mec='k', markersize=4, ls='', zorder=0,
mfc='none', label=f'Ref. {refs["Barker1976"]}, 300K, melt')
## Kamishima (2015) - 300K # Kamishima $\\it{et\ al.}$ (2015)
axes[1].plot(1e7, 0.011692, marker='>', mec='k', markersize=4, ls='', zorder=0,
mfc='k', fillstyle='full', label=f'Ref. {refs["Kamishima2015"]}, 300K')
## make plot pretty
axes[1].set(xlim=[7e6,6e11], xscale='log', xlabel=r'$\nu=1/t$, Hz')
axes[1].legend(title=r'Na $\beta$', handletextpad=0.5, handlelength=1.5)
## add guidelines
axes[1].plot([1e7, 4e8], [6e-3, 6e-3*40**0.1], c='grey', lw=0.4)
axes[1].plot([4e9, 4e11], [0.05*100**-0.6, 0.05], c='grey', lw=0.4)
# ===== (c) Ag-beta spectra 300K =====
## load planes
planes_to_load = all_planes.query('metal == "Ag" & config == "120_4" & T1 == 300')
macro_planes_data = hu.load_macro_planes(planes_to_load)
ax = axes[2]
## load and plot Ag beta conductivity spectra
for i, plane in macro_planes_data.iterrows():
ph = plane.phase; mm = plane.metal; cn = plane.config
st = plane.stoich; ex = plane.exclude
T1 = plane.T1; folder = plane.folder
N = len(plane.atoms.query('atom == @mm'))
cell = plane.cell
dcoms = list()
## load a pre-corrected CoM trajectory
cor = False
try:
cor_fname = glob.glob(plane.folder + f'/cm_{mm}-{st}-{ex}-{T1}K-{mm}-cor.csv')
if isinstance(cor_fname, list) and len(cor_fname) == 1 :
com = pd.read_csv(cor_fname[0]).set_index('time')
print(f'\nLoaded a corrected CoM trajectory for {mm} {cn} T1={T1}K')
cor = True
except :
com = None; continue
dtt = com.index[1]-com.index[0]
## average multiple starts
for duration in durations:
## enforce start_step >= duration
if enforce_indep and start_step < duration : start_step = duration
if com.index.max() <= duration*4 :
dcoms.append(np.nan)
continue
dr = com.loc[duration+com.index.min()::int(start_step/dtt)] - com.loc[:com.index.max()-duration:int(start_step/dtt)].values
# dr['dcom'] = (dr.x**2 + dr.y**2 + dr.z**2)/duration
dr['dcom'] = (dr.x**2 + dr.y**2 )/duration
all_dcom2 = dr.dcom.values * N / 4
dcoms.append(np.mean(all_dcom2))
sigmas = sigma_T(N,cell,np.array(dcoms)*unit_conv)/T1
this_marker = next(markers)
ax.plot(1e12/durations, sigmas, this_marker+next(lines), label=f'eMSD, {T1}K', markersize=5,
c=batlow_even(0))
## plot the two-hop relaxation time
int_fun = interp1d(1e12/durations, sigmas, fill_value=1e-10, bounds_error=False)
gs = np.array(hu.load_gs(folder+f'/{mm}-*-gs-{T1}K*ps.csv', option='Funke', radii=rs_list))
ax.plot(1e12/gs, int_fun(1e12/gs), marker=this_marker, mfc='yellow', mec='k', zorder=3, ls='', fillstyle='full')
## plot literature values
## Barker (1976) melt - 300K # Barker $\\it{et\ al.}$ (1976) melt
lit21 = pd.read_csv('./production/beta-Ag/Ag_120_Barker1976_melt_lit.csv', names=['logfreq','sigma'])
axes[2].plot(10**lit21.logfreq, lit21.sigma, marker='s', mec='k', markersize=4, ls='',
mfc='none', label=f'Ref. {refs["Barker1976"]}, 300K, melt', zorder=0)
## 3 samples from Kamishima (2014) - near 300K ## Kamishima $\\it{et\ al.}$ (2014)
lit22 = pd.read_csv('./production/beta-Ag/Ag_120_Kamishima2014_296K_S1_lit.csv', names=['logfreq','sigma'])
axes[2].plot(10**lit22.logfreq, lit22.sigma, marker='o', mec='k', markersize=4, ls='',
mfc='k', fillstyle='full', label=f'Ref. {refs["Kamishima2014"]}, 296K, A', zorder=0)
lit23 = pd.read_csv('./production/beta-Ag/Ag_120_Kamishima2014_286K_S2_lit.csv', names=['logfreq','sigma'])
axes[2].plot(10**lit23.logfreq, lit23.sigma, marker='^', mec='k', markersize=4, ls='',
mfc='k', fillstyle='full', label=f'Ref. {refs["Kamishima2014"]}, 286K, B', zorder=0)
lit24 = pd.read_csv('./production/beta-Ag/Ag_120_Kamishima2014_299K_S3_lit.csv', names=['logfreq','sigma'])
axes[2].plot(10**lit24.logfreq, lit24.sigma, marker='v', mec='k', markersize=4, ls='',
mfc='k', fillstyle='full', label=f'Ref. {refs["Kamishima2014"]}, 299K, C', zorder=0)
## make plot pretty
axes[2].set(xlim=[5e5,6e11], xscale='log', xlabel=r'$\nu=1/t$, Hz')
axes[2].legend(title=r'Ag $\beta$', handletextpad=0.5, handlelength=1.5)
## add guidelines
axes[2].plot([4e9, 4e11], [0.05*100**-0.6, 0.05], c='grey', lw=0.4)
axes[2].plot([2e6, 2e8], [3e-3, 3e-3*100**0.1], c='grey', lw=0.4)
fig.tight_layout(pad=0.5, w_pad=0.25)
# =============================================================================
# %% Fig 3 bottom row: Arrhenius plots
# =============================================================================
# Parameters:
start_1 = 0 ## [ps] time at which to start sampling CoM MSD
start_step = 2500 ## [ps] interval for sampling CoM MSD
start_last = 97500 ## [ps] last time at which to sample CoM MSD
duration = 2500 ## [ps] how long each sampling is
refs_dict = {'Davies(1986)':38, 'Briant(1980)':34, 'Bates(1981)':35,
'Whittingham(1972)':55, 'Almond(1984)':32}
beta_refs_dict = {'Ag':53, 'K':55, 'Na':54}
# ========== automatic things below this line ==========
## array for multiple starts and its tuple description for lookup of pre-dones
starts = np.arange(start_1,start_last,start_step,dtype=float)
spec=(start_1,start_step,start_last,duration)
## pre-load and filter for the same computation conditions right away
sigmas_msd = pd.read_csv('./production/sigmas_msd.csv')
sigmas_msd.spec = sigmas_msd.spec.apply(eval)
sigmas_msd_spec = sigmas_msd.query('spec == @spec')
# figure
fig, axes = plt.subplots(1,3, sharey=True, figsize=(12,4))
# ===== (d) Na-doubleprime: normal + quenched =====
planes_to_load = all_planes.query('metal == "Na" & config in ["unsym_0", "symm_1"] & T1 in [230,300,473,600]')
macro_planes_data = hu.load_macro_planes(planes_to_load)
## structure for new computations
new_sigmas_msd = list()
for i, plane in macro_planes_data.iterrows():
all_dcom = list()
all_derr = list()
ph = plane.phase
mm = plane.metal
cn = plane.config
st = plane.stoich
ex = plane.exclude
T1 = plane.T1
com = plane.com
N = len(plane.atoms.query('atom == @mm'))
## check this configuration was already computed
pre_done = sigmas_msd_spec.query('metal == @mm & stoich == @st & exclude == @ex & T1 == @T1')
assert len(pre_done) > 0, 're-compute {mm} {cn} {T1}'
new_sigmas_msd.append(pre_done.to_dict('records')[0])
# print(f'pre-done {variable}={var}, {variable2}={var2} T1={T1}K, sigma*T = {pre_done.sigt.iloc[0]:.2e} S*K/cm')
## convert all fitted sigmas to dataframe
new_sigmas_msd = pd.DataFrame(new_sigmas_msd)
## plot normal Na beta-doubleprime
sigts = new_sigmas_msd.query('config == "unsym_0"')
axes[0].errorbar(x=1000./sigts.T1.values, y=sigts.sigt, zorder=2.5,
yerr=[sigts.sigt-sigts.sigt_20, sigts.sigt_80-sigts.sigt],
label=r'Na $\beta^{\prime\prime}$, eMSD', mfc=hu.metal_colors['Na'],
mec=hu.metal_colors['Na'], c=hu.metal_colors['Na'],
fillstyle='full', marker='o', ls='')
## plot literature values
lit_folder = macro_planes_data.lit_folder.unique()[0]
d_lit_files = sorted(glob.glob(lit_folder + f'/{mm}*sigma*lit.csv'), reverse=True)
for f, sym in zip(d_lit_files, ['o','s','D','v','^','<','>']) :
d_lit = np.loadtxt(f, delimiter = ',')
# print('loaded', f)
## find the author+year if they are in the filename
auth = [x[0] for x in [re.findall('[A-z]*\(19\d\d\)$', x) for x in re.split('/|-|_| ',f)] if len(x) > 0][0]
try: t_synth = [x[0] for x in [re.findall('1\d\d0$', x) for x in re.split('/|-|_| ',f)] if len(x) > 0][0]
except: t_synth = None
ref = refs_dict[auth]
label = f'Ref. {ref}'
if 'symm' in f :
label += ', quench'
continue ## skip this for simplifying the plot
elif t_synth is not None :
# label += f', {t_synth}C'
if int(t_synth) == 1700 : continue
## scatterplot, can be updated to include errorbars
axes[0].plot(d_lit[:,0], 10**d_lit[:,1], label=label, zorder=0,
mec='k', # if variable2 != 'metal' else hu.metal_colors[var],
mfc=(0,0,0,0), marker=sym, linestyle='', markersize=5)
axes[0].set(ylabel='$\sigma$T [$\Omega^{{-1}}$ cm$^{{-1}}$ K]', xlabel='1000/T, K$^{-1}$',
ylim=[1.5e-2,1.7e3], yscale='log', xlim=[1.3,4.45])
axes[0].legend(loc='lower left', title=r'Na $\beta^{\prime\prime}$', title_fontsize=10)
# ===== (e) K,Ag-doubleprime =====
planes_to_load = all_planes.query('metal in ["K", "Ag"] & config == "unsym_0" & T1 in [230,300,473,600]')
macro_planes_data = hu.load_macro_planes(planes_to_load)
## structure for new computations
new_sigmas_msd = list()
for i, plane in macro_planes_data.iterrows():
all_dcom = list()
all_derr = list()
ph = plane.phase
mm = plane.metal
cn = plane.config
st = plane.stoich
ex = plane.exclude
T1 = plane.T1
com = plane.com
N = len(plane.atoms.query('atom == @mm'))