diff --git a/automol/amchi/__init__.py b/automol/amchi/__init__.py index 0eb40a37..e05955bc 100644 --- a/automol/amchi/__init__.py +++ b/automol/amchi/__init__.py @@ -89,6 +89,7 @@ from ._conv import chemkin_name from ._conv import connectivity_digest from ._conv import stereo_digest +from ._conv import chi_ from ._conv import smiles from ._conv import graph from ._conv import geometry @@ -198,6 +199,7 @@ 'chemkin_name', 'connectivity_digest', 'stereo_digest', + 'chi_', 'smiles', 'graph', 'geometry', diff --git a/automol/amchi/_conv.py b/automol/amchi/_conv.py index a39baab3..a187c9a8 100644 --- a/automol/amchi/_conv.py +++ b/automol/amchi/_conv.py @@ -149,6 +149,19 @@ def stereo_digest(chi: str, racem: bool = False, max_len: int | None = None) -> return ste_str +def chi_(chi: str) -> str: + """Convert AMChI string to InChI, if appropriate. + + :param chi: AMChI string + :return: An InChI or AMChI string encoding the same species + """ + gra = graph(chi, local_stereo=True) + ich = graph_.inchi(gra, stereo=True, local_stereo=True) + if not graph_.inchi_is_bad(gra, ich): + return ich + return chi + + def smiles(chi, res_stereo=True): """Convert a ChI string into a SMILES string. diff --git a/automol/graph/_2conv.py b/automol/graph/_2conv.py index 12c3dc1e..1d60f7ee 100644 --- a/automol/graph/_2conv.py +++ b/automol/graph/_2conv.py @@ -188,7 +188,7 @@ def _clean_and_validate_connected_geometry( return geo if matches or not check else None -def inchi(gra, stereo=True): +def inchi(gra, stereo: bool=True, local_stereo: bool=False): """Generate an InChI string from a molecular graph. :param gra: molecular graph @@ -197,7 +197,7 @@ def inchi(gra, stereo=True): :type stereo: bool :rtype: str """ - smi = smiles(gra, stereo=stereo, res_stereo=False) + smi = smiles(gra, stereo=stereo, res_stereo=False, local_stereo=local_stereo) rdm = rdkit_.from_smiles(smi) ich = rdkit_.to_inchi(rdm) return ich