OpenStructure
observer.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-2020 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_OBSERVER_HH
21 #define OST_MM_OBSERVER_HH
22 
23 
24 #include <boost/shared_ptr.hpp>
25 
26 #include <ost/io/mol/io_profile.hh>
27 #include <ost/io/mol/pdb_writer.hh>
28 #include <ost/mol/entity_handle.hh>
29 #include <ost/mol/coord_frame.hh>
30 #include <ost/mol/coord_group.hh>
32 #include <ost/mol/mm/topology.hh>
33 #include <ost/mol/mm/modeller.hh>
34 #include <ost/stdint.hh>
35 
36 namespace OpenMM{
37  class Context; //hacky way of telling the Context is around.
38  //will be included in source file to avoid
39  //dependencies on external libraries
40 }
41 
42 namespace ost { namespace mol{ namespace mm{
43 
44 class Observer;
45 class TrajObserver;
46 class TrajWriter;
47 typedef boost::shared_ptr<Observer> ObserverPtr;
48 typedef boost::shared_ptr<TrajObserver> TrajObserverPtr;
49 typedef boost::shared_ptr<TrajWriter> TrajWriterPtr;
50 
51 
52 class Observer{
53 public:
54 
55  virtual void Notify() = 0;
56 
57  virtual void Init(boost::shared_ptr<OpenMM::Context> c,
58  TopologyPtr top,
59  ost::mol::EntityHandle& ent) = 0;
60 
61  virtual int Rhythm() = 0;
62 
63 };
64 
65 
66 class TrajObserver : public Observer{
67 
68 public:
69 
70  TrajObserver(int rhythm): rhythm_(rhythm), registered_(false) { }
71 
72  void Init(boost::shared_ptr<OpenMM::Context> c,
73  TopologyPtr top,
75 
76  void Notify();
77 
78  int Rhythm() { return rhythm_; }
79 
80  CoordGroupHandle GetTraj() { return c_group_; }
81 
82 private:
83 
85  boost::shared_ptr<OpenMM::Context> context_;
86  int rhythm_;
87  bool registered_;
88 };
89 
90 class TrajWriter : public Observer{
91 
92 //Note, that this code is highly redundant to the code in io/mol/dcd_io.hh!!!
93 
94 public:
95 
96  TrajWriter(int rhythm, const String& pdb_filename, const String& dcd_filename)
97  : rhythm_(rhythm), pdb_filename_(pdb_filename),
98  dcd_filename_(dcd_filename), stream_(), registered_(false),
99  frames_(0) { }
100 
101  void Init(boost::shared_ptr<OpenMM::Context> c,
102  TopologyPtr top,
104 
105  void Notify();
106 
107  int Rhythm() { return rhythm_; }
108 
109  void Finalize();
110 
111 private:
112 
113  TrajWriter(const TrajWriter& writer) { } //output filestream is unique!
114 
115 
116  boost::shared_ptr<OpenMM::Context> context_;
117  int rhythm_;
118  String pdb_filename_;
119  String dcd_filename_;
120  std::ofstream stream_;
121  bool registered_;
122  uint32_t frames_;
123  std::vector<float> x;
124  std::vector<float> y;
125  std::vector<float> z;
126 };
127 
128 
129 }}}//ns
130 
131 #endif
coordinate group, for trajectories and such
Definition: coord_group.hh:39
Protein or molecule.
virtual int Rhythm()=0
virtual void Init(boost::shared_ptr< OpenMM::Context > c, TopologyPtr top, ost::mol::EntityHandle &ent)=0
virtual void Notify()=0
TrajObserver(int rhythm)
Definition: observer.hh:70
CoordGroupHandle GetTraj()
Definition: observer.hh:80
void Init(boost::shared_ptr< OpenMM::Context > c, TopologyPtr top, ost::mol::EntityHandle &ent)
void Init(boost::shared_ptr< OpenMM::Context > c, TopologyPtr top, ost::mol::EntityHandle &ent)
TrajWriter(int rhythm, const String &pdb_filename, const String &dcd_filename)
Definition: observer.hh:96
std::string String
Definition: base.hh:54
boost::shared_ptr< TrajWriter > TrajWriterPtr
Definition: observer.hh:49
boost::shared_ptr< Observer > ObserverPtr
Definition: observer.hh:46
boost::shared_ptr< Topology > TopologyPtr
Definition: topology.hh:48
boost::shared_ptr< TrajObserver > TrajObserverPtr
Definition: observer.hh:48
Definition: base.dox:1
unsigned int uint32_t
Definition: stdint_msc.hh:80