Skip to content

Commit

Permalink
last comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Jul 17, 2024
1 parent f8c62df commit 6049ea9
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 191 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ For v3.0 (to be submitted):

- [x] Fig. or Figure? → Fig. ;-)
- [x] PACS code, MSC code? → not relevant, also PACS is discontinued
- [ ] tries to move labels as much as possible in graphs
- [x] tries to move labels as much as possible in graphs
- [x] pack the geometries
- [x] Description of the SI? → Nope
- [x] Mat → Matsui
- [x] Data availability
- [x] Update SI (!!)
- [ ] Address last comments
- [x] Address last comments
2 changes: 1 addition & 1 deletion analyses/plot_pot_er.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def plot_corr_Er(ax, data: pandas.DataFrame, column: str):

x = numpy.array([(f * subdata['Er']).min(), (f * subdata['Er']).max()])
ax.plot(x, result.slope*x + result.intercept, 'k--')
ax.text(0, result.intercept + .1, '$R^2$={:.2f}'.format(result.rvalue **2))
ax.text(3 * f, result.intercept - .05, '$R^2$={:.2f}'.format(result.rvalue **2), size=12)

def make_table(f, data: pandas.DataFrame, solvent: str):
subdata = data[(data['solvent'] == solvent) & data['px'].notnull()]
Expand Down
111 changes: 62 additions & 49 deletions analyses/plot_pot_hammet.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,46 @@
from scipy.spatial import distance_matrix
from nitroxides.commons import dG_DH, AU_TO_M, LabelPositioner, AU_TO_EV

LABELS = {'E_ox': [], 'E_red': []}
POINTS_POSITION ={'E_ox': [], 'E_red': []}
LABELS_KWARGS = {'E_ox': [], 'E_red': []}
LABELS_PATH = {'E_ox': pathlib.Path('pot_hammet_ox.pos'), 'E_red': pathlib.Path('pot_hammet_red.pos')}

def plot_hammet(ax, data: pandas.DataFrame, column: str, family: str, color: str):
subdata = data[(data['solvent'] == 'water') & (data['family'] == family) & data['hammet'].notnull()]
LABELS = {'E_ox_hammet': [], 'E_red_hammet': [], 'E_ox_inductive': [], 'E_red_inductive': []}
POINTS_POSITION = {'E_ox_hammet': [], 'E_red_hammet': [], 'E_ox_inductive': [], 'E_red_inductive': []}
LABELS_KWARGS = {'E_ox_hammet': [], 'E_red_hammet': [], 'E_ox_inductive': [], 'E_red_inductive': []}
LABELS_PATH = {
'E_ox_hammet': pathlib.Path('pot_hammet_ox.pos'),
'E_red_hammet': pathlib.Path('pot_hammet_red.pos'),
'E_ox_inductive': pathlib.Path('pot_hammet_ox_inductive.pos'),
'E_red_inductive': pathlib.Path('pot_hammet_red_inductive.pos')
}

def plot_hammet(ax, data: pandas.DataFrame, column: str, family: str, color: str, const: str = 'hammet'):
subdata = data[(data['solvent'] == 'water') & (data['family'] == family) & data[const].notnull()]

if column == 'E_ox':
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
else:
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

ax.plot(subdata['hammet'], subdata[column] - dG_DH_, 'o', color=color, label=family.replace('Family.', ''))
ax.plot(subdata[const], subdata[column] - dG_DH_, 'o', color=color, label=family.replace('Family.', ''))

for name, hammet, e in zip(subdata['name'], subdata['hammet'], subdata[column] - dG_DH_):
for name, hammet, e in zip(subdata['name'], subdata[const], subdata[column] - dG_DH_):
name = name.replace('mol_', '')
LABELS[column].append(name)
POINTS_POSITION[column].append((hammet, e))
LABELS_KWARGS[column].append(dict(color=color, ha='center', va='center'))
n = '{}_{}'.format(column, const)
LABELS[n].append(name)
POINTS_POSITION[n].append((hammet, e))
LABELS_KWARGS[n].append(dict(color=color, ha='center', va='center'))

def plot_corr_hammet(ax, data: pandas.DataFrame, column: str):
subdata = data[(data['solvent'] == 'water') & data['hammet'].notnull()]
def plot_corr_hammet(ax, data: pandas.DataFrame, column: str, family: str, color: str, const: str = 'hammet'):
subdata = data[(data['solvent'] == 'water') & (data['family'] == family) & data[const].notnull()]

if column == 'E_ox':
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
else:
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

result = scipy.stats.linregress(subdata['hammet'], subdata[column] - dG_DH_)
result = scipy.stats.linregress(subdata[const], subdata[column] - dG_DH_)

x = numpy.array([-1., 1.])
ax.plot(x, result.slope*x + result.intercept, 'k--')
ax.text(-.7, -result.slope + result.intercept, '$R^2$={:.3f}'.format(result.rvalue **2))
ax.plot(x, result.slope*x + result.intercept, '--', color=color)
ax.text(-.9, -result.slope + result.intercept + .1, '$R^2$={:.2f}'.format(result.rvalue **2), color=color)

parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', default='../data/Data_pot.csv')
Expand All @@ -53,46 +59,53 @@ def plot_corr_hammet(ax, data: pandas.DataFrame, column: str):

data = pandas.read_csv(args.input)

figure = plt.figure(figsize=(9, 5))
ax1, ax2 = figure.subplots(1, 2)

plot_hammet(ax1, data, 'E_ox', 'Family.P6O', 'tab:blue')
plot_hammet(ax1, data, 'E_ox', 'Family.P5O', 'black')
plot_corr_hammet(ax1, data, 'E_ox')
figure = plt.figure(figsize=(8, 8))
(ax1, ax2), (ax3, ax4) = figure.subplots(2, 2)

positioner = LabelPositioner.from_file(
LABELS_PATH['E_ox'],
numpy.array(POINTS_POSITION['E_ox']),
LABELS['E_ox'],
labels_kwargs=LABELS_KWARGS['E_ox']
)
for axes, const in [((ax1, ax2), 'hammet'), ((ax3, ax4), 'inductive'),]:

for family, color in [('Family.P6O', 'tab:blue'), ('Family.P5O', 'black')]:
plot_hammet(axes[0], data, 'E_ox', family, color, const=const)
plot_corr_hammet(axes[0], data, 'E_ox', family, color, const=const)

n = 'E_ox_{}'.format(const)

if args.reposition_labels:
positioner.optimize(dx=1e-4, beta=1e5, krep=1, kspring=1000, c=0.03, b0=0.01, scale=(.15, 1))
positioner.save(LABELS_PATH['E_ox'])
positioner = LabelPositioner.from_file(
LABELS_PATH[n],
numpy.array(POINTS_POSITION[n]),
LABELS[n],
labels_kwargs=LABELS_KWARGS[n]
)

positioner.add_labels(ax1)
if args.reposition_labels:
positioner.optimize(dx=1e-3, beta=1e4, krep=1, kspring=1000, c=0.03, b0=0.02, scale=(.2, 1))
positioner.save(LABELS_PATH[n])

plot_hammet(ax2, data, 'E_red', 'Family.P6O', 'tab:blue')
plot_hammet(ax2, data, 'E_red', 'Family.P5O', 'black')
plot_corr_hammet(ax2, data, 'E_red')
positioner.add_labels(axes[0])

for family, color in [('Family.P6O', 'tab:blue'), ('Family.P5O', 'black')]:
plot_hammet(axes[1], data, 'E_red', family, color, const=const)
plot_corr_hammet(axes[1], data, 'E_red', family, color, const=const)

n = 'E_red_{}'.format(const)

positioner = LabelPositioner.from_file(
LABELS_PATH['E_red'],
numpy.array(POINTS_POSITION['E_red']),
LABELS['E_red'],
labels_kwargs=LABELS_KWARGS['E_red']
)
positioner = LabelPositioner.from_file(
LABELS_PATH[n],
numpy.array(POINTS_POSITION[n]),
LABELS[n],
labels_kwargs=LABELS_KWARGS[n]
)

if args.reposition_labels:
positioner.optimize(dx=1e-3, beta=1e4, krep=1, kspring=1000, c=0.03, b0=0.015, scale=(.2, 1))
positioner.save(LABELS_PATH['E_red'])
if args.reposition_labels:
positioner.optimize(dx=1e-3, beta=1e4, krep=1, kspring=1000, c=0.04, b0=0.03, scale=(.3, 1))
positioner.save(LABELS_PATH[n])

positioner.add_labels(ax2)
positioner.add_labels(axes[1])

[ax.set_xlabel('Hammet constant $\\sigma$') for ax in [ax1, ax2]]
ax1.set_ylabel('$E^0_{abs}(N^+|N^\\bullet)$ (V)')
ax2.set_ylabel('$E^0_{abs}(N^\\bullet|N^-)$ (V)')
[ax.set_xlabel('Hammet constant $\\sigma_m$ or $\\sigma_p$') for ax in [ax1, ax2]]
[ax.set_xlabel('Inductive constante $\\sigma_I$') for ax in [ax3, ax4]]
[ax.set_ylabel('$E^0_{abs}(N^+|N^\\bullet)$ (V)') for ax in [ax1, ax3]]
[ax.set_ylabel('$E^0_{abs}(N^\\bullet|N^-)$ (V)') for ax in [ax2, ax4]]

