chemaxon.search

This package contains functions for chemical searches with molecules.

GitHub examples: https://github.com/ChemAxon/python-examples/blob/main/jupyter/06_molecule_search.ipynb

@dataclass()
class MoleculeSearch:

Search object to perform molecule searches

@typecheck(SearchType, (str, Standardizer, None))
MoleculeSearch( search_type=<SearchType.SUBSTRUCTURE: 2>, standardizer: str | chemaxon.standardizer.Standardizer = 'aromatize:g')
search_type: SearchType

The type of search to be performed. Default is SearchType.SUBSTRUCTURE

The configuration string of the standardizer to be applied before the search, or the chemaxon.standardizer.standardizer.Standardizer object. Default is general aromatization, if None or empty string is provided, no standardization will be applied

@typecheck(Molecule, Molecule, bool)
def find( self, query: chemaxon.Molecule, target: chemaxon.Molecule, return_colored_hit=False) -> SearchHit | None:

Molecule searching. Returns the first hit in the target chemaxon.Molecule.

Parameters
Returns

SearchHit, or None if there was no match.

@typecheck(Molecule, list, bool)
def find_in_list( self, query: chemaxon.Molecule, target_list: list[chemaxon.Molecule], return_colored_hit: bool = False) -> list[SearchHit | None]:

Molecule searching in list. Returns the first hit in the chemaxon.Molecule for each target.

Get a list of SearchHits or None.

Parameters
Raises
  • RuntimeError: In case of exception (unrecoverable errors) the function will exit and stop the searching.
Returns

list[SearchHit | None] - List of SearchHit objects in the same order as the input list of targets (target_mol_list). If no hit was found on a given target, None is returned on the corresponding index.

@typecheck(Molecule, Molecule, bool, int)
def find_all( self, query: chemaxon.Molecule, target: chemaxon.Molecule, return_colored_hit: bool = False, limit: int = 10000) -> list[SearchHit]:

Molecule searching. Returns all hits of the query in the target chemaxon.Molecule.

Every distinct mapping of the query onto the target (including symmetry-equivalent ones) is returned as a separate SearchHit.

Parameters
  • query: chemaxon.Molecule - The chemaxon.Molecule to match
  • target: chemaxon.Molecule - The target chemaxon.Molecule to which the query is being matched
  • return_colored_hit: bool - If True, each hit carries a colored target showing the matched atoms and bonds. Default is False.
  • limit: int - The maximum number of hits to collect. The search stops once this many hits are found, or there are no more hits, so the result never exceeds limit (it is truncated in match order for targets with more matches). Must be at least 1. Default is DEFAULT_FIND_ALL_LIMIT.
Raises
  • ValueError: If limit is less than 1.
Returns

list[SearchHit] - One SearchHit per match, at most limit of them. An empty list if there was no match.

class SearchType(enum.Enum):

Supported molecule search types

SUBSTRUCTURE = <SearchType.SUBSTRUCTURE: 2>

Substructure search that applies both screening and atom-by-atom search. This is the default search type.

DUPLICATE = <SearchType.DUPLICATE: 5>

Duplicate search (formerly called perfect)

@dataclass(frozen=True)
class SearchHit:

Search hit result object

SearchHit( hit_indices: list[int], colored_hit: chemaxon.Molecule | None = None)
hit_indices: list[int]

List of atom indices in the target molecule that were matched by the query molecule. The index of the i-th atom (in the list) is the index of the target atom matched against the ith atom in the query molecule. None if there was no match

colored_hit: chemaxon.Molecule | None = None

Colored target molecule showing the matched atoms and bonds. None if return_colored_hit was False

DEFAULT_FIND_ALL_LIMIT = 10000