1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
//
// Copyright (C) 2018 Susan H. Leung
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include "FragmentCatalogEntry.h"
#include <RDGeneral/types.h>
#include <RDGeneral/utils.h>
#include <GraphMol/RDKitBase.h>
#include <RDGeneral/StreamOps.h>
#include <GraphMol/MolPickler.h>
#include <iostream>
#include <fstream>
namespace RDKit {
namespace MolStandardize {
// FragmentCatalogEntry::FragmentCatalogEntry(const ROMol *omol, const PATH_TYPE
// &path) { PRECONDITION(omol, "bad mol");
//}
//
// FragmentCatalogEntry::FragmentCatalogEntry(const std::string &pickle) {
// dp_props = new Dict();
// this->initFromString(pickle);
//}
void FragmentCatalogEntry::toStream(std::ostream &ss) const {
MolPickler::pickleMol(*dp_mol, ss);
boost::int32_t tmpInt;
tmpInt = getBitId();
streamWrite(ss, tmpInt);
tmpInt = d_descrip.size();
streamWrite(ss, tmpInt);
ss.write(d_descrip.c_str(), tmpInt * sizeof(char));
}
std::string FragmentCatalogEntry::Serialize() const {
std::stringstream ss(std::ios_base::binary | std::ios_base::out |
std::ios_base::in);
toStream(ss);
return ss.str();
}
void FragmentCatalogEntry::initFromStream(std::istream &ss) {
// the molecule:
dp_mol = new ROMol();
MolPickler::molFromPickle(ss, *dp_mol);
boost::int32_t tmpInt;
// the bitId:
streamRead(ss, tmpInt);
setBitId(tmpInt);
// the description:
streamRead(ss, tmpInt);
char *tmpText = new char[tmpInt + 1];
ss.read(tmpText, tmpInt * sizeof(char));
tmpText[tmpInt] = 0;
d_descrip = tmpText;
delete[] tmpText;
}
void FragmentCatalogEntry::initFromString(const std::string &text) {
std::stringstream ss(std::ios_base::binary | std::ios_base::out |
std::ios_base::in);
// initialize the stream:
ss.write(text.c_str(), text.length());
// now start reading out values:
initFromStream(ss);
}
} // namespace MolStandardize
} // namespace RDKit
|