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