double WeightedExcludedVolumeRestraint::unprotected_evaluate(
    DerivativeAccumulator *accum) const
{
    bool calc_deriv = accum? true: false;
    IMP_LOG_VERBOSE("before resample\n");
    // //generate the transformed maps
    // std::vector<DensityMap*> transformed_maps;
    // for(int rb_i=0;rb_i<rbs_.size();rb_i++){
    //   DensityMap *dm=create_density_map(
    //       atom::get_bounding_box(atom::Hierarchy(rbs_[rb_i])),spacing);
    //   get_transformed_into(
    //       rbs_surface_maps_[rb_i],
    //       rbs_[rb_i].get_transformation()*rbs_orig_trans_[rb_i],
    //       dm,
    //       false);
    //   transformed_maps.push_back(dm);
    // }
    double score=0.;
    // MRCReaderWriter mrw;
    // for(int i=0;i<transformed_maps.size();i++){
    //   std::stringstream ss;
    //   ss<<"transformed_map_"<<i<<".mrc";
    //   std::stringstream s1;
    //   s1<<"transformed_pdb_"<<i<<".pdb";
    //   atom::write_pdb(atom::Hierarchy(rbs_[i]),s1.str().c_str());
    //   write_map(transformed_maps[i],ss.str().c_str(),mrw);
    //   for(int j=i+1;j<transformed_maps.size();j++){
    //     if (get_interiors_intersect(transformed_maps[i],
    //                                 transformed_maps[j])){
    //     score += CoarseCC::cross_correlation_coefficient(
    //                              *transformed_maps[i],
    //                              *transformed_maps[j],1.,false,true);
    //     }
    //   }
    // }
    em::SurfaceShellDensityMaps resampled_surfaces;
    for(unsigned int i=0; i<rbs_.size(); i++) {
        kernel::ParticlesTemp rb_ps=rb_refiner_->get_refined(rbs_[i]);
        resampled_surfaces.push_back(new em::SurfaceShellDensityMap(rb_ps,1.));
    }
    for(unsigned int i=0; i<rbs_.size(); i++) {
        for(unsigned int j=i+1; j<rbs_.size(); j++) {
            if (get_interiors_intersect(resampled_surfaces[i],
                                        resampled_surfaces[j])) {
                score += em::CoarseCC::cross_correlation_coefficient(
                             resampled_surfaces[i],
                             resampled_surfaces[j],1.,true,FloatPair(0.,0.));
            }
        }
    }

    if (calc_deriv) {
        IMP_WARN("WeightedExcludedVolumeRestraint currently"
                 <<" does not support derivatives\n");
    }
    /*for(int i=resampled_surfaces.size()-1;i<0;i--){
      delete(resampled_surfaces[i]);
      }*/
    return score;
}
Ejemplo n.º 2
0
IntPairs QuadraticClosePairsFinder::get_close_pairs(
    const algebra::BoundingBox3Ds &bbs) const {
  set_was_used(true);
  IMP_OBJECT_LOG;
  IMP_LOG_TERSE("Adding close pairs from "
                << bbs.size() << " boxes with threshold " << get_distance()
                << std::endl);
  IntPairs ret;
  const double d2 = get_distance() / 2.0;
  for (unsigned int i = 0; i < bbs.size(); ++i) {
    algebra::BoundingBox3D bi = bbs[i] + d2;
    for (unsigned int j = 0; j < i; ++j) {
      algebra::BoundingBox3D bj = bbs[j] + d2;
      if (get_interiors_intersect(bi, bj)) {
        ret.push_back(IntPair(i, j));
      }
    }
  }
  return ret;
}
IntPairs NearestNeighborsClosePairsFinder::get_close_pairs(
    const algebra::BoundingBox3Ds &bas,
    const algebra::BoundingBox3Ds &bbs) const {
  set_was_used(true);
  IMP_OBJECT_LOG;
  IMP_LOG_TERSE("Quadratic add_close_pairs called with "
                << bas.size() << " and " << bbs.size() << std::endl);
  IntPairs ret;
  const double d2 = get_distance() / 2.0;
  for (unsigned int i = 0; i < bas.size(); ++i) {
    algebra::BoundingBox3D bi = bas[i] + d2;
    for (unsigned int j = 0; j < bbs.size(); ++j) {
      algebra::BoundingBox3D bj = bbs[j] + d2;
      if (get_interiors_intersect(bi, bj)) {
        ret.push_back(IntPair(i, j));
      }
    }
  }
  return ret;
}
Ejemplo n.º 4
0
double CoarseCC::cross_correlation_coefficient(const DensityMap *grid1,
                                               const DensityMap *grid2,
                                               float grid2_voxel_data_threshold,
                                               bool allow_padding,
                                               FloatPair norm_factors) {
  IMP_LOG_VERBOSE("Going to calculate correlation score with values: "
                  << "grid2_voxel_data_threshold:" << grid2_voxel_data_threshold
                  << " allow_padding:" << allow_padding << " norm factors:"
                  << norm_factors.first << "," << norm_factors.second << "\n");
  // run validation checks
  const DensityHeader *grid2_header = grid2->get_header();
  const DensityHeader *grid1_header = grid1->get_header();

  IMP_INTERNAL_CHECK(
      grid2_header->dmax > grid2_voxel_data_threshold,
      "voxel_data_threshold: " << grid2_voxel_data_threshold
                               << " is not within the map range: "
                               << grid2_header->dmin << "-"
                               << grid2_header->dmax << std::endl);

  IMP_INTERNAL_CHECK(grid1_header->is_top_calculated(),
                     "Top should be calculated for grid1\n");

  IMP_INTERNAL_CHECK(grid2_header->is_top_calculated(),
                     "Top should be calculated for grid2\n");

  IMP_INTERNAL_CHECK(grid1->same_voxel_size(grid2),
                     "Both grids should have the same spacing\n");
  if (!allow_padding) {
    // additional validity checks
    IMP_USAGE_CHECK(
        grid1->same_dimensions(grid2),
        "This function cannot handle density maps of different size. "
            << "First map dimensions : " << grid1_header->get_nx() << " x "
            << grid1_header->get_ny() << " x " << grid1_header->get_nz() << "; "
            << "Second map dimensions: " << grid2_header->get_nx() << " x "
            << grid2_header->get_ny() << " x " << grid2_header->get_nz());
    IMP_USAGE_CHECK(
        grid1->same_voxel_size(grid2),
        "This function cannot handle density maps of different pixelsize. "
            << "First grid pixelsize : " << grid1_header->get_spacing() << "; "
            << "Second grid pixelsize: " << grid2_header->get_spacing());
    return cross_correlation_coefficient_internal(
        grid1, grid2, grid2_voxel_data_threshold, norm_factors);
  } else {
    IMP_LOG_VERBOSE("calculated correlation between padded maps\n");
    // create a padded version of the grids
    // copy maps to contain the same extent
    if (!get_interiors_intersect(get_bounding_box(grid1),
                                 get_bounding_box(grid2))) {
      return 0.;
    }
    algebra::BoundingBox3D merged_bb =
        get_bounding_box(grid1) + get_bounding_box(grid2);
    PointerMember<DensityMap> padded_grid1 =
        create_density_map(merged_bb, grid1_header->get_spacing());
    padded_grid1->add(grid1);
    padded_grid1->get_header_writable()->set_resolution(
        grid1->get_header()->get_resolution());
    PointerMember<DensityMap> padded_grid2 =
        create_density_map(merged_bb, grid2_header->get_spacing());
    padded_grid2->add(grid2);
    padded_grid2->get_header_writable()->set_resolution(
        grid2->get_header()->get_resolution());
    padded_grid1->calcRMS();
    padded_grid2->calcRMS();
    IMP_LOG_VERBOSE("calculate correlation internal " << std::endl);
    double score = cross_correlation_coefficient_internal(
        padded_grid1, padded_grid2, grid2_voxel_data_threshold, norm_factors);
    // release the padded versions of the grids
    return score;
  }
}