RDKit: MolCatalogEntry.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
MolCatalogEntry.h
Go to the documentation of this file.
1//
2// Copyright (C) 2006 Greg Landrum
3//
4#include <RDGeneral/export.h>
5#ifndef _RD_MOLCATALOGENTRY_H_
6#define _RD_MOLCATALOGENTRY_H_
7
8#include <RDGeneral/Dict.h>
9#include <Catalogs/CatalogEntry.h>
10#include <fstream>
11#include <string>
12
13namespace RDKit {
14class ROMol;
15
16//! This class is used to store ROMol objects in a MolCatalog
17 class RDKIT_MOLCATALOG_EXPORT MolCatalogEntry : public RDCatalog::CatalogEntry {
18 public:
19 MolCatalogEntry() : d_descrip("") {
20 dp_props = new Dict();
21 setBitId(-1);
22 }
23
24 //! copy constructor
25 MolCatalogEntry(const MolCatalogEntry &other);
26
27 //! create an entry to hold the provided ROMol
28 /*!
29 The MolCatalogEntry takes ownership of the pointer
30 */
31 MolCatalogEntry(const ROMol *omol);
32
33 //! construct from a pickle
34 MolCatalogEntry(const std::string &pickle) { this->initFromString(pickle); }
35
36 ~MolCatalogEntry() override;
37
38 std::string getDescription() const override { return d_descrip; }
39
40 void setDescription(std::string val) { d_descrip = val; }
41
42 unsigned int getOrder() const { return d_order; }
43 void setOrder(unsigned int order) { d_order = order; }
44
45 const ROMol *getMol() const { return dp_mol; }
46 //! hold the provided ROMol
47 /*!
48 The MolCatalogEntry takes ownership of the pointer.
49 If the MolCatalogEntry already has a molecule, this one will be deleted.
50 */
51 void setMol(const ROMol *molPtr);
52
53 //! set a named property
54 template <typename T>
55 void setProp(const char *key, T &val) const {
56 dp_props->setVal(key, val);
57 }
58
59 //! \overload
60 template <typename T>
61 void setProp(const std::string &key, T &val) const {
62 setProp(key.c_str(), val);
63 }
64
65 //! get the value of a named property
66 template <typename T>
67 void getProp(const char *key, T &res) const {
68 dp_props->getVal(key, res);
69 }
70 //! \overload
71 template <typename T>
72 void getProp(const std::string &key, T &res) const {
73 getProp(key.c_str(), res);
74 }
75
76 //! returns true if such a property exists
77 bool hasProp(const char *key) const {
78 if (!dp_props) {
79 return false;
80 }
81 return dp_props->hasVal(key);
82 }
83 //! \overload
84 bool hasProp(const std::string &key) const { return hasProp(key.c_str()); }
85
86 //! clears a named property
87 void clearProp(const char *key) const { dp_props->clearVal(key); }
88 //! \overload
89 void clearProp(const std::string &key) const { clearProp(key.c_str()); }
90
91 //! serializes this entry to the stream
92 void toStream(std::ostream &ss) const override;
93 //! returns a serialized (pickled) form of the entry
94 std::string Serialize() const override;
95 //! initialize from a stream containing a pickle
96 void initFromStream(std::istream &ss) override;
97 //! initialize from a string containing a pickle
98 void initFromString(const std::string &text) override;
99
100 private:
101 const ROMol *dp_mol{nullptr};
102 Dict *dp_props;
103
104 unsigned int d_order{0};
105 std::string d_descrip;
106};
107} // namespace RDKit
108
109#endif
CatalogEntry.h
Dict.h
Defines the Dict class.
RDCatalog::CatalogEntry
Abstract base class to be used to represent an entry in a Catalog.
Definition CatalogEntry.h:19
RDCatalog::CatalogEntry::setBitId
void setBitId(int bid)
sets our bit Id
Definition CatalogEntry.h:24
RDKit::Dict
The Dict class can be used to store objects of arbitrary type keyed by strings.
Definition Dict.h:36
RDKit::MolCatalogEntry::getOrder
unsigned int getOrder() const
Definition MolCatalogEntry.h:42
RDKit::MolCatalogEntry::clearProp
void clearProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition MolCatalogEntry.h:89
RDKit::MolCatalogEntry::setMol
void setMol(const ROMol *molPtr)
hold the provided ROMol
RDKit::MolCatalogEntry::initFromString
void initFromString(const std::string &text) override
initialize from a string containing a pickle
RDKit::MolCatalogEntry::MolCatalogEntry
MolCatalogEntry(const std::string &pickle)
construct from a pickle
Definition MolCatalogEntry.h:34
RDKit::MolCatalogEntry::getMol
const ROMol * getMol() const
Definition MolCatalogEntry.h:45
RDKit::MolCatalogEntry::setOrder
void setOrder(unsigned int order)
Definition MolCatalogEntry.h:43
RDKit::MolCatalogEntry::getProp
void getProp(const char *key, T &res) const
get the value of a named property
Definition MolCatalogEntry.h:67
RDKit::MolCatalogEntry::setProp
void setProp(const char *key, T &val) const
set a named property
Definition MolCatalogEntry.h:55
RDKit::MolCatalogEntry::setProp
void setProp(const std::string &key, T &val) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition MolCatalogEntry.h:61
RDKit::MolCatalogEntry::MolCatalogEntry
MolCatalogEntry(const MolCatalogEntry &other)
copy constructor
RDKit::MolCatalogEntry::clearProp
void clearProp(const char *key) const
clears a named property
Definition MolCatalogEntry.h:87
RDKit::MolCatalogEntry::toStream
void toStream(std::ostream &ss) const override
serializes this entry to the stream
RDKit::MolCatalogEntry::setDescription
void setDescription(std::string val)
Definition MolCatalogEntry.h:40
RDKit::MolCatalogEntry::initFromStream
void initFromStream(std::istream &ss) override
initialize from a stream containing a pickle
RDKit::MolCatalogEntry::~MolCatalogEntry
~MolCatalogEntry() override
RDKit::MolCatalogEntry::Serialize
std::string Serialize() const override
returns a serialized (pickled) form of the entry
RDKit::MolCatalogEntry::getDescription
std::string getDescription() const override
returns a text description of this entry
Definition MolCatalogEntry.h:38
RDKit::MolCatalogEntry::getProp
void getProp(const std::string &key, T &res) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition MolCatalogEntry.h:72
RDKit::MolCatalogEntry::MolCatalogEntry
MolCatalogEntry(const ROMol *omol)
create an entry to hold the provided ROMol
RDKit::MolCatalogEntry::hasProp
bool hasProp(const char *key) const
returns true if such a property exists
Definition MolCatalogEntry.h:77
RDKit::MolCatalogEntry::MolCatalogEntry
MolCatalogEntry()
Definition MolCatalogEntry.h:19
RDKit::MolCatalogEntry::hasProp
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition MolCatalogEntry.h:84
RDKit::ROMol
Definition ROMol.h:199
export.h
RDKIT_MOLCATALOG_EXPORT
#define RDKIT_MOLCATALOG_EXPORT
Definition export.h:297
RDKit
Std stuff.
Definition Abbreviations.h:19