def getAdjacencyList(request, identifier): """ Returns an adjacency list of the species corresponding to `identifier`. `identifier` should be something recognized by NCI resolver, eg. SMILES, InChI, CACTVS, chemical name, etc. The NCI resolver has some bugs regarding reading SMILES of radicals. E.g. it thinks CC[CH] is CCC, so we first try to use the identifier directly as a SMILES string, and only pass it through the resolver if that does not work. """ if identifier.strip() == '': return HttpResponse('', mimetype="text/plain") from rmgpy.molecule.molecule import Molecule molecule = Molecule() try: # try using the string as a SMILES directly molecule.fromSMILES(str(identifier)) except (IOError, ValueError): # try converting it to a SMILES using the NCI chemical resolver url = "http://cactus.nci.nih.gov/chemical/structure/{0}/smiles".format( urllib.quote(identifier)) try: f = urllib2.urlopen(url, timeout=5) except urllib2.URLError, e: return HttpResponseNotFound( "404: Couldn't identify {0}. NCI resolver responded {1} to request for {2}" .format(identifier, e, url)) smiles = f.read() molecule.fromSMILES(smiles)
def getAdjacencyList(request, identifier): """ Returns an adjacency list of the species corresponding to `identifier`. `identifier` should be something recognized by NCI resolver, eg. SMILES, InChI, CACTVS, chemical name, etc. The NCI resolver has some bugs regarding reading SMILES of radicals. E.g. it thinks CC[CH] is CCC, so we first try to use the identifier directly as a SMILES string, and only pass it through the resolver if that does not work. For specific problematic cases, the NCI resolver is bypassed and the SMILES is returned from a dictionary of values. For O2, the resolver returns the singlet form which is inert in RMG. For oxygen, the resolver returns 'O' as the SMILES, which is the SMILES for water. """ from rmgpy.molecule import AtomTypeError if identifier.strip() == '': return HttpResponse('', content_type="text/plain") from rmgpy.molecule.molecule import Molecule molecule = Molecule() try: # try using the string as a SMILES directly molecule.fromSMILES(str(identifier)) except AtomTypeError: return HttpResponse('Invalid Molecule', status=501) except KeyError, e: return HttpResponse('Invalid Element: {0!s}'.format(e), status=501)
def getAdjacencyList(request, identifier): """ Returns an adjacency list of the species corresponding to `identifier`. `identifier` should be something recognized by NCI resolver, eg. SMILES, InChI, CACTVS, chemical name, etc. The NCI resolver has some bugs regarding reading SMILES of radicals. E.g. it thinks CC[CH] is CCC, so we first try to use the identifier directly as a SMILES string, and only pass it through the resolver if that does not work. """ if identifier.strip() == '': return HttpResponse('', mimetype="text/plain") from rmgpy.molecule.molecule import Molecule molecule = Molecule() try: # try using the string as a SMILES directly molecule.fromSMILES(str(identifier)) except IOError: # try converting it to a SMILES using the NCI chemical resolver url = "http://cactus.nci.nih.gov/chemical/structure/{0}/smiles".format(urllib.quote(identifier)) try: f = urllib2.urlopen(url, timeout=5) except urllib2.URLError, e: return HttpResponseNotFound("404: Couldn't identify {0}. NCI resolver responded {1} to request for {2}".format(identifier, e, url)) smiles = f.read() molecule.fromSMILES(smiles)
def testSSSR(self): """ Test the Molecule.getSmallestSetOfSmallestRings() method with a complex polycyclic molecule. """ molecule = Molecule() molecule.fromSMILES('C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC') #http://cactus.nci.nih.gov/chemical/structure/C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC/image sssr = molecule.getSmallestSetOfSmallestRings() self.assertEqual( len(sssr), 3)
def testSSSR(self): """ Test the Molecule.getSmallestSetOfSmallestRings() method with a complex polycyclic molecule. """ molecule = Molecule() molecule.fromSMILES('C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC') #http://cactus.nci.nih.gov/chemical/structure/C(CC1C(C(CCCCCCCC)C1c1ccccc1)c1ccccc1)CCCCCC/image sssr = molecule.getSmallestSetOfSmallestRings() self.assertEqual(len(sssr), 3)
def getAdjacencyList(request, identifier): """ Returns an adjacency list of the species corresponding to `identifier`. `identifier` should be something recognized by NCI resolver, eg. SMILES, InChI, CACTVS, chemical name, etc. The NCI resolver has some bugs regarding reading SMILES of radicals. E.g. it thinks CC[CH] is CCC, so we first try to use the identifier directly as a SMILES string, and only pass it through the resolver if that does not work. For specific problematic cases, the NCI resolver is bypassed and the SMILES is returned from a dictionary of values. For O2, the resolver returns the singlet form which is inert in RMG. For oxygen, the resolver returns 'O' as the SMILES, which is the SMILES for water. """ if identifier.strip() == '': return HttpResponse('', content_type="text/plain") from rmgpy.molecule.molecule import Molecule molecule = Molecule() try: # try using the string as a SMILES directly molecule.fromSMILES(str(identifier)) except (IOError, ValueError): known_names = {'O2': '[O][O]', 'oxygen': '[O][O]'} key = str(identifier) if key in known_names: smiles = known_names[key] else: # try converting it to a SMILES using the NCI chemical resolver url = "http://cactus.nci.nih.gov/chemical/structure/{0}/smiles".format( urllib.quote(identifier)) try: f = urllib2.urlopen(url, timeout=5) except urllib2.URLError, e: return HttpResponseNotFound( "404: Couldn't identify {0}. NCI resolver responded {1} to request for {2}" .format(identifier, e, url)) smiles = f.read() molecule.fromSMILES(smiles)
def getAdjacencyList(request, identifier): """ Returns an adjacency list of the species corresponding to `identifier`. `identifier` should be something recognized by NCI resolver, eg. SMILES, InChI, CACTVS, chemical name, etc. The NCI resolver has some bugs regarding reading SMILES of radicals. E.g. it thinks CC[CH] is CCC, so we first try to use the identifier directly as a SMILES string, and only pass it through the resolver if that does not work. For specific problematic cases, the NCI resolver is bypassed and the SMILES is returned from a dictionary of values. For O2, the resolver returns the singlet form which is inert in RMG. For oxygen, the resolver returns 'O' as the SMILES, which is the SMILES for water. """ if identifier.strip() == '': return HttpResponse('', content_type="text/plain") from rmgpy.molecule.molecule import Molecule molecule = Molecule() try: # try using the string as a SMILES directly molecule.fromSMILES(str(identifier)) except (IOError, ValueError): known_names = {'O2':'[O][O]', 'oxygen':'[O][O]'} key = str(identifier) if key in known_names: smiles = known_names[key] else: # try converting it to a SMILES using the NCI chemical resolver url = "http://cactus.nci.nih.gov/chemical/structure/{0}/smiles".format(urllib.quote(identifier)) try: f = urllib2.urlopen(url, timeout=5) except urllib2.URLError, e: return HttpResponseNotFound("404: Couldn't identify {0}. NCI resolver responded {1} to request for {2}".format(identifier, e, url)) smiles = f.read() molecule.fromSMILES(smiles)