Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Function for getting ChI from AMChI #568

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions automol/amchi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -198,6 +199,7 @@
'chemkin_name',
'connectivity_digest',
'stereo_digest',
'chi_',
'smiles',
'graph',
'geometry',
Expand Down
13 changes: 13 additions & 0 deletions automol/amchi/_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions automol/graph/_2conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down