Skip to content

alinemol.models

ALineMol provides two model families for the ID/OOD benchmarks: a classical machine-learning baseline and fragment-aware graph neural networks.

Classical ML baseline

CML is a light wrapper around scikit-learn's RandomForestClassifier exposing the standard estimator API. It requires no deep-learning dependencies and serves as the in-distribution reference model.

from alinemol.models.cml import CML

clf = CML()
clf.fit(X_train, y_train)
proba = clf.predict_proba(X_test)

CML

CML()

Classical machine-learning baseline classifier.

A thin wrapper around :class:sklearn.ensemble.RandomForestClassifier that exposes the standard scikit-learn estimator API (fit/predict/ predict_proba/score/get_params/set_params). It provides a simple, dependency-light baseline for molecular property classification that can be compared against the graph neural network models in :mod:alinemol.models.fragGNN.

Attributes:

Name Type Description
model

The underlying RandomForestClassifier instance (100 trees, random_state=0).

Example

from alinemol.models.cml import CML clf = CML() clf.fit(X_train, y_train) # doctest: +SKIP preds = clf.predict(X_test) # doctest: +SKIP

fit

fit(X, y)

Fit the random forest on training features and labels.

Parameters:

Name Type Description Default
X ndarray

Feature matrix of shape (n_samples, n_features).

required
y ndarray

Target labels of shape (n_samples,).

required

predict

predict(X)

Predict class labels for X.

Parameters:

Name Type Description Default
X ndarray

Feature matrix of shape (n_samples, n_features).

required

Returns:

Type Description

numpy.ndarray: Predicted class labels of shape (n_samples,).

predict_proba

predict_proba(X)

Predict class probabilities for X.

Parameters:

Name Type Description Default
X ndarray

Feature matrix of shape (n_samples, n_features).

required

Returns:

Type Description

numpy.ndarray: Array of shape (n_samples, n_classes) with

per-class probabilities.

score

score(X, y)

Return the mean accuracy on the given test data and labels.

Parameters:

Name Type Description Default
X ndarray

Feature matrix of shape (n_samples, n_features).

required
y ndarray

True labels of shape (n_samples,).

required

Returns:

Name Type Description
float

Mean accuracy in [0, 1].

get_params

get_params(deep=True)

Get parameters of the underlying estimator.

Parameters:

Name Type Description Default
deep bool

If True, return the parameters of nested sub-objects too.

True

Returns:

Name Type Description
dict

Mapping of parameter names to their values.

set_params

set_params(**params)

Set parameters of the underlying estimator.

Parameters:

Name Type Description Default
**params

Estimator parameters to set.

{}

Returns:

Name Type Description
RandomForestClassifier

The wrapped estimator with updated

parameters.

Graph neural networks

Requires the [gnn] extra

The GNN models depend on torch, torch-geometric, DGL/DGL-LifeSci, and torch-scatter. Install with pip install -e ".[gnn]" (and a matching torch-scatter wheel for your torch/CUDA build). They are described here rather than auto-documented so this documentation builds without the heavy GNN stack.

FragGNN

alinemol.models.fragGNN.FragGNN is a fragment-aware graph neural network built on GIN/GINE convolutions. It encodes atoms, bonds, and molecular fragments with dedicated encoders and exchanges information between the atom- and fragment-level representations via message passing. A smaller variant, FragGNNSmall, is available for lighter-weight experiments.

Key building blocks live in alinemol.models.layers:

Layer Role
AtomEncoder Embeds atom features
BondEncoder Embeds bond features
FragEncoder Embeds fragment-level features
InterMessage Passes messages between atom and fragment views
MLP Generic multi-layer perceptron head

See the training scripts (scripts/clf_train_gnn.py) for an end-to-end GNN training example, and the Hyperparameters reference for the search spaces used to tune them.

Source

Full model source is on GitHub.