 |
RDKit
Open-source cheminformatics and machine learning.
|
Go to the documentation of this file.
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<
156 typedef typename CAT_GRAPH_TRAITS::vertex_iterator
VER_ITER;
167 :
Catalog<entryType, paramType>() {
217 tmpUInt =
static_cast<unsigned int>(children.size());
219 for (RDKit::INT_VECT::const_iterator ivci = children.begin();
220 ivci != children.end(); ivci++) {
229 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
245 unsigned int tmpUInt;
249 unsigned int numEntries;
256 paramType *params =
new paramType();
257 params->initFromStream(ss);
267 for (
unsigned int i = 0; i < numEntries; i++) {
268 entryType *entry =
new entryType();
269 entry->initFromStream(ss);
274 for (
unsigned int i = 0; i < numEntries; i++) {
275 unsigned int nNeighbors;
277 for (
unsigned int j = 0; j < nNeighbors; j++) {
286 return static_cast<unsigned int>(boost::num_vertices(d_graph));
292 std::stringstream ss(std::ios_base::binary | std::ios_base::out |
295 ss.write(text.c_str(), text.length());
309 unsigned int addEntry(entryType *entry,
bool updateFPLength =
true) {
311 if (updateFPLength) {
313 entry->setBitId(fpl);
317 unsigned int eid =
static_cast<unsigned int>(
319 orderType etype = entry->getOrder();
323 if (d_orderMap.find(etype) == d_orderMap.end()) {
325 d_orderMap[etype] = nets;
327 d_orderMap[etype].push_back(eid);
341 void addEdge(
unsigned int id1,
unsigned int id2) {
349 typename CAT_GRAPH_TRAITS::edge_descriptor edge;
351 boost::tie(edge, found) = boost::edge(boost::vertex(id1, d_graph),
352 boost::vertex(id2, d_graph), d_graph);
354 boost::add_edge(id1, id2, d_graph);
362 int vd =
static_cast<int>(boost::vertex(idx, d_graph));
363 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
372 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
374 const entryType *res = NULL;
376 const entryType *e = pMap[i];
377 if (e->getBitId() ==
static_cast<int>(idx)) {
389 typename boost::property_map<CatalogGraph, vertex_entry_t>::const_type
393 const entryType *e = pMap[i];
394 if (
static_cast<unsigned int>(e->getBitId()) == idx) {
407 boost::tie(nbrIdx, endIdx) = boost::adjacent_vertices(idx, d_graph);
408 while (nbrIdx != endIdx) {
409 res.push_back(
static_cast<int>(*nbrIdx));
419 return d_orderMap[ord];
428 typename std::map<orderType, RDKit::INT_VECT>::const_iterator elem;
429 elem = d_orderMap.find(ord);
431 elem != d_orderMap.end(),
432 " catalog does not contain any entries of the order specified");
445 std::map<orderType, RDKit::INT_VECT> d_orderMap;
451 typename boost::property_map<CatalogGraph, vertex_entry_t>::type pMap =
452 boost::get(vertex_entry_t(), d_graph);
453 while (entItP.first != entItP.second) {
454 delete pMap[*(entItP.first++)];
paramType * dp_cParams
our params object
boost::property< vertex_entry_t, entryType * > EntryProperty
unsigned int getNumEntries() const
returns the number of entries
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
boost::graph_traits< CatalogGraph > CAT_GRAPH_TRAITS
std::vector< int > INT_VECT
used by the BGL to set up the node properties in our graph
void initFromString(const std::string &text)
fills the contents of this object from a string containing a pickle
const entryType * getEntryWithIdx(unsigned int idx) const
returns a pointer to our entry with a particular index
virtual const entryType * getEntryWithIdx(unsigned int idx) const =0
returns a particular entry in the Catalog
virtual std::string Serialize() const =0
return a serialized form of the Catalog as an std::string
void setFPLength(unsigned int val)
sets our fingerprint length
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord) const
returns a list of the indices that have a particular order
#define CHECK_INVARIANT(expr, mess)
void streamRead(std::istream &ss, T &loc)
does a binary read of an object from a stream
int getIdOfEntryWithBitId(unsigned int idx) const
returns the index of the entry with a particular bit ID
virtual unsigned int getNumEntries() const =0
returns the number of entries
const RDKit::INT_VECT & getEntriesOfOrder(orderType ord)
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
A Catalog with a hierarchical structure.
void addEdge(unsigned int id1, unsigned int id2)
adds an edge between two entries in the catalog
void streamWrite(std::ostream &ss, const T &val)
does a binary write of an object to a stream
void initFromStream(std::istream &ss)
fills the contents of this object from a stream containing a pickle
abstract base class for a catalog object
CAT_GRAPH_TRAITS::vertex_iterator VER_ITER
std::pair< VER_ITER, VER_ITER > ENT_ITER_PAIR
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, EntryProperty > CatalogGraph
the type of the graph itself:
unsigned int d_fpLength
the length of our fingerprint
RDKit::INT_VECT getDownEntryList(unsigned int idx) const
returns a list of the indices of entries below the one passed in
const paramType * getCatalogParams() const
returns a pointer to our parameters
const entryType * getEntryWithBitId(unsigned int idx) const
returns a pointer to our entry with a particular bit ID
std::string Serialize() const
serializes this object and returns the resulting pickle
CAT_GRAPH_TRAITS::adjacency_iterator DOWN_ENT_ITER
#define PRECONDITION(expr, mess)
#define URANGE_CHECK(x, hi)
virtual unsigned int addEntry(entryType *entry, bool updateFPLength=true)=0
adds an entry to the catalog
std::pair< DOWN_ENT_ITER, DOWN_ENT_ITER > DOWN_ENT_ITER_PAIR
void toStream(std::ostream &ss) const
serializes this object to a stream
virtual void setCatalogParams(const paramType *params)
sets our parameters by copying the params argument
boost::vertex_property_tag kind
unsigned int getFPLength() const
returns the length of our fingerprint