Standardize¶
molfp.standardize
¶
Structure normalization: standardize molecules before fingerprint computation.
Provides a pipeline for cleaning, desalting, normalizing, and deduplicating molecules — critical preprocessing before fingerprint calculation to ensure consistent and reproducible results.
Pipeline (following Greg Landrum's RSC OpenScience protocol): 1. Parse SMILES → RDKit Mol 2. Cleanup: remove Hs, disconnect metals, normalize, reionize 3. Desalt: keep largest fragment (FragmentParent) 4. Neutralize: remove charges where possible (Uncharger) 5. Canonicalize tautomer: pick a single canonical tautomer form 6. Canonical SMILES: generate standardized SMILES string 7. InChIKey: compute for deduplication
standardize_mol(smiles_or_mol)
¶
Full standardization pipeline. Returns standardized RDKit Mol or None.
Steps: parse → cleanup → desalt → neutralize → canonical tautomer.
smiles_to_mol(input_data, *, column=None, standardize=False)
¶
Convert SMILES to RDKit Mol objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
SMILES string, list of SMILES, pd.Series, or pd.DataFrame |
required | |
column
|
DataFrame column name (auto-detected if None) |
None
|
|
standardize
|
if True, apply full standardization pipeline |
False
|
Returns:
| Type | Description |
|---|---|
|
Single Mol (for string input) or list[Mol|None] (for batch input). |
|
|
Returns None for invalid SMILES. |
mol_to_smiles(input_data, *, column=None, canonical=True)
¶
Convert RDKit Mol objects (or SMILES) to canonical SMILES strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Mol, SMILES string, list, pd.Series, or pd.DataFrame |
required | |
column
|
DataFrame column name (auto-detected if None) |
None
|
|
canonical
|
if True (default), return canonical SMILES |
True
|
Returns:
| Type | Description |
|---|---|
|
Single SMILES string (for single input) or list[str|None] (for batch). |
standardize_smiles(smiles)
¶
Standardize a SMILES string. Returns canonical SMILES or None.
get_inchikey(smiles_or_mol)
¶
Compute InChIKey for a molecule (after standardization).
desalt(smiles_or_mol)
¶
Remove salts/counterions, keep the largest fragment.
neutralize(smiles_or_mol)
¶
Remove charges where chemically reasonable.
canonicalize_tautomer(smiles_or_mol)
¶
Pick the canonical tautomer form.
standardize_batch(smiles_list, return_failures=False)
¶
Standardize a list of SMILES. Returns list of canonical SMILES.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smiles_list
|
list[str]
|
list of SMILES strings |
required |
return_failures
|
bool
|
if True, return (results, failures) tuple |
False
|
Returns:
| Type | Description |
|---|---|
list[str | None] | tuple[list[str | None], list[tuple[int, str]]]
|
list of standardized SMILES (None for failures) |
list[str | None] | tuple[list[str | None], list[tuple[int, str]]]
|
if return_failures: (results, [(idx, original_smiles), ...]) |
deduplicate(smiles_list, method='inchikey')
¶
Deduplicate molecules using InChIKey or canonical SMILES.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smiles_list
|
list[str]
|
list of SMILES strings |
required |
method
|
str
|
"inchikey" (default, handles tautomers/salts) or "canonical" |
'inchikey'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict with: unique_smiles: list of unique standardized SMILES unique_indices: indices of first occurrence duplicates: list of (idx, original_smiles, duplicate_of_idx) mapping: {original_idx: unique_idx} n_input: total input n_unique: unique count n_duplicates: duplicate count n_failed: failed to parse |
preprocess(smiles_list, deduplicate_method='inchikey')
¶
Full preprocessing pipeline: standardize + deduplicate.
Convenience function combining standardize_batch and deduplicate.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict with: clean_smiles: list of unique standardized SMILES clean_mols: list of RDKit Mol objects (ready for FP computation) dedup_result: full deduplication result dict standardization_failures: [(idx, smiles), ...] |