plt.tight_layout()
figure.savefig(args.output)
38 changes: 19 additions & 19 deletions analyses/pot_hammet_ox.pos
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
,label,x,y
0,3,0.4576194551447756,5.176347775489531
1,4,-0.6606786893389066,5.139446733924163
2,5,-0.25112430538905217,5.18815546245546
3,6,-0.3782332015637821,5.19469803681695
4,7,0.46619835666638804,5.099563815532129
5,8,0.44919503190560184,5.203110932341964
6,11,0.6170431239177386,5.296202705937092
7,12,0.48980260023399724,5.289174666471553
8,61,0.2303611942347875,5.205943433790021
9,15,0.3680648088282664,5.265534837088523
10,16,-0.15985673167674225,5.139990050271139
11,17,0.12053743319824385,5.115172161265339
12,18,0.12139334660940311,5.141368819654295
13,19,0.35324034156647377,5.105653807241818
14,21,0.8598592769349482,5.2878534135542585
15,56,0.2811774868724122,5.174688084155005
16,57,0.0986909467164238,5.080575907276883
17,58,0.2804138275758015,5.317279899002262
18,59,0.10218132248457962,5.186546152052083
0,3,0.4656610520531984,5.152417704564987
1,4,-0.6619049175699073,5.109509642795776
2,5,-0.30489980001724165,5.157673432648357
3,6,-0.3744511249944037,5.204534527734516
4,7,0.5207049024291663,5.105300510656678
5,8,0.4685449719711929,5.212333685706411
6,11,0.5942757421805165,5.26690499872594
7,12,0.4984461760139272,5.319452721428102
8,61,0.24888752994444552,5.2151799022595835
9,15,0.36656076386291225,5.235372653308749
10,16,-0.14388278834627607,5.16959473689317
11,17,0.15830518394163073,5.107061371120523
12,18,0.1523359552800044,5.168807658996612
13,19,0.3463333522455231,5.133962895633457
14,21,0.8604157136013464,5.297784710475765
15,56,0.3025314332598707,5.1651932328748265
16,57,0.044855782742234424,5.087187385609759
17,58,0.28479378295988245,5.327166770378123
18,59,0.08530681495166542,5.216335927032842
8 changes: 8 additions & 0 deletions analyses/pot_hammet_ox_inductive.pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
,label,x,y
0,4,0.08186001529337986,5.109669262795919
1,5,0.1216877781083697,5.179951223916893
2,6,0.26614123810058693,5.204223136232075
3,61,0.441928789072139,5.175859953858624
4,16,0.004853312884317348,5.154778148621946
5,17,0.23000928203322155,5.104671984782734
6,18,0.29008216968548856,5.132189953182486
38 changes: 19 additions & 19 deletions analyses/pot_hammet_red.pos
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
,label,x,y
0,3,0.4352083462440204,3.0116800415883263
1,4,-0.6562121090433323,3.010440101492028
2,5,-0.2629680933188102,2.9840132731138604
3,6,-0.364194688738776,3.033507401135774
4,7,0.47792258351026057,2.7875626965663995
5,8,0.4597628155273639,3.05596282690366
6,11,0.6023137066881413,3.1164431657135685
7,12,0.48234002806695414,3.152896507213074
8,61,0.22535150910342203,3.046064622432041
9,15,0.37101496454175054,2.966578215473745
10,16,-0.16097137025307323,2.8710966481003237
11,17,0.2190092710125824,2.9142559067618317
12,18,0.10141105589034936,2.960508715566389
13,19,0.44540862803096176,2.7574447522759185
14,21,0.8736394854908002,3.155250845339613
15,56,0.2872158227717198,2.7398726716995943
16,57,0.11705461837728477,2.8728723482933916
17,58,0.2608371158535701,2.7696985017581195
18,59,0.04649924626357542,2.900332165360863
0,3,0.4990244640551145,3.0010280141011356
1,4,-0.6718668547338792,3.0252138283592562
2,5,-0.29158488492932827,2.969758016682694
3,6,-0.352321062073168,3.0485186701559117
4,7,0.45988533990197816,2.8026866051653823
5,8,0.44756264752176833,3.0715122621198025
6,11,0.6315731980255984,3.1290609603411412
7,12,0.4947782009410651,3.1690258292053675
8,61,0.22946429763164528,3.030994075545434
9,15,0.36830563739852423,2.981910200761413
10,16,-0.16512102424067154,2.8559740904299598
11,17,0.23289805487069487,2.9147097503643757
12,18,0.11536504251354196,2.976286041717534
13,19,0.4435114839990776,2.736719935243295
14,21,0.868802064446903,3.1399317469845727
15,56,0.2759952972892173,2.725164954506571
16,57,0.11450125028242476,2.8575151098804445
17,58,0.26719533093094594,2.814114857132419
18,59,0.03245426200475297,2.8891308161561295
8 changes: 8 additions & 0 deletions analyses/pot_hammet_red_inductive.pos
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
,label,x,y
0,4,0.035337376581764765,2.972832641983517
1,5,0.17303030526137994,2.9745066545200234
2,6,0.256138337583797,3.048211819297735
3,61,0.4624777991554793,3.0908431851705114
4,16,0.11658116035635802,2.8564251098759574
5,17,0.22672574154336922,2.8821160103296757
6,18,0.3084960903721986,2.9185944209147814
Loading

0 comments on commit 6049ea9

Please sign in to comment.