---
name: smartclass
description: >
  Classify chemical structures using SMARTS patterns against Wikidata-sourced chemical classes. Use when writing Python code that uses the smartclass package.
license: MIT
compatibility: Requires Python >=3.12.
---

# smartclass

Classify chemical structures using SMARTS patterns against Wikidata-sourced chemical classes

## Installation

```bash
pip install smartclass
```

## API overview

### Classes

Main classes provided by the package

- `exceptions.ChemicalConversionError`
- `exceptions.ClassificationError`
- `exceptions.ConfigurationError`
- `exceptions.DataExportError`
- `exceptions.DataLoadingError`
- `exceptions.InChIError`
- `exceptions.InvalidInputError`
- `exceptions.MoleculeParsingError`
- `exceptions.NetworkError`
- `exceptions.SMARTSError`
- `exceptions.SMILESError`

### Exceptions

Exception classes

- `SmartclassError`: Base exception for all smartclass errors

### Functions

Utility functions

- `bfs_search_classes_generator.tqdm_bfs_search_classes_generator`
- `calculate_mcs`: Calculate Maximum Common Substructure (MCS) for a list of molecules
- `check_missing_stereochemistry`: Check stereochemistry
- `check_smiles_contains_no_dot`: Checks if SMILES contains no dot
- `check_smiles_contains_no_isotope`: Checks if SMILES contains no isotope
- `check_smiles_isomeric`: Check isomeric smiles
- `combine_csv_files`: Combine multiple CSV files into a single CSV file
- `configure_logging`: Configure logging for the smartclass package
- `convert_chemical_formula`: Convert chemical formula
- `convert_classyfire_dict`: Converts the classyfire json into a CHEMONTID dictionary
- `convert_inchi_to_inchikey`: Convert a structure InChI to InChIKey
- `convert_inchi_to_mass`: Convert a structure InChI to mass
- `convert_inchi_to_mol`: Convert a structure InChI to MOL
- `convert_inchi_to_smiles`: Convert a structure InChI to SMILES
- `convert_list_of_dict`: Convert a list of dictionaries to a dictionary with possible inversion
- `convert_mol_to_cxsmiles`: Convert a structure MOL to CXSMILES
- `convert_mol_to_inchi`: Convert a structure MOL to InChI
- `convert_mol_to_inchikey`: Convert an RDKit Mol object to an InChIKey
- `convert_mol_to_smarts`: Convert a structure MOL to SMARTS
- `convert_mol_to_smiles`: Convert a structure MOL to SMILES
- `convert_molblock_to_mol`: Convert a structure MOLBlock to MOL
- `convert_smarts_to_mol`: Convert a structure SMARTS to MOL
- `convert_smiles_to_canonical_smiles`: Convert a structure SMILES to canonical SMILES
- `convert_smiles_to_formula`: Convert a structure SMILES to a molecular formula
- `convert_smiles_to_inchi`: Convert a structure SMILES to InChI
- `convert_smiles_to_mass`: Convert a structure SMILES to an exact mass
- `convert_smiles_to_mol`: Convert a SMILES string to an RDKit Mol object
- `download_file_if_not_exists`: Downloads a file from the specified URL if it does not exist
- `enumerate_structures`: Enumerate structural variants of a molecule
- `export_dict_to_json`: Export dict to json
- `export_results`: Export a list of dictionaries to a CSV or TSV file
- `fix_inchi_tautomerization`: Fix InChI tautomerization
- `get_config`: Get the global configuration instance
- `get_logger`: Get a logger for the given module name
- `get_num_atoms_bonds`: Get number of atoms and bonds
- `get_num_matched_atoms_bonds`: Get number of matched atoms and bonds
- `get_request`: Send a GET request to a SPARQL endpoint and retrieve JSON data
- `load_csv_from_path`: Load csv from path
- `load_external_classes_file`: Load a Polars DataFrame from an external tsv file with chemical classes
- `load_json_from_path`: Load json from path
- `load_json_from_url`: Load JSON from URL
- `load_json_from_url_or_path`: Load json from URL or path
- `load_pkg_bitter_smiles`: Load bitter SMILES data from the package file into a Polars DataFrame
- `load_pkg_chemical_hierarchy`: Load chemical class hierarchy from a TSV file
- `load_pkg_classes`: Load chemical classes data from the package file into a Polars DataFrame
- `load_pkg_data`: Load the package data
- `load_pkg_file`: Load data from a package-bundled file into a Polars DataFrame
- `load_pkg_mappings`: Load chemont__wd mappings data from the package file into a Polars DataFrame
- `load_pkg_mia`: Load Mono Indole Alkaloids (MIA) data from the package file into a Polars DataFrame
- `load_smiles`: Load unique SMILES strings from a CSV or TSV file
- `load_tsv_from_path`: Load tsv from path
- `read_query`: Read a SPARQL query from a file path or URL
- `resources.extract_chebi`
- `resources.get_chebi`
- `sample_list`: Randomly sample items from a list
- `search_class.build_filter_catalog`
- `search_classes.tqdm_bfs_search_classes_generator`
- `split_csv`: Split a CSV file into multiple smaller CSV files
- `standardize`: Standardize

### Constants

Module-level constants and data

- `bfs_search_classes_generator.ClassDict`
- `bfs_search_classes_generator.ClassHierarchy`
- `bfs_search_classes_generator.MatchResult`
- `bfs_search_classes_generator.c`
- `bfs_search_classes_generator.class_hierarchy`
- `bfs_search_classes_generator.classes`
- `bfs_search_classes_generator.logger`
- `bfs_search_classes_generator.params`
- `bfs_search_classes_generator.results_bfs`
- `bfs_search_classes_generator.structures`
- `search_class.logger`
- `search_classes.RESULT_FIELDS`
- `search_classes.logger`

### Other

Additional exports

- `api`: SMARTCLASS API TODO
- `chebi`: Smartclass classifies structures using SMARTS.resources.chebi
- `chem`: Smartclass classifies structures using SMARTS.chem
- `chembl`: Smartclass classifies structures using SMARTS.resources.chembl
- `chemont`: Smartclass classifies structures using SMARTS.resources.chemont
- `examples`
- `get_class_structures`: Build a mapping from class IDs to their SMARTS structures
- `io`: Smartclass classifies structures using SMARTS.io
- `schema`
- `testing`
- `wikidata`: Smartclass classifies structures using SMARTS.resources.wikidata

## Resources

- [llms.txt](llms.txt) — Indexed API reference for LLMs
- [llms-full.txt](llms-full.txt) — Comprehensive documentation for LLMs
