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 Molecule
    from rmgpy.exceptions import AtomTypeError
    from ssl import SSLError

    known_names = {
        'o2': '[O][O]',
        'oxygen': '[O][O]',
        'benzyl': '[CH2]c1ccccc1',
        'phenyl': '[c]1ccccc1',
    }

    # Ensure that input is a string
    identifier = str(identifier).strip()

    # Return empty string for empty input
    if identifier == '':
        return HttpResponse('', content_type="text/plain")

    molecule = Molecule()

    # Check if identifier is an InChI string
    if identifier.startswith('InChI=1'):
        try:
            molecule.fromInChI(identifier)
        except AtomTypeError:
            return HttpResponse('Invalid Molecule', status=501)
        except KeyError, e:
            return HttpResponse('Invalid Element: {0!s}'.format(e), status=501)
示例#2
0
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 Molecule
    from rmgpy.exceptions import AtomTypeError
    from ssl import SSLError

    known_names = {
        'o2': '[O][O]',
        'oxygen': '[O][O]',
        'benzyl': '[CH2]c1ccccc1',
        'phenyl': '[c]1ccccc1',
    }

    # Ensure that input is a string
    identifier = str(identifier).strip()

    # Return empty string for empty input
    if identifier == '':
        return HttpResponse('', content_type="text/plain")

    molecule = Molecule()

    # Check if identifier is an InChI string
    if identifier.startswith('InChI=1'):
        try:
            molecule.fromInChI(identifier)
        except AtomTypeError:
            return HttpResponse('Invalid Molecule', status=501)
        except KeyError, e:
            return HttpResponse('Invalid Element: {0!s}'.format(e), status=501)
示例#3
0
                    
for f in os.listdir(folder):
    f = os.path.join(folder,f)
    stem, ext = os.path.splitext(f)
    if ext != '.thermo':
        continue

    with open(f) as thermofile:
        line = thermofile.readline()
        match = re.match('InChI = "(.*?)(\/mult\d)*"',line)
        if not match: continue
        inchi = match.group(1)
        mult = match.group(2)
        if mult: continue
        mol = Molecule()
        mol.fromInChI(inchi)
        mmol = rmgpy.qm.mopac.MopacMolPM3(mol, settings)
        print mmol.uniqueID, f
        thermo = mmol.loadThermoData()
        if not thermo: continue
        
        assert inchi.startswith('InChI=1S/')
        inchimain = inchi[9:]
        keystart = keydict[inchimain]
        jthermo = thermodict[keystart]
        print mol.toSMILES()
        print inchi
        print keystart
        print thermo
        print jthermo