chemaxon.structurechecker

This package contains functions for structure checking of molecules, and fixers.

GitHub examples: https://github.com/ChemAxon/python-examples/blob/main/jupyter/05_structure_checker.ipynb

class StructureChecker:

Chemical structure checker. It has method for both detecting various structural issues, or even fix them with the fix method.

More info about structure checkers: https://docs.chemaxon.com/display/docs/structure-checker_index.html

Example:

 structurechecker = StructureChecker("aromaticityerror:type=basic")

 structurechecker = StructureChecker(["wedgeerror", "valenceerror"])

 with open("config.xml") as f:
     structurechecker = StructureChecker(f)
StructureChecker(config: str | list[str] | io.IOBase)
config: str

Configuration parameter in any of the following formats:

  • xml string
  • action string
  • list of action strings
  • file object of the configuration file.
@typecheck(Molecule, bool)
def check( self, mol: chemaxon.Molecule, return_colored_mol: bool = True) -> StructureCheckerBatchResult:

Molecule structure checking.

Parameters
  • mol: The molecule to be checked.
  • return_colored_mol: Whether to return a colored molecule showing the errors. Default is True.
Raises
  • RuntimeError: If the molecule contains more than 500 atoms / bonds.
Returns

StructureCheckerBatchResult - Structure checking batch result.

@typecheck(Molecule)
def fix( self, mol: chemaxon.Molecule) -> StructureFixerResult:

Fixes the given structure based on the config provided during StructureChecker construction.

Parameters
Returns

StructureFixerResult object containing the fixed molecule and a flag showing if the fix was successful. If fix was unsuccessful it returns the original mol.

@dataclass(frozen=True)
class StructureCheckerBatchResult:

Contains a list of StructureChecker.check method results and an aggregated colored molecule showing all errors as union.

StructureCheckerBatchResult( results: list[StructureCheckerResult], aggregated_colored_mol: chemaxon.Molecule | None)
results: list[StructureCheckerResult]

list of StructureCheckerResults

aggregated_colored_mol: chemaxon.Molecule | None

colored molecule showing all errors as union, None if return_colored_mol is False or no errors found

def is_error_free(self) -> bool:

Returns whether there is no error detected in the molecule.

@dataclass(frozen=True)
class StructureCheckerResult:

The result of the StructureChecker.check method. Contains information of the discovered issues.

StructureCheckerResult( description: str, checker_name: str, colored_mol: chemaxon.Molecule | None, atom_indices: list[int], bond_indices: list[int], sgroup_indices: list[int], rgroup_ids: list[int])
description: str

Description of the found error

checker_name: str

name of the checker reporting the error

colored_mol: chemaxon.Molecule | None

colored molecule showing the errors, None if return_colored_mol is False

atom_indices: list[int]

list of atom indices with errors

bond_indices: list[int]

list of bond indices with errors

sgroup_indices: list[int]

list of S-group indices with errors

rgroup_ids: list[int]

list of R-group ids with errors

@dataclass(frozen=True)
class StructureFixerResult:

The result of the StructureChecker.fix method. It contains the fixed molecule and a flag indicating whether the fix was successful.

StructureFixerResult(fixed_mol: chemaxon.Molecule, is_fix_successful: bool)
fixed_mol: chemaxon.Molecule

fixed molecule or the original if fix was not successful

is_fix_successful: bool

whether the fixing was successful