orthonym.validation.dual_validator#
Note
Internal API. Names and behaviour may change between releases.
Combined OPSIN + PubChem validation logic.
Strategy: Try OPSIN first (fast, local). If OPSIN cannot parse the name, fall back to PubChem PUG-REST API lookup. A compound passes round-trip validation if EITHER validator produces an InChI match with the original molecule.
This dual approach recovers RT credit for correct names that OPSIN’s parser cannot handle (e.g., complex decomposition names, unusual substituent patterns).
- class orthonym.validation.dual_validator.DualResult(opsin_parsed=False, opsin_rt=False, pubchem_resolved=False, pubchem_rt=False, combined_rt=False, opsin_smiles=None, pubchem_inchi=None)#
Bases:
objectResult of dual OPSIN+PubChem validation for a single compound.
- opsin_parsed: bool = False#
- opsin_rt: bool = False#
- pubchem_resolved: bool = False#
- pubchem_rt: bool = False#
- combined_rt: bool = False#
- opsin_smiles: str | None = None#
- pubchem_inchi: str | None = None#
- orthonym.validation.dual_validator.validate_compound(smiles, name, opsin_jar=None, pubchem_cache=None, skip_pubchem_api=False)#
Validate a generated IUPAC name using OPSIN (primary) and PubChem (fallback).
Strategy: 1. Compute InChI of the original SMILES. 2. Try OPSIN parse-back: parse name -> compute InChI -> compare. 3. If OPSIN fails to parse, try PubChem lookup: get InChI -> compare. 4. combined_rt = opsin_rt OR pubchem_rt.
- Parameters:
smiles (str) – Original SMILES string.
name (str) – Generated IUPAC name to validate.
opsin_jar (str | None) – Path to OPSIN JAR file (auto-detected if None).
pubchem_cache (dict | None) – Mutable dict used as PubChem lookup cache.
skip_pubchem_api (bool) – If True, use only cached PubChem results.
- Returns:
DualResult with all validation fields populated.
- Return type:
- orthonym.validation.dual_validator.validate_batch(compounds, opsin_jar=None, pubchem_cache=None, skip_pubchem_api=False)#
Validate a batch of compounds using batch OPSIN parsing for efficiency.
- Parameters:
compounds (List[Tuple[str, str]]) – List of (smiles, name) tuples.
opsin_jar (str | None) – Path to OPSIN JAR file.
pubchem_cache (dict | None) – Mutable dict for PubChem cache.
skip_pubchem_api (bool) – If True, skip PubChem API calls.
- Returns:
List of DualResult, one per compound in same order.
- Return type:
List[DualResult]