double Fine2DRegistrationRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const {
  IMP_UNUSED(accum);
  calls_++;
  IMP_USAGE_CHECK(accum == nullptr,
                  "Fine2DRegistrationRestraint: This restraint does not "
                  "provide derivatives ");

  // projection_ needs to be mutable, son this const function can change it.
  // project_particles changes the matrix of projection_
  ProjectingOptions options(params_.pixel_size, params_.resolution);
  double score = 0;
  try {
    do_project_particles(ps_, projection_->get_data(), PP_.get_rotation(),
                         PP_.get_translation(), options, masks_);
    score = score_function_->get_score(subject_, projection_);
  }
  catch (cv::Exception &e) {
    IMP_LOG(WARNING,
            "Fine2DRegistration. Error computing the score: "
            "Returning 1 (maximum score). Most probably because projecting "
            "out of the image size."
                << e.what() << std::endl);
    score = 1.0;
  }
  IMP_LOG_VERBOSE("Fine2DRegistration. Score: " << score << std::endl);
  return score;
}
Ejemplo n.º 2
0
void get_projection(em2d::Image *img, const ParticlesTemp &ps,
                    const RegistrationResult &reg,
                    const ProjectingOptions &options, MasksManagerPtr masks,
                    String name) {
  IMP_LOG_VERBOSE("Generating projection in a em2d::Image" << std::endl);

  if (masks == MasksManagerPtr()) {
    masks = MasksManagerPtr(
        new MasksManager(options.resolution, options.pixel_size));
    masks->create_masks(ps);
    IMP_LOG_VERBOSE("Masks generated from get_projection()" << std::endl);
  }
  algebra::Vector3D translation = options.pixel_size * reg.get_shift_3d();
  algebra::Rotation3D R = reg.get_rotation();

  do_project_particles(ps, img->get_data(), R, translation, options, masks);
  if (options.normalize) em2d::do_normalize(img, true);
  reg.set_in_image(img->get_header());
  img->get_header().set_object_pixel_size(options.pixel_size);
  if (options.save_images) {
    if (name.empty()) {
      IMP_THROW("get_projection: File name string is empty ", IOException);
    }
    if (options.srw == Pointer<ImageReaderWriter>()) {
      IMP_THROW(
          "The options class does not have an "
          "ImageReaderWriter assigned. Create an ImageReaderWriter "
          "and assigned to the srw member of ProjectingOptions.",
          IOException);
    }
    img->write(name, options.srw);
  }
}
Ejemplo n.º 3
0
void CollisionCrossSection::set_model_particles(
    const ParticlesTemp &ps) {

  IMP_LOG_TERSE("CollisionCrossSection: Model particles set"
                << std::endl);

  for (unsigned int i = 0; i < ps.size(); ++i) {
    IMP_USAGE_CHECK(
        (core::XYZR::get_is_setup(ps[i]) && atom::Mass::get_is_setup(ps[i])),
        "Particle " << i << " does not have the required attributes"
                    << std::endl);
  }
  masks_manager_->create_masks(ps);
  // Compute projections
  collision_cross_section_ = 0.0;
  for (unsigned int i = 0; i < n_projections_; ++i) {
    ProjectingOptions options(pixel_size_, resolution_);
    do_project_particles(ps, average_projection_, regs_[i].get_rotation(),
                         pixel_size_ * regs_[i].get_shift_3d(), options,
                         masks_manager_);
    collision_cross_section_ += get_projected_area(average_projection_);
  }
  collision_cross_section_ /= static_cast<double>(n_projections_);
  particles_set_ = true;
}