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

raise RunRequiredError( prolif.exceptions.RunRequiredError: Please run the fingerprint analysis before attempting to display results. #169

Closed tjrong123 closed 7 months ago

tjrong123 commented 7 months ago

I am facing a RunRequiredError during an analysis of protein-ligand network. I have updated the LigNetwork.from_fingerprint for the new version, but now having the RunRequiredError. Can anyone help me with the code?

import MDAnalysis as mda import prolif as plf import numpy as np import os from prolif.plotting.network import LigNetwork

File paths

trajectory_file = "prot_lig_prod_30.dcd" prot = "prot_lig_equil.pdb" lig = "resname LIG" output_name = "contact_analysis" threshold = 0.5 # Set the threshold to 0.5

Load topology

u = mda.Universe(prot, trajectory_file) lig = u.select_atoms("resname LIG") prot = u.select_atoms("protein")

number_frames_analysis = len(u.trajectory) if number_frames_analysis > 10: stride_animation = number_frames_analysis // 10 else: stride_animation = 1

Run fingerprint analysis

fp = plf.Fingerprint() fp.run(u.trajectory[::int(stride_animation)], lig, prot) df = fp.to_dataframe()

Create RDKit-like molecules for visualisation

lmol = plf.Molecule.from_mda(lig) pmol = plf.Molecule.from_mda(prot)

Set the threshold to 0.5 in the following line

net = LigNetwork.from_fingerprint(df, lmol,

replace with kind="frame", frame=0 for the other depiction

                      kind="aggregate", threshold=float(threshold),
                      rotation=270)

net.save(os.path.join(output_name + ".html"))

Save Ligand Interaction Network as PNG image

png_output_path = os.path.join(output_name + "_network.png") net.save_image(png_output_path) print(f"Ligand Interaction Network saved as {png_output_path}")

cbouy commented 7 months ago

Hi @tjrong123

In net = LigNetwork.from_fingerprint(df, the first argument should be the fingerprint object, not the dataframe, you don't need the dataframe anymore for making the lignetwork plot

tjrong123 commented 7 months ago

thanks alot @cbouy

tjrong123 commented 7 months ago

@cbouy I have corrected the code as you pointed out, however now I face another error :/miniconda3/lib/python3.9/site-packages/pandas/core/groupby/grouper.py", line 985, in get_grouper raise KeyError(gpr) KeyError: 'ligand'

Appreciate any comment. My code as follow:

import MDAnalysis as mda import prolif as plf import numpy as np import os from prolif.plotting.network import LigNetwork

File paths

trajectory_file = "prot_lig_prod_30.dcd" prot = "prot_lig_equil.pdb" lig = "resname LIG" output_name = "contact_analysis" threshold = 0.5 # Set the threshold to 0.5

Load topology

u = mda.Universe(prot, trajectory_file) lig = u.select_atoms("resname LIG") prot = u.select_atoms("protein")

Create RDKit-like molecules for visualisation

lig_mol = plf.Molecule.from_mda(lig) pmol = plf.Molecule.from_mda(prot)

Run fingerprint analysis

fp = plf.Fingerprint() fp.run(u.trajectory[::10], lig, prot)

Set the threshold to 0.5 in the following line

net = LigNetwork.from_fingerprint(fp, lig_mol, threshold=float(threshold), rotation=270) net.save(os.path.join(output_name + ".html"))

Save Ligand Interaction Network as PNG image

png_output_path = os.path.join(output_name + "_network.png") net.save_image(png_output_path) print(f"Ligand Interaction Network saved as {png_output_path}")

cbouy commented 7 months ago

Can you add this right after fp.run:

print(lig)
print(prot)
df = fp.to_dataframe()
print(df)

It's hard to tell what's wrong exactly just from your code, but it looks like the dataframe is empty (i.e. no interactions were detected) in this case.