RDKit: Feature.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Feature.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef __FEATURE_H_30112004_1121__
11 #define __FEATURE_H_30112004_1121__
12
13 #include <vector>
14 #include <Geometry/point.h>
15
16 namespace RDFeatures {
17 template <typename FAMILYMARKER, typename TYPEMARKER = FAMILYMARKER,
18 typename LOCTYPE = RDGeom::Point3D>
19 class ExplicitFeature {
20 public:
21 ExplicitFeature(){};
22 explicit ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
23 : d_family(f), d_type(t){};
24 ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t,
25 const LOCTYPE &loc)
26 : d_family(f), d_type(t), d_loc(loc){};
27
28 const FAMILYMARKER &getFamily() const { return d_family; };
29 void setFamily(const FAMILYMARKER &f) { d_family = f; };
30
31 const TYPEMARKER &getType() const { return d_type; };
32 void setType(const TYPEMARKER &t) { d_type = t; };
33
34 const LOCTYPE &getLoc() const { return d_loc; };
35 void setLoc(const LOCTYPE &loc) { d_loc = loc; };
36
37 const std::vector<LOCTYPE> &getDirs() const { return d_dirs; };
38 std::vector<LOCTYPE> &getDirs() { return d_dirs; };
39
40 private:
41 FAMILYMARKER d_family;
42 TYPEMARKER d_type;
43 LOCTYPE d_loc;
44 std::vector<LOCTYPE> d_dirs;
45 };
46
47 template <typename FAMILYMARKER, typename TYPEMARKER = FAMILYMARKER,
48 typename LOCTYPE = RDGeom::Point3D>
49 class ImplicitFeature {
50 public:
51 ImplicitFeature() : d_weightSum(0.0){};
52 explicit ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
53 : d_weightSum(0.0), d_family(f), d_type(t){};
54
55 const FAMILYMARKER &getFamily() const { return d_family; };
56 void setFamily(const FAMILYMARKER &f) { d_family = f; };
57
58 const TYPEMARKER &getType() const { return d_type; };
59 void setType(const TYPEMARKER &t) { d_type = t; };
60
61 LOCTYPE getLoc() const {
62 PRECONDITION(d_weights.size() == d_locs.size(), "weight/locs mismatch");
63 LOCTYPE accum;
64 for (unsigned int i = 0; i < d_weights.size(); i++) {
65 LOCTYPE tmp = *d_locs[i];
66 tmp *= d_weights[i] / d_weightSum;
67 accum += tmp;
68 }
69 return accum;
70 };
71 void addPoint(const LOCTYPE *p, double weight = 1.0) {
72 d_locs.push_back(p);
73 d_weights.push_back(weight);
74 d_weightSum += weight;
75 }
76 void reset() {
77 d_locs.clear();
78 d_weights.clear();
79 d_weightSum = 0.0;
80 }
81
82 const std::vector<LOCTYPE> &getDirs() const { return d_dirs; };
83 std::vector<LOCTYPE> &getDirs() { return d_dirs; };
84
85 private:
86 double d_weightSum;
87 FAMILYMARKER d_family;
88 TYPEMARKER d_type;
89 std::vector<double> d_weights;
90 std::vector<const LOCTYPE *> d_locs;
91 // FIX: add something correct for directions
92 std::vector<LOCTYPE> d_dirs;
93 };
94 }
95 #endif
RDFeatures::ImplicitFeature::setFamily
void setFamily(const FAMILYMARKER &f)
Definition: Feature.h:56
RDFeatures::ImplicitFeature::ImplicitFeature
ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition: Feature.h:52
RDFeatures::ExplicitFeature::setFamily
void setFamily(const FAMILYMARKER &f)
Definition: Feature.h:29
RDFeatures::ImplicitFeature
Definition: Feature.h:49
RDFeatures::ExplicitFeature::getLoc
const LOCTYPE & getLoc() const
Definition: Feature.h:34
point.h
RDFeatures::ImplicitFeature::getDirs
const std::vector< LOCTYPE > & getDirs() const
Definition: Feature.h:82
RDFeatures::ImplicitFeature::getFamily
const FAMILYMARKER & getFamily() const
Definition: Feature.h:55
RDFeatures::ExplicitFeature
Definition: Feature.h:19
RDFeatures::ImplicitFeature::getType
const TYPEMARKER & getType() const
Definition: Feature.h:58
RDFeatures::ImplicitFeature::getDirs
std::vector< LOCTYPE > & getDirs()
Definition: Feature.h:83
RDFeatures::ImplicitFeature::ImplicitFeature
ImplicitFeature()
Definition: Feature.h:51
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t, const LOCTYPE &loc)
Definition: Feature.h:24
RDFeatures
Definition: Feature.h:16
RDFeatures::ImplicitFeature::reset
void reset()
Definition: Feature.h:76
RDFeatures::ExplicitFeature::setType
void setType(const TYPEMARKER &t)
Definition: Feature.h:32
RDFeatures::ExplicitFeature::getType
const TYPEMARKER & getType() const
Definition: Feature.h:31
RDGeom::Point3D
Definition: point.h:45
RDFeatures::ExplicitFeature::getDirs
std::vector< LOCTYPE > & getDirs()
Definition: Feature.h:38
RDFeatures::ExplicitFeature::getFamily
const FAMILYMARKER & getFamily() const
Definition: Feature.h:28
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition: Feature.h:22
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:107
RDFeatures::ImplicitFeature::getLoc
LOCTYPE getLoc() const
Definition: Feature.h:61
RDFeatures::ImplicitFeature::addPoint
void addPoint(const LOCTYPE *p, double weight=1.0)
Definition: Feature.h:71
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature()
Definition: Feature.h:21
RDFeatures::ExplicitFeature::setLoc
void setLoc(const LOCTYPE &loc)
Definition: Feature.h:35
RDFeatures::ExplicitFeature::getDirs
const std::vector< LOCTYPE > & getDirs() const
Definition: Feature.h:37
RDFeatures::ImplicitFeature::setType
void setType(const TYPEMARKER &t)
Definition: Feature.h:59