{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Predicting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Import packages" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import torch\n", "from lightning import pytorch as pl\n", "from pathlib import Path\n", "\n", "from chemprop import data, featurizers, models" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Change model input here" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "chemprop_dir = Path.cwd().parent\n", "checkpoint_path = chemprop_dir / \"tests\" / \"data\" / \"example_model_v2_regression_mol.ckpt\" # path to the checkpoint file.\n", "# If the checkpoint file is generated using the training notebook, it will be in the `checkpoints` folder with name similar to `checkpoints/epoch=19-step=180.ckpt`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load model" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/hwpang/miniforge3/envs/chemprop_v2_dev/lib/python3.11/site-packages/lightning/pytorch/utilities/parsing.py:199: Attribute 'graph_transform' is an instance of `nn.Module` and is already saved during checkpointing. It is recommended to ignore them using `self.save_hyperparameters(ignore=['graph_transform'])`.\n", "/home/hwpang/miniforge3/envs/chemprop_v2_dev/lib/python3.11/site-packages/lightning/pytorch/utilities/parsing.py:199: Attribute 'output_transform' is an instance of `nn.Module` and is already saved during checkpointing. It is recommended to ignore them using `self.save_hyperparameters(ignore=['output_transform'])`.\n" ] }, { "data": { "text/plain": [ "MPNN(\n", " (message_passing): BondMessagePassing(\n", " (W_i): Linear(in_features=86, out_features=300, bias=False)\n", " (W_h): Linear(in_features=300, out_features=300, bias=False)\n", " (W_o): Linear(in_features=372, out_features=300, bias=True)\n", " (W_d): Linear(in_features=300, out_features=300, bias=True)\n", " (dropout): Dropout(p=0.0, inplace=False)\n", " (tau): ReLU()\n", " (V_d_transform): Identity()\n", " (graph_transform): GraphTransform(\n", " (V_transform): Identity()\n", " (E_transform): Identity()\n", " )\n", " )\n", " (agg): MeanAggregation()\n", " (bn): BatchNorm1d(300, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n", " (predictor): RegressionFFN(\n", " (ffn): MLP(\n", " (0): Sequential(\n", " (0): Linear(in_features=300, out_features=300, bias=True)\n", " )\n", " (1): Sequential(\n", " (0): ReLU()\n", " (1): Dropout(p=0.0, inplace=False)\n", " (2): Linear(in_features=300, out_features=1, bias=True)\n", " )\n", " )\n", " (criterion): MSELoss()\n", " (output_transform): UnscaleTransform()\n", " )\n", " (X_d_transform): Identity()\n", ")" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpnn = models.MPNN.load_from_checkpoint(checkpoint_path)\n", "mpnn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Change predict input here" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "chemprop_dir = Path.cwd().parent\n", "test_path = chemprop_dir / \"tests\" / \"data\" / \"regression\" / \"mol\" / \"mol.csv\"\n", "smiles_column = 'smiles'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load test smiles" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | smiles | \n", "lipo | \n", "
|---|---|---|
| 0 | \n", "Cn1c(CN2CCN(CC2)c3ccc(Cl)cc3)nc4ccccc14 | \n", "3.54 | \n", "
| 1 | \n", "COc1cc(OC)c(cc1NC(=O)CSCC(=O)O)S(=O)(=O)N2C(C)... | \n", "-1.18 | \n", "
| 2 | \n", "COC(=O)[C@@H](N1CCc2sccc2C1)c3ccccc3Cl | \n", "3.69 | \n", "
| 3 | \n", "OC[C@H](O)CN1C(=O)C(Cc2ccccc12)NC(=O)c3cc4cc(C... | \n", "3.37 | \n", "
| 4 | \n", "Cc1cccc(C[C@H](NC(=O)c2cc(nn2C)C(C)(C)C)C(=O)N... | \n", "3.10 | \n", "
| ... | \n", "... | \n", "... | \n", "
| 95 | \n", "CC(C)N(CCCNC(=O)Nc1ccc(cc1)C(C)(C)C)C[C@H]2O[C... | \n", "2.20 | \n", "
| 96 | \n", "CCN(CC)CCCCNc1ncc2CN(C(=O)N(Cc3cccc(NC(=O)C=C)... | \n", "2.04 | \n", "
| 97 | \n", "CCSc1c(Cc2ccccc2C(F)(F)F)sc3N(CC(C)C)C(=O)N(C)... | \n", "4.49 | \n", "
| 98 | \n", "COc1ccc(Cc2c(N)n[nH]c2N)cc1 | \n", "0.20 | \n", "
| 99 | \n", "CCN(CCN(C)C)S(=O)(=O)c1ccc(cc1)c2cnc(N)c(n2)C(... | \n", "2.00 | \n", "
100 rows × 2 columns
\n", "| \n", " | smiles | \n", "lipo | \n", "pred | \n", "
|---|---|---|---|
| 0 | \n", "Cn1c(CN2CCN(CC2)c3ccc(Cl)cc3)nc4ccccc14 | \n", "3.54 | \n", "2.176904 | \n", "
| 1 | \n", "COc1cc(OC)c(cc1NC(=O)CSCC(=O)O)S(=O)(=O)N2C(C)... | \n", "-1.18 | \n", "2.148450 | \n", "
| 2 | \n", "COC(=O)[C@@H](N1CCc2sccc2C1)c3ccccc3Cl | \n", "3.69 | \n", "2.159459 | \n", "
| 3 | \n", "OC[C@H](O)CN1C(=O)C(Cc2ccccc12)NC(=O)c3cc4cc(C... | \n", "3.37 | \n", "2.167359 | \n", "
| 4 | \n", "Cc1cccc(C[C@H](NC(=O)c2cc(nn2C)C(C)(C)C)C(=O)N... | \n", "3.10 | \n", "2.153605 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "
| 95 | \n", "CC(C)N(CCCNC(=O)Nc1ccc(cc1)C(C)(C)C)C[C@H]2O[C... | \n", "2.20 | \n", "2.149804 | \n", "
| 96 | \n", "CCN(CC)CCCCNc1ncc2CN(C(=O)N(Cc3cccc(NC(=O)C=C)... | \n", "2.04 | \n", "2.153695 | \n", "
| 97 | \n", "CCSc1c(Cc2ccccc2C(F)(F)F)sc3N(CC(C)C)C(=O)N(C)... | \n", "4.49 | \n", "2.158461 | \n", "
| 98 | \n", "COc1ccc(Cc2c(N)n[nH]c2N)cc1 | \n", "0.20 | \n", "2.175282 | \n", "
| 99 | \n", "CCN(CCN(C)C)S(=O)(=O)c1ccc(cc1)c2cnc(N)c(n2)C(... | \n", "2.00 | \n", "2.159477 | \n", "
100 rows × 3 columns
\n", "