コード例 #1
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
// the caller is responsible for delete[]'ing this
boost::uint8_t *copyBytes(const FPBReader_impl *dp_impl, unsigned int which) {
  PRECONDITION(dp_impl, "bad reader pointer");
  boost::uint8_t *res;
  res = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint];
  if (!dp_impl->df_lazy) {
    boost::uint8_t *fpData = NULL;
    extractBytes(dp_impl, which, fpData);
    memcpy(static_cast<void *>(res), fpData,
           dp_impl->numBytesStoredPerFingerprint);
  } else {
    extractBytes(dp_impl, which, res);
  }
  return res;
};
コード例 #2
0
	/*
	* ShockBurst packet format (length in bytes in parenthesis):
	*
	* +--------------+---------------+----------------------------+-----------+
	* | Preamble (1) | Address (3-5) | Payload (1-32)             | CRC (1-2) |
	* +--------------+---------------+----------------------------+-----------+
	*
	* CRC is calculated over the "Address" and "Payload" fields, and it is 2
	* bytes in case of ANT.
	*/
	bool decodePacket(int32_t sample)
	{
		int i;
		_threshold = extractThreshold();

		if (detectPreamble()) {
			uint8_t tmp_buf[ADDRESS_LENGTH + PAYLOAD_LENGTH + 2];
			extractBytes(8, tmp_buf, sizeof(tmp_buf));
			if (isShockBurstPacket(tmp_buf)) {
				packetData.clear();

				// address
				uint64_t address = 0;
				for (int i = 0; i < ADDRESS_LENGTH; ++i)
					address |= tmp_buf[i] << (ADDRESS_LENGTH - 1 - i) * 8;
				packetData["address"] = Pothos::Object(address);

				// CRC
				uint16_t crc = tmp_buf[ADDRESS_LENGTH + PAYLOAD_LENGTH] << 8 |
					tmp_buf[ADDRESS_LENGTH + PAYLOAD_LENGTH + 1];
				packetData["crc"] = Pothos::Object(crc);

				// paylod
				packetData["payload"] = Pothos::Object(std::vector<uint8_t>(
							tmp_buf + ADDRESS_LENGTH,
							tmp_buf + ADDRESS_LENGTH + PAYLOAD_LENGTH));

				return true;
			}
		}

		return false;
	}
