Dear Marta,

this function works now:


from rdkit import Chem
from rdkit.Chem.rdchem import BondType


AROMATIC = BondType.AROMATIC
SINGLE = BondType.SINGLE
DOUBLE = BondType.DOUBLE
TRIPLE = BondType.TRIPLE


def atomtype(mol,atom):
    t=1
    for linkatoms in atom.GetNeighbors():
            bond =  mol.GetBondBetweenAtoms(atom.GetIdx(),linkatoms.GetIdx())
            if bond.GetBondType() == AROMATIC:
                t=2
            if bond.GetBondType() == DOUBLE:
                t=2
            if bond.GetBondType() == TRIPLE:
                t=3
    return t


suppl = Chem.SDMolSupplier('examples/set00.sdf',removeHs = False)
i=0
for mol in suppl:
    i+=1
    v=-1
    for atom in mol.GetAtoms():
        v+=1
        t=atomtype(mol,atom)
        if i<2:
            print str(v) + " " + atom.GetSymbol() + " " + str(t)




but not with the previous call to that part

atom.GetNeighbors()[-1].GetBonds()


My desire output is:

0 N 1

1 O 2

2 O 2

3 C 2

4 C 2

5 C 2

6 C 2

7 C 2

8 C 2

9 C 2

10 C 2

11 C 2

12 C 2

13 C 2

14 C 2

15 C 2

16 C 2

17 C 1

18 H 1

19 H 1

20 H 1

21 H 1

22 H 1

23 H 1

24 H 1

25 H 1

26 H 1

27 H 1

28 H 1?




Dr. Guillaume GODIN
Principal Scientist
Chemoinformatic & Datamining
Innovation
CORPORATE R&D DIVISION
DIRECT LINE +41 (0)22 780 3645
MOBILE          +41 (0)79 536 1039
        Firmenich SA
        RUE DES JEUNES 1 | CASE POSTALE 239 | CH-1211 GENEVE 8

________________________________
De : Marta Stępniewska-Dziubińska <mart...@ibb.waw.pl>
Envoyé : jeudi 14 septembre 2017 11:56
A : Guillaume GODIN
Cc : rdkit-discuss@lists.sourceforge.net
Objet : Re: [Rdkit-discuss] is there an issue with my code or with GetNeighbors 
function ?

Dear Guillaume,

I'm not sure what your code should do and what behavior you expect. I see that 
you do not change the value of t when you see a single bond. So maybe you just 
do not update this value and print and old one? Also, you iterate over bonds of 
atom's last neighbor (so for H you loop over bonds of aromatic C). Is that 
intended?

Best
Marta SD

2017-09-14 11:32 GMT+02:00 Guillaume GODIN 
<guillaume.go...@firmenich.com<mailto:guillaume.go...@firmenich.com>>:

?



Dear all



from rdkit import Chem
from rdkit.Chem.rdchem import BondType


AROMATIC = BondType.AROMATIC
SINGLE = BondType.SINGLE
DOUBLE = BondType.DOUBLE
TRIPLE = BondType.TRIPLE


suppl = 
Chem.SDMolSupplier('/Users/GVALMTGG/Downloads/neemp-sources/examples/set00.sdf',removeHs
 = False)
i=0
for mol in suppl:
    i+=1
    v=-1
    for atom in mol.GetAtoms():
        v+=1
        t=1
        for bond in atom.GetNeighbors()[-1].GetBonds():
            if bond.GetBondType() == AROMATIC:
                t=1.5
            if bond.GetBondType() == DOUBLE:
                t=2
            if bond.GetBondType() == TRIPLE:
                t=3
        if i<2:
            print str(v) + " " + atom.GetSymbol() + " " + str(t)



Why the code return H with 1.5 type bond ?


I used anaconda environment to run the code:


/Users/GVALMTGG/anaconda/envs/my-rdkit-env/bin/python 
/Users/GVALMTGG/PycharmProjects/neemp/neemp.py
0 N 1
1 O 2
2 O 2
3 C 1
4 C 1
5 C 1
6 C 1
7 C 1
8 C 1
9 C 1
10 C 1
11 C 1.5
12 C 2
13 C 1
14 C 1
15 C 2
16 C 2
17 C 1
18 H 1.5
19 H 1.5
20 H 1.5
21 H 1.5
22 H 1.5
23 H 1.5
24 H 1.5
25 H 1.5
26 H 1.5
27 H 1
28 H 1


Dr. Guillaume GODIN
Principal Scientist
Chemoinformatic & Datamining
Innovation
CORPORATE R&D DIVISION
DIRECT LINE +41 (0)22 780 3645<tel:+41%2022%20780%2036%2045>
MOBILE          +41 (0)79 536 1039<tel:+41%2079%20536%2010%2039>
        Firmenich SA
        RUE DES JEUNES 1 | CASE POSTALE 239 | CH-1211 GENEVE 8


**********************************************************************
DISCLAIMER
This email and any files transmitted with it, including replies and forwarded 
copies (which may contain alterations) subsequently transmitted from Firmenich, 
are confidential and solely for the use of the intended recipient. The contents 
do not represent the opinion of Firmenich except to the extent that it relates 
to their official business.
**********************************************************************

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net<mailto:Rdkit-discuss@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to