Skip to content

Commit bf67a67

Browse files
committed
Fix issue-driven docs and notebook inference flows
1 parent 46e919c commit bf67a67

4 files changed

Lines changed: 1791 additions & 2209 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ pip install -e .
9797
conda install -c kimlab stride
9898
```
9999

100+
Use the explicit `-c kimlab` form above. The `kimlab::stride` shorthand can fail on some conda setups.
101+
100102
### 🐳 Docker
101103

102104
A `Dockerfile` is included for containerized usage (PyTorch 2.4, CUDA 12.4, Python 3.12.4 via Mambaforge).

batch_demo.ipynb

Lines changed: 59 additions & 1 deletion
Large diffs are not rendered by default.

colab_demo.ipynb

Lines changed: 1673 additions & 2207 deletions
Large diffs are not rendered by default.

single_demo.ipynb

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,57 @@
1-
{"cells":[{"cell_type":"markdown","id":"49b08bbc-db31-4aa4-89b4-2313c0030642","metadata":{},"source":"## Define inputs"},{"cell_type":"code","execution_count":11,"id":"3c1841bb-8c35-4562-b86f-30777bb299bb","metadata":{},"outputs":[],"source":"parameter = 'Km' # allowed values: [\"kcat\", \"Km\", \"Ki\"] \nparameter = parameter.lower()\n\nuse_cpu = 1 # set to 0 if you have GPU enabled\n\nuniprot_id = \"P35557\" \n# If you do not have a uniprot-id, enter some name (for eg: \"enzyme1\")\nsequence = 'MLDDRARMEAAKKEKVEQILAEFQLQEEDLKKVMRRMQKEMDRGLRLETHEEASVKMLPTYVRSTPEGSEVGDFLSLDLGGTNFRVMLVKVGEGEEGQWSVKTKHQMYSIPEDAMTGTAEMLFDYISECISDFLDKHQMKHKKLPLGFTFSFPVRHEDIDKGILLNWTKGFKASGAEGNNVVGLLRDAIKRRGDFEMDVVAMVNDTVATMISCYYEDHQCEVGMIVGTGCNACYMEEMQNVELVEGDEGRMCVNTEWGAFGDSGELDEFLLEYDRLVDESSANPGQQLYEKLIGGKYMGELVRLVLLRLVDENLLFHGEASEQLRTRGAFETRFVSQVESDTGDRKQIYNILSTLGLRPSTTDCDIVRRACESVSTRAAHMCSAGLAGVINRMRESRSEDVMRITVGVDGSVYKLHPSFKERFHASVRRLTPSCEITFIESEEGSGRGAALVSAVACKKACMLGQ'\nSMILES = \"C([C@@H]1[C@H]([C@@H]([C@H](C(O1)O)O)O)O)O\" "},{"cell_type":"markdown","id":"db40ad26-0481-405b-8323-70d23f0ef44e","metadata":{},"source":"## Navigate to below cell and click \"Run->Run Selected Cell\" to get prediction"},{"cell_type":"markdown","id":"81de60cf-39b5-4546-83da-497c15e01b59","metadata":{},"source":"The result will be printed on the right column"},{"cell_type":"code","execution_count":16,"id":"be6cfa1f-9724-44ad-8ff9-ba8dcd51b887","metadata":{"jupyter":{"source_hidden":true}},"outputs":[{"name":"stdout","output_type":"stream","text":["Input success!\n","Enzyme sequence length: 465\n","Substrate structure:\n","Predicting.. This will take a while..\n","\n"]},{"data":{"text/latex":["$\\displaystyle K_{m} = 5.57977 mM$"],"text/plain":["<IPython.core.display.Math object>"]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["\n","\n"]},{"data":{"text/latex":["$\\displaystyle log_{10}(K_{m}) = 0.74662$"],"text/plain":["<IPython.core.display.Math object>"]},"metadata":{},"output_type":"display_data"},{"data":{"text/latex":["$\\displaystyle SD_{total} = 0.69207$"],"text/plain":["<IPython.core.display.Math object>"]},"metadata":{},"output_type":"display_data"},{"data":{"text/latex":["$\\displaystyle SD_{aleatoric} = 0.64138$"],"text/plain":["<IPython.core.display.Math object>"]},"metadata":{},"output_type":"display_data"},{"data":{"text/latex":["$\\displaystyle SD_{epistemic} = 0.25999$"],"text/plain":["<IPython.core.display.Math object>"]},"metadata":{},"output_type":"display_data"}],"source":"import time\nimport os\nimport pandas as pd\nimport numpy as np\nfrom IPython.display import Image, display\nfrom rdkit import Chem\nfrom IPython.display import display, Latex, Math\n\ndef create_csv_sh(parameter, uni, seq, smi):\n try:\n mol = Chem.MolFromSmiles(smi)\n smi = Chem.MolToSmiles(mol)\n except:\n print('Invalid SMILES input!')\n print('Correct your input! Exiting..')\n return\n valid_aas = list('ACDEFGHIKLMNPQRSTVWY')\n for aa in seq:\n if not aa in valid_aas:\n print('Invalid Enzyme sequence input!')\n print('Correct your input! Exiting..')\n return\n if parameter=='kcat':\n if '.' in smi:\n x = smi.split('.')\n y = sorted(x)\n smi = '.'.join(y)\n f = open(f'{uni}_{parameter}_input.csv', 'w')\n f.write('name,sequence,SMILES,pdbpath\\n')\n f.write(f'{uni},{seq},{smi},{uni}.pdb\\n')\n f.close()\n\n f = open(f'predict.sh', 'w')\n f.write(f'''\nTEST_FILE_PREFIX={uni}_{parameter}\nRECORDS_FILE=${{TEST_FILE_PREFIX}}.json\nCHECKPOINT_DIR=./production_models/{parameter}/\n\npython ./scripts/create_pdbrecords.py --data_file ${{TEST_FILE_PREFIX}}_input.csv --out_file ${{RECORDS_FILE}}\npython predict.py --test_path ${{TEST_FILE_PREFIX}}_input.csv --preds_path ${{TEST_FILE_PREFIX}}_output.csv --checkpoint_dir $CHECKPOINT_DIR --uncertainty_method mve --smiles_column SMILES --individual_ensemble_predictions --protein_records_path $RECORDS_FILE\n''')\n f.close()\n\n print('Input success!')\n print('Enzyme sequence length:', len(sequence))\n print('Substrate structure:')\n # display(ShowMols([mol]))\n\n return seq, smi\n\nseq, smi = create_csv_sh(parameter, uniprot_id, sequence, SMILES)\n\nprint('Predicting.. This will take a while..\\n')\n\ndef get_predictions(parameter, uniprot_id):\n df = pd.read_csv(f'{uniprot_id}_{parameter}_output.csv')\n unit = ' mM'\n if parameter=='kcat':\n parameter_print = 'k_{cat}'\n parameter_print_log = 'log_{10}(k_{cat})'\n target_col = 'log10kcat_max'\n unit = ' s^{-1}'\n elif parameter=='km':\n target_col = 'log10km_mean'\n parameter_print = 'K_{m}'\n parameter_print_log = 'log_{10}(K_{m})'\n else:\n target_col = 'log10ki_mean'\n parameter_print = 'K_{i}'\n parameter_print_log = 'log_{10}(K_{i})'\n\n unc_col = f'{target_col}_mve_uncal_var'\n model_cols = [col for col in df.columns if col.startswith(target_col) and 'model_' in col]\n\n unc = df[unc_col].iloc[0]\n\n prediction = df[target_col].iloc[0]\n prediction_linear = np.power(10, prediction)\n\n model_out = df[target_col].iloc[0]\n model_outs = np.array([df[col].iloc[0] for col in model_cols])\n # print(model_outs)\n epi_unc = np.var(model_outs)#np.sum(np.power(2, model_outs))/10. - np.power(2, model_out)\n alea_unc = unc - epi_unc\n epi_unc = np.sqrt(epi_unc)\n alea_unc = np.sqrt(alea_unc)\n unc = np.sqrt(unc)\n\n # print(unc-epi_unc-alea_unc)\n # def display_outs(prediction_type, out, alea_output, epi_output, unit):\n display(Math((parameter_print + f' = {prediction_linear:.5f}'+ unit)))\n print('\\n')\n display(Math((parameter_print_log + f' = {prediction:.5f}')))\n display(Math(('SD_{total}'+f' = {unc:.5f}')))\n display(Math(('SD_{aleatoric}'+f' = {alea_unc:.5f}')))\n display(Math(('SD_{epistemic}'+f' = {epi_unc:.5f}')))\n\nif use_cpu:\n os.system(\"export PROTEIN_EMBED_USE_CPU=1;./predict.sh >/dev/null 2>&1\")\nelse:\n os.system(\"export PROTEIN_EMBED_USE_CPU=0;./predict.sh >/dev/null 2>&1\")\n\nget_predictions(parameter,uniprot_id)"}],"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.5"}},"nbformat":4,"nbformat_minor":5}
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "single-title",
6+
"metadata": {},
7+
"source": "## Define inputs"
8+
},
9+
{
10+
"cell_type": "code",
11+
"execution_count": null,
12+
"id": "single-params",
13+
"metadata": {},
14+
"outputs": [],
15+
"source": "parameter = 'km' # allowed values: ['kcat', 'km', 'ki']\nparameter = parameter.lower()\n\nuse_cpu = 1 # set to 0 if you have GPU enabled\n\nuniprot_id = 'P35557'\n# If you do not have a UniProt ID, enter another stable identifier such as 'enzyme1'.\nsequence = 'MLDDRARMEAAKKEKVEQILAEFQLQEEDLKKVMRRMQKEMDRGLRLETHEEASVKMLPTYVRSTPEGSEVGDFLSLDLGGTNFRVMLVKVGEGEEGQWSVKTKHQMYSIPEDAMTGTAEMLFDYISECISDFLDKHQMKHKKLPLGFTFSFPVRHEDIDKGILLNWTKGFKASGAEGNNVVGLLRDAIKRRGDFEMDVVAMVNDTVATMISCYYEDHQCEVGMIVGTGCNACYMEEMQNVELVEGDEGRMCVNTEWGAFGDSGELDEFLLEYDRLVDESSANPGQQLYEKLIGGKYMGELVRLVLLRLVDENLLFHGEASEQLRTRGAFETRFVSQVESDTGDRKQIYNILSTLGLRPSTTDCDIVRRACESVSTRAAHMCSAGLAGVINRMRESRSEDVMRITVGVDGSVYKLHPSFKERFHASVRRLTPSCEITFIESEEGSGRGAALVSAVACKKACMLGQ'\nSMILES = 'C([C@@H]1[C@H]([C@@H]([C@H](C(O1)O)O)O)O)O'\n"
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"id": "single-run-note",
20+
"metadata": {},
21+
"source": "## Run prediction"
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "single-run",
27+
"metadata": {
28+
"jupyter": {
29+
"source_hidden": true
30+
}
31+
},
32+
"outputs": [],
33+
"source": "from pathlib import Path\n\nimport pandas as pd\nfrom catpred.inference import PredictionRequest, run_prediction_pipeline\n\ninput_file = Path(f'{uniprot_id}_{parameter}.csv')\ninput_df = pd.DataFrame([\n {\n 'name': uniprot_id,\n 'sequence': sequence,\n 'SMILES': SMILES,\n 'pdbpath': f'{uniprot_id}.pdb',\n }\n])\ninput_df.to_csv(input_file, index=False)\n\ncheckpoint_dir = f'../data/pretrained/production/{parameter}'\nrequest = PredictionRequest(\n parameter=parameter,\n input_file=str(input_file),\n checkpoint_dir=checkpoint_dir,\n use_gpu=not bool(use_cpu),\n repo_root='.',\n)\n\noutfile = run_prediction_pipeline(request=request, results_dir='results')\noutput_final = pd.read_csv(outfile)\nprint('Output saved to', outfile)\noutput_final\n"
34+
}
35+
],
36+
"metadata": {
37+
"kernelspec": {
38+
"display_name": "Python 3 (ipykernel)",
39+
"language": "python",
40+
"name": "python3"
41+
},
42+
"language_info": {
43+
"codemirror_mode": {
44+
"name": "ipython",
45+
"version": 3
46+
},
47+
"file_extension": ".py",
48+
"mimetype": "text/x-python",
49+
"name": "python",
50+
"nbconvert_exporter": "python",
51+
"pygments_lexer": "ipython3",
52+
"version": "3.12.4"
53+
}
54+
},
55+
"nbformat": 4,
56+
"nbformat_minor": 5
57+
}

0 commit comments

Comments
 (0)