Index: kernel/test/particle_refiners/test_refone.py =================================================================== --- kernel/test/particle_refiners/test_refone.py (revision 0) +++ kernel/test/particle_refiners/test_refone.py (revision 0) @@ -0,0 +1,37 @@ +import unittest +import IMP +import IMP.test + +class TestRefon(IMP.test.TestCase): + def setUp(self): + """Build a set of test particles""" + IMP.test.TestCase.setUp(self) + + def test_it(self): + """Test that RefineOncePairScore uses refiners properly""" + m= IMP.Model() + print "hello" + ps= self.create_particles_in_box(m, 20) + for p in ps: + p.add_attribute(IMP.FloatKey("volume"), 1, False) + bds= self.create_chain(ps, 10) + bdss= IMP.BondDecoratorListScoreState(ps) + m.add_score_state(bdss) + bcss= IMP.CoverBondsScoreState(bdss) + m.evaluate(False) + bps= IMP.test.TestCase.ConstPairScore(1) + br= IMP.BondCoverParticleRefiner(IMP.FloatKey("radius"), + IMP.FloatKey("volume")) + r= IMP.test.TestCase.TestParticleRefiner(br) + ro= IMP.RefineOncePairScore(r, bps) + print "setup" + for i in range(0, len(bds)): + for j in range(0,i): + ro.evaluate(bds[i].get_particle(), + bds[j].get_particle(), + None) + print "done" + self.assert_(1) + +if __name__ == '__main__': + unittest.main() Index: kernel/test/particle_refiners/test_bond_pr.py =================================================================== --- kernel/test/particle_refiners/test_bond_pr.py (revision 0) +++ kernel/test/particle_refiners/test_bond_pr.py (revision 0) @@ -0,0 +1,65 @@ +import unittest +import IMP +import IMP.test + +rk = IMP.FloatKey("radius") + +class Test(IMP.test.TestCase): + """Tests for bond refiner""" + + def _set_up_stuff(self, n): + # return [model, particles, bonds] + m= IMP.Model() + ps= self.create_particles_in_box(m) + bds= self.create_chain(ps, 10) + bl= IMP.BondDecoratorListScoreState(ps) + ss= IMP.CoverBondsScoreState(bl, rk) + m.add_score_state(bl) + m.add_score_state(ss) + return [m, ps, bds] + + + def test_set_position(self): + """Make sure that bond cover coordinates are correct""" + IMP.set_log_level(IMP.VERBOSE) + [m,ps, bds]= self._set_up_stuff(8) + vk= IMP.FloatKey("volume") + rk= IMP.FloatKey("radius") + bc= IMP.BondCoverParticleRefiner(rk, vk) + for p in ps: + self.assert_(not bc.get_can_refine(p)) + for b in bds: + b.get_particle().add_attribute(vk, 1, False) + self.assert_(bc.get_can_refine(b.get_particle())) + rps= bc.get_refined(b.get_particle()) + + d0= IMP.XYZDecorator.cast(b.get_bonded(0).get_particle()) + d1= IMP.XYZDecorator.cast(b.get_bonded(1).get_particle()) + + vol=0.0 + print "Bond from " + d0.show() + print " to " + d1.show() + print + for p in rps: + r= p.get_value(rk) + print "Cover particle is has radius "+str(r) + dc= IMP.XYZDecorator.cast(p) + dc.show() + print + v= 4.0/3.0 * 3.14 * r**3 + vol = vol + v + n= len(rps) + print vol*(n-1.0)/n + print vol + print vol*(n+1.0)/n + print n + # crap check + self.assert_(.5*vol* (n-1.0)/n < 1 and 2*vol *(n+1.0)/n > 1) + + + + +if __name__ == '__main__': + unittest.main() Index: kernel/test/particle_refiners/test_children.py =================================================================== --- kernel/test/particle_refiners/test_children.py (revision 0) +++ kernel/test/particle_refiners/test_children.py (revision 0) @@ -0,0 +1,35 @@ +import unittest +import IMP +import IMP.test + + +class Test(IMP.test.TestCase): + """Tests for children refiner""" + + + def test_set_position(self): + """Make sure the Children refiner works""" + IMP.set_log_level(IMP.VERBOSE) + print "hello" + m= IMP.Model() + pp= IMP.Particle() + m.add_particle(pp) + hpp= IMP.HierarchyDecorator.create(pp) + c=[] + for i in range(0,10): + p= IMP.Particle() + m.add_particle(p) + hp= IMP.HierarchyDecorator.create(p) + hpp.add_child(hp) + c.append(p) + pr= IMP.ChildrenParticleRefiner() + cs= pr.get_refined(pp) + self.assertEqual(len(cs), len(c)) + for i in range(0, len(cs)): + self.assertEqual(c[i].get_index().get_index(), + cs[i].get_index().get_index()) + + + +if __name__ == '__main__': + unittest.main() Index: kernel/test/states/test_nonbonded_list.py =================================================================== --- kernel/test/states/test_nonbonded_list.py (revision 597) +++ kernel/test/states/test_nonbonded_list.py (working copy) @@ -2,26 +2,7 @@ import IMP, IMP.test import random -class OnePair(IMP.PairScore): - def __init__(self): - IMP.PairScore.__init__(self) - def evaluate(self, pa, pb, da): - return 1 - def get_version_info(self): - return IMP.VersionInfo("Me", "0.5") - def show(self, t): - print "One Pair" -class OneScore(IMP.UnaryFunction): - def __init__(self): - IMP.UnaryFunction.__init__(self) - def evaluate(self, feat): - return 100 - def evaluate_deriv(self, feat): - return 100, 0.0 - def show(self, *args): - print "One score" - class TestNBL(IMP.test.TestCase): def setUp(self): IMP.test.TestCase.setUp(self) @@ -83,24 +64,11 @@ self.do_test_bi_update(ss) def make_spheres(self, m, num, lbv, ubv, minr, maxr): - ps=self.make_particles(m, num, lbv, ubv) + ps=self.create_particles_in_box(m, num, lbv, ubv) for p in ps: p.add_attribute(self.rk, random.uniform(minr, maxr), False) return ps - def make_particles(self, m, num, lbv, ubv): - ps=IMP.Particles() - lb=IMP.Vector3D(lbv[0],lbv[1],lbv[2]) - ub=IMP.Vector3D(ubv[0],ubv[1],ubv[2]) - for i in range(0, num): - p= IMP.Particle() - m.add_particle(p) - d=IMP.XYZDecorator.create(p) - d.set_coordinates_are_optimized(True) - d.randomize_in_box(lb, ub) - ps.append(p) - return ps - def do_test_update(self, ss): m= IMP.Model() self.make_spheres(m, 20, [0,0,0], [10,10,10], .1, 1) @@ -111,7 +79,7 @@ s=eval(ss) s.set_particles(m.get_particles()) m.add_score_state(s) - o= OnePair() + o= IMP.test.TestCase.ConstPairScore(1) r= IMP.NonbondedRestraint(o, s) m.add_restraint(r) # use the internal checks @@ -135,9 +103,9 @@ b= IMP.BondDecoratorListScoreState(pts) s.add_bonded_list(b) m.add_score_state(s) - o= OnePair() + o= IMP.test.TestCase.ConstPairScore(1) r= IMP.NonbondedRestraint(o, s) - os=OneScore() + os=IMP.test.TestCase.ConstUnaryFunction(100) print os.evaluate(6) br= IMP.BondDecoratorRestraint(os, b) m.add_restraint(r) @@ -151,15 +119,15 @@ #IMP.set_log_level(IMP.TERSE) m= IMP.Model() ps=IMP.Particles() - ps= self.make_particles(m, 20, [0,0,0], [10,10,10]) - pts= self.make_particles(m, 20, [160,160,160], [170,170,170]) + ps= self.create_particles_in_box(m, 20, [0,0,0], [10,10,10]) + pts= self.create_particles_in_box(m, 20, [160,160,160], [170,170,170]) for p in pts: ps.append(p) md=15 s=eval(ss) s.set_particles(ps) m.add_score_state(s) - o= OnePair() + o= IMP.test.TestCase.ConstPairScore(1) r= IMP.NonbondedRestraint(o, s) m.add_restraint(r) score= m.evaluate(False) @@ -200,7 +168,7 @@ # ps0, ps1) s.set_particles(ps0, ps1) m.add_score_state(s) - o= OnePair() + o= IMP.test.TestCase.ConstPairScore(1) r= IMP.NonbondedRestraint(o, s) m.add_restraint(r) score= m.evaluate(False) @@ -218,7 +186,7 @@ # ps0, ps1) s.set_particles(ps0, ps1) m.add_score_state(s) - o= OnePair() + o= IMP.test.TestCase.ConstPairScore(1) r= IMP.NonbondedRestraint(o, s) m.add_restraint(r) for i in range(0,20): Index: kernel/include/IMP/Restraint.h =================================================================== --- kernel/include/IMP/Restraint.h (revision 597) +++ kernel/include/IMP/Restraint.h (working copy) @@ -41,6 +41,9 @@ constructor and should provide methods so that the set of particles can be modified after construction. + A restraint can be added to the model multiple times or to multiple + restraint sets in the same model. + \note When logging is VERBOSE, restraints should print enough information in evaluate to reproduce the the entire flow of data in evaluate. When logging is TERSE the restraint should print out only a constant number of Index: kernel/include/IMP/ParticleRefiner.h =================================================================== --- kernel/include/IMP/ParticleRefiner.h (revision 0) +++ kernel/include/IMP/ParticleRefiner.h (revision 0) @@ -0,0 +1,62 @@ +/** + * \file ParticleRefiner.h + * \brief Refine a particle into a list of particles. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + */ + +#ifndef __IMP_PARTICLE_REFINER_H +#define __IMP_PARTICLE_REFINER_H + +#include "IMP_config.h" +#include "base_types.h" +#include "VersionInfo.h" +#include "internal/RefCountedObject.h" + +namespace IMP +{ + +class Particle; +class DerivativeAccumulator; + +//! Abstract class to implement hierarchical methods. +/** The job of this class is to take a single particle and, if + appropriate, return a list of particles. . +*/ +class IMPDLLEXPORT ParticleRefiner : public internal::RefCountedObject +{ +public: + ParticleRefiner() {} + virtual ~ParticleRefiner(); + //! Return true if this refiner can refine that particle + /** This should not throw, so be careful what fields are touched. + */ + virtual bool get_can_refine(Particle *a) const {return false;} + //! Refine the passed particle into a set of particles. + /** As a precondition can_refine_particle(a) should be true. + */ + virtual Particles get_refined(Particle *a); + + //! Cleanup after refining + /** If da is non-NULL then the derivatives should be propagated + to the appropriate particles. This method is only called when + then caller is done with the particles, so the particles + can be destroyed if they are temporary. + */ + virtual void cleanup_refined(Particle *a, Particles &b, + DerivativeAccumulator *da=0) {} + virtual void show(std::ostream &out=std::cout) const { + out << "ParticleRefiner base" << std::endl; + }; + + virtual IMP::VersionInfo get_version_info() const =0; +}; + +typedef std::vector ParticleRefiners; +typedef Index ParticleRefinerIndex; + +IMP_OUTPUT_OPERATOR(ParticleRefiner); + +} // namespace IMP + +#endif /* __IMP_PAIR_SCORE_H */ Index: kernel/include/IMP/optimizers/Mover.h =================================================================== --- kernel/include/IMP/optimizers/Mover.h (revision 597) +++ kernel/include/IMP/optimizers/Mover.h (working copy) @@ -51,7 +51,7 @@ moves. This number can be either used to scale a continuous move or affect the probability of a discrete move. */ - virtual void propose_move(float size)=0; + virtual void propose_move(float probability)=0; //! set whether the proposed modification is accepted /** \note Accepting should not change the Particles at all. */ Index: kernel/include/IMP/decorators/macros.h =================================================================== --- kernel/include/IMP/decorators/macros.h (revision 597) +++ kernel/include/IMP/decorators/macros.h (working copy) @@ -68,7 +68,8 @@ return IMP::DecoratorBase::cast(p); \ } \ static bool is_instance_of(::IMP::Particle *p) { \ - return has_required_attributes(p); \ + decorator_initialize_static_data(); \ + return has_required_attributes(p); \ } \ /** Write information about this decorator to out. Each line should \ prefixed by prefix*/ \ Index: kernel/include/IMP/internal/units.h =================================================================== --- kernel/include/IMP/internal/units.h (revision 597) +++ kernel/include/IMP/internal/units.h (working copy) @@ -33,7 +33,7 @@ namespace internal { -struct AtomsPerMol {}; +struct IMPDLLEXPORT AtomsPerMol {}; struct MDEnergyTag; Index: kernel/include/IMP/internal/RefCountedObject.h =================================================================== --- kernel/include/IMP/internal/RefCountedObject.h (revision 597) +++ kernel/include/IMP/internal/RefCountedObject.h (working copy) @@ -21,8 +21,7 @@ { //! Common base class for ref counted objects. -/** Currently the only ref counted objects are particles. - This class acts as a tag rather than providing any functionality. +/** This class acts as a tag rather than providing any functionality. \internal */ @@ -104,8 +103,6 @@ void unref(O o) { BOOST_STATIC_ASSERT(!boost::is_pointer::value); - /*IMP_LOG(VERBOSE, "NonUnRef called with nonpointer for " - << o << std::endl);*/ } @@ -114,17 +111,12 @@ void ref(O o) { BOOST_STATIC_ASSERT(!boost::is_pointer::value); - /*IMP_LOG(VERBOSE, "NonRef count called with nonpointer for " - << o << std::endl);*/ } //! Can be called on any object and will only unref it if appropriate template void unref(O* o) { - /*IMP_LOG(VERBOSE, "Unref count called with " - << (boost::is_base_of::value) - << " for " << o << std::endl);*/ UnRef<(boost::is_base_of::value)>::eval(o); } @@ -133,9 +125,6 @@ template void ref(O* o) { - /*IMP_LOG(VERBOSE, "Ref called with " - << (boost::is_base_of::value) - << " for " << o << std::endl);*/ Ref<(boost::is_base_of::value)>::eval(o); } Index: kernel/include/IMP/unary_functions/WormLikeChain.h =================================================================== --- kernel/include/IMP/unary_functions/WormLikeChain.h (revision 597) +++ kernel/include/IMP/unary_functions/WormLikeChain.h (working copy) @@ -31,7 +31,11 @@ /** \param[in] l_max maximum length of the chain in angstroms \param[in] lp persistence length in angstroms */ - WormLikeChain(Float l_max, Float lp) : lmax_(l_max), lp_(lp) {} + WormLikeChain(Float l_max, Float lp) : lmax_(l_max), lp_(lp) { + IMP_check(l_max > lp, "The persistance length should be less " + << "than the total length for this model", + ValueException); + } virtual ~WormLikeChain() {} Index: kernel/include/IMP/SConscript =================================================================== --- kernel/include/IMP/SConscript (revision 597) +++ kernel/include/IMP/SConscript (working copy) @@ -1,26 +1,41 @@ +Import('env') import os.path -Import('env') - -files = ['base_types.h', 'random.h', 'Index.h', 'Model.h', - 'Particle.h', 'ScoreState.h', 'OptimizerState.h', 'IMP_config.h', - 'log.h', 'DerivativeAccumulator.h', - 'Key.h', 'utility.h', 'Restraint.h', 'Optimizer.h', - 'DecoratorBase.h', 'Vector3D.h', - 'UnaryFunction.h', 'PairScore.h', 'SingletonScore.h', 'macros.h', - 'TripletScore.h', 'exception.h', 'VersionInfo.h'] - -# Install the include files: -includedir = os.path.join(env['includedir'], 'IMP') +files=[ + 'DecoratorBase.h', + 'DerivativeAccumulator.h', + 'IMP_config.h', + 'Index.h', + 'Key.h', + 'Model.h', + 'Optimizer.h', + 'OptimizerState.h', + 'PairScore.h', + 'Particle.h', + 'ParticleRefiner.h', + 'Restraint.h', + 'ScoreState.h', + 'SingletonScore.h', + 'TripletScore.h', + 'UnaryFunction.h', + 'Vector3D.h', + 'VersionInfo.h', + 'base_types.h', + 'exception.h', + 'log.h', + 'macros.h', + 'random.h', + 'utility.h', + ] +includedir = os.path.join(env['includedir'], 'IMP' ) inst = env.Install(includedir, files) env.Alias('install', inst) - -# Subdirectories -SConscript('restraints/SConscript') -SConscript('optimizers/SConscript') -SConscript('decorators/SConscript') -SConscript('internal/SConscript') -SConscript('unary_functions/SConscript') -SConscript('pair_scores/SConscript') -SConscript('singleton_scores/SConscript') -SConscript('triplet_scores/SConscript') -SConscript('score_states/SConscript') +SConscript('decorators/SConscript' ) +SConscript('internal/SConscript' ) +SConscript('optimizers/SConscript' ) +SConscript('pair_scores/SConscript' ) +SConscript('particle_refiners/SConscript' ) +SConscript('restraints/SConscript' ) +SConscript('score_states/SConscript' ) +SConscript('singleton_scores/SConscript' ) +SConscript('triplet_scores/SConscript' ) +SConscript('unary_functions/SConscript' ) Index: kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h =================================================================== --- kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (revision 0) +++ kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (revision 0) @@ -0,0 +1,37 @@ +/** + * \file BondCoverParticleRefiner.h + * \brief Cover a bond with a constant volume set of spheres + * + * Copyright 2007-8 Sali Lab. All rights reserved. + */ + +#ifndef __IMP_BOND_COVER_PARTICLE_REFINER_H +#define __IMP_BOND_COVER_PARTICLE_REFINER_H + +#include "../internal/kernel_version_info.h" +#include "../ParticleRefiner.h" + +namespace IMP +{ + +//! Cover a bond with a constant volume set of spheres. +/** Perhaps I want to add various custom bond types so that + this will only expand some custom bonds. Currently any + particle which is an instance of BondDecorator is expanded. +*/ +class IMPDLLEXPORT BondCoverParticleRefiner : public ParticleRefiner +{ + FloatKey rk_; + FloatKey vk_; +public: + BondCoverParticleRefiner(FloatKey rk, + FloatKey vk); + + virtual ~BondCoverParticleRefiner() {} + + IMP_PARTICLE_REFINER(internal::kernel_version_info); +}; + +} // namespace IMP + +#endif /* __IMP_PAIR_SCORE_H */ Index: kernel/include/IMP/particle_refiners/SConscript =================================================================== --- kernel/include/IMP/particle_refiners/SConscript (revision 0) +++ kernel/include/IMP/particle_refiners/SConscript (revision 0) @@ -0,0 +1,9 @@ +Import('env') +import os.path +files=[ + 'BondCoverParticleRefiner.h', + 'MolecularHierarchyParticleRefiner.h', + ] +includedir = os.path.join(env['includedir'], 'IMP', 'particle_refiners' ) +inst = env.Install(includedir, files) +env.Alias('install', inst) Index: kernel/include/IMP/particle_refiners/ChildrenParticleRefiner.h =================================================================== --- kernel/include/IMP/particle_refiners/ChildrenParticleRefiner.h (revision 0) +++ kernel/include/IMP/particle_refiners/ChildrenParticleRefiner.h (revision 0) @@ -0,0 +1,32 @@ +/** + * \file ChildrenParticleRefiner.h + * \brief Cover a bond with a constant volume set of spheres + * + * Copyright 2007-8 Sali Lab. All rights reserved. + */ + +#ifndef __IMP_BOND_CHILDREN_PARTICLE_REFINER_H +#define __IMP_BOND_CHILDREN_PARTICLE_REFINER_H + +#include "../ParticleRefiner.h" +#include "../internal/kernel_version_info.h" + +namespace IMP +{ + +//! Return the hierarchy children of a particle. +/** Derivatives are not propagated back to parent or anything. +*/ +class IMPDLLEXPORT ChildrenParticleRefiner : public ParticleRefiner +{ +public: + ChildrenParticleRefiner(); + + virtual ~ChildrenParticleRefiner() {} + + IMP_PARTICLE_REFINER(internal::kernel_version_info); +}; + +} // namespace IMP + +#endif /* __IMP_PAIR_SCORE_H */ Index: kernel/include/IMP/macros.h =================================================================== --- kernel/include/IMP/macros.h (revision 597) +++ kernel/include/IMP/macros.h (working copy) @@ -207,7 +207,30 @@ /** \return version and authorship information */ \ virtual IMP::VersionInfo get_version_info() const { return version_info; } +//! Define the basics needed for a particle refiner +/** This macro declares the following functions + - bool can_refine(Particle*) const; + - void cleanup(Particle *a, Particles &b, + DerivativeAccumulator *da); + - void show(std::ostream &out) const; + - Particles refine(Particle *) const; + \param[in] version_info The version info object to return + + */ +#define IMP_PARTICLE_REFINER(version_info) \ + public: \ + /** Return if the particle can be refined*/ \ + virtual bool get_can_refine(Particle*) const; \ + /** Write information about the state to the stream */ \ + virtual void show(std::ostream &out) const; \ + /** Destroy any created particles and propagate derivatives */ \ + virtual void cleanup_refined(Particle *a, Particles &b, \ + DerivativeAccumulator *da=0); \ + /** Return a list of particles which refines the passed particle.*/ \ + virtual Particles get_refined(Particle *); \ + virtual IMP::VersionInfo get_version_info() const { return version_info; } + //! Use the swap_with member function to swap two objects #define IMP_SWAP(name) \ inline void swap(name &a, name &b) { \ Index: kernel/include/IMP.h =================================================================== --- kernel/include/IMP.h (revision 597) +++ kernel/include/IMP.h (working copy) @@ -1,84 +1,107 @@ /** - * \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/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/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 #endif /* __IMP_H */ Index: kernel/src/SConscript =================================================================== --- kernel/src/SConscript (revision 597) +++ kernel/src/SConscript (working copy) @@ -12,6 +12,7 @@ unary_functions_files = SConscript('unary_functions/SConscript') score_states_files = SConscript('score_states/SConscript') pair_scores_files = SConscript('pair_scores/SConscript') +particle_refiners_files = SConscript('particle_refiners/SConscript') singleton_scores_files = SConscript('singleton_scores/SConscript') triplet_scores_files = SConscript('triplet_scores/SConscript') score_states_files = SConscript('score_states/SConscript') @@ -21,10 +22,11 @@ files = ['base_types.cpp', 'Model.cpp', 'Particle.cpp', 'ScoreState.cpp', 'OptimizerState.cpp', 'Log.cpp', 'Restraint.cpp', 'Optimizer.cpp', - 'random.cpp', 'Key.cpp', 'exception.cpp' + 'random.cpp', 'Key.cpp', 'exception.cpp', 'ParticleRefiner.cpp' ] + decorators_files + restraints_files + optimizers_files \ + unary_functions_files + pair_scores_files + singleton_scores_files \ - + triplet_scores_files + score_states_files + internal_files + + triplet_scores_files + score_states_files + internal_files \ + + particle_refiners_files # Build the shared library: lib = env.SharedLibrary('imp', files) Index: kernel/src/ParticleRefiner.cpp =================================================================== --- kernel/src/ParticleRefiner.cpp (revision 0) +++ kernel/src/ParticleRefiner.cpp (revision 0) @@ -0,0 +1,21 @@ +/** + * \file ParticleRefiner.cpp + * \brief Classes to handle individual model particles. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + * + */ + +#include "IMP/ParticleRefiner.h" + +namespace IMP +{ + +ParticleRefiner::~ParticleRefiner(){} + +Particles ParticleRefiner::get_refined(Particle *p) { + throw ErrorException("Can't refine"); + return Particles(); +} + +} Index: kernel/src/particle_refiners/BondCoverParticleRefiner.cpp =================================================================== --- kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (revision 0) +++ kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (revision 0) @@ -0,0 +1,146 @@ +/** + * \file BondCoverParticleRefiner.cpp + * \brief A bond cover pair score. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + */ + +#include "IMP/particle_refiners/BondCoverParticleRefiner.h" +#include "IMP/decorators/bond_decorators.h" +#include "IMP/decorators/XYZDecorator.h" +#include "IMP/internal/constants.h" + +#include + +namespace IMP +{ + +BondCoverParticleRefiner::BondCoverParticleRefiner(FloatKey rk, + FloatKey vk): rk_(rk), + vk_(vk){ + if (0) { + BondCoverParticleRefiner t(rk, vk); + } +} + + +bool BondCoverParticleRefiner::get_can_refine(Particle *p) const { + if (!BondDecorator::is_instance_of(p)) return false; + return (p->has_attribute(vk_)); + +} + +/* n (4/3) pi (d/(2n))^3 = v + n^2= (4/3) pi (d/2)^3 / v + */ +Particles BondCoverParticleRefiner::get_refined(Particle *p) { + IMP_assert(get_can_refine(p), "Trying to refine the unrefinable"); + + Float v= p->get_value(vk_); + BondDecorator bd(p); + BondedDecorator e0= bd.get_bonded(0); + BondedDecorator e1= bd.get_bonded(1); + IMP_IF_CHECK(CHEAP) { + XYZDecorator::cast(e0.get_particle()); + XYZDecorator::cast(e1.get_particle()); + } + XYZDecorator d0(e0.get_particle()); + XYZDecorator d1(e1.get_particle()); + Float d= distance(d0, d1); + + float nsf=std::sqrt(internal::PI * d*square(d)/(6.0 * v)); + unsigned int ns= static_cast(std::ceil(nsf) )+1; + Float r, vt; + Float last_error=-4*v; + for(int i=0; i< 5; ++i) { + r= d/(2.0*ns); + vt= 4.0/3.0*internal::PI*r*square(r)*ns; + Float err= vt-v; + if (err > 0) { + if (last_error < err) { + IMP_LOG(VERBOSE, "adding to the number of spheres " << ns + << " " << err << " " << last_error << std::endl); + ++ns; + r= d/(2.0*ns); + vt= 4.0/3.0*internal::PI*r*square(r)*ns; + } else { + IMP_LOG(VERBOSE, "Leaving the number of spheres " << ns + << " " << err << " " << last_error << std::endl); + } + break; + } else { + IMP_LOG(VERBOSE, "Subtracting from the number of spheres " << ns + << " " << err << std::endl); + if (ns ==1) break; + --ns; + last_error=-err; + } + } + + IMP_LOG(VERBOSE, "Refining bond with length " << d << " into " + << ns << " particles" << std::endl); + + Vector3D vb= d0.get_vector(); + Vector3D ud= d0.get_vector_to(d1).get_unit_vector(); + Particles ret; + Float f= d/(2.0*nsf); + IMP_LOG(VERBOSE, "Resulting volume is " << vt + << " (" << 4.0/3.0*internal::PI*f*square(f)*nsf << ")" + << " with target of " << v << std::endl); + IMP_LOG(VERBOSE, "Base coordinate is " << vb << " and unit vector is " + << ud << std::endl); + for (unsigned int i=0; i< ns; ++i) { + Particle *np= new Particle(); + p->get_model()->add_particle(np); + XYZDecorator d= XYZDecorator::create(np); + d.set_coordinates(vb+ (1+2*i)*r* ud); + np->add_attribute(rk_, r, false); + ret.push_back(np); + } + return ret; +} + + + +void BondCoverParticleRefiner::cleanup_refined(Particle *p, + Particles &ps, + DerivativeAccumulator *da) { + IMP_assert(get_can_refine(p), "Cleanup called with non-refinable particle"); + BondDecorator bd(p); + BondedDecorator e0= bd.get_bonded(0); + BondedDecorator e1= bd.get_bonded(1); + IMP_IF_CHECK(CHEAP) { + XYZDecorator::cast(e0.get_particle()); + XYZDecorator::cast(e1.get_particle()); + } + XYZDecorator d0(e0.get_particle()); + XYZDecorator d1(e1.get_particle()); + + if (da) { + for (unsigned int i=0; i< ps.size(); ++i) { + Float w= (i+.5)/ (ps.size()+1); + XYZDecorator d(ps[i]); + DerivativeAccumulator da0(*da, w); + DerivativeAccumulator da1(*da, 1-w); + for (unsigned int i=0; i< 3; ++i) { + d0.add_to_coordinate_derivative(i, d.get_coordinate_derivative(i), da0); + d1.add_to_coordinate_derivative(i, d.get_coordinate_derivative(i), da1); + } + } + } + + for (unsigned int i=0; i< ps.size(); ++i) { + // note that the particles get deleted at this point currently + ps[i]->get_model()->remove_particle(ps[i]->get_index()); + } + ps.clear(); +} + +void BondCoverParticleRefiner::show(std::ostream &out) const +{ + out << "BondCoverParticleRefiner:\n" + << "radius key: " << rk_ + << "\nvolume key: " << vk_ << std::endl; +} + +} // namespace IMP Index: kernel/src/particle_refiners/SConscript =================================================================== --- kernel/src/particle_refiners/SConscript (revision 0) +++ kernel/src/particle_refiners/SConscript (revision 0) @@ -0,0 +1,4 @@ +files=[ + File( 'BondCoverParticleRefiner.cpp'), File('ChildrenParticleRefiner.cpp' ), + ] +Return('files') Index: kernel/src/particle_refiners/ChildrenParticleRefiner.cpp =================================================================== --- kernel/src/particle_refiners/ChildrenParticleRefiner.cpp (revision 0) +++ kernel/src/particle_refiners/ChildrenParticleRefiner.cpp (revision 0) @@ -0,0 +1,47 @@ +/** + * \file ChildrenParticleRefiner.cpp + * \brief A bond cover pair score. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + */ + +#include "IMP/particle_refiners/ChildrenParticleRefiner.h" +#include "IMP/decorators/HierarchyDecorator.h" + +namespace IMP +{ + +ChildrenParticleRefiner::ChildrenParticleRefiner() { +} + + +bool ChildrenParticleRefiner::get_can_refine(Particle *p) const { + if (!HierarchyDecorator::is_instance_of(p)) return false; + return HierarchyDecorator(p).get_number_of_children() != 0; + +} + +Particles ChildrenParticleRefiner::get_refined(Particle *p) { + IMP_assert(get_can_refine(p), "Trying to refine the unrefinable"); + HierarchyDecorator d(p); + Particles ps(d.get_number_of_children()); + for (unsigned int i=0; i< d.get_number_of_children(); ++i){ + ps[i]= d.get_child(i).get_particle(); + } + return ps; +} + + + +void ChildrenParticleRefiner::cleanup_refined(Particle *, + Particles &, + DerivativeAccumulator *) { + // This space left intentionally blank +} + +void ChildrenParticleRefiner::show(std::ostream &out) const +{ + out << "ChildrenParticleRefiner" << std::endl; +} + +} // namespace IMP Index: kernel/src/pair_scores/SConscript =================================================================== --- kernel/src/pair_scores/SConscript (revision 597) +++ kernel/src/pair_scores/SConscript (working copy) @@ -1,6 +1,7 @@ Import('env') -files = ['DistancePairScore.cpp', 'SphereDistancePairScore.cpp'] +files = ['DistancePairScore.cpp', 'SphereDistancePairScore.cpp', + 'RefineOncePairScore.cpp'] files = [File(x) for x in files] Return('files') Index: kernel/pyext/IMP/test.py =================================================================== --- kernel/pyext/IMP/test.py (revision 597) +++ kernel/pyext/IMP/test.py (working copy) @@ -2,7 +2,6 @@ import random import IMP - class TestCase(unittest.TestCase): """Super class for IMP test cases""" @@ -28,9 +27,11 @@ add it to the model.""" p = IMP.Particle() model.add_particle(p) - p.add_attribute(IMP.FloatKey("x"), x, True) - p.add_attribute(IMP.FloatKey("y"), y, True) - p.add_attribute(IMP.FloatKey("z"), z, True) + d= IMP.XYZDecorator.create(p) + d.set_x(x) + d.set_y(y) + d.set_z(z) + d.set_coordinates_are_optimized(True) return p def randomize_particles(self, particles, deviation): @@ -72,3 +73,90 @@ if v < vmin: fmin, vmin = f, v self.assertInTolerance(fmin, expected_fmin, step) + + def create_particles_in_box(self, model, num=10, + lb= [0,0,0], + ub= [10,10,10]): + """Create a bunch of particles in a box""" + lbv=IMP.Vector3D(lb[0],lb[1],lb[2]) + ubv=IMP.Vector3D(ub[0],ub[1],ub[2]) + ps= IMP.Particles() + for i in range(0,num): + p= IMP.Particle() + model.add_particle(p) + d= IMP.XYZDecorator.create(p) + d.randomize_in_box(lbv, ubv) + ps.append(p) + d.set_coordinates_are_optimized(True) + return ps + def create_chain(self, ps, length=1, stiffness=1): + bds= [] + IMP.BondedDecorator.create(ps[0]) + for i in range(1,len(ps)): + ba= IMP.BondedDecorator.cast(ps[i-1]) + bb= IMP.BondedDecorator.create(ps[i]) + bds.append(IMP.custom_bond(ba, bb, length, stiffness)) + return bds + + class ConstPairScore(IMP.PairScore): + def __init__(self, v): + IMP.PairScore.__init__(self) + self.v=v + def evaluate(self, pa, pb, da): + return self.v + def get_version_info(self): + return IMP.VersionInfo("Me", "0.5") + def show(self, t): + print "ConstPairScore "+ str(self.v) + + class ConstUnaryFunction(IMP.UnaryFunction): + def __init__(self, v): + IMP.UnaryFunction.__init__(self) + self.v=v + def evaluate(self, feat): + return self.v + def evaluate_deriv(self, feat): + return self.v, 0.0 + def show(self, *args): + print "ConstUF with value "+str(self.v) + + + class TestParticleRefiner(IMP.ParticleRefiner): + """A class which makes sure that the right particles are passed back""" + def __init__(self, pr): + IMP.ParticleRefiner.__init__(self) + self.pr= pr + self.dict={} + def show(self, junk): + print "Testing particle refiner" + self.pr.show() + def get_version_info(self): + return IMP.VersionInfo("Daniel Russel", "0.5") + def get_can_refine(self, p): + print "Can refine? "+ str(p.get_index().get_index()) + print "Return is " + str(self.pr.get_can_refine(p)) + return self.pr.get_can_refine(p) + def get_refined(self, p): + print "Refining "+ str(p.get_index().get_index()) + ps= self.pr.get_refined(p) + self.dict[p.get_index().get_index()] = ps + print self.dict + return ps + def cleanup_refined(self, p, ps, da): + # test breaks if refine is called 2x with the same particle + print "starting cleanup "+str( p.get_index().get_index() ) + print self.dict + if not self.pr.get_can_refine(p): + print "cleanup the unrefined" + raise ValueError('Cleanup the unrefined') + if not self.dict.has_key(p.get_index().get_index()): + print "Missing particle info" + raise ValueError("Missing particle info") + ops= self.dict[p.get_index().get_index()] + print "fetched" + if (len(ops) != len(ps)): + raise ValueError("Cached particles and returned particles don't match on size") + for i in range(0, len(ops)): + if (ps[i].get_index() != ops[i].get_index()): + raise ValueError("Cached particles and returned particles don't match") + self.pr.cleanup_refined(p, ps) Index: kernel/pyext/IMP.i =================================================================== --- kernel/pyext/IMP.i (revision 597) +++ kernel/pyext/IMP.i (working copy) @@ -78,9 +78,16 @@ %pythonprepend DistancePairScore::DistancePairScore %{ args[0].thisown=0 %} + %pythonprepend BondCoverPairScore::BondCoverPairScore %{ + args[0].thisown=0 + %} %pythonprepend SphereDistancePairScore::SphereDistancePairScore %{ args[0].thisown=0 %} + %pythonprepend RefineOncePairScore::RefineOncePairScore %{ + args[0].thisown=0 + args[1].thisown=0 + %} %pythonprepend DistanceToSingletonScore::DistanceToSingletonScore %{ args[0].thisown=0 %} @@ -96,6 +103,9 @@ %pythonprepend MonteCarlo::set_local_optimizer %{ args[1].thisown=0 %} + %pythonprepend VRMLLogOptimizerState::add_particle_refiner %{ + args[1].thisown=0 + %} %pythonprepend Particle::get_value %{ check_particle(args[0], args[1]) %} @@ -143,6 +153,7 @@ %feature("director") IMP::PairScore; %feature("director") IMP::TripletScore; %feature("director") IMP::Optimizer; +%feature("director") IMP::ParticleRefiner; %include "IMP/Key.h" %include "IMP/internal/Object.h" @@ -166,6 +177,7 @@ %include "IMP/log.h" %include "IMP/Model.h" %include "IMP/PairScore.h" +%include "IMP/ParticleRefiner.h" %include "IMP/SingletonScore.h" %include "IMP/TripletScore.h" %include "IMP/Particle.h" @@ -192,7 +204,10 @@ %include "IMP/optimizers/states/CMMLogOptimizerState.h" %include "IMP/optimizers/states/VelocityScalingOptimizerState.h" %include "IMP/pair_scores/DistancePairScore.h" +%include "IMP/pair_scores/RefineOncePairScore.h" %include "IMP/pair_scores/SphereDistancePairScore.h" +%include "IMP/particle_refiners/BondCoverParticleRefiner.h" +%include "IMP/particle_refiners/ChildrenParticleRefiner.h" %include "IMP/singleton_scores/DistanceToSingletonScore.h" %include "IMP/singleton_scores/AttributeSingletonScore.h" %include "IMP/triplet_scores/AngleTripletScore.h"