Ejemplo n.º 1
0
IMPEM2D_BEGIN_INTERNAL_NAMESPACE

ProjectionSphere::ProjectionSphere(unsigned int n, double r) :
  grid_(0.1, // voxel size
        IMP::algebra::BoundingBox3D(IMP::algebra::Vector3D(-1.01, -1.01, -1.01),
                                    IMP::algebra::Vector3D(1.01, 1.01, 1.01))) {

  IMP::algebra::SphericalVector3Ds spherical_coords;
  quasi_evenly_spherical_distribution(n, spherical_coords, r);

  // convert sphere coordinate to rotation and axis
  for (unsigned int i = 0; i < spherical_coords.size(); i++) {
    IMP::algebra::SphericalVector3D v = spherical_coords[i];
    double cy = cos(v[1] / 2.0);
    double cz = cos(v[2] / 2.0);
    double sy = sin(v[1] / 2.0);
    double sz = sin(v[2] / 2.0);
    // this is a rotation about z axis by an angle v[2]
    // followed by rotation about y axis by an angle v[1]
    IMP::algebra::Rotation3D r(cy * cz, sy * sz, sy * cz, cy * sz);
    rotations_.push_back(r);
    axes_.push_back(v.get_cartesian_coordinates());
  }

  // fill grid
  for (unsigned int i = 0; i < axes_.size(); i++) {
    Grid::Index grid_index = grid_.get_nearest_index(axes_[i]);
    grid_[grid_index].push_back(i);
  }
}
Ejemplo n.º 2
0
void compute_projections(const Particles& all_particles,
                         const Particles& lig_particles,
                         unsigned int projection_number,
                         double pixel_size, double resolution,
                         boost::ptr_vector<Projection>& projections,
                         int image_size) {

  // get coordinates, radius and mass
  IMP::algebra::Vector3Ds all_points(all_particles.size());
  std::vector<double> all_radii(all_particles.size());
  for (unsigned int i = 0; i < all_particles.size(); i++) {
    all_points[i] = core::XYZ(all_particles[i]).get_coordinates();
    all_radii[i] = core::XYZR(all_particles[i]).get_radius();
  }

  IMP::algebra::Vector3Ds lig_points(lig_particles.size());
  std::vector<double> lig_radii(lig_particles.size());
  std::vector<double> lig_mass(lig_particles.size());
  for (unsigned int i = 0; i < lig_particles.size(); i++) {
    lig_points[i] = core::XYZ(lig_particles[i]).get_coordinates();
    lig_radii[i] = core::XYZR(lig_particles[i]).get_radius();
    lig_mass[i] = atom::Mass(lig_particles[i]).get_mass();
  }

  int axis_size = image_size;
  // use image_size if given
  if (!(image_size > 0)) {
    double max_dist = compute_max_distance(all_points);
    static IMP::em::KernelParameters kp(resolution);
    double radius = 3.0;
    const IMP::em::RadiusDependentKernelParameters& params =
        kp.get_params(radius);
    double wrap_length = 2 * params.get_kdist() + 1.0;
    axis_size =
        (int)((max_dist + 2 * wrap_length + 2 * pixel_size) / pixel_size + 2);
    if (axis_size <= image_size) axis_size = image_size;
  }

  // storage for rotated points
  IMP::algebra::Vector3Ds rotated_points(all_points.size());
  IMP::algebra::Vector3Ds rotated_ligand_points(lig_points.size());
  // points on a sphere
  IMP::algebra::SphericalVector3Ds spherical_coords;
  quasi_evenly_spherical_distribution(projection_number, spherical_coords, 1.0);

  for (unsigned int i = 0; i < spherical_coords.size(); i++) {
    // convert sphere coordinate to rotation
    IMP::algebra::SphericalVector3D v = spherical_coords[i];
    double cy = cos(v[1] / 2.0);
    double cz = cos(v[2] / 2.0);
    double sy = sin(v[1] / 2.0);
    double sz = sin(v[2] / 2.0);
    // this is a rotation about z axis by an angle v[2]
    // followed by rotation about y axis by an angle v[1]
    IMP::algebra::Rotation3D r(cy * cz, sy * sz, sy * cz, cy * sz);

    // rotate points
    for (unsigned int p_index = 0; p_index < all_points.size(); p_index++)
      rotated_points[p_index] = r * all_points[p_index];
    for (unsigned int p_index = 0; p_index < lig_points.size(); p_index++)
      rotated_ligand_points[p_index] = r * lig_points[p_index];

    // project
    std::auto_ptr<Projection> p(
        new Projection(rotated_points, rotated_ligand_points, lig_radii,
                       lig_mass, pixel_size, resolution, axis_size));
    p->set_rotation(r);
    p->set_axis(IMP::algebra::Vector3D(v.get_cartesian_coordinates()));
    p->set_id(i);
    // rasmol
    // std::cout << "#projection " << i+1 <<"\nreset\nrotate Z "
    //<< IMP_RAD_2_DEG(v[2]);
    // std::cout << "\nrotate Y -" << IMP_RAD_2_DEG(v[1]) << std::endl;
    // chimera
    // std::cout << "#projection " << i+1
    //<<"\nreset;turn x 180; turn z -" << IMP_RAD_2_DEG(v[2]);
    // std::cout << ";turn y -" << IMP_RAD_2_DEG(v[1])
    //<< ";wait;sleep 3;"<< std::endl;
    // string file_name = "projection_" +
    //   string(boost::lexical_cast<string>(i+1)) + ".pgm";
    // p.write_PGM(file_name);
    projections.push_back(p.release());
  }
}
Ejemplo n.º 3
0
void compute_projections(const Particles& particles,
                         unsigned int projection_number, double pixel_size,
                         double resolution,
                         boost::ptr_vector<Projection>& projections,
                         int image_size) {

  // get coordinates, radius and mass
  IMP::algebra::Vector3Ds points(particles.size());
  std::vector<double> mass(particles.size());
  for (unsigned int i = 0; i < particles.size(); i++) {
    points[i] = core::XYZ(particles[i]).get_coordinates();
    mass[i] = atom::Mass(particles[i]).get_mass();
  }

  // estimate max image size
  double max_dist = compute_max_distance(points);
  static IMP::em::KernelParameters kp(resolution);
  double wrap_length = 2 * kp.get_rkdist() + 1.0;
  int axis_size =
      (int)((max_dist + 2 * wrap_length + 2 * pixel_size) / pixel_size + 2);
  if (axis_size <= image_size) axis_size = image_size;

  // storage for rotated points
  IMP::algebra::Vector3Ds rotated_points(points.size());
  // points on sphere
  IMP::algebra::SphericalVector3Ds spherical_coords;
  quasi_evenly_spherical_distribution(projection_number, spherical_coords, 1.0);

  for (unsigned int i = 0; i < spherical_coords.size(); i++) {
    // convert sphere coordinate to rotation
    IMP::algebra::SphericalVector3D v = spherical_coords[i];
    double cy = cos(v[1] / 2.0);
    double cz = cos(v[2] / 2.0);
    double sy = sin(v[1] / 2.0);
    double sz = sin(v[2] / 2.0);
    // this is a rotation about z axis by an angle v[2]
    // followed by rotation about y axis by an angle v[1]
    IMP::algebra::Rotation3D r(cy * cz, sy * sz, sy * cz, cy * sz);

    // rotate points
    for (unsigned int point_index = 0; point_index < points.size();
         point_index++) {
      rotated_points[point_index] = r * points[point_index];
    }
    // project
    IMP_UNIQUE_PTR<Projection> p(new Projection(rotated_points, mass,
                                                pixel_size, resolution,
                                                axis_size));
    p->set_rotation(r);
    p->set_axis(IMP::algebra::Vector3D(v.get_cartesian_coordinates()));
    p->set_id(i);
    // rasmol
    // std::cout << "#projection " << i+1
    //<<"\nreset\nrotate Z " << RAD_2_DEG(v[2]);
    // std::cout << "\nrotate Y -" << IMP_RAD_2_DEG(v[1]) << std::endl;
    // chimera
    // std::cout << "#projection " << i+1
    //<<"\nreset;turn x 180; turn z -" <<  IMP_RAD_2_DEG(v[2]);
    // std::cout << ";turn y -" << IMP_RAD_2_DEG(v[1])
    // << ";wait;sleep 3;"<< std::endl;
    // string file_name = "projection_" +
    //   string(boost::lexical_cast<string>(i+1)) + ".pgm";
    // p.write_PGM(file_name);
    projections.push_back(p.release());
  }
}