forlilab / Meeko

Interfacing RDKit and AutoDock
GNU Lesser General Public License v2.1
182 stars 43 forks source link

`PDBQTMolecule` from `.pdbqt` error: 'numpy.ndarray' object has no attribute 'append' #29

Closed linminhtoo closed 1 year ago

linminhtoo commented 1 year ago

Hello,

I tried to parse .pdbqt file using meeko but got an error:

from meeko import PDBQTMolecule
pdbqt_mol = PDBQTMolecule.from_file(my_pdbqt_path), is_dlg=False, skip_typing=True)
File /nix/store/pd3h7x3zskxlj161kqhihah3r735i17h-python3-3.10.5-env/lib/python3.10/site-packages/meeko/molecule_pdbqt.py:315, in PDBQTMolecule.from_file(cls, pdbqt_filename, name, poses_to_read, energy_range, is_dlg, skip_typing)
    313 with open(pdbqt_filename) as f:
    314     pdbqt_string = f.read()
--> 315 instance = cls(pdbqt_string, name, poses_to_read, energy_range, is_dlg, skip_typing) 
    316 instance._pdbqt_filename = pdbqt_filename
    317 return instance

File /nix/store/pd3h7x3zskxlj161kqhihah3r735i17h-python3-3.10.5-env/lib/python3.10/site-packages/meeko/molecule_pdbqt.py:287, in PDBQTMolecule.__init__(self, pdbqt_string, name, poses_to_read, energy_range, is_dlg, skip_typing)
    285 poses_to_read = poses_to_read if poses_to_read is not None else -1
    286 energy_range = energy_range if energy_range is not None else -1
--> 287 results = _read_ligand_pdbqt_file(pdbqt_string, poses_to_read, energy_range, is_dlg, skip_typing)
    288 self._atoms, self._positions, self._atom_annotations, self._pose_data = results
    290 if self._atoms.shape[0] == 0:

File /nix/store/pd3h7x3zskxlj161kqhihah3r735i17h-python3-3.10.5-env/lib/python3.10/site-packages/meeko/molecule_pdbqt.py:120, in _read_ligand_pdbqt_file(pdbqt_string, poses_to_read, energy_range, is_dlg, skip_typing)
    117         i += 1
    119 # Once it is done, we can return to a normal life... and add existing atoms
--> 120 tmp_atoms.append((i, serial, name, resid, resname, chainid, xyz, partial_charges, atom_type))
    121 tmp_positions.append(xyz)
    122 tmp_actives.append(i)

AttributeError: 'numpy.ndarray' object has no attribute 'append'

Here's the PDBQT file for your reference: https://gist.github.com/linminhtoo/5949437ae066fdd136709971dcc36220 The ligand was prepared using meeko before docking to Vina-GPU.

Do you know what's the issue? Thank you! Min Htoo

linminhtoo commented 1 year ago

I found the problem. It only throws this error if the .pdbqt file contains multiple poses. If I read the .pdbqt and then do some text parsing to retain just the top pose, then it works fine:

from meeko import PDBQTMolecule

with open(my_pdbqt_path, "r") as f:
    poses = f.read()
top_pose_pdbqt = "MODE" + poses.split("MODE")[1]
pdbqt_mol = PDBQTMolecule(top_pose_pdbqt, is_dlg=False, skip_typing=True)
rdkit_mol = pdbqt_mol[0].export_rdkit_mol()

So, seems like there's a bug when reading multiple poses?

I also confirm that the below works:

pdbqt_mol = PDBQTMolecule.from_file(my_pdbqt_path, skip_typing=True, poses_to_read=1)
...
diogomart commented 1 year ago

Hello

Looks like the program you used (Vina-GPU) writes MODE instead of MODEL. So this fixes it:

sed "s/MODE /MODEL /g" results.pdbqt > results-OK.pdbqt

By the way, this molecule is a macrocycle but most likely Vina-GPU can't handle the CG/G pseudo atoms, so it isn't rebuilding the broken bond between CG atoms.