def _gen3(ich): if has_stereo(ich): raise ValueError gra = graph(ich, stereo=False) gra = explicit(gra) geo = automol.graph.embed.geometry(gra) return geo
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 = object_from_hardcoded_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 = explicit(gra) geo = automol.graph.embed.geometry(gra) return geo for gen_ in [_gen1, _gen1, _gen1, _gen2, _gen3]: success = False # geo = gen_(ich) # geo_ich = automol.convert.geom.inchi(geo) # same_conn = automol.inchi.same_connectivity(ich, geo_ich) # conn = automol.geom.connected(geo) # has_stereo = automol.inchi.has_stereo(ich) try: geo = gen_(ich) geo_ich = inchi(geo) # Check connectivity same_conn = same_connectivity(ich, geo_ich) conn = 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
def conformers(ich, nconfs): """ 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 = object_from_hardcoded_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 # def _gen2(ich): # pbm = _pybel.from_inchi(ich) # geos = _pybel.to_conformers(pbm) # return geos for gen_ in [_gen1]: success = False try: geos = gen_(ich) for geo in geos: geo_ich = 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
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 = object_from_hardcoded_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 = graph(geo, stereo=stereo) gra = implicit(gra) return gra