Assuming you know which atom(s) you want to add H+'s to, it's easy to do that using an RWMol:
In [8]: mol = Chem.MolFromSmiles('O=C(O)C1=CC(=NNC2=CC=C(C=C2)C(=O)NCCC(=O)O)C=CC1=O') In [9]: rwmol = Chem.RWMol(mol) In [10]: hidx = rwmol.AddAtom(Chem.Atom(1)) In [11]: rwmol.AddBond(16,hidx,Chem.BondType.SINGLE) Out[11]: 28 In [12]: rwmol.GetAtomWithIdx(16).SetFormalCharge(1) In [13]: Chem.MolToSmiles(rwmol) Out[13]: '[H][NH+](CCC(=O)O)C(=O)c1ccc(NN=C2C=CC(=O)C(C(=O)O)=C2)cc1' Notice that the H atom is actually in the graph there (i.e. it shows up in the SMILES as an actual atom). You probably want to remove those Hs and sanitize the molecule after you're done adding the Hs: In [14]: nmol = Chem.RemoveHs(rwmol) In [15]: Chem.MolToSmiles(nmol) Out[15]: 'O=C(O)CC[NH2+]C(=O)c1ccc(NN=C2C=CC(=O)C(C(=O)O)=C2)cc1' The documentation includes a bit more information (and some warnings) about modifying molecules: http://rdkit.org/docs/GettingStartedInPython.html#editing-molecules Best, -greg On Mon, Mar 25, 2019 at 10:13 AM HC.Ji <ji.hongc...@foxmail.com> wrote: > I m tring simulate the fragmentation of ESI mass spectra based on the > [M+H]+ ions. Thus, I want to simulate the ionisation by the addition of one > proton to heteroatoms. For example, > > from rdkit.Chem import AllChem > from rdkit.Chem.Draw import rdMolDraw2D > from IPython.display import SVG > # read mol > mol = > Chem.MolFromSmiles('O=C(O)C1=CC(=NNC2=CC=C(C=C2)C(=O)NCCC(=O)O)C=CC1=O') > > # draw the mol > dr = rdMolDraw2D.MolDraw2DSVG(800,800) > dr.SetFontSize(0.3) > op = dr.drawOptions() > for i in range(mol.GetNumAtoms()) : > op.atomLabels[i] = mol.GetAtomWithIdx(i).GetSymbol() + str((i+1)) > AllChem.Compute2DCoords(mol) > dr.DrawMolecule(mol) > dr.FinishDrawing() > svg = dr.GetDrawingText() > SVG(svg) > > If I want to add one proton to the N atom with the index of #17 and to > ionize the molecule, what should I do in rdkit? > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss