def score(self, function, protein = None, *args, **kwargs): """Scoring procedure. Parameters ---------- function: string Which scoring function to use. protein: oddt.toolkit.Molecule Default protein to use as reference Note ---- Additional parameters are passed directly to the scoring function. """ if type(protein) is str: extension = protein.split('.')[-1] protein = six.next(toolkit.readfile(extension, protein)) protein.protein = True # trigger cache protein.atom_dict if type(function) is str: if function.lower().startswith('rfscore'): from oddt.scoring.functions.RFScore import rfscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) elif bit.startswith('v'): new_kwargs['version'] = int(bit.replace('v', '')) sf = rfscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower().startswith('nnscore'): from oddt.scoring.functions.NNScore import nnscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) sf = nnscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower() == 'autodock_vina': from oddt.docking import autodock_vina sf = autodock_vina(protein, *args, **kwargs) sf.set_protein(protein) else: raise ValueError('Scoring Function %s was not implemented in ODDT' % function) else: if hasattr(function, 'set_protein') and hasattr(function, 'predict_ligands') and hasattr(function, 'predict_ligand'): sf = function sf.set_protein(protein) else: raise ValueError('Supplied object "%s" is not an ODDT scoring funtion' % function.__name__) if self.n_cpu != 1: _parallel_helper_partial = partial(_parallel_helper, sf, 'predict_ligand') self._pipe = Pool(self.n_cpu if self.n_cpu > 0 else None).imap(_parallel_helper_partial, ({'ligand': lig} for lig in self._pipe), chunksize=100) else: self._pipe = sf.predict_ligands(self._pipe)
def score(self, function, protein = None, *args, **kwargs): """Scoring procedure. Parameters ---------- function: string Which scoring function to use. protein: oddt.toolkit.Molecule Default protein to use as reference Note ---- Additional parameters are passed directly to the scoring function. """ if type(protein) is str: extension = protein.split('.')[-1] protein = toolkit.readfile(extension, protein).next() protein.protein = True # trigger cache protein.atom_dict if type(function) is str: if function.lower().startswith('rfscore'): from oddt.scoring.functions.RFScore import rfscore tmp = function.lower().split('_') v = int(tmp[-1][1:]) if len(tmp) > 1 else 1 sf = rfscore.load(version=v) sf.set_protein(protein) elif function.lower() == 'nnscore': from oddt.scoring.functions.NNScore import nnscore sf = nnscore.load() sf.set_protein(protein) elif function.lower() == 'autodock_vina': from oddt.docking import autodock_vina sf = autodock_vina(protein, *args, **kwargs) sf.set_protein(protein) else: raise ValueError('Scoring Function %s was not implemented in ODDT' % function) else: if hasattr(function, 'set_protein') and hasattr(function, 'predict_ligands') and hasattr(function, 'predict_ligand'): sf = function sf.set_protein(protein) else: raise ValueError('Supplied object "%s" is not an ODDT scoring funtion' % function.__name__) if self.n_cpu != 1: _parallel_helper_partial = partial(_parallel_helper, sf, 'predict_ligand') self._pipe = self._pool.imap(_parallel_helper_partial, ({'ligand': lig} for lig in self._pipe), chunksize=100) else: self._pipe = sf.predict_ligands(self._pipe)
def score(self, function, protein=None, *args, **kwargs): """Scoring procedure compatible with any scoring function implemented in ODDT and other pickled SFs which are subclasses of `oddt.scoring.scorer`. Parameters ---------- function: string Which scoring function to use. protein: oddt.toolkit.Molecule Default protein to use as reference Note ---- Additional parameters are passed directly to the scoring function. """ if isinstance(protein, six.string_types): extension = protein.split('.')[-1] protein = next(oddt.toolkit.readfile(extension, protein)) protein.protein = True elif protein is None: raise ValueError('Protein needs to be set for structure based ' 'scoring') # trigger cache protein.atom_dict if isinstance(function, six.string_types): if isfile(function): sf = scorer.load(function) sf.set_protein(protein) elif function.lower().startswith('rfscore'): from oddt.scoring.functions.RFScore import rfscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) elif bit.startswith('v'): new_kwargs['version'] = int(bit.replace('v', '')) sf = rfscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower().startswith('nnscore'): from oddt.scoring.functions.NNScore import nnscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) sf = nnscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower() == 'autodock_vina': from oddt.docking import autodock_vina sf = autodock_vina(protein, *args, **kwargs) sf.set_protein(protein) else: raise ValueError('Scoring Function %s was not implemented in ' 'ODDT' % function) else: if isinstance(function, scorer): sf = function sf.set_protein(protein) else: raise ValueError('Supplied object "%s" is not an ODDT scoring ' 'funtion' % function.__name__) self._pipe.append(partial(method_caller, sf, 'predict_ligands'))
def score(self, function, protein=None, *args, **kwargs): """Scoring procedure compatible with any scoring function implemented in ODDT and other pickled SFs which are subclasses of `oddt.scoring.scorer`. Parameters ---------- function: string Which scoring function to use. protein: oddt.toolkit.Molecule Default protein to use as reference Notes ----- Additional parameters are passed directly to the scoring function. """ if isinstance(protein, six.string_types): extension = protein.split('.')[-1] protein = next(oddt.toolkit.readfile(extension, protein)) protein.protein = True elif protein is None: raise ValueError('Protein needs to be set for structure based ' 'scoring') # trigger cache protein.atom_dict if isinstance(function, six.string_types): if isfile(function): sf = scorer.load(function) sf.set_protein(protein) elif function.lower().startswith('rfscore'): from oddt.scoring.functions.RFScore import rfscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) elif bit.startswith('v'): new_kwargs['version'] = int(bit.replace('v', '')) sf = rfscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower().startswith('nnscore'): from oddt.scoring.functions.NNScore import nnscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) sf = nnscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower().startswith('plec'): from oddt.scoring.functions.PLECscore import PLECscore new_kwargs = {} for bit in function.lower().split('_'): if bit.startswith('pdbbind'): new_kwargs['pdbbind_version'] = int(bit.replace('pdbbind', '')) elif bit.startswith('plec'): new_kwargs['version'] = bit.replace('plec', '') elif bit.startswith('p'): new_kwargs['depth_protein'] = int(bit.replace('p', '')) elif bit.startswith('l'): new_kwargs['depth_ligand'] = int(bit.replace('l', '')) elif bit.startswith('s'): new_kwargs['size'] = int(bit.replace('s', '')) sf = PLECscore.load(**new_kwargs) sf.set_protein(protein) elif function.lower() == 'autodock_vina': from oddt.docking import autodock_vina sf = autodock_vina(protein, *args, **kwargs) sf.set_protein(protein) else: raise ValueError('Scoring Function %s was not implemented in ' 'ODDT' % function) else: if isinstance(function, scorer): sf = function sf.set_protein(protein) else: raise ValueError('Supplied object "%s" is not an ODDT scoring ' 'funtion' % function.__name__) self._pipe.append(partial(method_caller, sf, 'predict_ligands'))