rdkit icon indicating copy to clipboard operation
rdkit copied to clipboard

CanonicalizeMol may generate the mirror image of the starting coordinates

Open ptosco opened this issue 3 years ago • 1 comments

Discussed in https://github.com/rdkit/rdkit/discussions/5292

Originally posted by petrucci86 May 15, 2022 It was found that CanonicalizeMol() may generate the mirror image of the starting coordinates. Here's a reproducible:

from rdkit import Chem
from rdkit.Chem import AllChem

compound = Chem.MolFromMolBlock("""CREYON GGG TRIMER
     RDKit          3D

115123  0  0  0  0  0  0  0  0999 V2000
    8.2042   -2.4634    3.1848 P   0  0  2  0  0  5  0  0  0  0  0  0
    7.8494   -3.4834    2.1238 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.8138   -2.6951    4.6291 O   0  0  0  0  0  1  0  0  0  0  0  0
    7.6396   -1.0063    2.7027 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.7680    0.1152    3.5679 C   0  0  0  0  0  0  0  0  0  0  0  0
    7.3128    1.3872    2.8602 C   0  0  1  0  0  0  0  0  0  0  0  0
    8.0988    1.5558    1.6567 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.2498    2.2325    0.6908 C   0  0  2  0  0  0  0  0  0  0  0  0
    5.8832    2.4410    1.3458 C   0  0  1  0  0  0  0  0  0  0  0  0
    5.8526    1.3516    2.3989 C   0  0  2  0  0  0  0  0  0  0  0  0
    4.9584    1.6282    3.4643 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.4522    0.9784    3.4851 P   0  0  2  0  0  5  0  0  0  0  0  0
    2.8200    1.3647    4.8079 O   0  0  0  0  0  0  0  0  0  0  0  0
    3.5593   -0.4888    3.1199 O   0  0  0  0  0  1  0  0  0  0  0  0
    2.6139    1.7212    2.2858 O   0  0  0  0  0  0  0  0  0  0  0  0
    2.2464    3.0927    2.4139 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.5986    3.6604    1.1426 C   0  0  1  0  0  0  0  0  0  0  0  0
    2.4788    3.5567    0.0163 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.6723    3.3375   -1.1641 C   0  0  2  0  0  0  0  0  0  0  0  0
    0.2133    3.3102   -0.7152 C   0  0  1  0  0  0  0  0  0  0  0  0
    0.3154    2.9161    0.7475 C   0  0  2  0  0  0  0  0  0  0  0  0
   -0.8028    3.3390    1.5120 O   0  0  0  0  0  0  0  0  0  0  0  0
   -2.0321    2.3004    1.8353 P   0  0  2  0  0  5  0  0  0  0  0  0
   -2.9865    3.0192    2.7687 O   0  0  0  0  0  0  0  0  0  0  0  0
   -1.4375    0.9747    2.2670 O   0  0  0  0  0  1  0  0  0  0  0  0
   -2.8089    2.0481    0.4126 O   0  0  0  0  0  0  0  0  0  0  0  0
   -3.5773    3.0909   -0.1820 C   0  0  0  0  0  0  0  0  0  0  0  0
   -4.1051    2.7174   -1.5726 C   0  0  1  0  0  0  0  0  0  0  0  0
   -3.0592    2.4160   -2.4956 O   0  0  0  0  0  0  0  0  0  0  0  0
   -3.5069    1.4069   -3.4170 C   0  0  2  0  0  0  0  0  0  0  0  0
   -4.9474    1.0847   -3.0352 C   0  0  1  0  0  0  0  0  0  0  0  0
   -5.0103    1.4902   -1.5683 C   0  0  2  0  0  0  0  0  0  0  0  0
   -6.3259    1.8118   -1.1533 O   0  0  0  0  0  0  0  0  0  0  0  0
   -7.2397    0.6938   -0.3787 P   0  0  2  0  0  5  0  0  0  0  0  0
   -8.5428    1.3520    0.0250 O   0  0  0  0  0  0  0  0  0  0  0  0
   -6.3938   -0.0082    0.6627 O   0  0  0  0  0  1  0  0  0  0  0  0
   -7.5357   -0.3592   -1.5932 O   0  0  0  0  0  0  0  0  0  0  0  0
   -8.3938    0.0106   -2.6592 C   0  0  0  0  0  0  0  0  0  0  0  0
   -5.7829    1.9282   -3.8299 O   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6110    0.2634   -3.3539 N   0  0  0  0  0  0  0  0  0  0  0  0
   -2.4041   -0.6383   -4.3635 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.4262   -1.4789   -3.8867 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.9536   -2.5536   -4.7147 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0876   -3.3483   -4.3712 O   0  0  0  0  0  0  0  0  0  0  0  0
   -1.6126   -2.5582   -5.9505 N   0  0  0  0  0  0  0  0  0  0  0  0
   -2.6119   -1.6397   -6.3441 C   0  0  0  0  0  0  0  0  0  0  0  0
   -3.0283   -0.6667   -5.5644 N   0  0  0  0  0  0  0  0  0  0  0  0
   -3.1227   -1.8316   -7.6012 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.0178   -1.1344   -2.6346 N   0  0  0  0  0  0  0  0  0  0  0  0
   -1.7444   -0.0735   -2.3431 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.2656    4.6518   -0.8403 O   0  0  0  0  0  0  0  0  0  0  0  0
    2.0870    2.1015   -1.8143 N   0  0  0  0  0  0  0  0  0  0  0  0
    1.7504    1.7238   -3.0873 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.3008    0.4731   -3.2379 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.1171   -0.2350   -4.4741 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.5844   -1.3440   -4.7000 O   0  0  0  0  0  0  0  0  0  0  0  0
    1.3346    0.5106   -5.3647 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.8024    1.7932   -5.1035 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.0046    2.4283   -3.9705 N   0  0  0  0  0  0  0  0  0  0  0  0
    0.0555    2.3352   -6.1164 N   0  0  0  0  0  0  0  0  0  0  0  0
    2.9508    0.0592   -2.1156 N   0  0  0  0  0  0  0  0  0  0  0  0
    2.7868    1.0548   -1.2666 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.9167    3.7336    1.9549 O   0  0  0  0  0  0  0  0  0  0  0  0
    7.1601    1.4424   -0.5316 N   0  0  0  0  0  0  0  0  0  0  0  0
    6.6121    1.8757   -1.7117 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.5983    0.7643   -2.5206 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.0300    0.8560   -3.8373 C   0  0  0  0  0  0  0  0  0  0  0  0
    5.9802   -0.0802   -4.6250 O   0  0  0  0  0  0  0  0  0  0  0  0
    5.5379    2.1446   -4.0800 N   0  0  0  0  0  0  0  0  0  0  0  0
    5.5942    3.2226   -3.1684 C   0  0  0  0  0  0  0  0  0  0  0  0
    6.1372    3.1160   -1.9760 N   0  0  0  0  0  0  0  0  0  0  0  0
    5.0404    4.3950   -3.6119 N   0  0  0  0  0  0  0  0  0  0  0  0
    7.1144   -0.3306   -1.8970 N   0  0  0  0  0  0  0  0  0  0  0  0
    7.4228    0.1042   -0.6906 C   0  0  0  0  0  0  0  0  0  0  0  0
    9.8135   -2.1697    3.1305 O   0  0  0  0  0  0  0  0  0  0  0  0
   10.4457   -2.0051    1.8723 C   0  0  0  0  0  0  0  0  0  0  0  0
    8.8215    0.2100    3.8504 H   0  0  0  0  0  0  0  0  0  0  0  0
    7.1718   -0.0558    4.4697 H   0  0  0  0  0  0  0  0  0  0  0  0
    7.5002    2.2436    3.5205 H   0  0  0  0  0  0  0  0  0  0  0  0
    7.7453    3.1731    0.4234 H   0  0  0  0  0  0  0  0  0  0  0  0
    5.0241    2.4145    0.6724 H   0  0  0  0  0  0  0  0  0  0  0  0
    5.6160    0.3916    1.9270 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.5514    3.1876    3.2548 H   0  0  0  0  0  0  0  0  0  0  0  0
    3.1441    3.6673    2.6474 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.3890    4.7240    1.3148 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.8905    4.1519   -1.8648 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.4500    2.6635   -1.2935 H   0  0  0  0  0  0  0  0  0  0  0  0
    0.4591    1.8326    0.8245 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.9513    3.9803   -0.2596 H   0  0  0  0  0  0  0  0  0  0  0  0
   -4.4175    3.3215    0.4813 H   0  0  0  0  0  0  0  0  0  0  0  0
   -4.6509    3.5876   -1.9609 H   0  0  0  0  0  0  0  0  0  0  0  0
   -3.4212    1.8275   -4.4257 H   0  0  0  0  0  0  0  0  0  0  0  0
   -5.2480    0.0488   -3.2148 H   0  0  0  0  0  0  0  0  0  0  0  0
   -4.5795    0.6944   -0.9505 H   0  0  0  0  0  0  0  0  0  0  0  0
   -8.5550    1.0911   -2.6900 H   0  0  0  0  0  0  0  0  0  0  0  0
   -9.3558   -0.4905   -2.5268 H   0  0  0  0  0  0  0  0  0  0  0  0
   -7.9479   -0.3161   -3.6016 H   0  0  0  0  0  0  0  0  0  0  0  0
   -6.6754    1.8983   -3.4495 H   0  0  0  0  0  0  0  0  0  0  0  0
   -1.3510   -3.2801   -6.6154 H   0  0  0  0  0  0  0  0  0  0  0  0
   -2.7963   -2.5853   -8.1959 H   0  0  0  0  0  0  0  0  0  0  0  0
   -3.8446   -1.2235   -7.9721 H   0  0  0  0  0  0  0  0  0  0  0  0
   -1.6810    0.4802   -1.4179 H   0  0  0  0  0  0  0  0  0  0  0  0
   -1.1002    4.7142   -0.3501 H   0  0  0  0  0  0  0  0  0  0  0  0
    1.1331    0.0944   -6.2690 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.3715    3.2501   -6.0209 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.0997    1.8359   -6.9852 H   0  0  0  0  0  0  0  0  0  0  0  0
    3.1579    1.0652   -0.2523 H   0  0  0  0  0  0  0  0  0  0  0  0
    5.1659    3.7905    2.5669 H   0  0  0  0  0  0  0  0  0  0  0  0
    5.1024    2.3152   -4.9817 H   0  0  0  0  0  0  0  0  0  0  0  0
    4.6182    4.4665   -4.5310 H   0  0  0  0  0  0  0  0  0  0  0  0
    5.0285    5.2232   -3.0268 H   0  0  0  0  0  0  0  0  0  0  0  0
    7.8362   -0.5082    0.0972 H   0  0  0  0  0  0  0  0  0  0  0  0
    9.9754   -1.1901    1.3171 H   0  0  0  0  0  0  0  0  0  0  0  0
   10.3844   -2.9333    1.2989 H   0  0  0  0  0  0  0  0  0  0  0  0
   11.4973   -1.7597    2.0394 H   0  0  0  0  0  0  0  0  0  0  0  0
  1  2  2  0
  1  3  1  1
  1  4  1  0
  4  5  1  0
  5  6  1  0
  6  7  1  0
  7  8  1  0
  8  9  1  0
  9 10  1  0
 10 11  1  0
 11 12  1  0
 12 13  2  0
 12 14  1  6
 12 15  1  0
 15 16  1  0
 16 17  1  0
 17 18  1  0
 18 19  1  0
 19 20  1  0
 20 21  1  0
 21 22  1  0
 22 23  1  0
 23 24  2  0
 23 25  1  1
 23 26  1  0
 26 27  1  0
 27 28  1  0
 28 29  1  0
 29 30  1  0
 30 31  1  0
 31 32  1  0
 32 33  1  0
 33 34  1  0
 34 35  2  0
 34 36  1  1
 34 37  1  0
 37 38  1  0
 31 39  1  0
 30 40  1  0
 40 41  1  0
 41 42  2  0
 42 43  1  0
 43 44  2  0
 43 45  1  0
 45 46  1  0
 46 47  2  0
 46 48  1  0
 42 49  1  0
 49 50  2  0
 20 51  1  0
 19 52  1  0
 52 53  1  0
 53 54  2  0
 54 55  1  0
 55 56  2  0
 55 57  1  0
 57 58  1  0
 58 59  2  0
 58 60  1  0
 54 61  1  0
 61 62  2  0
  9 63  1  0
  8 64  1  0
 64 65  1  0
 65 66  2  0
 66 67  1  0
 67 68  2  0
 67 69  1  0
 69 70  1  0
 70 71  2  0
 70 72  1  0
 66 73  1  0
 73 74  2  0
  1 75  1  0
 75 76  1  0
 10  6  1  0
 21 17  1  0
 32 28  1  0
 50 40  1  0
 47 41  1  0
 62 52  1  0
 59 53  1  0
 74 64  1  0
 71 65  1  0
  5 77  1  0
  5 78  1  0
  6 79  1  1
  8 80  1  6
  9 81  1  6
 10 82  1  6
 16 83  1  0
 16 84  1  0
 17 85  1  1
 19 86  1  6
 20 87  1  6
 21 88  1  6
 27 89  1  0
 27 90  1  0
 28 91  1  6
 30 92  1  6
 31 93  1  1
 32 94  1  1
 38 95  1  0
 38 96  1  0
 38 97  1  0
 39 98  1  0
 45 99  1  0
 48100  1  0
 48101  1  0
 50102  1  0
 51103  1  0
 57104  1  0
 60105  1  0
 60106  1  0
 62107  1  0
 63108  1  0
 69109  1  0
 72110  1  0
 72111  1  0
 74112  1  0
 76113  1  0
 76114  1  0
 76115  1  0
M  CHG  4   3  -1  14  -1  25  -1  36  -1
M  END
""", removeHs=False)

