Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save greglandrum/3367a960aa79a6fe52a4067487ca5533 to your computer and use it in GitHub Desktop.
Save greglandrum/3367a960aa79a6fe52a4067487ca5533 to your computer and use it in GitHub Desktop.
iwatobipen_reactions_and_coordinates
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "from rdkit import Chem\nfrom rdkit.Chem import AllChem\nfrom rdkit.Chem import rdChemReactions",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "mol = Chem.AddHs(Chem.MolFromSmiles('c1ccncc1'))",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "AllChem.EmbedMolecule(mol)",
"execution_count": 3,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 3,
"data": {
"text/plain": "0"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "If we want to keep the coordinates of the H, we can include it in the reaction:"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "rxn = rdChemReactions.ReactionFromSmarts('[c:1][#1:2]>>[c:1][F:2]')",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "ps = rxn.RunReactants((mol,))",
"execution_count": 5,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "om = ps[0][0]\nChem.SanitizeMol(om)",
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 7,
"data": {
"text/plain": "rdkit.Chem.rdmolops.SanitizeFlags.SANITIZE_NONE"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(Chem.MolToMolBlock(mol))",
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"text": "\n RDKit 3D\n\n 11 11 0 0 0 0 0 0 0 0999 V2000\n -0.1044 1.1576 0.0430 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.2030 0.3447 0.0302 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.1017 -1.0368 -0.0208 C 0 0 0 0 0 0 0 0 0 0 0 0\n 0.1237 -1.5610 -0.0578 N 0 0 0 0 0 0 0 0 0 0 0 0\n 1.2528 -0.8282 -0.0482 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.1362 0.5521 0.0030 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.1931 2.2308 0.0828 H 0 0 0 0 0 0 0 0 0 0 0 0\n -2.1800 0.8222 0.0617 H 0 0 0 0 0 0 0 0 0 0 0 0\n -2.0157 -1.6087 -0.0278 H 0 0 0 0 0 0 0 0 0 0 0 0\n 2.2472 -1.2554 -0.0783 H 0 0 0 0 0 0 0 0 0 0 0 0\n 2.0380 1.1830 0.0122 H 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 2 0\n 2 3 1 0\n 3 4 2 0\n 4 5 1 0\n 5 6 2 0\n 6 1 1 0\n 1 7 1 0\n 2 8 1 0\n 3 9 1 0\n 5 10 1 0\n 6 11 1 0\nM END\n\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "print(Chem.MolToMolBlock(om))",
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"text": "\n RDKit 3D\n\n 11 11 0 0 0 0 0 0 0 0999 V2000\n -0.1044 1.1576 0.0430 C 0 0 0 0 0 0 0 0 0 0 0 0\n -0.1931 2.2308 0.0828 F 0 0 0 0 0 0 0 0 0 0 0 0\n -1.2030 0.3447 0.0302 C 0 0 0 0 0 0 0 0 0 0 0 0\n 1.1362 0.5521 0.0030 C 0 0 0 0 0 0 0 0 0 0 0 0\n -1.1017 -1.0368 -0.0208 C 0 0 0 0 0 0 0 0 0 0 0 0\n -2.1800 0.8222 0.0617 H 0 0 0 0 0 0 0 0 0 0 0 0\n 1.2528 -0.8282 -0.0482 C 0 0 0 0 0 0 0 0 0 0 0 0\n 2.0380 1.1830 0.0122 H 0 0 0 0 0 0 0 0 0 0 0 0\n 0.1237 -1.5610 -0.0578 N 0 0 0 0 0 0 0 0 0 0 0 0\n -2.0157 -1.6087 -0.0278 H 0 0 0 0 0 0 0 0 0 0 0 0\n 2.2472 -1.2554 -0.0783 H 0 0 0 0 0 0 0 0 0 0 0 0\n 1 2 1 0\n 1 3 2 0\n 4 1 1 0\n 3 5 1 0\n 3 6 1 0\n 7 4 2 0\n 4 8 1 0\n 5 9 2 0\n 5 10 1 0\n 9 7 1 0\n 7 11 1 0\nM END\n\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.2",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "iwatobipen_reactions_and_coordinates",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@iwatobipen
Copy link

Thank you for sharing your code! This is what I would like to do!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment