IMP  2.0.1
The Integrative Modeling Platform
HybridMonteCarlo.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/HybridMonteCarlo.h
3  * \brief A hybrid monte carlo implementation
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPISD_HYBRID_MONTE_CARLO_H
10 #define IMPISD_HYBRID_MONTE_CARLO_H
11 
12 #include <IMP/isd/isd_config.h>
13 #include <IMP/core/MonteCarlo.h>
16 
17 IMPISD_BEGIN_NAMESPACE
18 
19 //! Hybrid Monte Carlo optimizer
20 
21 class IMPISDEXPORT HybridMonteCarlo : public core::MonteCarlo
22 {
23 
24 public:
25  HybridMonteCarlo(Model *m, Float kT=1.0, unsigned steps=100,
26  Float timestep=1.0, unsigned persistence=1);
27 
28  Float get_kinetic_energy() const;
29 
30  Float get_potential_energy() const;
31 
32  Float get_total_energy() const;
33 
34  //set md timestep
35  void set_timestep(Float ts);
36  double get_timestep() const;
37 
38  //set number of md steps per mc step
39  void set_number_of_md_steps(unsigned nsteps);
40  unsigned get_number_of_md_steps() const;
41 
42  //set how many mc steps happen until you redraw the momenta
43  void set_persistence(unsigned persistence=1);
44  unsigned get_persistence() const;
45 
46  //return pointer to isd::MolecularDynamics instance
47  //useful if you want to set other stuff that is not exposed here
48  MolecularDynamics* get_md() const;
49 
50  //evaluate should return the total energy
51  double do_evaluate(const ParticleIndexes &) const
52 {
53  double ekin = md_->get_kinetic_energy();
54  double epot;
55  if (get_maximum_difference() < std::numeric_limits<double>::max()) {
56  epot = get_scoring_function()->evaluate_if_below(false,
57  get_last_accepted_energy()+get_maximum_difference());
58  } else {
59  epot = get_scoring_function()->evaluate(false);
60  }
61  return ekin + epot;
62 }
63 
64  virtual void do_step();
66 private:
67  unsigned num_md_steps_,persistence_;
68  unsigned persistence_counter_;
69  IMP::internal::OwnerPointer<MolecularDynamicsMover> mv_;
70  IMP::Pointer<MolecularDynamics> md_;
71 
72 };
73 
74 IMPISD_END_NAMESPACE
75 
76 #endif /* IMPISD_HYBRID_MONTE_CARLO_H */