00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef OST_MM_GROMCACS_BLOCK_MODIFIERS_HH
00021 #define OST_MM_GROMCACS_BLOCK_MODIFIERS_HH
00022
00023
00024 #include <boost/shared_ptr.hpp>
00025
00026 #include <ost/message.hh>
00027 #include <ost/mol/bond_handle.hh>
00028 #include <ost/mol/residue_handle.hh>
00029 #include <ost/mol/entity_handle.hh>
00030 #include <ost/mol/atom_handle.hh>
00031 #include <ost/mol/xcs_editor.hh>
00032 #include <ost/geom/vec3.hh>
00033 #include <ost/mol/mm/block_modifiers.hh>
00034 #include <ost/mol/mm/buildingblock.hh>
00035
00036
00037 namespace ost{ namespace mol{ namespace mm{
00038
00039 class GromacsHydrogenConstructor;
00040 class GromacsTerminiConstructor;
00041 class GromacsBlockModifier;
00042
00043 typedef boost::shared_ptr<GromacsHydrogenConstructor> GromacsHydrogenConstructorPtr;
00044 typedef boost::shared_ptr<GromacsTerminiConstructor> GromacsTerminiConstructorPtr;
00045 typedef boost::shared_ptr<GromacsBlockModifier> GromacsBlockModifierPtr;
00046
00047 class GromacsPositionRuleEvaluator{
00048
00049 public:
00050 static std::vector<geom::Vec3> EvaluatePosRule(int rule, int number,
00051 const std::vector<geom::Vec3>& anchors);
00052 };
00053
00054 class GromacsHydrogenConstructor : public HydrogenConstructor{
00055
00056 public:
00057
00058 GromacsHydrogenConstructor() { }
00059
00060 virtual void ApplyOnBuildingBlock(BuildingBlockPtr);
00061
00062 virtual void ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol::XCSEditor& ed);
00063
00064 void AddHydrogenRule(uint number, int method,
00065 const std::vector<String>& hydrogen_names,
00066 const std::vector<String>& anchors);
00067
00068 virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
00069
00070 virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; }
00071
00072 template <typename DS>
00073 void Serialize(DS& ds){
00074 int num_hydrogen_add_rules = add_number_.size();
00075 ds & num_hydrogen_add_rules;
00076
00077 if(ds.IsSource()){
00078 add_number_ = std::vector<int>(num_hydrogen_add_rules);
00079 methods_ = std::vector<int>(num_hydrogen_add_rules);
00080 hydrogen_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
00081 anchor_atom_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
00082 }
00083
00084 for(int i = 0; i < num_hydrogen_add_rules; ++i){
00085 ds & add_number_[i];
00086 ds & methods_[i];
00087 int num_hydrogen_names = hydrogen_names_[i].size();
00088 int num_anchor_names = anchor_atom_names_[i].size();
00089 ds & num_hydrogen_names;
00090 ds & num_anchor_names;
00091 if(ds.IsSource()){
00092 hydrogen_names_[i] = std::vector<String>(num_hydrogen_names);
00093 anchor_atom_names_[i] = std::vector<String>(num_anchor_names);
00094 }
00095
00096 for(int j = 0; j < num_hydrogen_names; ++j){
00097 ds & hydrogen_names_[i][j];
00098 }
00099 for(int j = 0; j < num_anchor_names; ++j){
00100 ds & anchor_atom_names_[i][j];
00101 }
00102 }
00103 }
00104
00105 private:
00106 std::vector<int> add_number_;
00107 std::vector<int> methods_;
00108 std::vector<std::vector<String> > hydrogen_names_;
00109 std::vector<std::vector<String> > anchor_atom_names_;
00110 };
00111
00112
00113 class GromacsBlockModifier : public BlockModifier{
00114
00115 public:
00116
00117 GromacsBlockModifier() { }
00118
00119 virtual void ApplyOnBuildingBlock(BuildingBlockPtr p);
00120
00121 virtual void ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol::XCSEditor& ed);
00122
00123 void AddReplaceRule(const String& name, const String& new_name,
00124 const String& new_type, Real new_charge);
00125
00126 void AddAddRule(int number, int method,
00127 const std::vector<String>& atom_names,
00128 const std::vector<String>& anchors,
00129 const String& type, Real charge);
00130
00131 void AddBond(InteractionPtr p) { this->CheckInteractionToAdd(p,"BOND");
00132 bonds_.push_back(p); }
00133
00134 void AddAngle(InteractionPtr p) { this->CheckInteractionToAdd(p,"ANGLE");
00135 angles_.push_back(p); }
00136
00137 void AddDihedral(InteractionPtr p) { this->CheckInteractionToAdd(p,"DIHEDRAL");
00138 dihedrals_.push_back(p); }
00139
00140 void AddImproper(InteractionPtr p) { this->CheckInteractionToAdd(p,"IMPROPER");
00141 impropers_.push_back(p); }
00142
00143 void AddCMap(InteractionPtr p) { this->CheckInteractionToAdd(p,"CMAP");
00144 cmaps_.push_back(p); }
00145
00146 void AddDeleteAtom(const String& atom_name) { delete_atom_names_.push_back(atom_name); }
00147
00148 virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
00149
00150 virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; }
00151
00152 template <typename DS>
00153 void Serialize(DS& ds){
00154
00155 int num_bonds = bonds_.size();
00156 int num_angles = angles_.size();
00157 int num_dihedrals = dihedrals_.size();
00158 int num_impropers = impropers_.size();
00159 int num_cmaps = cmaps_.size();
00160
00161 ds & num_bonds;
00162 ds & num_angles;
00163 ds & num_dihedrals;
00164 ds & num_impropers;
00165 ds & num_cmaps;
00166
00167 for(int i = 0; i < num_bonds; ++i){
00168 int func_type;
00169 if(ds.IsSource()){
00170 ds & func_type;
00171 bonds_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00172 }
00173 else{
00174 func_type = bonds_[i]->GetFuncType();
00175 ds & func_type;
00176 }
00177 ds & *(bonds_[i]);
00178 }
00179
00180 for(int i = 0; i < num_angles; ++i){
00181 int func_type;
00182 if(ds.IsSource()){
00183 ds & func_type;
00184 angles_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00185 }
00186 else{
00187 func_type = angles_[i]->GetFuncType();
00188 ds & func_type;
00189 }
00190 ds & *(angles_[i]);
00191 }
00192
00193 for(int i = 0; i < num_dihedrals; ++i){
00194 int func_type;
00195 if(ds.IsSource()){
00196 ds & func_type;
00197 dihedrals_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00198 }
00199 else{
00200 func_type = dihedrals_[i]->GetFuncType();
00201 ds & func_type;
00202 }
00203 ds & *(dihedrals_[i]);
00204 }
00205
00206 for(int i = 0; i < num_impropers; ++i){
00207 int func_type;
00208 if(ds.IsSource()){
00209 ds & func_type;
00210 impropers_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00211 }
00212 else{
00213 func_type = impropers_[i]->GetFuncType();
00214 ds & func_type;
00215 }
00216 ds & *(impropers_[i]);
00217 }
00218
00219 for(int i = 0; i < num_cmaps; ++i){
00220 int func_type;
00221 if(ds.IsSource()){
00222 ds & func_type;
00223 cmaps_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00224 }
00225 else{
00226 func_type = cmaps_[i]->GetFuncType();
00227 ds & func_type;
00228 }
00229 ds & *(cmaps_[i]);
00230 }
00231
00232 int num_replace_atoms = replace_old_atom_name_.size();
00233 ds & num_replace_atoms;
00234
00235 if(ds.IsSource()){
00236 replace_old_atom_name_ = std::vector<String>(num_replace_atoms);
00237 replace_new_atom_name_ = std::vector<String>(num_replace_atoms);
00238 replace_new_atom_type_ = std::vector<String>(num_replace_atoms);
00239 replace_new_charge_ = std::vector<Real>(num_replace_atoms);
00240 }
00241
00242 for(int i = 0; i < num_replace_atoms; ++i){
00243 ds & replace_old_atom_name_[i];
00244 ds & replace_new_atom_name_[i];
00245 ds & replace_new_atom_type_[i];
00246 ds & replace_new_charge_[i];
00247 }
00248
00249 int num_add_atoms = add_add_number_.size();
00250 ds & num_add_atoms;
00251
00252 if(ds.IsSource()){
00253 add_add_number_ = std::vector<int>(num_add_atoms);
00254 add_methods_ = std::vector<int>(num_add_atoms);
00255 add_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
00256 add_anchor_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
00257 add_atom_types_ = std::vector<String>(num_add_atoms);
00258 add_charges_ = std::vector<Real>(num_add_atoms);
00259 }
00260
00261 for(int i = 0; i < num_add_atoms; ++i){
00262 ds & add_add_number_[i];
00263 ds & add_methods_[i];
00264 ds & add_atom_types_[i];
00265 ds & add_charges_[i];
00266 int num_add_atom_names = add_atom_names_[i].size();
00267 int num_add_anchor_atom_names = add_anchor_atom_names_[i].size();
00268 ds & num_add_atom_names;
00269 ds & num_add_anchor_atom_names;
00270 if(ds.IsSource()){
00271 add_atom_names_[i] = std::vector<String>(num_add_atom_names);
00272 add_anchor_atom_names_[i] = std::vector<String>(num_add_anchor_atom_names);
00273 }
00274 for(int j = 0; j < num_add_atom_names; ++j){
00275 ds & add_atom_names_[i][j];
00276 }
00277 for(int j = 0; j < num_add_anchor_atom_names; ++j){
00278 ds & add_anchor_atom_names_[i][j];
00279 }
00280 }
00281
00282 int num_delete_atoms = delete_atom_names_.size();
00283 ds & num_delete_atoms;
00284 if(ds.IsSource()){
00285 delete_atom_names_ = std::vector<String>(num_delete_atoms);
00286 }
00287 for(int i = 0; i < num_delete_atoms; ++i){
00288 ds & delete_atom_names_[i];
00289 }
00290 }
00291
00292 private:
00293
00294 void CheckInteractionToAdd(InteractionPtr p, const String& interaction_type) const;
00295
00296
00297
00298
00299 std::vector<InteractionPtr> bonds_;
00300 std::vector<InteractionPtr> angles_;
00301 std::vector<InteractionPtr> dihedrals_;
00302 std::vector<InteractionPtr> impropers_;
00303 std::vector<InteractionPtr> cmaps_;
00304
00305
00306 std::vector<String> replace_old_atom_name_;
00307 std::vector<String> replace_new_atom_name_;
00308 std::vector<String> replace_new_atom_type_;
00309 std::vector<Real> replace_new_charge_;
00310
00311
00312 std::vector<int> add_add_number_;
00313 std::vector<int> add_methods_;
00314 std::vector<std::vector<String> > add_atom_names_;
00315 std::vector<std::vector<String> > add_anchor_atom_names_;
00316 std::vector<String> add_atom_types_;
00317 std::vector<Real> add_charges_;
00318
00319
00320 std::vector<String> delete_atom_names_;
00321 };
00322
00323
00324
00325
00326 }}}
00327
00328 #endif