00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OST_MM_FORCEFIELD_READER_HH
00021 #define OST_MM_FORCEFIELD_READER_HH
00022
00023 #include <fstream>
00024
00025 #include <boost/filesystem.hpp>
00026 #include <boost/algorithm/string.hpp>
00027 #include <boost/lexical_cast.hpp>
00028 #include <boost/unordered_map.hpp>
00029
00030 #include <ost/base.hh>
00031 #include <ost/io/io_exception.hh>
00032 #include <ost/mol/mm/forcefield.hh>
00033 #include <ost/mol/mm/interaction.hh>
00034 #include <ost/mol/mm/gromacs_block_modifiers.hh>
00035
00036
00037 namespace ost { namespace mol{ namespace mm{
00038
00039 class GromacsData;
00040 class CHARMMData;
00041 class FFReader;
00042 typedef boost::shared_ptr<GromacsData> GromacsDataPtr;
00043 typedef boost::shared_ptr<FFReader> FFReaderPtr;
00044 typedef boost::shared_ptr<CHARMMData> CHARMMDataPtr;
00045
00046 class GromacsData{
00047 public:
00048 static GromacsDataPtr Instance();
00049 int GetKeywordIndex(const String& keyword);
00050 String ConvertToStandard(const String& res_name, const String& atom_name);
00051 bool ConversionExists(const String& res_name);
00052
00053 private:
00054 GromacsData();
00055 GromacsData(const GromacsData&);
00056 GromacsDataPtr operator=(const GromacsDataPtr&);
00057 static GromacsDataPtr instance_;
00058 boost::unordered_map<String,int> keyword_map_;
00059 boost::unordered_map<String, std::vector<std::pair<String,String> > > renaming_to_standard_;
00060
00061 };
00062
00063 class CHARMMData{
00064 public:
00065 static CHARMMDataPtr Instance();
00066 int GetKeywordIndex(const String& keyword);
00067
00068 private:
00069 CHARMMData();
00070 CHARMMData(const CHARMMData&);
00071 CHARMMDataPtr operator=(const CHARMMDataPtr&);
00072 static CHARMMDataPtr instance_;
00073 boost::unordered_map<String,int> keyword_map_;
00074 };
00075
00076 class MMPreprocessor{
00077
00078 public:
00079
00080 MMPreprocessor(const String& basepath): basepath_(basepath) { }
00081
00082 std::vector<std::vector<String> > Process(const String& filename);
00083
00084 void SetDefinition(const String& def) { defines_.insert(def); }
00085
00086 boost::filesystem::path GetBasedir() { return basepath_; }
00087
00088 private:
00089
00090
00091 void ResolveIFDEF(std::vector<std::vector<String> >& file_content, int line_counter);
00092
00093
00094 std::vector<std::vector<String> > ReadFile(const String& filename);
00095
00096 std::map<String,std::vector<String> > definitions_;
00097 std::set<String> defines_;
00098 boost::filesystem::path basepath_;
00099 };
00100
00101
00102 class FFReader {
00103 public:
00104
00105 FFReader(const String& base_dir);
00106
00107 void SetPreprocessorDefinition(const String& def) { preprocessor_.SetDefinition(def); }
00108
00109 void ReadGromacsForcefield();
00110
00111 ForcefieldPtr GetForcefield() { return ff_;}
00112
00113 void SetForcefield(ForcefieldPtr ff) { ff_ = ff; }
00114
00115 void ReadResidueDatabase(const String& basename);
00116
00117 void ReadITP(const String& basename);
00118
00119 void ReadCHARMMPRM(const String& basename);
00120
00121 void ReadCHARMMRTF(const String& basename);
00122
00123 private:
00124
00125 InteractionPtr ParseBond(const std::vector<String>& data,
00126 bool type_definition,
00127 FuncType functype = Invalid);
00128
00129 InteractionPtr ParseAngle(const std::vector<String>& data,
00130 bool type_definition,
00131 FuncType functype = Invalid);
00132
00133 InteractionPtr ParseDihedral(const std::vector<String>& data,
00134 bool type_definition,
00135 FuncType functype = Invalid);
00136
00137 InteractionPtr ParseCMap(const std::vector<String>& data,
00138 bool type_definition,
00139 FuncType functype = Invalid);
00140
00141 InteractionPtr ParseLJ(const std::vector<String>& data,
00142 bool type_definition,
00143 FuncType functype = Invalid);
00144
00145 InteractionPtr ParseLJPair(const std::vector<String>& data,
00146 bool type_definition,
00147 FuncType functype = Invalid);
00148
00149 InteractionPtr ParseConstraint(const std::vector<String>& data,
00150 bool type_definition,
00151 FuncType functype = Invalid);
00152
00153 InteractionPtr ParseGenborn(const std::vector<String>& data,
00154 bool type_definition,
00155 FuncType functype = Invalid);
00156
00157 InteractionPtr ParseExclusion(const std::vector<String>& data,
00158 bool type_definition,
00159 FuncType functype = Invalid);
00160
00161 BuildingBlockPtr BlockFromRTP(const std::vector<std::vector<String> >& data);
00162
00163 BuildingBlockPtr BlockFromITP(const std::vector<std::vector<String> >& data);
00164
00165 TerminiConstructorPtr ParseTermini(const std::vector<std::vector<String> >& data);
00166
00167 BlockModifierPtr ParseBlockModifier(const std::vector<std::vector<String> >& data);
00168
00169 void ParseHydrogenRule(const std::vector<String>& data, GromacsHydrogenConstructor& constructor);
00170
00171 void ParseTerminiReplaceRule(const std::vector<String>& data, GromacsBlockModifier& constructor);
00172
00173 void ParseTerminiAddRule(const std::vector<String>& data1, const std::vector<String>& data2,
00174 GromacsBlockModifier& constructor);
00175
00176
00177 void ParseForcefield(std::vector<std::vector<String> >& content);
00178 void ParseAtomTypes(std::vector<std::vector<String> >& content);
00179
00180
00181 void ParseCHARMMPRM(std::vector<std::vector<String> >& content);
00182
00183 void ParseCHARMMRTF(std::vector<std::vector<String> >& content);
00184
00185
00186 void ParseRTP(std::vector<std::vector<String> >& content);
00187 void ParseARN(std::vector<std::vector<String> >& content);
00188 void ParseHDB(std::vector<std::vector<String> >& content);
00189 void ParseNTDB(std::vector<std::vector<String> >& content);
00190 void ParseCTDB(std::vector<std::vector<String> >& content);
00191 void ParseVSD(std::vector<std::vector<String> >& content);
00192 void ParseRtoB(std::vector<std::vector<String> >& content);
00193
00194 void ParseITP(std::vector<std::vector<String> >& content);
00195
00196 boost::unordered_map<String, std::vector<std::pair<String,String> > > atom_renaming_ff_specific_;
00197 boost::unordered_map<String, ResidueNamesPtr> res_renaming_ff_specific_;
00198
00199 std::vector<FuncType> ff_bonded_types_;
00200
00201 MMPreprocessor preprocessor_;
00202 ForcefieldPtr ff_;
00203
00204
00205
00206 std::vector<FuncType> bonded_types_;
00207 std::vector<String> read_residues_;
00208 };
00209
00210
00211 }}}
00212
00213 #endif