rxn4chemistry / rxnmapper

RXNMapper: Unsupervised attention-guided atom-mapping. Code complementing our Science Advances publication on "Extraction of organic chemistry grammar from unsupervised learning of chemical reactions" (https://advances.sciencemag.org/content/7/15/eabe4166).
http://rxnmapper.ai
MIT License
286 stars 68 forks source link

Boolean index did not match #8

Closed vmarar closed 4 years ago

vmarar commented 4 years ago

~/opt/anaconda3/envs/REL/lib/python3.7/site-packages/rxnmapper/attention.py in pxr_filt_atoms(self) 171 """PXR only the atoms, no special tokens""" 172 if self._pxr_filt_atoms is None: --> 173 self._pxr_filt_atoms = self.pxr[[i != -1 for i in self.pnums]][ 174 :, [i != -1 for i in self.rnums] 175 ]

IndexError: boolean index did not match indexed array along dimension 0; dimension is 47 but corresponding boolean dimension is 18

I got this error when running the examples.ipynb, do you know what it could be?

pschwllr commented 4 years ago

Hard to say like that, could you provide us with more information?

What is the example reaction that you are using as input? What are your versions of pytorch, hugginface transformers and rdkit?

import torch
torch.__version__
> '1.6.0'
import transformers
transformers.__version__
> '3.3.1'

After installing rxnmapper with:

conda create -n rxnmapper_test python=3.7
conda activate rxnmapper_test
conda install -c rdkit rdkit=2020.03.3
pip install rxnmapper

I can run the following example code without error:

from rxnmapper import RXNMapper
rxn_mapper = RXNMapper()
rxns = ['CCOCC.C[Mg+].O=Cc1ccc(F)cc1Cl.[Br-]>>CC(O)c1ccc(F)cc1Cl',
       'BrCCOCCBr.CCN(C(C)C)C(C)C.CCOC(C)=O.CN(C)C=O.Cl.NCC(F)(F)CO>>OCC(F)(F)CN1CCOCC1'
       ]
outputs = rxn_mapper.get_attention_guided_atom_maps(rxns)
print(outputs[0]['mapped_rxn'])
vmarar commented 4 years ago

Thanks!