def _connected_geometry(ich, check=True): """ 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 :param check: check stereo and connectivity? :type check: bool :rtype: automol molecular geometry data structure """ # print("inchi in:", ich) geo = hardcoded_object_from_inchi_by_key('geom', ich) if geo is None: 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) checks_pass = ((same_conn and conn) and (not _has_stereo or ich_equiv)) # print('original inchi', ich) # print('geometry inchi', geo_ich) if not check or checks_pass: success = True break except (RuntimeError, TypeError, ValueError): continue if not success: raise error.FailedGeometryGenerationError('Failed InChI:', ich) return geo
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
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