Skip to content

Commit

Permalink
furbish SI in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Jun 1, 2024
1 parent 6a68356 commit 5817197
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 120 deletions.
3 changes: 1 addition & 2 deletions analyses/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ all:
python plot_CIP.py -o ../FigureS2.pdf
python plot_pairs.py -o ../FigureS3.pdf
python plot_pot_hammet.py -o ../FigureS4.pdf
python plot_cplx_r.py -o ../FigureS5.pdf
python plot_cplx_Gx1.py -o ../FigureS6.pdf
python plot_cplx_Gx1.py -o ../FigureS5.pdf
3 changes: 2 additions & 1 deletion analyses/nitroxides/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas
from scipy.spatial import distance_matrix

# -- Electrolyres, from wB97X-D/6-311+G(d)
# -- Electrolytes, from wB97X-D/6-311+G(d)
G_NME4 = {'water': -214.096721, 'acetonitrile': -214.104109}
G_BF4 = {'water': -424.654435, 'acetonitrile': -424.656267}
RADII_NME4 = {'water': 2.108130614275878, 'acetonitrile': 2.098320849223868}
Expand All @@ -13,6 +13,7 @@
# -- CST

C_NITROXIDE = 1e-3 # mol L-1
EPSILON_R = {'water': 80, 'acetonitrile': 35}

# -- Debye-Huckel theory

Expand Down
38 changes: 38 additions & 0 deletions analyses/nitroxides/tex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import pandas

def format_table(data: pandas.DataFrame, titles: list, line_maker, column_def=None) -> str:
if column_def is None:
column_def = ['X[c]'] * len(titles)
column_def[0] = '>{\\bfseries}l'

r = '\\begin{{tblr}}{{{}}}\n\\hline\n'.format(''.join(column_def))

# titles
r += ' & '.join(titles) + '\\\\\n\\hline\n'

# data
for row in data.iterrows():
r += ' & '.join(line_maker(row[1])) + '\\\\\n'

r += '\\hline\n\\end{tblr}'

return r

def format_longtable(data: pandas.DataFrame, titles: list, line_maker, column_def=None) -> str:
if column_def is None:
column_def = ['X[c]'] * len(titles)
column_def[0] = '>{\\bfseries}l'

r = '\\begin{{longtblr}}[caption={{}}]{{colspec={{{}}}, width = 0.85\\linewidth,rowhead=1}}\n\\hline\n'.format(''.join(column_def))

# titles
r += ' & '.join(titles) + '\\\\\n\\hline\n'

# data
for row in data.iterrows():
r += ' & '.join(line_maker(row[1])) + '\\\\\n'

r += '\\hline\n\\end{longtblr}\n'

return r
66 changes: 49 additions & 17 deletions analyses/plot_cplx_Gx1.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import pandas
import matplotlib.pyplot as plt
import numpy
import sys
import pathlib
import argparse

from matplotlib.ticker import AutoMinorLocator, MultipleLocator
from nitroxides.commons import AU_TO_ANG, AU_TO_KJMOL, G_NME4, G_BF4, RADII_BF4, RADII_NME4, C_NITROXIDE, dG_DH_cplx_Kx1
from nitroxides.commons import AU_TO_ANG, AU_TO_KJMOL, G_NME4, G_BF4, RADII_BF4, RADII_NME4, C_NITROXIDE, dG_DH_cplx_Kx1, EPSILON_R
from nitroxides.tex import format_longtable

T = 298.15
R = 8.3145e-3 # kJ mol⁻¹

def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: float, color: str):
def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, color: str):
subdata_k01 = data[(data['family'] == family) & (data['solvent'] == solvent) & (data['has_anion'] == True)] # K_01 → N+ + A-
subdata_k21 = data[(data['family'] == family) & (data['solvent'] == solvent) & (data['has_cation'] == True)] # K_21 → N- + C+

