-
Notifications
You must be signed in to change notification settings - Fork 0
/
mag_susceptibility.py
607 lines (491 loc) · 18.7 KB
/
mag_susceptibility.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
# -*- coding: utf-8 -*-
"""
Created on Mon May 9 16:47:20 2022
@author: C.Cattin
"""
import numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['text.latex.preamble'] = r'\boldmath'
font = {'family' : 'serif',
'serif' : 'cm10',
'weight' : 'bold',
'size' : 16}
matplotlib.rc('font', **font)
import matplotlib.pyplot as plt
### OPEN FILE ###
def open_file(path):
'''
Extract data from .dat file from MPMS experiments
Parameters
----------
path : str
Path to the file.
Returns
-------
M magnetization, array
H magnetic field, array
'''
with open(path) as file :
data = file.read()
file.close()
#Splitting each line
data = data.replace('\n',',').split(',')
#Remove the header
data = data[138:]
#Get the title of each collumn
title = data[1:69]
#Remove the title of the collumnns
data = data[69:]
#Extract data
comment = data[::len(title)]
Time_stamp = np.array(data[1::len(title)],dtype=np.float32)
Temperature = np.array(data[2::len(title)],dtype=np.float32)
Magnetic_Field = np.array(data[3::len(title)],dtype=np.float32)
center_position = np.array(data[10::len(title)],dtype=np.float32)
range_data = np.array(data[13::len(title)],dtype=np.float32)
min_temp = np.array(data[15::len(title)],dtype=np.float32)
max_temp = np.array(data[16::len(title)],dtype=np.float32)
min_field = np.array(data[17::len(title)],dtype=np.float32)
max_field = np.array(data[18::len(title)],dtype=np.float32)
DC_Moment_Free_Ctr = np.array(data[39::len(title)],dtype=np.float32)
DC_Moment_Err_Free_Ctr = np.array(data[40::len(title)],dtype=np.float32)
DC_Moment_Fixed_Ctr = np.array(data[37::len(title)],dtype=np.float32)
DC_Moment_Err_Fixed_Ctr= np.array(data[38::len(title)],dtype=np.float32)
return (data,
title,
comment,
Time_stamp,
Temperature,
Magnetic_Field,
center_position,
range_data,
min_temp,max_temp,
min_field,max_field,
DC_Moment_Free_Ctr,DC_Moment_Err_Free_Ctr,
DC_Moment_Fixed_Ctr,DC_Moment_Err_Fixed_Ctr
)
### MATH ###
def compute_chi(DC_Moment_Free_Ctr,Magnetic_Field,mass,Molar_Weight):
"""
Compute magnetic susceptibility from magnetic moment, magnetic field,
mass of the sample and the molar weight of the species.
Parameters
----------
DC_Moment_Free_Ctr : np.array
magnetic moment
Magnetic_Field : np.array
applied magnetic field
mass : float
Mass of the sample
Molar_Weight : float
Molar weight of the sample
Returns
-------
chi : np.array
magnetic suceptibility
inv_chi : np.array
Inverse of the magnetic suceptibility
"""
#Compute chi
chi = DC_Moment_Free_Ctr/mass * Molar_Weight / Magnetic_Field
#Compute the inverse of chi
inv_chi = 1/chi
return chi,inv_chi
def get_C_factor(inv_chi,Temperature):
"""
Fit 1/chi versus the temperature with the Curie-Weiss law :
\chi^{-1} = T/C - \theta_{CW}/C
Parameters
----------
inv_chi : np.array
Inverse of the magnetic susceptibility
Temperature : np.array
Temperature of the system
Returns
-------
C : float
C factor in the Curie-Weiss law
Theta_CW : float
Theta in the Curie-Weiss law
"""
#Only one magnetic field
if Temperature.size == 1:
#Only applied above 250K
index = np.where(Temperature<=250)
#Remove other data
Temperature = np.delete(Temperature,index)
inv_chi = np.delete(inv_chi,index)
#Fit data
inv_C,minus_Theta_over_C = np.polyfit(Temperature,inv_chi,1)
#Various magnetic fields
else :
#Only applied above 250K
#Initializing
index = np.where(Temperature[0]<=250)
#Remove other data
Temperature_new = np.delete(Temperature[0],index)
inv_chi_new = np.delete(inv_chi[0],index)
#Fit data
inv_C,minus_Theta_over_C = np.polyfit(Temperature_new,inv_chi_new,1)
#Loop over all the different magnetic fields
for i in range(1,Temperature.size):
#ONly apply above 250K
index = np.where(Temperature[i]<=250)
#Remove other data
Temperature_new_i = np.delete(Temperature[i],index)
inv_chi_new_i = np.delete(inv_chi[i],index)
#Fit data
inv_C_i,minus_Theta_over_C_i = np.polyfit(Temperature_new_i,inv_chi_new_i,1)
#Concatenate
inv_C = np.vstack((inv_C,inv_C_i))
minus_Theta_over_C = np.vstack((minus_Theta_over_C,minus_Theta_over_C_i))
#Return the correct values
C = 1/inv_C
Theta_CW = - minus_Theta_over_C * C
return C , Theta_CW
def compare_mu_eff(spin,C,g=2):
"""
Compare the factor before mu_B for the mu_eff
Parameters
----------
spin : float
spin of the system.
C : float
C factor in the Curie-Weiss law
g : float, optional
g factor. The default is 2.
Returns
-------
theory : float
Factor in theory.
experiment : float
Factor in the experiment.
"""
theory = g*np.sqrt(spin*(spin+1))
experiment = np.sqrt(8*C)
print('Theory : {}'.format(theory))
print('Experiment : {}'.format(experiment))
return theory,experiment
### PLOT ###
def plot_chi_temperature(chi,inv_chi,
Temperature,
mag_field,
file_save=['chi_vs_T.pdf',
'inv_chi_vs_T.pdf'],
color=['red','blue'],
label = r'B=0.1T'):
"""
Generate a plot of chi and 1/chi versus the temperature
Parameters
----------
chi : np.array
magnetic suceptibility
inv_chi : np.array
Inverse of the magnetic suceptibility
Temperature : np.array
Temperature of the system.
mag_field : array
magnetic fields applied to the system
file_save : array of str, optionnal
file name to save the plot, the default is ['chi_vs_T.pdf','inv_chi_vs_T.pdf']
color : array of str , optionnal
color of the different plot, the default is ['red','blue']
label : array of str , optionnal
label of each data set (Chemical compound and magnetic field for example)
Returns
-------
fig and ax of the different plots
"""
#Fit C and Theta_CW via the Curie-Weiss law
C, Theta_CW = get_C_factor(inv_chi, Temperature)
#Plot chi versus temperature
fig_1,ax_1 = plt.subplots(1)
#If only one magnetic field
if chi.size == 1 :
ax_1.plot(Temperature,chi,'o',color='red',markersize=3,mfc='none',
label=label)
#If various magnetic fields
else :
#Loop over all the different magnetic fields
for i in range(chi.size):
ax_1.plot(Temperature[i],chi[i],
'o',color=color[i],markersize=3,mfc='none',
label=label[i])
#General properties
ax_1.grid()
ax_1.set_xlabel(r'$T(K)$')
ax_1.set_ylabel(r'$\chi(emu.mol^{-1})$')
ax_1.legend()
#Save the figure
plt.savefig(file_save[0],bbox_inches='tight')
#Plot 1/chi versus the temperature and the fitting curve
#1/chi vs T
fig_2,ax_2 = plt.subplots(1)
#If only one magnetic field
if chi.size == 1:
ax_2.plot(Temperature,inv_chi,'o',color='red',markersize=3,mfc='none',
label=label)
#Fitted data
#Only applied above 250K
index = np.where(Temperature<=250)
#Remove other data
Temperature = np.delete(Temperature,index)
inv_chi = np.delete(inv_chi,index)
#Plot
ax_2.plot(Temperature,Temperature/C - Theta_CW/C,color='black',label='Fitted curve')
#If various magnetic fields
else :
#Loop over all the different magnetic fields
for i in range(chi.size):
ax_2.plot(Temperature[i],inv_chi[i],
'o',color=color[i],markersize=3,mfc='none',
label=label[i])
#Fitted data
#Only applied above 250K
index = np.where(Temperature[i]<=250)
#Remove other data
Temperature_new = np.delete(Temperature[i],index)
#Plot
ax_2.plot(Temperature_new,Temperature_new/C[i] - Theta_CW[i]/C[i],
color='black',label='Fitted curve')
#General properties
ax_2.grid()
ax_2.set_xlabel(r'$T(K)$')
ax_2.set_ylabel(r'$\chi^{-1}(emu^{-1}.mol)$')
ax_2.legend()
plt.savefig(file_save[1],bbox_inches='tight')
plt.show()
return fig_1,ax_1,fig_2,ax_2
### MAIN FUNCTION ###
def main_susceptibility(path,
mass,Molar_Weight,spin,mag_field,
file_save,
abnormal_value=False,
color = ['red','blue'],
label = r'B=0.1T'):
'''
Main function of the programm
Parameters
----------
path : str
Path to the files.
mass : float
Mass of the system in g
Molar_Weight : float
Molar weight of the system in g/mol
spin : float
Spin of the system
mag_field : array
Applied magnetic fields in T
file_save : list of str
path to save the plot : [chi_VS_T.pdf,inv_chi_VS_T]
abnormal_value : list, optional
List of the index of abnormal values. The default is False.
color : array of str , optionnal
color of the different plot, the default is ['red','blue']
label : array of str , optionnal
label of each data set (Chemical compound and magnetic field for example)
Returns
-------
C : float
C factor in the Curie-Weiss law
Theta_CW : float
Theta in the Curie-Weiss law
theory : float
Factor in theory.
experiment : float
Factor in the experiment.
'''
#If only one magnetic field
if type(path) == str :
#Extract data
(data,
title,
comment,
Time_stamp,
Temperature,
Magnetic_Field,
center_position,
range_data,
min_temp,max_temp,
min_field,max_field,
DC_Moment_Free_Ctr,DC_Moment_Err_Free_Ctr,
DC_Moment_Fixed_Ctr,DC_Moment_Err_Fixed_Ctr
) = open_file(path)
#Compute chi
chi,inv_chi = compute_chi(DC_Moment_Free_Ctr, Magnetic_Field, mass, Molar_Weight)
#Delete abnormal values
if abnormal_value != False :
chi = np.delete(chi,abnormal_value)
inv_chi = np.delete(inv_chi,abnormal_value)
Temperature = np.delete(Temperature,abnormal_value)
#Various magnetic fields
else:
#Extract data
#Initialization
(data,
title,
comment,
Time_stamp,
Temperature,
Magnetic_Field,
center_position,
range_data,
min_temp,max_temp,
min_field,max_field,
DC_Moment_Free_Ctr,DC_Moment_Err_Free_Ctr,
DC_Moment_Fixed_Ctr,DC_Moment_Err_Fixed_Ctr
) = open_file(path[0])
#Compute chi
chi,inv_chi = compute_chi(DC_Moment_Free_Ctr, Magnetic_Field, mass, Molar_Weight)
#Delete abnormal values
if abnormal_value != False :
chi = np.delete(chi,abnormal_value)
inv_chi = np.delete(inv_chi,abnormal_value)
Temperature = np.delete(Temperature,abnormal_value)
#Loop over all the different magnetic fields
for i in range(1,len(path)):
#Extract data
(data,
title,
comment,
Time_stamp,
Temperature_i,
Magnetic_Field,
center_position,
range_data,
min_temp,max_temp,
min_field,max_field,
DC_Moment_Free_Ctr,DC_Moment_Err_Free_Ctr,
DC_Moment_Fixed_Ctr,DC_Moment_Err_Fixed_Ctr
) = open_file(path[i])
#Compute chi
chi_i,inv_chi_i = compute_chi(DC_Moment_Free_Ctr, Magnetic_Field, mass, Molar_Weight)
#Delete abnormal values
if abnormal_value != False :
chi_i = np.delete(chi_i,abnormal_value)
inv_chi_i = np.delete(inv_chi_i,abnormal_value)
Temperature_i = np.delete(Temperature_i,abnormal_value)
#Concatenate
#chi = np.vstack((chi,chi_i))
#inv_chi = np.vstack((inv_chi,inv_chi_i))
#Temperature = np.vstack((Temperature,Temperature_i))
chi = [chi]
chi.append(chi_i)
chi = np.array(chi,dtype=object)
inv_chi = [inv_chi]
inv_chi.append(inv_chi_i)
inv_chi = np.array(inv_chi,dtype=object)
Temperature = [Temperature]
Temperature.append(Temperature_i)
Temperature = np.array(Temperature,dtype=object)
#Do the plot
fig_1 , ax_1 , fig_2 , ax_2 = plot_chi_temperature(chi,inv_chi,Temperature,
mag_field=mag_field,
file_save=file_save,color=color,label=label)
#Get the C factor
C , Theta_CW = get_C_factor(inv_chi, Temperature)
#Compare results
theory,experiment = compare_mu_eff(spin, C)
return C , Theta_CW , theory , experiment,chi,inv_chi,Temperature, fig_1,ax_1,fig_2,ax_2
if __name__=='__main__':
path = {
#06/05 Experiment on Li2MnO3
'06/05_01T' : '../Mag/Li2MnO3/06_05/06_05_Li2MnO3_01T.dat',
'06/05_1T' : '../Mag/Li2MnO3/06_05/06_05_Li2MnO3_1T.dat',
#11/05 Experiment on Li3Ni2SbO6
'11/05_01T' : '../Mag/Li3Ni2SbO6/11_05/11_05_Li3Ni2SbO6_01T.dat',
'11/05_1T' : '../Mag/Li3Ni2SbO6/11_05/11_05_Li3Ni2SbO6_1T.dat',
#20/05 Experiment on Li3Ni2SbO6 Protonated HT
'20/05_01T_size' : '../Mag/Li3Ni2SbO6/20_05_Proton_HT/20_05_Li3Ni2SbO6_proton_HT_01T_size.dat',
'20/05_01T' : '../Mag/Li3Ni2SbO6/20_05_Proton_HT/20_05_Li3Ni2SbO6_proton_HT_01T.dat',
'20/05_1T' : '../Mag/Li3Ni2SbO6/20_05_Proton_HT/20_05_Li3Ni2SbO6_proton_HT_1T.dat',
#25/05 Experiment on Li2MnO3 protonated 50C 4M 48h
'25/05_01T' : '../Mag/Li2MnO3/25_05/25_05_Li2MnO3_proton_50_4M_48h_01T.dat',
'25/05_1T' : '../Mag/Li2MnO3/25_05/25_05_Li2MnO3_proton_50_4M_48h_1T.dat',
'25/05_1T_size' : '../Mag/Li2MnO3/25_05/25_05_Li2MnO3_proton_50_4M_48h_1T_size.dat',
#07/06 Experiment on Na3Ni2SbO6
'07/06_01T' : '../Mag/Na3Ni2SbO6/07_06/07_06_Na3Ni2SbO6_01T.dat',
'07/06_1T' : '../Mag/Na3Ni2SbO6/07_06/07_06_Na3Ni2SbO6_1T.dat',
'07/06_01T_size' : '../Mag/Na3Ni2SbO6/07_06/07_06_Na3Ni2SbO6_01T_size.dat',
#09/06 Experiment on Li3Co2SbO6
'09/06_01T' : '../Mag/Li3Co2SbO6/09_06/09_06_Li3Co2SbO6_01T.dat',
'09/06_1T' : '../Mag/Li3Co2SbO6/09_06/09_06_Li3Co2SbO6_1T.dat',
#10/06 Experiment on Co2P2O7
'10/06_01T' : '../Mag/Co2P2O7/10_06/10_06_Co2P2O7_01T.dat',
'10/06_01T_corrected' : '../Mag/Co2P2O7/10_06/10_06_Co2P2O7_01T_corrected.dat',
'10/06_1T' : '../Mag/Co2P2O7/10_06/10_06_Co2P2O7_1T.dat',
'10/06_1T_corrected' : '../Mag/Co2P2O7/10_06/10_06_Co2P2O7_1T_corrected.dat',
#14/06 Experiment on Na3Cu2SbO6
'14/06_01T' : '../Mag/Na3Cu2SbO6/14_06/14_06_Na3Cu2SbO6_01T.dat',
'14/06_1T' : '../Mag/Na3Cu2SbO6/14_06/14_06_Na3Cu2SbO6_1T.dat',
#15/06 Experiment on Li3Cu2SbO6
'15/06_01T' : '../Mag/Li3Cu2SbO6/15_06/15_06_Li3Cu2SbO6_01T.dat',
'15/06_1T' : '../Mag/Li3Cu2SbO6/15_06/15_06_Li3Cu2SbO6_1T.dat',
#17/06 Experiment on Li3Cu2SbO6 to correct 1T values
'17/06_1T' : '../Mag/Li3Cu2SbO6/17_06/17_06_Li3Cu2SbO6_1T.dat',
#23/06 Experiment on (Ag3)Na3Cu2SbO6
'23/06_01T' : '../Mag/Na3Cu2SbO6/23_06/23_06_(Ag3)Na3Cu2SbO6_01T.dat',
'23/06_1T' : '../Mag/Na3Cu2SbO6/23_06/23_06_(Ag3)Na3Cu2SbO6_1T.dat',
}
mass = {
#06/05 Experiment on Li2MnO3
'06/05' : 28.60e-3,
#11/05 Experiment on Li3Ni2SbO6
'11/05' : 20.85e-3,
#20/05 Experiment on Li3Ni2SbO6 Protonated HT
'20/05' : 20.57e-3,
#25/05 Experiment on Li2MnO3 protonated 50C 4M 48h
'25/05' : 21.17e-3,
#07/06 Experiment on Na3Ni2SbO6
'07/06' : 20.88e-3,
#09/06 Experiment on Li3Co2SbO6
'09/06' : 23.21e-3,
#10/06 Experiment on Co2P2O7
'10/06' : 20.44e-3,
#14/06 Experiment on Na3Cu2SbO6
'14/06' : 23.50e-3,
#15/06 Experiment on Li3Cu2SbO6
'15/06' : 20.55e-3,
#23/06 Experiment on (Ag3)Na3Cu2SbO6
'23/06' : 23.91e-3,
}
Molar_Weight = {
'Li2MnO3' : 116.82,
'Li3Ni2SbO6' : 355.9662,
'Na3Ni2SbO6' : 404.11,
'Li3Co2SbO6' : 356.45,
'Co2P2O7' : 291.81,
'Na3Cu2SbO6' : 413.82,
'Li3Cu2SbO6' : 365.67,
'Ag3Cu2SbO6' : 668.45,
}
abnormal_value = {
'06/05' : [73,74],
'20/05' : [142,143],
'20/05_size' : [130,131],
'25/05' : [2,363],
'07/06' : [327,190,220,221,224,328],
'10/06' : [129,324],
'14/06_1T' : [55,139]
}
spin = {
'06/05' : 3/2,
'11/05' : 1,
'09/06' : 1/2,
'10/06' : 3/2,
'14/06' : 1/2,
'15/06' : 1/2
}
file_save = ['chi_vs_T_01T_1T.pdf','inv_chi_vs_T_01T_1T.pdf']
C , Theta_CW , theory , experiment, chi , inv_chi , Temperature,fig_1,ax_1,fig_2,ax_2 = main_susceptibility(
path = [path['23/06_01T'],path['23/06_1T']],
mass = mass['23/06'],
Molar_Weight = Molar_Weight['Ag3Cu2SbO6'],
spin = 1/2,
mag_field = [0.1,1],
file_save = file_save,
abnormal_value = False)
#Devide by 2 when there is 2 metallic atoms
experiment = experiment / 2