connorcoley / rdchiral

Wrapper for RDKit's RunReactants to improve stereochemistry handling
MIT License
151 stars 50 forks source link

AddBond() fails in RDKit 2020 #21

Open ljn917 opened 4 years ago

ljn917 commented 4 years ago

The new rdkit 2020.03 has stricter bond checks (maybe incorrect) and the code to merge molecules fails and gives the following error. A temporary workaround is to use ReplaceBond() instead of AddBond().

>>> from rdchiral.main import *
>>> rdchiralRunText("([#16;a:3]:[c:4]:[c:5](:[#7;a:6])-[CH2;D2;+0:7]-[CH2;D2;+0:8]-[c:9].[NH2;D1;+0:1]-[c:2])>>O=[N+;H0;D3:1](-[O-])-[c:2].[#16;a:3]:[c:4]:[c:5](:[#7;a:6])/[CH;D2;+0:7]=[CH;D2;+0:8]\\[c:9]", "[CH3:1][C:2](=[O:3])[NH:4][c:5]1[n:6][c:7]([CH2:21][CH2:22][c:23]2[cH:24][cH:25][c:26]([NH2:29])[cH:27][cH:28]2)[c:8]([CH2:10][c:11]2[cH:12][cH:13][cH:14][c:15]([S:17]([CH3:18])(=[O:19])=[O:20])[cH:16]2)[s:9]1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ljn/lab_jensen/rdchiral/rdchiral/main.py", line 94, in rdchiralRunText
    return rdchiralRun(rxn, reactants, **kwargs)
  File "/home/ljn/lab_jensen/rdchiral/rdchiral/main.py", line 261, in rdchiralRun
    merged_mol.GetBondBetweenAtoms(
RuntimeError: Pre-condition Violation
    Stereo atoms should be specified before specifying CIS/TRANS bond stereochemistry
    Violation occurred on line 288 in file /usr/local/rdkit/include/rdkit/GraphMol/Bond.h
    Failed Expression: what <= STEREOE || getStereoAtoms().size() == 2
    RDKIT: 2020.03.4
    BOOST: 1_67

ReplaceBond() workaround, replace the code between line 259-266 with

                        merged_mol.AddBond(merged_map_to_id[bi],
                            merged_map_to_id[bj], BondType.UNSPECIFIED)
                        idx = merged_mol.GetBondBetweenAtoms(
                            merged_map_to_id[bi], merged_map_to_id[bj]
                        ).GetIdx()
                        merged_mol.ReplaceBond(idx, b)