Esempio n. 1
0
    def fastrocs_query(self, qmol, numHits, host):
        with self.logger("fastrocs_query") as logger:
            ofs = oechem.oemolostream()
            ofs.SetFormat(oechem.OEFormat_OEB)
            ofs.openstring()
            oechem.OEWriteMolecule(ofs, qmol)
            bytes = ofs.GetString()

            s = ServerProxy("http://" + host)
            data = Binary(bytes)
            # idx = s.SubmitQuery(data, numHits)

            dargs = {
                'altStarts': 'random',
                'tversky': False,
                'shapeOnly': False
            }
            assert (numHits is not None)
            assert (data is not None)
            assert (dargs is not None)

            idx = s.SubmitQuery(data, numHits, 'oeb', 'oeb', dargs)

            first = False
            while True:
                try:
                    current, total = s.QueryStatus(idx, True)
                except Fault as e:
                    logger.error((str(e)))
                    return 1

                if total == 0:
                    continue

                if first:
                    # logger.log("%s/%s" % ("current", "total"))
                    first = False
                # logger.log("%i/%i" % (current, total))
                if total <= current:
                    break
            results = s.QueryResults(idx)
            ifs = oechem.oemolistream()
            ifs.openstring(results.data)
            ifs.SetFormat(oechem.OEFormat_OEB)
            mols = []
            for mol in ifs.GetOEMols():
                good_mol = oechem.OEMol(mol)
                oechem.OEAddExplicitHydrogens(good_mol)
                oechem.OEClearSDData(good_mol)
                oeshape.OEDeleteCompressedColorAtoms(good_mol)
                oeshape.OEClearCachedSelfColor(good_mol)
                oeshape.OEClearCachedSelfShape(good_mol)
                oeshape.OERemoveColorAtoms(good_mol)
                mols.append(good_mol)
        return mols
Esempio n. 2
0
    def __call__(self,
                 smiles,
                 receptor_name,
                 receptor=None,
                 receptor_path=None):
        receptor = self.get_receptor_from_request(receptor, receptor_path)
        s = ServerProxy("http://" + f'{self.hostname}:{self.port}')

        opts = OEOptions()
        opts.high_resolution = False

        idx = s.SubmitQuery(smiles, receptor, receptor_name, opts)

        not_done = True
        while not_done:
            try:
                not_done = not s.QueryStatus(idx)
                time.sleep(2)
            except Fault as e:
                print(str(e), file=sys.stderr)
                return 1

        results = s.QueryResults(idx)
        return results