RDKit: Feature.h Source File

| 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
17 namespace RDFeatures {
18template <typename FAMILYMARKER, typename TYPEMARKER = FAMILYMARKER,
19 typename LOCTYPE = RDGeom::Point3D>
20 class ExplicitFeature {
21 public:
22 ExplicitFeature() {}
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>
50 class ImplicitFeature {
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
PRECONDITION
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t, const LOCTYPE &loc)
Definition Feature.h:25
RDFeatures::ExplicitFeature::setLoc
void setLoc(const LOCTYPE &loc)
Definition Feature.h:36
RDFeatures::ExplicitFeature::getFamily
const FAMILYMARKER & getFamily() const
Definition Feature.h:29
RDFeatures::ExplicitFeature::setType
void setType(const TYPEMARKER &t)
Definition Feature.h:33
RDFeatures::ExplicitFeature::getDirs
const std::vector< LOCTYPE > & getDirs() const
Definition Feature.h:38
RDFeatures::ExplicitFeature::getType
const TYPEMARKER & getType() const
Definition Feature.h:32
RDFeatures::ExplicitFeature::setFamily
void setFamily(const FAMILYMARKER &f)
Definition Feature.h:30
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition Feature.h:23
RDFeatures::ExplicitFeature::getDirs
std::vector< LOCTYPE > & getDirs()
Definition Feature.h:39
RDFeatures::ExplicitFeature::ExplicitFeature
ExplicitFeature()
Definition Feature.h:22
RDFeatures::ExplicitFeature::getLoc
const LOCTYPE & getLoc() const
Definition Feature.h:35
RDFeatures::ImplicitFeature::ImplicitFeature
ImplicitFeature()
Definition Feature.h:52
RDFeatures::ImplicitFeature::setFamily
void setFamily(const FAMILYMARKER &f)
Definition Feature.h:57
RDFeatures::ImplicitFeature::getDirs
const std::vector< LOCTYPE > & getDirs() const
Definition Feature.h:83
RDFeatures::ImplicitFeature::ImplicitFeature
ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition Feature.h:53
RDFeatures::ImplicitFeature::getFamily
const FAMILYMARKER & getFamily() const
Definition Feature.h:56
RDFeatures::ImplicitFeature::getDirs
std::vector< LOCTYPE > & getDirs()
Definition Feature.h:84
RDFeatures::ImplicitFeature::addPoint
void addPoint(const LOCTYPE *p, double weight=1.0)
Definition Feature.h:72
RDFeatures::ImplicitFeature::setType
void setType(const TYPEMARKER &t)
Definition Feature.h:60
RDFeatures::ImplicitFeature::getLoc
LOCTYPE getLoc() const
Definition Feature.h:62
RDFeatures::ImplicitFeature::getType
const TYPEMARKER & getType() const
Definition Feature.h:59
RDFeatures::ImplicitFeature::reset
void reset()
Definition Feature.h:77
RDGeom::Point3D
Definition point.h:53
export.h
RDFeatures
Definition Feature.h:17
point.h