ParticlePairsTemp MSConnectivityRestraint::get_connected_pairs() const { IMP_CHECK_OBJECT(ps_.get()); tree_.finalize(); MSConnectivityScore mcs(tree_, ps_.get(), eps_, *const_cast<MSConnectivityRestraint *>(this)); EdgeSet edges = mcs.get_connected_pairs(); ParticlePairsTemp ret(edges.size()); unsigned index = 0; for (EdgeSet::iterator p = edges.begin(); p != edges.end(); ++p) { ret[index++] = ParticlePair(mcs.get_particle(p->first), mcs.get_particle(p->second)); } return ret; }
inline bool CollisionBox<ScalarT, dimN>::addParticle( const typename CollisionBox<ScalarT, dimN>::Point& newPosition, const typename CollisionBox<ScalarT, dimN>::Vector& newVelocity) { /* Find the cell containing the new particle: */ Point newP=newPosition; Index cellIndex; for (int i=0;i<dimension;++i) { if (newP[i]<boundaries.min[i]+particleRadius) newP[i]=boundaries.min[i]+particleRadius; else if (newP[i]>boundaries.max[i]-particleRadius) newP[i]=boundaries.max[i]-particleRadius; cellIndex[i]=int(Math::floor((newP[i]-boundaries.min[i])/cellSize[i]))+1; } GridCell* cell=cells.getAddress(cellIndex); /* Check if there is room to add the new particle: */ for (int i=0;i<numNeighbors;++i) { GridCell* neighborCell=cell+neighborOffsets[i]; for (Particle* pPtr=neighborCell->particlesHead;pPtr!=0;pPtr=pPtr->cellSucc) { Scalar dist2=Geometry::sqrDist(pPtr->position,newP); if (dist2<=Scalar(2)*particleRadius2) return false; // Could not add the particle } } /* Add a new particle to the particle list: */ particles.push_back(Particle()); Particle& p=particles.back(); /* Initialize the new particle: */ p.position=newPosition; p.velocity=newVelocity; p.timeStamp=Scalar(0); cell->addParticle(&p); for (typename ParticleList::iterator i = particles.begin(); i != particles.end() && &(*i) != &p; ++i) { if (&(*i) != &p) { particlePairs.push_back(ParticlePair(&p, &(*i))); } } return true; // Particle succesfully added }
ParticlePairsTemp get_possible_interactions(const ParticlesTemp &ps, double max_distance, ParticleStatesTable *pst) { if (ps.empty()) return ParticlePairsTemp(); ParticleStatesList psl; ParticlesTemp all= pst->get_particles(); unsigned int max=0; for (unsigned int i=0; i< all.size(); ++i) { psl.push_back( pst->get_particle_states(all[i])); max= std::max(psl[i]->get_number_of_particle_states(), max); } algebra::BoundingBox3Ds bbs(ps.size()); for (unsigned int i=0; i< max; ++i) { for (unsigned int j=0; j< all.size(); ++j) { psl[j]->load_particle_state(std::min(i, psl[j]->get_number_of_particle_states()-1), all[j]); } ps[0]->get_model()->update(); for (unsigned int j=0; j< ps.size(); ++j) { core::XYZ d(ps[j]); bbs[j]+= d.get_coordinates(); } } for (unsigned int j=0; j< ps.size(); ++j) { core::XYZR d(ps[j]); bbs[j]+= d.get_radius() + max_distance; } IMP_NEW(core::GridClosePairsFinder, gcpf, ()); gcpf->set_distance(max_distance); IntPairs ips= gcpf->get_close_pairs(bbs); ParticlePairsTemp ret(ips.size()); for (unsigned int i=0; i< ips.size(); ++i) { ret[i]= ParticlePair(ps[ips[i].first], ps[ips[i].second]); } return ret; }
void add(Particle *p1, Particle *p2) { this->push_back(ParticlePair(p1, p2)); }