From 3329cb006353f049e88fb3f82708e3b2584de1fc Mon Sep 17 00:00:00 2001 From: diogom Date: Fri, 26 Apr 2024 10:12:55 -0700 Subject: [PATCH] API CHANGE PDBQTReceptor init from string --- meeko/receptor_pdbqt.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/meeko/receptor_pdbqt.py b/meeko/receptor_pdbqt.py index 12257ae6..b87ad3dd 100644 --- a/meeko/receptor_pdbqt.py +++ b/meeko/receptor_pdbqt.py @@ -99,7 +99,8 @@ def _read_receptor_pdbqt_string(pdbqt_string, skip_typing=False): alt_id, in_code, occupancy, temp_factor, record_type)) idx += 1 - + if idx == 0: + raise ValueError(f"no atoms found in {pdbqt_string=}") atoms = np.array(atoms, dtype=atoms_dtype) return atoms, atom_annotations @@ -129,23 +130,32 @@ class PDBQTReceptor: flexres_templates = flexres_templates skip_types=("H",) - def __init__(self, pdbqt_filename, skip_typing=False): - self._pdbqt_filename = pdbqt_filename + def __init__(self, pdbqt_string, skip_typing=False): + self._pdbqt_filename = None self._atoms = None self._atom_annotations = None self._KDTree = None - with open(pdbqt_filename) as f: - pdbqt_string = f.read() - self._atoms, self._atom_annotations = _read_receptor_pdbqt_string(pdbqt_string, skip_typing) # We add to the KDTree only the rigid part of the receptor self._KDTree = spatial.cKDTree(self._atoms['xyz']) self._bonds = _identify_bonds(self._atom_annotations['all'], self._atoms['xyz'], self._atoms['atom_type']) self.atom_idxs_by_res = self.get_atom_indices_by_residue(self._atoms) + @classmethod + def from_pdbqt_filename(cls, pdbqt_filename, skip_typing=False): + with open(pdbqt_filename) as f: + pdbqt_string = f.read() + receptor = cls(pdbqt_string, skip_typing) + receptor._pdbqt_filename = pdbqt_filename + return receptor + def __repr__(self): - return ('' % (self._pdbqt_filename, self._atoms.shape[0])) + if self._pdbqt_filename is None: + msg = '' % self._atoms.shape[0] + else: + msg ='' % (self._pdbqt_filename, self._atoms.shape[0]) + return msg @staticmethod def get_atom_indices_by_residue(atoms):