99from scipy .spatial import distance_matrix
1010from nitroxides .commons import dG_DH , AU_TO_M , LabelPositioner , AU_TO_EV
1111
12- LABELS = {'E_ox' : [], 'E_red' : []}
13- POINTS_POSITION = {'E_ox' : [], 'E_red' : []}
14- LABELS_KWARGS = {'E_ox' : [], 'E_red' : []}
15- LABELS_PATH = {'E_ox' : pathlib .Path ('pot_hammet_ox.pos' ), 'E_red' : pathlib .Path ('pot_hammet_red.pos' )}
16-
17- def plot_hammet (ax , data : pandas .DataFrame , column : str , family : str , color : str ):
18- subdata = data [(data ['solvent' ] == 'water' ) & (data ['family' ] == family ) & data ['hammet' ].notnull ()]
12+ LABELS = {'E_ox_hammet' : [], 'E_red_hammet' : [], 'E_ox_inductive' : [], 'E_red_inductive' : []}
13+ POINTS_POSITION = {'E_ox_hammet' : [], 'E_red_hammet' : [], 'E_ox_inductive' : [], 'E_red_inductive' : []}
14+ LABELS_KWARGS = {'E_ox_hammet' : [], 'E_red_hammet' : [], 'E_ox_inductive' : [], 'E_red_inductive' : []}
15+ LABELS_PATH = {
16+ 'E_ox_hammet' : pathlib .Path ('pot_hammet_ox.pos' ),
17+ 'E_red_hammet' : pathlib .Path ('pot_hammet_red.pos' ),
18+ 'E_ox_inductive' : pathlib .Path ('pot_hammet_ox_inductive.pos' ),
19+ 'E_red_inductive' : pathlib .Path ('pot_hammet_red_inductive.pos' )
20+ }
21+
22+ def plot_hammet (ax , data : pandas .DataFrame , column : str , family : str , color : str , const : str = 'hammet' ):
23+ subdata = data [(data ['solvent' ] == 'water' ) & (data ['family' ] == family ) & data [const ].notnull ()]
1924
2025 if column == 'E_ox' :
2126 dG_DH_ = dG_DH (subdata ['z' ] + 1 , subdata ['z' ], subdata ['r_ox' ] / AU_TO_M * 1e-10 , subdata ['r_rad' ] / AU_TO_M * 1e-10 , 80 , 0 ) * AU_TO_EV
2227 else :
2328 dG_DH_ = dG_DH (subdata ['z' ], subdata ['z' ] - 1 , subdata ['r_rad' ] / AU_TO_M * 1e-10 , subdata ['r_red' ] / AU_TO_M * 1e-10 , 80 , 0 ) * AU_TO_EV
2429
25- ax .plot (subdata ['hammet' ], subdata [column ] - dG_DH_ , 'o' , color = color , label = family .replace ('Family.' , '' ))
30+ ax .plot (subdata [const ], subdata [column ] - dG_DH_ , 'o' , color = color , label = family .replace ('Family.' , '' ))
2631
27- for name , hammet , e in zip (subdata ['name' ], subdata ['hammet' ], subdata [column ] - dG_DH_ ):
32+ for name , hammet , e in zip (subdata ['name' ], subdata [const ], subdata [column ] - dG_DH_ ):
2833 name = name .replace ('mol_' , '' )
29- LABELS [column ].append (name )
30- POINTS_POSITION [column ].append ((hammet , e ))
31- LABELS_KWARGS [column ].append (dict (color = color , ha = 'center' , va = 'center' ))
34+ n = '{}_{}' .format (column , const )
35+ LABELS [n ].append (name )
36+ POINTS_POSITION [n ].append ((hammet , e ))
37+ LABELS_KWARGS [n ].append (dict (color = color , ha = 'center' , va = 'center' ))
3238
33- def plot_corr_hammet (ax , data : pandas .DataFrame , column : str ):
34- subdata = data [(data ['solvent' ] == 'water' ) & data ['hammet' ].notnull ()]
39+ def plot_corr_hammet (ax , data : pandas .DataFrame , column : str , family : str , color : str , const : str = 'hammet' ):
40+ subdata = data [(data ['solvent' ] == 'water' ) & ( data ['family' ] == family ) & data [ const ].notnull ()]
3541
3642 if column == 'E_ox' :
3743 dG_DH_ = dG_DH (subdata ['z' ] + 1 , subdata ['z' ], subdata ['r_ox' ] / AU_TO_M * 1e-10 , subdata ['r_rad' ] / AU_TO_M * 1e-10 , 80 , 0 ) * AU_TO_EV
3844 else :
3945 dG_DH_ = dG_DH (subdata ['z' ], subdata ['z' ] - 1 , subdata ['r_rad' ] / AU_TO_M * 1e-10 , subdata ['r_red' ] / AU_TO_M * 1e-10 , 80 , 0 ) * AU_TO_EV
4046
41- result = scipy .stats .linregress (subdata ['hammet' ], subdata [column ] - dG_DH_ )
47+ result = scipy .stats .linregress (subdata [const ], subdata [column ] - dG_DH_ )
4248
4349 x = numpy .array ([- 1. , 1. ])
44- ax .plot (x , result .slope * x + result .intercept , 'k --' )
45- ax .text (- .7 , - result .slope + result .intercept , '$R^2$={:.3f }' .format (result .rvalue ** 2 ))
50+ ax .plot (x , result .slope * x + result .intercept , '--' , color = color )
51+ ax .text (- .9 , - result .slope + result .intercept + .1 , '$R^2$={:.2f }' .format (result .rvalue ** 2 ), color = color )
4652
4753parser = argparse .ArgumentParser ()
4854parser .add_argument ('-i' , '--input' , default = '../data/Data_pot.csv' )
@@ -53,46 +59,53 @@ def plot_corr_hammet(ax, data: pandas.DataFrame, column: str):
5359
5460data = pandas .read_csv (args .input )
5561
56- figure = plt .figure (figsize = (9 , 5 ))
57- ax1 , ax2 = figure .subplots (1 , 2 )
58-
59- plot_hammet (ax1 , data , 'E_ox' , 'Family.P6O' , 'tab:blue' )
60- plot_hammet (ax1 , data , 'E_ox' , 'Family.P5O' , 'black' )
61- plot_corr_hammet (ax1 , data , 'E_ox' )
62+ figure = plt .figure (figsize = (8 , 8 ))
63+ (ax1 , ax2 ), (ax3 , ax4 ) = figure .subplots (2 , 2 )
6264
63- positioner = LabelPositioner .from_file (
64- LABELS_PATH ['E_ox' ],
65- numpy .array (POINTS_POSITION ['E_ox' ]),
66- LABELS ['E_ox' ],
67- labels_kwargs = LABELS_KWARGS ['E_ox' ]
68- )
65+ for axes , const in [((ax1 , ax2 ), 'hammet' ), ((ax3 , ax4 ), 'inductive' ),]:
66+
67+ for family , color in [('Family.P6O' , 'tab:blue' ), ('Family.P5O' , 'black' )]:
68+ plot_hammet (axes [0 ], data , 'E_ox' , family , color , const = const )
69+ plot_corr_hammet (axes [0 ], data , 'E_ox' , family , color , const = const )
70+
71+ n = 'E_ox_{}' .format (const )
6972
70- if args .reposition_labels :
71- positioner .optimize (dx = 1e-4 , beta = 1e5 , krep = 1 , kspring = 1000 , c = 0.03 , b0 = 0.01 , scale = (.15 , 1 ))
72- positioner .save (LABELS_PATH ['E_ox' ])
73+ positioner = LabelPositioner .from_file (
74+ LABELS_PATH [n ],
75+ numpy .array (POINTS_POSITION [n ]),
76+ LABELS [n ],
77+ labels_kwargs = LABELS_KWARGS [n ]
78+ )
7379
74- positioner .add_labels (ax1 )
80+ if args .reposition_labels :
81+ positioner .optimize (dx = 1e-3 , beta = 1e4 , krep = 1 , kspring = 1000 , c = 0.03 , b0 = 0.02 , scale = (.2 , 1 ))
82+ positioner .save (LABELS_PATH [n ])
7583
76- plot_hammet (ax2 , data , 'E_red' , 'Family.P6O' , 'tab:blue' )
77- plot_hammet (ax2 , data , 'E_red' , 'Family.P5O' , 'black' )
78- plot_corr_hammet (ax2 , data , 'E_red' )
84+ positioner .add_labels (axes [0 ])
85+
86+ for family , color in [('Family.P6O' , 'tab:blue' ), ('Family.P5O' , 'black' )]:
87+ plot_hammet (axes [1 ], data , 'E_red' , family , color , const = const )
88+ plot_corr_hammet (axes [1 ], data , 'E_red' , family , color , const = const )
89+
90+ n = 'E_red_{}' .format (const )
7991
80- positioner = LabelPositioner .from_file (
81- LABELS_PATH ['E_red' ],
82- numpy .array (POINTS_POSITION ['E_red' ]),
83- LABELS ['E_red' ],
84- labels_kwargs = LABELS_KWARGS ['E_red' ]
85- )
92+ positioner = LabelPositioner .from_file (
93+ LABELS_PATH [n ],
94+ numpy .array (POINTS_POSITION [n ]),
95+ LABELS [n ],
96+ labels_kwargs = LABELS_KWARGS [n ]
97+ )
8698
87- if args .reposition_labels :
88- positioner .optimize (dx = 1e-3 , beta = 1e4 , krep = 1 , kspring = 1000 , c = 0.03 , b0 = 0.015 , scale = (.2 , 1 ))
89- positioner .save (LABELS_PATH ['E_red' ])
99+ if args .reposition_labels :
100+ positioner .optimize (dx = 1e-3 , beta = 1e4 , krep = 1 , kspring = 1000 , c = 0.04 , b0 = 0.03 , scale = (.3 , 1 ))
101+ positioner .save (LABELS_PATH [n ])
90102
91- positioner .add_labels (ax2 )
103+ positioner .add_labels (axes [ 1 ] )
92104
93- [ax .set_xlabel ('Hammet constant $\\ sigma$' ) for ax in [ax1 , ax2 ]]
94- ax1 .set_ylabel ('$E^0_{abs}(N^+|N^\\ bullet)$ (V)' )
95- ax2 .set_ylabel ('$E^0_{abs}(N^\\ bullet|N^-)$ (V)' )
105+ [ax .set_xlabel ('Hammet constant $\\ sigma_m$ or $\\ sigma_p$' ) for ax in [ax1 , ax2 ]]
106+ [ax .set_xlabel ('Inductive constante $\\ sigma_I$' ) for ax in [ax3 , ax4 ]]
107+ [ax .set_ylabel ('$E^0_{abs}(N^+|N^\\ bullet)$ (V)' ) for ax in [ax1 , ax3 ]]
108+ [ax .set_ylabel ('$E^0_{abs}(N^\\ bullet|N^-)$ (V)' ) for ax in [ax2 , ax4 ]]
96109
97110plt .tight_layout ()
98111figure .savefig (args .output )
0 commit comments