12 #ifndef __RD_CATALOG_H__ 13 #define __RD_CATALOG_H__ 17 #include <boost/graph/graph_traits.hpp> 18 #include <boost/graph/adjacency_list.hpp> 19 #include <boost/version.hpp> 20 #if BOOST_VERSION >= 104000 21 #include <boost/property_map/property_map.hpp> 23 #include <boost/property_map.hpp> 39 template <
class entryType,
class paramType>
53 virtual std::string
Serialize()
const = 0;
64 virtual unsigned int addEntry(entryType *entry,
65 bool updateFPLength =
true) = 0;
89 "A parameter object already exists on the catalog");
134 template <
class entryType,
class paramType,
class orderType>
142 typedef boost::vertex_property_tag
kind;
147 typedef boost::adjacency_list<
155 typedef typename CAT_GRAPH_TRAITS::vertex_iterator
VER_ITER;
173 this->initFromString(
pickle);
216 tmpUInt =
static_cast<unsigned int>(children.size());
218 for (RDKit::INT_VECT::const_iterator ivci = children.begin();
219 ivci != children.end(); ivci++) {
228 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
244 unsigned int tmpUInt;
248 unsigned int numEntries;
255 paramType *params =
new paramType();
256 params->initFromStream(ss);
265 for (
unsigned int i = 0; i < numEntries; i++) {
266 entryType *entry =
new entryType();
267 entry->initFromStream(ss);
272 for (
unsigned int i = 0; i < numEntries; i++) {
273 unsigned int nNeighbors;
275 for (
unsigned int j = 0; j < nNeighbors; j++) {
277 this->addEdge(i, tmpInt);
283 unsigned int getNumEntries()
const {
return static_cast<unsigned int>(boost::num_vertices(d_graph)); }
288 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
291 ss.write(text.c_str(), text.length());
293 this->initFromStream(ss);
305 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true) {
307 if (updateFPLength) {
309 entry->setBitId(fpl);
313 unsigned int eid =
static_cast<unsigned int>(boost::add_vertex(EntryProperty(entry), d_graph));
314 orderType etype = entry->getOrder();
318 if (d_orderMap.find(etype) == d_orderMap.end()) {
320 d_orderMap[etype] = nets;
322 d_orderMap[etype].push_back(eid);
336 void addEdge(
unsigned int id1,
unsigned int id2) {
344 typename CAT_GRAPH_TRAITS::edge_descriptor edge;
346 boost::tie(edge, found) = boost::edge(boost::vertex(id1, d_graph),
347 boost::vertex(id2, d_graph), d_graph);
349 boost::add_edge(id1, id2, d_graph);
357 int vd =
static_cast<int>(boost::vertex(idx, d_graph));
358 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
367 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
369 const entryType *res = NULL;
371 const entryType *e = pMap[i];
372 if (e->getBitId() ==
static_cast<int>(idx)) {
384 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
388 const entryType *e = pMap[i];
389 if (static_cast<unsigned int>(e->getBitId()) == idx) {
401 DOWN_ENT_ITER nbrIdx, endIdx;
402 boost::tie(nbrIdx, endIdx) = boost::adjacent_vertices(idx, d_graph);
403 while (nbrIdx != endIdx) {
404 res.push_back(static_cast<int>(*nbrIdx));
414 return d_orderMap[ord];
423 typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
424 elem = d_orderMap.find(ord);
426 elem != d_orderMap.end(),
427 " catalog does not contain any entries of the order specified");
433 CatalogGraph d_graph;
440 std::map<orderType, RDKit::INT_VECT> d_orderMap;
445 ENT_ITER_PAIR entItP = boost::vertices(d_graph);
446 typename boost::property_map<CatalogGraph, vertex_entry_t>::type pMap =
448 while (entItP.first != entItP.second) {
449 delete pMap[*(entItP.first++)];
460 template <
class entryType,
class orderType>
469 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true);
474 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
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)
unsigned int getNumEntries() const
returns the number of entries
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
RDKIT_CHEMREACTIONS_EXPORT void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss
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 RDKit::INT_VECT & getEntriesOfOrder(orderType ord) const
returns a list of the indices that have a particular order
abstract base class for a catalog object
std::string Serialize() const
serializes this object and returns the resulting pickle
const paramType * getCatalogParams() const
returns a pointer to our parameters
std::vector< int > INT_VECT
CAT_GRAPH_TRAITS::vertex_iterator VER_ITER
RDKit::INT_VECT getDownEntryList(unsigned int idx) const
returns a list of the indices of entries below the one passed in
boost::property< vertex_entry_t, entryType * > EntryProperty
const entryType * getEntryWithIdx(unsigned int idx) const
returns a pointer to our entry with a particular index
#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)
RDKIT_RDGENERAL_EXPORT std::ostream & toStream(std::ostream &)
unsigned int d_fpLength
the length of our fingerprint
const entryType * getEntryWithBitId(unsigned int idx) const
returns a pointer to our entry with a particular bit ID
paramType * dp_cParams
our params object
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord)
returns a list of the indices that have a particular order
void addEdge(unsigned int id1, unsigned int id2)
adds an edge between two entries in the catalog
unsigned int getFPLength() const
returns the length of our fingerprint
unsigned int addEntry(entryType *entry, bool updateFPLength=true)
add a new entry to the catalog
void toStream(std::ostream &ss) const
serializes this object to a stream
void setFPLength(unsigned int val)
sets our fingerprint length