Hello all. When traversing a molecule's atoms with atom.GetNeighbors(), the object returned for an atom is not necessarily the same object returned when the atom is indexed directly from the molecule. This means one can't directly compare two atoms as objects found while traversing a molecule via neighbors to see if they are the same atom. It seems a new object is created for the atom returned by .GetNeighbors(). Is this expected behavior and what is the reason for this? I've found that the comparison can be done by using atom.GetIdx(), but wanted to use the objects themselves for various reasons. Thanks.

Example:
-------------------------

from rdkit import Chem

m = Chem.MolFromSmiles('C(F)(Cl)(Br)(I)')
atoms = [myatom for myatom in m.GetAtoms()]
for myatom in atoms:
    print(myatom.GetIdx(),myatom.GetSymbol(),myatom)

print("The neighbors of {} are:".format(atoms[1].GetSymbol()))
for newatom in atoms[1].GetNeighbors():
    print(newatom.GetIdx(),newatom.GetSymbol(),newatom)

print("C0 == C0 ?")
print(atoms[0] == newatom)

Output:
----------------------------
0 C <rdkit.Chem.rdchem.Atom object at 0x7f0d429ca760>
1 F <rdkit.Chem.rdchem.Atom object at 0x7f0d429ca850>
2 Cl <rdkit.Chem.rdchem.Atom object at 0x7f0d429ca940>
3 Br <rdkit.Chem.rdchem.Atom object at 0x7f0d429caa30>
4 I <rdkit.Chem.rdchem.Atom object at 0x7f0d429cab20>
The neighbors of F are:
0 C <rdkit.Chem.rdchem.Atom object at 0x7f0d429cac10>
C0 == C0 ?
False






_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to