Chem.AssignStereochemistryFrom3D(compound)
compound_canon = Chem.Mol(compound)
AllChem.CanonicalizeMol(compound_canon, normalizeCovar=True, ignoreHs=True)
Chem.AssignStereochemistryFrom3D(compound_canon)
print(AllChem.CalcRMS(compound_canon, compound))
5.352834539276516
chirality_compound = Chem.FindMolChiralCenters(compound, useLegacyImplementation=False)
chirality_compound_canon = Chem.FindMolChiralCenters(compound_canon, useLegacyImplementation=False)
print(chirality_compound == chirality_compound_canon)
False
print(chirality_compound)
print(chirality_compound_canon)
[(0, 'R'), (5, 'R'), (7, 'R'), (8, 'R'), (9, 'S'), (11, 'R'), (16, 'R'), (18, 'R'), (19, 'R'), (20, 'S'), (22, 'R'), (27, 'R'), (29, 'R'), (30, 'R'), (31, 'S'), (33, 'R')]
[(0, 'S'), (5, 'S'), (7, 'S'), (8, 'S'), (9, 'R'), (11, 'S'), (16, 'S'), (18, 'S'), (19, 'S'), (20, 'R'), (22, 'S'), (27, 'S'), (29, 'S'), (30, 'S'), (31, 'R'), (33, 'S')]
print(AllChem.GetAlignmentTransform(compound_canon, compound)[0])
3.8816982044141284

This is indeed a mirror image:

for i in range(compound_canon.GetConformer().GetNumAtoms()):
    coord = compound_canon.GetConformer().GetAtomPosition(i)
    coord.x = -coord.x
    compound_canon.GetConformer().SetAtomPosition(i, coord)
Chem.AssignStereochemistryFrom3D(compound_canon)
chirality_compound_canon = Chem.FindMolChiralCenters(compound_canon, useLegacyImplementation=False)
print(chirality_compound == chirality_compound_canon)
True
print(AllChem.GetAlignmentTransform(compound_canon, compound)[0])
0.0

ptosco avatar May 18 '22 07:05 ptosco

This issue was marked as stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Oct 22 '24 02:10 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Nov 06 '24 02:11 github-actions[bot]