Case Study - Alanine Dipeptide
Contents
Case Study - Alanine Dipeptide#
** Info about the data **
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib notebook
import nglview
Molecular Visualization using nglview#
view = nglview.show_file("ini0.pdb")
view
view = nglview.show_file("ini0.pdb")
view.add_label(label_type="element", color="black")
view
Plotting the Potential Energy Surface#
# Set font size
mpl.rcParams['font.size'] = 14
mpl.rcParams['legend.fontsize'] = 'large'
df = pd.read_csv("a1a2ene.csv")
df.head()
phi | psi | energy | |
---|---|---|---|
0 | -180 | -180 | -0.120177 |
1 | -180 | -160 | -0.118642 |
2 | -180 | -140 | -0.116515 |
3 | -180 | -120 | -0.115398 |
4 | -180 | -100 | -0.115198 |
# Need to prepare data for plotting.
x = df["phi"].unique()
y = df["psi"].unique()
z = df["energy"].values.reshape(19, -1, order="F")
# Get the min and max energy values
pmin = z.min()
pmax = z.max()
fig, ax = plt.subplots()
ticks = np.linspace(pmin, pmax, 5)
CS = ax.contourf(x, y, z, cmap="jet", levels=30)
#ax.contour(x_,y_, values_square, colors='white')
ax.set_aspect('equal')
ax.set_xlabel(r'$\phi$')
ax.set_ylabel(r'$\psi$')
fig.colorbar(CS, format="%.3f", ticks=ticks)
<matplotlib.colorbar.Colorbar at 0x7f6ebe151280>
Low and High Energy#
import matplotlib.image as mpimg
import nglview
min_loc = np.argwhere(z == np.min(z))
max_loc = np.argwhere(z == np.max(z))
print(max_loc)
print(min_loc)
[[0 9]]
[[14 5]]
max_view = nglview.show_file("pdb/opt.0.9.pdb")
max_view
min_view = nglview.show_file("pdb/opt.14.5.pdb")
min_view
min_v = min_view.render_image()
with open('low_energy.png', 'wb') as t:
t.write(min_v.value)
max_v = max_view.render_image()
max_v
with open('high_energy.png', 'wb') as t:
t.write(max_v.value)
im = mpimg.imread("low_energy.png")
crop = im[:1200, 1500:2500 , :4]
im2 = mpimg.imread("high_energy.png")
crop2 = im2[:1200, 1500:2500 , :4]
fig, ax = plt.subplots(1, 3, figsize=(10,6))
ticks = np.linspace(pmin, pmax, 5)
CS = ax[0].contourf(x, y, z, cmap="jet", levels=30)
ax[0].contour(x,y, z, colors='white')
ax[0].set_aspect('equal')
ax[0].set_xlabel(r'$\phi$')
ax[0].set_ylabel(r'$\psi$')
ax[1].imshow(crop)
ax[1].axis("off")
ax[2].imshow(crop2)
ax[2].axis("off")
fig.colorbar(CS, format="%.3f", ticks=ticks, location="bottom", ax=ax[:])
<matplotlib.colorbar.Colorbar at 0x7f6e8f569f70>