コード例 #3
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
void containingNeighbors(const FPBReader_impl *dp_impl,
                         const boost::uint8_t *bv,
                         std::vector<unsigned int> &res) {
  PRECONDITION(dp_impl, "bad reader pointer");
  PRECONDITION(bv, "bad bv");
  res.clear();
  boost::uint64_t probeCount =
      CalcBitmapPopcount(bv, dp_impl->numBytesStoredPerFingerprint);

  boost::uint64_t startScan = 0, endScan = dp_impl->len;
  if (dp_impl->popCountOffsets.size() == dp_impl->nBits + 2) {
    startScan = dp_impl->popCountOffsets[probeCount];
    // std::cerr << " scan: " << startScan << "-" << endScan << std::endl;
  }
  boost::uint8_t *dbv;
  if (dp_impl->df_lazy) {
    dbv = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint];
  }
  for (boost::uint64_t i = startScan; i < endScan; ++i) {
    extractBytes(dp_impl, i, dbv);
    if (CalcBitmapAllProbeBitsMatch(bv, dbv,
                                    dp_impl->numBytesStoredPerFingerprint)) {
      res.push_back(i);
    }
  }
  if (dp_impl->df_lazy) delete[] dbv;
}
コード例 #4
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
// the caller is responsible for delete'ing this
ExplicitBitVect *extractFP(const FPBReader_impl *dp_impl, unsigned int which) {
  PRECONDITION(dp_impl, "bad reader pointer");
  boost::uint8_t *fpData;
  if (dp_impl->df_lazy) {
    fpData = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint];
  }
  extractBytes(dp_impl, which, fpData);
  boost::dynamic_bitset<> *resDBS = bytesToBitset(fpData, dp_impl->nBits);
  if (dp_impl->df_lazy) delete[] fpData;
  return new ExplicitBitVect(resDBS);
};
コード例 #5
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
void tanimotoNeighbors(const FPBReader_impl *dp_impl, const boost::uint8_t *bv,
                       double threshold,
                       std::vector<std::pair<double, unsigned int> > &res,
                       bool usePopcountScreen, unsigned int readCache = 1000) {
  PRECONDITION(dp_impl, "bad reader pointer");
  PRECONDITION(bv, "bad bv");
  RANGE_CHECK(-1e-6, threshold, 1.0 + 1e-6);
  PRECONDITION(readCache > 0, "bad cache size");
  res.clear();
  boost::uint64_t probeCount =
      CalcBitmapPopcount(bv, dp_impl->numBytesStoredPerFingerprint);

  boost::uint64_t startScan = 0, endScan = dp_impl->len;
  if (usePopcountScreen &&
      dp_impl->popCountOffsets.size() == dp_impl->nBits + 2) {
    // figure out the bounds based on equation 24 from:
    // 1. Swamidass, S. J. & Baldi, P. Bounds and Algorithms for Fast Exact
    // Searches of Chemical Fingerprints in Linear and Sublinear Time. J. Chem.
    // Inf. Model. 47, 302–317 (2007).
    // http://pubs.acs.org/doi/abs/10.1021/ci600358f
    boost::uint32_t minDbCount =
        static_cast<boost::uint32_t>(floor(threshold * probeCount));
    boost::uint32_t maxDbCount =
        (threshold > 1e-6)
            ? static_cast<boost::uint32_t>(ceil(probeCount / threshold))
            : dp_impl->numBytesStoredPerFingerprint;
    // std::cerr << "probeCount: " << probeCount << " bounds: " << minDbCount
    //           << "-" << maxDbCount << std::endl;
    startScan = dp_impl->popCountOffsets[minDbCount];
    endScan = dp_impl->popCountOffsets[maxDbCount + 1];
    // std::cerr << " scan: " << startScan << "-" << endScan << std::endl;
  }
  boost::uint8_t *dbv;
  if (dp_impl->df_lazy) {
    dbv = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint * readCache];
  }
  for (boost::uint64_t i = startScan; i < endScan; i += readCache) {
    unsigned int toRead = readCache;
    if (i + toRead >= endScan) {
      toRead = endScan - i;
    }
    extractBytes(dp_impl, i, dbv, toRead);
    for (unsigned int j = 0; j < toRead; ++j) {
      double tani =
          CalcBitmapTanimoto(dbv + j * dp_impl->numBytesStoredPerFingerprint,
                             bv, dp_impl->numBytesStoredPerFingerprint);
      if (tani >= threshold) {
        res.push_back(std::make_pair(tani, i + j));
      }
    }
  }
  if (dp_impl->df_lazy) delete[] dbv;
}
コード例 #6
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
void tverskyNeighbors(const FPBReader_impl *dp_impl, const boost::uint8_t *bv,
                      double ca, double cb, double threshold,
                      std::vector<std::pair<double, unsigned int> > &res,
                      bool usePopcountScreen) {
  PRECONDITION(dp_impl, "bad reader pointer");
  PRECONDITION(bv, "bad bv");
  RANGE_CHECK(-1e-6, threshold, 1.0 + 1e-6);
  res.clear();
  boost::uint64_t probeCount =
      CalcBitmapPopcount(bv, dp_impl->numBytesStoredPerFingerprint);

  boost::uint64_t startScan = 0, endScan = dp_impl->len;
  if (usePopcountScreen &&
      dp_impl->popCountOffsets.size() == dp_impl->nBits + 2) {
    // figure out the bounds based on equation 25 from:
    // 1. Swamidass, S. J. & Baldi, P. Bounds and Algorithms for Fast Exact
    // Searches of Chemical Fingerprints in Linear and Sublinear Time. J. Chem.
    // Inf. Model. 47, 302–317 (2007).
    // http://pubs.acs.org/doi/abs/10.1021/ci600358f
    boost::uint32_t minDbCount = static_cast<boost::uint32_t>(floor(
        (threshold * probeCount * ca) / (1. - threshold + threshold * ca)));
    boost::uint32_t maxDbCount =
        ((threshold * cb) > 1e-6)
            ? static_cast<boost::uint32_t>(
                  ceil(probeCount * (1 - threshold + threshold * cb) /
                       (threshold * cb)))
            : dp_impl->numBytesStoredPerFingerprint;
    // std::cerr << "probeCount: " << probeCount << " bounds: " << minDbCount
    //          << "-" << maxDbCount << std::endl;
    startScan = dp_impl->popCountOffsets[minDbCount];
    endScan = dp_impl->popCountOffsets[maxDbCount + 1];
    // std::cerr << " scan: " << startScan << "-" << endScan << std::endl;
  }

  boost::uint8_t *dbv;
  if (dp_impl->df_lazy) {
    dbv = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint];
  }
  for (boost::uint64_t i = startScan; i < endScan; ++i) {
    extractBytes(dp_impl, i, dbv);
    double sim = CalcBitmapTversky(
        dbv, bv, dp_impl->numBytesStoredPerFingerprint, ca, cb);
    // std::cerr << "  i:" << i << " " << tani << " ? " << threshold <<
    // std::endl;
    if (sim >= threshold) {
      res.push_back(std::make_pair(sim, i));
    }
  }
  if (dp_impl->df_lazy) delete[] dbv;
}
コード例 #7
0
ファイル: FPBReader.cpp プロジェクト: ASKCOS/rdkit
double tversky(const FPBReader_impl *dp_impl, unsigned int which,
               const ::boost::uint8_t *bv, double ca, double cb) {
  PRECONDITION(dp_impl, "bad reader pointer");
  PRECONDITION(bv, "bad bv pointer");
  if (which >= dp_impl->len) {
    throw ValueErrorException("bad index");
  }
  boost::uint8_t *fpData;
  if (dp_impl->df_lazy) {
    fpData = new boost::uint8_t[dp_impl->numBytesStoredPerFingerprint];
  }
  extractBytes(dp_impl, which, fpData);
  double res = CalcBitmapTversky(fpData, bv,
                                 dp_impl->numBytesStoredPerFingerprint, ca, cb);
  if (dp_impl->df_lazy) delete[] fpData;
  return res;
};
コード例 #8
0
ファイル: dextractor.c プロジェクト: fvrmatteo/CV
void header_view(FILE *fp) {
	printf("\033[22;32mHeader information:\n\n");
	extractBytes(fp, 0, 8, "  \033[22;37m[\033[01;37m+\033[22;37m] Magic: \033[22;31m", false, false);
	extractBytes(fp, 8, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Checksum: \033[22;31m", false, false);
	extractBytes(fp, 12, 20, "  \033[22;37m[\033[01;37m+\033[22;37m] Signature: \033[22;31m", false, false);
	extractBytes(fp, 32, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] File Size: \033[22;31m", true, true);
	extractBytes(fp, 36, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Header Size: \033[22;31m", true, true);
	extractBytes(fp, 40, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Endian Tag: \033[22;31m", false, false);
	extractBytes(fp, 44, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Link Size: \033[22;31m", true, true);
	extractBytes(fp, 48, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Link Offset: \033[22;31m", false, true);
	extractBytes(fp, 52, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Map Offset: \033[22;31m", false, true);
	extractBytes(fp, 56, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] String Ids Size: \033[22;31m", true, true);
	extractBytes(fp, 60, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] String Ids Offset: \033[22;31m", false, true);
	extractBytes(fp, 64, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Type Ids Size: \033[22;31m", true, true);
	extractBytes(fp, 68, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Type Ids Offset: \033[22;31m", false, true);
	extractBytes(fp, 72, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Proto Ids Size: \033[22;31m", true, true);
	extractBytes(fp, 76, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Proto Ids Offset: \033[22;31m", false, true);
	extractBytes(fp, 80, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Field Ids Size: \033[22;31m", true, true);
	extractBytes(fp, 84, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Field Ids Offset: \033[22;31m", false, true);
	extractBytes(fp, 88, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Method Ids Size: \033[22;31m", true, true);
	extractBytes(fp, 92, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Method Ids Offset: \033[22;31m", false, true);
	extractBytes(fp, 96, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Class Defs Size: \033[22;31m", true, true);
	extractBytes(fp, 100, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Class Defs Offset: \033[22;31m", false, true);
	extractBytes(fp, 104, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Data Size: \033[22;31m", true, true);
	extractBytes(fp, 108, 4, "  \033[22;37m[\033[01;37m+\033[22;37m] Data Offset: \033[22;31m", false, true);
	printf("\n");
}