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
00069 uint GetNumHydrogenRules() const { return add_number_.size(); }
00070
00071 int GetHydrogenRuleNumber(uint idx) const { return add_number_[idx]; }
00072 int GetHydrogenRuleMethod(uint idx) const { return methods_[idx]; }
00073 const std::vector<String>&
00074 GetHydrogenRuleNames(uint idx) const { return hydrogen_names_[idx]; }
00075 const std::vector<String>&
00076 GetHydrogenRuleAnchors(uint idx) const { return anchor_atom_names_[idx]; }
00077
00078 virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
00079
00080 virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; }
00081
00082 template <typename DS>
00083 void Serialize(DS& ds){
00084 int num_hydrogen_add_rules = add_number_.size();
00085 ds & num_hydrogen_add_rules;
00086
00087 if(ds.IsSource()){
00088 add_number_ = std::vector<int>(num_hydrogen_add_rules);
00089 methods_ = std::vector<int>(num_hydrogen_add_rules);
00090 hydrogen_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
00091 anchor_atom_names_ = std::vector<std::vector<String> >(num_hydrogen_add_rules);
00092 }
00093
00094 for(int i = 0; i < num_hydrogen_add_rules; ++i){
00095 ds & add_number_[i];
00096 ds & methods_[i];
00097 int num_hydrogen_names = hydrogen_names_[i].size();
00098 int num_anchor_names = anchor_atom_names_[i].size();
00099 ds & num_hydrogen_names;
00100 ds & num_anchor_names;
00101 if(ds.IsSource()){
00102 hydrogen_names_[i] = std::vector<String>(num_hydrogen_names);
00103 anchor_atom_names_[i] = std::vector<String>(num_anchor_names);
00104 }
00105
00106 for(int j = 0; j < num_hydrogen_names; ++j){
00107 ds & hydrogen_names_[i][j];
00108 }
00109 for(int j = 0; j < num_anchor_names; ++j){
00110 ds & anchor_atom_names_[i][j];
00111 }
00112 }
00113 }
00114
00115 private:
00116 std::vector<int> add_number_;
00117 std::vector<int> methods_;
00118 std::vector<std::vector<String> > hydrogen_names_;
00119 std::vector<std::vector<String> > anchor_atom_names_;
00120 };
00121
00122
00123 class GromacsBlockModifier : public BlockModifier{
00124
00125 public:
00126
00127 GromacsBlockModifier() { }
00128
00129 virtual void ApplyOnBuildingBlock(BuildingBlockPtr p);
00130
00131 virtual void ApplyOnResidue(ost::mol::ResidueHandle& res, ost::mol::XCSEditor& ed);
00132
00133 void AddReplaceRule(const String& name, const String& new_name,
00134 const String& new_type, Real new_charge);
00135
00136 void AddAddRule(int number, int method,
00137 const std::vector<String>& atom_names,
00138 const std::vector<String>& anchors,
00139 const String& type, Real charge);
00140
00141 void AddBond(InteractionPtr p) { this->CheckInteractionToAdd(p,"BOND");
00142 bonds_.push_back(p); }
00143
00144 void AddAngle(InteractionPtr p) { this->CheckInteractionToAdd(p,"ANGLE");
00145 angles_.push_back(p); }
00146
00147 void AddDihedral(InteractionPtr p) { this->CheckInteractionToAdd(p,"DIHEDRAL");
00148 dihedrals_.push_back(p); }
00149
00150 void AddImproper(InteractionPtr p) { this->CheckInteractionToAdd(p,"IMPROPER");
00151 impropers_.push_back(p); }
00152
00153 void AddCMap(InteractionPtr p) { this->CheckInteractionToAdd(p,"CMAP");
00154 cmaps_.push_back(p); }
00155
00156 void AddDeleteAtom(const String& atom_name) { delete_atom_names_.push_back(atom_name); }
00157
00158
00159 const std::vector<InteractionPtr>& GetBonds() const { return bonds_; }
00160 const std::vector<InteractionPtr>& GetAngles() const { return angles_; }
00161 const std::vector<InteractionPtr>& GetDihedrals() const { return dihedrals_; }
00162 const std::vector<InteractionPtr>& GetImpropers() const { return impropers_; }
00163 const std::vector<InteractionPtr>& GetCmaps() const { return cmaps_; }
00164 const std::vector<String>& GetDeleteAtoms() const { return delete_atom_names_; }
00165
00166 uint GetNumReplaceRules() const { return replace_old_atom_name_.size(); }
00167 const String& GetReplaceRuleName(uint idx) const {
00168 return replace_old_atom_name_[idx];
00169 }
00170 const String& GetReplaceRuleNewName(uint idx) const {
00171 return replace_new_atom_name_[idx];
00172 }
00173 const String& GetReplaceRuleNewType(uint idx) const {
00174 return replace_new_atom_type_[idx];
00175 }
00176 Real GetReplaceRuleNewCharge(uint idx) const {
00177 return replace_new_charge_[idx];
00178 }
00179
00180 uint GetNumAddRules() const { return add_add_number_.size(); }
00181 int GetAddRuleNumber(uint idx) const { return add_add_number_[idx]; }
00182 int GetAddRuleMethod(uint idx) const { return add_methods_[idx]; }
00183 const std::vector<String>&
00184 GetAddRuleNames(uint idx) const { return add_atom_names_[idx]; }
00185 const std::vector<String>&
00186 GetAddRuleAnchors(uint idx) const { return add_anchor_atom_names_[idx]; }
00187 const String& GetAddRuleType(uint idx) const { return add_atom_types_[idx]; }
00188 Real GetAddRuleCharge(uint idx) const { return add_charges_[idx]; }
00189
00190 virtual void OnSave(ost::io::BinaryDataSink& ds) { ds << *this; }
00191
00192 virtual BlockModifierType GetBlockModifierType() { return GromacsBlockModifiers; }
00193
00194 template <typename DS>
00195 void Serialize(DS& ds){
00196
00197 int num_bonds = bonds_.size();
00198 int num_angles = angles_.size();
00199 int num_dihedrals = dihedrals_.size();
00200 int num_impropers = impropers_.size();
00201 int num_cmaps = cmaps_.size();
00202
00203 ds & num_bonds;
00204 ds & num_angles;
00205 ds & num_dihedrals;
00206 ds & num_impropers;
00207 ds & num_cmaps;
00208
00209 for(int i = 0; i < num_bonds; ++i){
00210 int func_type;
00211 if(ds.IsSource()){
00212 ds & func_type;
00213 bonds_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00214 }
00215 else{
00216 func_type = bonds_[i]->GetFuncType();
00217 ds & func_type;
00218 }
00219 ds & *(bonds_[i]);
00220 }
00221
00222 for(int i = 0; i < num_angles; ++i){
00223 int func_type;
00224 if(ds.IsSource()){
00225 ds & func_type;
00226 angles_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00227 }
00228 else{
00229 func_type = angles_[i]->GetFuncType();
00230 ds & func_type;
00231 }
00232 ds & *(angles_[i]);
00233 }
00234
00235 for(int i = 0; i < num_dihedrals; ++i){
00236 int func_type;
00237 if(ds.IsSource()){
00238 ds & func_type;
00239 dihedrals_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00240 }
00241 else{
00242 func_type = dihedrals_[i]->GetFuncType();
00243 ds & func_type;
00244 }
00245 ds & *(dihedrals_[i]);
00246 }
00247
00248 for(int i = 0; i < num_impropers; ++i){
00249 int func_type;
00250 if(ds.IsSource()){
00251 ds & func_type;
00252 impropers_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00253 }
00254 else{
00255 func_type = impropers_[i]->GetFuncType();
00256 ds & func_type;
00257 }
00258 ds & *(impropers_[i]);
00259 }
00260
00261 for(int i = 0; i < num_cmaps; ++i){
00262 int func_type;
00263 if(ds.IsSource()){
00264 ds & func_type;
00265 cmaps_.push_back(InteractionPtr(new Interaction(FuncType(func_type))));
00266 }
00267 else{
00268 func_type = cmaps_[i]->GetFuncType();
00269 ds & func_type;
00270 }
00271 ds & *(cmaps_[i]);
00272 }
00273
00274 int num_replace_atoms = replace_old_atom_name_.size();
00275 ds & num_replace_atoms;
00276
00277 if(ds.IsSource()){
00278 replace_old_atom_name_ = std::vector<String>(num_replace_atoms);
00279 replace_new_atom_name_ = std::vector<String>(num_replace_atoms);
00280 replace_new_atom_type_ = std::vector<String>(num_replace_atoms);
00281 replace_new_charge_ = std::vector<Real>(num_replace_atoms);
00282 }
00283
00284 for(int i = 0; i < num_replace_atoms; ++i){
00285 ds & replace_old_atom_name_[i];
00286 ds & replace_new_atom_name_[i];
00287 ds & replace_new_atom_type_[i];
00288 ds & replace_new_charge_[i];
00289 }
00290
00291 int num_add_atoms = add_add_number_.size();
00292 ds & num_add_atoms;
00293
00294 if(ds.IsSource()){
00295 add_add_number_ = std::vector<int>(num_add_atoms);
00296 add_methods_ = std::vector<int>(num_add_atoms);
00297 add_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
00298 add_anchor_atom_names_ = std::vector<std::vector<String> >(num_add_atoms);
00299 add_atom_types_ = std::vector<String>(num_add_atoms);
00300 add_charges_ = std::vector<Real>(num_add_atoms);
00301 }
00302
00303 for(int i = 0; i < num_add_atoms; ++i){
00304 ds & add_add_number_[i];
00305 ds & add_methods_[i];
00306 ds & add_atom_types_[i];
00307 ds & add_charges_[i];
00308 int num_add_atom_names = add_atom_names_[i].size();
00309 int num_add_anchor_atom_names = add_anchor_atom_names_[i].size();
00310 ds & num_add_atom_names;
00311 ds & num_add_anchor_atom_names;
00312 if(ds.IsSource()){
00313 add_atom_names_[i] = std::vector<String>(num_add_atom_names);
00314 add_anchor_atom_names_[i] = std::vector<String>(num_add_anchor_atom_names);
00315 }
00316 for(int j = 0; j < num_add_atom_names; ++j){
00317 ds & add_atom_names_[i][j];
00318 }
00319 for(int j = 0; j < num_add_anchor_atom_names; ++j){
00320 ds & add_anchor_atom_names_[i][j];
00321 }
00322 }
00323
00324 int num_delete_atoms = delete_atom_names_.size();
00325 ds & num_delete_atoms;
00326 if(ds.IsSource()){
00327 delete_atom_names_ = std::vector<String>(num_delete_atoms);
00328 }
00329 for(int i = 0; i < num_delete_atoms; ++i){
00330 ds & delete_atom_names_[i];
00331 }
00332 }
00333
00334 private:
00335
00336 void CheckInteractionToAdd(InteractionPtr p, const String& interaction_type) const;
00337
00338
00339
00340
00341 std::vector<InteractionPtr> bonds_;
00342 std::vector<InteractionPtr> angles_;
00343 std::vector<InteractionPtr> dihedrals_;
00344 std::vector<InteractionPtr> impropers_;
00345 std::vector<InteractionPtr> cmaps_;
00346
00347
00348 std::vector<String> replace_old_atom_name_;
00349 std::vector<String> replace_new_atom_name_;
00350 std::vector<String> replace_new_atom_type_;
00351 std::vector<Real> replace_new_charge_;
00352
00353
00354 std::vector<int> add_add_number_;
00355 std::vector<int> add_methods_;
00356 std::vector<std::vector<String> > add_atom_names_;
00357 std::vector<std::vector<String> > add_anchor_atom_names_;
00358 std::vector<String> add_atom_types_;
00359 std::vector<Real> add_charges_;
00360
00361
00362 std::vector<String> delete_atom_names_;
00363 };
00364
00365
00366
00367
00368 }}}
00369
00370 #endif