OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ff_reader.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_FORCEFIELD_READER_HH
21 #define OST_MM_FORCEFIELD_READER_HH
22 
23 #include <fstream>
24 
25 #include <boost/filesystem.hpp>
26 #include <boost/algorithm/string.hpp>
27 #include <boost/lexical_cast.hpp>
28 #include <boost/unordered_map.hpp>
29 
30 #include <ost/base.hh>
31 #include <ost/io/io_exception.hh>
32 #include <ost/mol/mm/forcefield.hh>
35 
36 
37 namespace ost { namespace mol{ namespace mm{
38 
39 class GromacsData;
40 class CHARMMData;
41 class FFReader;
42 typedef boost::shared_ptr<GromacsData> GromacsDataPtr;
43 typedef boost::shared_ptr<FFReader> FFReaderPtr;
44 typedef boost::shared_ptr<CHARMMData> CHARMMDataPtr;
45 
47 public:
48  static GromacsDataPtr Instance();
49  int GetKeywordIndex(const String& keyword);
50  String ConvertToStandard(const String& res_name, const String& atom_name);
51  bool ConversionExists(const String& res_name);
52 
53 private:
54  GromacsData();
55  GromacsData(const GromacsData&);
56  GromacsDataPtr operator=(const GromacsDataPtr&);
57  static GromacsDataPtr instance_;
58  boost::unordered_map<String,int> keyword_map_;
59  boost::unordered_map<String, std::vector<std::pair<String,String> > > renaming_to_standard_;
60 
61 };
62 
63 class CHARMMData{
64 public:
65  static CHARMMDataPtr Instance();
66  int GetKeywordIndex(const String& keyword);
67 
68 private:
69  CHARMMData();
70  CHARMMData(const CHARMMData&);
71  CHARMMDataPtr operator=(const CHARMMDataPtr&);
72  static CHARMMDataPtr instance_;
73  boost::unordered_map<String,int> keyword_map_;
74 };
75 
77 
78 public:
79 
80  MMPreprocessor(const String& basepath): basepath_(basepath) { }
81 
82  std::vector<std::vector<String> > Process(const String& filename);
83 
84  void SetDefinition(const String& def) { defines_.insert(def); }
85 
86  boost::filesystem::path GetBasedir() { return basepath_; }
87 
88 private:
89 
90  //function, that can recursively resolve ifdef / ifndef statements
91  void ResolveIFDEF(std::vector<std::vector<String> >& file_content, int line_counter);
92 
93  //simply reads a file, cuts it into pieces and removes comments marked by '*' and ';'
94  std::vector<std::vector<String> > ReadFile(const String& filename);
95 
96  std::map<String,std::vector<String> > definitions_;
97  std::set<String> defines_;
98  boost::filesystem::path basepath_;
99 };
100 
101 
102 class FFReader {
103 public:
104 
105  FFReader(const String& base_dir);
106 
107  void SetPreprocessorDefinition(const String& def) { preprocessor_.SetDefinition(def); }
108 
109  void ReadGromacsForcefield();
110 
111  ForcefieldPtr GetForcefield() { return ff_;}
112 
113  void SetForcefield(ForcefieldPtr ff) { ff_ = ff; }
114 
115  void ReadResidueDatabase(const String& basename);
116 
117  void ReadITP(const String& basename);
118 
119  void ReadCHARMMPRM(const String& basename);
120 
121  void ReadCHARMMRTF(const String& basename);
122 
123 private:
124 
125  InteractionPtr ParseBond(const std::vector<String>& data,
126  bool type_definition,
127  FuncType functype = Invalid);
128 
129  InteractionPtr ParseAngle(const std::vector<String>& data,
130  bool type_definition,
131  FuncType functype = Invalid);
132 
133  InteractionPtr ParseDihedral(const std::vector<String>& data,
134  bool type_definition,
135  FuncType functype = Invalid);
136 
137  InteractionPtr ParseCMap(const std::vector<String>& data,
138  bool type_definition,
139  FuncType functype = Invalid);
140 
141  InteractionPtr ParseLJ(const std::vector<String>& data,
142  bool type_definition,
143  FuncType functype = Invalid);
144 
145  InteractionPtr ParseLJPair(const std::vector<String>& data,
146  bool type_definition,
147  FuncType functype = Invalid);
148 
149  InteractionPtr ParseConstraint(const std::vector<String>& data,
150  bool type_definition,
151  FuncType functype = Invalid);
152 
153  InteractionPtr ParseGenborn(const std::vector<String>& data,
154  bool type_definition,
155  FuncType functype = Invalid);
156 
157  InteractionPtr ParseExclusion(const std::vector<String>& data,
158  bool type_definition,
159  FuncType functype = Invalid);
160 
161  BuildingBlockPtr BlockFromRTP(const std::vector<std::vector<String> >& data);
162 
163  BuildingBlockPtr BlockFromITP(const std::vector<std::vector<String> >& data);
164 
165  TerminiConstructorPtr ParseTermini(const std::vector<std::vector<String> >& data);
166 
167  BlockModifierPtr ParseBlockModifier(const std::vector<std::vector<String> >& data);
168 
169  void ParseHydrogenRule(const std::vector<String>& data, GromacsHydrogenConstructor& constructor);
170 
171  void ParseTerminiReplaceRule(const std::vector<String>& data, GromacsBlockModifier& constructor);
172 
173  void ParseTerminiAddRule(const std::vector<String>& data1, const std::vector<String>& data2,
174  GromacsBlockModifier& constructor);
175 
176  //Reader functions for the mandatory forcefield files
177  void ParseForcefield(std::vector<std::vector<String> >& content);
178  void ParseAtomTypes(std::vector<std::vector<String> >& content);
179 
180  //Reader functions for CHARMM stuff
181  void ParseCHARMMPRM(std::vector<std::vector<String> >& content);
182 
183  void ParseCHARMMRTF(std::vector<std::vector<String> >& content);
184 
185  //Reader functions for all different residue database files
186  void ParseRTP(std::vector<std::vector<String> >& content);
187  void ParseARN(std::vector<std::vector<String> >& content);
188  void ParseHDB(std::vector<std::vector<String> >& content);
189  void ParseNTDB(std::vector<std::vector<String> >& content);
190  void ParseCTDB(std::vector<std::vector<String> >& content);
191  void ParseVSD(std::vector<std::vector<String> >& content);
192  void ParseRtoB(std::vector<std::vector<String> >& content);
193  //Reader function for single molecule itp files
194  void ParseITP(std::vector<std::vector<String> >& content);
195 
196  boost::unordered_map<String, std::vector<std::pair<String,String> > > atom_renaming_ff_specific_;
197  boost::unordered_map<String, ResidueNamesPtr> res_renaming_ff_specific_;
198 
199  std::vector<FuncType> ff_bonded_types_;
200 
201  MMPreprocessor preprocessor_;
202  ForcefieldPtr ff_;
203 
204  //following part is ugly...
205  //data that is read during the residue datababase parsing process gets stored in there
206  std::vector<FuncType> bonded_types_;
207  std::vector<String> read_residues_;
208 };
209 
210 
211 }}}//ns
212 
213 #endif
void ReadCHARMMPRM(const String &basename)
String ConvertToStandard(const String &res_name, const String &atom_name)
void ReadCHARMMRTF(const String &basename)
boost::shared_ptr< Interaction > InteractionPtr
Definition: interaction.hh:39
std::string String
Definition: base.hh:54
ForcefieldPtr GetForcefield()
Definition: ff_reader.hh:111
void SetPreprocessorDefinition(const String &def)
Definition: ff_reader.hh:107
void ReadITP(const String &basename)
bool ConversionExists(const String &res_name)
boost::shared_ptr< BlockModifier > BlockModifierPtr
boost::filesystem::path GetBasedir()
Definition: ff_reader.hh:86
int GetKeywordIndex(const String &keyword)
boost::shared_ptr< CHARMMData > CHARMMDataPtr
Definition: ff_reader.hh:44
std::vector< std::vector< String > > Process(const String &filename)
static GromacsDataPtr Instance()
FFReader(const String &base_dir)
boost::shared_ptr< FFReader > FFReaderPtr
Definition: ff_reader.hh:43
boost::shared_ptr< GromacsData > GromacsDataPtr
Definition: ff_reader.hh:41
boost::shared_ptr< ost::mol::mm::Forcefield > ForcefieldPtr
Definition: forcefield.hh:42
static CHARMMDataPtr Instance()
int GetKeywordIndex(const String &keyword)
void SetForcefield(ForcefieldPtr ff)
Definition: ff_reader.hh:113
boost::shared_ptr< TerminiConstructor > TerminiConstructorPtr
void ReadResidueDatabase(const String &basename)
MMPreprocessor(const String &basepath)
Definition: ff_reader.hh:80
void SetDefinition(const String &def)
Definition: ff_reader.hh:84
boost::shared_ptr< BuildingBlock > BuildingBlockPtr