def testCounts(self): vals = [ ((0, 1, 2), 4), ((0, 0, 0), 0), ((2, 2, 2), 9), ((1, 1, 2), 7), ((1, 2, 2), 8), ] for combo, tgt in vals: res = Utils.CountUpTo(3, 3, combo) assert res == tgt, f'Bad res ({res}) for combo {str((combo, tgt))}'
def GetBitIdx(self, featIndices, dists, sortIndices=True): """ returns the index for a pharmacophore described using a set of feature indices and distances **Arguments*** - featIndices: a sequence of feature indices - dists: a sequence of distance between the features, only the unique distances should be included, and they should be in the order defined in Utils. - sortIndices : sort the indices **Returns** the integer bit index """ nPoints = len(featIndices) if nPoints > 3: raise NotImplementedError('>3 points not supported') if nPoints < self.minPointCount: raise IndexError('bad number of points') if nPoints > self.maxPointCount: raise IndexError('bad number of points') # this is the start of the nPoint-point pharmacophores startIdx = self._starts[nPoints] # # now we need to map the pattern indices to an offset from startIdx # if sortIndices: tmp = list(featIndices) tmp.sort() featIndices = tmp if featIndices[0] < 0: raise IndexError('bad feature index') if max(featIndices) >= self._nFeats: raise IndexError('bad feature index') if nPoints == 3: featIndices, dists = Utils.OrderTriangle(featIndices, dists) offset = Utils.CountUpTo(self._nFeats, nPoints, featIndices) if _verbose: print('offset for feature %s: %d' % (str(featIndices), offset)) offset *= len(self._scaffolds[len(dists)]) try: if _verbose: print('>>>>>>>>>>>>>>>>>>>>>>>') print('\tScaffolds:', repr(self._scaffolds[len(dists)]), type(self._scaffolds[len(dists)])) print('\tDists:', repr(dists), type(dists)) print('\tbins:', repr(self._bins), type(self._bins)) bin = self._findBinIdx(dists, self._bins, self._scaffolds[len(dists)]) except ValueError: fams = self.GetFeatFamilies() fams = [fams[x] for x in featIndices] raise IndexError( 'distance bin not found: feats: %s; dists=%s; bins=%s; scaffolds: %s' % (fams, dists, self._bins, self._scaffolds)) return startIdx + offset + bin