RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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#include <RDGeneral/export.h>
11#ifndef __FEATURE_H_30112004_1121__
12#define __FEATURE_H_30112004_1121__
13
14#include <vector>
15#include <Geometry/point.h>
16
17namespace RDFeatures {
18template <typename FAMILYMARKER, typename TYPEMARKER = FAMILYMARKER,
19 typename LOCTYPE = RDGeom::Point3D>
21 public:
23 explicit ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
24 : d_family(f), d_type(t) {}
25 ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t,
26 const LOCTYPE &loc)
27 : d_family(f), d_type(t), d_loc(loc) {}
28
29 const FAMILYMARKER &getFamily() const { return d_family; }
30 void setFamily(const FAMILYMARKER &f) { d_family = f; }
31
32 const TYPEMARKER &getType() const { return d_type; }
33 void setType(const TYPEMARKER &t) { d_type = t; }
34
35 const LOCTYPE &getLoc() const { return d_loc; }
36 void setLoc(const LOCTYPE &loc) { d_loc = loc; }
37
38 const std::vector<LOCTYPE> &getDirs() const { return d_dirs; }
39 std::vector<LOCTYPE> &getDirs() { return d_dirs; }
40
41 private:
42 FAMILYMARKER d_family;
43 TYPEMARKER d_type;
44 LOCTYPE d_loc;
45 std::vector<LOCTYPE> d_dirs;
46};
47
48template <typename FAMILYMARKER, typename TYPEMARKER = FAMILYMARKER,
49 typename LOCTYPE = RDGeom::Point3D>
51 public:
52 ImplicitFeature() : d_weightSum(0.0) {}
53 explicit ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
54 : d_weightSum(0.0), d_family(f), d_type(t) {}
55
56 const FAMILYMARKER &getFamily() const { return d_family; }
57 void setFamily(const FAMILYMARKER &f) { d_family = f; }
58
59 const TYPEMARKER &getType() const { return d_type; }
60 void setType(const TYPEMARKER &t) { d_type = t; }
61
62 LOCTYPE getLoc() const {
63 PRECONDITION(d_weights.size() == d_locs.size(), "weight/locs mismatch");
64 LOCTYPE accum;
65 for (unsigned int i = 0; i < d_weights.size(); i++) {
66 LOCTYPE tmp = *d_locs[i];
67 tmp *= d_weights[i] / d_weightSum;
68 accum += tmp;
69 }
70 return accum;
71 }
72 void addPoint(const LOCTYPE *p, double weight = 1.0) {
73 d_locs.push_back(p);
74 d_weights.push_back(weight);
75 d_weightSum += weight;
76 }
77 void reset() {
78 d_locs.clear();
79 d_weights.clear();
80 d_weightSum = 0.0;
81 }
82
83 const std::vector<LOCTYPE> &getDirs() const { return d_dirs; }
84 std::vector<LOCTYPE> &getDirs() { return d_dirs; }
85
86 private:
87 double d_weightSum;
88 FAMILYMARKER d_family;
89 TYPEMARKER d_type;
90 std::vector<double> d_weights;
91 std::vector<const LOCTYPE *> d_locs;
92 // FIX: add something correct for directions
93 std::vector<LOCTYPE> d_dirs;
94};
95} // namespace RDFeatures
96#endif
#define PRECONDITION(expr, mess)
Definition Invariant.h:109
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t, const LOCTYPE &loc)
Definition Feature.h:25
void setLoc(const LOCTYPE &loc)
Definition Feature.h:36
const FAMILYMARKER & getFamily() const
Definition Feature.h:29
void setType(const TYPEMARKER &t)
Definition Feature.h:33
const std::vector< LOCTYPE > & getDirs() const
Definition Feature.h:38
const TYPEMARKER & getType() const
Definition Feature.h:32
void setFamily(const FAMILYMARKER &f)
Definition Feature.h:30
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition Feature.h:23
std::vector< LOCTYPE > & getDirs()
Definition Feature.h:39
const LOCTYPE & getLoc() const
Definition Feature.h:35
void setFamily(const FAMILYMARKER &f)
Definition Feature.h:57
const std::vector< LOCTYPE > & getDirs() const
Definition Feature.h:83
ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition Feature.h:53
const FAMILYMARKER & getFamily() const
Definition Feature.h:56
std::vector< LOCTYPE > & getDirs()
Definition Feature.h:84
void addPoint(const LOCTYPE *p, double weight=1.0)
Definition Feature.h:72
void setType(const TYPEMARKER &t)
Definition Feature.h:60
LOCTYPE getLoc() const
Definition Feature.h:62
const TYPEMARKER & getType() const
Definition Feature.h:59