Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TrajectoryRecorder.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet;
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file protocols/canonical_sampling/TrajectoryRecorder.cc
11 ///
12 /// @brief
13 /// @author
14 
15 
16 // Unit header or inline function header
18 
19 // Other project headers or inline function headers
21 #include <core/pose/Pose.hh>
22 #include <core/scoring/Energies.hh>
25 // AUTO-REMOVED #include <protocols/canonical_sampling/ThermodynamicMover.hh> // required for Windows build
26 #include <utility/tag/Tag.hh>
27 
28 // External library headers
29 
30 // C++ headers
31 #include <iomanip>
32 #include <basic/options/option_macros.hh>
33 #include <basic/Tracer.hh>
34 
35 static basic::Tracer tr( "protocols.canonical_sampling.TrajectoryRecorder" );
36 
37 #include <utility/vector0.hh>
38 #include <utility/vector1.hh>
39 // Operating system headers
40 
41 OPT_1GRP_KEY( Integer, trajectory, stride )
42 OPT_1GRP_KEY( Boolean, trajectory, cumulate_jobs )
43 OPT_1GRP_KEY( Boolean, trajectory, cumulate_replicas )
44 
45 bool protocols::canonical_sampling::TrajectoryRecorder::options_registered_( false );
46 
47 void protocols::canonical_sampling::TrajectoryRecorder::register_options() {
48  using namespace basic::options;
49  using namespace OptionKeys;
50  if ( options_registered_ ) return;
51  options_registered_ = true;
52  NEW_OPT( trajectory::stride, "how often should a snapshot be written to the trajectory", 1 );
53  NEW_OPT( trajectory::cumulate_jobs, "write structures from different jobs into the same trajectory file", false );
54  NEW_OPT( trajectory::cumulate_replicas, "write structures from different replicas the same trajectory file", false );
55 }
56 
57 
58 namespace protocols {
59 namespace canonical_sampling {
60 
61 TrajectoryRecorder::TrajectoryRecorder() :
62  stride_(1),
63  model_count_(0),
64  step_count_(0),
65  cumulate_jobs_( false ),
66  cumulate_replicas_( false )
67 {
68  using namespace basic::options;
69  using namespace OptionKeys;
70  if ( options_registered_ ) {
71  stride_ = option[ OptionKeys::trajectory::stride ]();
72  cumulate_jobs_ = option[ OptionKeys::trajectory::cumulate_jobs ]();
73  cumulate_replicas_ = option[ OptionKeys::trajectory::cumulate_replicas ]();
74  }
75  file_name_ = "traj";
76 }
77 
79 {}
80 
82  TrajectoryRecorder const & other
83 ) :
84  protocols::canonical_sampling::ThermodynamicObserver(other),
85  stride_(other.stride_),
87  step_count_(other.step_count_),
88  file_name_(other.file_name_),
91 {}
92 
95 {
96  // assignment not allowed
97  runtime_assert(false);
98  return *this;
99 }
100 
103 {
104  return "TrajectoryRecorder";
105 }
106 
107 void
109  utility::tag::TagPtr const tag,
110  protocols::moves::DataMap & /* data */,
111  protocols::filters::Filters_map const & /* filters */,
112  protocols::moves::Movers_map const & /* movers */,
113  core::pose::Pose const & /* pose */
114 )
115 {
116  stride_ = tag->getOption< core::Size >( "stride", 100 );
117  file_name_ = tag->getOption< std::string >( "filename", file_name_ );
118  cumulate_jobs_= tag->getOption< bool > ("cumulate_jobs", false );
119  cumulate_replicas_= tag->getOption< bool > ("cumulate_replicas", false );
120 }
121 
122 void
126 ) {
127  model_count_ = 0;
128  step_count_ = 0;
129 }
130 
131 void
133  core::pose::Pose const & pose,
134  protocols::canonical_sampling::MetropolisHastingsMoverCAP metropolis_hastings_mover //= 0
135  ) {
136  ++step_count_;
137 
138  if (step_count_ % stride_ == 0) {
139  ++model_count_;
140  write_model(pose, metropolis_hastings_mover);
141  }
142 }
143 
144 void
147 }
148 
149 void
152 }
153 
154 void
157  protocols::canonical_sampling::MetropolisHastingsMover const & metropolis_hastings_mover,
158  core::Size cycle //default=0; non-zero if trajectory is restarted
159 ) {
160  reset(
161  *(metropolis_hastings_mover.monte_carlo()),
162  &metropolis_hastings_mover
163  );
164  if (cycle != 0) {
165  step_count_ = cycle;
167  }
168 }
169 
170 void
172  protocols::canonical_sampling::MetropolisHastingsMover const & metropolis_hastings_mover
173 )
174 {
176  metropolis_hastings_mover.monte_carlo()->last_accepted_pose(),
177  &metropolis_hastings_mover
178  );
179 }
180 
181 } // namespace canonical_sampling
182 } // namespace protocols