OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gromacs_block_modifiers.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2015 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 #ifndef OST_MM_GROMCACS_BLOCK_MODIFIERS_HH
21 #define OST_MM_GROMCACS_BLOCK_MODIFIERS_HH
22 
23 
24 #include <boost/shared_ptr.hpp>
25 
26 #include <ost/message.hh>
27 #include <ost/mol/bond_handle.hh>
29 #include <ost/mol/entity_handle.hh>
30 #include <ost/mol/atom_handle.hh>
31 #include <ost/mol/xcs_editor.hh>
32 #include <ost/geom/vec3.hh>
35 
36 
37 namespace ost{ namespace mol{ namespace mm{
38 
39 class GromacsHydrogenConstructor;
40 class GromacsTerminiConstructor;
42 
43 typedef boost::shared_ptr<GromacsHydrogenConstructor> GromacsHydrogenConstructorPtr;
44 typedef boost::shared_ptr<GromacsTerminiConstructor> GromacsTerminiConstructorPtr;
45 typedef boost::shared_ptr<GromacsBlockModifier> GromacsBlockModifierPtr;
46 
48 
49 public:
50  static std::vector<geom::Vec3> EvaluatePosRule(int rule, int number,
51  const std::vector<geom::Vec3>& anchors);
52 };
53 
55 
56 public:
57 
59 
61 
63 
64  void AddHydrogenRule(uint number, int method,
65  const std::vector<String>& hydrogen_names,
66  const std::vector<String>& anchors);
67 
68  // GET STUFF (for data extraction)
69  uint GetNumHydrogenRules() const { return add_number_.size(); }
70  // all getters for idx < GetNumHydrogenRules()
71  int GetHydrogenRuleNumber(uint idx) const { return add_number_[idx]; }
72  int GetHydrogenRuleMethod(uint idx) const { return methods_[idx]; }
73  const std::vector<String>&
74  GetHydrogenRuleNames(uint idx) const { return hydrogen_names_[idx]; }
75  const std::vector<String>&
76  GetHydrogenRuleAnchors(uint idx) const { return anchor_atom_names_[idx]; }
77 
78  virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
79 
81 
82  template <typename DS>
83  void Serialize(DS& ds){
84  int num_hydrogen_add_rules = add_number_.size();
85  ds & num_hydrogen_add_rules;
86 
87  if(ds.IsSource()){
88  add_number_ = std::vector<int>(num_hydrogen_add_rules);
89  methods_ = std::vector<int>(num_hydrogen_add_rules);
90  hydrogen_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
91  anchor_atom_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
92  }
93 
94  for(int i = 0; i < num_hydrogen_add_rules; ++i){
95  ds & add_number_[i];
96  ds & methods_[i];
97  int num_hydrogen_names = hydrogen_names_[i].size();
98  int num_anchor_names = anchor_atom_names_[i].size();
99  ds & num_hydrogen_names;
100  ds & num_anchor_names;
101  if(ds.IsSource()){
102  hydrogen_names_[i] = std::vector<String>(num_hydrogen_names);
103  anchor_atom_names_[i] = std::vector<String>(num_anchor_names);
104  }
105 
106  for(int j = 0; j < num_hydrogen_names; ++j){
107  ds & hydrogen_names_[i][j];
108  }
109  for(int j = 0; j < num_anchor_names; ++j){
110  ds & anchor_atom_names_[i][j];
111  }
112  }
113  }
114 
115 private:
116  std::vector<int> add_number_;
117  std::vector<int> methods_;
118  std::vector<std::vector<String> > hydrogen_names_;
119  std::vector<std::vector<String> > anchor_atom_names_;
120 };
121 
122 
124 
125 public:
126 
128 
129  virtual void ApplyOnBuildingBlock(BuildingBlockPtr p);
130 
132 
133  void AddReplaceRule(const String& name, const String& new_name,
134  const String& new_type, Real new_charge);
135 
136  void AddAddRule(int number, int method,
137  const std::vector<String>& atom_names,
138  const std::vector<String>& anchors,
139  const String& type, Real charge);
140 
141  void AddBond(InteractionPtr p) { this->CheckInteractionToAdd(p,"BOND");
142  bonds_.push_back(p); }
143 
144  void AddAngle(InteractionPtr p) { this->CheckInteractionToAdd(p,"ANGLE");
145  angles_.push_back(p); }
146 
147  void AddDihedral(InteractionPtr p) { this->CheckInteractionToAdd(p,"DIHEDRAL");
148  dihedrals_.push_back(p); }
149 
150  void AddImproper(InteractionPtr p) { this->CheckInteractionToAdd(p,"IMPROPER");
151  impropers_.push_back(p); }
152 
153  void AddCMap(InteractionPtr p) { this->CheckInteractionToAdd(p,"CMAP");
154  cmaps_.push_back(p); }
155 
156  void AddDeleteAtom(const String& atom_name) { delete_atom_names_.push_back(atom_name); }
157 
158  // GET STUFF (for data extraction)
159  const std::vector<InteractionPtr>& GetBonds() const { return bonds_; }
160  const std::vector<InteractionPtr>& GetAngles() const { return angles_; }
161  const std::vector<InteractionPtr>& GetDihedrals() const { return dihedrals_; }
162  const std::vector<InteractionPtr>& GetImpropers() const { return impropers_; }
163  const std::vector<InteractionPtr>& GetCmaps() const { return cmaps_; }
164  const std::vector<String>& GetDeleteAtoms() const { return delete_atom_names_; }
165  // all idx for replace rules < GetNumReplaceRules()
166  uint GetNumReplaceRules() const { return replace_old_atom_name_.size(); }
167  const String& GetReplaceRuleName(uint idx) const {
168  return replace_old_atom_name_[idx];
169  }
170  const String& GetReplaceRuleNewName(uint idx) const {
171  return replace_new_atom_name_[idx];
172  }
173  const String& GetReplaceRuleNewType(uint idx) const {
174  return replace_new_atom_type_[idx];
175  }
177  return replace_new_charge_[idx];
178  }
179  // all idx for add rules < GetNumAddRules()
180  uint GetNumAddRules() const { return add_add_number_.size(); }
181  int GetAddRuleNumber(uint idx) const { return add_add_number_[idx]; }
182  int GetAddRuleMethod(uint idx) const { return add_methods_[idx]; }
183  const std::vector<String>&
184  GetAddRuleNames(uint idx) const { return add_atom_names_[idx]; }
185  const std::vector<String>&
186  GetAddRuleAnchors(uint idx) const { return add_anchor_atom_names_[idx]; }
187  const String& GetAddRuleType(uint idx) const { return add_atom_types_[idx]; }
188  Real GetAddRuleCharge(uint idx) const { return add_charges_[idx]; }
189 
190  virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
191 
193 
194  template <typename DS>
195  void Serialize(DS& ds){
196 
197  int num_bonds = bonds_.size();
198  int num_angles = angles_.size();
199  int num_dihedrals = dihedrals_.size();
200  int num_impropers = impropers_.size();
201  int num_cmaps = cmaps_.size();
202 
203  ds & num_bonds;
204  ds & num_angles;
205  ds & num_dihedrals;
206  ds & num_impropers;
207  ds & num_cmaps;
208 
209  for(int i = 0; i < num_bonds; ++i){
210  int func_type;
211  if(ds.IsSource()){
212  ds & func_type;
213  bonds_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
214  }
215  else{
216  func_type = bonds_[i]->GetFuncType();
217  ds & func_type;
218  }
219  ds & *(bonds_[i]);
220  }
221 
222  for(int i = 0; i < num_angles; ++i){
223  int func_type;
224  if(ds.IsSource()){
225  ds & func_type;
226  angles_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
227  }
228  else{
229  func_type = angles_[i]->GetFuncType();
230  ds & func_type;
231  }
232  ds & *(angles_[i]);
233  }
234 
235  for(int i = 0; i < num_dihedrals; ++i){
236  int func_type;
237  if(ds.IsSource()){
238  ds & func_type;
239  dihedrals_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
240  }
241  else{
242  func_type = dihedrals_[i]->GetFuncType();
243  ds & func_type;
244  }
245  ds & *(dihedrals_[i]);
246  }
247 
248  for(int i = 0; i < num_impropers; ++i){
249  int func_type;
250  if(ds.IsSource()){
251  ds & func_type;
252  impropers_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
253  }
254  else{
255  func_type = impropers_[i]->GetFuncType();
256  ds & func_type;
257  }
258  ds & *(impropers_[i]);
259  }
260 
261  for(int i = 0; i < num_cmaps; ++i){
262  int func_type;
263  if(ds.IsSource()){
264  ds & func_type;
265  cmaps_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
266  }
267  else{
268  func_type = cmaps_[i]->GetFuncType();
269  ds & func_type;
270  }
271  ds & *(cmaps_[i]);
272  }
273 
274  int num_replace_atoms = replace_old_atom_name_.size();
275  ds & num_replace_atoms;
276 
277  if(ds.IsSource()){
278  replace_old_atom_name_ = std::vector<String>(num_replace_atoms);
279  replace_new_atom_name_ = std::vector<String>(num_replace_atoms);
280  replace_new_atom_type_ = std::vector<String>(num_replace_atoms);
281  replace_new_charge_ = std::vector<Real>(num_replace_atoms);
282  }
283 
284  for(int i = 0; i < num_replace_atoms; ++i){
285  ds & replace_old_atom_name_[i];
286  ds & replace_new_atom_name_[i];
287  ds & replace_new_atom_type_[i];
288  ds & replace_new_charge_[i];
289  }
290 
291  int num_add_atoms = add_add_number_.size();
292  ds & num_add_atoms;
293 
294  if(ds.IsSource()){
295  add_add_number_ = std::vector<int>(num_add_atoms);
296  add_methods_ = std::vector<int>(num_add_atoms);
297  add_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
298  add_anchor_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
299  add_atom_types_ = std::vector<String>(num_add_atoms);
300  add_charges_ = std::vector<Real>(num_add_atoms);
301  }
302 
303  for(int i = 0; i < num_add_atoms; ++i){
304  ds & add_add_number_[i];
305  ds & add_methods_[i];
306  ds & add_atom_types_[i];
307  ds & add_charges_[i];
308  int num_add_atom_names = add_atom_names_[i].size();
309  int num_add_anchor_atom_names = add_anchor_atom_names_[i].size();
310  ds & num_add_atom_names;
311  ds & num_add_anchor_atom_names;
312  if(ds.IsSource()){
313  add_atom_names_[i] = std::vector<String>(num_add_atom_names);
314  add_anchor_atom_names_[i] = std::vector<String>(num_add_anchor_atom_names);
315  }
316  for(int j = 0; j < num_add_atom_names; ++j){
317  ds & add_atom_names_[i][j];
318  }
319  for(int j = 0; j < num_add_anchor_atom_names; ++j){
320  ds & add_anchor_atom_names_[i][j];
321  }
322  }
323 
324  int num_delete_atoms = delete_atom_names_.size();
325  ds & num_delete_atoms;
326  if(ds.IsSource()){
327  delete_atom_names_ = std::vector<String>(num_delete_atoms);
328  }
329  for(int i = 0; i < num_delete_atoms; ++i){
330  ds & delete_atom_names_[i];
331  }
332  }
333 
334 private:
335 
336  void CheckInteractionToAdd(InteractionPtr p, const String& interaction_type) const;
337 
338  //Atoms, that will be added to the building block
339 
340  //Interactions, that will be added to the building block
341  std::vector<InteractionPtr> bonds_;
342  std::vector<InteractionPtr> angles_;
343  std::vector<InteractionPtr> dihedrals_;
344  std::vector<InteractionPtr> impropers_;
345  std::vector<InteractionPtr> cmaps_;
346 
347  //paramters we need for the replace statement
348  std::vector<String> replace_old_atom_name_;
349  std::vector<String> replace_new_atom_name_;
350  std::vector<String> replace_new_atom_type_;
351  std::vector<Real> replace_new_charge_;
352 
353  //parameters we need for the add statement => gromacs dependent rules!
354  std::vector<int> add_add_number_;
355  std::vector<int> add_methods_;
356  std::vector<std::vector<String> > add_atom_names_;
357  std::vector<std::vector<String> > add_anchor_atom_names_;
358  std::vector<String> add_atom_types_;
359  std::vector<Real> add_charges_;
360 
361  //parameters we need for the delete statement
362  std::vector<String> delete_atom_names_;
363 };
364 
365 
366 
367 
368 }}}
369 
370 #endif
virtual void OnSave(ost::io::BinaryDataSink &ds)
boost::shared_ptr< GromacsBlockModifier > GromacsBlockModifierPtr
const std::vector< String > & GetDeleteAtoms() const
void AddReplaceRule(const String &name, const String &new_name, const String &new_type, Real new_charge)
const std::vector< InteractionPtr > & GetBonds() const
boost::shared_ptr< Interaction > InteractionPtr
Definition: interaction.hh:39
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
const String & GetAddRuleType(uint idx) const
boost::shared_ptr< GromacsHydrogenConstructor > GromacsHydrogenConstructorPtr
virtual void OnSave(ost::io::BinaryDataSink &ds)
const std::vector< String > & GetHydrogenRuleNames(uint idx) const
const String & GetReplaceRuleNewType(uint idx) const
const std::vector< InteractionPtr > & GetImpropers() const
const std::vector< String > & GetAddRuleNames(uint idx) const
virtual BlockModifierType GetBlockModifierType()
const String & GetReplaceRuleName(uint idx) const
void AddDeleteAtom(const String &atom_name)
external coordinate system editor
Definition: xcs_editor.hh:36
const std::vector< InteractionPtr > & GetAngles() const
boost::shared_ptr< GromacsTerminiConstructor > GromacsTerminiConstructorPtr
const std::vector< InteractionPtr > & GetDihedrals() const
void AddAddRule(int number, int method, const std::vector< String > &atom_names, const std::vector< String > &anchors, const String &type, Real charge)
const String & GetReplaceRuleNewName(uint idx) const
const std::vector< String > & GetAddRuleAnchors(uint idx) const
virtual void ApplyOnBuildingBlock(BuildingBlockPtr)
virtual void ApplyOnResidue(ost::mol::ResidueHandle &res, ost::mol::XCSEditor &ed)
void AddHydrogenRule(uint number, int method, const std::vector< String > &hydrogen_names, const std::vector< String > &anchors)
const std::vector< InteractionPtr > & GetCmaps() const
static std::vector< geom::Vec3 > EvaluatePosRule(int rule, int number, const std::vector< geom::Vec3 > &anchors)
const std::vector< String > & GetHydrogenRuleAnchors(uint idx) const
virtual void ApplyOnResidue(ost::mol::ResidueHandle &res, ost::mol::XCSEditor &ed)
unsigned int uint
Definition: base.hh:29
virtual void ApplyOnBuildingBlock(BuildingBlockPtr p)
boost::shared_ptr< BuildingBlock > BuildingBlockPtr