Skip to content

Commit

Permalink
New: Function for getting ChI from AMChI
Browse files Browse the repository at this point in the history
  • Loading branch information
avcopan committed Sep 2, 2024
1 parent bcbbf82 commit cfcc4c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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

0 comments on commit cfcc4c3

Please sign in to comment.