MonteCarloMoverResult RigidBodyMover::do_propose() { IMP_OBJECT_LOG; RigidBody d(get_model(), pi_); last_transformation_ = d.get_reference_frame().get_transformation_to(); algebra::Vector3D translation; if (max_translation_ > 0) { translation = algebra::get_random_vector_in( algebra::Sphere3D(d.get_coordinates(), max_translation_)); } else { translation = algebra::get_zero_vector_d<3>(); } algebra::Rotation3D rc; if (max_angle_ > 0) { algebra::Vector3D axis = algebra::get_random_vector_on(algebra::get_unit_sphere_d<3>()); ::boost::uniform_real<> rand(-max_angle_, max_angle_); Float angle = rand(random_number_generator); algebra::Rotation3D r = algebra::get_rotation_about_axis(axis, angle); rc = r * d.get_reference_frame().get_transformation_to().get_rotation(); } else { rc = algebra::get_identity_rotation_3d(); } algebra::Transformation3D t(rc, translation); IMP_LOG_VERBOSE("proposed move " << t << std::endl); IMP_USAGE_CHECK( d.get_coordinates_are_optimized(), "Rigid body passed to RigidBodyMover" << " must be set to be optimized. particle: " << d->get_name()); d.set_reference_frame(algebra::ReferenceFrame3D(t)); return MonteCarloMoverResult(ParticleIndexes(1, pi_), 1.0); }
MonteCarloMoverResult MonteCarlo::do_move() { ParticleIndexes ret; double prob = 1.0; for (MoverIterator it = movers_begin(); it != movers_end(); ++it) { IMP_LOG_VERBOSE("Moving using " << (*it)->get_name() << std::endl); IMP_CHECK_OBJECT(*it); { // IMP_LOG_CONTEXT("Mover " << (*it)->get_name()); MonteCarloMoverResult cur = (*it)->propose(); ret += cur.get_moved_particles(); prob *= cur.get_proposal_ratio(); } IMP_LOG_VERBOSE("end\n"); } return MonteCarloMoverResult(ret, prob); }
MonteCarloMoverResult RigidBodyMover::do_propose() { IMP_OBJECT_LOG; RigidBody d(get_model(), pi_); last_transformation_= d.get_reference_frame().get_transformation_to(); algebra::Vector3D translation = algebra::get_random_vector_in(algebra::Sphere3D(d.get_coordinates(), max_translation_)); algebra::Vector3D axis = algebra::get_random_vector_on(algebra::get_unit_sphere_d<3>()); ::boost::uniform_real<> rand(-max_angle_,max_angle_); Float angle =rand(random_number_generator); algebra::Rotation3D r = algebra::get_rotation_about_axis(axis, angle); algebra::Rotation3D rc = r*d.get_reference_frame().get_transformation_to().get_rotation(); algebra::Transformation3D t(rc, translation); IMP_LOG_VERBOSE("proposed move " << t << std::endl); d.set_reference_frame(algebra::ReferenceFrame3D(t)); return MonteCarloMoverResult(ParticleIndexes(1, pi_), 1.0); }
MonteCarloMoverResult NormalMover::do_propose() { IMP_OBJECT_LOG; boost::normal_distribution<double> mrng(0, stddev_); boost::variate_generator<RandomNumberGenerator &, boost::normal_distribution<double> > sampler(random_number_generator, mrng); for (unsigned int i = 0; i < pis_.size(); ++i) { for (unsigned int j = 0; j < keys_.size(); ++j) { originals_[i][j] = get_model()->get_attribute(keys_[j], pis_[i]); } for (unsigned int j = 0; j < keys_.size(); ++j) { IMP_USAGE_CHECK( get_model()->get_is_optimized(keys_[j], pis_[i]), "NormalMover can't move non-optimized attribute. " << "particle: " << get_model()->get_particle_name(pis_[i]) << "attribute: " << keys_[j]); get_model()->set_attribute(keys_[j], pis_[i], originals_[i][j] + sampler()); } } return MonteCarloMoverResult(pis_, 1.0); }