VinaLC: Parallel Molecular Docking Program

Biochemical and Biophysical Systems Group
VinaLC version: 1.1.2

terms.h
Go to the documentation of this file.
1 /*
2 
3  Copyright (c) 2006-2010, The Scripps Research Institute
4 
5  Licensed under the Apache License, Version 2.0 (the "License");
6  you may not use this file except in compliance with the License.
7  You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16 
17  Author: Dr. Oleg Trott <ot14@columbia.edu>,
18  The Olson Lab,
19  The Scripps Research Institute
20 
21 */
22 
23 #ifndef VINA_TERMS_H
24 #define VINA_TERMS_H
25 
26 #include <boost/ptr_container/ptr_vector.hpp>
27 #include "model.h"
28 
29 struct term {
30  std::string name;
31  virtual ~term() {}
32 };
33 
34 struct distance_additive : public term {
36  distance_additive(fl cutoff_) : cutoff(cutoff_) {}
37  virtual fl eval(const atom_base& a, const atom_base& b, fl r) const = 0;
38  virtual ~distance_additive() {}
39 };
40 
41 struct usable : public distance_additive {
43  usable(fl cutoff_) : distance_additive(cutoff_), atom_typing_used(atom_type::XS) {}
44  fl eval(const atom_base& a, const atom_base& b, fl r) const { // should not be overriden
45  return eval(a.get(atom_typing_used), b.get(atom_typing_used), r);
46  }
47  virtual fl eval(sz t1, sz t2, fl r) const { return 0; }
48  virtual ~usable() {}
49 };
50 
51 struct additive : public term {
54  virtual fl eval(const model& m, const atom_index& i, const atom_index& j) const = 0;
55  virtual ~additive() {}
56 };
57 
58 struct intermolecular : public term {
59  virtual fl eval(const model& m) const = 0;
60 };
61 
70  operator flv() const;
72  std::vector<std::string> get_names() const;
74 private:
75  unsigned num_bonded_heavy_atoms(const model& m, const atom_index& i) const; // FIXME? - could be static, but I don't feel like declaring function friends
76  unsigned atom_rotors(const model& m, const atom_index& i) const; // the number of rotatable bonds to heavy ligand atoms
77 
79  template<class Archive>
80  void serialize(Archive & ar, const unsigned version) {
81  ar & num_tors;
82  ar & num_rotors;
83  ar & num_heavy_atoms;
86  ar & num_ligands;
87  ar & ligand_lengths_sum;
88  }
89 };
90 
91 struct conf_independent : public term {
92  virtual fl eval(const conf_independent_inputs& in, fl x, flv::const_iterator& it) const = 0;
93  virtual sz size() const = 0; // how many parameters does it take
94 };
95 
96 template<typename T>
97 struct term_set {
98  std::vector<bool> enabled;
99  boost::ptr_vector<T> fun; // FIXME? const T?
100  void add(unsigned e, T* f) { // FIXME? const T* ?
101  enabled.push_back(e > 0);
102  fun.push_back(f);
103  }
104  sz num_enabled() const {
105  sz tmp = 0;
106  VINA_FOR_IN(i, enabled)
107  if(enabled[i])
108  ++tmp;
109  return tmp;
110  }
111  void get_names(bool enabled_only, std::vector<std::string>& out) const { // appends to "out"
112  VINA_CHECK(enabled.size() == fun.size());
113  VINA_FOR_IN(i, fun)
114  if(!enabled_only || enabled[i])
115  out.push_back(fun[i].name);
116  }
117  void filter(flv::const_iterator& in, flv& out) const {
118  VINA_CHECK(enabled.size() == fun.size());
119  VINA_FOR_IN(i, enabled) {
120  if(enabled[i])
121  out.push_back(*in);
122  ++in;
123  }
124  }
125  fl max_cutoff() const {
126  fl tmp = 0;
127  VINA_FOR_IN(i, fun)
128  tmp = (std::max)(tmp, fun[i].cutoff);
129  return tmp;
130  }
131  sz size() const { return fun.size(); }
132  const T& operator[](sz i) const { return fun[i]; }
133 };
134 
135 
136 struct factors {
137  flv e; // external
138  flv i; // internal
139  sz size() const { return e.size() + i.size(); }
140  //sz num_weights() const { return (std::max)(e.size(), i.size()); } // FIXME? compiler bug? getting warnings here
141  sz num_weights() const { return (e.size() > i.size()) ? e.size() : i.size(); }
142  fl eval(const flv& weights, bool include_internal) const;
143 private:
145  template<class Archive>
146  void serialize(Archive & ar, const unsigned version) {
147  ar & e;
148  ar & i;
149  }
150 };
151 
152 struct terms {
158 
159  // the class takes ownership of the pointer with 'add'
160  void add(unsigned e, distance_additive* p) { distance_additive_terms.add(e, p); }
161  void add(unsigned e, usable* p) { usable_terms.add(e, p); }
162  void add(unsigned e, additive* p) { additive_terms.add(e, p); }
163  void add(unsigned e, intermolecular* p) { intermolecular_terms.add(e, p); }
164  void add(unsigned e, conf_independent* p) { conf_independent_terms.add(e, p); }
165 
166  std::vector<std::string> get_names(bool enabled_only) const; // does not include conf-independent
167  sz size_internal() const;
168  sz size() const { return size_internal() + intermolecular_terms.size(); }
169  sz size_conf_independent(bool enabled_only) const; // number of parameters does not necessarily equal the number of operators
170  fl max_r_cutoff() const;
171  flv evale(const model& m) const;
172  flv evali(const model& m) const;
173  flv evale_robust(const model& m) const;
174  factors eval(const model& m) const;
175  fl eval_conf_independent(const conf_independent_inputs& in, fl x, flv::const_iterator& it) const;
176  flv filter_external(const flv& v) const;
177  flv filter_internal(const flv& v) const;
178  factors filter(const factors& f) const;
179  void display_info() const;
180 private:
181  void eval_additive_aux(const model& m, const atom_index& i, const atom_index& j, fl r, flv& out) const; // out is added to
182 
183 };
184 
185 #endif