Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
gkxiao authored Jul 20, 2021
1 parent 65799ec commit 65c8192
Showing 1 changed file with 171 additions and 0 deletions.
171 changes: 171 additions & 0 deletions pka.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import random\n",
"import os\n",
"import pandas as pd\n",
"from rdkit import Chem\n",
"\n",
"upload_url=r'http://xundrug.cn:5001/modules/upload0/'\n",
"\n",
"def predict_pka(smi):\n",
" param={\"Smiles\" : (\"tmg\", smi)}\n",
" headers={'token':'O05DriqqQLlry9kmpCwms2IJLC0MuLQ7'}\n",
" response=requests.post(url=upload_url, files=param, headers=headers)\n",
" jsonbool=int(response.headers['ifjson'])\n",
" if jsonbool==1:\n",
" res_json=response.json()\n",
" if res_json['status'] == 200:\n",
" pka_datas = res_json['gen_datas']\n",
" return pka_datas\n",
" else:\n",
" raise RuntimeError(\"Error for pKa prediction\")\n",
" else:\n",
" raise RuntimeError(\"Error for pKa prediction\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#BBB Score\n",
"#Gupta, M.; Lee, H. J.; Barden, C. J.; Weaver, D. F. The Blood–Brain Barrier (BBB) Score. J. Med. Chem. 2019, 62 (21), 9824–9836. https://doi.org/10.1021/acs.jmedchem.9b01220.\n",
"\n",
"def pka_bbb(base,acid):\n",
" if len(base) == 0 and len(acid) == 0:\n",
" # If molecule has neither (neutral molecule), \n",
" # take the pKa that would give the maximal score for pKa descriptor (pKa=0 for MPO, pKa = 8.81 for BBB)\n",
" pka = 8.81\n",
" \n",
" elif len(base) != 0 and max(base) >= 5:\n",
" # If the molecule has basic pKa's ≥ 5, take the most basic pKa\n",
" pka = max(base)\n",
" \n",
" elif len(base) == 0 and len(acid) != 0:\n",
" if max(acid) >= 9.0:\n",
" pka = 9.0\n",
" else:\n",
" pka = max(acid)\n",
" elif len(base) != 0 and max(base) < 5 and len(acid) != 0:\n",
" pka = max(acid)\n",
" return pka"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# run \n",
"smi = \"CC(=O)Nc1ccc(O)cc1\"\n",
"data_pka = predict_pka(smi)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# get result\n",
"base = data_pka['Base'].values()\n",
"acid = data_pka['Acid'].values()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# String to number\n",
"base = list(map(float,list(base)))\n",
"acid = list(map(float,list(acid)))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Base pka []\n",
"Acid pka: [13.84, 10.1]\n"
]
}
],
"source": [
"print('Base pka',base)\n",
"print('Acid pka:',acid)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BBB pka: 9.0\n"
]
}
],
"source": [
"x = pka_bbb(base,acid)\n",
"print('BBB pka:', x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 65c8192

Please sign in to comment.