VinaLC: Parallel Molecular Docking Program

Biochemical and Biophysical Systems Group
VinaLC version: 1.1.2

model.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_MODEL_H
24 #define VINA_MODEL_H
25 
26 #include <boost/optional.hpp> // for context
27 
28 #include "file.h"
29 #include "tree.h"
30 #include "matrix.h"
31 #include "precalculate.h"
32 #include "igrid.h"
33 #include "grid_dim.h"
34 
37  sz a;
38  sz b;
39  interacting_pair(sz type_pair_index_, sz a_, sz b_) : type_pair_index(type_pair_index_), a(a_), b(b_) {}
40 };
41 
42 typedef std::vector<interacting_pair> interacting_pairs;
43 
44 typedef std::pair<std::string, boost::optional<sz> > parsed_line;
45 typedef std::vector<parsed_line> context;
46 
47 struct ligand : public flexible_body, atom_range {
48  unsigned degrees_of_freedom; // can be different from the apparent number of rotatable bonds, because of the disabled torsions
51  ligand(const flexible_body& f, unsigned degrees_of_freedom_) : flexible_body(f), atom_range(0, 0), degrees_of_freedom(degrees_of_freedom_) {}
52  void set_range();
53 };
54 
55 struct residue : public main_branch {
56  residue(const main_branch& m) : main_branch(m) {}
57 };
58 
61 
62 struct non_cache; // forward declaration
63 struct naive_non_cache; // forward declaration
64 struct cache; // forward declaration
65 struct szv_grid; // forward declaration
66 struct terms; // forward declaration
67 struct conf_independent_inputs; // forward declaration
68 struct pdbqt_initializer; // forward declaration - only declared in parse_pdbqt.cpp
69 struct model_test;
70 
71 struct model {
72  void append(const model& m);
74 
76  sz num_internal_pairs() const;
77  sz num_other_pairs() const { return other_pairs.size(); }
78  sz num_ligands() const { return ligands.size(); }
79  sz num_flex() const { return flex.size(); }
80  sz ligand_degrees_of_freedom(sz ligand_number) const { return ligands[ligand_number].degrees_of_freedom; }
81  sz ligand_longest_branch(sz ligand_number) const;
82  sz ligand_length(sz ligand_number) const;
83 
84  szv get_movable_atom_types(atom_type::t atom_typing_used_) const;
85 
86  conf_size get_size() const;
87  conf get_initial_conf() const; // torsions = 0, orientations = identity, ligand positions = current
88 
89  grid_dims movable_atoms_box(fl add_to_each_dimension, fl granularity = 0.375) const;
90 
91  void write_flex ( const path& name, const std::string& remark) const { write_context(flex_context, name, remark); }
92  void write_ligand(sz ligand_number, const path& name, const std::string& remark) const { VINA_CHECK(ligand_number < ligands.size()); write_context(ligands[ligand_number].cont, name, remark); }
93  void write_structure(std::stringstream& out) const {
95  write_context(ligands[i].cont, out);
96  if(num_flex() > 0) // otherwise remark is written in vain
98  }
99  void write_structure(ofile& out) const {
100  VINA_FOR_IN(i, ligands)
101  write_context(ligands[i].cont, out);
102  if(num_flex() > 0) // otherwise remark is written in vain
104  }
105  void write_structure(std::stringstream& out, const std::string& remark) const {
106  out << remark;
107  write_structure(out);
108  }
109  void write_structure(ofile& out, const std::string& remark) const {
110  out << remark;
111  write_structure(out);
112  }
113  void write_model(std::stringstream& out, sz model_number, const std::string& remark) const {
114  out << "MODEL " << model_number << '\n';
115  write_structure(out, remark);
116  out << "ENDMDL\n";
117  }
118  void write_structure(const path& name) const { ofile out(name); write_structure(out); }
119  void write_model(ofile& out, sz model_number, const std::string& remark) const {
120  out << "MODEL " << model_number << '\n';
121  write_structure(out, remark);
122  out << "ENDMDL\n";
123  }
124  void seti(const conf& c);
125  void sete(const conf& c);
126  void set (const conf& c);
127 
128  fl gyration_radius(sz ligand_number) const; // uses coords
129 
130  const atom_base& movable_atom (sz i) const { assert(i < m_num_movable_atoms); return atoms[i]; }
131  const vec& movable_coords(sz i) const { assert(i < m_num_movable_atoms); return coords[i]; }
132 
133  const vec& atom_coords(const atom_index& i) const;
134  fl distance_sqr_between(const atom_index& a, const atom_index& b) const;
135  bool atom_exists_between(const distance_type_matrix& mobility, const atom_index& a, const atom_index& b, const szv& relevant_atoms) const; // there is an atom closer to both a and b then they are to each other and immobile relative to them
136 
137  distance_type distance_type_between(const distance_type_matrix& mobility, const atom_index& i, const atom_index& j) const;
138 
139  // clean up
140  fl evali (const precalculate& p, const vec& v ) const;
141  fl evale (const precalculate& p, const igrid& ig, const vec& v ) const;
142  fl eval (const precalculate& p, const igrid& ig, const vec& v, const conf& c );
143  fl eval_deriv(const precalculate& p, const igrid& ig, const vec& v, const conf& c, change& g);
144 
145  fl eval_intramolecular( const precalculate& p, const vec& v, const conf& c);
146  fl eval_adjusted (const scoring_function& sf, const precalculate& p, const igrid& ig, const vec& v, const conf& c, fl intramolecular_energy);
147 
148 
149  fl rmsd_lower_bound(const model& m) const; // uses coords
150  fl rmsd_upper_bound(const model& m) const; // uses coords
151  fl rmsd_ligands_upper_bound(const model& m) const; // uses coords
152 
153  void verify_bond_lengths() const;
154  void about() const;
155 
156  vecv get_ligand_internal_coords() const { // FIXME rm
157  VINA_CHECK(ligands.size() == 1);
158  vecv tmp;
159  const ligand& lig = ligands.front();
160  VINA_RANGE(i, lig.begin, lig.end)
161  tmp.push_back(internal_coords[i]);
162  return tmp;
163  }
164 
165  vecv get_ligand_coords() const { // FIXME rm
166  VINA_CHECK(ligands.size() == 1);
167  vecv tmp;
168  const ligand& lig = ligands.front();
169  VINA_RANGE(i, lig.begin, lig.end)
170  tmp.push_back(coords[i]);
171  return tmp;
172  }
173  vecv get_heavy_atom_movable_coords() const { // FIXME mv
174  vecv tmp;
176  if(atoms[i].el != EL_TYPE_H)
177  tmp.push_back(coords[i]);
178  return tmp;
179  }
180  void check_internal_pairs() const;
181  void print_stuff() const; // FIXME rm
182 
183  fl clash_penalty() const;
184 
185 private:
186  friend struct non_cache;
187  friend struct naive_non_cache;
188  friend struct cache;
189  friend struct szv_grid;
190  friend struct terms;
191  friend struct conf_independent_inputs;
192  friend struct appender_info;
193  friend struct pdbqt_initializer;
194  friend struct model_test;
195 
197 
198  const atom& get_atom(const atom_index& i) const { return (i.in_grid ? grid_atoms[i.i] : atoms[i.i]); }
199  atom& get_atom(const atom_index& i) { return (i.in_grid ? grid_atoms[i.i] : atoms[i.i]); }
200 
201  void write_context(const context& c, std::stringstream& out) const;
202  void write_context(const context& c, ofile& out) const;
203  void write_context(const context& c, ofile& out, const std::string& remark) const {
204  out << remark;
205  }
206  void write_context(const context& c, const path& name) const {
207  ofile out(name);
208  write_context(c, out);
209  }
210  void write_context(const context& c, const path& name, const std::string& remark) const {
211  ofile out(name);
212  write_context(c, out, remark);
213  }
214  fl rmsd_lower_bound_asymmetric(const model& x, const model& y) const; // actually static
215 
216  atom_index sz_to_atom_index(sz i) const; // grid_atoms, atoms
217  bool bonded_to_HD(const atom& a) const;
218  bool bonded_to_heteroatom(const atom& a) const;
219  sz find_ligand(sz a) const;
220  void bonded_to(sz a, sz n, szv& out) const;
221  szv bonded_to(sz a, sz n) const;
222 
223  void assign_bonds(const distance_type_matrix& mobility); // assign bonds based on relative mobility, distance and covalent length
224  void assign_types();
225  void initialize_pairs(const distance_type_matrix& mobility);
226  void initialize(const distance_type_matrix& mobility);
227  fl clash_penalty_aux(const interacting_pairs& pairs) const;
228 
232 
234  atomv atoms; // movable, inflex
238  interacting_pairs other_pairs; // all except internal to one ligand: ligand-other ligands; ligand-flex/inflex; flex-flex/inflex
239 
242 };
243 
244 #endif