{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Chemical Structure Inputs for PUG-REST"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Objectives\n",
"\n",
"- Use SMILES and InChI strings to specify the input compound for a PUG-REST request.\n",
"- Use a structure-data (SD) file to specify the input compound for a PUG-REST request.\n",
"- Learn to submit a PUG-REST request using the HTTP-POST method.\n",
"
\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can use a chemical structure as an input for a PUG-REST request. PUG-REST accepts some popular chemical structure line notations such as SMILES and InChI strings. It is also possible to use an Structure-Data File (SDF) as a structure input.
\n",
"To learn how to specify the structure input in a PUG-REST request, one needs to know that there are two methods by which data are transferred from clients (users) and servers (PubChem) through PUG-REST. Discussing what these methods are in detail is beyond the scope of this material, and it is enough to know three things:
\n",
"- When you make a PUG-REST request by typing the request URL in the address bar of your web browser (such as Google Chrome, MS Internet Explorer), the HTTP GET method is used
\n",
"- The HTTP GET method transfers information encoded in a single-line URL.
\n",
"- Some chemical structure inputs are not appropriate to encode in a single-line URL (because they may contain special characters not compatible with the URL syntax, span over multiple lines, or too long), and the HTTP POST needs to be used for such cases.\n",
"\n",
"For more information on HTTP GET and POST, read the following documents.\n",
"\n",
"- HTTP request methods (https://www.w3schools.com/tags/ref_httpmethods.asp)\n",
"- Get vs. POST (https://www.diffen.com/difference/GET-vs-POST-HTTP-Requests)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here, import the Requests library, necessary to make web service requests to PubChem."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Using the HTTP GET method."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1-(1) Structure encoded in the URL path."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In some cases, you can encode a chemical structure in the PUG-REST request URL path as in the following example."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"prolog = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/CC(C)CC1=CC=C(C=C1)C(C)C(=O)O/cids/txt\n"
]
}
],
"source": [
"smiles1 = \"CC(C)CC1=CC=C(C=C1)C(C)C(=O)O\"\n",
"url = prolog + \"/compound/smiles/\" + smiles1 + \"/cids/txt\"\n",
"print(url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This request URL returns ibuprofen (CID 3672)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3672\n",
"\n"
]
}
],
"source": [
"res = requests.get(url)\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Try to run the following"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Status: 400\n",
"Code: PUGREST.BadRequest\n",
"Message: Unable to standardize the given structure - perhaps some special characters need to be escaped or data packed in a MIME form?\n",
"Detail: error: \n",
"Detail: status: 400\n",
"Detail: output: Caught ncbi::CException: Standardization failed\n",
"Detail: Output Log:\n",
"Detail: Record 1: Warning: Cactvs Ensemble cannot be created from input string\n",
"Detail: Record 1: Error: Unable to convert input into a compound object\n",
"Detail: \n",
"Detail: \n",
"\n"
]
}
],
"source": [
"smiles2 = \"CC1=C([C@@](SC1=O)(C)/C=C(\\C)/C=C)O\"\n",
"\n",
"url = prolog + \"/compound/smiles/\" + smiles2 + \"/cids/txt\"\n",
"res = requests.get(url)\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
Note in the above example that the SMILES string contains special characters. In this case a forward slash (\"/\"), which is also used in the URL path. These special characters conflict with the PUG-REST request URL syntax, causing an error when used in the PUG-REST request URL."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1-(2) Structure encoded as a URL argument"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To circumvent the issue mentioned above, the SMILES string may be encoded as the URL argments (as an optional parameter followed by the \"?\" character)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/cids/txt?smiles=CC1=C([C@@](SC1=O)(C)/C=C(\\C)/C=C)O\n",
"135403829\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/smiles/cids/txt?\" + \"smiles=\" + smiles2\n",
"print(url)\n",
"res2 = requests.get(url)\n",
"print(res2.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1-(3) Structure passed in a dictionary"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It is also possible to pass the structure query as a key-value pair in a dictionary. The following example does the same task as the previous example does."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"135403829\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/smiles/cids/txt\"\n",
"struct = { 'smiles': smiles2 }\n",
"res3 = requests.get(url, params = struct)\n",
"print(res3.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The object returned from a web service request (res, res2, and res3 in our examples) contains information on the request URL through which the data have been retrieved. This information can be accessed using the \".url\" attribute of the object, as shown in this example:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CC1=C([C@@](SC1=O)(C)/C=C(\\C)/C=C)O\n",
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/cids/txt?smiles=CC1=C([C@@](SC1=O)(C)/C=C(%5CC)/C=C)O\n",
"\n",
"{'smiles': 'CC1=C([C@@](SC1=O)(C)/C=C(\\\\C)/C=C)O'}\n",
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/cids/txt?smiles=CC1%3DC%28%5BC%40%40%5D%28SC1%3DO%29%28C%29%2FC%3DC%28%5CC%29%2FC%3DC%29O\n"
]
}
],
"source": [
"print(smiles2) # the orginal smiles string unencoded\n",
"print(res2.url) # from (request 2) structure encoded as a URL argument\n",
"print()\n",
"print(struct) # to show the smiles string in the dictionary is unencoded for URL\n",
"print(res3.url) # from (request 3) structure passed in a dictionary"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From these two URLs, we can see two important things:\n",
"- When the structure is passed using a key-value pair in a dictionary (i.e., \"res3\"), the structure is automatically encoded as a URL argument (after the \"?\" mark).\n",
"- When the structure is passed in a dictionary, the special characters in the SMILES string are coverted according to the URL encoding rules: https://www.w3schools.com/tags/ref_urlencode.asp. [for example, the equal sign \"=\" changes into \"%3D\", and \"(\" into \"%28\", \"/\" into \"%2F\", etc]\n",
"
\n",
"\n",
"\n",
"It illustrates that the last two approaches using HTTP GET are essentially the same."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Exercise 1a__ Retrieve (in the CSV (comma-separated values) format) the Hydrogen bond donor and acceptor counts, TPSA, and XLogP of the chemical represented by the SMILES string: \"C1=CC(=C(C=C1Cl)O)OC2=C(C=C(C=C2)Cl)Cl\". When you construct a PUG-REST url for this request, encode the structure in the URL path. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# Write your code in this cell.\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 1b** Get the CID corresponding to the following InChI string, using the HTTP GET method. Pay attention to the case sensitivity of the URL parameter part after the \"?\" mark."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"inchi = \"InChI=1S/C17H14O4S/c1-22(19,20)14-9-7-12(8-10-14)15-11-21-17(18)16(15)13-5-3-2-4-6-13/h2-10H,11H2,1H3\""
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# Write your code in this cell\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Using the HTTP POST method"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2-(1) Comparison of HTTP POST and GET"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All the three examples above use the HTTP GET method, as implied in the use of \"requests.get()\". Alternatively, one can use the HTTP POST method. For example, the following example returns the identical result as the last two HTTP GET examples."
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/cids/txt?smiles=CC1%3DC%28%5BC%40%40%5D%28SC1%3DO%29%28C%29%2FC%3DC%28%5CC%29%2FC%3DC%29O\n",
"135403829\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/smiles/cids/txt\"\n",
"struct = { 'smiles': smiles2 }\n",
"res = requests.post(url, params = struct) # the SMILES as a URL parameter\n",
"print(res.url)\n",
"print(res.text)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/smiles/cids/txt\n",
"135403829\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/smiles/cids/txt\"\n",
"struct = { 'smiles': smiles2 }\n",
"res = requests.post(url, data = struct) # the SMILES as data\n",
"print(res.url)\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the first one passes the input SMILES string as a parameter, while the second one passes it as data. Because of this, the URL stored in the \"res.url\" variable in the second code does not contain structure informaion."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2-(2) HTTP POST for multi-line structure input"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The HTTP POST method should be used if the input molecular structure for PUG-REST request span over multiple lines (e.g., stored in a structure-data file (SDF) format). The SDF file contains structure information of a molecule in a multi-line format, along with other data."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"mysdf = '''1983\n",
" -OEChem-07241917072D\n",
"\n",
" 20 20 0 0 0 0 0 0 0999 V2000\n",
" 2.8660 -2.5950 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.5981 1.4050 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 1.4050 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 0.4050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.7320 -0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 -0.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.7320 -1.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 -1.0950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 -1.5950 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.7320 1.9050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.7320 2.9050 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.2690 0.2150 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 1.4631 0.2150 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.3291 1.7150 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.2690 -1.4050 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 1.4631 -1.4050 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.3520 2.9050 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.7320 3.5250 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.1120 2.9050 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.3291 -2.9050 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 1 9 1 0 0 0 0\n",
" 1 20 1 0 0 0 0\n",
" 2 10 2 0 0 0 0\n",
" 3 4 1 0 0 0 0\n",
" 3 10 1 0 0 0 0\n",
" 3 14 1 0 0 0 0\n",
" 4 5 2 0 0 0 0\n",
" 4 6 1 0 0 0 0\n",
" 5 7 1 0 0 0 0\n",
" 5 12 1 0 0 0 0\n",
" 6 8 2 0 0 0 0\n",
" 6 13 1 0 0 0 0\n",
" 7 9 2 0 0 0 0\n",
" 7 15 1 0 0 0 0\n",
" 8 9 1 0 0 0 0\n",
" 8 16 1 0 0 0 0\n",
" 10 11 1 0 0 0 0\n",
" 11 17 1 0 0 0 0\n",
" 11 18 1 0 0 0 0\n",
" 11 19 1 0 0 0 0\n",
"M END\n",
"> \n",
"1983\n",
"\n",
"> \n",
"1\n",
"\n",
"> \n",
"139\n",
"\n",
"> \n",
"2\n",
"\n",
"> \n",
"2\n",
"\n",
"> \n",
"1\n",
"$$$$\n",
"'''"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this example, the triple quotes (''') are used to enclose a multi-line string. This multi-line sdf data is used as an input for a PUG-REST request through the HTTP POST."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/sdf/cids/txt\n",
"1983\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/sdf/cids/txt\"\n",
"mydata = { 'sdf': mysdf }\n",
"res = requests.post(url, data=mydata) # the multiline sdf as URL data\n",
"print(res.url)\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2-(3) HTTP POST for SDF file input"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"One may want to use the structure stored in a file as the input for a PUG-REST request. The following code shows how to read an SDF file into a variable. This code cell assumes that the 'Structure2D_CID_5288826.sdf' file is in the current directory. The file can be downloaded from the **Chapter 2 Assignments** page."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5288826\n",
" -OEChem-08171913162D\n",
"\n",
" 40 44 0 1 0 0 0 0 0999 V2000\n",
" 2.2314 0.0528 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 -2.4021 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 2.4021 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 6.1607 -0.9511 0.0000 N 0 0 3 0 0 0 0 0 0 0 0 0\n",
" 3.6897 -0.4755 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0\n",
" 4.5133 -0.9511 0.0000 C 0 0 2 0 0 0 0 0 0 0 0 0\n",
" 5.3370 -0.4755 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0\n",
" 2.8660 -0.9511 0.0000 C 0 0 2 0 0 0 0 0 0 0 0 0\n",
" 4.2392 0.2219 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6897 0.4755 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.3370 0.4755 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.5918 0.2219 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.5133 0.9511 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 -1.9022 0.0000 C 0 0 2 0 0 0 0 0 0 0 0 0\n",
" 4.5133 -1.9022 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 0.9511 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6897 -2.3777 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 6.8418 -1.6832 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.5133 1.9022 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 1.9022 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6897 2.3777 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.0597 -1.6022 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.6284 -1.2740 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0496 -1.1875 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 4.3760 0.8266 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6795 0.4887 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.9476 0.3679 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.5490 1.0581 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 6.1840 0.4057 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.4989 0.8349 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.8660 -2.5222 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.0503 -2.2122 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6897 -2.9977 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 6.3879 -2.1055 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 7.2641 -2.1371 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 7.2957 -1.2609 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 5.0503 2.2122 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 3.6897 2.9977 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 -3.0222 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 2.0000 3.0222 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0\n",
" 1 8 1 0 0 0 0\n",
" 1 16 1 0 0 0 0\n",
" 14 2 1 6 0 0 0\n",
" 2 39 1 0 0 0 0\n",
" 3 20 1 0 0 0 0\n",
" 3 40 1 0 0 0 0\n",
" 4 7 1 0 0 0 0\n",
" 4 12 1 0 0 0 0\n",
" 4 18 1 0 0 0 0\n",
" 5 6 1 0 0 0 0\n",
" 5 8 1 0 0 0 0\n",
" 5 9 1 1 0 0 0\n",
" 5 10 1 0 0 0 0\n",
" 6 7 1 0 0 0 0\n",
" 6 15 1 0 0 0 0\n",
" 6 22 1 1 0 0 0\n",
" 7 11 1 0 0 0 0\n",
" 7 23 1 6 0 0 0\n",
" 8 14 1 0 0 0 0\n",
" 8 24 1 1 0 0 0\n",
" 9 12 1 0 0 0 0\n",
" 9 25 1 0 0 0 0\n",
" 9 26 1 0 0 0 0\n",
" 10 13 2 0 0 0 0\n",
" 10 16 1 0 0 0 0\n",
" 11 13 1 0 0 0 0\n",
" 11 27 1 0 0 0 0\n",
" 11 28 1 0 0 0 0\n",
" 12 29 1 0 0 0 0\n",
" 12 30 1 0 0 0 0\n",
" 13 19 1 0 0 0 0\n",
" 14 17 1 0 0 0 0\n",
" 14 31 1 0 0 0 0\n",
" 15 17 2 0 0 0 0\n",
" 15 32 1 0 0 0 0\n",
" 16 20 2 0 0 0 0\n",
" 17 33 1 0 0 0 0\n",
" 18 34 1 0 0 0 0\n",
" 18 35 1 0 0 0 0\n",
" 18 36 1 0 0 0 0\n",
" 19 21 2 0 0 0 0\n",
" 19 37 1 0 0 0 0\n",
" 20 21 1 0 0 0 0\n",
" 21 38 1 0 0 0 0\n",
"M END\n",
"> \n",
"5288826\n",
"\n",
"> \n",
"1\n",
"\n",
"> \n",
"494\n",
"\n",
"> \n",
"4\n",
"\n",
"> \n",
"2\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"AAADceB6MAAAAAAAAAAAAAAAAAAAASAAAAA8YIEAAAAWAEjBAAAAHgAACAAADzzhmAYyBoMABgCAAiBCAAACCAAgIAAIiAAOiIgNNiKGsRuGeCOkwBGLuAew8PcPoAABAAAYQADQAAaAADSAAAAAAAAAAA==\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"\n",
"> \n",
"InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1\n",
"\n",
"> \n",
"BQJCRHHNABKAKU-KBQPJGBKSA-N\n",
"\n",
"> \n",
"0.8\n",
"\n",
"> \n",
"285.136493\n",
"\n",
"> \n",
"C17H19NO3\n",
"\n",
"> \n",
"285.34\n",
"\n",
"> \n",
"CN1CCC23C4C1CC5=C2C(=C(C=C5)O)OC3C(C=C4)O\n",
"\n",
"> \n",
"CN1CC[C@]23[C@@H]4[C@H]1CC5=C2C(=C(C=C5)O)O[C@H]3[C@H](C=C4)O\n",
"\n",
"> \n",
"52.9\n",
"\n",
"> \n",
"285.136493\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"21\n",
"\n",
"> \n",
"5\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"0\n",
"\n",
"> \n",
"1\n",
"\n",
"> \n",
"-1\n",
"\n",
"> \n",
"1\n",
"5\n",
"255\n",
"\n",
"> \n",
"10 13 8\n",
"10 16 8\n",
"13 19 8\n",
"16 20 8\n",
"19 21 8\n",
"14 2 6\n",
"20 21 8\n",
"5 9 5\n",
"6 22 5\n",
"7 23 6\n",
"8 24 5\n",
"\n",
"$$$$\n",
"\n"
]
}
],
"source": [
"with open('Structure2D_CID_5288826.sdf', 'r') as file:\n",
" mysdf = file.read()\n",
" \n",
"print(mysdf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now the structure stored in the \"mysdf\" can be used in a PUG-REST request through HTTP-POST. For example, the code cell below shows how to retrieve various names (also called \"synonyms\") of the input structure."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"morphine\n",
"Morphia\n",
"Morphinum\n",
"Morphium\n",
"Morphina\n",
"Morphin\n",
"(-)-Morphine\n",
"Duromorph\n",
"MS Contin\n",
"DepoDur\n",
"Meconium\n",
"Morphinism\n",
"Moscontin\n",
"Ospalivina\n",
"Morfina\n",
"l-Morphine\n",
"Dulcontin\n",
"Nepenthe\n",
"Roxanol\n",
"Kadian\n",
"57-27-2\n",
"MORPHINE SULFATE\n",
"Infumorph\n",
"Dreamer\n",
"Morpho\n",
"Avinza\n",
"Hocus\n",
"Unkie\n",
"Cube juice\n",
"Hard stuff\n",
"Oramorph SR\n",
"Statex SR\n",
"M-Eslon\n",
"Ms Emma\n",
"Morphin [German]\n",
"Morfina [Italian]\n",
"Duramorph\n",
"Morphina [Italian]\n",
"Morphine [BAN]\n",
"Astramorph PF\n",
"Duramorph PF\n",
"CCRIS 5762\n",
"Dolcontin\n",
"HSDB 2134\n",
"(5R,6S,9R,13S,14R)-4,5-Epoxy-N-methyl-7-morphinen-3,6-diol\n",
"UNII-76I7G6D29C\n",
"D-(-)-Morphine\n",
"CHEBI:17303\n",
"CHEMBL70\n",
"EINECS 200-320-2\n",
"4,5alpha-Epoxy-17-methyl-7-morphinen-3,6alpha-diol\n",
"7,8-Didehydro-4,5-epoxy-17-methyl-morphinan-3,6-diol\n",
"(7R,7AS,12BS)-3-METHYL-2,3,4,4A,7,7A-HEXAHYDRO-1H-4,12-METHANO[1]BENZOFURO[3,2-E]ISOQUINOLINE-7,9-DIOL\n",
"DEA No. 9300\n",
"Morphine Anhydrate\n",
"76I7G6D29C\n",
"(5alpha,6alpha)-17-methyl-7,8-didehydro-4,5-epoxymorphinan-3,6-diol\n",
"Morphine (BAN)\n",
"Morphine Forte\n",
"RMS\n",
"Morphine H.P\n",
"(5alpha,6alpha)-Didehydro-4,5-epoxy-17-methylmorphinan-3,6-diol\n",
"Morphinan-3,6-alpha-diol, 7,8-didehydro-4,5-alpha-epoxy-17-methyl-\n",
"Morphine Extra-Forte\n",
"Morphinan-3,6-diol, 7,8-didehydro-4,5-epoxy-17-methyl-, (5alpha,6alpha)-\n",
"9H-9,9c-Iminoethanophenanthro(4,5-bcd)furan-3,5-diol, 4a,5,7a,8-tetrahydro-12-methyl-\n",
"methyl[?]diol\n",
"Aguettant\n",
"Dinamorf\n",
"Sevredol\n",
"Dimorf\n",
"MOI\n",
"Epimorph\n",
"Morphitec\n",
"Oramorph\n",
"Rescudose\n",
"Statex Drops\n",
"OMS Concentrate\n",
"RMS Uniserts\n",
"Roxanol UD\n",
"(Morphine)\n",
"Substitol (TN)\n",
"Mscontin, Oramorph\n",
"(4R,4aR,7S,7aR,12bS)-3-methyl-2,4,4a,7,7a,13-hexahydro-1H-4,12-methanobenzofuro[3,2-e]isoquinoline-7,9-diol\n",
"(-)-(etorphine)\n",
"MSIR\n",
"Roxanol 100\n",
"(-)Morphine sulfate\n",
"Morfina Dosa (TN)\n",
"SDZ202-250\n",
"NSC11441\n",
"SDZ 202-250\n",
"MS/L\n",
"MS/S\n",
"Epitope ID:116646\n",
"Morphinan-3,6-diol, 7,8-didehydro-4,5-epoxy-17-methyl- (5alpha,6alpha)-\n",
"SCHEMBL2997\n",
"M.O.S\n",
"BIDD:GT0147\n",
"GTPL1627\n",
"DTXSID9023336\n",
"Morphine 0.1 mg/ml in Methanol\n",
"Morphine 1.0 mg/ml in Methanol\n",
"BQJCRHHNABKAKU-KBQPJGBKSA-N\n",
"ZINC3812983\n",
"BDBM50000092\n",
"AKOS015966554\n",
"DB00295\n",
"AN-23579\n",
"AN-23737\n",
"LS-91748\n",
"C01516\n",
"D08233\n",
"7,8-Didehydro-4,5-epoxy-17-methylmorphinan-3,6-diol\n",
"UNII-1M5VY6ITRT component BQJCRHHNABKAKU-KBQPJGBKSA-N\n",
"17-methyl-7,8-didehydro-4,5alpha-epoxymorphinan-3,6alpha-diol\n",
"7,8-Didehydro-4,5-epoxy-17-methylmorphinan-3,6-diol(morphine)\n",
"(5A,6A)-7,8-DIDEHYDRO-4,5-EPOXY-17-METHYLMORPHINIAN-3,6-DIOL\n",
"(5alpha,6alpha)-7,8-Didehydro-4,5-epoxy-17-methylmorphinan-3,6-diol\n",
"(5alpha,6beta)-17-methyl-7,8-didehydro-4,5-epoxymorphinan-3,6-diol\n",
"3-(4-Hydroxy-phenyl)-1-propyl-piperidine-3-carboxylic acid ethyl ester\n",
"6-tert-Butyl-3-methyl-1,2,3,4,5,6-hexahydro-2,6-methano-benzo[d]azocine\n",
"(-)(5.alpha.,6.alpha.)-7,8-Didehydro-4,5-epoxy-17-methylmorphinan-3,6-diol\n",
"Morphinan-3,6-diol, 7,8-didehydro-4,5-epoxy-17-methyl- (5..alpha.,6.alpha.)-\n",
"Morphine solution, 1.0 mg/mL in methanol, ampule of 1 mL, certified reference material\n",
"(1S,5R,13R,14S)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"(1S,5R,13R,14S,17R)-4-methyl-12-oxa-4-azapentacyclo[9.6.1.0;{1,13}.0;{5,17}.0;{7,18}]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"(1S,5R,13R,14S,17R)-4-methyl-12-oxa-4-azapentacyclo[9.6.1.0^{1,13}.0^{5,17}.0^{7,18}]octadeca-7,9,11(18),15-tetraene-10,14-diol\n",
"(morphine) 4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"2-{4-[2,4-diamino-6-pteridinylmethyl(methyl)amino]phenylcarboxamido}pentanedioic acid(morphine)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol ; HydroChloride\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol ;sulphate salt(morphine)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol((Morphine))\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol(morphine sulfate)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol(morphine)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol(Morphine)(HCl)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol,sulfate(Morphinesulfate)\n",
"4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diolMorphine\n",
"4-methyl-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"4-methyl-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol (morphine)\n",
"4-methyl-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol(Morphine)\n",
"6,11-Dimethyl-3-(3-methyl-but-2-enyl)-1,2,3,4,5,6-hexahydro-2,6-methano-benzo[d]azocin-8-ol(Morphine)\n",
"9H-9,9c-Iminoethanophenanthro(4,5-bcd)furan-3,5-diol, 4alpha,5,7alpha,8-tetrahydro-12-methyl-\n",
"MORPHINE, (5A,6A)-7,8-DIDEHYDRO-4,5-EPOXY-17-METHYLMORPHINIAN-3,6-DIOL, MORPHIUM, MORPHIA, DOLCONTIN, DUROMORPH, MORPHINA, NEPENTHE\n",
"Morphine;4-methyl-(1S,5R,13R,14S,17R)-12-oxa-4-azapentacyclo[9.6.1.01,13.05,17.07,18]octadeca-7(18),8,10,15-tetraene-10,14-diol\n",
"\n"
]
}
],
"source": [
"url = prolog + \"/compound/sdf/synonyms/txt\"\n",
"mydata = { 'sdf': mysdf }\n",
"res = requests.post(url, data=mydata)\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Exercise 2a** Retrieve (in the **CSV** format) the XlogP, molecular weight, hydrogen bond donor count, hydrogen bond aceptor count, and TPSA of the compounds contained in the five sdf files below, which can be downloaded from the **Chapter 2 Assignments** page. \n",
"\n",
"- Use a for loop to retrieve the data for each compound.\n",
"- Import the time package and add \"time.sleep(0.2)\" to sleep 0.2 seconds after retrieving the data for each compound.\n",
"- Refer to the \"lecture 1\" notebook to see how to merge the multiple CSV outputs into a single CSV output."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"files = ['lecture02_ex2b_compound1.sdf','lecture02_ex2b_compound2.sdf','lecture02_ex2b_compound3.sdf', \\\n",
" 'lecture02_ex2b_compound4.sdf','lecture02_ex2b_compound5.sdf']"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# Write your code in this cell.\n",
"\n",
"\n"
]
}
],
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}