Skip to content

Commit dbcca33

Browse files
committed
Fix geometry -> InChI generation
1 parent 96df5aa commit dbcca33

1 file changed

Lines changed: 2 additions & 29 deletions

File tree

src/automol/geom/_1conv.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pyparsing as pp
1010
from numpy.typing import ArrayLike
1111
from pyparsing import pyparsing_common as ppc
12+
from rdkit.Chem.inchi import MolBlockToInchiAndAuxInfo
1213
from phydat import phycon
1314

1415
from .. import vmat
@@ -340,38 +341,10 @@ def inchi_with_numbers(geo, stereo=True, gra=None):
340341
gra = graph_base.set_stereo_from_geometry(gra, geo)
341342

342343
mlf, key_map_inv = molfile_with_atom_mapping(gra, geo=geo)
343-
rdm = rdkit_.from_molfile(mlf)
344-
ich, aux_info = rdkit_.to_inchi(rdm, with_aux_info=True)
344+
ich, aux_info = MolBlockToInchiAndAuxInfo(mlf)
345345

346346
nums_lst = _parse_sort_order_from_aux_info(aux_info)
347347
nums_lst = tuple(tuple(map(key_map_inv.__getitem__, nums)) for nums in nums_lst)
348-
349-
# Assuming the MolFile InChI works, the above code is all we need. What
350-
# follows is to correct cases where it fails.
351-
# This only appears to work sometimes, so when it doesn't, we fall back on
352-
# the original inchi output.
353-
if geo is not None:
354-
gra = graph_base.set_stereo_from_geometry(gra, geo)
355-
gra = graph_base.implicit(gra)
356-
sub_ichs = inchi_base.split(ich)
357-
358-
failed = False
359-
360-
new_sub_ichs = []
361-
for sub_ich, nums in zip(sub_ichs, nums_lst):
362-
sub_gra = graph_base.subgraph(gra, nums, stereo=True)
363-
sub_ich = _connected_inchi_with_graph_stereo(sub_ich, sub_gra, nums)
364-
if sub_ich is None:
365-
failed = True
366-
break
367-
368-
new_sub_ichs.append(sub_ich)
369-
370-
# If it worked, replace the InChI with our forced-stereo InChI.
371-
if not failed:
372-
ich = inchi_base.join(new_sub_ichs)
373-
ich = inchi_base.standard_form(ich)
374-
375348
return ich, nums_lst
376349

377350

0 commit comments

Comments
 (0)