This weblog put up will information you thru utilizing sk-chem
, a python library that gives a scikit-learn interface for cheminformatics duties. We’ll use sk-chem
to construct a machine studying mannequin that predicts the solubility of small molecules.
sk-chem
is a python library that simplifies working with chemical knowledge inside the acquainted scikit-learn framework. It affords instruments for:
- Molecule Standardization: Making ready molecules for additional processing (e.g., eradicating salts)
- Molecule Transformation: Changing molecules into codecs usable by machine studying fashions
- Function Technology: Extracting related info (fingerprints, descriptors) from molecules
- Drive Area Optimization: Minimizing the power of a molecule
Set up is easy utilizing pip:
pip set up git+https://github.com/pnhuy/sk-chem
This instance demonstrates the best way to use sk-chem
to foretell the solubility of small molecules utilizing a machine studying mannequin. We’ll use the Delaney dataset, a widely known benchmark for this process.
Import Libraries and Load Information:
We’ll import essential libraries like pandas, scikit-learn modules, and parts from sk-chem
. The script then downloads the Delaney dataset and splits it into options (SMILES strings) and goal variable (predicted log solubility).
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.impute import SimpleImputer
from sklearn.preprocessing import StandardScaler
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import GridSearchCVfrom sk_chem.options.fingerprint_features import AtomPairCountFingerprint, MorganFingerprint, RdkitFingerprint, TopologicalTorsionFingerprint
from sk_chem.options.rdkit_features import RdkitFeaturizer
from sk_chem.options.mordred_features import ModredFeaturizer
from sk_chem.forcefields.mmff import MMFF
from sk_chem.forcefields.uff import UFF
from sk_chem.molecules.rdkit_mol import RdkitMoleculeTransformer
from sk_chem.standardizers.rdkit_standardizer import RdkitMolStandardizer
DATA_URL = "https://uncooked.githubusercontent.com/deepchem/deepchem/grasp/datasets/delaney-processed.csv"
df = pd.read_csv(DATA_URL)
X = df['smiles']
y = df['ESOL predicted log solubility in mols per litre']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Function Engineering:
sk-chem
affords varied methods to symbolize molecules as options for machine studying fashions. This instance makes use of a pipeline to discover totally different featurizers:
- RdkitFeaturizer: Generates options primarily based on the RDKit cheminformatics toolkit.
- ModredFeaturizer: Computes a variety of molecular descriptors utilizing the Mordred library.
- Fingerprint Options: These options seize the molecular construction primarily based on totally different fingerprints like AtomPairCount, RdkitFingerprint, MorganFingerprint, and TopologicalTorsionFingerprint.
The script makes use of a GridSearchCV object to discover totally different featurizers together with pressure area optimizers (MMFF and UFF) to seek out one of the best mixture for our mannequin.
params_grid = {
'featurizer': [
RdkitFeaturizer(),
ModredFeaturizer(),
AtomPairCountFingerprint(),
RdkitFingerprint(),
MorganFingerprint(),
TopologicalTorsionFingerprint(),
],
'forcefield_optimizer': [
MMFF(),
UFF(),
]
}
Machine Studying Mannequin Coaching:
The pipeline additionally contains preprocessing steps like standardization and imputation to deal with lacking values. Lastly, a Random Forest Regressor mannequin is used to foretell solubility.
pipeline = Pipeline([
('molecule_standardizer', RdkitMolStandardizer()),
('molecule_transformer', RdkitMoleculeTransformer()),
('forcefield_optimizer', MMFF()),
('featurizer', RdkitFeaturizer()),
('imputer', SimpleImputer(strategy='constant', fill_value=-1)),
('scaler', StandardScaler()),
('model', RandomForestRegressor(random_state=42)),
])
Mannequin Analysis:
The script performs a grid search to establish one of the best hyperparameter mixture for the pipeline. It then evaluates the mannequin’s efficiency on the take a look at set utilizing the imply squared error (MSE) metric.
grid_search = GridSearchCV(pipeline, params_grid, cv=5, n_jobs=-1, verbose=1)
grid_search = grid_search.match(X_train, y_train)finest = grid_search.best_estimator_
y_pred = finest.predict(X_test)
train_mse = mean_squared_error(y_train, finest.predict(X_train))
test_mse = mean_squared_error(y_test, y_pred)
print("Finest Parameters: ", grid_search.best_params_)
print(f"Prepare MSE: {train_mse}")
print(f"Check MSE: {test_mse}")
Notice: It is a fundamental instance. Actual-world cheminformatics duties would possibly contain extra advanced mannequin architectures and hyperparameter tuning methods.
sk-chem
offers a handy option to combine cheminformatics duties into scikit-learn workflows. This weblog put up supplied a glimpse into its functionalities by constructing a mannequin for predicting molecular solubility. With sk-chem
, you may discover varied options, pressure fields, and machine studying fashions to deal with various cheminformatics issues.