Skip to content

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

standardize_smiles(
    x: DataFrame, taut_canonicalization: bool = True
) -> DataFrame

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 smiles column

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

drop_duplicates(x: DataFrame) -> DataFrame

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(
    x: DataFrame, taut_canonicalization: bool = True
) -> DataFrame

Standardization pipeline for a DataFrame.

This function performs the following operations on the input DataFrame
  • Standardize the 'smiles' column using the standardize_smiles function.
  • Drop conflicting duplicates using the drop_duplicates function.
  • 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

Standardizer(
    metal_disconnect: Optional[bool] = None, canon_taut: Optional[bool] = None
)

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

params property

params

Return the MolStandardize CleanupParameters.

canon_taut property

canon_taut

Return whether tautomer canonicalization will be done.

metal_disconnect property

metal_disconnect

Return whether metallorganic complexes will be disconnected.

taut_enumerator property

taut_enumerator

Return the TautomerEnumerator object.

uncharger property

uncharger

Return the Uncharger object.

lfrag_chooser property

lfrag_chooser

Return the LargestFragmentChooser object.

metal_disconnector property

metal_disconnector

Return the MetalDisconnector object.

normalizer property

normalizer

Return the Normalizer object.

reionizer property

reionizer

Return the Reionizer object.

charge_parent

charge_parent(mol_in)

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_mol(mol_in)

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.