/** * \file Fine2DRegistrationRestraint.cpp * \brief Finely refine the angles and translations of a set of subjet images * Copyright 2007-2010 IMP Inventors. All rights reserved. **/ #include "IMP/em2d/Fine2DRegistrationRestraint.h" #include "IMP/em2d/project.h" #include "IMP/em2d/scores2D.h" #include "IMP/container_macros.h" #include "IMP/algebra/SphericalVector3D.h" #include "IMP/log.h" IMPEM2D_BEGIN_NAMESPACE void Fine2DRegistrationRestraint::initialize( ParticlesTemp &ps, double resolution, double pixelsize, Model *scoring_model, OldMasksManager *masks) { IMP_LOG(IMP::TERSE,"Initializing Fine2DRegistrationRestraint" <generate_masks(ps); } else { masks_= masks; } // Set the model this->set_model(scoring_model); // Create a particle for the projection parameters to be optimized subj_params_particle_ = new Particle(scoring_model); PP_ = ProjectionParameters::setup_particle(subj_params_particle_); PP_.decorate_particle(subj_params_particle_); PP_.set_parameters_optimized(true); // add the restraint to the model scoring_model->add_restraint(this); } void Fine2DRegistrationRestraint::set_subject_image(em::Image &subject) { // Set image subject_ = &subject; // Prepare another image to store projections // IMP_NEW(em::Image,projection_,()); projection_ = new em::Image(); int rows = subject_->get_data().get_number_of_rows(); int cols = subject_->get_data().get_number_of_columns(); projection_->resize(rows,cols); PP_.set_rotation(subject_->get_header().get_Phi(), subject_->get_header().get_Theta(), subject_->get_header().get_Psi()); PP_.set_translation2D(subject_->get_header().get_xorigin()*pixelsize_, subject_->get_header().get_yorigin()*pixelsize_); algebra::Vector3D min_values(-pixelsize_*rows,-pixelsize_*cols,0.0); algebra::Vector3D max_values( pixelsize_*rows, pixelsize_*cols,0.0); PP_.set_proper_ranges_for_keys(this->get_model(),min_values,max_values); IMP_LOG(IMP::VERBOSE,"Subject set for Fine2DRegistrationRestraint" <get_data(), R,translation,resolution_,pixelsize_,masks_); double ccc = subject_->get_data().cross_correlation_coefficient( projection_->get_data()); double score = ccc_to_em2d(ccc); IMP_LOG(VERBOSE, "Fine2DRegistration. Score: " << score <