-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_potentials.py
executable file
·152 lines (115 loc) · 4.87 KB
/
plot_potentials.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
#!/usr/bin/env python
import sys
import numpy as np
import argparse as arg
import matplotlib.pyplot as plt
from matplotlib import ticker, gridspec
from matplotlib import rc
import matplotlib
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
#rc('font',**{'family':'serif','serif':['Palatino']})
rc('text', usetex=True)
# matplotlib.use('pgf')
# matplotlib.rcParams['pgf.texsystem'] = 'pdflatex'
# matplotlib.rcParams['text.usetex'] = True
# matplotlib.rcParams['text.latex.preamble'] = [ r'\usepackage{siunitx}',
# r'\sisetup{detect-all}',
# r'\usepackage{helvet}',
# r'\usepackage{sansmath}',
# r'\sansmath' ]
def options():
'''Defines the options of the script.'''
parser = arg.ArgumentParser(
formatter_class=arg.ArgumentDefaultsHelpFormatter)
#
# Input Options
#
inp = parser.add_argument_group("Input Data")
inp.add_argument('--qm', type=str, dest='QMFile',
help='''QM Data.''')
inp.add_argument('--mm', type=str, dest='MMFile',
help='''MM Data.''')
inp.add_argument('-m', '--min', type=int, default=180, dest='Min',
help='''Centre of the plot.''')
inp.add_argument('-l', '--label', type=str, default="phi_1", dest='Label',
help='''Label of the plot.''')
inp.add_argument('-c', '--color', type=str, default="b", dest='Color',
help='''Color of the plot.''')
inp.add_argument('-r', '--rescale', default=False, action="store_true", dest='Rescale',
help='''Vertical shifting activated.''')
#
# Output Options
#
out = parser.add_argument_group("Output Options")
out.add_argument('-p', '--pre', default=None, type=str, dest='OutPre',
help='''Output File Prefix.''')
out.add_argument('-o', '--output', default=None, type=str, dest='Out',
help='''Output File Format.''')
args = parser.parse_args()
Opts = vars(args)
return Opts
def myround(x, base=30):
return base * round(x/base)
def plot(qmdata, mmdata, **kwargs):
color = kwargs.pop("Color", "b")
label = kwargs.pop("Label", "phi_1")
rescale = kwargs.pop("Rescale", False)
x_min = kwargs.pop("Min", 180)
x_min = myround(x_min)
fig = plt.figure(figsize=(12, 9))
gs = gridspec.GridSpec(1, 1)
# Sort and transform
qmdata = qmdata[qmdata[:,0].argsort()]
mmdata = mmdata[mmdata[:,0].argsort()]
mask = qmdata[:,0] < 0
qmdata[:,0][mask] = 360 + qmdata[:,0][mask]
mask = mmdata[:,0] < 0
mmdata[:,0][mask] = 360 + mmdata[:,0][mask]
qmdata = qmdata[qmdata[:,0].argsort()]
mmdata = mmdata[mmdata[:,0].argsort()]
# qmdata[:,0] = np.unwrap(qmdata[:,0] * np.pi / 180) * 180 / np.pi - 360
# mmdata[:,0] = np.unwrap(mmdata[:,0] * np.pi / 180) * 180 / np.pi - 360
# Vertical shift
if rescale:
qmdata[:,1] = qmdata[:,1] - qmdata[:,1].min()
mmdata[:,1] = mmdata[:,1] - mmdata[:,1].min()
# Plot
ax = plt.subplot(gs[0])
ax.scatter(qmdata[:,0], qmdata[:,1], color=color, s=80)
ax.plot(mmdata[:,0], mmdata[:,1], color=color, lw=2, ls="--")
ax.set_xlabel(r"$\%s_{%s}$ / deg" % tuple(label.split("_")), size=30, labelpad=5)
ax.set_ylabel(r"$\Delta E$ / KJ mol$^{-1}$", size=30, labelpad=5)
xtickmaj = ticker.MultipleLocator(30)
xtickmin = ticker.AutoMinorLocator(5)
ytickmaj = ticker.MaxNLocator(5)
ytickmin = ticker.AutoMinorLocator(5)
ax.xaxis.set_major_locator(xtickmaj)
ax.xaxis.set_minor_locator(xtickmin)
ax.yaxis.set_major_locator(ytickmaj)
ax.yaxis.set_minor_locator(ytickmin)
ax.xaxis.set_ticks_position('both')
ax.yaxis.set_ticks_position('both')
ax.tick_params(axis='both', which='major', direction='in', labelsize=28, pad=10, length=5)
ax.tick_params(axis='both', which='minor', direction='in', labelsize=28, pad=10, length=2)
ax.set_xlim(qmdata[:,0].min(), qmdata[:,0].max())
ax.set_xlim(x_min - 90, x_min + 90)
return
if __name__ == '__main__':
Opts = options()
qmdata = np.loadtxt(Opts["QMFile"])[:,:2]
mmdata = np.loadtxt(Opts["MMFile"])[:,:2]
plot(qmdata, mmdata, **Opts)
if Opts["Out"]:
if Opts["OutPre"]:
name = "%s_%s_%s.%s" % (Opts["OutPre"],
Opts["Label"].split("_")[0],
Opts["Label"].split("_")[1],
Opts["Out"])
else:
name = "%s_%s.%s" % (Opts["Label"].split("_")[0],
Opts["Label"].split("_")[1],
Opts["Out"])
plt.savefig(name, dpi=600)
else:
plt.show()