RDKit
Open-source cheminformatics and machine learning.
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>
20  public:
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>
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
void setFamily(const FAMILYMARKER &f)
Definition: Feature.h:56
ImplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition: Feature.h:52
void setFamily(const FAMILYMARKER &f)
Definition: Feature.h:29
const LOCTYPE & getLoc() const
Definition: Feature.h:34
const std::vector< LOCTYPE > & getDirs() const
Definition: Feature.h:82
const FAMILYMARKER & getFamily() const
Definition: Feature.h:55
const TYPEMARKER & getType() const
Definition: Feature.h:58
std::vector< LOCTYPE > & getDirs()
Definition: Feature.h:83
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t, const LOCTYPE &loc)
Definition: Feature.h:24
void setType(const TYPEMARKER &t)
Definition: Feature.h:32
const TYPEMARKER & getType() const
Definition: Feature.h:31
std::vector< LOCTYPE > & getDirs()
Definition: Feature.h:38
const FAMILYMARKER & getFamily() const
Definition: Feature.h:28
ExplicitFeature(const FAMILYMARKER &f, const TYPEMARKER &t)
Definition: Feature.h:22
#define PRECONDITION(expr, mess)
Definition: Invariant.h:107
LOCTYPE getLoc() const
Definition: Feature.h:61
void addPoint(const LOCTYPE *p, double weight=1.0)
Definition: Feature.h:71
void setLoc(const LOCTYPE &loc)
Definition: Feature.h:35
const std::vector< LOCTYPE > & getDirs() const
Definition: Feature.h:37
void setType(const TYPEMARKER &t)
Definition: Feature.h:59