def _connected_smiles(ich): smi = object_from_hardcoded_inchi_by_key('smiles', ich) if smi is None: ich = automol.inchi.standard_form(ich) rdm = _rdkit.from_inchi(ich) smi = _rdkit.to_smiles(rdm) return smi
def _connected_formula(ich): fml = object_from_hardcoded_inchi_by_key('formula', ich) if fml is None: ich = automol.inchi.standard_form(ich) rdm = _rdkit.from_inchi(ich) fml = _rdkit.to_formula(rdm) return fml
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(object_from_hardcoded_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 = object_from_hardcoded_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
def _connected_graph(ich, no_stereo=False): gra = object_from_hardcoded_inchi_by_key('graph', ich) if gra is None: ich = automol.inchi.standard_form(ich) if no_stereo or not automol.inchi.has_stereo(ich): rdm = _rdkit.from_inchi(ich) gra = _rdkit.to_connectivity_graph(rdm) else: geo = geometry(ich) gra = automol.convert.geom.graph(geo) gra = automol.graph.implicit(gra) return gra
def test__inchi_geometry(): """ test automol.inchi.geometry """ ref_ich = 'InChI=1S/H2S/h1H2' ich = automol.geom.inchi(automol.inchi.geometry(ref_ich)) assert ich == ref_ich ref_ich = 'InChI=1S/Cl2/c1-2' ich = automol.geom.inchi(automol.inchi.geometry(ref_ich)) assert ich == ref_ich ref_ich = 'InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3' pbm = pybel.from_inchi(ref_ich) ich = pybel.to_inchi(pbm) assert ich == ref_ich rdm = rdkit.from_inchi(ref_ich) ich = automol.geom.inchi(rdkit.to_geometry(rdm)) assert ich == ref_ich ref_ich = 'InChI=1S/Ar' rdm = rdkit.from_inchi(ref_ich) ich = automol.geom.inchi(rdkit.to_geometry(rdm)) assert ich == ref_ich
def _connected_smiles(ich): """ Convert a SMILES string into an InChI string. :param smi: SMILES string :type smi: str :rtype: str """ smi = object_from_hardcoded_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
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 = object_from_hardcoded_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
def recalculate(ich, force_stereo=False): """ recalculate InChI string """ # for now, just assert that we have no multi-component strings with # hardcoded parts -- these are guaranteed to fail ichs = automol.inchi.split(ich) if len(ichs) > 1: if any(object_from_hardcoded_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 = automol.inchi.join(ref_ichs) return ret # raise error.FailedInchiGenerationError ret = object_from_hardcoded_inchi_by_key('inchi', ich) if ret is None: _options = '-SUU' if force_stereo else '' rdm = _rdkit.from_inchi(ich) ret = _rdkit.to_inchi(rdm, options=_options, with_aux_info=False) return ret
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
def _gen1(ich): rdm = _rdkit.from_inchi(ich) geos = _rdkit.to_conformers(rdm, nconfs) return geos