Skip to content

Be more accepting of ways people express InChI#172

Merged
kroenlein merged 2 commits intomainfrom
feature/inchi
Jul 20, 2022
Merged

Be more accepting of ways people express InChI#172
kroenlein merged 2 commits intomainfrom
feature/inchi

Conversation

@kroenlein
Copy link
Copy Markdown
Collaborator

Improved filtering around InChI strings. I think this meets the requested functionality.

@kroenlein kroenlein requested a review from lkubie July 19, 2022 21:43
Copy link
Copy Markdown
Contributor

@lkubie lkubie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a little robustness and provided a real-life example as to why.

self._inchi = None
elif isinstance(value, str):
if not value.lower().startswith('inchi'):
value = f"InChI=1S/{value}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this with the 1s/ so I want to check for that too. Here's Sigma Aldrich for example

Suggested change
value = f"InChI=1S/{value}"
if not value.lower().startswith("1s/") and not value.lower().startswith("1/"):
value = f"InChI=1S/{value}"
else:
value = f"InChI={value}"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch; thanks!

assert test_inchi.inchi == test_struct

assert InChI("inchi=1/C8H8O3").inchi == "InChI=1/C8H8O3"
assert InChI("C8H8O3").inchi == "InChI=1S/C8H8O3"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert InChI("C8H8O3").inchi == "InChI=1S/C8H8O3"
assert InChI("C8H8O3").inchi == "InChI=1S/C8H8O3"
assert InChI("1/C8H8O3").inchi == "InChI=1/C8H8O3"
assert InChI("1s/C8H8O3").inchi == "InChI=1s/C8H8O3"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good add, though the standard expects a capital S.

@kroenlein kroenlein requested a review from lkubie July 20, 2022 15:03
@kroenlein kroenlein merged commit cbc0f42 into main Jul 20, 2022
@kroenlein kroenlein deleted the feature/inchi branch July 20, 2022 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants