-
Notifications
You must be signed in to change notification settings - Fork 0
/
solvation_cv.py
647 lines (621 loc) · 38.9 KB
/
solvation_cv.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
import numpy as np
from solvation_fit import SolvationFit
class SolvationCV(SolvationFit):
"""Class to calculate and store solvation and anion-cation energies.
Attributes
----------
cation_IA : dict
Dictionary that contains the ionization energies and electron affinities of the cations.
anion_IA : dict
Dictionary that contains the ionization energies and electron affinities of the anions.
solvent_IA : dict
Dictionary that contains the ionization energies and electron affinities of the solvents.
data_file : str
File containing the experimental data.
calc_type : list
Indicates which components are going to be constant and which are going to be varied
in the calculation.
calc_type[0] : 'solvent' or 'ion' (constant part of the calculation).
calc_type[1] : if calc_type[0] == 'solvent' this is a list solvents.
calc_type[1] : if calc_type[0] == 'ion' this is a list of 2-tuples,
fist cation and second anion.
min_bound : float
Lower bound on the gamma and zeta parameters. Default is no bound.
max_bound : float
Upper bound on the gamma and zeta parameters. Default is no bound.
cations : {None, list}
Cations that will be considered in the calculation.
Default is the same cations included in cations_IA.
anions : {None, list}
Anions that will be considered in the calculation.
Default is the same anions included in anions_IA.
solvents : {None, list}
Solvents that will be considered in the calculation.
Default is the same solvents included in solvent_IA.
solvation_data : dict
Dictionary that contains all the experimental data.
i_cat_solv : np.ndarray
Numpy array that contains the training I values for the cations that will be used
in the solvation energy calculations.
a_cat_solv : np.ndarray
Numpy array that contains the training A values for the cations that will be used
in the solvation energy calculations.
i_an_solv : np.ndarray
Numpy array that contains the training I values for the anions that will be used
in the solvation energy calculations.
a_an_solv : np.ndarray
Numpy array that contains the training A values for the anions that will be used
in the solvation energy calculations.
i_sol_solv : np.ndarray
Numpy array that contains the training I values for the solvents that will be used
in the solvation energy calculations.
a_sol_solv : np.ndarray
Numpy array that contains the training A values for the solvents that will be used
in the solvation energy calculations.
i_cat_diff : np.ndarray
Numpy array that contains the training I values for the cations that will be used
in the anion-cation energy calculations.
a_cat_diff : np.ndarray
Numpy array that contains the training A values for the cations that will be used
in the anion-cation energy calculations.
i_an_diff : np.ndarray
Numpy array that contains the training I values for the anions that will be used
in the anion-cation energy calculations.
a_an_diff : np.ndarray
Numpy array that contains the training A values for the anions that will be used
in the anion-cation energy calculations.
i_sol_diff : np.ndarray
Numpy array that contains the training I values for the solvents that will be used
in the anion-cation energy calculations.
a_sol_diff : np.ndarray
Numpy array that contains the training A values for the solvents that will be used
in the anion-cation energy calculations.
popt_sol_e_allparams_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the solvation energy calculation.
All parameters are varied.
popt_sol_e_allparams_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the solvation energy calculation.
All parameters are varied.
popt_sol_e_gamma_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the solvation energy calculation.
Only the gamma and linear parameters are varied.
popt_sol_e_gamma_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the solvation energy calculation.
Only the gamma and linear parameters are varied.
popt_sol_e_zeta_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the solvation energy calculation.
Only the zeta and linear parameters are varied.
popt_sol_e_zeta_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the solvation energy calculation.
Only the zeta and linear parameters are varied.
popt_sol_e_simple_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the solvation energy calculation.
Only the linear parameters are varied.
popt_an_cat_diff_allparams_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the anion-cation energy calculation.
All parameters are varied.
popt_an_cat_diff_allparams_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the anion-cation energy calculation.
All parameters are varied.
popt_an_cat_diff_gamma_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the anion-cation energy calculation.
Only the gamma and linear parameters are varied.
popt_an_cat_diff_gamma_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the anion-cation energy calculation.
Only the gamma and linear parameters are varied.
popt_an_cat_diff_zeta_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the anion-cation energy calculation.
Only the zeta and linear parameters are varied.
popt_an_cat_diff_zeta_bound : np.ndarray (if it can be calculated)
Numpy array with the (bound) parameters of the anion-cation energy calculation.
Only the zeta and linear parameters are varied.
popt_an_cat_diff_simple_unbound : np.ndarray (if it can be calculated)
Numpy array with the (unbound) parameters of the anion-cation energy calculation.
Only the linear parameters are varied.
sol_e_allparams_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Unbound parameters. All parameters varied.
sol_e_allparams_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Bound parameters. All parameters varied.
sol_e_gamma_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
sol_e_gamma_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Bound parameters. Gamma and linear parameters varied.
sol_e_zeta_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
sol_e_zeta_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Bound parameters. Zeta and linear parameters varied.
sol_e_simple_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the solvation energy calculations.
Unbound parameters. Linear parameters varied.
an_cat_diff_allparams_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Unbound parameters. All parameters varied.
an_cat_diff_allparams_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Bound parameters. All parameters varied.
an_cat_diff_gamma_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
an_cat_diff_gamma_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Bound parameters. Gamma and linear parameters varied.
an_cat_diff_zeta_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
an_cat_diff_zeta_bound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Bound parameters. Zeta and linear parameters varied.
an_cat_diff_simple_unbound_result : np.ndarray (if it can be calculated)
Numpy array with the results of the anion-cation energy calculations.
Unbound parameters. Linear parameters varied.
sol_e_allparams_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Unbound parameters. All parameters varied.
sol_e_allparams_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Bound parameters. All parameters varied.
sol_e_gamma_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
sol_e_gamma_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Bound parameters. Gamma and linear parameters varied.
sol_e_zeta_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
sol_e_zeta_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Bound parameters. Zeta and linear parameters varied.
sol_e_simple_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the solvation energy calculations.
Unbound parameters. Linear parameters varied.
an_cat_diff_allparams_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Unbound parameters. All parameters varied.
an_cat_diff_allparams_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Bound parameters. All parameters varied.
an_cat_diff_gamma_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
an_cat_diff_gamma_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Bound parameters. Gamma and linear parameters varied.
an_cat_diff_zeta_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
an_cat_diff_zeta_bound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Bound parameters. Zeta and linear parameters varied.
an_cat_diff_simple_unbound_error : np.ndarray (if it can be calculated)
Numpy array with the errors of the anion-cation energy calculations.
Unbound parameters. Linear parameters varied.
exp_data_solv : np.ndarray
Experimantal solvation energies (training set).
exp_data_solv : np.ndarray
Experimental anion-cation energies (training set).
i_cat_solv_total : np.ndarray
Numpy array that contains the available I values for the cations that will be used
in the solvation energy calculations.
a_cat_solv_total : np.ndarray
Numpy array that contains the available A values for the cations that will be used
in the solvation energy calculations.
i_an_solv_total : np.ndarray
Numpy array that contains the available I values for the anions that will be used
in the solvation energy calculations.
a_an_solv_total : np.ndarray
Numpy array that contains the available A values for the anions that will be used
in the solvation energy calculations.
i_sol_solv_total : np.ndarray
Numpy array that contains the available I values for the solvents that will be used
in the solvation energy calculations.
a_sol_solv_total : np.ndarray
Numpy array that contains the available A values for the solvents that will be used
in the solvation energy calculations.
i_cat_diff_total : np.ndarray
Numpy array that contains the available I values for the cations that will be used
in the anion-cation energy calculations.
a_cat_diff_total : np.ndarray
Numpy array that contains the available A values for the cations that will be used
in the anion-cation energy calculations.
i_an_diff_total : np.ndarray
Numpy array that contains the available I values for the anions that will be used
in the anion-cation energy calculations.
a_an_diff_total : np.ndarray
Numpy array that contains the available A values for the anions that will be used
in the anion-cation energy calculations.
i_sol_diff_total : np.ndarray
Numpy array that contains the available I values for the solvents that will be used
in the anion-cation energy calculations.
a_sol_diff_total : np.ndarray
Numpy array that contains the available A values for the solvents that will be used
in the anion-cation energy calculations.
exp_data_solv_total : np.ndarray
Experimental solvation energies.
exp_data_solv_total : np.ndarray
Experimental anion-cation energies.
i_cat_solv_test : np.ndarray
Numpy array that contains the test I values for the cations that will be used
in the solvation energy calculations.
a_cat_solv_test : np.ndarray
Numpy array that contains the test A values for the cations that will be used
in the solvation energy calculations.
i_an_solv_test : np.ndarray
Numpy array that contains the test I values for the anions that will be used
in the solvation energy calculations.
a_an_solv_test : np.ndarray
Numpy array that contains the test A values for the anions that will be used
in the solvation energy calculations.
i_sol_solv_test : np.ndarray
Numpy array that contains the test I values for the solvents that will be used
in the solvation energy calculations.
a_sol_solv_test : np.ndarray
Numpy array that contains the test A values for the solvents that will be used
in the solvation energy calculations.
i_cat_diff_test : np.ndarray
Numpy array that contains the test I values for the cations that will be used
in the anion-cation energy calculations.
a_cat_diff_test : np.ndarray
Numpy array that contains the test A values for the cations that will be used
in the anion-cation energy calculations.
i_an_diff_test : np.ndarray
Numpy array that contains the test I values for the anions that will be used
in the anion-cation energy calculations.
a_an_diff_test : np.ndarray
Numpy array that contains the test A values for the anions that will be used
in the anion-cation energy calculations.
i_sol_diff_test : np.ndarray
Numpy array that contains the test I values for the solvents that will be used
in the anion-cation energy calculations.
a_sol_diff_test : np.ndarray
Numpy array that contains the test A values for the solvents that will be used
in the anion-cation energy calculations.
exp_data_solv_test : np.ndarray
Experimental solvation energies (test set).
exp_data_solv_test : np.ndarray
Experimental anion-cation energies (test set).
sol_e_allparams_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Bound parameters. All parameters varied.
sol_e_gamma_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
sol_e_gamma_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Bound parameters. Gamma and linear parameters varied.
sol_e_zeta_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
sol_e_zeta_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Bound parameters. Zeta and linear parameters varied.
sol_e_simple_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the solvation energy calculations.
Unbound parameters. Linear parameters varied.
an_cat_diff_allparams_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Unbound parameters. All parameters varied.
an_cat_diff_allparams_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Bound parameters. All parameters varied.
an_cat_diff_gamma_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Unbound parameters. Gamma and linear parameters varied.
an_cat_diff_gamma_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Bound parameters. Gamma and linear parameters varied.
an_cat_diff_zeta_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Unbound parameters. Zeta and linear parameters varied.
an_cat_diff_zeta_bound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Bound parameters. Zeta and linear parameters varied.
an_cat_diff_simple_unbound_cv : np.ndarray (if it can be calculated)
Numpy array with the cv errors of the anion-cation energy calculations.
Unbound parameters. Linear parameters varied.
Methods
-------
__init__(self, cation_IA, anion_IA, solvent_IA, data_file, calc_type,
min_bound=-np.inf, max_bound=np.inf, cations=None, anions=None, solvents=None)
Initialize the object.
gen_data_container()
Generate the dictionary that will contain all the experimental data.
read_data(self)
Read all the experimental data from self.data_file.
select_data(self)
Select the I and A values that will be used for the current calculation.
fit_data(self)
Fit the data to the experimental solvation energies and anion-cation energies.
get_results_errors(self)
Calculate the CDFT solvation energies and anion-cation energies and errors.
Errors calculated as: CDFT_value - Experimental_value.
Static Methods
--------------
Eab(i_a, a_a, i_b, a_b, gamma=1.0, zeta=1.0)
Calculate the charge transfer energy between two compounds.
sol_e_allparams(data, gamma_cat, gamma_an, zeta_cat, zeta_an, m, b)
Input of the solvation energy fit, all parameters varied.
sol_e_gamma(data, gamma_cat, gamma_an, m, b)
Input of the solvation energy fit, gamma and linear parameters varied.
sol_e_zeta(data, zeta_cat, zeta_an, m, b)
Input of the solvation energy fit, zeta and linear parameters varied.
sol_e_simple(data, m, b)
Input of the solvation energy fit, linear parameters varied.
an_cat_dif_allparams(data, gamma_cat, gamma_an, zeta_cat, zeta_an, m, b)
Input of the anion-cation energy fit, all parameters varied.
an_cat_dif_gamma(data, gamma_cat, gamma_an, m, b)
Input of the anion-cation energy fit, gamma and linear parameters varied.
an_cat_dif_zeta(data, zeta_cat, zeta_an, m, b)
Input of the anion-cation energy fit, zeta and linear parameters varied.
an_cat_dif_simple(data, m, b)
Input of the anion-cation energy fit, linear parameters varied.
sol_e_allparams_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol,
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b)
Calculate the solvation energy, all parameters varied.
sol_e_gamma_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, gamma_cat, gamma_an, m, b)
Calculate the solvation energy, gamma and linear parameters varied.
sol_e_zeta_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, zeta_cat, zeta_an, m, b)
Calculate the solvation energy, zeta and linear parameters varied.
sol_e_simple_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, m, b)
Calculate the solvation energy, linear parameters varied.
an_cat_dif_allparams_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol,
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b)
Calculate the anion-cation energy, all parameters varied.
an_cat_dif_gamma_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, gamma_cat, gamma_an, m, b)
Calculate the anion-cation energy, gamma and linear parameters varied.
an_cat_dif_zeta_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, zeta_cat, zeta_an, m, b)
Calculate the anion-cation energy, zeta and linear parameters varied.
an_cat_dif_simple_expl(i_cat, a_cat, i_an, a_an, i_sol, a_sol, m, b)
Calculate the anion-cation energy, linear parameters varied.
"""
def __init__(self, solv_object, solv_test_indices, diff_test_indices):
"""Initialize the object.
Parameters
----------
solv_object : SolvationFit
SolvationFit instance.
solv_test_indices : list
List with indices that will be used as test set in the CV for the solvation energy.
diff_test_indices : list
List with indices that will be used as test set in the CV for the
anion_cat calculations.
"""
self.calc_type = solv_object.calc_type
self.min_bound = solv_object.min_bound
self.max_bound = solv_object.max_bound
# Copy selected data
self.a_cat_solv_total = solv_object.a_cat_solv
self.i_an_solv_total = solv_object.i_an_solv
self.i_cat_solv_total = solv_object.i_cat_solv
self.a_an_solv_total = solv_object.a_an_solv
self.i_sol_solv_total = solv_object.i_sol_solv
self.a_sol_solv_total = solv_object.a_sol_solv
self.exp_data_solv_total = solv_object.exp_data_solv
self.i_cat_diff_total = solv_object.i_cat_diff
self.a_cat_diff_total = solv_object.a_cat_diff
self.i_an_diff_total = solv_object.i_an_diff
self.a_an_diff_total = solv_object.a_an_diff
self.i_sol_diff_total = solv_object.i_sol_diff
self.a_sol_diff_total = solv_object.a_sol_diff
self.exp_data_diff_total = solv_object.exp_data_diff
self.solv_test_indices = solv_test_indices
self.diff_test_indices = diff_test_indices
self.separate_data_solv()
self.separate_data_diff()
self.fit_data()
self.get_cv_results()
def separate_data_solv(self):
"""Separate the solvation data into training and test sets."""
training_indices = [i for i in range(len(self.i_cat_solv_total))
if i not in self.solv_test_indices]
self.i_cat_solv = self.i_cat_solv_total[training_indices]
self.a_cat_solv = self.a_cat_solv_total[training_indices]
self.i_an_solv = self.i_an_solv_total[training_indices]
self.a_an_solv = self.a_an_solv_total[training_indices]
self.i_sol_solv = self.i_sol_solv_total[training_indices]
self.a_sol_solv = self.a_sol_solv_total[training_indices]
self.exp_data_solv = self.exp_data_solv_total[training_indices]
self.i_cat_solv_test = self.i_cat_solv_total[self.solv_test_indices]
self.a_cat_solv_test = self.a_cat_solv_total[self.solv_test_indices]
self.i_an_solv_test = self.i_an_solv_total[self.solv_test_indices]
self.a_an_solv_test = self.a_an_solv_total[self.solv_test_indices]
self.i_sol_solv_test = self.i_sol_solv_total[self.solv_test_indices]
self.a_sol_solv_test = self.a_sol_solv_total[self.solv_test_indices]
self.exp_data_solv_test = self.exp_data_solv_total[self.solv_test_indices]
def separate_data_diff(self):
"""Separate the anion_cation data into training and test sets."""
training_indices = [i for i in range(len(self.i_cat_diff_total))
if i not in self.diff_test_indices]
self.i_cat_diff = self.i_cat_diff_total[training_indices]
self.a_cat_diff = self.a_cat_diff_total[training_indices]
self.i_an_diff = self.i_an_diff_total[training_indices]
self.a_an_diff = self.a_an_diff_total[training_indices]
self.i_sol_diff = self.i_sol_diff_total[training_indices]
self.a_sol_diff = self.a_sol_diff_total[training_indices]
self.exp_data_diff = self.exp_data_diff_total[training_indices]
self.i_cat_diff_test = self.i_cat_diff_total[self.diff_test_indices]
self.a_cat_diff_test = self.a_cat_diff_total[self.diff_test_indices]
self.i_an_diff_test = self.i_an_diff_total[self.diff_test_indices]
self.a_an_diff_test = self.a_an_diff_total[self.diff_test_indices]
self.i_sol_diff_test = self.i_sol_diff_total[self.diff_test_indices]
self.a_sol_diff_test = self.a_sol_diff_total[self.diff_test_indices]
self.exp_data_diff_test = self.exp_data_diff_total[self.diff_test_indices]
def get_cv_results(self):
"""Calculate the CDFT solvation energies and anion-cation energies and errors.
Notes
-----
Errors calculated as: CDFT_value - Experimental_value.
"""
if hasattr(self, 'popt_sol_e_allparams_unbound'):
sol_e_allparams_unbound_error = []
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b = self.popt_sol_e_allparams_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_allaparams_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, zeta_cat, zeta_an, m, b)
sol_e_allparams_unbound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_allparams_unbound_error = np.array(sol_e_allparams_unbound_error)
self.sol_e_allparams_unbound_cv = np.sqrt(np.mean(self.sol_e_allparams_unbound_error**2))
if hasattr(self, 'popt_sol_e_allparams_bound'):
sol_e_allparams_bound_error = []
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b = self.popt_sol_e_allparams_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_allaparams_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, zeta_cat, zeta_an, m, b)
sol_e_allparams_bound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_allparams_bound_error = np.array(sol_e_allparams_bound_error)
self.sol_e_allparams_bound_cv = np.sqrt(np.mean(self.sol_e_allparams_bound_error**2))
if hasattr(self, 'popt_sol_e_gamma_unbound'):
sol_e_gamma_unbound_error = []
gamma_cat, gamma_an, m, b = self.popt_sol_e_gamma_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_gamma_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, m, b)
sol_e_gamma_unbound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_gamma_unbound_error = np.array(sol_e_gamma_unbound_error)
self.sol_e_gamma_unbound_cv = np.sqrt(np.mean(self.sol_e_gamma_unbound_error**2))
if hasattr(self, 'popt_sol_e_gamma_bound'):
sol_e_gamma_bound_error = []
gamma_cat, gamma_an, m, b = self.popt_sol_e_gamma_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_gamma_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, m, b)
sol_e_gamma_bound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_gamma_bound_error = np.array(sol_e_gamma_bound_error)
self.sol_e_gamma_bound_cv = np.sqrt(np.mean(self.sol_e_gamma_bound_error**2))
if hasattr(self, 'popt_sol_e_zeta_unbound'):
sol_e_zeta_unbound_error = []
zeta_cat, zeta_an, m, b = self.popt_sol_e_zeta_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_zeta_expl(i_c, a_c, i_a, a_a, i_s, a_s, zeta_cat,
zeta_an, m, b)
sol_e_zeta_unbound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_zeta_unbound_error = np.array(sol_e_zeta_unbound_error)
self.sol_e_zeta_unbound_cv = np.sqrt(np.mean(self.sol_e_zeta_unbound_error**2))
if hasattr(self, 'popt_sol_e_zeta_bound'):
sol_e_zeta_bound_error = []
zeta_cat, zeta_an, m, b = self.popt_sol_e_zeta_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_zeta_expl(i_c, a_c, i_a, a_a, i_s, a_s, zeta_cat,
zeta_an, m, b)
sol_e_zeta_bound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_zeta_bound_error = np.array(sol_e_zeta_bound_error)
self.sol_e_zeta_bound_cv = np.sqrt(np.mean(self.sol_e_zeta_bound_error**2))
if hasattr(self, 'popt_sol_e_simple_unbound'):
sol_e_simple_unbound_error = []
m, b = self.popt_sol_e_simple_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_solv_test, self.a_cat_solv_test,
self.i_an_solv_test, self.a_an_solv_test,
self.i_sol_solv_test, self.a_sol_solv_test)):
dE = SolvationFit.sol_e_simple_expl(i_c, a_c, i_a, a_a, i_s, a_s, m, b)
sol_e_simple_unbound_error.append(self.exp_data_solv_test[index] - dE)
self.sol_e_simple_unbound_error = np.array(sol_e_simple_unbound_error)
self.sol_e_simple_unbound_cv = np.sqrt(np.mean(self.sol_e_simple_unbound_error**2))
if hasattr(self, 'popt_an_cat_diff_allparams_unbound'):
an_cat_diff_allparams_unbound_error = []
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b = self.popt_an_cat_diff_allparams_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_allparams_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, zeta_cat, zeta_an, m, b)
an_cat_diff_allparams_unbound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_allparams_unbound_error = np.array(
an_cat_diff_allparams_unbound_error)
self.an_cat_diff_allparams_unbound_cv = np.sqrt(np.mean(self.an_cat_diff_allparams_unbound_error**2))
if hasattr(self, 'popt_an_cat_diff_allparams_bound'):
an_cat_diff_allparams_bound_error = []
gamma_cat, gamma_an, zeta_cat, zeta_an, m, b = self.popt_an_cat_diff_allparams_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_allparams_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, zeta_cat, zeta_an, m, b)
an_cat_diff_allparams_bound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_allparams_bound_error = np.array(an_cat_diff_allparams_bound_error)
self.an_cat_diff_allparams_bound_cv = np.sqrt(np.mean(self.an_cat_diff_allparams_bound_error**2))
if hasattr(self, 'popt_an_cat_diff_gamma_unbound'):
an_cat_diff_gamma_unbound_error = []
gamma_cat, gamma_an, m, b = self.popt_an_cat_diff_gamma_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_gamma_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, m, b)
an_cat_diff_gamma_unbound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_gamma_unbound_error = np.array(an_cat_diff_gamma_unbound_error)
self.an_cat_diff_gamma_unbound_cv = np.sqrt(np.mean(self.an_cat_diff_gamma_unbound_error**2))
if hasattr(self, 'popt_an_cat_diff_gamma_bound'):
an_cat_diff_gamma_bound_error = []
gamma_cat, gamma_an, m, b = self.popt_an_cat_diff_gamma_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_gamma_expl(i_c, a_c, i_a, a_a, i_s, a_s, gamma_cat,
gamma_an, m, b)
an_cat_diff_gamma_bound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_gamma_bound_error = np.array(an_cat_diff_gamma_bound_error)
self.an_cat_diff_gamma_bound_cv = np.sqrt(np.mean(self.an_cat_diff_gamma_bound_error**2))
if hasattr(self, 'popt_an_cat_diff_zeta_unbound'):
an_cat_diff_zeta_unbound_error = []
zeta_cat, zeta_an, m, b = self.popt_an_cat_diff_zeta_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_zeta_expl(i_c, a_c, i_a, a_a, i_s, a_s, zeta_cat,
zeta_an, m, b)
an_cat_diff_zeta_unbound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_zeta_unbound_error = np.array(an_cat_diff_zeta_unbound_error)
self.an_cat_diff_zeta_unbound_cv = np.sqrt(np.mean(self.an_cat_diff_zeta_unbound_error**2))
if hasattr(self, 'popt_an_cat_diff_zeta_bound'):
an_cat_diff_zeta_bound_error = []
zeta_cat, zeta_an, m, b = self.popt_an_cat_diff_zeta_bound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_zeta_expl(i_c, a_c, i_a, a_a, i_s, a_s, zeta_cat,
zeta_an, m, b)
an_cat_diff_zeta_bound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_zeta_bound_error = np.array(an_cat_diff_zeta_bound_error)
self.an_cat_diff_zeta_bound_cv = np.sqrt(np.mean(self.an_cat_diff_zeta_bound_error**2))
if hasattr(self, 'popt_an_cat_diff_simple_unbound'):
an_cat_diff_simple_unbound_error = []
m, b = self.popt_an_cat_diff_simple_unbound
for index, (i_c, a_c, i_a, a_a, i_s, a_s) in enumerate(
zip(self.i_cat_diff_test, self.a_cat_diff_test,
self.i_an_diff_test, self.a_an_diff_test,
self.i_sol_diff_test, self.a_sol_diff_test)):
dE = SolvationFit.an_cat_dif_simple_expl(i_c, a_c, i_a, a_a, i_s, a_s, m, b)
an_cat_diff_simple_unbound_error.append(self.exp_data_diff_test[index] - dE)
self.an_cat_diff_simple_unbound_error = np.array(an_cat_diff_simple_unbound_error)
self.an_cat_diff_simple_unbound_cv = np.sqrt(np.mean(self.an_cat_diff_simple_unbound_error**2))