Speculating a comparison of the outputs by both programs may help, I let RDKit
process to SMILES to yield a representation including the atom indices. Derived from the cookbook, the MWE for the Jupyter notebook was
from rdkit import Chem
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import Draw
from rdkit.Chem import rdDepictor
from rdkit.Chem.Draw import rdMolDraw2D
from IPython.display import SVG
IPythonConsole.ipython_useSVG=True
def mol_with_atom_index(mol):
for atom in mol.GetAtoms():
atom.SetAtomMapNum(atom.GetIdx())
return mol
mol = Chem.MolFromSmiles("OCCn2c(=N)n(CCOc1ccc(Cl)cc1Cl)c3ccccc23")
mol = mol_with_atom_index(mol)
mc = Chem.Mol(mol.ToBinary())
drawer = rdMolDraw2D.MolDraw2DSVG(450, 200)
drawer.DrawMolecule(mc)
drawer.FinishDrawing()
svg = drawer.GetDrawingText()
display(SVG(svg.replace('svg:','')))
In a second step, I requested pysmiles
to list for non-H atoms atom index, atom symbol (first two columns) and number of hydrogen bound (trailing column).
from pysmiles import read_smiles
smiles = "OCCn2c(=N)n(CCOc1ccc(Cl)cc1Cl)c3ccccc23"
molecule = read_smiles(smiles)
pysmiles_list = zip(molecule.nodes(data="element"), molecule.nodes(data="hcount"))
for element in pysmiles_list:
print(element)
By visual inspection, RDKit's annotated formula and pysmiles' listing agree with each other except for the endocyclic nitrogens (N:3
and N:6
):

((0, 'O'), (0, 1))
((1, 'C'), (1, 2))
((2, 'C'), (2, 2))
((3, 'N'), (3, 1))
((4, 'C'), (4, 0))
((5, 'N'), (5, 1))
((6, 'N'), (6, 1))
((7, 'C'), (7, 2))
((8, 'C'), (8, 2))
((9, 'O'), (9, 0))
((10, 'C'), (10, 0))
((11, 'C'), (11, 1))
((12, 'C'), (12, 1))
((13, 'C'), (13, 0))
((14, 'Cl'), (14, 0))
((15, 'C'), (15, 1))
((16, 'C'), (16, 0))
((17, 'Cl'), (17, 0))
((18, 'C'), (18, 0))
((19, 'C'), (19, 1))
((20, 'C'), (20, 1))
((21, 'C'), (21, 1))
((22, 'C'), (22, 1))
((23, 'C'), (23, 0))
A similar listing of atom index, atom type, and number of hydrogens bond to the non-H may be achieved iterating with RDKit over the non-H atoms
for atom in mol.GetAtoms():
print("{:2} {:2} {}".format(atom.GetIdx(), atom.GetSymbol(),
atom.GetTotalNumHs()))
to yield
0 O 1
1 C 2
2 C 2
3 N 0
4 C 0
5 N 1
6 N 0
7 C 2
8 C 2
9 O 0
10 C 0
11 C 1
12 C 1
13 C 0
14 Cl 0
15 C 1
16 C 0
17 Cl 0
18 C 0
19 C 1
20 C 1
21 C 1
22 C 1
23 C 0
As outlined in the answer by @rapelpy
, there is a problem with pysmiles which the maintainer(s) might rectify in future. The computations in this answer were performed with pysmiles (version 1.0.1, Jun 25, 2020), and RDKit as packaged for Debian 11 (testing) (version 2020.09.4).
RDkit
, this is the code:molecule = RDkit.Chem.MolFromSmiles(smiles)
, and forpysmiles
this is what I use:molecule = pysmiles.read_smiles(smiles)
. I don't have any additional options that I passed to them $\endgroup$