예제 #1
0
파일: _conv.py 프로젝트: snelliott/automol
def _connected_geometry(ich):
    """ Generate a molecular geometry from an InChI string where
        all atoms are connected by at least one bond.

        :param ich: InChI string
        :type ich: str
        :rtype: automol molecular geometry data structure
    """

    geo = hardcoded_object_from_inchi_by_key('geom', ich)
    if geo is None:
        ich = standard_form(ich)

        def _gen1(ich):
            rdm = rdkit_.from_inchi(ich)
            geo, = rdkit_.to_conformers(rdm, nconfs=1)
            return geo

        def _gen2(ich):
            pbm = pybel_.from_inchi(ich)
            geo = pybel_.to_geometry(pbm)
            return geo

        def _gen3(ich):
            if has_stereo(ich):
                raise ValueError

            gra = graph(ich, stereo=False)
            gra = automol.graph.explicit(gra)
            geo = automol.graph.embed.geometry(gra)
            return geo

        for gen_ in [_gen1, _gen1, _gen1, _gen2, _gen3]:
            success = False
            try:
                geo = gen_(ich)
                geo_ich = automol.geom.inchi(geo)
                # Check connectivity
                same_conn = same_connectivity(ich, geo_ich)
                conn = automol.geom.connected(geo)
                _has_stereo = has_stereo(ich)
                ich_equiv = equivalent(ich, geo_ich)
                if (same_conn and conn) and (not _has_stereo or ich_equiv):
                    success = True
                    break
            except (RuntimeError, TypeError, ValueError):
                continue

        if not success:
            raise error.FailedGeometryGenerationError

    return geo
예제 #2
0
파일: _conv.py 프로젝트: Auto-Mech/autochem
def is_complete(ich):
    """ Determine if the InChI string is complete
        (has all stereo-centers assigned).

        Currently only checks species that does not have any
        resonance structures.

        :param ich: InChI string
        :type ich: str
        :rtype: bool
    """

    gra = graph(ich, stereo=False)
    ste_atm_keys = automol.graph.stereogenic_atom_keys(gra)
    ste_bnd_keys = automol.graph.stereogenic_bond_keys(gra)
    graph_has_stereo = bool(ste_atm_keys or ste_bnd_keys)

    _complete = equivalent(
        ich, standard_form(ich)) and not (has_stereo(ich) ^ graph_has_stereo)

    return _complete
예제 #3
0
파일: _conv.py 프로젝트: snelliott/automol
def conformers(ich, nconfs=1):
    """ Generate a list of molecular geometries for various conformers
        of a species from an InChI string.

        :param ich: InChI string
        :type ich: str
        :param nconfs: number of conformer structures to generate
        :type: int
        :rtype: automol molecular geometry data structure
    """

    geo = hardcoded_object_from_inchi_by_key('geom', ich)
    if geo is None:
        ich = standard_form(ich)

        def _gen1(ich):
            rdm = rdkit_.from_inchi(ich)
            geos = rdkit_.to_conformers(rdm, nconfs)
            return geos

        for gen_ in [_gen1]:
            success = False
            try:
                geos = gen_(ich)
                for geo in geos:
                    geo_ich = automol.geom.inchi(geo)
                    if same_connectivity(
                            ich, geo_ich) and (not has_stereo(ich)
                                               or equivalent(ich, geo_ich)):
                        success = True  # fix
                        break
            except (RuntimeError, TypeError, ValueError):
                continue

        if not success:
            raise error.FailedGeometryGenerationError

    return geos
예제 #4
0
파일: _conv.py 프로젝트: snelliott/automol
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