OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
forcefield.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_FORCE_FIELD_HH
21 #define OST_MM_FORCE_FIELD_HH
22 
23 #include <vector>
24 #include <algorithm>
25 
26 
27 #include <boost/shared_ptr.hpp>
28 #include <boost/unordered_map.hpp>
29 
30 #include <ost/message.hh>
35 
36 namespace ost { namespace mol{ namespace mm{
37 
38 struct ResidueNames;
39 class Forcefield;
40 
41 typedef boost::shared_ptr<ResidueNames> ResidueNamesPtr;
42 typedef boost::shared_ptr<ost::mol::mm::Forcefield> ForcefieldPtr;
43 
44 struct ResidueNames{
45 
46  ResidueNames() { };
47 
49  main(a),nter(b),cter(c),twoter(d) { }
50 
55 
56  bool Contains(const String& name){
57  return name == main || name == nter || name == cter || name == twoter;
58  }
59 
60  template <typename DS>
61  void Serialize(DS& ds){
62  ds & main;
63  ds & nter;
64  ds & cter;
65  ds & twoter;
66  }
67 };
68 
69 
70 class Forcefield {
71 public:
72 
73  Forcefield(): gen_pairs_(true), fudge_LJ_(1.0),fudge_QQ_(1.0) { }
74 
75  static ForcefieldPtr Load(const String& filename);
76 
77  void Save(const String& filename);
78 
79  //Getter functions
80 
81  BuildingBlockPtr GetBuildingBlock(const String& name) const;
82 
83  BlockModifierPtr GetBlockModifier(const String& modifier_name) const;
84 
85  std::vector<String> GetBuildingBlockNames() const;
86 
87  String GetAtomType(const String& res_name, const String& atom_name) const;
88 
90 
91  BlockModifierPtr GetNTerModifier(const String& res_name, const String& ter_name = "") const;
92 
93  BlockModifierPtr GetCTerModifier(const String& res_name, const String& ter_name = "") const;
94 
95  InteractionPtr GetBond(const String& type1,
96  const String& type2) const;
97 
98  InteractionPtr GetAngle(const String& type1,
99  const String& type2,
100  const String& type3) const;
101 
102  std::vector<InteractionPtr> GetDihedrals(const String& type1,
103  const String& type2,
104  const String& type3,
105  const String& type4) const;
106 
107  std::vector<InteractionPtr> GetImpropers(const String& type1,
108  const String& type2,
109  const String& type3,
110  const String& type4) const;
111 
112  InteractionPtr GetCMap(const String& type1,
113  const String& type2,
114  const String& type3,
115  const String& type4,
116  const String& type5) const;
117 
118  InteractionPtr GetImplicitGenborn(const String& type1) const;
119 
120  InteractionPtr GetLJ(const String& type1,
121  const String& type2,
122  bool pair=false) const;
123 
124  InteractionPtr GetLJ(const String& type) const;
125 
126  InteractionPtr GetConstraint(const String& type1,
127  const String& type2);
128 
129  Real GetMass(const String& type) const;
130 
131  Real GetFudgeLJ() const { return fudge_LJ_; }
132 
133  Real GetFudgeQQ() const { return fudge_QQ_; }
134 
135  //functions to add interactions and settings
136 
137  void AddBuildingBlock(const String& name, BuildingBlockPtr p) { building_blocks_[name] = p; }
138 
139  void AddBond(InteractionPtr p);
140 
141  void AddAngle(InteractionPtr p);
142 
143  void AddDihedral(InteractionPtr p);
144 
145  void AddImproper(InteractionPtr p);
146 
147  void AddCMap(InteractionPtr p);
148 
150 
151  void AddLJ(InteractionPtr p);
152 
153  void AddLJPair(InteractionPtr p);
154 
156 
157  void AddMass(const String& type, Real mass) { atom_masses_[type] = mass; }
158 
159  void SetFudgeLJ(Real f_lj) { fudge_LJ_ = f_lj; }
160 
161  void SetFudgeQQ(Real f_qq) { fudge_QQ_ = f_qq; }
162 
163  void SetGenPairs(bool gen_pairs) { gen_pairs_ = gen_pairs; }
164 
165  void AddResidueRenamingRule(const String& name,
166  const String& ff_main_name,
167  const String& ff_n_ter_name,
168  const String& ff_c_ter_name,
169  const String& ff_two_ter_name);
170 
171  void AddAtomRenamingRule(const String& res_name,
172  const String& old_atom_name,
173  const String& new_atom_name);
174 
175  String GetResidueRenamingMain(const String& name) const;
176 
177  String GetResidueRenamingNTer(const String& name) const;
178 
179  String GetResidueRenamingCTer(const String& name) const;
180 
181  String GetResidueRenamingTwoTer(const String& name) const;
182 
183  String GetAtomRenaming(const String& res_name, const String& atom_name) const;
184 
186  hydrogen_constructors_[residue_name] = p;
187  }
188 
189  void AddBlockModifier(const String& modifier_name,
190  BlockModifierPtr p) { block_modifiers_[modifier_name] = p; }
191 
192  void SetStandardCTer(const String& res_name, const String& ter_name) { standard_c_termini_[res_name] = ter_name; }
193 
194  void SetStandardNTer(const String& res_name, const String& ter_name) { standard_n_termini_[res_name] = ter_name; }
195 
196 
197  //Renaming to the forcefield specific names (residues/atoms)
198  void AssignFFSpecificNames(ost::mol::EntityHandle& handle, bool reverse=false) const;
199 
200  // get renaming rules (for data extraction)
201  bool HasAtomRenamingRules(const String& res_name) const {
202  return (atom_renaming_ff_specific_.find(res_name)
203  != atom_renaming_ff_specific_.end());
204  }
205  typedef std::vector<std::pair<String,String> > AtomRenamingType;
206  const AtomRenamingType& GetAtomRenamingRules(const String& res_name) const;
207 
208 private:
209 
210  String AtomTypesToKeyword(std::vector<String>& types, bool allow_reordering = true) const;
211  void CheckInteractionToAdd(InteractionPtr p, const String& interaction_type) const;
212 
213  //this is all nonbonded stuff
214  bool gen_pairs_;
215  Real fudge_LJ_;
216  Real fudge_QQ_;
217 
218  boost::unordered_map<String, Real> atom_masses_;
219  boost::unordered_map<String, BuildingBlockPtr> building_blocks_;
220  boost::unordered_map<String, BlockModifierPtr> block_modifiers_;
221 
222  //the standard interactions
223  boost::unordered_map<String,InteractionPtr> bonds_;
224  boost::unordered_map<String,InteractionPtr> angles_;
225  boost::unordered_map<String,InteractionPtr> lj_14_pairs_;
226  boost::unordered_map<String,InteractionPtr> constraints_;
227  boost::unordered_map<String,InteractionPtr> cmaps_;
228  boost::unordered_map<String,InteractionPtr> implicit_genborn_;
229  boost::unordered_map<String,InteractionPtr> ljs_;
230  boost::unordered_map<String,std::vector<InteractionPtr> > dihedrals_;
231  boost::unordered_map<String,std::vector<InteractionPtr> > improper_dihedrals_;
232 
233  boost::unordered_map<String, AtomRenamingType> atom_renaming_ff_specific_;
234  boost::unordered_map<String, ResidueNamesPtr> res_renaming_ff_specific_;
235 
236  boost::unordered_map<String, HydrogenConstructorPtr> hydrogen_constructors_;
237  boost::unordered_map<String, String> standard_n_termini_;
238  boost::unordered_map<String, String> standard_c_termini_;
239 };
240 
241 }}}//ns
242 
243 #endif
void SetStandardNTer(const String &res_name, const String &ter_name)
Definition: forcefield.hh:194
void AddCMap(InteractionPtr p)
void AddBlockModifier(const String &modifier_name, BlockModifierPtr p)
Definition: forcefield.hh:189
String GetAtomType(const String &res_name, const String &atom_name) const
std::vector< InteractionPtr > GetImpropers(const String &type1, const String &type2, const String &type3, const String &type4) const
boost::shared_ptr< HydrogenConstructor > HydrogenConstructorPtr
boost::shared_ptr< Interaction > InteractionPtr
Definition: interaction.hh:39
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
void AddLJ(InteractionPtr p)
void SetFudgeLJ(Real f_lj)
Definition: forcefield.hh:159
void AddLJPair(InteractionPtr p)
void AddAtomRenamingRule(const String &res_name, const String &old_atom_name, const String &new_atom_name)
Protein or molecule.
Real GetFudgeQQ() const
Definition: forcefield.hh:133
InteractionPtr GetImplicitGenborn(const String &type1) const
String GetResidueRenamingCTer(const String &name) const
BlockModifierPtr GetBlockModifier(const String &modifier_name) const
boost::shared_ptr< BlockModifier > BlockModifierPtr
String GetAtomRenaming(const String &res_name, const String &atom_name) const
void AssignFFSpecificNames(ost::mol::EntityHandle &handle, bool reverse=false) const
Real GetMass(const String &type) const
static ForcefieldPtr Load(const String &filename)
InteractionPtr GetLJ(const String &type1, const String &type2, bool pair=false) const
void AddImplicitGenborn(InteractionPtr p)
InteractionPtr GetAngle(const String &type1, const String &type2, const String &type3) const
void AddHydrogenConstructor(const String &residue_name, HydrogenConstructorPtr p)
Definition: forcefield.hh:185
String GetResidueRenamingMain(const String &name) const
void Save(const String &filename)
structure
InteractionPtr GetCMap(const String &type1, const String &type2, const String &type3, const String &type4, const String &type5) const
bool Contains(const String &name)
Definition: forcefield.hh:56
BuildingBlockPtr GetBuildingBlock(const String &name) const
boost::shared_ptr< ost::mol::mm::Forcefield > ForcefieldPtr
Definition: forcefield.hh:42
BlockModifierPtr GetNTerModifier(const String &res_name, const String &ter_name="") const
bool HasAtomRenamingRules(const String &res_name) const
Definition: forcefield.hh:201
HydrogenConstructorPtr GetHydrogenConstructor(const String &name) const
void AddBond(InteractionPtr p)
void AddImproper(InteractionPtr p)
ResidueNames(String a, String b, String c, String d)
Definition: forcefield.hh:48
Real GetFudgeLJ() const
Definition: forcefield.hh:131
void AddMass(const String &type, Real mass)
Definition: forcefield.hh:157
void SetStandardCTer(const String &res_name, const String &ter_name)
Definition: forcefield.hh:192
void AddConstraint(InteractionPtr p)
String GetResidueRenamingTwoTer(const String &name) const
InteractionPtr GetConstraint(const String &type1, const String &type2)
std::vector< std::pair< String, String > > AtomRenamingType
Definition: forcefield.hh:205
void AddDihedral(InteractionPtr p)
std::vector< InteractionPtr > GetDihedrals(const String &type1, const String &type2, const String &type3, const String &type4) const
void SetFudgeQQ(Real f_qq)
Definition: forcefield.hh:161
String GetResidueRenamingNTer(const String &name) const
std::vector< String > GetBuildingBlockNames() const
void AddAngle(InteractionPtr p)
void AddBuildingBlock(const String &name, BuildingBlockPtr p)
Definition: forcefield.hh:137
void SetGenPairs(bool gen_pairs)
Definition: forcefield.hh:163
boost::shared_ptr< ResidueNames > ResidueNamesPtr
Definition: forcefield.hh:39
void AddResidueRenamingRule(const String &name, const String &ff_main_name, const String &ff_n_ter_name, const String &ff_c_ter_name, const String &ff_two_ter_name)
InteractionPtr GetBond(const String &type1, const String &type2) const
BlockModifierPtr GetCTerModifier(const String &res_name, const String &ter_name="") const
const AtomRenamingType & GetAtomRenamingRules(const String &res_name) const
boost::shared_ptr< BuildingBlock > BuildingBlockPtr