Tutorial 1

Molecular Representations

Build, visualize, and compare five molecule-to-vector representations — physicochemical descriptors, Morgan fingerprints, an xtb solvation-energy descriptor, a ChemBERTa foundation-model embedding, and molecular graphs — using the ESOL solubility dataset.

Jules Schleinitz
90 min
Python · Google Colab
Back to schedule

Open in Google Colab

The notebook has most of the code pre-filled. Complete the exercises marked Exercise or your code here as you go.

Open Notebook

Getting started

Open the Colab notebook using the button above. The notebook is structured into clearly labelled sections. Run each cell in order; cells marked Exercise require you to fill in code. Stuck on one? The solutions notebook (see Resources below) has a worked example for every exercise.

  1. RDKit setup. Load the ESOL dataset and get comfortable with RDKit's Mol objects, drawing, and the Descriptors module.

  2. Dimensionality reduction. Build the reusable plot_chemical_space/evaluate_representation_knn toolkit, and see why standardization, correlated-feature removal, and the choice of PCA vs. t-SNE vs. UMAP all change what the resulting 2D map looks like.

  3. Data visualization example. Run the toolkit end-to-end on a trivial representation to confirm the pipeline works.

  4. Build your own representation. Hypothesize which molecular properties drive solubility, implement compute_custom_features, and see how it scores.

  5. Compare with an expert-defined representation. Build RDKit's physicochemical descriptors (plus charge/pKa) and compare against your own.

  6. Morgan fingerprints. Compute ECFP4 fingerprints, see how sparse they are, and remove zero-variance bits before visualizing.

  7. Featurize with xtb. Run a real gas-phase-vs-solvation single-point calculation live on 20 molecules, then switch to a precomputed CSV for the full dataset.

  8. Featurize with ChemBERTa. Extract a frozen embedding per molecule from a pretrained foundation model and visualize its chemical space.

  9. Graph definition. Implement bond-type edge features, compare two molecules' graph sizes directly, and see why pooling is needed before a graph can be visualized like every other representation.


Answer these questions as you work through the notebook. Discuss with your neighbour — some have no single right answer.

    Warm-up

    Are the descriptors standardized before PCA is run today? How many descriptors does it take before standardization visibly changes what PC1 is made of?

    Easy
    Core

    What fraction of the 2048 Morgan fingerprint bits are zero-variance on this ~1128-molecule dataset?

    Easy
    Core

    Compare PCA, t-SNE, and UMAP on the same descriptor block — which shows the clearest logS-correlated structure? How does removing correlated features change what PC1 is made of?

    Medium
    Core

    Rank every representation you build (your own, the expert descriptors, fingerprints, xtb, ChemBERTa, mean-pooled graph) by evaluate_representation_knn RMSE. Does the ranking match your visual impression from the Bokeh plots?

    Medium
    Challenge

    Does adding the xtb solvation descriptor or the ChemBERTa embedding improve evaluate_representation_knn RMSE over the expert descriptor set alone? What about all of them concatenated together?

    Challenge
    Challenge

    Why can't a molecular graph be fed directly into plot_chemical_space, and what does mean-pooling the atom features fix?

    Challenge

Notebook (Colab) Solutions notebook (Colab) GitHub repo Paired lecture notes Datamol — molecular featurization library DescriPyTor — interpretable QM descriptors from Gaussian/xTB/ORCA outputs AQME — conformer generation and xTB/DFT/RDKit descriptor workflows Chemetrian — web platform for DFT and cheminformatics descriptors