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