Ejemplo n.º 1
0
def to_inchi(str_data, in_format):
    mol = OBMol()
    conv = OBConversion()
    conv.SetInFormat(in_format)
    conv.ReadString(mol, str_data)

    conv.SetOutFormat('inchi')
    inchi = conv.WriteString(mol).rstrip()
    conv.SetOptions('K', conv.OUTOPTIONS)
    inchikey = conv.WriteString(mol).rstrip()

    return (inchi, inchikey)
Ejemplo n.º 2
0
class Converter:
    def __init__(self, can=False):
        self._OBconverter = OBConversion()
        self._OBconverter.SetOutFormat('smi')
        options = 'in'
        if can:
            options += 'c'
        self._OBconverter.SetOptions(options, OBConversion.OUTOPTIONS)

    def getSmiles(self, mol):
        smiles = self._OBconverter.WriteString(mol.OBMol)[:-1]
        if '@' in smiles:
            smiles = self._OBconverter.WriteString(mol.OBMol)[:-1]
        return smiles
Ejemplo n.º 3
0
def to_inchi(str_data, in_format):
    mol = OBMol()
    conv = OBConversion()
    conv.SetInFormat(in_format)
    # Hackish for now, convert to xyz first...
    conv.SetOutFormat('xyz')
    conv.ReadString(mol, str_data)
    xyz = conv.WriteString(mol)

    # Now convert to inchi and inchikey.
    mol = OBMol()
    conv.SetInFormat('xyz')
    conv.ReadString(mol, xyz)

    conv.SetOutFormat('inchi')
    inchi = conv.WriteString(mol).rstrip()
    conv.SetOptions("K", conv.OUTOPTIONS)
    inchikey = conv.WriteString(mol).rstrip()

    return (inchi, inchikey)
Ejemplo n.º 4
0
def get_inchikey_gen():
    ob_conversion = OBConversion()
    ob_conversion.SetInAndOutFormats("inchi", "inchi")
    ob_conversion.SetOptions("K", ob_conversion.OUTOPTIONS)

    def get_inchikey(ser):
        try:
            if 'inchikey' in ser:
                return ser.inchikey

            if ser.inchi is None or ser.inchi == '':
                raise Exception('Empty inchi')

            mol = OBMol()
            ob_conversion.ReadString(mol, ser.inchi)
            return ob_conversion.WriteString(mol).strip('\n')
        except Exception as e:
            LOG.warning(e)
            return '{}-{}-{}'.format(ser.formula, ser['name'], ser['id'])

    return get_inchikey