Closed tjrong123 closed 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
thanks alot @cbouy
@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
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
u = mda.Universe(prot, trajectory_file) lig = u.select_atoms("resname LIG") prot = u.select_atoms("protein")
lig_mol = plf.Molecule.from_mda(lig) pmol = plf.Molecule.from_mda(prot)
fp = plf.Fingerprint() fp.run(u.trajectory[::10], lig, prot)
net = LigNetwork.from_fingerprint(fp, lig_mol, threshold=float(threshold), rotation=270) net.save(os.path.join(output_name + ".html"))
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}")
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.
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 depictionnet.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}")