Created
December 11, 2019 22:46
-
-
Save ptosco/e4fd19a0ed5adb03c65e86290491dffc to your computer and use it in GitHub Desktop.
Feed a string to a MolSupplier
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from rdkit import Chem\n", | |
"from io import BytesIO" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sdf_block = \"\"\"\\\n", | |
"CCO\n", | |
" Some API Name 3D\n", | |
"\n", | |
" 9 8 0 0 0 0 0 0 0 0999 V2000\n", | |
" 0.9111 -0.0580 0.0833 C 0 -0.539850 0 0 0 0 0 0 0 0 0 0\n", | |
" -0.5645 -0.3943 -0.0668 C 0 0.052144 0 0 0 0 0 0 0 0 0 0\n", | |
" -1.3951 0.7270 0.2733 O 0 -0.556284 0 0 0 0 0 0 0 0 0 0\n", | |
" 1.1128 0.3865 1.0677 H 0 0.172888 0 0 0 0 0 0 0 0 0 0\n", | |
" 1.2517 0.6586 -0.6717 H 0 0.157527 0 0 0 0 0 0 0 0 0 0\n", | |
" 1.5381 -0.9524 -0.0063 H 0 0.163812 0 0 0 0 0 0 0 0 0 0\n", | |
" -0.8972 -1.1630 0.6576 H 0 0.138112 0 0 0 0 0 0 0 0 0 0\n", | |
" -0.8158 -0.7181 -1.0929 H 0 0.106288 0 0 0 0 0 0 0 0 0 0\n", | |
" -1.1410 1.5140 -0.2440 H 0 0.305363 0 0 0 0 0 0 0 0 0 0\n", | |
" 1 2 1 0 0 0 0\n", | |
" 1 4 1 0 0 0 0\n", | |
" 1 5 1 0 0 0 0\n", | |
" 1 6 1 0 0 0 0\n", | |
" 2 3 1 0 0 0 0\n", | |
" 2 7 1 0 0 0 0\n", | |
" 2 8 1 0 0 0 0\n", | |
" 3 9 1 0 0 0 0\n", | |
"M END\n", | |
"\n", | |
"> <Id>\n", | |
"939090603255\n", | |
"\n", | |
"> <SMILES>\n", | |
"CCO\n", | |
"\n", | |
"> <Atoms>\n", | |
"9\n", | |
"\n", | |
"> <Bonds>\n", | |
"8\n", | |
"\n", | |
"> <Chiral>\n", | |
"false\n", | |
"\n", | |
"> <Energy>\n", | |
"-14261.901904236434\n", | |
"\n", | |
"> <Enthalpy (kcal/mol @ 298 K)>\n", | |
"47.3436630758052\n", | |
"\n", | |
"> <Gibbs energy (kcal/mol @ 298 K)>\n", | |
"29.8354953675966\n", | |
"\n", | |
"> <Zero point energy (kcal/mol @ 0 K)>\n", | |
"44.196874495459795\n", | |
"\n", | |
"> <Molecular dipole (X, Y, Z)>\n", | |
"-1.761841, 0.283414, 1.207075\n", | |
"\n", | |
"> <Source energy>\n", | |
"-14259.552636725288\n", | |
"\n", | |
"$$$$\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"With `Chem.ForwardSDMolSupplier` and a file-like object:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"-14259.552636725288\n" | |
] | |
} | |
], | |
"source": [ | |
"mol = None\n", | |
"with BytesIO(sdf_block.encode(\"UTF-8\")) as hnd:\n", | |
" for mol in Chem.ForwardSDMolSupplier(hnd):\n", | |
" print(mol.GetProp(\"Source energy\"))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"With `Chem.SDMolSupplier.SetData()`:" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"-14259.552636725288\n" | |
] | |
} | |
], | |
"source": [ | |
"suppl = Chem.SDMolSupplier()\n", | |
"suppl.SetData(sdf_block)\n", | |
"for mol in suppl:\n", | |
" print(mol.GetProp(\"Source energy\"))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"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.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment