SimpleExcludedVolume create_simple_excluded_volume_on_molecules( atom::Hierarchies const &mhs) { IMP_CHECK_CODE(size_t mhs_size = mhs.size()); IMP_USAGE_CHECK(mhs_size > 0, "At least one hierarchy should be given"); kernel::ParticlesTemp ps; for ( size_t i=0; i<mhs.size(); ++i ) { kernel::ParticlesTemp leaves= IMP::atom::get_leaves(mhs[i]); ps.insert(ps.end(), leaves.begin(), leaves.end()); } /****** Set the restraint ******/ IMP_NEW(container::ListSingletonContainer, lsc, (ps)); IMP_NEW(core::ExcludedVolumeRestraint, evr, (lsc)); /****** Add restraint to the model ******/ //Model *mdl = mhs[0].get_particle()->get_model(); //mdl->add_restraint(evr); /****** Return a SimpleExcludedVolume object ******/ return SimpleExcludedVolume(evr); }
void KMLProxy::run(Particles *initial_centers) { IMP_INTERNAL_CHECK(is_init_,"The proxy was not initialized"); IMP_LOG(VERBOSE,"KMLProxy::run start \n"); //use the initial centers if provided KMPointArray *kmc=nullptr; if (initial_centers != nullptr) { IMP_INTERNAL_CHECK(kcenters_ == initial_centers->size(), "the number of initial points differs from the number of required" <<" centers\n"); IMP_LOG(VERBOSE,"KMLProxy::run initial centers provided : \n"); kmc = allocate_points(kcenters_,atts_.size()); for (unsigned int i=0;i<kcenters_;i++){ Particle *cen=(*initial_centers)[i]; for(unsigned int j=0;j<atts_.size();j++) { (*(*kmc)[i])[j]=cen->get_value(atts_[j]); } } } IMP_LOG(VERBOSE,"KMLProxy::run load initial guess \n"); //load the initail guess KMFilterCenters ctrs(kcenters_, data_, kmc,damp_factor_); //apply lloyd search IMP_LOG(VERBOSE,"KMLProxy::run load lloyd \n"); lloyd_alg_ = new KMLocalSearchLloyd(&ctrs,&term_); log_header(); IMP_CHECK_CODE(clock_t start = clock()); IMP_LOG(VERBOSE,"KMLProxy::run excute lloyd \n"); lloyd_alg_->execute(); IMP_LOG(VERBOSE,"KMLProxy::run analyse \n"); KMFilterCentersResults best_clusters = lloyd_alg_->get_best(); IMP_CHECK_CODE(Float exec_time = elapsed_time(start)); // print summary IMP_LOG_WRITE(TERSE,log_summary(&best_clusters,exec_time)); IMP_LOG_WRITE(TERSE,best_clusters.show(IMP_STREAM)); IMP_INTERNAL_CHECK(kcenters_ == (unsigned int) best_clusters.get_number_of_centers(), "The final number of centers does not match the requested one"); IMP_INTERNAL_CHECK (dim_ == (unsigned int) best_clusters.get_dim(), "The dimension of the final clusters is wrong"); //TODO clear the centroids list //set the centroids: Particle *p; IMP_LOG(VERBOSE,"KMLProxy::run load best results \n"); for (unsigned int ctr_ind = 0; ctr_ind < kcenters_; ctr_ind++) { KMPoint *kmp = best_clusters[ctr_ind]; //create a new particle p = new Particle(m_); centroids_.push_back(p); for (unsigned int att_ind = 0; att_ind < dim_; att_ind++) { p->add_attribute(atts_[att_ind],(*kmp)[att_ind],false); } } //set the assignment of particles to centers //array of number of all points //TODO - return this IMP_LOG(VERBOSE,"KMLProxy::run get assignments \n"); const Ints *close_center = best_clusters.get_assignments(); IMP_LOG(VERBOSE,"KMLProxy::run get assignments 2\n"); for (int i=0;i<data_->get_number_of_points();i++) { //std::cout<<"ps number i: " << i << " close center : " //<< (*close_center)[i] << std::endl; assignment_[ps_[i]]=(*close_center)[i]; } }