The problem is this line:

>
core_smiles_2='C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C\4)C=C3)=C\C1=N2'

Python is interpreting the \4 as an escape sequence. You either need to
double the backslash or use an "r string" to protect the backslash from
being interpreted that way. That is, either of these should be fine:

>
core_smiles_2=r'C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C\4)C=C3)=C\C1=N2'
>
core_smiles_2='C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C\\4)C=C3)=C\C1=N2'

Ivan



On Wed, Mar 13, 2019 at 6:54 AM Chencheng Fan <s8chf...@stud.uni-saarland.de>
wrote:

> Hello everyone,
>
> I meet a problem that I don’t understand how it happens and how to solve
> it.
>
> First, I generate an rdkit_object from reading a mol file(Porphyrin
> molecule). Then generate Smiles from the rdkit_object and save the Smiles
> string in a parameter. Then use the parameter to generate rdkit_object. The
> code works well until now. However, if I directly try to generate
> rdkit_object from the Smiles string, it will return SMILES Parse
> Error:syntax error for input.
>
> I appreciate very much for your help!
>
> Have a good day!
>
> Best wishes
> Cheng
>
> The mol file is:
>
>
> Code is:
>
> from __future__ import print_function
> import rdkit
> from rdkit import Chem
> from rdkit.Chem import AllChem
>
>
> Corefile='Porphyrin.mol'
> core_rdkit_object=Chem.MolFromMolFile(Corefile)
> core_smiles=Chem.MolToSmiles(core_rdkit_object)
> print('core_smiles',core_smiles)
> core=Chem.MolFromSmiles(core_smiles)
> print('rdkit_object',core)
> coreh=Chem.AddHs(core)
> AllChem.EmbedMolecule(coreh)
> print(Chem.MolToMolBlock(coreh))
>
>
> core_smiles_2='C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C\4)C=C3)=C\C1=N2'
> core=Chem.MolFromSmiles(core_smiles_2)
> print(core)
> coreh=Chem.AddHs(core)
> AllChem.EmbedMolecule(coreh)
> print(Chem.MolToMolBlock(coreh))
>
>
> Error is:
>
> core_smiles
>  C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C\4)C=C3)=C\C1=N2
> rdkit_object.       <rdkit.Chem.rdchem.Mol object at 0x2ab4209e1b40>
> [11:50:20] UFFTYPER: Unrecognized atom type: Zn1+2 (9)
> [11:50:20] SMILES Parse Error: syntax error for input:
> 'C1=C/C2=C/c3ccc4n3[Zn]n3/c(cc/c3=C/C3=N/C(=C)C=C3)=C\C1=N2'
> None
> Traceback (most recent call last):
>  File "test-generate_core.py", line 21, in <module>
>    coreh=Chem.AddHs(core)
> Boost.Python.ArgumentError: Python argument types in
>    rdkit.Chem.rdmolops.AddHs(NoneType)
> did not match C++ signature:
>    AddHs(RDKit::ROMol mol, bool explicitOnly=False, bool addCoords=False,
> boost::python::api::object onlyOnAtoms=None, bool addResidueInfo=False)
>
>
> _______________________________________________
> 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

Reply via email to