11 #ifndef __RD_CATALOG_H__ 12 #define __RD_CATALOG_H__ 16 #include <boost/graph/graph_traits.hpp> 17 #include <boost/graph/adjacency_list.hpp> 18 #include <boost/version.hpp> 19 #if BOOST_VERSION >= 104000 20 #include <boost/property_map/property_map.hpp> 22 #include <boost/property_map.hpp> 38 template <
class entryType,
class paramType>
52 virtual std::string
Serialize()
const = 0;
63 virtual unsigned int addEntry(entryType *entry,
64 bool updateFPLength =
true) = 0;
88 "A parameter object already exists on the catalog");
133 template <
class entryType,
class paramType,
class orderType>
141 typedef boost::vertex_property_tag
kind;
146 typedef boost::adjacency_list<
154 typedef typename CAT_GRAPH_TRAITS::vertex_iterator
VER_ITER;
172 this->initFromString(
pickle);
215 tmpUInt =
static_cast<unsigned int>(children.size());
217 for (RDKit::INT_VECT::const_iterator ivci = children.begin();
218 ivci != children.end(); ivci++) {
227 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
243 unsigned int tmpUInt;
247 unsigned int numEntries;
254 paramType *params =
new paramType();
255 params->initFromStream(ss);
264 for (
unsigned int i = 0; i < numEntries; i++) {
265 entryType *entry =
new entryType();
266 entry->initFromStream(ss);
271 for (
unsigned int i = 0; i < numEntries; i++) {
272 unsigned int nNeighbors;
274 for (
unsigned int j = 0; j < nNeighbors; j++) {
276 this->addEdge(i, tmpInt);
282 unsigned int getNumEntries()
const {
return static_cast<unsigned int>(boost::num_vertices(d_graph)); }
287 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
290 ss.write(text.c_str(), text.length());
292 this->initFromStream(ss);
304 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true) {
306 if (updateFPLength) {
308 entry->setBitId(fpl);
312 unsigned int eid =
static_cast<unsigned int>(boost::add_vertex(EntryProperty(entry), d_graph));
313 orderType etype = entry->getOrder();
317 if (d_orderMap.find(etype) == d_orderMap.end()) {
319 d_orderMap[etype] = nets;
321 d_orderMap[etype].push_back(eid);
335 void addEdge(
unsigned int id1,
unsigned int id2) {
343 typename CAT_GRAPH_TRAITS::edge_descriptor edge;
345 boost::tie(edge, found) = boost::edge(boost::vertex(id1, d_graph),
346 boost::vertex(id2, d_graph), d_graph);
348 boost::add_edge(id1, id2, d_graph);
356 int vd =
static_cast<int>(boost::vertex(idx, d_graph));
357 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
366 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
368 const entryType *res = NULL;
370 const entryType *e = pMap[i];
371 if (e->getBitId() ==
static_cast<int>(idx)) {
383 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
387 const entryType *e = pMap[i];
388 if (static_cast<unsigned int>(e->getBitId()) == idx) {
400 DOWN_ENT_ITER nbrIdx, endIdx;
401 boost::tie(nbrIdx, endIdx) = boost::adjacent_vertices(idx, d_graph);
402 while (nbrIdx != endIdx) {
403 res.push_back(static_cast<int>(*nbrIdx));
413 return d_orderMap[ord];
422 typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
423 elem = d_orderMap.find(ord);
425 elem != d_orderMap.end(),
426 " catalog does not contain any entries of the order specified");
432 CatalogGraph d_graph;
439 std::map<orderType, RDKit::INT_VECT> d_orderMap;
444 ENT_ITER_PAIR entItP = boost::vertices(d_graph);
445 typename boost::property_map<CatalogGraph, vertex_entry_t>::type pMap =
447 while (entItP.first != entItP.second) {
448 delete pMap[*(entItP.first++)];
459 template <
class entryType,
class orderType>
468 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true);
473 std::vector<entryType *> d_vector;
virtual const entryType * getEntryWithIdx(unsigned int idx) const =0
returns a particular entry in the Catalog
void initFromString(const std::string &text)
fills the contents of this object from a string containing a pickle
CAT_GRAPH_TRAITS::adjacency_iterator DOWN_ENT_ITER
used by the BGL to set up the node properties in our graph
unsigned int getFPLength() const
returns the length of our fingerprint
int getIdOfEntryWithBitId(unsigned int idx) const
returns the index of the entry with a particular bit ID
virtual std::string Serialize() const =0
return a serialized form of the Catalog as an std::string
#define CHECK_INVARIANT(expr, mess)
boost::vertex_property_tag kind
virtual void setCatalogParams(paramType *params)
sets our parameters by copying the params argument
virtual unsigned int addEntry(entryType *entry, bool updateFPLength=true)=0
adds an entry to the catalog
void streamRead(std::istream &ss, T &loc)
does a binary read of an object from a stream
boost::graph_traits< CatalogGraph > CAT_GRAPH_TRAITS
unsigned int getNumEntries() const
returns the number of entries
virtual unsigned int getNumEntries() const =0
returns the number of entries
std::pair< DOWN_ENT_ITER, DOWN_ENT_ITER > DOWN_ENT_ITER_PAIR
a linear Catalog (analogous to an std::vector)
A Catalog with a hierarchical structure.
std::pair< VER_ITER, VER_ITER > ENT_ITER_PAIR
void initFromStream(std::istream &ss)
fills the contents of this object from a stream containing a pickle
const entryType * getEntryWithIdx(unsigned int idx) const
returns a pointer to our entry with a particular index
abstract base class for a catalog object
void toStream(std::ostream &ss) const
serializes this object to a stream
const paramType * getCatalogParams() const
returns a pointer to our parameters
std::string Serialize() const
serializes this object and returns the resulting pickle
std::vector< int > INT_VECT
CAT_GRAPH_TRAITS::vertex_iterator VER_ITER
boost::property< vertex_entry_t, entryType * > EntryProperty
const entryType * getEntryWithBitId(unsigned int idx) const
returns a pointer to our entry with a particular bit ID
#define URANGE_CHECK(x, hi)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, EntryProperty > CatalogGraph
the type of the graph itself:
void streamWrite(std::ostream &ss, const T &val)
does a binary write of an object to a stream
#define PRECONDITION(expr, mess)
unsigned int d_fpLength
the length of our fingerprint
paramType * dp_cParams
our params object
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord)
returns a list of the indices that have a particular order
std::ostream & toStream(std::ostream &)
void addEdge(unsigned int id1, unsigned int id2)
adds an edge between two entries in the catalog
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord) const
returns a list of the indices that have a particular order
unsigned int addEntry(entryType *entry, bool updateFPLength=true)
add a new entry to the catalog
void setFPLength(unsigned int val)
sets our fingerprint length
void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
RDKit::INT_VECT getDownEntryList(unsigned int idx) const
returns a list of the indices of entries below the one passed in