A plot of interactions over time is shown only in black and gray #149
Unanswered
AbdulrahamnEid
asked this question in
Q&A
Replies: 1 comment 4 replies
-
Hi @AbdulrahamnEid, try downgrading your version of seaborn: |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to show the schematics of protein-ligand interactions in 200 ns from gromacs simulation, but the Figs are only shown in black and gray. What is the solution to that problem?
#!/usr/bin/env python
coding: utf-8
In[1]:
import prolif as plf
import MDAnalysis as mda
from MDAnalysis.topology.guessers import guess_types
import seaborn as sns
import pandas as pd
In[6]:
dir_= r'E:\SCI\MDS\prolif\MVC\223232\'
u = mda.Universe(dir_+'MD.gro',
dir_+'MD_center_test.xtc', guess_bonds=True
)
guessed_elements = guess_types(u.atoms.names)
u.add_TopologyAttr('elements', guessed_elements)
# create selections for the ligand and protein
lig = u.atoms.select_atoms("resname LIG")
prot = u.atoms.select_atoms("protein")
In[7]:
from rdkit import Chem
from rdkit.Chem import Draw
import math as m
create a molecule from the MDAnalysis selection
lmol = plf.Molecule.from_mda(lig)
cleanup before drawing
mol = Chem.RemoveHs(lmol)
mol.RemoveAllConformers()
Draw.MolToImage(mol, size=(400,200))
In[10]:
pmol = plf.Molecule.from_mda(prot)
frags = []
to show all residues, simply use
for res in pmol:
for i in range(300):
res = pmol[i]
mol = Chem.RemoveHs(res)
mol.RemoveAllConformers()
frags.append(mol)
Draw.MolsToGridImage(
frags,
legends=[str(res.resid) for res in pmol],
subImgSize=(200, 140),
molsPerRow=4,
maxMols=prot.n_residues,
)
In[11]:
use default interactions
fp = plf.Fingerprint()
run on a slice of frames from begining to end with a step of 1
fp.run(u.trajectory, lig, prot, residues=None, progress=True, n_jobs=None) # detect amino acids close to the ligand (6 A)
In[26]:
df = fp.to_dataframe()
show only the 10 first frames
df.head(5)
df = df[::10]
df
In[36]:
to show the occurence of interaction types for each amino acid
prob=0.5
calculate the occurence of each interaction on the trajectory
occ = df.mean()
restrict to the frequent ones
inter = occ.loc[occ >= prob]
print(inter)
print(inter.reset_index()['interaction'].unique())
In[37]:
drop the ligand residue column since there's only a single ligand residue
df = df.droplevel("ligand", axis=1)
df.head(5)
In[43]:
def plot(sub_data, part, dpi):
sns.set_theme(font_scale=.8, style="white", context="talk")
g = sns.catplot(
data=sub_data, x="interaction", y="Time (ns)", hue="interaction", col="residue",
hue_order=sub_data.interaction.unique(),#['Hydrophobic', 'HBAcceptor', 'PiCation', 'HBDonor', 'PiStacking'], #plf.Fingerprint.list_available(show_hidden=False),#["Hydrophobic", "HBDonor", "HBAcceptor", "PiStacking", "CationPi", "Cationic"],
height=3, aspect=0.2, jitter=0, sharex=False, marker="", s=8, linewidth=.3#, pointsize=2
)
g.set_titles("{col_name}")
g.set(xticks=[], ylim=(-.5, data['Time (ns)'].max()))#(data.Frame.max()+1)/10))
g.set_xticklabels([])
g.set_xlabels("")
g.fig.subplots_adjust(wspace=0)
g.add_legend()
g.despine(bottom=True)
for ax in g.axes.flat:
#ax.invert_yaxis()
ax.set_title(ax.get_title(), pad=15, rotation=60, ha="center", va="baseline")
g.savefig(dir+f"/interactions_occurence_larger_{prob}part{part}.tiff",
dpi=dpi)
reorganize data
data = df.reset_index()
data = pd.melt(data, id_vars=["Frame"], var_name=["residue","interaction"])
data = data[data["value"] != False]
data["Time (ns)"] = data["Frame"]*.01
data.reset_index(inplace=True, drop=True)
plot
number_figs = 3
aa_numb = int(m.ceil(len(data.residue.unique())/number_figs))
unique = data.residue.unique()
for i in range(number_figs):
if (i+1) * aa_numb > len(data.residue.unique()):
aa_names = unique[iaa_numb : ]
else:
aa_names = unique[iaa_numb : (i+1)*aa_numb]
sub_data = data[data.residue.isin(aa_names)]
plot(sub_data, i+1, dpi=500)
Beta Was this translation helpful? Give feedback.
All reactions