11 #ifndef __RD_CATALOG_H__ 12 #define __RD_CATALOG_H__ 15 #include <boost/graph/graph_traits.hpp> 16 #include <boost/graph/adjacency_list.hpp> 17 #include <boost/version.hpp> 18 #if BOOST_VERSION >= 104000 19 #include <boost/property_map/property_map.hpp> 21 #include <boost/property_map.hpp> 37 template <
class entryType,
class paramType>
50 virtual std::string
Serialize()
const = 0;
61 virtual unsigned int addEntry(entryType *entry,
bool updateFPLength =
true) = 0;
132 template <
class entryType,
class paramType,
class orderType>
140 typedef boost::vertex_property_tag
kind;
145 typedef boost::adjacency_list<boost::vecS,
148 boost::bidirectionalS,
152 typedef typename CAT_GRAPH_TRAITS::vertex_iterator
VER_ITER;
169 this->initFromString(pickle);
213 tmpUInt = children.size();
215 for(RDKit::INT_VECT::const_iterator ivci=children.begin();
216 ivci!=children.end();
226 std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
241 unsigned int tmpUInt;
245 unsigned int numEntries;
252 paramType *params =
new paramType();
253 params->initFromStream(ss);
262 for(
unsigned int i=0;i<numEntries;i++){
263 entryType *entry =
new entryType();
264 entry->initFromStream(ss);
269 for(
unsigned int i=0;i<numEntries;i++){
270 unsigned int nNeighbors;
272 for(
unsigned int j=0;j<nNeighbors;j++){
274 this->addEdge(i,tmpInt);
281 return boost::num_vertices(d_graph);
287 std::stringstream ss(std::ios_base::binary|std::ios_base::out|std::ios_base::in);
289 ss.write(text.c_str(),text.length());
291 this->initFromStream(ss);
303 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true){
305 if (updateFPLength) {
307 entry->setBitId(fpl);
311 unsigned int eid = boost::add_vertex(EntryProperty(entry), d_graph);
312 orderType etype = entry->getOrder();
316 if (d_orderMap.find(etype) == d_orderMap.end()) {
318 d_orderMap[etype] = nets;
320 d_orderMap[etype].push_back(eid);
334 void addEdge(
unsigned int id1,
unsigned int id2) {
342 typename CAT_GRAPH_TRAITS::edge_descriptor edge;
344 boost::tie(edge,found) = boost::edge(boost::vertex(id1,d_graph),
345 boost::vertex(id2,d_graph),
348 boost::add_edge(id1, id2, d_graph);
356 int vd = 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(*nbrIdx);
413 return d_orderMap[ord];
422 typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
423 elem = d_orderMap.find(ord);
424 CHECK_INVARIANT(elem!=d_orderMap.end(),
" catalog does not contain any entries of the order specified");
431 CatalogGraph d_graph;
437 std::map<orderType, RDKit::INT_VECT> d_orderMap;
442 ENT_ITER_PAIR entItP = boost::vertices(d_graph);
443 typename boost::property_map < CatalogGraph, vertex_entry_t>::type
445 while (entItP.first != entItP.second) {
446 delete pMap[*(entItP.first++)];
461 template <
class entryType,
class orderType>
470 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true);
475 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
#define RANGE_CHECK(lo, x, hi)
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)
void setCatalogParams(paramType *params)
sets our parameters by copying the params argument
boost::vertex_property_tag kind
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
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, EntryProperty > CatalogGraph
the type of the graph itself:
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
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
RDKit::INT_VECT getDownEntryList(unsigned int idx) const
returns a list of the indices of entries below the one passed in