Skip to content

Commit

Permalink
fix reactive typing for ligands
Browse files Browse the repository at this point in the history
  • Loading branch information
diogomart committed Sep 4, 2024
1 parent 25b2357 commit 82c5702
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
19 changes: 13 additions & 6 deletions meeko/preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,12 @@ def setup(self):
" MoleculePreparation.prepare() returns a list of MoleculeSetup instances."
)
warnings.warn(msg, DeprecationWarning)
return self.deprecated_setup_access
if len(self.deprecated_setup_access) > 1:
raise RuntimeError(
"got multiple setups, use new api: molsetup_list = mk_prep(mol)"
)

return self.deprecated_setup_access[0]

@classmethod
def get_defaults_dict(cls):
Expand Down Expand Up @@ -551,20 +556,22 @@ def prepare(
self.reactive_smarts,
self.reactive_smarts_idx,
)

if len(reactive_types_dicts) == 0:
raise RuntimeError("reactive SMARTS didn't match")

setups = []
for r in reactive_types_dicts:
new_setup = setup.copy()
# There is no guarantee that the addition order in the dictionary will be the correct order to
# create the list in, so first sorts the keys from the dictionary then extracts the values in order
# to construct the new atom type list.
sorted_keys = list(r.keys())
sorted_keys.sort()
new_setup_atom_type = [r[idx] for idx in sorted_keys]
new_setup.atom_type = new_setup_atom_type
for idx, atom_type in r.items():
new_setup.atoms[idx].atom_type = atom_type
setups.append(new_setup)

# for a gentle introduction of the new API
self.deprecated_setup_access = setups[0]
self.deprecated_setup_access = setups

return setups

Expand Down
4 changes: 2 additions & 2 deletions meeko/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def atom_name_to_molsetup_index(chorizo_residue, atom_name):
return index


def assign_x(molsetup, reactive_atom_index, get_reactive_atype=get_reactive_atype):
def assign_reactive_types_by_index(molsetup, reactive_atom_index, get_reactive_atype=get_reactive_atype):

atypes = {atom.index: atom.atom_type for atom in molsetup.atoms}

Expand Down Expand Up @@ -166,7 +166,7 @@ def assign_reactive_types(
for atom_indices in molsetup.find_pattern(smarts):

reactive_atom_index = atom_indices[smarts_idx]
atypes = assign_x(
atypes = assign_reactive_types_by_index(
molsetup,
reactive_atom_index,
get_reactive_atype
Expand Down
5 changes: 3 additions & 2 deletions scripts/mk_prepare_receptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

import numpy as np

from meeko.reactive import atom_name_to_molsetup_index, assign_x
from meeko.reactive import atom_name_to_molsetup_index
from meeko.reactive import assign_reactive_types_by_index
from meeko import PDBQTMolecule
from meeko import RDKitMolCreate
from meeko import MoleculePreparation
Expand Down Expand Up @@ -441,7 +442,7 @@ def get_args():
# get reactive atom types
reactive_aname = reactive_flexres_name[res_id]
reactive_atomi = atom_name_to_molsetup_index(chorizo.residues[res_id], reactive_aname)
reactive_atypes = assign_x(chorizo.residues[res_id].molsetup, reactive_atomi)
reactive_atypes = assign_reactive_types_by_index(chorizo.residues[res_id].molsetup, reactive_atomi)
# set reactive atom types
nr_atom = len(chorizo.residues[res_id].molsetup.atoms)
for atom_index in range(nr_atom):
Expand Down

0 comments on commit 82c5702

Please sign in to comment.