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

Problem using the last version of Prolif #154

Closed xavgit closed 10 months ago

xavgit commented 10 months ago

Hi, If I run the following using the last version of prolif:

fp = plf.Fingerprint() fp.run_from_iterable( docked_poses , receptor )

I receive the the error:

0%| | 0/5 [00:00<?, ?it/s] multiprocess.pool.RemoteTraceback: """ Traceback (most recent call last): File "/home/xxxx/.local/lib/python3.8/site-packages/multiprocess/pool.py", line 125, in worker result = (True, func(*args, *kwds)) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/parallel.py", line 233, in executor return cls.fp.generate(mol, cls.pmol, residues=cls.residues, metadata=True) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 371, in generate interactions = get_interactions(lres, pres) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 306, in metadata return { File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 309, in if (metadata := interaction(res1, res2, metadata=True)) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 54, in wrapped return next(interaction(args, **kwargs), None) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/interactions/base.py", line 48, in call for int_data in self.detect(lig_res, prot_res): File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/interactions/interactions.py", line 480, in detect yield self.metadata( File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/interactions/base.py", line 71, in metadata [get_mapindex(prot_res, index) for index in prot_indices] File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/interactions/base.py", line 71, in [get_mapindex(prot_res, index) for index in prot_indices] File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/interactions/utils.py", line 24, in get_mapindex return res.GetAtomWithIdx(index).GetUnsignedProp("mapindex") KeyError: 'mapindex' """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "prolif_analysis.py", line 11, in fp.run_from_iterable( docked_poses , receptor ) File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 596, in run_from_iterable return self._run_iter_parallel( File "/home/xxxx/.local/lib/python3.8/site-packages/prolif/fingerprint.py", line 629, in _run_iter_parallel for i, ifp_data in enumerate(pool.process(lig_iterable)): File "/home/xxxx/.local/lib/python3.8/site-packages/tqdm/std.py", line 1180, in iter for obj in iterable: File "/home/xxxx/.local/lib/python3.8/site-packages/multiprocess/pool.py", line 868, in next raise value KeyError: 'mapindex'


(program exited with code: 1) Press return to continue

If I downgrade to 1.1.0 version then it seems that all is fine obtaining:

100%|█████████████████████████████████████████████| 5/5 [00:00<00:00, 81.23it/s]


(program exited with code: 0) Press return to continue

Thanks. Saverio

PS: I have used the F5 key of Geany to run the code.

cbouy commented 10 months ago

How did you prepare docked_poses and receptor?

xavgit commented 10 months ago

Hi, thanks for the reply.

For the receptor I have used the following code; import pickle import prolif as plf import MDAnalysis as mda

u = mda.Universe( 'receptor_dock_prep.pdb' ) receptor = plf.Molecule.from_mda( u ) with open( 'receptor_dock_prep_mda.pkl' , 'wb' ) as outfile: pickle.dump( receptor , outfile )

Then from a file ZINCID_docked.sdf converted from the file ZINCID_docked.pdbqt ( obtained using vina with num_modes = 5 ) using mk_export.py the following code:

import pickle import prolif as plf

with open( 'receptor_dock_prep_mda.pkl' , 'rb' ) as infile: receptor = pickle.load( infile ) docked_poses = plf.sdf_supplier( 'ZINCID_docked.sdf' )

fp = plf.Fingerprint() fp.run_from_iterable( docked_poses , receptor ) df = fp.to_dataframe()

With prolif 1.1.0 it runs without errors.

Thanks.

Saverio ZINC000016999890_docked.pdbqt.txt ZINC000016999890_docked.sdf.txt

cbouy commented 10 months ago

Ah yes this might be because you're loading your receptor from a pickle file, by default RDKit does not transfer atomic properties when you do this. The previous version of ProLIF was applying a patch (on import) for this which wasn't very conservative, and the new version only applies the patch when necessary.

You can force-apply the patch by running this before pickling your receptor:

from prolif.pickling import PICKLE_HANDLER

PICKLE_HANDLER.set()

# pickle your receptor
...

or alternatively:

from rdkit import Chem

Chem.SetDefaultPickleProperties(Chem.PropertyPickleOptions.AtomProps ^ Chem.PropertyPickleOptions.MolProps)

which should do the same thing

xavgit commented 10 months ago

Hi, thanks for your help and the Prolif package. I will avoid to use pickle. The reason to use it is for save time and prepare the receptor from mda only one time for many different docked ligands.

Thanks. Saverio

orgw commented 1 month ago

Thank you!! this helped