File: MolCatalogEntry.h

package info (click to toggle)
rdkit 202503.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,160 kB
  • sloc: cpp: 399,240; python: 77,453; ansic: 25,517; java: 8,173; javascript: 4,005; sql: 2,389; yacc: 1,565; lex: 1,263; cs: 1,081; makefile: 580; xml: 229; fortran: 183; sh: 105
file content (109 lines) | stat: -rw-r--r-- 2,926 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
//  Copyright (C) 2006 Greg Landrum
//
#include <RDGeneral/export.h>
#ifndef _RD_MOLCATALOGENTRY_H_
#define _RD_MOLCATALOGENTRY_H_

#include <RDGeneral/Dict.h>
#include <Catalogs/CatalogEntry.h>
#include <fstream>
#include <string>

namespace RDKit {
class ROMol;

//! This class is used to store ROMol objects in a MolCatalog
class RDKIT_MOLCATALOG_EXPORT MolCatalogEntry : public RDCatalog::CatalogEntry {
 public:
  MolCatalogEntry() : d_descrip("") {
    dp_props = new Dict();
    setBitId(-1);
  }

  //! copy constructor
  MolCatalogEntry(const MolCatalogEntry &other);

  //! create an entry to hold the provided ROMol
  /*!
    The MolCatalogEntry takes ownership of the pointer
   */
  MolCatalogEntry(const ROMol *omol);

  //! construct from a pickle
  MolCatalogEntry(const std::string &pickle) { this->initFromString(pickle); }

  ~MolCatalogEntry() override;

  std::string getDescription() const override { return d_descrip; }

  void setDescription(std::string val) { d_descrip = val; }

  unsigned int getOrder() const { return d_order; }
  void setOrder(unsigned int order) { d_order = order; }

  const ROMol *getMol() const { return dp_mol; }
  //! hold the provided ROMol
  /*!
    The MolCatalogEntry takes ownership of the pointer.
    If the MolCatalogEntry already has a molecule, this one will be deleted.
   */
  void setMol(const ROMol *molPtr);

  //! set a named property
  template <typename T>
  void setProp(const char *key, T &val) const {
    dp_props->setVal(key, val);
  }

  //! \overload
  template <typename T>
  void setProp(const std::string &key, T &val) const {
    setProp(key.c_str(), val);
  }

  //! get the value of a named property
  template <typename T>
  void getProp(const char *key, T &res) const {
    dp_props->getVal(key, res);
  }
  //! \overload
  template <typename T>
  void getProp(const std::string &key, T &res) const {
    getProp(key.c_str(), res);
  }

  //! returns true if such a property exists
  bool hasProp(const char *key) const {
    if (!dp_props) {
      return false;
    }
    return dp_props->hasVal(key);
  }
  //! \overload
  bool hasProp(const std::string &key) const { return hasProp(key.c_str()); }

  //! clears a named property
  void clearProp(const char *key) const { dp_props->clearVal(key); }
  //! \overload
  void clearProp(const std::string &key) const { clearProp(key.c_str()); }

  //! serializes this entry to the stream
  void toStream(std::ostream &ss) const override;
  //! returns a serialized (pickled) form of the entry
  std::string Serialize() const override;
  //! initialize from a stream containing a pickle
  void initFromStream(std::istream &ss) override;
  //! initialize from a string containing a pickle
  void initFromString(const std::string &text) override;

 private:
  const ROMol *dp_mol{nullptr};
  Dict *dp_props;

  unsigned int d_order{0};
  std::string d_descrip;
};
}  // namespace RDKit

#endif