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>
39template <
class entryType,
class paramType>
64 virtual unsigned int addEntry(entryType *entry,
65 bool updateFPLength =
true) = 0;
89 "A parameter object already exists on the catalog");
134template <
class entryType,
class paramType,
class orderType>
142 typedef boost::vertex_property_tag
kind;
147 typedef boost::adjacency_list<
156 typedef typename CAT_GRAPH_TRAITS::vertex_iterator
VER_ITER;
214 tmpUInt =
static_cast<unsigned int>(children.size());
216 for (RDKit::INT_VECT::const_iterator ivci = children.begin();
217 ivci != children.end(); ivci++) {
226 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
242 unsigned int tmpUInt;
246 unsigned int numEntries;
253 paramType *params =
new paramType();
254 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++) {
283 return static_cast<unsigned int>(boost::num_vertices(d_graph));
289 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
292 ss.write(text.c_str(), text.length());
306 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true)
override {
308 if (updateFPLength) {
310 entry->setBitId(fpl);
314 unsigned int eid =
static_cast<unsigned int>(
316 orderType etype = entry->getOrder();
320 if (d_orderMap.find(etype) == d_orderMap.end()) {
322 d_orderMap[etype] = nets;
324 d_orderMap[etype].push_back(eid);
338 void addEdge(
unsigned int id1,
unsigned int id2) {
346 typename CAT_GRAPH_TRAITS::edge_descriptor edge;
348 boost::tie(edge, found) = boost::edge(boost::vertex(id1, d_graph),
349 boost::vertex(id2, d_graph), d_graph);
351 boost::add_edge(id1, id2, d_graph);
359 int vd =
static_cast<int>(boost::vertex(idx, d_graph));
360 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
369 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
371 const entryType *res =
nullptr;
373 const entryType *e = pMap[i];
374 if (e->getBitId() ==
static_cast<int>(idx)) {
386 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
390 const entryType *e = pMap[i];
391 if (
static_cast<unsigned int>(e->getBitId()) == idx) {
404 boost::tie(nbrIdx, endIdx) = boost::adjacent_vertices(idx, d_graph);
405 while (nbrIdx != endIdx) {
406 res.push_back(
static_cast<int>(*nbrIdx));
416 return d_orderMap[ord];
425 typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
426 elem = d_orderMap.find(ord);
428 elem != d_orderMap.end(),
429 " catalog does not contain any entries of the order specified");
442 std::map<orderType, RDKit::INT_VECT> d_orderMap;
448 typename boost::property_map<CatalogGraph, vertex_entry_t>::type pMap =
449 boost::get(vertex_entry_t(), d_graph);
450 while (entItP.first != entItP.second) {
451 delete pMap[*(entItP.first++)];
#define CHECK_INVARIANT(expr, mess)
#define URANGE_CHECK(x, hi)
#define PRECONDITION(expr, mess)
abstract base class for a catalog object
virtual std::string Serialize() const =0
return a serialized form of the Catalog as an std::string
virtual unsigned int addEntry(entryType *entry, bool updateFPLength=true)=0
adds an entry to the catalog
unsigned int getFPLength() const
returns the length of our fingerprint
virtual void setCatalogParams(const paramType *params)
sets our parameters by copying the params argument
virtual unsigned int getNumEntries() const =0
returns the number of entries
const paramType * getCatalogParams() const
returns a pointer to our parameters
paramType * dp_cParams
our params object
unsigned int d_fpLength
the length of our fingerprint
void setFPLength(unsigned int val)
sets our fingerprint length
virtual const entryType * getEntryWithIdx(unsigned int idx) const =0
returns a particular entry in the Catalog
A Catalog with a hierarchical structure.
boost::graph_traits< CatalogGraph > CAT_GRAPH_TRAITS
CAT_GRAPH_TRAITS::vertex_iterator VER_ITER
CAT_GRAPH_TRAITS::adjacency_iterator DOWN_ENT_ITER
const entryType * getEntryWithBitId(unsigned int idx) const
returns a pointer to our entry with a particular bit ID
HierarchCatalog(const paramType *params)
Construct by making a copy of the input params object.
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord) const
returns a list of the indices that have a particular order
RDKit::INT_VECT getDownEntryList(unsigned int idx) const
returns a list of the indices of entries below the one passed in
int getIdOfEntryWithBitId(unsigned int idx) const
returns the index of the entry with a particular bit ID
unsigned int getNumEntries() const override
returns the number of entries
const entryType * getEntryWithIdx(unsigned int idx) const override
returns a pointer to our entry with a particular index
std::string Serialize() const override
serializes this object and returns the resulting pickle
void initFromStream(std::istream &ss)
fills the contents of this object from a stream containing a pickle
HierarchCatalog(const std::string &pickle)
Construct from a pickle (a serialized form of the HierarchCatalog)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, EntryProperty > CatalogGraph
the type of the graph itself:
std::pair< VER_ITER, VER_ITER > ENT_ITER_PAIR
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord)
returns a list of the indices that have a particular order
void initFromString(const std::string &text)
fills the contents of this object from a string containing a pickle
~HierarchCatalog() override
boost::property< vertex_entry_t, entryType * > EntryProperty
std::pair< DOWN_ENT_ITER, DOWN_ENT_ITER > DOWN_ENT_ITER_PAIR
unsigned int addEntry(entryType *entry, bool updateFPLength=true) override
add a new entry to the catalog
void addEdge(unsigned int id1, unsigned int id2)
adds an edge between two entries in the catalog
void toStream(std::ostream &ss) const
serializes this object to a stream
std::vector< int > INT_VECT
void streamRead(std::istream &ss, T &loc)
does a binary read of an object from a stream
void streamWrite(std::ostream &ss, const T &val)
does a binary write of an object to a stream
used by the BGL to set up the node properties in our graph
boost::vertex_property_tag kind