Skip to content

1-methylthiophene silently accepted as neutral trivalent sulfur: discontinuous valency sets are never enforced #323

Open

Description

@guillaume-osmo

OPSIN accepts a neutral sulfur with three bonds, silently.

$ java -jar opsin-cli-2.9.0-jar-with-dependencies.jar -o smi -n
1-methylthiophene        CS1C=CC=C1              accepted
1-methylfuran            <rejected>              "Atom is in unphysical valency state! Element: O valency: 3"
1-methylthiophen-1-ium   C[S+]1C=CC=C1           the structure that name actually denotes
1-methylselenophene      C[SeH]1C=CC=C1          accepted, and OPSIN invents a hydrogen

CS1C=CC=C1 is impossible without a positive charge. The oxygen analogue is correctly rejected; sulfur is not, and no warning is produced.

Cause

ValencyChecker.getMaximumValency returns only the last entry of possibleStableValencies, and checkValency tests only valency <= maximum. Neutral S is registered {2,4,6}, so valency 3 passes on 3 <= 6. Neutral O is {2}, so 3 correctly fails. Every element with a discontinuous allowed-valency set is unchecked at its intermediate valencies.

Scale and, importantly, the direction of the trade

This one is different from the other issues I have filed. Those all turned rejections into correct structures. This one turns silently wrong structures into rejections, so it is a recall loss — worth stating plainly so it can be weighed rather than discovered.

Over all 112,629,018 single-component names in PubChem's CID-IUPAC dump, with the check tightened:

silently wrong structures that become honest rejections 12,315
names that were CORRECT and become rejected 0
structures changed anywhere in the corpus 0

Every newly rejected name was adjudicated against PubChem's own key rather than sampled: across 1.4M names spanning three differentials (a general 500,000; a 500,000 enriched for at-risk element tokens; a 400,000 restricted to lambda-convention names, where an intermediate valency is legitimate), 274 unique names become rejected and master was wrong on all 274.

Suggested fix, and the two things that do not work

Exact set membership is wrong. Valency at check time counts bonds to heavy atoms only, and Atom.determineValency then fills the shortfall with implicit hydrogen, so exact membership rejects methylphosphane (P valency 1, not in {3,5}).

The real rule is narrower: implicit hydrogen may bring an atom up to its standard bonding number, but should not push it into a hypervalent state. A hypervalent chalcogen or halogen is made hypervalent by bonds to other elements, never by a hydrogen.

Group 15 must be excluded. R2P(=O)H and relatives are conventional, so phosphorus does legitimately reach a hypervalent state with an implicit hydrogen — including it rejects 2-oxo-1,3-dihydroisophosphindole, which master gets exactly right.

Charged atoms, lambda-convention atoms and atoms with an explicitly set valency all state their valency rather than infer it, so should be exempt. 1lambda4-thiophene is the correct spelling for the sulfur case and continues to parse.

PR to follow. Suite green, and every control — sulfoxide, sulfone, sulfonic acid, thiophene 1,1-dioxide, tetrahydrothiophene, the lambda spelling — is unchanged.

Tested with OPSIN 2.9.0 and current master, JDK 26 on macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions