Index: kernel/test/restraints/test_tunnel.py =================================================================== --- kernel/test/restraints/test_tunnel.py (revision 0) +++ kernel/test/restraints/test_tunnel.py (revision 0) @@ -0,0 +1,62 @@ +import unittest +import IMP +import IMP.test +import IMP.utils +import math + +class TunnelTest(IMP.test.TestCase): + """Tests for tunnel restraints""" + + def test_score(self): + """Test derivatives and score of tunnel restraint""" + IMP.set_log_level(IMP.VERBOSE) + m= IMP.Model() + p= IMP.Particle() + m.add_particle(p) + d= IMP.XYZDecorator.create(p) + rk= IMP.FloatKey("radiusk") + p.add_attribute(rk, 1, False) + f= IMP.HarmonicLowerBound(0, 1) + tr= IMP.TunnelRestraint(f, rk) + tr.set_height(10) + tr.set_radius(5) + tr.set_center(IMP.Vector3D(10,10,10)) + tr.add_particle(p) + tr.set_coordinate(2) + m.add_restraint(tr) + m.evaluate(True) + d.set_coordinates(IMP.Vector3D(10,10,10)) + self.assertEqual(m.evaluate(True), 0) + + print "Test left" + d.set_coordinates(IMP.Vector3D(4, 10, 10)) + self.assert_(m.evaluate(True)>0) + self.assertEqual(d.get_coordinate_derivative(2), 0) + self.assertEqual(d.get_coordinate_derivative(1), 0) + print d.get_coordinate_derivative(0) + self.assert_(d.get_coordinate_derivative(0) > 0) + + print "Test above" + d.set_coordinates(IMP.Vector3D(10, 4, 10)) + self.assert_(m.evaluate(True)>0) + self.assertEqual(d.get_coordinate_derivative(2), 0) + self.assertEqual(d.get_coordinate_derivative(0), 0) + print d.get_coordinate_derivative(1) + self.assert_(d.get_coordinate_derivative(1) > 0) + + print "Test bottom" + d.set_coordinates(IMP.Vector3D(30, 30, 3)) + self.assert_(m.evaluate(True)>0) + self.assertEqual(d.get_coordinate_derivative(0), 0) + self.assertEqual(d.get_coordinate_derivative(1), 0) + self.assert_(d.get_coordinate_derivative(2) < 0) + + print "Test top" + d.set_coordinates(IMP.Vector3D(30, 30, 17)) + self.assert_(m.evaluate(True)>0) + self.assertEqual(d.get_coordinate_derivative(0), 0) + self.assertEqual(d.get_coordinate_derivative(1), 0) + self.assert_(d.get_coordinate_derivative(2) > 0) + +if __name__ == '__main__': + unittest.main() Index: kernel/include/IMP/restraints/TunnelRestraint.h =================================================================== --- kernel/include/IMP/restraints/TunnelRestraint.h (revision 0) +++ kernel/include/IMP/restraints/TunnelRestraint.h (revision 0) @@ -0,0 +1,82 @@ +/** + * \file TunnelRestraint.h \brief Tunnel restraint. + * + * Just return a constant. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + * + */ + +#ifndef __IMP_TUNNEL_RESTRAINT_H +#define __IMP_TUNNEL_RESTRAINT_H + +#include "../IMP_config.h" +#include "../Restraint.h" +#include "../Vector3D.h" +#include "../UnaryFunction.h" +#include "../internal/kernel_version_info.h" + +namespace IMP +{ +class PairScore; + +//! Restrain particles to a tunnel. +/** Particles with x,y,z coordinates and an optional radius are + prevented from being in a volume destribed by a slab from + (center[i]-height) to (center+height) on the ith coordinate with a + tunnel of radius r centered at center. To set which coordinate + is used use the get/set _coordinate functions. + + Note that the UnaryFunction should look like a lower bound with 0 + meaning that the particle is just touching the tunnel. + + \ingroup restraint + */ +class IMPDLLEXPORT TunnelRestraint : public Restraint +{ + int coordinate_; + Vector3D center_; + Float height_; + Float radius_; + internal::ObjectPointer f_; + FloatKey rk_; +public: + TunnelRestraint(UnaryFunction* f, FloatKey rk); + + void set_center(Vector3D c){ + center_=c; + } + void set_height(Float h){ + IMP_check(h >= 0, + "Height can't be negative", + ValueException); + height_=h; + } + void set_radius(Float h){ + IMP_check(h >= 0, + "Radius can't be negative", + ValueException); + radius_=h; + } + void set_coordinate(unsigned int i) { + IMP_check(i < 3, + "Invalid coordinate value", + ValueException); + coordinate_=i; + } + unsigned int get_coordinate() const { + return coordinate_; + } + + using Restraint::add_particles; + using Restraint::add_particle; + using Restraint::set_particles; + using Restraint::clear_particles; + using Restraint::erase_particle; + + IMP_RESTRAINT(internal::kernel_version_info) +}; + +} // namespace IMP + +#endif /* __IMP_CONSTANT_RESTRAINT_H */ Index: kernel/include/IMP/restraints/SConscript =================================================================== --- kernel/include/IMP/restraints/SConscript (revision 611) +++ kernel/include/IMP/restraints/SConscript (working copy) @@ -1,15 +1,21 @@ +Import('env') import os.path -Import('env') - -files = ['ConnectivityRestraint.h', - 'DistanceRestraint.h', 'AngleRestraint.h', - 'DihedralRestraint.h', 'RestraintSet.h', - 'NonbondedRestraint.h', 'BondDecoratorRestraint.h', - 'SingletonListRestraint.h', 'PairListRestraint.h', - 'TripletChainRestraint.h', 'PairChainRestraint.h', - 'ConstantRestraint.h'] - -# Install the include files: -includedir = os.path.join(env['includedir'], 'IMP', 'restraints') +files=[ + 'AngleRestraint.h', + 'BondDecoratorRestraint.h', + 'ConnectivityRestraint.h', + 'ConstantRestraint.h', + 'DihedralRestraint.h', + 'DistanceRestraint.h', + 'NonbondedRestraint.h', + 'PairChainRestraint.h', + 'PairListRestraint.h', + 'RestraintSet.h', + 'SingletonListRestraint.h', + 'SymmetryRestraint.h', + 'TripletChainRestraint.h', + 'TunnelRestraint.h', + ] +includedir = os.path.join(env['includedir'], 'IMP', 'restraints' ) inst = env.Install(includedir, files) env.Alias('install', inst) Index: kernel/src/restraints/TunnelRestraint.cpp =================================================================== --- kernel/src/restraints/TunnelRestraint.cpp (revision 0) +++ kernel/src/restraints/TunnelRestraint.cpp (revision 0) @@ -0,0 +1,103 @@ +/** + * \file TunnelRestraint.cpp \brief Don't restrain anything. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + * + */ + +#include "IMP/restraints/TunnelRestraint.h" +#include "IMP/decorators/XYZDecorator.h" + +namespace IMP +{ + +TunnelRestraint::TunnelRestraint(UnaryFunction *f, FloatKey r) : f_(f), + rk_(r){ + coordinate_=0; + center_=Vector3D(0,0,0); + height_=0; + radius_=0; +} + + + +Float TunnelRestraint::evaluate(DerivativeAccumulator *accum) +{ + Float ret=0; + for (Restraint::ParticleIterator it= Restraint::particles_begin(); + it != Restraint::particles_end(); ++it) { + XYZDecorator d(*it); + Float radius=0; + if (rk_ != FloatKey() && (*it)->has_attribute(rk_)) { + radius= (*it)->get_value(rk_); + } + IMP_LOG(VERBOSE, "Tunnel restraint on particle " << d << std::endl); + Float hr= height_+radius; + if (d.get_coordinate(coordinate_) < center_[coordinate_] + hr + && d.get_coordinate(coordinate_) > center_[coordinate_] - hr) { + Float sd=0; + for (int i=1; i< 3; ++i) { + int oc= (i+coordinate_)%3; + sd+= square(d.get_coordinate(oc)- center_[oc]); + } + sd= std::sqrt(sd); + IMP_LOG(VERBOSE, "The distance is " << sd << " and radius " + << radius_ << std::endl); + if (sd > radius_-radius) { + Float rd= sd-radius_; + Float hdu= center_[coordinate_] + height_ + - d.get_coordinate(coordinate_); + Float hdd= d.get_coordinate(coordinate_) + + height_- center_[coordinate_]; + Vector3D deriv(0,0,0); + Float score=0; + Float deriv_scalar=0; + /*! \todo Clean up these tests so I am not dependent on two expressions + being the same and evaluating to the same thing */ + // look below if changed + Float dist= -std::min(std::min(rd, hdu), hdd) - radius; + if (accum) { + score= f_->evaluate_deriv(dist, deriv_scalar); + } else { + score= f_->evaluate(dist); + } + + // kind if evil + if (dist== -rd -radius) { + Vector3D v= (d.get_vector() - center_).get_unit_vector(); + for (int i=0; i< 2; ++i) { + int oc= (i+coordinate_+1)%3; + deriv[oc]= v[oc]*deriv_scalar; + } + } else { + // kind of evil + if (dist == -hdu -radius) deriv_scalar= -deriv_scalar; + deriv[coordinate_]= deriv_scalar; + } + + if (accum) { + for (unsigned int i=0; i< 3; ++i) { + d.add_to_coordinate_derivative(i, deriv[i], *accum); + } + } + ret+= score; + } else { + IMP_LOG(VERBOSE, "Particle " << (*it)->get_index() + << " is in channel" << std::endl); + } + } else { + IMP_LOG(VERBOSE, "Particle " << (*it)->get_index() + << " is outside of slab" << std::endl); + } + } + return ret; +} + +void TunnelRestraint::show(std::ostream& out) const +{ + out << "Tunnel restraint :" << f_ + << " " << center_ << " " << height_ << " " + << coordinate_ << std::endl; +} + +} // namespace IMP Index: kernel/src/restraints/SConscript =================================================================== --- kernel/src/restraints/SConscript (revision 611) +++ kernel/src/restraints/SConscript (working copy) @@ -1,11 +1,16 @@ -Import('env') - -files = ['ConnectivityRestraint.cpp', 'RestraintSet.cpp', - 'DistanceRestraint.cpp', 'AngleRestraint.cpp', 'DihedralRestraint.cpp', - 'NonbondedRestraint.cpp', 'BondDecoratorRestraint.cpp', - 'SingletonListRestraint.cpp', 'PairListRestraint.cpp', - 'TripletChainRestraint.cpp', 'PairChainRestraint.cpp', - 'ConstantRestraint.cpp'] - -files = [File(x) for x in files] +files=[ + File( 'AngleRestraint.cpp' ), + File( 'BondDecoratorRestraint.cpp' ), + File( 'ConnectivityRestraint.cpp' ), + File( 'ConstantRestraint.cpp' ), + File( 'DihedralRestraint.cpp' ), + File( 'DistanceRestraint.cpp' ), + File( 'NonbondedRestraint.cpp' ), + File( 'PairChainRestraint.cpp' ), + File( 'PairListRestraint.cpp' ), + File( 'RestraintSet.cpp' ), + File( 'SingletonListRestraint.cpp' ), + File( 'TripletChainRestraint.cpp' ), + File( 'TunnelRestraint.cpp' ), + ] Return('files') Index: kernel/pyext/IMP.i =================================================================== --- kernel/pyext/IMP.i (revision 611) +++ kernel/pyext/IMP.i (working copy) @@ -42,6 +42,9 @@ %pythonprepend NonbondedListScoreState::add_bonded_list %{ args[1].thisown=0 %} + %pythonprepend TunnelRestraint::TunnelRestraint %{ + args[0].thisown=0 + %} %pythonprepend DistanceRestraint::DistanceRestraint %{ args[0].thisown=0 %} @@ -234,6 +237,7 @@ %include "IMP/restraints/RestraintSet.h" %include "IMP/restraints/SingletonListRestraint.h" %include "IMP/restraints/TripletChainRestraint.h" +%include "IMP/restraints/TunnelRestraint.h" namespace IMP { %template(ParticleIndex) Index; Index: kernel/include/IMP.h =================================================================== --- kernel/include/IMP.h (revision 611) +++ kernel/include/IMP.h (working copy) @@ -1,88 +1,108 @@ /** - * \file IMP.h \brief IMP, an Integrative Modeling Platform. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - +* ile IMP.h rief IMP, an Integrative Modeling Platform. +* +* Copyright 2007-8 Sali Lab. All rights reserved. +* +*/ #ifndef __IMP_H #define __IMP_H - -#include "IMP/IMP_config.h" -#include "IMP/log.h" -#include "IMP/random.h" -#include "IMP/base_types.h" -#include "IMP/Particle.h" -#include "IMP/Optimizer.h" -#include "IMP/Restraint.h" -#include "IMP/exception.h" -#include "IMP/UnaryFunction.h" -#include "IMP/unary_functions/Harmonic.h" -#include "IMP/unary_functions/HarmonicLowerBound.h" -#include "IMP/unary_functions/HarmonicUpperBound.h" -#include "IMP/unary_functions/OpenCubicSpline.h" -#include "IMP/unary_functions/ClosedCubicSpline.h" -#include "IMP/unary_functions/Cosine.h" -#include "IMP/unary_functions/Linear.h" -#include "IMP/unary_functions/WormLikeChain.h" -#include "IMP/Model.h" -#include "IMP/PairScore.h" -#include "IMP/SingletonScore.h" -#include "IMP/TripletScore.h" -#include "IMP/Vector3D.h" -#include "IMP/VersionInfo.h" -#include "IMP/ParticleRefiner.h" -#include "IMP/particle_refiners/BondCoverParticleRefiner.h" -#include "IMP/particle_refiners/ChildrenParticleRefiner.h" -#include "IMP/decorators/HierarchyDecorator.h" -#include "IMP/decorators/MolecularHierarchyDecorator.h" -#include "IMP/decorators/NameDecorator.h" -#include "IMP/decorators/AtomDecorator.h" -#include "IMP/decorators/ResidueDecorator.h" -#include "IMP/decorators/XYZDecorator.h" -#include "IMP/decorators/bond_decorators.h" -#include "IMP/optimizers/SteepestDescent.h" -#include "IMP/optimizers/ConjugateGradients.h" -#include "IMP/optimizers/MolecularDynamics.h" -#include "IMP/optimizers/BrownianDynamics.h" -#include "IMP/optimizers/MonteCarlo.h" -#include "IMP/optimizers/Mover.h" -#include "IMP/optimizers/MoverBase.h" -#include "IMP/optimizers/movers/BallMover.h" -#include "IMP/optimizers/movers/NormalMover.h" -#include "IMP/optimizers/states/VRMLLogOptimizerState.h" -#include "IMP/optimizers/states/CMMLogOptimizerState.h" -#include "IMP/optimizers/states/VelocityScalingOptimizerState.h" -#include "IMP/pair_scores/DistancePairScore.h" -#include "IMP/pair_scores/SphereDistancePairScore.h" -#include "IMP/pair_scores/RefineOncePairScore.h" -#include "IMP/singleton_scores/DistanceToSingletonScore.h" -#include "IMP/singleton_scores/AttributeSingletonScore.h" -#include "IMP/triplet_scores/AngleTripletScore.h" -#include "IMP/restraints/RestraintSet.h" -#include "IMP/restraints/ConstantRestraint.h" -#include "IMP/restraints/DistanceRestraint.h" -#include "IMP/restraints/AngleRestraint.h" -#include "IMP/restraints/DihedralRestraint.h" -#include "IMP/restraints/ConnectivityRestraint.h" -#include "IMP/restraints/NonbondedRestraint.h" -#include "IMP/restraints/BondDecoratorRestraint.h" -#include "IMP/restraints/SingletonListRestraint.h" -#include "IMP/restraints/PairListRestraint.h" -#include "IMP/restraints/TripletChainRestraint.h" -#include "IMP/restraints/PairChainRestraint.h" -#include "IMP/score_states/BipartiteNonbondedListScoreState.h" -#include "IMP/score_states/MaxChangeScoreState.h" -#include "IMP/score_states/NonbondedListScoreState.h" -#include "IMP/score_states/BondedListScoreState.h" -#include "IMP/score_states/BondDecoratorListScoreState.h" -#include "IMP/score_states/AllNonbondedListScoreState.h" -#include "IMP/score_states/GravityCenterScoreState.h" -#include "IMP/score_states/CoverBondsScoreState.h" - - -/** - \namespace IMP The IMP namespace. - */ - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif /* __IMP_H */