On Sep 7, 2018, at 22:22, Alexey Orlov <data2sc...@gmail.com> wrote:
> I'm trying to calculate the number of equivalent/nonequivalent neighbor 
> heteroatoms for each atom i of molecule m.
> 
> For examples, the third carbon atom of molecule CC(OH)CC has two 
> nonequivalent neighbors: one carbon atom connected to OH and CH3 and another 
> carbon atom that is connected only to H.  In the case of molecule CC(OH)C(C)C 
> the third carbon atom has two equivalent neighbor heteroatoms (methyl groups) 
> and another neighbor distinct from these two -- atom connected to OH and CH3.

I think you are looking for Chem.CanonicalRankAtoms() described at 
http://rdkit.org/Python_Docs/rdkit.Chem.rdmolfiles-module.html#CanonicalRankAtoms
 .

>>> mol = Chem.MolFromSmiles("CC(O)CC")
>>> list(Chem.CanonicalRankAtoms(mol, breakTies=False))
[1, 4, 2, 3, 0]

As you wrote, there are no equivalent atoms.

>>> mol = Chem.MolFromSmiles("CC(O)C(C)C")
>>> list(Chem.CanonicalRankAtoms(mol, breakTies=False))
[2, 5, 3, 4, 0, 0]

this identifies the two identical methyl groups, both with rank 0.

You might try something like:

from collections import Counter
def get_atoms_neighbor_rank_counts(mol):
    indices = []
    ranks = list(Chem.CanonicalRankAtoms(mol, breakTies=False))
    for atom in mol.GetAtoms():
      equivalents = Counter()
      equivalents.update(ranks[a.GetIdx()] for a in atom.GetNeighbors())
      counts = [count for rank, count in equivalents.most_common()]
      print("Neighbor symmetry counts for", atom.GetIdx(), "are", counts)

For your first test case it gives:

>>> mol = Chem.MolFromSmiles("CC(O)CC")
>>> get_atoms_neighbor_rank_counts(mol)
Neighbor symmetry counts for 0 are [1]
Neighbor symmetry counts for 1 are [1, 1, 1]
Neighbor symmetry counts for 2 are [1]
Neighbor symmetry counts for 3 are [1, 1]
Neighbor symmetry counts for 4 are [1]


That is, all of the atoms have unique neighbors.

For the second test case it gives:


>>> mol = Chem.MolFromSmiles("CC(O)C(C)C")
>>> get_atoms_neighbor_rank_counts(mol)
Neighbor symmetry counts for 0 are [1]
Neighbor symmetry counts for 1 are [1, 1, 1]
Neighbor symmetry counts for 2 are [1]
Neighbor symmetry counts for 3 are [2, 1]
Neighbor symmetry counts for 4 are [1]
Neighbor symmetry counts for 5 are [1]

That is, the atom with index 3 (the 4th atom) has 3 neighbors, two of which are 
identical.

Finally,


>>> mol = Chem.MolFromSmiles("CC(C)(C)OC(C)(C)C")
>>> get_atoms_neighbor_rank_counts(mol)
Neighbor symmetry counts for 0 are [1]
Neighbor symmetry counts for 1 are [3, 1]
Neighbor symmetry counts for 2 are [1]
Neighbor symmetry counts for 3 are [1]
Neighbor symmetry counts for 4 are [2]
Neighbor symmetry counts for 5 are [3, 1]
Neighbor symmetry counts for 6 are [1]
Neighbor symmetry counts for 7 are [1]
Neighbor symmetry counts for 8 are [1]

This says that the atoms with indices 1 and 5 each have 4 neighbor, 3 of which 
are identical, and that the atom with index 4 has 2 neighbors, both of which 
are identical.


                                Andrew
                                da...@dalkescientific.com




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

Reply via email to