chemosim-lab / ProLIF

Interaction Fingerprints for protein-ligand complexes and more
https://prolif.readthedocs.io
Apache License 2.0
337 stars 66 forks source link

Getting interaction barcode #156

Closed Le-Phung-Hien closed 9 months ago

Le-Phung-Hien commented 9 months ago

Hi,

Thanks for the help on the last issues, Now I'm trying to get the interaction barcode as an image.

I'm running this script now with an sdf file the ligands:

import MDAnalysis as mda
import prolif as plf
import sys
import argparse
import os
from IPython.display import display
from prolif.plotting.barcode import Barcode

# Create an argument parser
parser = argparse.ArgumentParser(description='Protein-ligand interaction barcoding')

# Add arguments
parser.add_argument('-p', '--protein', type=str, help='Path to the protein file')
parser.add_argument('-l', '--ligands', type=str, help='Path to the ligand file')

# Parse the command-line arguments
args = parser.parse_args()

protein = args.protein
ligands = args.ligands

# Read the protein file
u = mda.Universe(protein)
protein_mol = plf.Molecule.from_mda(u)

# Load ligands
poses_path = str(os.path.abspath(ligands))
if ligands.endswith('.sdf'):
    pose_iterable = plf.sdf_supplier(poses_path)
if ligands.endswith('.mol2'):
    pose_iterable = plf.mol2_supplier(poses_path)

# Use default interactions
fp = plf.Fingerprint()

# Run on your poses
fp.run_from_iterable(pose_iterable, protein_mol)

# show dataframe
df = fp.to_dataframe(index_col="Compound")
display(df)

# show barcode
fp.plot_barcode(xlabel="Compound")

# show first compound's interactions
fp.plot_lignetwork(pose_iterable[0])

Everything running well, but nothing else happen after the table get displayed on screen, no error warning also.

Do I need Jupyter to display the barcode and interaction?

Thanks!

cbouy commented 9 months ago

You don't need it but it's preferred, since you can execute each line of code separately so it's more appropriate for an interactive analysis, especially for the visualization of your results.

Otherwise it will require extra steps:

For the barcode you need to add from matplotlib import pyplot as plt, then after plot_barcode you can add plt.show() to show the barcode (blocks the script until you close the window), or plt.savefig("barcode.png") to save the image to a location.

For the lignetwork, it's really meant to be used in a notebook. You could run the following to save each pose as an HTML file though:

from prolif.plotting.network import LigNetwork

for index, pose_mol in enumerate(pose_iterable):
    ligplot = LigNetwork.from_fingerprint(
        fp=fp,
        ligand_mol=pose_mol,
        kind="frame",
        frame=pose_index,
    )
    ligplot.save(f"ligplot_{index}.html")

and remove plot_lignetwork