Skip to content

Commit

Permalink
New: Re-use CHEMKIN name with stereo suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
avcopan committed Aug 29, 2024
1 parent 3d0fffb commit 372d25a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
15 changes: 9 additions & 6 deletions automol/amchi/_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def amchi_key(chi):
return rdkit_.inchi_to_inchi_key(chi)


def chemkin_name(chi: str) -> str:
def chemkin_name(chi: str, root_name: str | None = None) -> str:
"""Generate a CHEMKIN name from a ChI string.
Todo: Simplified names for common species. Anything that can be described as a
Expand All @@ -62,8 +62,13 @@ def chemkin_name(chi: str) -> str:
C5e13 = O1CCC1CC = 1,3-epoxypentane
:param chi: ChI string
:param root_name: A root for the CHEMKIN name, to add stereo if needed
:return: The CHEMKIN name
"""
if root_name is not None:
ste_str = stereo_digest(chi, max_len=16 - len(root_name))
return root_name + ste_str

return digest(chi, conn_max_len=10, ste_max_len=6)


Expand Down Expand Up @@ -429,16 +434,14 @@ def add_stereo(chi):
return chi


def expand_stereo(chi, enant=True):
def expand_stereo(chi: str, enant: bool = True, strained: bool = False) -> list[str]:
"""Obtain all possible stereoisomers of a ChI string.
:param chi: ChI string
:type chi: str
:param enant: Include all enantiomers, or only canonical ones?
:type enant: bool
:rtype: list[str]
:param strained: Include strained stereoisomers?
"""
gra = graph(chi, stereo=False)
sgrs = graph_.expand_stereo(gra, enant=enant, symeq=False)
sgrs = graph_.expand_stereo(gra, enant=enant, strained=strained, symeq=False)
ste_chis = [graph_.amchi(sgr, stereo=True) for sgr in sgrs]
return ste_chis
7 changes: 2 additions & 5 deletions automol/reac/_3find.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,8 @@ def find(rct_gras, prd_gras, stereo=False):
# check whether this is a valid reaction
rct_fmls = list(map(graph.formula, rct_gras))
prd_fmls = list(map(graph.formula, prd_gras))
rct_strs = list(map(form.string, rct_fmls))
prd_strs = list(map(form.string, prd_fmls))
assert form.reac.is_valid_reaction(
rct_fmls, prd_fmls
), f"Invalid reaction: {str(rct_strs):s} -> {str(prd_strs):s}"
if not form.reac.is_valid_reaction(rct_fmls, prd_fmls):
return ()

# Cycle through the different finders and gather all possible reactions
finders_ = [
Expand Down

0 comments on commit 372d25a

Please sign in to comment.