alinemol.preprocessing¶
Utilities for cleaning and standardizing molecular datasets before splitting or model training. The public entry points wrap RDKit-based normalization so that duplicate, malformed, or non-canonical SMILES do not leak noise into your splits.
from alinemol.preprocessing import standardization_pipeline
clean_df = standardization_pipeline(raw_df) # canonicalize + de-duplicate
Pipeline functions¶
standardize_smiles
¶
Standardization of a SMILES string.
Uses the Standardizer to perform sequence of cleaning operations on a SMILES string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
DataFrame
|
pd.DataFrame with |
required |
taut_canonicalization
|
bool
|
whether or not to use tautomer canonicalization |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame with 'canonical_smiles', 'molecular_weight', and 'num_atoms' additional columns |
drop_duplicates
¶
Remove conflicting duplicates from a DataFrame.
This function processes the DataFrame to
- Drop rows where the 'canonical_smiles' values are the same but the labels differ (conflicting rows).
- Retain only one row for each set of identical 'canonical_smiles' values with the same label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
DataFrame
|
The input DataFrame containing a 'canonical_smiles' column. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with conflicting duplicates removed, ensuring unique rows. |
standardization_pipeline
¶
Standardization pipeline for a DataFrame.
This function performs the following operations on the input DataFrame
- Standardize the 'smiles' column using the
standardize_smilesfunction. - Drop conflicting duplicates using the
drop_duplicatesfunction. - Return a DataFrame with 'smiles' and 'label' columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
DataFrame
|
The input DataFrame containing a 'smiles' column. |
required |
taut_canonicalization
|
bool
|
Whether or not to use tautomer canonicalization. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A DataFrame with standardized 'canonical_smiles' values and conflicting duplicates removed. |
Note
The input DataFrame must contain a 'smiles' and label column.
Output DataFrame will contain 'smiles' and label columns.
Standardizer¶
The Standardizer class implements the underlying normalization steps
(sanitization, salt/solvent stripping, tautomer canonicalization).
Standardizer
¶
Bases: BaseLogger
Simple wrapper class around rdkit Standardizer.
Constructor.
All parameters are optional. Arges: metal_disconnect: if True, metallorganic complexes are disconnected canon_taut:if True, molecules are converted to their canonical tautomer
metal_disconnect
property
¶
Return whether metallorganic complexes will be disconnected.
charge_parent
¶
Sequentially apply a series of MolStandardize operations:
- MetalDisconnector
- Normalizer
- Reionizer
- LargestFragmentChooser
- Uncharger
The net result is that a desalted, normalized, neutral molecule with implicit Hs is returned.
standardize_mol
¶
Standardize a single molecule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mol_in
|
a Chem.Mol |
required |
Returns: (standardized Chem.Mol, n_taut) tuple if success. n_taut will be negative if tautomer enumeration was aborted due to reaching a limit * (None, error_msg) if failure
This calls self.charge_parent() and, if self._canon_taut is True, runs tautomer canonicalization.