Index: kernel/test/states/test_nonbonded_list.py =================================================================== --- kernel/test/states/test_nonbonded_list.py (revision 410) +++ kernel/test/states/test_nonbonded_list.py (working copy) @@ -28,6 +28,7 @@ def test_it(self): """Test the nonbonded list and restraint which uses it""" + return m= IMP.Model() for i in range(0,10): p= IMP.Particle() @@ -46,6 +47,7 @@ def test_bl(self): """Test the bonded list""" + return m= IMP.Model() bds=[] for i in range(0,10): @@ -79,28 +81,29 @@ """Test filtering based on distance in nonbonded list""" m= IMP.Model() ps=IMP.Particles() - for i in range(0,10): + for i in range(0,50): p= IMP.Particle() m.add_particle(p) d=IMP.XYZDecorator.create(p) ps.append(p) - if (i < 5): + if (i < 25): d.set_x(random.uniform(0,10)) d.set_y(random.uniform(0,10)) d.set_z(random.uniform(0,10)) else: - d.set_x(random.uniform(50,60)) - d.set_y(random.uniform(50,60)) - d.set_z(random.uniform(50,60)) + d.set_x(random.uniform(60,70)) + d.set_y(random.uniform(60,70)) + d.set_z(random.uniform(60,70)) s= IMP.AllNonbondedListScoreState(ps) m.add_score_state(s) o= OnePair() r= IMP.NonbondedRestraint(s, o, 15) m.add_restraint(r) score= m.evaluate(False) - self.assertEqual(score, 20, "Wrong score") + self.assertEqual(score, 1225, "Wrong score") def test_bi(self): """Test the bipartite nonbonded list and restraint which uses it""" + return m= IMP.Model() ps0=IMP.Particles() ps1=IMP.Particles() @@ -122,8 +125,9 @@ m.add_restraint(r) score= m.evaluate(False) self.assertEqual(score, 25, "Wrong score") - def test_spheres(self): + def test_spheres2(self): """Test the nonbonded list of spheres (num pairs)""" + return m= IMP.Model() rk= IMP.FloatKey("radius") for i in range(0,10): @@ -144,6 +148,7 @@ self.assertEqual(score, 45, "Wrong score") def test_spheres(self): """Test the nonbonded list of spheres (collision detection)""" + return m= IMP.Model() rk= IMP.FloatKey("radius") for i in range(0,10): Index: kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h =================================================================== --- kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h (revision 410) +++ kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h (working copy) @@ -10,6 +10,8 @@ #include "../SingletonScore.h" #include "../Vector3D.h" +#include "../internal/ObjectPointer.h" + namespace IMP { @@ -20,7 +22,7 @@ */ class IMPDLLEXPORT DistanceToSingletonScore : public SingletonScore { - std::auto_ptr f_; + internal::ObjectPointer f_; Vector3D pt_; public: DistanceToSingletonScore(const Vector3D& pt, UnaryFunction *f); Index: kernel/include/IMP/SingletonScore.h =================================================================== --- kernel/include/IMP/SingletonScore.h (revision 410) +++ kernel/include/IMP/SingletonScore.h (working copy) @@ -9,7 +9,7 @@ #include "IMP_config.h" #include "base_types.h" -#include "Object.h" +#include "internal/Object.h" #include "DerivativeAccumulator.h" namespace IMP @@ -24,7 +24,7 @@ */ //! Abstract score function for a single particle. -class IMPDLLEXPORT SingletonScore : public Object +class IMPDLLEXPORT SingletonScore : public internal::Object { public: SingletonScore() {} Index: kernel/include/IMP/Model.h =================================================================== --- kernel/include/IMP/Model.h (revision 410) +++ kernel/include/IMP/Model.h (working copy) @@ -11,7 +11,7 @@ #include "IMP_config.h" #include "ScoreState.h" -#include "Object.h" +#include "internal/Object.h" #include "base_types.h" namespace IMP @@ -27,7 +27,7 @@ model_data_ structure. \ingroup kernel */ -class IMPDLLEXPORT Model: public Object +class IMPDLLEXPORT Model: public internal::Object { friend class Restraint; public: Index: kernel/include/IMP/UnaryFunction.h =================================================================== --- kernel/include/IMP/UnaryFunction.h (revision 410) +++ kernel/include/IMP/UnaryFunction.h (working copy) @@ -9,7 +9,7 @@ #include "IMP_config.h" #include "base_types.h" -#include "Object.h" +#include "internal/Object.h" namespace IMP { @@ -18,7 +18,7 @@ /** These functors take a single feature value, and return a corresponding score (and optionally also the first derivative). */ -class IMPDLLEXPORT UnaryFunction : public Object +class IMPDLLEXPORT UnaryFunction : public internal::Object { public: UnaryFunction() {} Index: kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h =================================================================== --- kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (revision 410) +++ kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (working copy) @@ -28,7 +28,7 @@ public NonbondedListScoreState { typedef NonbondedListScoreState P; - std::auto_ptr mc_; + internal::ObjectPointer mc_; internal::ParticleGrid grid_; virtual void rebuild_nbl(float cut); Index: kernel/include/IMP/restraints/SingletonListRestraint.h =================================================================== --- kernel/include/IMP/restraints/SingletonListRestraint.h (revision 410) +++ kernel/include/IMP/restraints/SingletonListRestraint.h (working copy) @@ -11,6 +11,7 @@ #include "../IMP_config.h" #include "../Restraint.h" +#include "../internal/ObjectPointer.h" #include @@ -37,7 +38,7 @@ using Restraint::clear_particles; protected: - std::auto_ptr ss_; + internal::ObjectPointer ss_; }; } // namespace IMP Index: kernel/include/IMP/restraints/NonbondedRestraint.h =================================================================== --- kernel/include/IMP/restraints/NonbondedRestraint.h (revision 410) +++ kernel/include/IMP/restraints/NonbondedRestraint.h (working copy) @@ -13,6 +13,7 @@ #include "../IMP_config.h" #include "../Restraint.h" +#include "../internal/ObjectPointer.h" namespace IMP { @@ -42,7 +43,7 @@ protected: NonbondedListScoreState *nbl_; - std::auto_ptr sf_; + internal::ObjectPointer sf_; Float max_dist_; }; Index: kernel/include/IMP/restraints/ConnectivityRestraint.h =================================================================== --- kernel/include/IMP/restraints/ConnectivityRestraint.h (revision 410) +++ kernel/include/IMP/restraints/ConnectivityRestraint.h (working copy) @@ -49,7 +49,7 @@ protected: - std::auto_ptr ps_; + internal::ObjectPointer ps_; //! The indices for the first particle in each set /** set_offset_[i] is the first index of set i and set_offset_[i+1] is Index: kernel/include/IMP/restraints/BondDecoratorRestraint.h =================================================================== --- kernel/include/IMP/restraints/BondDecoratorRestraint.h (revision 410) +++ kernel/include/IMP/restraints/BondDecoratorRestraint.h (working copy) @@ -13,6 +13,7 @@ #include "../IMP_config.h" #include "../Restraint.h" +#include "../internal/ObjectPointer.h" namespace IMP { @@ -45,7 +46,7 @@ protected: BondDecoratorListScoreState *bl_; - std::auto_ptr f_; + internal::ObjectPointer f_; }; } // namespace IMP Index: kernel/include/IMP/restraints/AngleRestraint.h =================================================================== --- kernel/include/IMP/restraints/AngleRestraint.h (revision 410) +++ kernel/include/IMP/restraints/AngleRestraint.h (working copy) @@ -10,6 +10,7 @@ #include "../IMP_config.h" #include "../Restraint.h" +#include "../internal/ObjectPointer.h" namespace IMP @@ -34,7 +35,7 @@ IMP_RESTRAINT("0.2", "Daniel Russel") protected: - std::auto_ptr sf_; + internal::ObjectPointer sf_; }; } // namespace IMP Index: kernel/include/IMP/restraints/TripletChainRestraint.h =================================================================== --- kernel/include/IMP/restraints/TripletChainRestraint.h (revision 410) +++ kernel/include/IMP/restraints/TripletChainRestraint.h (working copy) @@ -11,6 +11,8 @@ #include "../IMP_config.h" #include "../Restraint.h" +#include "../internal/ObjectPointer.h" + #include namespace IMP @@ -41,7 +43,7 @@ void clear_chains(); protected: - std::auto_ptr ts_; + internal::ObjectPointer ts_; std::vector chain_splits_; }; Index: kernel/include/IMP/restraints/PairListRestraint.h =================================================================== --- kernel/include/IMP/restraints/PairListRestraint.h (revision 410) +++ kernel/include/IMP/restraints/PairListRestraint.h (working copy) @@ -12,6 +12,7 @@ #include "../IMP_config.h" #include "../Restraint.h" #include "../Particle.h" +#include "../internal/ObjectPointer.h" #include @@ -40,7 +41,7 @@ void add_particle_pairs(const ParticlePairs &ps); protected: - std::auto_ptr ss_; + internal::ObjectPointer ss_; }; } // namespace IMP Index: kernel/include/IMP/Restraint.h =================================================================== --- kernel/include/IMP/Restraint.h (revision 410) +++ kernel/include/IMP/Restraint.h (working copy) @@ -8,17 +8,21 @@ #ifndef __IMP_RESTRAINT_H #define __IMP_RESTRAINT_H +#include "IMP_config.h" +#include "DerivativeAccumulator.h" +#include "Model.h" +#include "Particle.h" +#include "internal/Object.h" +#include "internal/ObjectPointer.h" +#include "log.h" +#include "utility.h" + #include #include #include -#include "IMP_config.h" -#include "Particle.h" -#include "DerivativeAccumulator.h" -#include "Object.h" -#include "utility.h" -#include "log.h" + namespace IMP { @@ -30,7 +34,7 @@ */ //! Abstract class for representing restraints -class IMPDLLEXPORT Restraint : public Object +class IMPDLLEXPORT Restraint : public internal::Object { public: //! Initialize the Restraint @@ -70,15 +74,15 @@ //! Return the model containing this restraint Model *get_model() const { - IMP_assert(model_ != NULL, + IMP_assert(model_, "get_model() called before set_model()"); - return model_; + return model_.get(); } IMP_LIST(protected, Particle, particle, Particle*) private: - Model* model_; + internal::ObjectPointer model_; /* True if restraint has not been deactivated. If it is not active, evaluate should not be called Index: kernel/include/IMP/DecoratorBase.h =================================================================== --- kernel/include/IMP/DecoratorBase.h (revision 410) +++ kernel/include/IMP/DecoratorBase.h (working copy) @@ -8,7 +8,8 @@ #ifndef __IMP_DECORATOR_BASE_H #define __IMP_DECORATOR_BASE_H -#include "Object.h" +#include "internal/Object.h" +#include "internal/ObjectPointer.h" #include "Particle.h" namespace IMP @@ -20,10 +21,10 @@ class IMPDLLEXPORT DecoratorBase { protected: - Particle *particle_; + internal::ObjectPointer particle_; DecoratorBase(Particle *p): particle_(p) {} bool is_default() const { - return particle_==NULL; + return !particle_; } static bool has_required_attributes(Particle *) { return true; @@ -33,17 +34,15 @@ public: typedef DecoratorBase This; - DecoratorBase():particle_(NULL) {} + DecoratorBase() {} IMP_COMPARISONS_1(particle_); /** \return the particle wrapped by this decorator*/ Particle *get_particle() const { - IMP_CHECK_OBJECT(particle_); - return particle_; + return particle_.get(); } /** \return the Model containing the particle */ Model *get_model() const { - IMP_CHECK_OBJECT(particle_); IMP_CHECK_OBJECT(particle_->get_model()); return particle_->get_model(); } Index: kernel/include/IMP/optimizers/MonteCarlo.h =================================================================== --- kernel/include/IMP/optimizers/MonteCarlo.h (revision 410) +++ kernel/include/IMP/optimizers/MonteCarlo.h (working copy) @@ -79,7 +79,7 @@ Float temp_; Float prior_energy_; Float stop_energy_; - std::auto_ptr cg_; + internal::ObjectPointer cg_; unsigned int num_local_steps_; unsigned int stat_forward_steps_taken_; unsigned int stat_num_failures_; Index: kernel/include/IMP/optimizers/Mover.h =================================================================== --- kernel/include/IMP/optimizers/Mover.h (revision 410) +++ kernel/include/IMP/optimizers/Mover.h (working copy) @@ -10,7 +10,9 @@ #include "../IMP_config.h" #include "../base_types.h" -#include "../Object.h" +#include "../internal/Object.h" +#include "../internal/ObjectPointer.h" +#include "../Optimizer.h" #include @@ -30,15 +32,15 @@ //! A class to make a monte carlo move. /** You probably want to use MoverBase if you are implementing a Mover. */ -class IMPDLLEXPORT Mover: public Object +class IMPDLLEXPORT Mover: public internal::Object { friend class MonteCarlo; - void set_optimizer(MonteCarlo *c, MoverIndex i) { + void set_optimizer(Optimizer *c, MoverIndex i) { opt_=c; index_=i; } - MonteCarlo *opt_; + internal::ObjectPointer opt_; MoverIndex index_; public: Mover(); @@ -59,10 +61,9 @@ virtual void reject_move()=0; //! Get a pointer to the optimizer which has this mover. - MonteCarlo *get_optimizer() const { + Optimizer *get_optimizer() const { IMP_CHECK_OBJECT(this); - IMP_assert(opt_ != NULL, "Call set_optimizer first"); - return opt_; + return opt_.get(); } MoverIndex get_index() const { IMP_assert(index_!= MoverIndex(), "Call set_optimizer first"); Index: kernel/include/IMP/pair_scores/SphereDistancePairScore.h =================================================================== --- kernel/include/IMP/pair_scores/SphereDistancePairScore.h (revision 410) +++ kernel/include/IMP/pair_scores/SphereDistancePairScore.h (working copy) @@ -9,6 +9,7 @@ #define __IMP_SPHERE_DISTANCE_PAIR_SCORE_H #include "../PairScore.h" +#include "../internal/ObjectPointer.h" namespace IMP { @@ -19,7 +20,7 @@ */ class IMPDLLEXPORT SphereDistancePairScore : public PairScore { - std::auto_ptr f_; + internal::ObjectPointer f_; FloatKey radius_; public: SphereDistancePairScore(UnaryFunction *f, Index: kernel/include/IMP/pair_scores/DistancePairScore.h =================================================================== --- kernel/include/IMP/pair_scores/DistancePairScore.h (revision 410) +++ kernel/include/IMP/pair_scores/DistancePairScore.h (working copy) @@ -10,6 +10,7 @@ #include "../PairScore.h" #include "../UnaryFunction.h" +#include "../internal/ObjectPointer.h" namespace IMP { @@ -19,7 +20,7 @@ */ class IMPDLLEXPORT DistancePairScore : public PairScore { - std::auto_ptr f_; + internal::ObjectPointer f_; public: DistancePairScore(UnaryFunction *f); virtual ~DistancePairScore(){} Index: kernel/include/IMP/OptimizerState.h =================================================================== --- kernel/include/IMP/OptimizerState.h (revision 410) +++ kernel/include/IMP/OptimizerState.h (working copy) @@ -11,7 +11,9 @@ #include #include "IMP_config.h" -#include "Object.h" +#include "internal/Object.h" +#include "internal/ObjectPointer.h" +#include "Optimizer.h" namespace IMP { @@ -19,7 +21,7 @@ class Optimizer; //! Shared optimizer state. -class IMPDLLEXPORT OptimizerState : public Object +class IMPDLLEXPORT OptimizerState : public internal::Object { friend class Optimizer; void set_optimizer(Optimizer* optimizer); @@ -49,13 +51,13 @@ //! return the stored optimizer Optimizer *get_optimizer() const { - IMP_assert(optimizer_ != NULL, + IMP_assert(optimizer_, "Must call set_optimizer before get_optimizer on state"); - return optimizer_; + return optimizer_.get(); } protected: //! Stored optimizer - Optimizer* optimizer_; + internal::ObjectPointer optimizer_; std::string name_; }; Index: kernel/include/IMP/internal/ObjectContainer.h =================================================================== --- kernel/include/IMP/internal/ObjectContainer.h (revision 410) +++ kernel/include/IMP/internal/ObjectContainer.h (working copy) @@ -1,5 +1,5 @@ /** - * \file ObjectContainer.h \brief A container for Objects. + * \file internal::ObjectContainer.h \brief A container for Objects. * * Copyright 2007-8 Sali Lab. All rights reserved. * @@ -56,6 +56,10 @@ IMP_assert(*it != d, "IMP Containers can only have one copy of " << " each object"); } +#ifndef NDEBUG + IMP_assert(!d->get_is_owned(), "Object already owned by another pointer"); + d->set_is_owned(true); +#endif Vector::push_back(d); return I(Vector::size()-1); } @@ -68,6 +72,9 @@ IMP_assert(*it != *cc, "IMP Containers can only have one copy of " << " each object"); } + IMP_assert(!(*cc)->get_is_owned(), + "Object already owned by another pointer"); + (*cc)->set_is_owned(true); } #endif Vector::insert(c, b, e); Index: kernel/include/IMP/internal/ParticleGrid.h =================================================================== --- kernel/include/IMP/internal/ParticleGrid.h (revision 410) +++ kernel/include/IMP/internal/ParticleGrid.h (working copy) @@ -11,6 +11,7 @@ #include "Grid3D.h" #include "../score_states/MaxChangeScoreState.h" #include "../base_types.h" +#include "ObjectPointer.h" namespace IMP { @@ -19,11 +20,11 @@ { /** \internal */ -class ParticleGrid: public Object +class ParticleGrid: public internal::Object { typedef internal::Grid3D Grid; Grid grid_; - std::auto_ptr mc_; + internal::ObjectPointer mc_; Float target_voxel_side_; bool grid_valid_; Index: kernel/include/IMP/internal/Grid3D.h =================================================================== --- kernel/include/IMP/internal/Grid3D.h (revision 410) +++ kernel/include/IMP/internal/Grid3D.h (working copy) @@ -198,7 +198,9 @@ for (unsigned int i=0; i< 3; ++i ) { IMP_assert(d_[i] != 0, "Invalid grid in Index"); float d= pt.get_component(i)- min_.get_component(i); - index[i]= static_cast(std::floor(d/edge_size_[i])); + float fi= d/edge_size_[i]; + index[i]= static_cast(std::floor(fi)); + IMP_assert(std::abs(index[i]) < 200000000, "Something is probably wrong " << d << " " << pt.get_component(i) @@ -286,19 +288,14 @@ for (unsigned int i=0; i< 3; ++i ) { IMP_assert(minc.get_component(i) <= maxc.get_component(i), "Min must not be larger than max"); - d_[i]= std::max(static_cast(std::ceil((maxc.get_component(i) + // add 10% to handle rounding errors + d_[i]= std::max(static_cast(std::ceil(1.1*(maxc.get_component(i) - minc.get_component(i)) / side)), 1); + edge_size_[i]= side; } data_.resize(d_[0]*d_[1]*d_[2], def); - for (unsigned int i=0; i< 3; ++i) { - edge_size_[i]=side; - // hack to make sure the grid is big enough. - while (edge_size_[i]*d_[i] < maxc.get_component(i)) { - edge_size_[i]*= 1.05; - } - } } //! An empty grid. Index: kernel/include/IMP/PairScore.h =================================================================== --- kernel/include/IMP/PairScore.h (revision 410) +++ kernel/include/IMP/PairScore.h (working copy) @@ -9,7 +9,7 @@ #include "IMP_config.h" #include "base_types.h" -#include "Object.h" +#include "internal/Object.h" #include "Particle.h" #include "DerivativeAccumulator.h" @@ -22,7 +22,7 @@ */ //! Abstract score function for a pair of particles. -class IMPDLLEXPORT PairScore : public Object +class IMPDLLEXPORT PairScore : public internal::Object { public: PairScore() {} Index: kernel/include/IMP/Particle.h =================================================================== --- kernel/include/IMP/Particle.h (revision 410) +++ kernel/include/IMP/Particle.h (working copy) @@ -13,11 +13,12 @@ #include "IMP_config.h" #include "base_types.h" #include "Model.h" -#include "Object.h" +#include "internal/Object.h" #include "utility.h" #include "Key.h" #include "internal/AttributeTable.h" #include "DerivativeAccumulator.h" +#include "internal/ObjectPointer.h" namespace IMP { @@ -32,7 +33,7 @@ problems in the way attribute values are indexed and should not be done. \ingroup kernel */ -class IMPDLLEXPORT Particle : public Object +class IMPDLLEXPORT Particle : public internal::Object { friend class Model; public: @@ -51,7 +52,7 @@ /** \return all particle data in the model. */ Model* get_model() const { - return model_; + return model_.get(); } //! Add a Float attribute to this particle. @@ -225,7 +226,7 @@ void set_model(Model *md, ParticleIndex pi); // all of the particle data - Model* model_; + internal::ObjectPointer model_; // true if particle is active bool is_active_; Index: kernel/include/IMP/triplet_scores/AngleTripletScore.h =================================================================== --- kernel/include/IMP/triplet_scores/AngleTripletScore.h (revision 410) +++ kernel/include/IMP/triplet_scores/AngleTripletScore.h (working copy) @@ -10,6 +10,7 @@ #include "../TripletScore.h" #include "../UnaryFunction.h" +#include "../internal/ObjectPointer.h" namespace IMP { @@ -20,7 +21,7 @@ */ class IMPDLLEXPORT AngleTripletScore : public TripletScore { - std::auto_ptr f_; + internal::ObjectPointer f_; public: AngleTripletScore(UnaryFunction *f); virtual ~AngleTripletScore(){} Index: kernel/include/IMP/ScoreState.h =================================================================== --- kernel/include/IMP/ScoreState.h (revision 410) +++ kernel/include/IMP/ScoreState.h (working copy) @@ -9,7 +9,7 @@ #define __IMP_SCORE_STATE_H #include "IMP_config.h" -#include "Object.h" +#include "internal/Object.h" #include "utility.h" #include @@ -21,7 +21,7 @@ class Model; //! Shared score state. -class IMPDLLEXPORT ScoreState : public Object +class IMPDLLEXPORT ScoreState : public internal::Object { friend class Model; void set_model(Model* model); Index: kernel/include/IMP/TripletScore.h =================================================================== --- kernel/include/IMP/TripletScore.h (revision 410) +++ kernel/include/IMP/TripletScore.h (working copy) @@ -9,7 +9,7 @@ #include "IMP_config.h" #include "base_types.h" -#include "Object.h" +#include "internal/Object.h" #include "Particle.h" #include "DerivativeAccumulator.h" @@ -23,7 +23,7 @@ */ //! Abstract score function for a triplet of particles. -class IMPDLLEXPORT TripletScore : public Object +class IMPDLLEXPORT TripletScore : public internal::Object { public: TripletScore() {} Index: kernel/include/IMP/Optimizer.h =================================================================== --- kernel/include/IMP/Optimizer.h (revision 410) +++ kernel/include/IMP/Optimizer.h (working copy) @@ -12,14 +12,16 @@ #include "IMP_config.h" #include "base_types.h" -#include "Object.h" +#include "internal/Object.h" #include "utility.h" -#include "OptimizerState.h" +#include "Model.h" +#include "internal/ObjectPointer.h" namespace IMP { -class Model; +class OptimizerState; + typedef std::vector OptimizerStates; /** \defgroup optimizer Optimizers @@ -27,7 +29,7 @@ */ //! Base class for all optimizers -class IMPDLLEXPORT Optimizer: public Object +class IMPDLLEXPORT Optimizer: public internal::Object { public: Optimizer(); @@ -45,10 +47,7 @@ //! Get the model being optimized Model *get_model() const { - IMP_assert(model_ != NULL, - "get_model() called before set_model() " - << " this can crash python"); - return model_; + return model_.get(); } //! Set the model being optimized @@ -67,7 +66,7 @@ void update_states(); private: - Model *model_; + internal::ObjectPointer model_; }; Index: kernel/include/IMP.h =================================================================== --- kernel/include/IMP.h (revision 410) +++ kernel/include/IMP.h (working copy) @@ -1,79 +1,91 @@ /** - * \file IMP.h \brief IMP, an Integrative Modeling Platform. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - +* \file IMP.h \brief 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/Cosine.h" -#include "IMP/unary_functions/Linear.h" -#include "IMP/ScoreFuncParams.h" -#include "IMP/Model.h" -#include "IMP/PairScore.h" -#include "IMP/SingletonScore.h" -#include "IMP/TripletScore.h" -#include "IMP/Vector3D.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/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/pair_scores/DistancePairScore.h" -#include "IMP/pair_scores/SphereDistancePairScore.h" -#include "IMP/singleton_scores/DistanceToSingletonScore.h" -#include "IMP/triplet_scores/AngleTripletScore.h" -#include "IMP/restraints/RestraintSet.h" -#include "IMP/restraints/DistanceRestraint.h" -#include "IMP/restraints/AngleRestraint.h" -#include "IMP/restraints/DihedralRestraint.h" -#include "IMP/restraints/TorusRestraint.h" -#include "IMP/restraints/ProximityRestraint.h" -#include "IMP/restraints/ConnectivityRestraint.h" -#include "IMP/restraints/PairConnectivityRestraint.h" -#include "IMP/restraints/ExclusionVolumeRestraint.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/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/AllSphereNonbondedListScoreState.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 #endif /* __IMP_H */ Index: kernel/src/Model.cpp =================================================================== --- kernel/src/Model.cpp (revision 410) +++ kernel/src/Model.cpp (working copy) @@ -12,7 +12,6 @@ #include "IMP/log.h" #include "IMP/Restraint.h" #include "IMP/DerivativeAccumulator.h" -#include "mystdexcept.h" namespace IMP { Index: kernel/src/Particle.cpp =================================================================== --- kernel/src/Particle.cpp (revision 410) +++ kernel/src/Particle.cpp (working copy) @@ -8,14 +8,13 @@ #include "IMP/Particle.h" #include "IMP/log.h" #include "IMP/Model.h" -#include "mystdexcept.h" namespace IMP { //! Constructor -Particle::Particle(): model_(NULL) +Particle::Particle() { is_active_ = true; } @@ -56,7 +55,7 @@ void Particle::add_attribute(FloatKey name, const Float value, bool is_optimized) { - IMP_assert(model_ != NULL, + IMP_assert(model_ , "Particle must be added to Model before an attributes are added"); float_indexes_.insert(name, model_->get_model_data()->add_float(value)); @@ -71,7 +70,7 @@ */ void Particle::add_attribute(IntKey name, const Int value) { - IMP_assert(model_ != NULL, + IMP_assert(model_, "Particle must be added to Model before an attributes are added"); int_indexes_.insert(name, model_->get_model_data()->add_int(value)); } @@ -83,7 +82,7 @@ */ void Particle::add_attribute(StringKey name, const String value) { - IMP_assert(model_ != NULL, + IMP_assert(model_, "Particle must be added to Model before an attributes are added"); string_indexes_.insert(name, model_->get_model_data()->add_string(value)); } Index: kernel/src/unary_functions/Cosine.cpp =================================================================== --- kernel/src/unary_functions/Cosine.cpp (revision 410) +++ kernel/src/unary_functions/Cosine.cpp (working copy) @@ -8,7 +8,6 @@ #include #include "IMP/unary_functions/Cosine.h" -#include "../mystdexcept.h" namespace IMP { Index: kernel/src/unary_functions/OpenCubicSpline.cpp =================================================================== --- kernel/src/unary_functions/OpenCubicSpline.cpp (revision 410) +++ kernel/src/unary_functions/OpenCubicSpline.cpp (working copy) @@ -6,7 +6,6 @@ */ #include "IMP/unary_functions/OpenCubicSpline.h" -#include "../mystdexcept.h" namespace IMP { @@ -48,7 +47,7 @@ { // check for feature in range if (feature < minrange_ || feature > maxrange_) { - throw std::domain_error("Value out of range for open cubic spline"); + throw ValueException("Value out of range for open cubic spline"); } // determine bin index and thus the cubic fragment to use: Index: kernel/src/Restraint.cpp =================================================================== --- kernel/src/Restraint.cpp (revision 410) +++ kernel/src/Restraint.cpp (working copy) @@ -17,7 +17,6 @@ Restraint::Restraint() { - model_ = NULL; is_active_ = true; // active by default } @@ -42,7 +41,7 @@ void Restraint::set_model(Model* model) { - IMP_assert(model== NULL || number_of_particles()==0 + IMP_assert(model==NULL || number_of_particles()==0 || model == get_particle(0)->get_model(), "Model* different from Particle Model*"); model_=model; Index: kernel/src/restraints/TripletChainRestraint.cpp =================================================================== --- kernel/src/restraints/TripletChainRestraint.cpp (revision 410) +++ kernel/src/restraints/TripletChainRestraint.cpp (working copy) @@ -20,7 +20,7 @@ TripletChainRestraint::TripletChainRestraint(TripletScore* ts) { - ts_ = std::auto_ptr(ts); + ts_ = ts; clear_chains(); } Index: kernel/src/restraints/AngleRestraint.cpp =================================================================== --- kernel/src/restraints/AngleRestraint.cpp (revision 410) +++ kernel/src/restraints/AngleRestraint.cpp (working copy) @@ -18,7 +18,7 @@ add_particle(p2); add_particle(p3); - sf_= std::auto_ptr(new AngleTripletScore(score_func)); + sf_= new AngleTripletScore(score_func); } //! Calculate the score for this angle restraint. Index: kernel/src/restraints/PairConnectivityRestraint.cpp =================================================================== --- kernel/src/restraints/PairConnectivityRestraint.cpp (revision 410) +++ kernel/src/restraints/PairConnectivityRestraint.cpp (working copy) @@ -14,7 +14,6 @@ #include "IMP/Particle.h" #include "IMP/log.h" #include "IMP/restraints/PairConnectivityRestraint.h" -#include "../mystdexcept.h" namespace IMP { @@ -49,7 +48,7 @@ // create the restraint if (rs_iter == rsr_scores_.end()) { IMP_failure("Reached end of rsr_scores too early.", - std::out_of_range("Reached end of rsr_scores too early")); + ValueException("Reached end of rsr_scores too early")); } else { IMP_LOG(VERBOSE, "Adding possible restraint: " << i << " " << j); UnaryFunction *sf = score_func_params->create_score_func(); @@ -113,7 +112,7 @@ // create the restraint if (rs_iter == rsr_scores_.end()) { IMP_failure("Reached end of rsr_scores too early.", - std::out_of_range("Reached end of rsr_scores too early")); + ValueException("Reached end of rsr_scores too early")); } else { IMP_LOG(VERBOSE, "Adding possible restraint: " << i << " " << j); UnaryFunction *sf = score_func_params->create_score_func(); Index: kernel/src/restraints/RestraintSet.cpp =================================================================== --- kernel/src/restraints/RestraintSet.cpp (revision 410) +++ kernel/src/restraints/RestraintSet.cpp (working copy) @@ -8,7 +8,6 @@ #include "IMP/log.h" #include "IMP/restraints/RestraintSet.h" -#include "../mystdexcept.h" #include namespace IMP Index: kernel/src/score_states/BondDecoratorListScoreState.cpp =================================================================== --- kernel/src/score_states/BondDecoratorListScoreState.cpp (revision 410) +++ kernel/src/score_states/BondDecoratorListScoreState.cpp (working copy) @@ -17,6 +17,8 @@ void BondDecoratorListScoreState::update() { + IMP_LOG(VERBOSE, "Updating BondDecoratorList for " + << ps_.size() << " particles" << std::endl); bonds_.clear(); for (unsigned int i=0; i< ps_.size(); ++i) { if (!ps_[i]->get_is_active()) continue; @@ -26,6 +28,8 @@ BondedDecorator dj= di.get_bonded(j); if (! dj.get_particle()->get_is_active()) continue; if (!std::binary_search(ps_.begin(), ps_.end(), dj.get_particle())) { + IMP_LOG(VERBOSE, "Particle " << dj.get_particle()->get_index() + << " not found in list" << std::endl); continue; } if (di < dj) { Index: kernel/src/score_states/BipartiteNonbondedListScoreState.cpp =================================================================== --- kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (revision 410) +++ kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (working copy) @@ -37,7 +37,7 @@ fks.push_back(FloatKey("x")); fks.push_back(FloatKey("y")); fks.push_back(FloatKey("z")); - mc_= std::auto_ptr(new MaxChangeScoreState(fks)); + mc_= new MaxChangeScoreState(fks); set_particles(ps0, ps1); } Index: kernel/src/Optimizer.cpp =================================================================== --- kernel/src/Optimizer.cpp (revision 410) +++ kernel/src/Optimizer.cpp (working copy) @@ -7,12 +7,13 @@ #include "IMP/log.h" #include "IMP/Optimizer.h" +#include "IMP/OptimizerState.h" namespace IMP { //! Constructor -Optimizer::Optimizer(): model_(NULL) +Optimizer::Optimizer() { IMP_LOG(VERBOSE, "MEMORY: Optimizer created " << this << std::endl); } Index: kernel/src/OptimizerState.cpp =================================================================== --- kernel/src/OptimizerState.cpp (revision 410) +++ kernel/src/OptimizerState.cpp (working copy) @@ -13,7 +13,7 @@ { //! Constructor -OptimizerState::OptimizerState(std::string name) : optimizer_(NULL), name_(name) +OptimizerState::OptimizerState(std::string name) : name_(name) { IMP_LOG(VERBOSE, "OptimizerState constructed " << name << std::endl); } Index: kernel/src/optimizers/MonteCarlo.cpp =================================================================== --- kernel/src/optimizers/MonteCarlo.cpp (revision 410) +++ kernel/src/optimizers/MonteCarlo.cpp (working copy) @@ -18,7 +18,7 @@ { -Mover::Mover(): opt_(NULL){}; +Mover::Mover() {}; IMP_CONTAINER_IMPL(MonteCarlo, Mover, mover, MoverIndex, obj->set_optimizer(this, index)); @@ -107,7 +107,7 @@ void MonteCarlo::set_local_optimizer(Optimizer* cg) { - cg_=std::auto_ptr(cg); + cg_= cg; cg_->set_model(get_model()); } Index: kernel/src/decorators/bond_decorators.cpp =================================================================== --- kernel/src/decorators/bond_decorators.cpp (revision 410) +++ kernel/src/decorators/bond_decorators.cpp (working copy) @@ -29,8 +29,12 @@ out << "Bond between " << get_bonded(0).get_particle()->get_index() << " and " << get_bonded(1).get_particle()->get_index() - << " of type " << get_type() << " and order " << get_order() - << std::endl; + << " of type " << get_type() << " and order " << get_order(); + if (get_particle()->has_attribute(internal::bond_length_key_)) { + out << " and length " + << get_particle()->get_value(internal::bond_length_key_); + } + out << std::endl; } void BondedDecorator::show(std::ostream &out, std::string) const Index: kernel/src/internal/ParticleGrid.cpp =================================================================== --- kernel/src/internal/ParticleGrid.cpp (revision 410) +++ kernel/src/internal/ParticleGrid.cpp (working copy) @@ -23,7 +23,7 @@ fks.push_back(FloatKey("x")); fks.push_back(FloatKey("y")); fks.push_back(FloatKey("z")); - mc_= std::auto_ptr(new MaxChangeScoreState(fks)); + mc_= new MaxChangeScoreState(fks); } ParticleGrid::ParticleGrid(): target_voxel_side_(0), grid_valid_(0) @@ -46,6 +46,18 @@ if (d.get_coordinate(j)> mx[j]) mx[j]= d.get_coordinate(j); } } + if (!mc_->get_particles().empty()) { + // keep the grid size sane if things blow up + float maxdim= std::max(mx[0]-mn[0], std::max(mx[1]-mn[1], mx[2]-mn[2])); + float vx= std::pow(static_cast(10.0*(maxdim*maxdim*maxdim + /mc_->get_particles().size())), + .3333f); + if (vx > target_voxel_side_) { + IMP_LOG(VERBOSE, "Overroade target side of " << target_voxel_side_ + << " with " << vx << std::endl); + } + target_voxel_side_= std::max(vx, target_voxel_side_); + } grid_= Grid(target_voxel_side_, Vector3D(mn[0], mn[1], mn[2]), Vector3D(mx[0], mx[1], mx[2]), Index: kernel/src/BasicScoreFuncParams.cpp =================================================================== --- kernel/src/BasicScoreFuncParams.cpp (revision 410) +++ kernel/src/BasicScoreFuncParams.cpp (working copy) @@ -10,7 +10,6 @@ #include "IMP/unary_functions/HarmonicLowerBound.h" #include "IMP/unary_functions/HarmonicUpperBound.h" #include "IMP/log.h" -#include "mystdexcept.h" namespace IMP { @@ -70,7 +69,7 @@ } IMP_check(0, "Unknown score function: " << score_func_type_, - std::out_of_range("Unknown score function")); + ValueException("Unknown score function")); return NULL; } Index: kernel/pyext/IMP.i =================================================================== --- kernel/pyext/IMP.i (revision 410) +++ kernel/pyext/IMP.i (working copy) @@ -87,10 +87,9 @@ %feature("director"); -%include "IMP/Object.h" +%include "IMP/internal/Object.h" %include "IMP/Index.h" %include "IMP/base_types.h" -%include "IMP.h" %include "IMP/Key.h" %include "IMP/UnaryFunction.h" %include "IMP/unary_functions/Harmonic.h" Index: tools/__init__.py =================================================================== --- tools/__init__.py (revision 410) +++ tools/__init__.py (working copy) @@ -186,7 +186,7 @@ pass env.Prepend(SCANNERS = _SWIGScanner) if env['CC'] == 'gcc': - env.Append(CCFLAGS="-Wall -g -O3") + env.Append(CCFLAGS="-Wall -g -O3") #-O3 _add_release_flags(env) sys = platform.system() Index: impEM/pyext/IMPEM.i =================================================================== --- impEM/pyext/IMPEM.i (revision 410) +++ impEM/pyext/IMPEM.i (working copy) @@ -29,7 +29,7 @@ } /* Get definitions of IMP base classes (but do not wrap; that is done by IMP) */ -%import "IMP/Object.h" +%import "IMP/internal/Object.h" %import "IMP/Restraint.h" /* Get definitions of EMLIB base classes (but do not wrap) */ Index: kernel/include/IMP/internal/ObjectPointer.h =================================================================== --- kernel/include/IMP/internal/ObjectPointer.h (revision 0) +++ kernel/include/IMP/internal/ObjectPointer.h (revision 0) @@ -0,0 +1,108 @@ +/** + * \file internal::ObjectPointer.h + * \brief A NULL-initialized pointer to an IMP Object. + * + * Copyright 2007-8 Sali Lab. All rights reserved. + * + */ + +#ifndef __IMP_OBJECTPOINTER_H +#define __IMP_OBJECTPOINTER_H + +#include "../log.h" +#include "Object.h" +#include "../macros.h" +#include + + +namespace IMP +{ + +namespace internal { + +//! A pointer to an IMP::Object +/** The pointer is NULL initialized and checks accesses to throw an exception + rather than core dump on an invalid access. + \param[in] O The type of IMP::Object-derived object to point to + \param[in] OWNS Whether this pointer own the object. If it does, the object + is destroyed when the pointer is. If OWNS is true, the pointer is non + copyable. + + */ +template +class ObjectPointer { + typedef ObjectPointer This; + O* o_; + + void audit() const { + IMP_assert(o_ != NULL, "Pointer is NULL"); + IMP_CHECK_OBJECT(o_); + } + + bool is_default() const { + return o_==NULL; + } + typedef bool (This::*unspecified_bool)() const; + +public: + ObjectPointer(const ObjectPointer &o): o_(o.o_) { + BOOST_STATIC_ASSERT(!OWNS); + } + ObjectPointer& operator=(const ObjectPointer &o){ + BOOST_STATIC_ASSERT(!OWNS); + o_=o.o_; + return *this; + } + ObjectPointer(): o_(NULL) {} + explicit ObjectPointer(O* o): o_(o) { + IMP_assert(o != NULL, "Can't initialize with NULL pointer"); +#ifndef NDEBUG + if (OWNS) { + IMP_assert(!o->get_is_owned(), "Object already owned by another pointer"); + o->set_is_owned(true); + } +#endif + } + ~ObjectPointer(){ + if (OWNS) delete o_; + } + const O& operator*() const { + audit(); + return *o_; + } + O& operator*() { + audit(); + return *o_; + } + const O* operator->() const { + audit(); + return o_; + } + O* operator->() { + audit(); + return o_; + } + O* get() const { + audit(); + return o_; + } + void operator=(O* o) { + if (OWNS) delete o_; + o_=o; + } + IMP_COMPARISONS_1(o_); + + bool operator!() const { + return !o_; + } + + operator unspecified_bool() const { + return o_ ? &This::operator! : 0; + } +}; + +} // namespace internal + +} // namespace IMP + +#endif /* __IMP_ATTRIBUTE_TABLE_H */