Ejemplo n.º 1
0
def recalculate(ich, stereo=False):
    """ Recalculate an InChI string.

        :param ich: InChI string
        :type ich: str
        :param stereo: force the same stereochem in recalculated InChI
        :type stereo: bool
        :rtype: str
    """

    # for now, just assert that we have no multi-component strings with
    # hardcoded parts -- these are guaranteed to fail
    ichs = split(ich)
    if len(ichs) > 1:
        if any(hardcoded_object_from_inchi_by_key('inchi', ich)
               for ich in ichs):
            ref_ichs = []
            for ich_i in ichs:
                ref_ichs.append(recalculate(ich_i))
            ref_ichs.sort()
            ret = join(ref_ichs)
            return ret
        # raise error.FailedInchiGenerationError

    ret = hardcoded_object_from_inchi_by_key('inchi', ich)
    if ret is None:
        _options = '-SUU' if stereo else ''
        rdm = rdkit_.from_inchi(ich)
        ret = rdkit_.to_inchi(rdm, options=_options, with_aux_info=False)

    return ret
Ejemplo n.º 2
0
def draw(ich, save_path=None):
    """ Draw an image
    """
    rdm = rdkit_.from_inchi(ich)
    img = rdkit_.draw(rdm)
    if save_path is not None:
        img.save(save_path)

    return img
Ejemplo n.º 3
0
def rdkit_molecule(gra):
    """ Convert a molecular graph to an RDKit molecule.

    This is mainly useful for quick visualization with IPython, which can be
    done as follows:
    >>> from IPython.display import display
    >>> display(rdkit_molecule(gra))

    :param gra: the graph
    :returns: the RDKit molecule
    """
    return rdkit_.from_inchi(inchi(gra))
Ejemplo n.º 4
0
def draw_grid(ichs, legends=None,
              img_per_row=3, sub_img_size=(200, 200),
              save_path=None):
    """ Draw an image
    """
    rdms = tuple(rdkit_.from_inchi(ich) for ich in ichs)
    img = rdkit_.draw_grid(
        rdms,
        img_per_row=img_per_row,
        sub_img_size=sub_img_size,
        legends=legends)
    if save_path is not None:
        img.save(save_path)

    return img
Ejemplo n.º 5
0
def _connected_smiles(ich):
    """ Convert a SMILES string into an InChI string.

        :param smi: SMILES string
        :type smi: str
        :rtype: str
    """

    smi = hardcoded_object_from_inchi_by_key('smiles', ich)
    if smi is None:
        ich = standard_form(ich)
        rdm = rdkit_.from_inchi(ich)
        smi = rdkit_.to_smiles(rdm)

    return smi
Ejemplo n.º 6
0
def _connected_formula(ich):
    """ Create a combined molecular from the formulas of a
        multi-component InChI string.

        :param ich: InChI string
        :type ich: str
        :rtype: dict[str: int]
    """

    fml = hardcoded_object_from_inchi_by_key('formula', ich)
    if fml is None:
        ich = standard_form(ich)
        rdm = rdkit_.from_inchi(ich)
        fml = rdkit_.to_formula(rdm)

    return fml
Ejemplo n.º 7
0
def _inchi_connected_graph(ich, stereo=True):
    """ Generate a molecular graph from an InChI string where
        all all atoms are connected by at least one bond.

        :param ich: InChI string
  d      :type ich: str
        :param remove_stereo: parameter to include stereochemistry information
        :type remove_stereo: bool
        :rtype: automol molecular graph
    """

    gra = hardcoded_object_from_inchi_by_key('graph', ich)
    if gra is None:
        ich = standard_form(ich)
        if not stereo or not has_stereo(ich):
            rdm = rdkit_.from_inchi(ich)
            gra = rdkit_.to_connectivity_graph(rdm)
        else:
            geo = geometry(ich)
            gra = automol.geom.graph(geo, stereo=stereo)

    gra = automol.graph.implicit(gra)
    return gra
Ejemplo n.º 8
0
 def _gen1(ich):
     rdm = rdkit_.from_inchi(ich)
     geos = rdkit_.to_conformers(rdm, nconfs)
     return geos