Exemple #1
0
void constructFragmenterBondTypes(
    std::istream *inStream,
    const std::map<unsigned int, std::string> &atomTypes,
    std::vector<FragmenterBondType> &defs, const std::string &comment,
    bool validate, bool labelByConnector) {
  PRECONDITION(inStream, "no stream");
  defs.clear();
  defs.resize(0);

  unsigned int line = 0;
  while (!inStream->eof()) {
    ++line;
    std::string tempStr = getLine(inStream);
    if (tempStr == "" || tempStr.find(comment) == 0) continue;
    std::vector<std::string> tokens;
    boost::split(tokens, tempStr, boost::is_any_of(" \t"),
                 boost::token_compress_on);
    if (tokens.size() < 3) {
      BOOST_LOG(rdWarningLog) << "line " << line << " is too short"
                              << std::endl;
      continue;
    }
    unsigned int idx1 = boost::lexical_cast<unsigned int>(tokens[0]);
    if (atomTypes.find(idx1) == atomTypes.end()) {
      BOOST_LOG(rdWarningLog) << "atom type #" << idx1 << " not recognized."
                              << std::endl;
      continue;
    }
    unsigned int idx2 = boost::lexical_cast<unsigned int>(tokens[1]);
    if (atomTypes.find(idx2) == atomTypes.end()) {
      BOOST_LOG(rdWarningLog) << "atom type #" << idx2 << " not recognized."
                              << std::endl;
      continue;
    }
    std::string sma1 = atomTypes.find(idx1)->second;
    std::string sma2 = atomTypes.find(idx2)->second;
    std::string smarts = "[$(" + sma1 + ")]" + tokens[2] + "[$(" + sma2 + ")]";
    ROMol *p = SmartsToMol(smarts);
    if (validate) {
      if (!p) {
        BOOST_LOG(rdWarningLog) << "cannot convert SMARTS " << smarts
                                << " to molecule at line " << line << std::endl;
        continue;
      }
    }
    FragmenterBondType fbt;
    fbt.atom1Type = idx1;
    fbt.atom2Type = idx2;
    if (labelByConnector) {
      fbt.atom1Label = idx1;
      fbt.atom2Label = idx2;
    } else {
      fbt.atom1Label = idx2;
      fbt.atom2Label = idx1;
    }
    if (p) {
      // for the purposes of replacing the bond, we'll use just the first
      // character to set the bond type (if we recognize it):
      switch (tokens[2][0]) {
        case '-':
          fbt.bondType = Bond::SINGLE;
          break;
        case '=':
          fbt.bondType = Bond::DOUBLE;
          break;
        case '#':
          fbt.bondType = Bond::TRIPLE;
          break;
        case ':':
          fbt.bondType = Bond::AROMATIC;
          break;
        default:
          fbt.bondType = p->getBondWithIdx(0)->getBondType();
      }
      fbt.query = ROMOL_SPTR(p);
    } else {
      fbt.bondType = Bond::UNSPECIFIED;
      fbt.query = ROMOL_SPTR();
    }
    defs.push_back(fbt);
  }
}
void logging_function2()
{
    src::logger_mt& lg = my_logger::get();
    BOOST_LOG(lg) << "Greetings from the global logger!";
}
 void on_data_sent(std::size_t size)
 {
     BOOST_LOG(m_stat) << logging::add_value("SentSize", size) << "Some data sent";
 }
 void on_data_received(std::size_t size)
 {
     BOOST_LOG(m_stat) << logging::add_value("ReceivedSize", size) << "Some data received";
 }
void logging_function()
{
    src::logger lg;
    BOOST_LOG(lg) << "Hello, world!";
}
Exemple #6
0
void FPBReader::init() {
  PRECONDITION(dp_istrm, "no stream");
  dp_impl = new detail::FPBReader_impl;
  dp_impl->istrm = dp_istrm;
  dp_impl->df_lazy = df_lazyRead;

  char magic[detail::magicSize];
  dp_istrm->read(magic, detail::magicSize);
  if (detail::FPB_MAGIC != std::string(magic, detail::magicSize)) {
    throw BadFileException("Invalid FPB magic");
  }
  while (1) {
    if (dp_istrm->eof()) throw BadFileException("EOF hit before FEND record");
    std::string chunkNm;
    boost::uint64_t chunkSz;
    boost::uint8_t *chunk = NULL;
    detail::readChunkDetails(*dp_istrm, chunkNm, chunkSz);
    // std::cerr << " Chunk: " << chunkNm << " " << chunkSz << std::endl;
    if (!df_lazyRead || (chunkNm != "AREN" && chunkNm != "FPID")) {
      detail::readChunkData(*dp_istrm, chunkSz, chunk);
      if (chunkNm == "FEND") {
        break;
      } else if (chunkNm == "POPC") {
        detail::extractPopCounts(dp_impl, chunkSz, chunk);
      } else if (chunkNm == "AREN") {
        dp_impl->dp_arenaChunk.reset(chunk);
        detail::extractArena(dp_impl, chunkSz, chunk);
        chunk = NULL;
      } else if (chunkNm == "FPID") {
        dp_impl->dp_idChunk.reset(chunk);
        detail::extractIds(dp_impl, chunkSz, chunk);
        chunk = NULL;
      } else if (chunkNm == "META") {
        // currently ignored
      } else if (chunkNm == "HASH") {
        // currently ignored
      } else {
        BOOST_LOG(rdWarningLog) << "Unknown chunk: " << chunkNm << " ignored."
                                << std::endl;
      }
      delete[] chunk;
    } else {
      // we are reading the AREN or FPID chunk in lazy mode, just get our
      // position in
      // the file.
      if (chunkNm == "AREN") {
        detail::extractArenaDetails(dp_impl, chunkSz);
      } else if (chunkNm == "FPID") {
        detail::extractIdsDetails(dp_impl, chunkSz);
      }
    }
  }
  if ((!df_lazyRead && !dp_impl->dp_arenaChunk) ||
      (df_lazyRead && !dp_impl->fpDataOffset))
    throw BadFileException("No AREN record found");
  if ((!df_lazyRead && !dp_impl->dp_idChunk) ||
      (df_lazyRead && !dp_impl->idDataOffset))
    throw BadFileException("No FPID record found");

  df_init = true;
};