IMP logo
IMP Reference Guide  2.6.1
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-2016 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/atom/Molecule.h>
16 #include <IMP/atom/Copy.h>
17 #include <IMP/Vector.h>
18 #include <boost/lexical_cast.hpp>
19 
20 IMPPMI_BEGIN_NAMESPACE
21 
22 //! Create an elastic network restraint set
24  Float dist_cutoff,
25  Float strength){
26  IMP_NEW(RestraintSet,rs,(ps[0]->get_model(),"ElasticNetwork"));
27  int nps=ps.size();
28  for (int n1=0;n1<nps;n1++){
29  for (int n2=n1+1;n2<nps;n2++){
30  Float dist = core::get_distance(core::XYZ(ps[n1]),
31  core::XYZ(ps[n2]));
32  if (dist<dist_cutoff){
34  (dist,strength));
36  ParticlePair(ps[n1],ps[n2]));
37  rs->add_restraint(rx);
38  }
39  }
40  }
41  return rs.release();
42 }
43 
44 inline Float get_bipartite_minimum_sphere_distance(const IMP::core::XYZRs& m1,
45  const IMP::core::XYZRs& m2) {
46 
47  double mindist = -1.0 ;
48 
49  for (unsigned int k1 = 0; k1 < m1.size(); ++k1) {
50  for (unsigned int k2 = 0; k2 < m2.size(); ++k2) {
51  double dist = IMP::core::get_distance(m1[k1],m2[k2]);
52  if (mindist < 0.0){mindist=dist;}
53  if (mindist > dist){mindist=dist;}
54  }
55  }
56  if (mindist < 0 ){mindist = 0;}
57  return mindist;
58 }
59 
60 
61 inline Floats get_list_of_bipartite_minimum_sphere_distance(const ParticlesTemps & pss) {
62  Floats mindistances;
63  for (unsigned int k1 = 0; k1 < pss.size()-1; ++k1) {
64  for (unsigned int k2 = k1+1; k2 < pss.size(); ++k2) {
65  IMP::core::XYZRs xyzrs1=IMP::core::XYZRs(pss[k1]);
66  IMP::core::XYZRs xyzrs2=IMP::core::XYZRs(pss[k2]);
67  double dist = IMP::pmi::get_bipartite_minimum_sphere_distance(xyzrs1,xyzrs2);
68  mindistances.push_back(dist);
69  }
70  }
71  return mindistances;
72 }
73 
74 //! Get the parent, or if non-tree Representation get the fake parent
76  if (h.get_model()->get_has_attribute(
77  atom::Hierarchy::get_traits().get_parent_key(),h.get_particle_index())){
79  atom::Hierarchy::get_traits().get_parent_key(),h.get_particle_index());
80  return atom::Hierarchy(h.get_model(),pidx);
81  }
82  else return atom::Hierarchy();
83 }
84 
85 
86 //! Walk up a PMI2 hierarchy/representations and get the "molname.copynum"
88  do {
89  if (atom::Molecule::get_is_setup(h) && atom::Copy::get_is_setup(h)) {
90  return h->get_name() + "."
91  + boost::lexical_cast<std::string>(atom::Copy(h).get_copy_index());
92  }
93  } while ((h = get_parent_representation(h)));
94  IMP_THROW("Hierarchy " << h << " has no molecule name or copy num.", ValueException);
95 }
96 
97 //! Walk up a PMI2 hierarchy/representations and check if the root is named System
99  do {
100  if (h->get_name()=="System") {
101  return true;
102  }
103  } while ((h = get_parent_representation(h)));
104  return false;
105 }
106 
107 IMPPMI_END_NAMESPACE
108 
109 #endif /* IMPPMI_UTILITIES_H */
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
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
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:191
A decorator for Molecules.
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
A decorator for keeping track of copies of a molecule.
Definition: Copy.h:28
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:63
std::string get_molecule_name_and_copy(atom::Hierarchy h)
Walk up a PMI2 hierarchy/representations and get the "molname.copynum".
Definition: utilities.h:87
The standard decorator for manipulating molecular structures.
RestraintSet * create_elastic_network(const Particles &ps, Float dist_cutoff, Float strength)
Create an elastic network restraint set.
Definition: utilities.h:23
double get_distance(XYZ a, XYZ b)
Compute the distance between a pair of particles.
Definition: XYZ.h:189
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
A class for storing lists of IMP items.
A Score on the distance between a pair of particles.
bool get_is_canonical(atom::Hierarchy h)
Walk up a PMI2 hierarchy/representations and check if the root is named System.
Definition: utilities.h:98
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
atom::Hierarchy get_parent_representation(atom::Hierarchy h)
Get the parent, or if non-tree Representation get the fake parent.
Definition: utilities.h:75
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
A decorator for keeping track of copies of a molecule.
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
An exception for an invalid value being passed to IMP.
Definition: exception.h:137
Decorator for a sphere-like particle.