dG_DH_k01_0 = dG_DH_cplx_Kx1(subdata_k01['z'] + 1, subdata_k01['z'], -1, subdata_k01['r_A'] / AU_TO_ANG, subdata_k01['r_AX'] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r, c_elt=0.1)
dG_DH_k21_0 = dG_DH_cplx_Kx1(subdata_k21['z'] - 1, subdata_k21['z'], 1, subdata_k21['r_A'] / AU_TO_ANG, subdata_k21['r_AX'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, epsilon_r, c_elt=0.1)
dG_DH_k01_0 = dG_DH_cplx_Kx1(subdata_k01['z'] + 1, subdata_k01['z'], -1, subdata_k01['r_A'] / AU_TO_ANG, subdata_k01['r_AX'] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent], c_elt=0.1)
dG_DH_k21_0 = dG_DH_cplx_Kx1(subdata_k21['z'] - 1, subdata_k21['z'], 1, subdata_k21['r_A'] / AU_TO_ANG, subdata_k21['r_AX'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, EPSILON_R[solvent], c_elt=0.1)

dG_DH_k01 = dG_DH_cplx_Kx1(subdata_k01['z'] + 1, subdata_k01['z'], -1, subdata_k01['r_A'] / AU_TO_ANG, subdata_k01['r_AX'] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k21 = dG_DH_cplx_Kx1(subdata_k21['z'] - 1, subdata_k21['z'], 1, subdata_k21['r_A'] / AU_TO_ANG, subdata_k21['r_AX'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k01 = dG_DH_cplx_Kx1(subdata_k01['z'] + 1, subdata_k01['z'], -1, subdata_k01['r_A'] / AU_TO_ANG, subdata_k01['r_AX'] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k21 = dG_DH_cplx_Kx1(subdata_k21['z'] - 1, subdata_k21['z'], 1, subdata_k21['r_A'] / AU_TO_ANG, subdata_k21['r_AX'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, EPSILON_R[solvent])

dG_k01_0 = (subdata_k01['G_cplx'] - G_BF4[solvent] + dG_DH_k01_0) * AU_TO_KJMOL
dG_k21_0 = (subdata_k21['G_cplx'] - G_NME4[solvent] + dG_DH_k21_0) * AU_TO_KJMOL
Expand All @@ -30,11 +31,37 @@ def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: f
ax.plot([int(x.replace('mol_', '')) for x in subdata_k21['name']], dG_k21, 's', color=color)
ax.plot([int(x.replace('mol_', '')) for x in subdata_k01['name']], dG_k01_0, 'o', markerfacecolor='none', markeredgecolor=color)
ax.plot([int(x.replace('mol_', '')) for x in subdata_k21['name']], dG_k21_0, 's', markerfacecolor='none', markeredgecolor=color)

def make_table(f, data: pandas.DataFrame, solvent: str):
subdata_k01 = data[(data['solvent'] == solvent) & (data['has_anion'] == True)] # K_01 → N+ + A-
subdata_k21 = data[(data['solvent'] == solvent) & (data['has_cation'] == True)] # K_21 → N- + C+

dG_DH_k01 = dG_DH_cplx_Kx1(subdata_k01['z'] + 1, subdata_k01['z'], -1, subdata_k01['r_A'] / AU_TO_ANG, subdata_k01['r_AX'] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k21 = dG_DH_cplx_Kx1(subdata_k21['z'] - 1, subdata_k21['z'], 1, subdata_k21['r_A'] / AU_TO_ANG, subdata_k21['r_AX'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, EPSILON_R[solvent])

subdata_k01.insert(1, 'dG_cplx', (subdata_k01['G_cplx'] - G_BF4[solvent] + dG_DH_k01) * AU_TO_KJMOL)
subdata_k21.insert(1, 'dG_cplx', (subdata_k21['G_cplx'] - G_NME4[solvent] + dG_DH_k21) * AU_TO_KJMOL)

subdata = subdata_k01.join(subdata_k21.set_index('name'), on='name', lsuffix='k01', rsuffix='k21', how='inner')

f.write(format_longtable(
subdata,
titles=['', '$a_{\\ce{NA}}$', '$\\Delta{G}_{cplx}^\\star$', '', '$a_{\\ce{NC}}$','$\\Delta{G}_{cplx}^\\star$'],
line_maker=lambda r: [
r['name'].replace('mol_', ''),
'{:.2f}'.format(r['r_AXk01']),
'{:.1f}'.format(r['dG_cplxk01']),
'',
'{:.2f}'.format(r['r_AXk21']),
'{:.1f}'.format(r['dG_cplxk21']),
]
))


parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', default='../data/Data_cplx_Kx1.csv')
parser.add_argument('-o', '--output', default='Data_cplx_Gx1.pdf')
parser.add_argument('-t', '--table')

args = parser.parse_args()

Expand All @@ -43,11 +70,11 @@ def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: f
figure = plt.figure(figsize=(10, 8))
ax1, ax2 = figure.subplots(2, 1, sharey=True, sharex=True)

plot_Kx1(ax1, data, 'Family.AMO', 'water', 80.,'tab:pink')
plot_Kx1(ax1, data, 'Family.P6O', 'water', 80.,'tab:blue')
plot_Kx1(ax1, data, 'Family.P5O', 'water', 80., 'black')
plot_Kx1(ax1, data, 'Family.IIO', 'water', 80., 'tab:green')
plot_Kx1(ax1, data, 'Family.APO', 'water', 80., 'tab:red')
plot_Kx1(ax1, data, 'Family.AMO', 'water', 'tab:pink')
plot_Kx1(ax1, data, 'Family.P6O', 'water', 'tab:blue')
plot_Kx1(ax1, data, 'Family.P5O', 'water', 'black')
plot_Kx1(ax1, data, 'Family.IIO', 'water', 'tab:green')
plot_Kx1(ax1, data, 'Family.APO', 'water', 'tab:red')

ax1.legend(ncols=5)
ax1.set_xlim(0.5,61.5)
Expand All @@ -56,10 +83,10 @@ def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: f
ax1.grid(which='both', axis='x')
ax1.plot([0, 62], [0, 0], '-', color='grey')

plot_Kx1(ax2, data, 'Family.P6O', 'acetonitrile', 35.,'tab:blue')
plot_Kx1(ax2, data, 'Family.P5O', 'acetonitrile', 35., 'black')
plot_Kx1(ax2, data, 'Family.IIO', 'acetonitrile', 35., 'tab:green')
plot_Kx1(ax2, data, 'Family.APO', 'acetonitrile', 35., 'tab:red')
plot_Kx1(ax2, data, 'Family.P6O', 'acetonitrile', 'tab:blue')
plot_Kx1(ax2, data, 'Family.P5O', 'acetonitrile', 'black')
plot_Kx1(ax2, data, 'Family.IIO', 'acetonitrile', 'tab:green')
plot_Kx1(ax2, data, 'Family.APO', 'acetonitrile', 'tab:red')

ax2.set_xlabel('Molecule id')
ax2.set_xlim(0.5,61.5)
Expand All @@ -68,7 +95,12 @@ def plot_Kx1(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: f
ax2.grid(which='both', axis='x')
ax2.plot([0, 62], [0, 0], '-', color='grey')

[ax.set_ylabel('$\\Delta G^\\star_{pair}$ (kJ mol$^{-1}$)') for ax in [ax1, ax2]]
[ax.set_ylabel('$\\Delta G^\\star_{cplx}$ (kJ mol$^{-1}$)') for ax in [ax1, ax2]]

plt.tight_layout()
figure.savefig(args.output)

if args.table:
with pathlib.Path(args.table).open('w') as f:
make_table(f, data, 'water')
make_table(f, data, 'acetonitrile')
72 changes: 53 additions & 19 deletions analyses/plot_cplx_Kx2.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import pandas
import matplotlib.pyplot as plt
import numpy
import sys
import pathlib
import argparse

from matplotlib.ticker import AutoMinorLocator, MultipleLocator
from nitroxides.commons import AU_TO_ANG, AU_TO_KJMOL, G_NME4, G_BF4, RADII_BF4, RADII_NME4, C_NITROXIDE, dG_DH_cplx_Kx2
from nitroxides.commons import AU_TO_ANG, AU_TO_KJMOL, G_NME4, G_BF4, RADII_BF4, RADII_NME4, C_NITROXIDE, dG_DH_cplx_Kx2, EPSILON_R
from nitroxides.tex import format_longtable

T = 298.15
R = 8.3145e-3 # kJ mol⁻¹

def plot_Kx2(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: float, color: str):
def plot_Kx2(ax, data: pandas.DataFrame, family: str, solvent: str, color: str):
subdata = data[(data['family'] == family) & (data['solvent'] == solvent)]

dG_DH_k02 = dG_DH_cplx_Kx2(subdata['z'] + 1, subdata['z'] + 1, 1, subdata['r_A_ox'] / AU_TO_ANG, subdata['r_AX_ox'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k12 = dG_DH_cplx_Kx2(subdata['z'], subdata['z'], 1, subdata['r_A_rad'] / AU_TO_ANG, subdata['r_AX_rad'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k22 = dG_DH_cplx_Kx2(subdata['z'] - 1, subdata['z'] - 1, 1, subdata['r_A_red'] / AU_TO_ANG, subdata['r_AX_red'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k02 = dG_DH_cplx_Kx2(subdata['z'] + 1, subdata['z'] + 1, 1, subdata['r_A_ox'] / AU_TO_ANG, subdata['r_AX_ox'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k12 = dG_DH_cplx_Kx2(subdata['z'], subdata['z'], 1, subdata['r_A_rad'] / AU_TO_ANG, subdata['r_AX_rad'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k22 = dG_DH_cplx_Kx2(subdata['z'] - 1, subdata['z'] - 1, 1, subdata['r_A_red'] / AU_TO_ANG, subdata['r_AX_red'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])

dG_k02 = (subdata['G_cplx_ox'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k02) * AU_TO_KJMOL
dG_k12 = (subdata['G_cplx_rad'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k12) * AU_TO_KJMOL
Expand All @@ -29,19 +30,47 @@ def plot_Kx2(ax, data: pandas.DataFrame, family: str, solvent: str, epsilon_r: f
ax.plot([int(x.replace('mol_', '')) for x in subdata['name']], numpy.log10(k12), '^', color=color)
ax.plot([int(x.replace('mol_', '')) for x in subdata['name']], numpy.log10(k22), 's', color=color)

def helpline_K02(ax, data: pandas.DataFrame, solvent: str, epsilon_r: float, color: str = 'black'):
def helpline_K02(ax, data: pandas.DataFrame, solvent: str, color: str = 'black'):
subdata = data[data['solvent'] == solvent]

dG_DH_k12 = dG_DH_cplx_Kx2(subdata['z'], subdata['z'], 1, subdata['r_A_rad'] / AU_TO_ANG, subdata['r_AX_rad'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, epsilon_r)
dG_DH_k12 = dG_DH_cplx_Kx2(subdata['z'], subdata['z'], 1, subdata['r_A_rad'] / AU_TO_ANG, subdata['r_AX_rad'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_k12 = (subdata['G_cplx_rad'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k12) * AU_TO_KJMOL
k12 = numpy.exp(-dG_k12 / (R * T))

ax.plot([int(x.replace('mol_', '')) for x in subdata['name']], numpy.log10(k12), '--', color=color, linewidth=0.75)

def make_table(f, data: pandas.DataFrame, solvent: str):
subdata = data[data['solvent'] == solvent]

dG_DH_k02 = dG_DH_cplx_Kx2(subdata['z'] + 1, subdata['z'] + 1, 1, subdata['r_A_ox'] / AU_TO_ANG, subdata['r_AX_ox'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k12 = dG_DH_cplx_Kx2(subdata['z'], subdata['z'], 1, subdata['r_A_rad'] / AU_TO_ANG, subdata['r_AX_rad'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])
dG_DH_k22 = dG_DH_cplx_Kx2(subdata['z'] - 1, subdata['z'] - 1, 1, subdata['r_A_red'] / AU_TO_ANG, subdata['r_AX_red'] / AU_TO_ANG, RADII_NME4[solvent] / AU_TO_ANG, RADII_BF4[solvent] / AU_TO_ANG, EPSILON_R[solvent])

subdata.insert(1, 'dG_cplx_ox', (subdata['G_cplx_ox'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k02) * AU_TO_KJMOL)
subdata.insert(1, 'dG_cplx_rad', (subdata['G_cplx_rad'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k12) * AU_TO_KJMOL)
subdata.insert(1, 'dG_cplx_red', (subdata['G_cplx_red'] - G_NME4[solvent] - G_BF4[solvent] + dG_DH_k22) * AU_TO_KJMOL)

f.write(format_longtable(
subdata,
titles=['', '$a_{\\ce{NAC+}}$', '$\\Delta{G}_{cplx}^\\star$', '', '$a_{\\ce{NAC^.}}$', '$\\Delta{G}_{cplx}^\\star$', '', '$a_{\\ce{NAC-}}$', '$\\Delta{G}_{cplx}^\\star$'],
line_maker=lambda r: [
r['name'].replace('mol_', ''),
'{:.2f}'.format(r['r_AX_ox']),
'{:.1f}'.format(r['dG_cplx_ox']),
'',
'{:.2f}'.format(r['r_AX_rad']),
'{:.1f}'.format(r['dG_cplx_rad']),
'',
'{:.2f}'.format(r['r_AX_red']),
'{:.1f}'.format(r['dG_cplx_red']),
]
))


parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', default='../data/Data_cplx_Kx2.csv')
parser.add_argument('-o', '--output', default='Data_cplx_Kx2.pdf')
parser.add_argument('-t', '--table')

args = parser.parse_args()

Expand All @@ -50,13 +79,13 @@ def helpline_K02(ax, data: pandas.DataFrame, solvent: str, epsilon_r: float, col
figure = plt.figure(figsize=(10, 8))
ax1, ax2 = figure.subplots(2, 1, sharey=True, sharex=True)

helpline_K02(ax1, data, 'water', 80, 'black')
helpline_K02(ax1, data, 'water', 'black')

plot_Kx2(ax1, data, 'Family.AMO', 'water', 80.,'tab:pink')
plot_Kx2(ax1, data, 'Family.P6O', 'water', 80.,'tab:blue')
plot_Kx2(ax1, data, 'Family.P5O', 'water', 80., 'black')
plot_Kx2(ax1, data, 'Family.IIO', 'water', 80., 'tab:green')
plot_Kx2(ax1, data, 'Family.APO', 'water', 80., 'tab:red')
plot_Kx2(ax1, data, 'Family.AMO', 'water', 'tab:pink')
plot_Kx2(ax1, data, 'Family.P6O', 'water', 'tab:blue')
plot_Kx2(ax1, data, 'Family.P5O', 'water', 'black')
plot_Kx2(ax1, data, 'Family.IIO', 'water', 'tab:green')
plot_Kx2(ax1, data, 'Family.APO', 'water', 'tab:red')

ax1.legend(ncols=5)
ax1.set_xlim(0.5,61.5)
Expand All @@ -67,12 +96,12 @@ def helpline_K02(ax, data: pandas.DataFrame, solvent: str, epsilon_r: float, col

ax1.legend()

helpline_K02(ax2, data, 'acetonitrile', 35, 'black')
helpline_K02(ax2, data, 'acetonitrile', 'black')

plot_Kx2(ax2, data, 'Family.P6O', 'acetonitrile', 35.,'tab:blue')
plot_Kx2(ax2, data, 'Family.P5O', 'acetonitrile', 35., 'black')
plot_Kx2(ax2, data, 'Family.IIO', 'acetonitrile', 35., 'tab:green')
plot_Kx2(ax2, data, 'Family.APO', 'acetonitrile', 35., 'tab:red')
plot_Kx2(ax2, data, 'Family.P6O', 'acetonitrile', 'tab:blue')
plot_Kx2(ax2, data, 'Family.P5O', 'acetonitrile', 'black')
plot_Kx2(ax2, data, 'Family.IIO', 'acetonitrile', 'tab:green')
plot_Kx2(ax2, data, 'Family.APO', 'acetonitrile', 'tab:red')

ax2.set_xlabel('Molecule id')
ax2.set_xlim(0.5,61.5)
Expand All @@ -85,3 +114,8 @@ def helpline_K02(ax, data: pandas.DataFrame, solvent: str, epsilon_r: float, col

plt.tight_layout()
figure.savefig(args.output)

if args.table:
with pathlib.Path(args.table).open('w') as f:
make_table(f, data, 'water')
make_table(f, data, 'acetonitrile')
56 changes: 0 additions & 56 deletions analyses/plot_cplx_r.py

This file was deleted.

Loading

0 comments on commit 5817197

Please sign in to comment.