IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
utilities.h
Go to the documentation of this file.
1 /**
2  * \file IMP/pmi/utilities.h
3  * \brief Useful utilities
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPPMI_UTILITIES_H
9 #define IMPPMI_UTILITIES_H
10 
11 #include <IMP/pmi/pmi_config.h>
14 #include <IMP/core/XYZR.h>
15 #include <IMP/base/Vector.h>
16 
17 IMPPMI_BEGIN_NAMESPACE
18 
19 //! Create an elastic network restraint set
21  Float dist_cutoff,
22  Float strength){
23  IMP_NEW(RestraintSet,rs,(ps[0]->get_model(),"ElasticNetwork"));
24  int nps=ps.size();
25  for (int n1=0;n1<nps;n1++){
26  for (int n2=n1+1;n2<nps;n2++){
27  Float dist = core::get_distance(core::XYZ(ps[n1]),
28  core::XYZ(ps[n2]));
29  if (dist<dist_cutoff){
31  (dist,strength));
33  ParticlePair(ps[n1],ps[n2]));
34  rs->add_restraint(rx);
35  }
36  }
37  }
38  return rs.release();
39 }
40 
41 inline Float get_bipartite_minimum_sphere_distance(const IMP::core::XYZRs& m1,
42  const IMP::core::XYZRs& m2) {
43 
44  double mindist = -1.0 ;
45 
46  for (unsigned int k1 = 0; k1 < m1.size(); ++k1) {
47  for (unsigned int k2 = 0; k2 < m2.size(); ++k2) {
48  double dist = IMP::core::get_distance(m1[k1],m2[k2]);
49  if (mindist < 0.0){mindist=dist;}
50  if (mindist > dist){mindist=dist;}
51  }
52  }
53  if (mindist < 0 ){mindist = 0;}
54  return mindist;
55 }
56 
57 
58 inline Floats get_list_of_bipartite_minimum_sphere_distance(const ParticlesTemps & pss) {
59  Floats mindistances;
60  for (unsigned int k1 = 0; k1 < pss.size()-1; ++k1) {
61  for (unsigned int k2 = k1+1; k2 < pss.size(); ++k2) {
62  IMP::core::XYZRs xyzrs1=IMP::core::XYZRs(pss[k1]);
63  IMP::core::XYZRs xyzrs2=IMP::core::XYZRs(pss[k2]);
64  double dist = IMP::pmi::get_bipartite_minimum_sphere_distance(xyzrs1,xyzrs2);
65  mindistances.push_back(dist);
66  }
67  }
68  return mindistances;
69 }
70 
71 IMPPMI_END_NAMESPACE
72 
73 #endif /* IMPPMI_UTILITIES_H */
Restraint * create_restraint(Score *s, const typename Score::Argument &t, std::string name=std::string())
Definition: generic.h:36
Distance restraint between two particles.
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: types.h:47
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Object used to hold a set of restraints.
Definition: RestraintSet.h:36
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Definition: object_macros.h:62
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:63
RestraintSet * create_elastic_network(const Particles &ps, Float dist_cutoff, Float strength)
Create an elastic network restraint set.
Definition: utilities.h:20
double get_distance(XYZ a, XYZ b)
Compute the distance between a pair of particles.
Definition: XYZ.h:190
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
A Score on the distance between a pair of particles.
Array< 2, WeakPointer< Particle >, Particle * > ParticlePair
Definition: base_types.h:135
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Decorator for a sphere-like particle.