double get_diffusion_coefficient(const algebra::Vector3Ds &displacements, double dt) { algebra::Vector3D Ds; for (unsigned int i=0; i< 3; ++i) { Ds[i]= get_diffusion_coefficient(displacements.begin(), displacements.end(), i, dt); } IMP_LOG_TERSE( "Diffusion coefficients are " << Ds << std::endl); int len=displacements.size()/2; algebra::Vector3D Ds0; for (unsigned int i=0; i< 3; ++i) { Ds0[i]= get_diffusion_coefficient(displacements.begin(), displacements.begin()+len, i, dt); } algebra::Vector3D Ds1; for (unsigned int i=0; i< 3; ++i) { Ds1[i]= get_diffusion_coefficient(displacements.begin()+len, displacements.end(), i, dt); } IMP_LOG_TERSE( "Partial coefficients are " << Ds0 << " and " << Ds1 << std::endl); return std::accumulate(Ds1.coordinates_begin(), Ds1.coordinates_end(), 0.0)/3.0; }
IMPMULTIFIT_BEGIN_NAMESPACE ProbabilisticAnchorGraph::ProbabilisticAnchorGraph( algebra::Vector3Ds anchor_positions) :Object("ProbabilisticAnchorGraph%1%") { GVertex u; for(unsigned int i=0; i<anchor_positions.size(); i++) { u = boost::add_vertex(g_); id2node_.push_back(u); } positions_.insert(positions_.end(),anchor_positions.begin(), anchor_positions.end()); }
algebra::Vector3Ds get_normals(const Ints &faces, const algebra::Vector3Ds &vertices) { IMP_INTERNAL_CHECK(faces.size() % 3 == 0, "Not triangles"); IMP_INTERNAL_CHECK(faces.size() > 0, "No faces"); Ints count(vertices.size()); algebra::Vector3Ds sum(vertices.size(), algebra::get_zero_vector_d<3>()); for (unsigned int i = 0; i < faces.size() / 3; ++i) { algebra::Vector3D n = get_normal(faces.begin() + 3 * i, faces.begin() + 3 * i + 3, vertices); IMP_INTERNAL_CHECK(!IMP::isnan(n[0]), "Nan found"); for (unsigned int j = 0; j < 3; ++j) { int v = faces[3 * i + j]; sum[v] += n; count[v] += 1; } } for (unsigned int i = 0; i < count.size(); ++i) { sum[i] /= count[i]; IMP_INTERNAL_CHECK(!IMP::isnan(sum[i][0]), "Nan found at end:" << count[i] << " on " << i); } return sum; }
algebra::Vector2Ds do_project_vectors(const algebra::Vector3Ds &ps, const algebra::Rotation3D &R, const algebra::Vector3D &translation, const algebra::Vector3D ¢er) { // Project unsigned long n_particles = ps.size(); algebra::Vector3D p; algebra::Vector2Ds vs(n_particles); for (unsigned long i = 0; i < n_particles; i++) { // Coordinates respect to the center p[0] = ps[i][0] - center[0]; p[1] = ps[i][1] - center[1]; p[2] = ps[i][2] - center[2]; // Point after transformation to project in Z axis // Not necessary to compute pz, is going to be ignored double px = R.get_rotated_one_coordinate(p, 0) + translation[0]; double py = R.get_rotated_one_coordinate(p, 1) + translation[1]; // Project is simply ignore Z-coordinate vs[i] = algebra::Vector2D(px, py); } return vs; }
algebra::Vector3Ds CoarseCC::calc_derivatives(const DensityMap *em_map, const DensityMap *model_map, const Particles &model_ps, const FloatKey &w_key, KernelParameters *kernel_params, const float &scalefac, const algebra::Vector3Ds &dv) { algebra::Vector3Ds dv_out; dv_out.insert(dv_out.end(), dv.size(), algebra::Vector3D(0., 0., 0.)); double tdvx = 0., tdvy = 0., tdvz = 0., tmp, rsq; int iminx, iminy, iminz, imaxx, imaxy, imaxz; const DensityHeader *model_header = model_map->get_header(); const DensityHeader *em_header = em_map->get_header(); const float *x_loc = em_map->get_x_loc(); const float *y_loc = em_map->get_y_loc(); const float *z_loc = em_map->get_z_loc(); IMP_INTERNAL_CHECK(model_ps.size() == dv.size(), "input derivatives array size does not match " << "the number of particles in the model map\n"); core::XYZRs model_xyzr = core::XYZRs(model_ps); // this would go away once we have XYZRW decorator const emreal *em_data = em_map->get_data(); float lim = kernel_params->get_lim(); long ivox; // validate that the model and em maps are not empty IMP_USAGE_CHECK(em_header->rms >= EPS, "EM map is empty ! em_header->rms = " << em_header->rms); // it may be that CG takes a too large step, which causes the particles // to go outside of the density // if (model_header->rms <= EPS){ // IMP_WARN("Model map is empty ! model_header->rms = " << model_header->rms // <<" derivatives are not calculated. the model centroid is : " << // core::get_centroid(core::XYZs(model_ps))<< // " the map centroid is " << em_map->get_centroid()<< // "number of particles in model:"<<model_ps.size() //<<std::endl); // return; // } // Compute the derivatives int nx = em_header->get_nx(); int ny = em_header->get_ny(); // int nz=em_header->get_nz(); IMP_INTERNAL_CHECK(em_map->get_rms_calculated(), "RMS should be calculated for calculating derivatives \n"); long nvox = em_header->get_number_of_voxels(); double lower_comp = 1. * nvox * em_header->rms * model_header->rms; for (unsigned int ii = 0; ii < model_ps.size(); ii++) { float x, y, z; x = model_xyzr[ii].get_x(); y = model_xyzr[ii].get_y(); z = model_xyzr[ii].get_z(); IMP_IF_LOG(VERBOSE) { algebra::Vector3D vv(x, y, z); IMP_LOG_VERBOSE( "start value:: (" << x << "," << y << "," << z << " ) " << em_map->get_value(x, y, z) << " : " << em_map->get_dim_index_by_location(vv, 0) << "," << em_map->get_dim_index_by_location(vv, 1) << "," << em_map->get_dim_index_by_location(vv, 2) << std::endl); } const RadiusDependentKernelParameters ¶ms = kernel_params->get_params(model_xyzr[ii].get_radius()); calc_local_bounding_box( // em_map, model_map, x, y, z, params.get_kdist(), iminx, iminy, iminz, imaxx, imaxy, imaxz); IMP_LOG_WRITE(VERBOSE, params.show()); IMP_LOG_VERBOSE("local bb: [" << iminx << "," << iminy << "," << iminz << "] [" << imaxx << "," << imaxy << "," << imaxz << "] \n"); tdvx = .0; tdvy = .0; tdvz = .0; for (int ivoxz = iminz; ivoxz <= imaxz; ivoxz++) { for (int ivoxy = iminy; ivoxy <= imaxy; ivoxy++) { ivox = ivoxz * nx * ny + ivoxy * nx + iminx; for (int ivoxx = iminx; ivoxx <= imaxx; ivoxx++) { /* if (em_data[ivox]<EPS) { ivox++; continue; }*/ float dx = x_loc[ivox] - x; float dy = y_loc[ivox] - y; float dz = z_loc[ivox] - z; rsq = dx * dx + dy * dy + dz * dz; rsq = EXP(-rsq * params.get_inv_sigsq()); tmp = (x - x_loc[ivox]) * rsq; if (std::abs(tmp) > lim) { tdvx += tmp * em_data[ivox]; } tmp = (y - y_loc[ivox]) * rsq; if (std::abs(tmp) > lim) { tdvy += tmp * em_data[ivox]; } tmp = (z - z_loc[ivox]) * rsq; if (std::abs(tmp) > lim) { tdvz += tmp * em_data[ivox]; } ivox++; } } } tmp = model_ps[ii]->get_value(w_key) * 2. * params.get_inv_sigsq() * scalefac * params.get_normfac() / lower_comp; IMP_LOG_VERBOSE("for particle:" << ii << " (" << tdvx << "," << tdvy << "," << tdvz << ")" << std::endl); dv_out[ii][0] = tdvx * tmp; dv_out[ii][1] = tdvy * tmp; dv_out[ii][2] = tdvz * tmp; } // particles return dv_out; }