rdkit / rdkit

The official sources for the RDKit library
BSD 3-Clause "New" or "Revised" License
2.51k stars 851 forks source link

Chem.ReplaceCore(labelByIndex = True): Issue with 0-indexed atoms #7562

Open ZCCheng97 opened 4 days ago

ZCCheng97 commented 4 days ago

Describe the bug Using Chem.ReplaceCore() to obtain fragments with the attachment points labelled by the index of the core. However, while indices of fragments are labelled correctly for eg. [1*]CC if it was originally attached to the 1-index atom on the core, it returns *CC instead of [0*]CC if the fragment was attached originally to the 0-index core atom.

To Reproduce

backboneS = "OCCCCO"
queryS = "COCCCCOC(C)(C)"

query = Chem.MolFromSmiles(queryS)
backbone = Chem.MolFromSmiles(backboneS)

tmp = Chem.ReplaceCore(query,backbone,labelByIndex=True)
rs = Chem.GetMolFrags(tmp,asMols=True)

for frag in rs:
    print(Chem.MolToSmiles(frag))

The output ended up as

*C
[5*]C(C)C

Expected behavior What I had expected from the output.

[0*]C
[5*]C(C)C

Configuration (please complete the following information):