Last active
September 27, 2018 23:57
-
-
Save zaltoprofen/f7e72f687ee6eeb8454aa88397dfd3e4 to your computer and use it in GitHub Desktop.
IsomericSMILES -> Chem.Mol -> CanonicalSMILES wrong result when `sanitize=True`
This file contains 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" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"original: CN1CCN(C(=O)O[C@H]2c3nccnc3C(=O)N2c2ccc(Cl)cn2)CC1\n" | |
] | |
} | |
], | |
"source": [ | |
"smiles = 'CN1CCN(CC1)C(=O)O[C@H]2C3=NC=CN=C3C(=O)N2C4=NC=C(C=C4)Cl'\n", | |
"smiles = Chem.MolToSmiles(Chem.MolFromSmiles(smiles))\n", | |
"print('original:', smiles)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"can1: CN1CCN(CC1)C(=O)OC1c2nccnc2C(=O)N1c1ccc(Cl)cn1\n" | |
] | |
} | |
], | |
"source": [ | |
"mol1 = Chem.MolFromSmiles(smiles, sanitize=False)\n", | |
"can1 = Chem.MolToSmiles(mol1, isomericSmiles=False, canonical=True)\n", | |
"print('can1:', can1)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"can2: CN1CCN(C(=O)OC2c3nccnc3C(=O)N2c2ccc(Cl)cn2)CC1\n" | |
] | |
} | |
], | |
"source": [ | |
"mol2 = Chem.MolFromSmiles(smiles, sanitize=True)\n", | |
"can2 = Chem.MolToSmiles(mol2, isomericSmiles=False, canonical=True)\n", | |
"print('can2:', can2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "AssertionError", | |
"evalue": "", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-5-13a40edd7147>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32massert\u001b[0m \u001b[0mcan1\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mcan2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mAssertionError\u001b[0m: " | |
] | |
} | |
], | |
"source": [ | |
"assert can1 == can2" | |
] | |
} | |
], | |
"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.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment