Skip to content

Commit

Permalink
Reorder logic to get rid of noise error and reword assoc. error
Browse files Browse the repository at this point in the history
It's possible for the program logic to be wrong and not the user, so the error message now implies that you should
double-check your InChI. Moving the error condition out of a try-block also lets us get rid of some unnecessary
noise -- we don't need two tracebacks for the same error (one for UnboundLocalException, another for ValueError),
since the error we care about is the second one anyway.
  • Loading branch information
zjp committed Apr 30, 2020
1 parent 4681637 commit acf67b2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions InchiGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,10 @@ def GenDSInchis(inchi):
for l in layers:
if 't' in l:
numds = 2**(len(l.translate({ord(i): None for i in 't,1234567890'}))-1)

try:
if numds == 0:
raise ValueError("No chiral carbon detected in the input molecule!")
else:
print("Number of diastereomers to be generated: " + str(numds))
except UnboundLocalError as e:
raise ValueError("No chiral carbon present in the input molecule!") from e

#find configuration sites (+ and -)
bs = ilist.index('t')
Expand Down

0 comments on commit acf67b2

Please sign in to comment.