Index: include/IMP/ModelData.h =================================================================== --- include/IMP/ModelData.h (revision 650) +++ include/IMP/ModelData.h (working copy) @@ -79,6 +79,8 @@ \return value of particle float attribute. */ Float get_value(const FloatIndex idx) const { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range index requested"); return float_data_[idx.get_index()].value_; } @@ -122,6 +124,8 @@ \return value of particle float attribute. */ Int get_value(const IntIndex idx) const { + IMP_assert(idx.get_index() < int_data_.size(), + "Out of range int requested"); return int_data_[idx.get_index()]; } @@ -144,6 +148,8 @@ \return value of particle string attribute. */ String get_value(const StringIndex idx) const { + IMP_assert(idx.get_index() < string_data_.size(), + "Out of range string requested"); return string_data_[idx.get_index()]; } Index: include/IMP/boost/noncopyable.h =================================================================== --- include/IMP/boost/noncopyable.h (revision 650) +++ include/IMP/boost/noncopyable.h (working copy) @@ -1,36 +0,0 @@ -// Boost noncopyable.hpp header file --------------------------------------// - -// (C) Copyright Beman Dawes 1999-2003. Distributed under the Boost -// Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/utility for documentation. - -#ifndef BOOST_NONCOPYABLE_HPP_INCLUDED -#define BOOST_NONCOPYABLE_HPP_INCLUDED -namespace IMP { -namespace boost { - -// Private copy constructor and copy assignment ensure classes derived from -// class noncopyable cannot be copied. - -// Contributed by Dave Abrahams - -namespace noncopyable_ // protection from unintended ADL -{ - class noncopyable - { - protected: - noncopyable() {} - ~noncopyable() {} - private: // emphasize the following members are private - noncopyable( const noncopyable& ); - const noncopyable& operator=( const noncopyable& ); - }; -} - -typedef noncopyable_::noncopyable noncopyable; - -} // namespace boost -} // namespace IMP -#endif // BOOST_NONCOPYABLE_HPP_INCLUDED Index: include/IMP/boost/SConscript =================================================================== --- include/IMP/boost/SConscript (revision 650) +++ include/IMP/boost/SConscript (working copy) @@ -1,10 +0,0 @@ -import os.path -Import('env') - -files = ['noncopyable.h'] - - -# Install the include files: -includedir = os.path.join(env['includedir'], 'IMP', 'boost') -inst = env.Install(includedir, files) -env.Alias('install', inst) Index: include/IMP/Model.h =================================================================== --- include/IMP/Model.h (revision 650) +++ include/IMP/Model.h (working copy) @@ -13,7 +13,7 @@ #include "ModelData.h" #include "RigidBody.h" #include "State.h" -#include "boost/noncopyable.h" +#include "Object.h" namespace IMP { @@ -25,7 +25,7 @@ /** All attribute data for particles is stored through indexing in the model_data_ structure. */ -class IMPDLLEXPORT Model: public boost::noncopyable +class IMPDLLEXPORT Model: public Object { friend class Restraint; public: Index: include/IMP/SConscript =================================================================== --- include/IMP/SConscript (revision 650) +++ include/IMP/SConscript (working copy) @@ -4,7 +4,8 @@ files = ['base_types.h', 'Index.h', 'ScoreFunc.h', 'Model.h', 'Particle.h', 'State.h', 'IMP_config.h', 'ModelData.h', 'RigidBody.h', 'log.h', 'DerivativeAccumulator.h', 'Key.h', 'AttributeTable.h', - 'utility.h', 'Restraint.h', 'Optimizer.h', 'DecoratorBase.h'] + 'utility.h', 'Restraint.h', 'Optimizer.h', 'DecoratorBase.h', + 'Object.h'] # Install the include files: includedir = os.path.join(env['includedir'], 'IMP') @@ -15,4 +16,3 @@ SConscript('restraints/SConscript') SConscript('optimizers/SConscript') SConscript('decorators/SConscript') -SConscript('boost/SConscript') Index: include/IMP/Particle.h =================================================================== --- include/IMP/Particle.h (revision 650) +++ include/IMP/Particle.h (working copy) @@ -14,7 +14,7 @@ #include "base_types.h" #include "Model.h" #include "Restraint.h" -#include "boost/noncopyable.h" +#include "Object.h" #include "utility.h" #include "Key.h" #include "AttributeTable.h" @@ -32,7 +32,7 @@ optimization. Removing particles and their attributes would cause problems in the way attribute values are indexed and should not be done. */ -class IMPDLLEXPORT Particle : public boost::noncopyable +class IMPDLLEXPORT Particle : public Object { friend class Model; public: Index: include/IMP/utility.h =================================================================== --- include/IMP/utility.h (revision 650) +++ include/IMP/utility.h (working copy) @@ -169,13 +169,16 @@ IndexType index(lcname##_vector_.size()); \ lcname##_vector_.push_back(obj); \ init; \ + IMP_CHECK_OBJECT(obj); \ return index; \ } \ Ucname *Class::get_##lcname(IndexType i) const { \ IMP_check(i.get_index() < lcname##_vector_.size(), \ "Index " << i << " out of range", \ IndexException(#Ucname)); \ - return lcname##_vector_[i.get_index()]; \ + Ucname *r= lcname##_vector_[i.get_index()]; \ + IMP_CHECK_OBJECT(r); \ + return r; \ } \ @@ -193,6 +196,8 @@ } \ lcname##_vector_.clear(); +//! Call the assert_is_valid method in the object base +#define IMP_CHECK_OBJECT(obj) (obj)->assert_is_valid() namespace IMP { //! Compute the square of a number Index: include/IMP/Object.h =================================================================== --- include/IMP/Object.h (revision 0) +++ include/IMP/Object.h (revision 0) @@ -0,0 +1,39 @@ +/** + * \file Object.h + * \brief A shared base class to help in debugging and things. + * + * Copyright 2007 Sali Lab. All rights reserved. + * + */ + +#ifndef __IMP_OBJECT_H +#define __IMP_OBJECT_H +#include + +namespace IMP { +/** + Currently this just makes the object noncopyable and adds heuristic checks + to make sure the memory has not been freed. + + \note Do not use NDEBUG to remove check_value_ as that changes the memory + layout and causes bad things to happen. It should get wrapped in some + sort of marco later. + */ +class IMPDLLEXPORT Object { +protected: + Object(); + ~Object(); + +public: + //! Throw an assertion if the object has been freed + void assert_is_valid() const; + +private: + Object(const Object &o){} + const Object& operator=(const Object &o) {return *this;} + + double check_value_; +}; + +} +#endif Index: include/IMP/Restraint.h =================================================================== --- include/IMP/Restraint.h (revision 650) +++ include/IMP/Restraint.h (working copy) @@ -17,7 +17,7 @@ #include "ScoreFunc.h" #include "Particle.h" #include "DerivativeAccumulator.h" -#include "boost/noncopyable.h" +#include "Object.h" #include "utility.h" #include "log.h" @@ -27,7 +27,7 @@ class Model; //! Abstract class for representing restraints -class IMPDLLEXPORT Restraint : public boost::noncopyable +class IMPDLLEXPORT Restraint : public Object { public: //! Initialize the Restraint and its model pointer @@ -76,14 +76,6 @@ name_=name; } - Particle *get_particle(unsigned int i) const; - - int add_particle(Particle *p) { - IMP_assert(p != NULL, "Can't add NULL particle"); - particles_.push_back(p); - return particles_.size()-1; - } - //! The model the restraint is part of. /** \param[in] model The model. */ @@ -98,11 +90,30 @@ return model_; } + protected: + Particle *get_particle(unsigned int i) const; + + int add_particle(Particle *p) { + IMP_assert(p != NULL, "Can't add NULL particle"); + particles_.push_back(p); + return particles_.size()-1; + } + //! Return the number of particles this restraint knows about unsigned int number_of_particles() const { return particles_.size(); } + //! Clear the internal list of particles + void clear_particles() { + return particles_.clear(); + } + + //! Replace the set of particles used by the restraint + void set_particles(const Particles &ps) { + particles_= ps; + } + private: //! all of the particle data Model* model_; Index: include/IMP/decorators/graph_base.h =================================================================== --- include/IMP/decorators/graph_base.h (revision 650) +++ include/IMP/decorators/graph_base.h (working copy) @@ -36,13 +36,16 @@ IMPDLLEXPORT Particle* graph_connect(Particle* a, Particle* b, - const GraphData &d); + const GraphData &d); +IMPDLLEXPORT void graph_disconnect(Particle* bond, + const GraphData &d); + IMPDLLEXPORT Particle* graph_get_edge(Particle* a, int i, - const GraphData &d); + const GraphData &d); IMPDLLEXPORT Particle* graph_get_neighbor(Particle* a, int i, - const GraphData &d); + const GraphData &d); IMPDLLEXPORT unsigned int graph_get_number_of_edges(Particle *a, const GraphData &d); Index: include/IMP/decorators/bond_decorators.h =================================================================== --- include/IMP/decorators/bond_decorators.h (revision 650) +++ include/IMP/decorators/bond_decorators.h (working copy) @@ -30,6 +30,7 @@ extern IMPDLLEXPORT FloatKey bond_length_key_; extern IMPDLLEXPORT IntKey bond_type_key_; extern IMPDLLEXPORT IntKey bond_order_key_; +extern IMPDLLEXPORT FloatKey bond_stiffness_key_; } // namespace internal @@ -48,7 +49,7 @@ public: //! The types a bond can have right now enum Type {UNKNOWN=-1, - COVALENT, HYDROGEN, DISULPHINE, SALT, PEPTIDE + COVALENT, HYDROGEN, DISULPHINE, SALT, PEPTIDE, HIGHORDER }; //! Get the atom i of the bond @@ -61,6 +62,10 @@ IMP_DECORATOR_GET_SET_OPT(length, internal::bond_length_key_, Float, Float, -1); + IMP_DECORATOR_GET_SET_OPT(stiffness, internal::bond_stiffness_key_, Float, + Float, -1); + + IMP_DECORATOR_GET_SET_OPT(type, internal::bond_type_key_, Int, Int, UNKNOWN); @@ -81,7 +86,7 @@ public: - int get_number_of_bonds() const { + unsigned int number_of_bonds() const { return graph_get_number_of_edges(get_particle(), internal::bond_graph_data_); } @@ -101,10 +106,10 @@ IMP_OUTPUT_OPERATOR(BondedDecorator); -BondedDecorator BondDecorator::get_atom(unsigned int i) const +inline BondedDecorator BondDecorator::get_atom(unsigned int i) const { Particle *p= graph_get_node(get_particle(), i, - internal::bond_graph_data_); + internal::bond_graph_data_); return BondedDecorator::cast(p); } @@ -112,16 +117,33 @@ /** \param[in] a The first Particle as a BondedDecorator \param[in] b The second Particle as a BondedDecorator \param[in] t The type to use for the bond + \param[in] l The length of the bond. Negative values are ignored. + \param[in] s The stiffness of the bond. Negative values are ignored. \return BondDecorator of the bond Particle. */ IMPDLLEXPORT -BondDecorator bond(BondedDecorator a, BondedDecorator b, Int t); +BondDecorator bond(BondedDecorator a, BondedDecorator b, Int t, + Float l=-1, Float s = -1); +//! Destroy the bond connecting to particles. +/** \param[in] b The bond. + */ +IMPDLLEXPORT +void unbond(BondDecorator b); + + //! Get all the particles connected to the current one via a path of bonds. IMPDLLEXPORT Particles get_bonded(BondedDecorator a); +//! Get the bond between two particles. +/** + BondDecorator() is returned if the particles are not bonded. + */ +IMPDLLEXPORT +BondDecorator get_bond(BondedDecorator a, BondedDecorator b); + } // namespace IMP #endif /* __IMP_BOND_DECORATORS_H */ Index: include/IMP/State.h =================================================================== --- include/IMP/State.h (revision 650) +++ include/IMP/State.h (working copy) @@ -11,14 +11,14 @@ #include #include "IMP_config.h" -#include "boost/noncopyable.h" +#include "Object.h" namespace IMP { class Model; //! Shared state. -class IMPDLLEXPORT State : public boost::noncopyable +class IMPDLLEXPORT State : public Object { friend class Model; void set_model(Model* model); Index: include/IMP/Optimizer.h =================================================================== --- include/IMP/Optimizer.h (revision 650) +++ include/IMP/Optimizer.h (working copy) @@ -12,14 +12,16 @@ #include "IMP_config.h" #include "base_types.h" -#include "Model.h" +#include "Object.h" #include "utility.h" namespace IMP { +class Model; + //! Base class for all optimizers -class IMPDLLEXPORT Optimizer +class IMPDLLEXPORT Optimizer: public Object { public: Optimizer(); Index: include/IMP/ScoreFunc.h =================================================================== --- include/IMP/ScoreFunc.h (revision 650) +++ include/IMP/ScoreFunc.h (working copy) @@ -11,6 +11,7 @@ #include "IMP_config.h" #include "base_types.h" +#include "Object.h" namespace IMP { @@ -20,7 +21,7 @@ could be maintained for both the score calls and the score and partial derivative calls. */ -class IMPDLLEXPORT ScoreFunc + class IMPDLLEXPORT ScoreFunc: public Object { public: ScoreFunc() {} @@ -71,11 +72,11 @@ */ Float harmonic(Float feature, Float& deriv); - void show(std::ostream &out=std::cout) const { out << "Harmonic: " << mean_ << " and " << sd_ << std::endl; } + protected: Float mean_; Float sd_; Index: src/Model.cpp =================================================================== --- src/Model.cpp (revision 650) +++ src/Model.cpp (working copy) @@ -20,7 +20,6 @@ //! Constructor Model::Model() { - IMP_LOG(VERBOSE, "MEMORY: Model created " << this << std::endl); model_data_ = new ModelData(); frame_num_ = 0; trajectory_on_ = false; @@ -30,7 +29,6 @@ //! Destructor Model::~Model() { - IMP_LOG(VERBOSE, "MEMORY: Model destroyed " << this << std::endl); IMP_CONTAINER_DELETE(Particle, particle); IMP_CONTAINER_DELETE(State, state); IMP_CONTAINER_DELETE(Restraint, restraint); @@ -89,6 +87,7 @@ IMP_LOG(VERBOSE, "Updating States " << std::flush); for (StateIterator it = states_begin(); it != states_end(); ++it) { + IMP_CHECK_OBJECT(*it); (*it)->update(); IMP_LOG(VERBOSE, "." << std::flush); } @@ -104,6 +103,7 @@ "Evaluating restraints " << calc_derivs << std::endl); for (RestraintIterator it = restraints_begin(); it != restraints_end(); ++it) { + IMP_CHECK_OBJECT(*it); IMP_LOG(VERBOSE, (*it)->get_name() << ": " << std::flush); Float tscore=0; if ((*it)->get_is_active()) { @@ -205,6 +205,7 @@ out << "Restraints:" << std::endl; for (RestraintConstIterator it = restraints_begin(); it != restraints_end(); ++it) { + IMP_CHECK_OBJECT(*it); out << (*it)->get_name() << std::endl; } Index: src/Particle.cpp =================================================================== --- src/Particle.cpp (revision 650) +++ src/Particle.cpp (working copy) @@ -18,13 +18,11 @@ Particle::Particle(): model_(NULL) { is_active_ = true; - IMP_LOG(VERBOSE, "MEMORY: Particle created " << pi_ << std::endl); } //! Constructor Particle::~Particle() { - IMP_LOG(VERBOSE, "MEMORY: Particle deleted " << pi_ << std::endl); } @@ -61,7 +59,6 @@ void Particle::add_attribute(FloatKey name, const Float value, bool is_optimized) { - IMP_LOG(VERBOSE, "add_float: " << name); IMP_assert(model_ != NULL, "Particle must be added to Model before an attributes are added"); float_indexes_.insert(name, model_->get_model_data()->add_float(value)); @@ -77,7 +74,6 @@ */ void Particle::add_attribute(IntKey name, const Int value) { - IMP_LOG(VERBOSE, "add_int: " << name); IMP_assert(model_ != NULL, "Particle must be added to Model before an attributes are added"); int_indexes_.insert(name, model_->get_model_data()->add_int(value)); Index: src/Object.cpp =================================================================== --- src/Object.cpp (revision 0) +++ src/Object.cpp (revision 0) @@ -0,0 +1,16 @@ +#include "IMP/Object.h" + +namespace IMP { +Object::Object(){ + check_value_=111111111; +} +Object::~Object() { + assert_is_valid(); + check_value_=666666666; +} + +void Object::assert_is_valid() const { + IMP_assert(check_value_==111111111, + "Previously freed object is not valid: " << this); +} +} Index: src/SConscript =================================================================== --- src/SConscript (revision 650) +++ src/SConscript (working copy) @@ -12,7 +12,7 @@ # Source files files = ['base_types.cpp', 'ScoreFunc.cpp', 'Model.cpp', 'ModelData.cpp', 'Particle.cpp', 'RigidBody.cpp', 'State.cpp', 'Log.cpp', - 'Restraint.cpp', 'Optimizer.cpp' + 'Restraint.cpp', 'Optimizer.cpp', 'Object.cpp' ] + decorators_files + restraints_files + optimizers_files # Build the shared library: Index: src/Restraint.cpp =================================================================== --- src/Restraint.cpp (revision 650) +++ src/Restraint.cpp (working copy) @@ -19,7 +19,6 @@ Restraint::Restraint(std::string name): name_(name) { model_ = NULL; - IMP_LOG(VERBOSE, "MEMORY: Restraint constructed " << this << std::endl); is_active_ = true; // active by default are_particles_active_ = true; // active by default } @@ -28,7 +27,6 @@ //! Destructor Restraint::~Restraint() { - IMP_LOG(VERBOSE, "MEMORY: Restraint deleted " << this << std::endl); } Index: src/restraints/DistanceRestraint.cpp =================================================================== --- src/restraints/DistanceRestraint.cpp (revision 650) +++ src/restraints/DistanceRestraint.cpp (working copy) @@ -63,6 +63,9 @@ */ Float DistanceRestraint::evaluate(DerivativeAccumulator *accum) { + + IMP_CHECK_OBJECT(score_func_); + Float d2=0, delta[3]; Float score; Index: src/restraints/SphericalRestraint.cpp =================================================================== --- src/restraints/SphericalRestraint.cpp (revision 650) +++ src/restraints/SphericalRestraint.cpp (working copy) @@ -42,6 +42,7 @@ Float SphericalRestraint::evaluate(DerivativeAccumulator *accum) { + IMP_CHECK_OBJECT(score_func_); Float d2=0; Float diff[3]; Index: src/State.cpp =================================================================== --- src/State.cpp (revision 650) +++ src/State.cpp (working copy) @@ -18,14 +18,14 @@ State::State(std::string name) : name_(name) { model_ = NULL; - IMP_LOG(VERBOSE, "State constructed"); + IMP_LOG(VERBOSE, "State constructed " << name << std::endl); } //! Destructor State::~State() { - IMP_LOG(VERBOSE, "State deleted"); + IMP_LOG(VERBOSE, "State deleted " << get_name() << std::endl); } Index: src/decorators/bond_decorators.cpp =================================================================== --- src/decorators/bond_decorators.cpp (revision 650) +++ src/decorators/bond_decorators.cpp (working copy) @@ -15,6 +15,7 @@ GraphData bond_graph_data_; bool bond_keys_initialized_=false; FloatKey bond_length_key_; +FloatKey bond_stiffness_key_; IntKey bond_type_key_; IntKey bond_order_key_; } @@ -36,6 +37,7 @@ } else { internal::bond_graph_data_= internal::GraphData("bond"); internal::bond_length_key_=FloatKey("bond length"); + internal::bond_stiffness_key_=FloatKey("bond stiffness"); internal::bond_type_key_= IntKey("bond type"); internal::bond_order_key_=IntKey("bond order"); internal::bond_keys_initialized_=true; @@ -53,15 +55,21 @@ BondDecorator bond(BondedDecorator a, BondedDecorator b, - Int t) + Int t, Float l, Float s) { Particle *p= internal::graph_connect(a.get_particle(), b.get_particle(), internal::bond_graph_data_); BondDecorator bd= BondDecorator::cast(p); bd.set_type(t); + if (l >= 0) bd.set_length(l); + if (s >= 0) bd.set_stiffness(s); return bd; } +void unbond(BondDecorator b) { + graph_disconnect(b.get_particle(), internal::bond_graph_data_); +} + Particles get_bonded(BondedDecorator a) { Particles out; internal::graph_connected_component(a.get_particle(), @@ -70,4 +78,14 @@ return out; } +BondDecorator get_bond(BondedDecorator a, BondedDecorator b) { + for (unsigned int i=0; i < a.number_of_bonds(); ++i) { + BondDecorator bd= a.get_bond(i); + if (bd.get_atom(0) == b || bd.get_atom(1) == b) { + return bd; + } + } + return BondDecorator(); } + +} Index: src/decorators/graph_base.cpp =================================================================== --- src/decorators/graph_base.cpp (revision 650) +++ src/decorators/graph_base.cpp (working copy) @@ -34,30 +34,52 @@ ParticleIndex pi=m->add_particle(p); p->add_attribute(d.node_keys_[0], a->get_index().get_index()); p->add_attribute(d.node_keys_[1], b->get_index().get_index()); - { - int nc= graph_get_number_of_edges(a, d); + for (int i=0; i< 2; ++i) { + Particle *cp=((i==0)?a:b); + int nc= graph_get_number_of_edges(cp, d); IntKey nm=graph_get_edge_key(nc, d); - a->add_attribute(nm, p->get_index().get_index()); - if (a->has_attribute(d.num_edges_key_)) { - a->set_value(d.num_edges_key_, nc+1); + if (!cp->has_attribute(nm)) { + cp->add_attribute(nm, p->get_index().get_index()); } else { - a->add_attribute(d.num_edges_key_, nc+1); + cp->set_value(nm, p->get_index().get_index()); } - } - { - int nc= graph_get_number_of_edges(b, d); - IntKey nm=graph_get_edge_key(nc, d); - b->add_attribute(nm, p->get_index().get_index()); - if (b->has_attribute(d.num_edges_key_)) { - b->set_value(d.num_edges_key_, nc+1); + if (cp->has_attribute(d.num_edges_key_)) { + cp->set_value(d.num_edges_key_, nc+1); } else { - b->add_attribute(d.num_edges_key_, nc+1); + cp->add_attribute(d.num_edges_key_, nc+1); } } return a->get_model()->get_particle(pi); } +void graph_disconnect(Particle* e, const GraphData &d) +{ + ParticleIndex pi=e->get_index(); + Particle *p[2]; + p[0]= graph_get_node(e, 0, d); + p[1]= graph_get_node(e, 1, d); + for (int i=0; i< 2; ++i) { + int shift=0; + Int nc= p[i]->get_value(d.num_edges_key_); + for (int j=0; j< nc; ++j) { + if (graph_get_edge(p[i], j, d) == e) { + IMP_assert(shift==0, "duplicate edges found in graph_base"); + shift=-1; + } else { + Int v = p[i]->get_value(graph_get_edge_key(j, d)); + p[i]->set_value(graph_get_edge_key(j+shift, d), v); + } + } + p[i]->set_value(graph_get_edge_key(nc-1, d), -1); + IMP_assert(shift==-1, "no edge found"); + IMP_assert(nc > 0, "Too few edges"); + p[i]->set_value(d.num_edges_key_, nc-1); + } + e->set_is_active(false); +} + + Particle* graph_get_edge(Particle* a, int i, const GraphData &d) { IntKey nm= graph_get_edge_key(i, d); Index: src/optimizers/ConjugateGradients.cpp =================================================================== --- src/optimizers/ConjugateGradients.cpp (revision 650) +++ src/optimizers/ConjugateGradients.cpp (working copy) @@ -9,6 +9,7 @@ #include "IMP/log.h" #include "IMP/optimizers/ConjugateGradients.h" +#include "IMP/Model.h" namespace IMP { Index: src/optimizers/SteepestDescent.cpp =================================================================== --- src/optimizers/SteepestDescent.cpp (revision 650) +++ src/optimizers/SteepestDescent.cpp (working copy) @@ -7,6 +7,7 @@ #include "IMP/log.h" #include "IMP/optimizers/SteepestDescent.h" +#include "IMP/Model.h" namespace IMP { Index: src/ScoreFunc.cpp =================================================================== --- src/ScoreFunc.cpp (revision 650) +++ src/ScoreFunc.cpp (working copy) @@ -15,8 +15,6 @@ //! Destructor Harmonic::~Harmonic() { - IMP_LOG(VERBOSE, - "Delete Harmonic: beware of early Python calls to destructor."); } //! Calculate harmonic score with respect to the given feature. @@ -72,8 +70,6 @@ //! Destructor HarmonicLowerBound::~HarmonicLowerBound() { - IMP_LOG(VERBOSE, "Delete HarmonicLowerBound: beware of early Python " - << "calls to destructor."); } //! Calculate lower-bound harmonic score with respect to the given feature. @@ -109,8 +105,6 @@ //! Destructor HarmonicUpperBound::~HarmonicUpperBound() { - IMP_LOG(VERBOSE, "Delete HarmonicUpperBound: beware of early Python " - << "calls to destructor."); } Index: src/ModelData.cpp =================================================================== --- src/ModelData.cpp (revision 650) +++ src/ModelData.cpp (working copy) @@ -32,15 +32,13 @@ */ FloatIndex ModelData::add_float(const Float value) { - FloatIndex f_index; int size = float_data_.size(); float_data_.resize(size + 1); - f_index = FloatIndex(size);//.set_index(size); - float_data_[f_index.get_index()].value_ = value; + float_data_[size].value_ = value; - return f_index; + return FloatIndex(size); } @@ -50,6 +48,8 @@ */ void ModelData::set_value(const FloatIndex idx, const Float value) { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range float requested"); float_data_[idx.get_index()].value_ = value; } @@ -61,6 +61,8 @@ */ void ModelData::add_to_deriv(const FloatIndex idx, Float value) { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range float requested"); float_data_[idx.get_index()].deriv_ += value; } @@ -70,6 +72,8 @@ */ Float ModelData::get_deriv(const FloatIndex idx) const { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range float requested"); return float_data_[idx.get_index()].deriv_; } @@ -79,6 +83,8 @@ */ bool ModelData::get_is_optimized(const FloatIndex idx) const { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range float requested"); return float_data_[idx.get_index()].is_optimized_; } @@ -88,6 +94,8 @@ */ void ModelData::set_is_optimized(const FloatIndex idx, bool is_optimized) { + IMP_assert(idx.get_index() < float_data_.size(), + "Out of range float requested"); float_data_[idx.get_index()].is_optimized_ = is_optimized; } @@ -110,15 +118,12 @@ */ IntIndex ModelData::add_int(const Int value) { - IntIndex i_index; int size = int_data_.size(); int_data_.resize(size + 1); + int_data_[size] = value; - i_index = IntIndex(size); - int_data_[i_index.get_index()] = value; - - return i_index; + return IntIndex(size); } //! Set particle attribute value. @@ -127,6 +132,8 @@ */ void ModelData::set_value(const IntIndex idx, const Int value) { + IMP_assert(idx.get_index() < int_data_.size(), + "Out of range int requested"); int_data_[idx.get_index()] = value; } @@ -139,15 +146,13 @@ */ StringIndex ModelData::add_string(const String value) { - StringIndex s_index; int size = string_data_.size(); string_data_.resize(size + 1); - s_index = StringIndex(size); - string_data_[s_index.get_index()] = value; + string_data_[size] = value; - return s_index; + return StringIndex(size); } //! Set particle attribute value. @@ -156,6 +161,8 @@ */ void ModelData::set_value(const StringIndex idx, const String value) { + IMP_assert(idx.get_index() < string_data_.size(), + "Out of range string requested"); string_data_[idx.get_index()] = value; } Index: pyext/IMP_macros.i =================================================================== --- pyext/IMP_macros.i (revision 650) +++ pyext/IMP_macros.i (working copy) @@ -23,8 +23,8 @@ public:\ typedef Name This;\ public: Name(); \ - static Name create(Particle *p);\ - static Name cast(Particle *p);\ + static Name create(::IMP::Particle *p);\ + static Name cast(::IMP::Particle *p);\ void show(std::ostream &out=std::cout, std::string pre="") #define IMP_DECORATOR_ARRAY_DECL(a, b) #define IMP_CONTAINER(Ucname, lcname, IndexType) \ Index: pyext/SConscript =================================================================== --- pyext/SConscript (revision 650) +++ pyext/SConscript (working copy) @@ -5,11 +5,11 @@ # Get a modified build environment suitable for building Python extensions: e = get_pyext_environment(env, cplusplus=True) e.Append(CPPPATH='#/include') -e.Append(LIBPATH='../src', LIBS='imp') +e.Append(LIBPATH='../src', LIBS=['imp', 'gmalloc']) # Build the Python extension from SWIG interface file: pyext = e.LoadableModule('_IMP', 'IMP.i', - SWIGFLAGS='-python -c++ -naturalvar -Iinclude') + SWIGFLAGS='-D_GLIBCXX_DEBUG -python -c++ -naturalvar -Iinclude') # IMP.py file should also be generated; copy to IMP subdirectory: pymod_gen = File('IMP.py') e.Depends(pymod_gen, pyext) Index: pyext/IMP.i =================================================================== --- pyext/IMP.i (revision 650) +++ pyext/IMP.i (working copy) @@ -34,10 +34,10 @@ %feature("director"); +%include "IMP/Object.h" %include "IMP/Index.h" %include "IMP/base_types.h" %include "IMP.h" -%include "IMP/boost/noncopyable.h" %include "IMP/Key.h" %include "IMP/ScoreFunc.h" %include "IMP/ModelData.h"