Index: kernel/include/IMP/internal/AttributeTable.h =================================================================== --- kernel/include/IMP/internal/AttributeTable.h (revision 512) +++ kernel/include/IMP/internal/AttributeTable.h (working copy) @@ -46,26 +46,21 @@ typedef Key Key; AttributeTable() {} const Value get_value(Key k) const { - IMP_check(contains(k), + IMP_assert(contains(k), "Attribute \"" << k.get_string() - << "\" not found in table.", - IndexException((std::string("Invalid attribute \"") - + k.get_string() + "\" requested").c_str())); + << "\" not found in table."); return map_[k.get_index()].second; } Value& get_value(Key k) { - IMP_check(contains(k), + IMP_assert(contains(k), "Attribute \"" << k.get_string() - << "\" not found in table.", - IndexException((std::string("Invalid attribute \"") - + k.get_string() + "\" requested").c_str())); + << "\" not found in table."); return map_[k.get_index()].second; } void insert(Key k, Value v); bool contains(Key k) const { - IMP_check(k != Key(), "Can't search for default key", - IndexException("Bad index")); + IMP_assert(k != Key(), "Can't search for default key"); return k.get_index() < map_.size() && map_[k.get_index()].first; } @@ -109,9 +104,8 @@ template inline void AttributeTable::insert(Key k, Value v) { - IMP_check(k != Key(), - "Can't insert default key", - IndexException("bad index")); + IMP_assert(k != Key(), + "Can't insert default key"); if (map_.size() <= k.get_index()) { map_.resize(k.get_index()+1); } Index: kernel/pyext/IMP.i =================================================================== --- kernel/pyext/IMP.i (revision 512) +++ kernel/pyext/IMP.i (working copy) @@ -14,8 +14,18 @@ /* Return derivatives from unary functions */ %include "typemaps.i" -%apply double &OUTPUT { IMP::Float& deriv }; +%apply double &OUTPUT { IMP::Float& }; +%pythoncode %{ +def check_particle(p, a): + if (not p.get_is_active()): + raise ValueError("Inactive Particle") + if (type(a)() == a): + raise IndexError("Cannot use default Index") + if (not p.has_attribute(a)): + raise IndexError("Particle does not have attribute") +%} + namespace IMP { %pythonprepend Model::add_particle %{ args[1].thisown=0 @@ -86,6 +96,34 @@ %pythonprepend MonteCarlo::set_local_optimizer %{ args[1].thisown=0 %} + %pythonprepend Particle::get_value %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::get_is_optimized %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::set_is_optimized %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::set_value %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::add_to_derivative %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::get_derivative %{ + check_particle(args[0], args[1]) + %} + %pythonprepend Particle::add_attribute %{ + # special case since we don't want to check that the attribute is there + if (not args[0].get_is_active()): + raise ValueError("Inactive Particle") + if (type(args[1])() == args[1]): + raise IndexError("Cannot use default Index") + if (args[0].has_attribute(args[1])): + raise IndexError("Particle already has attribute") + + %} } /* Don't wrap internal functions */ @@ -106,6 +144,7 @@ %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/DerivativeAccumulator.h" %include "IMP/Restraint.h" %include "IMP/ScoreState.h" @@ -128,6 +167,7 @@ %include "IMP/Optimizer.h" %include "IMP/optimizers/SteepestDescent.h" %include "IMP/optimizers/ConjugateGradients.h" +%include "IMP/optimizers/BrownianDynamics.h" %include "IMP/optimizers/MolecularDynamics.h" %include "IMP/optimizers/Mover.h" %include "IMP/optimizers/MoverBase.h"