[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-dev] [IMP-commits] r3986 - in trunk/modules/helper: . include pyext src test



I would also recommend making the return types more symmetric by providing a similar wrapper for the FitRestraint (it doesn't have to do anything extra, but that way it looks the same as the others and you store it by value too).


On Oct 28, 2009, at 1:25 PM, Notification of IMP commits wrote:

Author: 
Date: 2009-10-28 13:25:46 -0700 (Wed, 28 Oct 2009)
New Revision: 3986

Added:
  trunk/modules/helper/include/simplify_restraint.h
  trunk/modules/helper/src/simplify_restraint.cpp
  trunk/modules/helper/test/test_simple_connectivity_on_molecules.py
Modified:
  trunk/modules/helper/SConscript
  trunk/modules/helper/pyext/swig.i-in
Log:
Add helper functions for restraints

Modified: trunk/modules/helper/SConscript
===================================================================
--- trunk/modules/helper/SConscript	2009-10-28 18:25:03 UTC (rev 3985)
+++ trunk/modules/helper/SConscript	2009-10-28 20:25:46 UTC (rev 3986)
@@ -2,5 +2,5 @@


env.IMPModuleBuild(version="SVN",
- required_modules=['em', 'display','atom', 'core', 'algebra'], + required_modules=['em', 'display','atom', 'core', 'algebra', 'misc'],
                   optional_dependencies=['CGAL'])

Added: trunk/modules/helper/include/simplify_restraint.h
===================================================================
--- trunk/modules/helper/include/ simplify_restraint.h (rev 0) +++ trunk/modules/helper/include/simplify_restraint.h 2009-10-28 20:25:46 UTC (rev 3986)
@@ -0,0 +1,450 @@
+/**
+ *  \file helper/simplify_restraint.h
+ *  \brief Helper functions for restraints
+ *
+ *  Copyright 2007-9 Sali Lab. All rights reserved.
+ */
+
+#ifndef IMPHELPER_SIMPLIFY_RESTRAINT_H
+#define IMPHELPER_SIMPLIFY_RESTRAINT_H
+
+#include "config.h"
+#include <IMP/SingletonContainer.h>
+#include <IMP/atom.h>
+#include <IMP/core.h>
+#include <IMP/misc.h>
+#include <IMP/em/FitRestraint.h>
+#include <IMP/em/DensityMap.h>
+#include <IMP/core/rigid_bodies.h>
+
+IMPHELPER_BEGIN_NAMESPACE
+
+
+//! Simple collision detection.
+/**
+ \note SimpleCollision stores pointers to PairsRestraint, HarmonicLowerBound,
+        and ClosePairsScoreState.
+ \note It provides convenient methods to change mean, k, standard deviation,
+        slack and distance.
+  \see PairsRestraint
+ */
+class IMPHELPEREXPORT SimpleCollision
+{
+public:
+  /** Creates collision detection on rigid bodies using
+      SphereDistancePairScore and ClosePairsScoreState.
+      The nonbonded list defined for the score state is refined using
+      RigidClosePairsFinder.
+
+    \see SphereDistancePairScore
+    \see HarmonicLowerBound
+    \see ClosePairsScoreState
+    \see ListSingletonContainer
+    \see RigidClosePairsFinder
+  */
+  friend SimpleCollision create_simple_collision_on_rigid_bodies(
+         core::RigidBodies *rbs);
+
+  core::PairsRestraint *restraint()
+  {
+    return pairs_restraint_;
+  }
+
+  core::HarmonicLowerBound *harmonic_lower_bound()
+  {
+    return harmonic_lower_bound_;
+  }
+
+  core::ClosePairsScoreState *close_pairs_score_state()
+  {
+    return close_pairs_score_state_;
+  }
+
+  //! Set the mean for the HarmonicLowerBound.
+  /** The default mean is 0.
+   */
+  void set_mean(Float mean)
+  {
+     harmonic_lower_bound_->set_mean(mean);
+  }
+
+  //! Set the standard deviation for the HarmonicLowerBound.
+  void set_stddev(Float sd)
+  {
+ static Float k = harmonic_lower_bound_- >k_from_standard_deviation(sd);
+     harmonic_lower_bound_->set_k(k);
+  }
+
+  //! Set the spring constant for the HarmonicLowerBound.
+  /** The default k is 1.
+   */
+  void set_k(Float k)
+  {
+     harmonic_lower_bound_->set_k(k);
+  }
+
+  //! Set the amount of slack for the ClosePairsScoreState.
+  /** The default slack is 2.
+   */
+  void set_slack(Float slack)
+  {
+     close_pairs_score_state_->set_slack(slack);
+  }
+
+  //! Set the distance threshold for the ClosePairsScoreState.
+  /** Uses the default distance in the ClosePairsScoreState.
+   */
+  void set_distance(Float distance)
+  {
+     close_pairs_score_state_->set_distance(distance);
+  }
+
+  VersionInfo get_version_info() const
+  {
+    return IMP::get_module_version_info();
+  }
+
+  void show(std::ostream &out = std::cout) const
+  {
+    out << "SimpleCollision(";
+    if ( pairs_restraint_ )
+      pairs_restraint_->show(out);
+    out << ")";
+  }
+
+private:
+  // prevent unauthorized creation
+  SimpleCollision(core::PairsRestraint *pairs_restraint,
+      core::HarmonicLowerBound *harmonic_lower_bound,
+      core::ClosePairsScoreState *close_pairs_score_state)
+    : pairs_restraint_(pairs_restraint)
+    , harmonic_lower_bound_(harmonic_lower_bound)
+    , close_pairs_score_state_(close_pairs_score_state)
+  {}
+
+  IMP::Pointer<core::PairsRestraint> pairs_restraint_;
+  IMP::Pointer<core::HarmonicLowerBound> harmonic_lower_bound_;
+  IMP::Pointer<core::ClosePairsScoreState> close_pairs_score_state_;
+};
+
+//! Simple connectivity restraint.
+/**
+  \note SimpleConnectivity stores pointers to ConnectivityRestraint,
+        and HarmonicUpperBound.
+  \note It provides convenient methods to change mean, k,
+        and standard deviation.
+  \see ConnectivityRestraint
+ */
+class IMPHELPEREXPORT SimpleConnectivity
+{
+public:
+
+  /** Creates ConnectivityRestraint on rigid bodies using
+      RigidBodyDistancePairScore and RigidMembersRefiner.
+
+    \see RigidBodyDistancePairScore
+    \see SphereDistancePairScore
+    \see HarmonicUpperBound
+    \see core::RigidMembersRefiner
+  */
+ friend SimpleConnectivity create_simple_connectivity_on_rigid_bodies(
+         core::RigidBodies *rbs);
+
+ /** Creates ConnectivityRestraint on molecules using LowestRefinedPairScore
+      and LeavesRefiner.
+
+    \see LowestRefinedPairScore
+    \see SphereDistancePairScore
+    \see HarmonicUpperBound
+    \see LeavesRefiner
+  */
+  friend SimpleConnectivity create_simple_connectivity_on_molecules(
+         Particles *ps);
+
+  core::ConnectivityRestraint *restraint()
+  {
+    return connectivity_restraint_;
+  }
+
+  core::HarmonicUpperBound *harmonic_upper_bound()
+  {
+    return harmonic_upper_bound_;
+  }
+
+  //! Set the mean for the HarmonicUpperBound.
+  /** The default mean is 0.
+   */
+  void set_mean(Float mean)
+  {
+     harmonic_upper_bound_->set_mean(mean);
+  }
+
+  //! Set the standard deviation for the HarmonicUpperBound.
+  void set_stddev(Float sd)
+  {
+ static Float k = harmonic_upper_bound_- >k_from_standard_deviation(sd);
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  //! Set the spring constant for the HarmonicUpperBound.
+  /** The default k is 1.
+   */
+  void set_k(Float k)
+  {
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  VersionInfo get_version_info() const
+  {
+    return IMP::get_module_version_info();
+  }
+
+  void show(std::ostream &out = std::cout) const
+  {
+    out << "SimpleConnectivity(";
+    if ( connectivity_restraint_ )
+      connectivity_restraint_->show(out);
+    out << ")";
+  }
+
+private:
+  // prevent unauthorized creation
+  SimpleConnectivity(
+      core::ConnectivityRestraint *connectivity_restraint,
+      core::HarmonicUpperBound *harmonic_upper_bound)
+    : connectivity_restraint_(connectivity_restraint)
+    , harmonic_upper_bound_(harmonic_upper_bound)
+  {}
+
+  IMP::Pointer<core::ConnectivityRestraint> connectivity_restraint_;
+  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
+};
+
+//! Simple distance restraint between two particles.
+/**
+   \note SimpleDistance stores pointers to DistanceRestraint, and
+         HarmonicUpperBound.
+   \note It provides convenient methods to change mean, k, and
+         standard deviation.
+
+   \see DistanceRestraint
+ */
+class IMPHELPEREXPORT SimpleDistance
+{
+public:
+
+ /** Creates DistanceRestraint using HarmonicUpperBound scoring function
+      as default.
+      \param[in] ps Pointer to two particles in distance restraint.
+  */
+  friend SimpleDistance create_simple_distance(Particles *ps);
+
+  core::DistanceRestraint *restraint()
+  {
+    return distance_restraint_;
+  }
+
+  core::HarmonicUpperBound *harmonic_upper_bound()
+  {
+    return harmonic_upper_bound_;
+  }
+
+  //! Set the mean for the HarmonicUpperBound.
+  /** The default mean is 0.
+   */
+  void set_mean(Float mean)
+  {
+     harmonic_upper_bound_->set_mean(mean);
+  }
+
+  //! Set the standard deviation for the HarmonicUpperBound.
+  void set_stddev(Float sd)
+  {
+ static Float k = harmonic_upper_bound_- >k_from_standard_deviation(sd);
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  //! Set the spring constant for the HarmonicUpperBound.
+  /** The default k is 1.
+   */
+  void set_k(Float k)
+  {
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  VersionInfo get_version_info() const
+  {
+    return IMP::get_module_version_info();
+  }
+
+  void show(std::ostream &out = std::cout) const
+  {
+    out << "SimpleDistance(";
+    if ( distance_restraint_ )
+      distance_restraint_->show(out);
+    out << ")";
+  }
+
+private:
+  // prevent unauthorized creation
+  SimpleDistance(
+      core::DistanceRestraint *distance_restraint,
+      core::HarmonicUpperBound *harmonic_upper_bound)
+    : distance_restraint_(distance_restraint)
+    , harmonic_upper_bound_(harmonic_upper_bound)
+  {}
+
+  IMP::Pointer<core::DistanceRestraint> distance_restraint_;
+  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
+};
+
+//! Simple diameter restraint.
+/**
+   \note SimpleDiameter stores pointers to DiameterRestraint, and
+         HarmonicUpperBound.
+   \note It provides convenient methods to change mean, k, and
+         standard deviation.
+   \see DiameterRestraint
+ */
+class IMPHELPEREXPORT SimpleDiameter
+{
+public:
+
+ /** Creates DiameterRestraint using HarmonicUpperBound scoring function
+      as default.
+      \param[in] ps Pointer to particles in diameter restraint.
+      \param[in] diameter Diameter.
+     \see ListSingletonContainer
+  */
+ friend SimpleDiameter create_simple_diameter(Particles *ps, Float diameter);
+
+  core::DiameterRestraint *restraint()
+  {
+    return diameter_restraint_;
+  }
+
+  core::HarmonicUpperBound *harmonic_upper_bound()
+  {
+    return harmonic_upper_bound_;
+  }
+
+  //! Set the mean for the HarmonicUpperBound.
+  /** The default mean is 0.
+   */
+  void set_mean(Float mean)
+  {
+     harmonic_upper_bound_->set_mean(mean);
+  }
+
+  //! Set the standard deviation for the HarmonicUpperBound.
+  void set_stddev(Float sd)
+  {
+ static Float k = harmonic_upper_bound_- >k_from_standard_deviation(sd);
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  //! Set the spring constant for the HarmonicUpperBound.
+  /** The default k is 1.
+   */
+  void set_k(Float k)
+  {
+     harmonic_upper_bound_->set_k(k);
+  }
+
+  VersionInfo get_version_info() const
+  {
+    return IMP::get_module_version_info();
+  }
+
+  void show(std::ostream &out = std::cout) const
+  {
+    out << "SimpleDiameter(";
+    if ( diameter_restraint_ )
+      diameter_restraint_->show(out);
+    out << ")";
+  }
+
+private:
+  // prevent unauthorized creation
+  SimpleDiameter(
+      core::DiameterRestraint *diameter_restraint,
+      core::HarmonicUpperBound *harmonic_upper_bound)
+    : diameter_restraint_(diameter_restraint)
+    , harmonic_upper_bound_(harmonic_upper_bound)
+  {}
+
+  IMP::Pointer<core::DiameterRestraint> diameter_restraint_;
+  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
+};
+
+//! Simple excluded volume restraint.
+/**
+   \see ExcludedVolumeRestraint
+ */
+class IMPHELPEREXPORT SimpleExcludedVolume
+{
+public:
+
+  /** Creates ExcludedVolumeRestraint using LeavesRefiner.
+   \see ListSingletonContainer
+  */
+ friend SimpleExcludedVolume create_simple_excluded_volume_on_rigid_bodies(
+         core::RigidBodies *rbs);
+
+  core::ExcludedVolumeRestraint *restraint()
+  {
+    return excluded_volume_restraint_;
+  }
+
+  VersionInfo get_version_info() const
+  {
+    return IMP::get_module_version_info();
+  }
+
+  void show(std::ostream &out = std::cout) const
+  {
+    out << "SimpleExcludedVolume(";
+    if ( excluded_volume_restraint_ )
+      excluded_volume_restraint_->show(out);
+    out << ")";
+  }
+
+private:
+  // prevent unauthorized creation
+  SimpleExcludedVolume(
+      core::ExcludedVolumeRestraint *excluded_volume_restraint)
+    : excluded_volume_restraint_(excluded_volume_restraint)
+  {}
+
+ IMP::Pointer<core::ExcludedVolumeRestraint> excluded_volume_restraint_;
+};
+
+IMPHELPEREXPORT SimpleCollision create_simple_collision_on_rigid_bodies(
+                core::RigidBodies *rbs);
+
+IMPHELPEREXPORT SimpleConnectivity create_simple_connectivity_on_rigid_bodies(
+                core::RigidBodies *rbs);
+
+IMPHELPEREXPORT SimpleConnectivity create_simple_connectivity_on_molecules(
+                Particles *ps);
+
+IMPHELPEREXPORT SimpleDistance create_simple_distance(Particles *ps);
+
+IMPHELPEREXPORT SimpleDiameter create_simple_diameter(
+                Particles *ps, Float diameter);
+
+IMPHELPEREXPORT SimpleExcludedVolume
+                create_simple_excluded_volume_on_rigid_bodies(
+                core::RigidBodies *rbs);
+
+IMPHELPEREXPORT em::DensityMap *load_map(
+ char const *map_fn, double spacing, double resolution);
+
+IMPHELPEREXPORT em::FitRestraint *create_em_restraint(
+                atom::Hierarchies const &mhs, em::DensityMap *dmap);
+
+IMPHELPEREXPORT Particles set_rigid_bodies(atom::Hierarchies const &mhs);
+
+IMPHELPER_END_NAMESPACE
+
+#endif /* IMPHELPER_SIMPLIFY_RESTRAINT_H */

Modified: trunk/modules/helper/pyext/swig.i-in
===================================================================
--- trunk/modules/helper/pyext/swig.i-in 2009-10-28 18:25:03 UTC (rev 3985) +++ trunk/modules/helper/pyext/swig.i-in 2009-10-28 20:25:46 UTC (rev 3986)
@@ -3,3 +3,4 @@
%include "IMP/helper/covers.h"
%include "IMP/helper/atom_hierarchy.h"
%include "IMP/helper/simplify_atom_hierarchy.h"
+%include "IMP/helper/simplify_restraint.h"

Added: trunk/modules/helper/src/simplify_restraint.cpp
===================================================================
--- trunk/modules/helper/src/ simplify_restraint.cpp (rev 0) +++ trunk/modules/helper/src/simplify_restraint.cpp 2009-10-28 20:25:46 UTC (rev 3986)
@@ -0,0 +1,263 @@
+/**
+    *  \file simplify_restraint.cpp
+    *  \brief Support for restraints.
+    *
+    *  Copyright 2007-9 Sali Lab. All rights reserved.
+    *
+    */
+
+#include "IMP/helper/simplify_restraint.h"
+#include "IMP/helper/rigid_bodies.h"
+#include <IMP/em/DensityMap.h>
+#include <IMP/em/MRCReaderWriter.h>
+
+IMPHELPER_BEGIN_NAMESPACE
+
+SimpleCollision create_simple_collision_on_rigid_bodies(core::RigidBodies *rbs)
+{
+ IMP_USAGE_CHECK(rbs->size() > 0, "At least one particle should be given",
+     ValueException);
+
+  /****** Set up the nonbonded list ******/
+  // Tell nbl on which particles you work on
+  // Look for close pairs within the list
+
+  IMP_NEW(core::ListSingletonContainer, lsc, ());
+  lsc->add_particles(*rbs);
+  IMP_NEW(core::ClosePairsScoreState, nbl, (lsc));
+
+  /****** Refine the nonbonded list ******/
+  // Set up the list of close pairs of each pair in NBL
+ // because you want to restraint the actual rigid bodies and not its particles + // Look for close members of the rigid bodies, one from each rigid body
+
+ //if set_close_pairs_finder is not called, then use the non refined list
+  //if rcpf omitted, then the score is between 2 spheres
+  IMP_NEW(core::RigidClosePairsFinder, rcpf, ());
+  nbl->set_close_pairs_finder(rcpf);
+  // Set the amount particles need to move before the list is updated
+  nbl->set_slack(2);
+
+ /****** Define the score used on each pair in the refined list ******/
+  // Score the distance between the spheres of each particles
+  // Each particle is required to have x,y,z and a radius
+ // The distance is going to be penalized by a harmonic lower bound with
+  // mean = 0 and force constant (k) = 1 kcal/mol/A/A
+ // The mean and k can be changed later on by calling set_mean and set_k + // k can also be obtained given the Gaussian standard deviation (angstroms),
+  // which can be changed using set_stddev
+
+ IMP_NEW(core::HarmonicLowerBound, h, (0, 1)); // (mean, force constant k)
+  IMP_NEW(core::SphereDistancePairScore, sdps, (h));
+
+  /****** Set the restraint ******/
+  // Define the restraint, work on all pairs and score them with sdps
+  // Add the restraint to the model
+
+ IMP_NEW(core::PairsRestraint, evr, (sdps, nbl- >get_close_pairs_container()));
+
+  /****** Add score state and restraint to the model ******/
+
+  Model *mdl = (*rbs)[0].get_model();
+  mdl->add_score_state(nbl);
+  mdl->add_restraint(evr);
+
+  /****** Return a SimpleCollision object ******/
+
+  return SimpleCollision(evr, h, nbl);
+}
+
+SimpleConnectivity create_simple_connectivity_on_rigid_bodies(
+                   core::RigidBodies *rbs)
+{
+ IMP_USAGE_CHECK(rbs->size() > 0, "At least one particle should be given",
+     ValueException);
+
+  /****** Define Refiner ******/
+ // Use RigidMembersRefiner when you want the set of particles representing
+  // a rigid body to be the same as the set of members
+
+  IMP_NEW(core::RigidMembersRefiner, rmr, ());
+
+  /****** Define PairScore ******/
+ // Use RigidBodyDistancePairScore to accelerate computation of the distance + // between two rigid bodies. The distance is defined as the minimal distance + // over all bipartite pairs with one particle taken from each rigid body.
+
+  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
+  IMP_NEW(core::SphereDistancePairScore, sdps, (h));
+  IMP_NEW(core::RigidBodyDistancePairScore, rdps, (sdps, rmr));
+
+  /****** Set the restraint ******/
+
+  IMP_NEW(core::ConnectivityRestraint, cr, (rdps));
+  for ( size_t i=0; i<rbs->size(); ++i )
+    cr->set_particles((*rbs)[i].get_particle());
+
+  /****** Add restraint to the model ******/
+
+  Model *mdl = (*rbs)[0].get_model();
+  mdl->add_restraint(cr);
+
+  /****** Return a SimpleConnectivity object ******/
+
+  return SimpleConnectivity(cr, h);
+}
+
+SimpleConnectivity create_simple_connectivity_on_molecules(Particles *ps)
+{
+ IMP_USAGE_CHECK(ps->size() > 0, "At least one particle should be given",
+     ValueException);
+
+
+  /****** Define Refiner ******/
+  // Use LeavesRefiner for the hierarchy leaves under a particle
+
+  IMP_NEW(core::LeavesRefiner, lr, (atom::Hierarchy::get_traits()));
+
+  /****** Define PairScore ******/
+ // Score on the lowest of the pairs defined by refining the two particles.
+
+  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
+  IMP_NEW(core::SphereDistancePairScore, sdps, (h));
+  IMP_NEW(misc::LowestRefinedPairScore, lrps, (lr, sdps));
+
+  /****** Set the restraint ******/
+
+  IMP_NEW(core::ConnectivityRestraint, cr, (lrps));
+  cr->set_particles((*ps));
+
+  /****** Add restraint to the model ******/
+
+  Model *mdl = (*ps)[0]->get_model();
+  mdl->add_restraint(cr);
+
+  /****** Return a SimpleConnectivity object ******/
+
+  return SimpleConnectivity(cr, h);
+}
+
+SimpleDistance create_simple_distance(Particles *ps)
+{
+  IMP_USAGE_CHECK(ps->size() == 2, "Two particles should be given",
+     ValueException);
+
+  /****** Set the restraint ******/
+
+  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
+  IMP_NEW(core::DistanceRestraint, dr, (h, (*ps)[0], (*ps)[1]));
+
+  /****** Add restraint to the model ******/
+
+  Model *mdl = (*ps)[0]->get_model();
+  mdl->add_restraint(dr);
+
+  /****** Return a SimpleDistance object ******/
+
+  return SimpleDistance(dr, h);
+}
+
+SimpleDiameter create_simple_diameter(Particles *ps, Float diameter)
+{
+ IMP_USAGE_CHECK(ps->size() >= 2, "At least two particles should be given",
+     ValueException);
+
+  /****** Set the restraint ******/
+
+  IMP_NEW(core::HarmonicUpperBound, h, (0, 1));
+  IMP_NEW(core::ListSingletonContainer, lsc, ());
+  lsc->add_particles(*ps);
+  IMP_NEW(core::DiameterRestraint, dr, (h, lsc, diameter));
+
+  /****** Add restraint to the model ******/
+
+  Model *mdl = (*ps)[0]->get_model();
+  mdl->add_restraint(dr);
+
+  /****** Return a SimpleDiameter object ******/
+
+  return SimpleDiameter(dr, h);
+}
+
+SimpleExcludedVolume create_simple_excluded_volume_on_rigid_bodies(
+                     core::RigidBodies *rbs)
+{
+ IMP_USAGE_CHECK(rbs->size() > 0, "At least one particle should be given",
+     ValueException);
+
+  /****** Set the restraint ******/
+
+  IMP_NEW(core::ListSingletonContainer, lsc, ());
+  lsc->add_particles(*rbs);
+
+  IMP_NEW(core::LeavesRefiner, lr, (atom::Hierarchy::get_traits()));
+  IMP_NEW(core::ExcludedVolumeRestraint, evr, (lsc, lr));
+
+  /****** Add restraint to the model ******/
+
+  Model *mdl = (*rbs)[0].get_model();
+  mdl->add_restraint(evr);
+
+  /****** Return a SimpleExcludedVolume object ******/
+
+  return SimpleExcludedVolume(evr);
+}
+
+Particles set_rigid_bodies(atom::Hierarchies const &mhs)
+{
+  size_t mhs_size = mhs.size();
+
+ IMP_USAGE_CHECK(mhs_size > 0, "At least one hierarchy should be given",
+     ValueException);
+
+  Particles rbs;
+  Model *mdl = mhs[0].get_model();
+
+  for ( size_t i=0; i<mhs_size; ++i )
+  {
+    // The rigid body is set to be optimized
+    ScoreState *rb_state = create_rigid_body(mhs[i]);
+
+    // Add the score state to the model to make the body rigid
+ // Remove the score state from the model to stop keeping the body rigid
+    mdl->add_score_state(rb_state);
+
+    rbs.push_back(mhs[i].get_particle());
+  }
+  return rbs;
+}
+
+em::DensityMap *load_map(char const *map_fn, double spacing, double resolution)
+{
+  em::MRCReaderWriter mrw;
+  em::DensityMap *dmap = em::read_map(map_fn, mrw);
+  em::DensityHeader *dmap_header = dmap->get_header_writable();
+  dmap_header->set_spacing(spacing);
+  dmap_header->set_resolution(resolution);
+
+  return dmap;
+}
+
+em::FitRestraint *create_em_restraint(
+    atom::Hierarchies const &mhs, em::DensityMap *dmap)
+{
+  size_t mhs_size = mhs.size();
+
+ IMP_USAGE_CHECK(mhs_size > 0, "At least one hierarchy should be given",
+     runtime_error);
+
+  Particles ps;
+  for ( size_t i=0; i<mhs_size; ++i )
+  {
+    Particles pss = core::get_leaves(mhs[i]);
+    for ( size_t j=0; j<pss.size(); ++j )
+      ps.push_back(pss[j]);
+  }
+  IMP_NEW(em::FitRestraint, fit_rs, (ps, dmap,
+        core::XYZR::get_default_radius_key(),
+        atom::Mass::get_mass_key(), 1.0));
+  fit_rs->set_model(mhs[0].get_particle()->get_model());
+  return fit_rs;
+}
+
+IMPHELPER_END_NAMESPACE

Added: trunk/modules/helper/test/ test_simple_connectivity_on_molecules.py
===================================================================
--- trunk/modules/helper/test/ test_simple_connectivity_on_molecules.py (rev 0) +++ trunk/modules/helper/test/ test_simple_connectivity_on_molecules.py 2009-10-28 20:25:46 UTC (rev 3986)
@@ -0,0 +1,77 @@
+import unittest
+import os
+import IMP
+import IMP.test
+import IMP.atom
+import IMP.helper
+
+class SimpleConnectivityTests(IMP.test.TestCase):
+    """Tests for the SimpleConnectivity """
+
+    def test_connectivity(self):
+
+        def create_particles(m, coordinates):
+            ps = IMP.Particles()
+            radkey = IMP.FloatKey("radius")
+            for pt in coordinates:
+                p = self.create_point_particle(m, *pt)
+                p.add_attribute(radkey, 1.0, False)
+                ps.append(p)
+            return ps
+
+        def compute_and_print_distances(ps):
+            distances = list()
+            for i, p0 in enumerate(ps):
+ print "*****************Distance %d******************" % i
+                for p1 in ps:
+                    if p1 == p0:
+                        continue
+                    dist = self.particle_distance(p0, p1)
+                    print dist
+                    distances.append(dist)
+            print "*******************************************"
+            return distances
+
+        def check_closer_distances(old, new):
+            for od, nd in zip(old, new):
+                self.assert_(od > nd)
+
+        IMP.set_log_level(IMP.VERBOSE)
+
+        m = IMP.Model()
+ ps = create_particles(m, [(0.0, 0.0, 0.0), (100.0, 0.0, 0.0), (0.0, 100.0, 0.0),
+          (0.0, 0.0, 100.0)])
+
+        old_dist = compute_and_print_distances(ps)
+
+        sc = IMP.helper.create_simple_connectivity_on_molecules(ps)
+
+        h = sc.harmonic_upper_bound()
+        r = sc.restraint()
+
+        sc.set_mean(0)
+        self.assertEquals(h.get_mean(), 0)
+
+        sc.set_k(1.5)
+        self.assertInTolerance(h.get_k(), 1.5, 1e-4)
+
+        sc.set_stddev(3.5)
+ self.assertInTolerance(h.get_k(), h.k_from_standard_deviation(3.5), 1e-4)
+
+        o = IMP.core.ConjugateGradients()
+        o.set_threshold(1e-4)
+        o.set_model(m)
+        o.optimize(1000)
+
+        new_dist = compute_and_print_distances(ps)
+
+        check_closer_distances(old_dist, new_dist)
+
+        r.show()
+        m.evaluate(False)
+
+        pps = r.get_connected_pairs()
+
+
+if __name__ == '__main__':
+    unittest.main()

_______________________________________________
IMP-commits mailing list

https://salilab.org/mailman/listinfo/imp-commits