-
Notifications
You must be signed in to change notification settings - Fork 27
fix: honor explicit zero valence instead of hallucinating hydrogens #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fbaensch-beilstein
wants to merge
2
commits into
dev
Choose a base branch
from
fix/zero-valence-hallucinated-hydrogens
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Regression test for https://github.com/IUPAC-InChI/InChI/issues/105 | ||
|
|
||
| An explicit zero valence (``VAL=-1`` in V3000, valence field ``15`` in V2000) | ||
| must not cause implicit hydrogens to be added. Before the fix, a terminal atom | ||
| carrying a single bond was treated as having a target valence of 15, so | ||
| ``15 - 1 = 14`` hydrogens were "hallucinated" per atom, yielding | ||
| ``InChI=1S/C2H28/c1-2/h1-2H14`` for ethane. | ||
|
|
||
| The correct behaviour is to honour the zero valence: no implicit hydrogens are | ||
| added while the drawn bond is kept, giving ``InChI=1S/C2/c1-2``. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from helpers import parse_inchi_from_executable_output | ||
|
|
||
| EXPECTED_INCHI = "InChI=1S/C2/c1-2" | ||
|
|
||
| ETHANE_V3000_ZERO_VALENCE = """ | ||
| ChemDraw04232514542D | ||
|
|
||
| 0 0 0 0 0 0 V3000 | ||
| M V30 BEGIN CTAB | ||
| M V30 COUNTS 2 1 0 0 0 | ||
| M V30 BEGIN ATOM | ||
| M V30 1 C 0.000000 0.000000 0.000000 0 VAL=-1 | ||
| M V30 2 C 1.000000 0.000000 0.000000 0 VAL=-1 | ||
| M V30 END ATOM | ||
| M V30 BEGIN BOND | ||
| M V30 1 1 1 2 | ||
| M V30 END BOND | ||
| M V30 END CTAB | ||
| M END | ||
| """ | ||
|
|
||
| ETHANE_V2000_ZERO_VALENCE = """ | ||
| test | ||
|
|
||
| 2 1 0 0 0 0 0 0 0 0999 V2000 | ||
| 0.0000 0.0000 0.0000 C 0 0 0 0 0 15 0 0 0 0 0 0 | ||
| 1.0000 0.0000 0.0000 C 0 0 0 0 0 15 0 0 0 0 0 0 | ||
| 1 2 1 0 0 0 0 | ||
| M END | ||
| """ | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "molfile", | ||
| [ETHANE_V3000_ZERO_VALENCE, ETHANE_V2000_ZERO_VALENCE], | ||
| ids=["v3000", "v2000"], | ||
| ) | ||
| def test_zero_valence_does_not_hallucinate_hydrogens(molfile, run_inchi_exe): | ||
| result = run_inchi_exe(molfile) | ||
| inchi = parse_inchi_from_executable_output(result.output) | ||
|
|
||
| assert inchi == EXPECTED_INCHI |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.