def push(data): indigo = Indigo() compound = indigo.loadMolecule(data) indigo_record = IndigoRecordMolecule(indigo_object=compound) elasticRepository = elastic_repository_molecule() elasticRepository.index_record(record=indigo_record)
def search(data): indigo = Indigo() compound = indigo.loadMolecule(data) indigo_record = IndigoRecordMolecule(indigo_object=compound) elasticRepository = elastic_repository_molecule() return elasticRepository.filter(exact=indigo_record)
def test_search_empty_fingerprint( elastic_repository: ElasticRepository, indigo_fixture: Indigo, resource_loader: Callable[[str], str], ): for smile in ["[H][H]", "[H][F]"]: rec = IndigoRecord(indigo_object=indigo_fixture.loadMolecule(smile), skip_errors=True) elastic_repository.index_record(rec) time.sleep(5) result = elastic_repository.filter(exact=IndigoRecord( indigo_object=indigo_fixture.loadMolecule("[H][H]"), skip_errors=True)) assert ("[H][H]" == next(result).as_indigo_object( indigo_fixture).canonicalSmiles()) with pytest.raises(StopIteration): next(result).as_indigo_object(indigo_fixture).canonicalSmiles()
def get_compound_id(smiles): """ returns kegg id for compund with given smiles """ indigo = Indigo() # convert smiles to standard format mol = indigo.loadMolecule(smiles) mol.aromatize() moi_smiles = mol.canonicalSmiles() # Get list of possible kegg IDs url = "http://rest.genome.jp/subcomp/?smiles=%s&cutoff=1.0" % smiles http_client = HTTPClient() try: response = http_client.fetch(url).body except HTTPError as e: raise RuntimeError("Error:", str(e)) http_client.close() subcomp_results = response.split("\n") subcomp_results.pop() subcomp_results = ([i.split('\t')[0] for i in subcomp_results]) # get smiles for all compound IDs found all_smiles = [] uni = UniChem() mapping = uni.get_mapping("kegg_ligand", "chebi") ch = ChEBI() all_smiles = [ch.getCompleteEntity(mapping[x]).smiles for x in subcomp_results] # convert smiles to a standard format for pos, mol in enumerate(all_smiles): m = indigo.loadMolecule(mol) m.aromatize() all_smiles[pos] = m.canonicalSmiles() # check if smiles matches given and, if so, use that compound ID # if not, errors out try: index = all_smiles.index(moi_smiles) except: raise RuntimeError("SMILES unmatchable to: %s" % str(all_smiles)) return subcomp_results[index]
def wrapper(): indigo = Indigo() opts = request.json.get('options', {}) for key, value in opts.items(): try: indigo.setOption(key, value) except IndigoException as e: pass mol_text = request.json.get("struct") try: mol = indigo.loadMolecule(mol_text) except IndigoException as e: return jsonify({'msg': str(e)}) return func(mol)
def get_molfile_v3000(compound: str) -> str: """Computes the molfile v3000 from a compound string. Args: compound: A molfile (either v2000 or v3000), MRV file, etc. Returns: The molfile v3000. """ indigo = Indigo() indigo.setOption("molfile-saving-mode", "3000") molecule = indigo.loadMolecule(compound) return molecule.molfile()
def get_inchikey(compound: str) -> str: """Computes the InChIKey from a compound string. Args: compound: A molfile (either v2000 or v3000), MRV file, SMILES, etc. Returns: The InChIKey for the compound. """ indigo = Indigo() indigo_inchi = IndigoInchi(indigo) molecule = indigo.loadMolecule(compound) inchi = indigo_inchi.getInchi(molecule) return indigo_inchi.getInchiKey(inchi)
def smiles(smiles_string): # Render SMILES to PNG indigo = Indigo() renderer = IndigoRenderer(indigo) mol = indigo.loadMolecule(smiles_string) mol.layout() # if not called, will be done automatically by the renderer indigo.setOption("render-output-format", "png") indigo.setOption("render-image-size", 250, 250) indigo.setOption("render-background-color", 1.0, 1.0, 1.0) indigo.setOption("render-coloring", True) indigo.setOption("aromaticity-model", "generic") mol.dearomatize() buf = renderer.renderToBuffer(mol) buf = io.BytesIO(buf) return send_file( buf, mimetype='image/png', as_attachment=False, )
from bingo_elastic.elastic import ElasticRepository from bingo_elastic.model import helpers from indigo import Indigo if __name__ == '__main__': indigo = Indigo() start_time = time.time() repository = ElasticRepository(host="127.0.0.1", port=9200) # try: # sdf = helpers.iterate_sdf("../data/pubchem/Compound_000000001_000500000.sdf") # repository.index_records(sdf) # except ValueError as e: # print(e) # # # time.sleep(300) print( "--- {} seconds for reading and indexing data ---".format(time.time() - start_time)) mol = indigo.loadMolecule( "Cc1ccc2nc(-c3ccc(NC(C4N(C(c5cccs5)=O)CCC4)=O)cc3)sc2c1") target = IndigoRecord(indigo_object=mol) alg = SimilarityMatch(target, 0.5) similar_records = repository.filter(similarity=alg, limit=20) print(similar_records) print("--- {} seconds ---".format(time.time() - start_time))
indigo.setOption("fp-ext-enabled", True) indigo.setOption("fp-ord-qwords", 0) # optional indigo.setOption("fp-tau-qwords", 0) # optional indigo.setOption("fp-any-qwords", 0) # optional molecules = [] for id in range(len(df_descriptors)): smiles = df_descriptors.ix[id, 'Structure'] descriptors = list(df_descriptors.ix[id])[2:] normalized = [(f - min_bounds[i]) / (max_bounds[i] - min_bounds[i]) for i, f in enumerate(descriptors)] fp = pack_normalized_descriptors_to_fingerprint( normalized, density=0.3, byte_size=fp_size_bytes) mol = indigo.loadMolecule(smiles) molecules += [mol] ext_fp = mol.fingerprintExt(fp, fp_size_bytes) bingo.insertWithExtFP(mol, ext_fp) print("Similarity matrix:") for m1 in molecules: for m2 in molecules: similarity = indigo.similarity(m1, m2) print("%.4f " % similarity, end="") print() print("Bingo similarity search:") query_id = 0 # use the fist molecule as a query for an example smiles = df_descriptors.ix[query_id, 'Structure'] print("Query: %s" % smiles)
for i, sml in enumerate(smiles): print("#%2d: %s" % (i, sml)) df_descriptors = [] indigo = Indigo() # indigo.setOption("similarity-type", "sim") # indigo.setOption("similarity-type", "chem") # indigo.setOption("similarity-type", "ECFP2") indigo.setOption("similarity-type", "ECFP4") # indigo.setOption("similarity-type", "ECFP6") # indigo.setOption("similarity-type", "ECFP8") fingerprints = [] for sml in smiles: mol = indigo.loadMolecule(sml) fp = mol.fingerprint("sim") fingerprints += [fp] print("*** Fingerprints ***") for i, fp in enumerate(fingerprints): str = fp.toString() density = fp_density(str) print("#%2d: Density: %f ; FP: %s" % (i, density, str)) print("*** Similarity matrix ***") for f0 in fingerprints: for f1 in fingerprints: similarity = indigo.similarity(f0, f1)