Index: kernel/include/IMP/restraints/SphericalRestraint.h =================================================================== --- kernel/include/IMP/restraints/SphericalRestraint.h (revision 363) +++ kernel/include/IMP/restraints/SphericalRestraint.h (working copy) @@ -1,49 +0,0 @@ -/** - * \file SphericalRestraint.h \brief Absolute position restraint. - * - * Optimize based on distance from an absolute position. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#ifndef __IMP_SPHERICAL_RESTRAINT_H -#define __IMP_SPHERICAL_RESTRAINT_H - -#include <list> - -#include "../IMP_config.h" -#include "../UnaryFunction.h" -#include "../Restraint.h" - -namespace IMP -{ - -//! Restrict particle position based on its distance to a point. -class IMPDLLEXPORT SphericalRestraint : public Restraint -{ -public: - // Create the SphericalRestraint. - /** - \param[in] p The particle to restrict. - \param[in] x The x coordinate to take distance to. - \param[in] y The y coordinate to take distance to. - \param[in] z The z coordinate to take distance to. - \param[in] score_func The scoring function. It is deleted in the - destructor. - */ - SphericalRestraint(Particle* p, - Float x, Float y, Float z, - UnaryFunction* score_func); - virtual ~SphericalRestraint(); - - IMP_RESTRAINT("0.5", "Daniel Russel"); - -protected: - Float center_[3]; - UnaryFunction* score_func_; -}; - -} // namespace IMP - -#endif /* __IMP_COORDINATE_RESTRAINT_H */ Index: kernel/src/restraints/SphericalRestraint.cpp =================================================================== --- kernel/src/restraints/SphericalRestraint.cpp (revision 363) +++ kernel/src/restraints/SphericalRestraint.cpp (working copy) @@ -1,91 +0,0 @@ -/** - * \file SphericalRestraint.cpp \brief Absolute position restraint. - * - * Optimize based on distance from an absolute position. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include <cmath> - -#include "IMP/Model.h" -#include "IMP/Particle.h" -#include "IMP/log.h" -#include "IMP/restraints/SphericalRestraint.h" -#include "IMP/decorators/XYZDecorator.h" - -namespace IMP -{ - -static const float MIN_DISTANCE_SQUARED=.001; - - - -SphericalRestraint::SphericalRestraint(Particle* p, - Float x, Float y, Float z, - UnaryFunction* score_func) -{ - add_particle(p); - center_[0]=x; - center_[1]=y; - center_[2]=z; - score_func_ =score_func; -} - -SphericalRestraint::~SphericalRestraint() -{ - delete score_func_; -} - - - -Float SphericalRestraint::evaluate(DerivativeAccumulator *accum) -{ - IMP_CHECK_OBJECT(score_func_); - - Float d2=0; - Float diff[3]; - XYZDecorator xyzd= XYZDecorator::cast(get_particle(0)); - for (unsigned int i=0; i< 3; ++i) { - diff[i] =xyzd.get_coordinate(i) - center_[i]; - d2+= diff[i]*diff[i]; - } - Float d= std::sqrt(d2); - if (d2 < MIN_DISTANCE_SQUARED) { - return 0; - } - - Float ret=0; - if (accum) { - Float deriv; - ret= (*score_func_)(d, deriv); - for (unsigned int i=0; i< 3; ++i) { - Float dd= deriv*diff[i]/d; - xyzd.add_to_coordinate_derivative(i, dd, *accum); - } - } else { - ret= (*score_func_)(d); - } - return ret; -} - - -void SphericalRestraint::show(std::ostream& out) const -{ - if (get_is_active()) { - out << "Spherical restraint (active):" << std::endl; - } else { - out << "Spherical restraint (inactive):" << std::endl; - } - - out << " version: " << version() << " "; - out << " last_modified_by: " << last_modified_by() << std::endl; - out << " particle: " << get_particle(0)->get_index(); - out << " "; - score_func_->show(out); - out << std::endl; - out << std::endl; -} - -} // namespace IMP Index: kernel/test/coordinate/test_coordinate.py =================================================================== --- kernel/test/coordinate/test_coordinate.py (revision 363) +++ kernel/test/coordinate/test_coordinate.py (working copy) @@ -1,69 +0,0 @@ -import unittest -import os -import IMP -import IMP.test -import IMP.utils - -class CoordinateTests(IMP.test.TestCase): - """Test various absolute position restraints""" - - def setUp(self): - self.model = IMP.Model() - p= IMP.Particle() - self.pi= self.model.add_particle(p); - d= IMP.XYZDecorator.create(p) - d.set_coordinates_are_optimized(True) - pc= IMP.Particle() - self.pic= self.model.add_particle(pc); - dc= IMP.XYZDecorator.create(pc) - - self.opt = IMP.SteepestDescent() - self.opt.set_model(self.model) - #self.opt.set_threshold(1e-5) - - - def _do_test(self, center, sf): - """All coordinate values should be greater than the set minimum""" - - r= IMP.SphericalRestraint(self.model.get_particle(self.pi), - center[0], center[1], center[2], - sf) - ri=self.model.add_restraint(r) - - self.opt.optimize(55) - self.model.get_restraint(ri).set_is_active(False) - - def _get_center(self): - v= IMP.Floats() - d= IMP.XYZDecorator.cast(self.model.get_particle(self.pic)) - v.append(d.get_x()) - v.append(d.get_y()) - v.append(d.get_z()) - return v - - def test_in_ball(self): - """Testing that restraint keeps point in ball""" - self.randomize_particles(self.model.get_particles(), 50.0) - f= IMP.HarmonicUpperBound(10,.1) - c= self._get_center() - self._do_test(c, f) - pd= IMP.XYZDecorator.cast(self.model.get_particle(self.pi)) - cd= IMP.XYZDecorator.cast(self.model.get_particle(self.pic)) - d= IMP.distance(pd, cd) - self.assert_(d < 11) - - def test_on_ball(self): - """Testing that restraint keeps point on sphere""" - self.randomize_particles(self.model.get_particles(), 50.0) - f= IMP.Harmonic(10,.1) - c= self._get_center() - self._do_test( c, f) - pd= IMP.XYZDecorator.cast(self.model.get_particle(self.pi)) - cd= IMP.XYZDecorator.cast(self.model.get_particle(self.pic)) - d= IMP.distance(pd, cd) - self.assert_(d < 11) - self.assert_(d > 9) - - -if __name__ == '__main__': - unittest.main()