IMP-dev
Threads by month
- ----- 2024 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- 869 discussions
As a general guideline in IMP get_ methods never returns a reference
and so doing things like get_foo.begin() is never a safe thing. Any
such method which happens to return a reference is just an
optimization for efficiency and might change later.
The only way I know to nicely catch the problem that Keren encountered
is to turn on iterator debugging in gcc, but that changes the C++ ABI
and so is a bit awkward if you link against any other C++ libraries.
1
0
Here is a new patch which includes the get_interacting_particles code.
It is not implemented for NonbondedRestraint as that did not appear to
be currently needed and required a few changes to the nonbonded lists
and so was not entirely trivial.
The other changes from the last version of the patch are:
- TripletChainRestraint now only has one chain (as with
PairChainRestraint)
- There is a new PairScore RefineHighPairScore which refines high
scoring pairs for use in hierarchical collision detection.
2
1
Frido was complaining that the nbl was too slow, so I thought I would
check in my local changes. The big thing is that the fastest
implementation I have uses the CGAL library. It is part of fedora extras
so getting it is not that big a deal (and I think there are installers
for macs). The nbl code is controlled by the macro IMP_USE_CGAL so
everything works fine without it. I have a patched scons init file which
adds support (but does not do a very good job since I don't know how to
write link tests and such).
First some small patches:
The first adds a constructor to decorators which assumes that the
particles have the needed fields (this is checked if debug code is
used). We should add checks to the python interface eventually.
The second patches the init file as above. It also adds an argument
extraroot which adds to the include search path and the lib path (and to
the runtime link path since it is needed to make the boost tests pass
currently). There are probably lots of ways to make this better as I
don't really know scons. Also, as a general point, the SConscript files
which build things should all be changed to add the local include and
lib paths to the front so that local headers mask globally installed
headers.
The third prints a nicer error message if you forget to set the model
before CG::optimize (this is independent of the other patches)
The fourth uses the decorator constructors in the bond decorators.
The fifth adds set_particles to the the list restraint I added before
(this is independent of anything else).
And the fifth patches the nonbonded lists. There is now just
AllNonbondedListScoreState and BipartiteNonbondedListScore state with
set_algorithm methods (and arguments to the constructor) to determine
which algorithm is used. The default is either grid or CGAL if the
latter is available. The other interface change is that the nbl now
takes the distance cutoff in its constructor (rather than the cutoff
being passed to the NBRestraint as before). This simplified things a
great deal. The patch also brings in a BondedList for chains which
should be faster than using the bond decorators.
Some timing results for the various nbls follow. The results are
normalized by the number of particles involved.
Nothing: (just run the python code to set up the particles)
For 50 particles got 3.24961185455
For 100 particles got 3.17380809784
For 1000 particles got 3.14385008812
For 10000 particles got 3.13716006279
For 100000 particles got 3.16522884369
Bbox- (CGAL)
For 50 particles got 3.32897806168
For 100 particles got 3.29577898979
For 1000 particles got 3.42112493515
For 10000 particles got 4.14875411987
For 100000 particles got 5.81269311905
Grid
For 50 particles got 3.63301706314
For 100 particles got 3.84657287598
For 1000 particles got 6.80274581909
For 10000 particles got 11.4696931839
Quadratic
For 50 particles got 3.39585018158
For 100 particles got 3.51785087585
For 1000 particles got 6.79182696342
For 10000 particles got 44.5892150402
Index: kernel/include/IMP/decorators/macros.h
===================================================================
--- kernel/include/IMP/decorators/macros.h (revision 524)
+++ kernel/include/IMP/decorators/macros.h (working copy)
@@ -44,15 +44,17 @@
add_required; \
} \
friend class DecoratorBase; \
- Name(::IMP::Particle* p): Parent(p) { \
- IMP_assert(has_required_attributes(p), \
- "This is not a particle of type " \
- << #Name << *p); \
- } \
public: \
typedef Name This; \
- /** The default constructor. This is used as a null value */ \
+ /** \short The default constructor. This is used as a null value */ \
Name(): Parent(){} \
+ /** \short Construct from a Particle which has all needed attributes */\
+ Name(::IMP::Particle *p): Parent(p){ \
+ if (!decorator_keys_initialized_) decorator_initialize_static_data();\
+ IMP_assert(has_required_attributes(p), \
+ "Particle missing required attributes for decorator" \
+ << #Name << *p << std::endl); \
+ } \
/** Add the necessary attributes to p and return a decorator. */ \
static Name create(::IMP::Particle *p) { \
return IMP::DecoratorBase::create<Name>(p); \
Index: tools/__init__.py
===================================================================
--- tools/__init__.py (revision 524)
+++ tools/__init__.py (working copy)
@@ -53,7 +53,10 @@
def _add_release_flags(env):
"""Add compiler flags for release builds, if requested"""
if env.get('release', False):
- env.Append(CPPDEFINES='NDEBUG')
+ env.Append(CPPDEFINES=['NDEBUG'])
+ env.Append(CCFLAGS=["-O3"])
+ else:
+ env.Append(CCFLAGS=["-g"])
def CheckGNUHash(context):
"""Disable GNU_HASH-style linking (if found) for backwards compatibility"""
@@ -186,16 +189,30 @@
pass
env.Prepend(SCANNERS = _SWIGScanner)
if env['CC'] == 'gcc':
- env.Append(CCFLAGS="-Wall -g -O3")
+ env.Append(CCFLAGS=["-Wall"])
_add_release_flags(env)
sys = platform.system()
if sys == 'SunOS':
# Find locally-installed libraries in /usr/local (e.g. for SWIG)
env['ENV']['LD_LIBRARY_PATH'] = '/usr/local/lib'
- # Make Modeller exetype variable available:
- if os.environ.has_key('EXECUTABLE_TYPESVN'):
- env['ENV']['EXECUTABLE_TYPESVN'] = os.environ['EXECUTABLE_TYPESVN']
+
+ if (ARGUMENTS.get('extraroot', '') != ''):
+ env.Append(CPPPATH=['$extraroot/include'])
+ env.Append(LIBPATH=['$extraroot/lib'])
+ env.Append(LINKFLAGS=['-Wl,-rpath,$extraroot/lib'])
+ env.Append(LD_LIBRARY_PATH=['$extraroot/lib'])
+ env['EXTRA_LDPATH']=ARGUMENTS.get('extraroot', '')+'/lib'
+ env['EXTRA_PYTHONPATH']=ARGUMENTS.get('extraroot', '')+'/lib/python2.5/site-packages'
+
+
+ if (ARGUMENTS.get('usecgal')):
+ # should do tests here to make sure it is usable, but I don't know how
+ env.Append(CPPDEFINES=['IMP_USE_CGAL'])
+ env.Append(LIBS= ['CGAL'])
+ if env['CC'] == 'gcc':
+ env.Append(CCFLAGS=["-frounding-math"])
+
# Set empty variables in case the Modeller check fails:
for mod in ('MODPY', 'EXETYPE'):
env['MODELLER_' + mod] = ''
@@ -309,6 +326,8 @@
# Remove options that don't work with C++ code:
if cplusplus:
opt = opt.replace("-Wstrict-prototypes", "")
+ if cplusplus:
+ opt = opt.replace("-O2", "")
e.Replace(CC=cc, CXX=cxx, LDMODULESUFFIX=so)
e.Replace(CPPFLAGS=basecflags.split() + opt.split())
@@ -372,3 +391,10 @@
opts.Add(BoolOption('release',
'Disable most runtime checks (e.g. for releases)',
False))
+ opts.Add(PathOption('extraroot',
+ 'Extra place to search for includes and libs',
+ '', PathOption.PathAccept))
+ # I would like to have a check, but it doesn't seem to turn it off it no value is passed
+ #PathOption.PathIsDir))
+ opts.Add(BoolOption('usecgal',
+ 'Use the CGAL library for some algorithms', False))
Index: kernel/src/optimizers/ConjugateGradients.cpp
===================================================================
--- kernel/src/optimizers/ConjugateGradients.cpp (revision 524)
+++ kernel/src/optimizers/ConjugateGradients.cpp (working copy)
@@ -214,6 +214,9 @@
Float ConjugateGradients::optimize(unsigned int max_steps)
{
+ IMP_check(get_model(),
+ "Must set the model on the optimizer before optimizing",
+ ValueException("Must set the model before optimizing"));
std::vector<Float> x, dx;
int i;
//ModelData* model_data = get_model()->get_model_data();
Index: kernel/src/decorators/bond_decorators.cpp
===================================================================
--- kernel/src/decorators/bond_decorators.cpp (revision 524)
+++ kernel/src/decorators/bond_decorators.cpp (working copy)
@@ -77,7 +77,7 @@
{
Particle *p= internal::graph_connect(a.get_particle(), b.get_particle(),
internal::bond_graph_data_);
- BondDecorator bd= BondDecorator::cast(p);
+ BondDecorator bd(p);
bd.set_type(t);
return bd;
}
Index: kernel/include/IMP/decorators/bond_decorators.h
===================================================================
--- kernel/include/IMP/decorators/bond_decorators.h (revision 524)
+++ kernel/include/IMP/decorators/bond_decorators.h (working copy)
@@ -102,7 +102,7 @@
BondDecorator get_bond(unsigned int i) const {
Particle *p= graph_get_edge(get_particle(), i,
internal::bond_graph_data_);
- return BondDecorator::cast(p);
+ return BondDecorator(p);
}
//! Get a BondedDecorator of the ith bonded particle
@@ -117,7 +117,7 @@
*/
BondedDecorator get_bonded(unsigned int i) const {
Particle *p= graph_get_edge(get_particle(), i, internal::bond_graph_data_);
- BondDecorator bd= BondDecorator::cast(p);
+ BondDecorator bd(p);
if (bd.get_bonded(0) == *this) return bd.get_bonded(1);
else return bd.get_bonded(0);
}
@@ -130,7 +130,7 @@
{
Particle *p= graph_get_node(get_particle(), i,
internal::bond_graph_data_);
- return BondedDecorator::cast(p);
+ return BondedDecorator(p);
}
//! Connect the two wrapped particles by a bond.
Index: kernel/include/IMP/restraints/SingletonListRestraint.h
===================================================================
--- kernel/include/IMP/restraints/SingletonListRestraint.h (revision 524)
+++ kernel/include/IMP/restraints/SingletonListRestraint.h (working copy)
@@ -38,6 +38,7 @@
using Restraint::add_particles;
using Restraint::clear_particles;
+ using Restraint::set_particles;
protected:
internal::ObjectPointer<SingletonScore, true> ss_;
Index: kernel/include/IMP/restraints/NonbondedRestraint.h
===================================================================
--- kernel/include/IMP/restraints/NonbondedRestraint.h (revision 524)
+++ kernel/include/IMP/restraints/NonbondedRestraint.h (working copy)
@@ -34,10 +34,8 @@
object is deleted upon destruction.
\param[in] nbl The non-bonded list to use to get the list
of particles.
- \param[in] max_dist Pairs beyond this distance may be dropped.
*/
- NonbondedRestraint(PairScore *ps, NonbondedListScoreState *nbl,
- Float max_dist= std::numeric_limits<Float>::max());
+ NonbondedRestraint(PairScore *ps, NonbondedListScoreState *nbl);
virtual ~NonbondedRestraint(){}
IMP_RESTRAINT(internal::kernel_version_info)
@@ -45,7 +43,6 @@
protected:
NonbondedListScoreState *nbl_;
internal::ObjectPointer<PairScore, true> sf_;
- Float max_dist_;
};
} // namespace IMP
Index: kernel/src/restraints/NonbondedRestraint.cpp
===================================================================
--- kernel/src/restraints/NonbondedRestraint.cpp (revision 524)
+++ kernel/src/restraints/NonbondedRestraint.cpp (working copy)
@@ -17,9 +17,8 @@
{
NonbondedRestraint::NonbondedRestraint(PairScore *ps,
- NonbondedListScoreState *nbl,
- Float md) : nbl_(nbl), sf_(ps),
- max_dist_(md)
+ NonbondedListScoreState *nbl)
+ : nbl_(nbl), sf_(ps)
{
}
@@ -31,12 +30,12 @@
IMP_CHECK_OBJECT(nbl_);
Float score=0;
IMP_LOG(VERBOSE, "Nonbonded restraint on "
- << std::distance(nbl_->nonbonded_begin(max_dist_),
- nbl_->nonbonded_end(max_dist_))
+ << std::distance(nbl_->nonbonded_begin(),
+ nbl_->nonbonded_end())
<< " pairs" << std::endl);
for (NonbondedListScoreState::NonbondedIterator it
- = nbl_->nonbonded_begin(max_dist_);
- it != nbl_->nonbonded_end(max_dist_); ++it) {
+ = nbl_->nonbonded_begin();
+ it != nbl_->nonbonded_end(); ++it) {
float thisscore = sf_->evaluate(it->first, it->second, accum);
if (thisscore != 0) {
IMP_LOG(VERBOSE, "Pair " << it->first->get_index()
Index: kernel/include/IMP/score_states/QuadraticNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/QuadraticNonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/QuadraticNonbondedListScoreState.h (working copy)
@@ -1,51 +0,0 @@
-/**
- * \file QuadraticNonbondedListScoreState.h
- * \brief Allow iteration through pairs of a set of spheres.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#ifndef __IMP_QUADRATIC_NONBONDED_LIST_SCORE_STATE_H
-#define __IMP_QUADRATIC_NONBONDED_LIST_SCORE_STATE_H
-
-#include "NonbondedListScoreState.h"
-#include "../internal/kernel_version_info.h"
-#include "MaxChangeScoreState.h"
-
-#include <vector>
-#include <limits>
-
-namespace IMP
-{
-
-//! A base class for nonbonded lists which test all pairs of particles
-/** This should not be used by end users. But since it needs to be in the
- inheritance hierarchy, it should be in the IMP namespace.
- */
-class IMPDLLEXPORT QuadraticNonbondedListScoreState:
- public NonbondedListScoreState
-{
- typedef NonbondedListScoreState P;
- internal::ObjectPointer<MaxChangeScoreState, true> mc_;
- float slack_;
- protected:
- void handle_nbl_pair( Particle *a, Particle *b, float d);
- const Particles &get_particles() const {
- return mc_->get_particles();
- }
- void set_particles(const Particles &ps) {
- P::clear_nbl();
- mc_->clear_particles();
- mc_->add_particles(ps);
- }
-
- QuadraticNonbondedListScoreState(FloatKey radius);
- ~QuadraticNonbondedListScoreState();
-
- public:
- void update();
-};
-
-} // namespace IMP
-
-#endif /* __IMP_QUADRATIC_NONBONDED_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/BondDecoratorListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BondDecoratorListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/BondDecoratorListScoreState.h (working copy)
@@ -8,10 +8,11 @@
#ifndef __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
#define __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
-#include <vector>
#include "BondedListScoreState.h"
#include "../decorators/bond_decorators.h"
+#include <vector>
+
namespace IMP
{
@@ -25,6 +26,7 @@
*/
class IMPDLLEXPORT BondDecoratorListScoreState: public BondedListScoreState
{
+ // This is only used to provide the iterators. Probably should be lazy.
std::vector<BondDecorator> bonds_;
Particles ps_;
public:
Index: kernel/include/IMP/score_states/NonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/NonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/NonbondedListScoreState.h (working copy)
@@ -11,6 +11,7 @@
#include "../ScoreState.h"
#include "../internal/ParticleGrid.h"
#include "../internal/kernel_version_info.h"
+#include "../decorators/XYZDecorator.h"
#include "BondedListScoreState.h"
#include <vector>
@@ -19,34 +20,52 @@
namespace IMP
{
+namespace internal
+{
+class NBLAddPairIfNonbonded;
+class NBLAddIfNonbonded;
+}
+
typedef std::vector<BondedListScoreState*> BondedListScoreStates;
-//! A base class for classes that maintain a list of non-bonded pairs.
-/**
+//! An abstract base class for classes that maintain a list of non-bonded pairs.
+/** \note If no value for the radius key is specified, all radii are
+ considered to be zero.
*/
class IMPDLLEXPORT NonbondedListScoreState: public ScoreState
{
private:
FloatKey rk_;
-
-protected:
+ // the distance cutoff to count a pair as adjacent
+ float cutoff_;
+ /* How much to add to the size of particles to allow them to move
+ without rebuilding*/
+ Float slack_;
+ /* An estimate of what the slack should be next time they are recomputed*/
+ Float next_slack_;
+ int num_steps_;
+ bool nbl_is_valid_;
// made protected for debugging code, do not use otherwise
typedef std::vector<std::pair<Particle*, Particle*> > NBL;
NBL nbl_;
- float last_cutoff_;
+protected:
+
+ Float get_slack() const {return slack_;}
+ Float get_cutoff() const {return cutoff_;}
+
unsigned int size_nbl() const {return nbl_.size();}
//! rebuild the nonbonded list
- /** \internal
+ /** This is used by classes which inherit from this to rebuild the NBL
+
+ \internal
*/
- virtual void rebuild_nbl(float cut)=0;
+ virtual void rebuild_nbl()=0;
- void clear_nbl() {
- last_cutoff_=-1;
- nbl_.clear();
- }
+
+ // Return true if two particles are bonded
bool are_bonded(Particle *a, Particle *b) const {
IMP_assert(a->get_is_active() && b->get_is_active(),
"Inactive particles should have been removed"
@@ -60,27 +79,13 @@
return false;
}
- struct AddToNBL;
- friend struct AddToNBL;
+ friend struct internal::NBLAddPairIfNonbonded;
+ friend struct internal::NBLAddIfNonbonded;
- // these should be two separate classes, but they are not
- struct AddToNBL{
- NonbondedListScoreState *state_;
- Particle *p_;
- AddToNBL(NonbondedListScoreState *s, Particle *p): state_(s),
- p_(p){}
- void operator()(Particle *p) {
- operator()(p_, p);
- }
- void operator()(Particle *a, Particle *b) {
- state_->add_to_nbl(a,b);
- }
- };
- //! tell the bonded lists what particles to pay attention to
- void propagate_particles(const Particles &ps);
- void add_to_nbl(Particle *a, Particle *b) {
+ // Add the pair to the nbl if the particles are not bonded
+ void add_if_nonbonded(Particle *a, Particle *b) {
IMP_assert(a->get_is_active() && b->get_is_active(),
"Inactive particles should have been stripped");
@@ -95,6 +100,28 @@
}
}
+ // Check if the bounding boxes of the spheres overlap
+ void add_if_box_overlap(Particle *a, Particle *b) {
+ XYZDecorator da(a);
+ XYZDecorator db(b);
+ float ra= get_radius(a);
+ float rb= get_radius(b);
+ for (unsigned int i=0; i< 3; ++i) {
+ float delta=std::abs(da.get_coordinate(i) - db.get_coordinate(i));
+ if (delta -ra -rb > cutoff_+slack_) {
+ IMP_LOG(VERBOSE, "Pair " << a->get_index()
+ << " and " << b->get_index() << " rejected on coordinate "
+ << i << " " << da.get_coordinate(i) << " and "
+ << db.get_coordinate(i) << " " << ra << " "
+ << rb << " " << slack_ << " " << slack_ << std::endl);
+ return ;
+ }
+ }
+ IMP_LOG(VERBOSE, "Adding pair " << a->get_index()
+ << " and " << b->get_index() << std::endl);
+ add_if_nonbonded(a, b);
+ }
+
Float get_radius(Particle *a) const {
if (rk_ != FloatKey() && a->has_attribute(rk_)) {
return a->get_value(rk_);
@@ -102,11 +129,26 @@
return 0;
}
}
+ // return true if the nbl was invalidated by a move of mc
+ bool update(Float mc);
+ // Return a list of all the particles in in with a radius field
+ Particles particles_with_radius(const Particles &in) const;
+
+
+ // Return true if the nbl is valid
+ bool get_nbl_is_valid() const {return nbl_is_valid_;}
+
+ void set_nbl_is_valid(bool tf) {
+ nbl_is_valid_= tf;
+ if (!nbl_is_valid_) {
+ nbl_.clear();
+ }
+ }
public:
/**
*/
- NonbondedListScoreState(FloatKey rk);
+ NonbondedListScoreState(Float cutoff, FloatKey rk);
FloatKey get_radius_key() const {return rk_;}
void set_radius_key(FloatKey rk) {rk_=rk;}
@@ -118,48 +160,56 @@
typedef BondedListScoreStateIterator BondedListIterator;
typedef BondedListScoreStateConstIterator BondedListConstIterator;
- IMP_SCORE_STATE(internal::kernel_version_info)
+ virtual void show(std::ostream &out=std::cout) const;
+ virtual IMP::VersionInfo get_version_info() const {
+ return internal::kernel_version_info;
+ }
//! An iterator through nonbonded particles
- /** The value type is an std::pair<Particle*, Particle*>
+ /** The value type is an ParticlePair.
*/
typedef NBL::const_iterator NonbondedIterator;
//! This iterates through the pairs of non-bonded particles
- /** \param[in] cutoff The state may ignore pairs which are futher
- apart than the cutoff.
- \note that this is highly unsafe and iteration can only be
- done once at a time. I will fix that eventually.
-
- \note The distance cutoff is the l2 norm between the 3D coordinates
- of the Particles. It ignore any size that may be associated with
- the particles.
- */
- NonbondedIterator nonbonded_begin(Float cutoff
- =std::numeric_limits<Float>::max()) {
- IMP_assert(last_cutoff_== cutoff || last_cutoff_==-1,
- "Bad things are happening with the iterators in "
- << "NonbondedListScoreState");
- if (last_cutoff_ < cutoff) {
- IMP_LOG(VERBOSE, "Rebuilding NBL cutoff " << cutoff << std::endl);
- clear_nbl();
- rebuild_nbl(cutoff);
- last_cutoff_=cutoff;
- }
+ NonbondedIterator nonbonded_begin() const {
+ IMP_check(get_nbl_is_valid(), "Must call update first",
+ ValueException("Must call update first"));
return nbl_.begin();
}
- NonbondedIterator nonbonded_end(Float cutoff
- =std::numeric_limits<Float>::max()) {
- if (last_cutoff_ < cutoff) {
- IMP_LOG(VERBOSE, "Rebuilding NBL cutoff " << cutoff << std::endl);
- clear_nbl();
- rebuild_nbl(cutoff);
- last_cutoff_=cutoff;
- }
+ NonbondedIterator nonbonded_end() const {
+ IMP_check(get_nbl_is_valid(), "Must call update first",
+ ValueException("Must call update first"));
return nbl_.end();
}
+
+
+ unsigned int number_of_nonbonded() const {
+ return nbl_.size();
+ }
};
+
+namespace internal
+{
+ struct NBLAddPairIfNonbonded{
+ NonbondedListScoreState *state_;
+ NBLAddPairIfNonbonded(NonbondedListScoreState *s): state_(s){}
+ void operator()(Particle *a, Particle *b) {
+ state_->add_if_nonbonded(a,b);
+ }
+ };
+
+ struct NBLAddIfNonbonded{
+ NonbondedListScoreState *state_;
+ Particle *p_;
+ NBLAddIfNonbonded(NonbondedListScoreState *s, Particle *p): state_(s),
+ p_(p){}
+ void operator()(Particle *p) {
+ state_->add_if_nonbonded(p_, p);
+ }
+ };
+}
+
} // namespace IMP
#endif /* __IMP_NONBONDED_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/SConscript
===================================================================
--- kernel/include/IMP/score_states/SConscript (revision 524)
+++ kernel/include/IMP/score_states/SConscript (working copy)
@@ -1,14 +1,15 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['BondedListScoreState.h', 'NonbondedListScoreState.h',
- 'BipartiteNonbondedListScoreState.h', 'MaxChangeScoreState.h',
- 'BondDecoratorListScoreState.h', 'AllNonbondedListScoreState.h',
- 'QuadraticBipartiteNonbondedListScoreState.h',
- 'QuadraticAllNonbondedListScoreState.h',
- 'QuadraticNonbondedListScoreState.h', 'GravityCenterScoreState.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'score_states')
+files=[
+ 'AllNonbondedListScoreState.h',
+ 'BipartiteNonbondedListScoreState.h',
+ 'BondDecoratorListScoreState.h',
+ 'BondedListScoreState.h',
+ 'ChainBondedListScoreState.h',
+ 'GravityCenterScoreState.h',
+ 'MaxChangeScoreState.h',
+ 'NonbondedListScoreState.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'score_states' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/score_states/QuadraticBipartiteNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/QuadraticBipartiteNonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/QuadraticBipartiteNonbondedListScoreState.h (working copy)
@@ -1,49 +0,0 @@
-/**
- * \file QuadraticBipartiteNonbondedListScoreState.h
- * \brief Allow iteration through pairs of a set of atoms.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#ifndef __IMP_QUADRATIC_BIPARTITE_NONBONDED_LIST_SCORE_STATE_H
-#define __IMP_QUADRATIC_BIPARTITE_NONBONDED_LIST_SCORE_STATE_H
-
-#include "QuadraticNonbondedListScoreState.h"
-#include "../internal/ParticleGrid.h"
-#include "../internal/kernel_version_info.h"
-
-#include <vector>
-#include <limits>
-
-namespace IMP
-{
-
-//! This class maintains a list of non-bonded pairs between two sets.
-/** The class works roughly like the NonbondedListScoreState except
- only pairs where one particle is taken from each set are returned.
-
- \note QuadraticBipartiteNonbondedListScoreState is basically an
- implementation detail for performance analysis and should not
- be used by end users.
- */
-class IMPDLLEXPORT QuadraticBipartiteNonbondedListScoreState:
- public QuadraticNonbondedListScoreState
-{
- typedef QuadraticNonbondedListScoreState P;
- unsigned int na_;
-
- virtual void rebuild_nbl(float cut);
-public:
- QuadraticBipartiteNonbondedListScoreState(FloatKey rk,
- const Particles &ps0,
- const Particles &ps1);
- QuadraticBipartiteNonbondedListScoreState(FloatKey rk);
-
- IMP_SCORE_STATE(internal::kernel_version_info)
-
- void set_particles(const Particles &ps0, const Particles &ps1);
-};
-
-} // namespace IMP
-
-#endif /* __IMP_QUADRATIC_BIPARTITE_NONBONDED_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (working copy)
@@ -1,32 +1,92 @@
/**
* \file BipartiteNonbondedListScoreState.h
- * \brief Allow iteration through pairs of a set of atoms.
+ * \brief Bipartiteow iteration through pairs of a set of s.
*
- * Copyright 2007-8 Sali Lab. All rights reserved.
+ * Copyright 2007-8 Sali Lab. Bipartite rights reserved.
*/
#ifndef __IMP_BIPARTITE_NONBONDED_LIST_SCORE_STATE_H
#define __IMP_BIPARTITE_NONBONDED_LIST_SCORE_STATE_H
-#include "QuadraticBipartiteNonbondedListScoreState.h"
+#include "NonbondedListScoreState.h"
+#include "../internal/kernel_version_info.h"
+#include "MaxChangeScoreState.h"
+
namespace IMP
{
-//! Maintain a nonbonded list between two disjoint sets.
-/**
- \note If no value for the radius key is specified, all radii are
- considered to be zero.
- \ingroup restraint
+//! This class maintains a list of non-bonded pairs of spheres between two sets
+/** To iterate through the list of pairs use the NonbondedListScoreState::begin,
+ NonbondedListScoreState::end functions.
+
+ The radius key can be the default key.
+
+ Changes in coordinates and radii are handled properly.
+
+ \ingroup restraint
*/
-class BipartiteNonbondedListScoreState:
- public QuadraticBipartiteNonbondedListScoreState {
- typedef QuadraticBipartiteNonbondedListScoreState P;
+class IMPDLLEXPORT BipartiteNonbondedListScoreState:
+ public NonbondedListScoreState
+{
+ typedef NonbondedListScoreState P;
public:
- BipartiteNonbondedListScoreState(FloatKey rk,
+ //! What algorithm to use to perform the computations
+ enum Algorithm {
+ //! Check all pairs of particles to see if they are close enough
+ QUADRATIC,
+#ifdef IMP_USE_CGAL
+ //! Sweep space looking for intersecting bounding boxes.
+ BBOX,
+ DEFAULT= BBOX
+#else
+ DEFAULT= QUADRATIC
+#endif
+ };
+protected:
+ Algorithm a_;
+ internal::ObjectPointer<MaxChangeScoreState, true> mc0_, mc1_, mcr_;
+
+ void process_sets(const Particles &p0,
+ const Particles &p1);
+
+ //! \internal
+ void rebuild_nbl();
+public:
+ /**\param[in] cutoff The distance cutoff to use.
+ \param[in] radius The key to use to get the radius
+ \param[in] a Which algorithm to use. The default is the best.
+ */
+ BipartiteNonbondedListScoreState(Float cutoff, FloatKey radius,
+ Algorithm a=DEFAULT);
+ /**\param[in] cutoff The distance cutoff to use.
+ \param[in] radius The key to use to get the radius
+ \param[in] ps0 The first set.
+ \param[in] ps1 The second set.
+ \param[in] a Which algorithm to use. The default is the best.
+ */
+ BipartiteNonbondedListScoreState(Float cutoff,
+ FloatKey radius,
const Particles &ps0,
- const Particles &ps1): P(rk, ps0, ps1){}
- BipartiteNonbondedListScoreState(FloatKey rk): P(rk){}
+ const Particles &ps1,
+ Algorithm a=DEFAULT);
+
+ ~BipartiteNonbondedListScoreState();
+ IMP_SCORE_STATE(internal::kernel_version_info);
+
+ //! Add the particles to the first set
+ void add_particles_0(const Particles &ps);
+ //! Add the particles to the second set
+ void add_particles_1(const Particles &ps);
+ //! Remove all particles
+ void clear_particles();
+ //! Replace the set of particles
+ void set_particles(const Particles &ps0, const Particles &ps1);
+
+ /** If there is CGAL support, a more efficient algorithm BBOX can be used*/
+ void set_algorithm(Algorithm a) {
+ a_=a;
+ }
};
} // namespace IMP
Index: kernel/include/IMP/score_states/BondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/BondedListScoreState.h (working copy)
@@ -25,9 +25,6 @@
BondedListScoreState(){}
virtual ~BondedListScoreState(){}
- //! Set the set of particles used
- virtual void set_particles(const Particles &ps)=0;
-
//! Return true if the two particles are bonded
virtual bool are_bonded(Particle *a, Particle *b) const =0;
};
Index: kernel/include/IMP/score_states/QuadraticAllNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/QuadraticAllNonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/QuadraticAllNonbondedListScoreState.h (working copy)
@@ -1,49 +0,0 @@
-/**
- * \file QuadraticAllNonbondedListScoreState.h
- * \brief Allow iteration through pairs of a set of spheres.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#ifndef __IMP_QUADRATIC_ALL_NONBONDED_LIST_SCORE_STATE_H
-#define __IMP_QUADRATIC_ALL_NONBONDED_LIST_SCORE_STATE_H
-
-#include "NonbondedListScoreState.h"
-#include "../internal/kernel_version_info.h"
-#include "QuadraticNonbondedListScoreState.h"
-
-#include <vector>
-#include <limits>
-
-namespace IMP
-{
-
-//! This class maintains a list of non-bonded pairs of spheres
-/** \note QuadraticBipartiteNonbondedListScoreState is basically an
- implementation detail for performance analysis and should not
- be used by end users.
- */
-class IMPDLLEXPORT QuadraticAllNonbondedListScoreState:
- public QuadraticNonbondedListScoreState
-{
- typedef QuadraticNonbondedListScoreState P;
-
- //! \internal
- void rebuild_nbl(Float cut);
-
-public:
- /**
- \param[in] ps A list of particles to use.
- \param[in] radius The key to use to get the radius
- */
- QuadraticAllNonbondedListScoreState(FloatKey radius,
- const Particles &ps= Particles());
- ~QuadraticAllNonbondedListScoreState();
- IMP_SCORE_STATE(internal::kernel_version_info)
-
- void set_particles(const Particles &ps);
-};
-
-} // namespace IMP
-
-#endif /* __IMP_QUADRATIC_ALL_NONBONDED_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/ChainBondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/ChainBondedListScoreState.h (revision 0)
+++ kernel/include/IMP/score_states/ChainBondedListScoreState.h (revision 0)
@@ -0,0 +1,44 @@
+/**
+ * \file ChainBondedListScoreState.h
+ * \brief Allow iteration through pairs of a set of atoms.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ */
+
+#ifndef __IMP_CHAIN_BONDED_LIST_SCORE_STATE_H
+#define __IMP_CHAIN_BONDED_LIST_SCORE_STATE_H
+
+#include "BondedListScoreState.h"
+#include "../decorators/bond_decorators.h"
+#include "../internal/Vector.h"
+
+namespace IMP
+{
+
+//! Exclude consecutive particles in a chain.
+/** \ingroup bond
+ */
+class IMPDLLEXPORT ChainBondedListScoreState: public BondedListScoreState
+{
+ std::vector<internal::Vector<Particle*> > chains_;
+ IntKey cik_;
+ unsigned int next_index_;
+public:
+ //! Find bonds amongst the following points.
+ /** \param [in] ps The set of particles to use.
+ */
+ ChainBondedListScoreState();
+ virtual ~ChainBondedListScoreState(){}
+
+ void add_chain(const Particles &ps);
+
+ void clear_chains();
+
+ virtual bool are_bonded(Particle *a, Particle *b) const;
+
+ virtual void update();
+};
+
+} // namespace IMP
+
+#endif /* __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/AllNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/AllNonbondedListScoreState.h (revision 524)
+++ kernel/include/IMP/score_states/AllNonbondedListScoreState.h (working copy)
@@ -9,76 +9,93 @@
#define __IMP_ALL_NONBONDED_LIST_SCORE_STATE_H
#include "NonbondedListScoreState.h"
-#include "../internal/ParticleGrid.h"
#include "../internal/kernel_version_info.h"
-#include "MaxChangeScoreState.h"
+#include "../internal/Vector.h"
-#include <vector>
-#include <limits>
namespace IMP
{
-//! This class maintains a list of non-bonded pairs of particles
-/** \note If no value for the radius key is specified, all radii are
- considered to be zero.
+class MaxChangeScoreState;
+namespace internal
+{
+class ParticleGrid;
+}
- \note The radius is currently assumed not to change. This could
- be fixed later.
+//! This class maintains a list of non-bonded pairs of spheres
+/** To iterate through the list of pairs use the NonbondedListScoreState::begin,
+ NonbondedListScoreState::end functions.
- \todo The structure is slightly dumb about rebuilding and will
- rebuild the whole list of any of the grids become invalidated.
- This could be improved as each piece is computed separately (so
- they could be cached).
+ The radius key can be the default key.
+ Changes in coordinates and radii are handled properly unless grid is used,
+ then changes in radii may not be handled properly.
+
\ingroup restraint
*/
class IMPDLLEXPORT AllNonbondedListScoreState:
public NonbondedListScoreState
{
typedef NonbondedListScoreState P;
+ public:
+ //! What algorithm to use to perform the computations
+ enum Algorithm {
+ //! Check all pairs of particles to see if they are close enough
+ QUADRATIC,
+ GRID,
+ //! Sweep space looking for intersecting bounding boxes.
+ BBOX,
+ DEFAULT
+ };
protected:
- //! \internal
- struct Bin
- {
- internal::ParticleGrid *grid;
- Float rmax;
- Bin(): grid(NULL), rmax(-1){}
- Bin(const Bin &o): grid(o.grid), rmax(o.rmax){}
- };
- std::vector<Bin> bins_;
+ Algorithm a_;
+ internal::ObjectPointer<MaxChangeScoreState, true> mc_, mcr_;
+ internal::Vector<internal::ParticleGrid*> bins_;
+ void check_nbl() const;
+
//! \internal
- void rebuild_nbl(Float cut);
+ void rebuild_nbl();
- void repartition_points(const Particles &ps, std::vector<Bin> &out);
- float side_from_r(float r) const;
+ // methods for grid
+ void grid_rebuild_nbl();
- void generate_nbl(const Bin &particle_bin, const Bin &grid_bin, float cut);
+ void grid_partition_points();
- void cleanup(std::vector<Bin> &bins);
+ void grid_generate_nbl(const internal::ParticleGrid *particle_bin,
+ const internal::ParticleGrid *grid_bin);
+ float grid_side_from_r(float r) const;
public:
- /**
- \param[in] ps A list of particles to use.
+ /**\param[in] cutoff The distance cutoff to use.
\param[in] radius The key to use to get the radius
+ \param[in] a Which algorithm to use. The default is the best.
*/
- AllNonbondedListScoreState(FloatKey radius,
- const Particles &ps=Particles());
+ AllNonbondedListScoreState(Float cutoff,
+ FloatKey radius,
+ Algorithm a= DEFAULT);
+ /**\param[in] cutoff The distance cutoff to use.
+ \param[in] radius The key to use to get the radius
+ \param[in] ps A list of particles to use.
+ \param[in] a Which algorithm to use. The default is the best.
+ */
+ AllNonbondedListScoreState(Float cutoff,
+ FloatKey radius,
+ const Particles &ps,
+ Algorithm a= DEFAULT);
~AllNonbondedListScoreState();
- IMP_SCORE_STATE(internal::kernel_version_info)
+ IMP_SCORE_STATE(internal::kernel_version_info);
+ //! Add the particles and add them to the NBL
+ void add_particles(const Particles &ps);
+ //! Remove all particles
+ void clear_particles();
+ //! Replace the set of particles
void set_particles(const Particles &ps);
- //! Add a few particles to the nonbonded list
- /** Note that this invalidates the nonbonded list.
- \todo We could just add newly created pairs to the nonbonded list.
- */
- void add_particles(const Particles &ps);
-
- //! Return a list of all the particles used
- Particles get_particles() const;
+ /** If there is CGAL support, a more efficient algorithm BBOX can be used*/
+ void set_algorithm(Algorithm a);
};
} // namespace IMP
Index: kernel/src/score_states/BondDecoratorListScoreState.cpp
===================================================================
--- kernel/src/score_states/BondDecoratorListScoreState.cpp (revision 524)
+++ kernel/src/score_states/BondDecoratorListScoreState.cpp (working copy)
@@ -24,7 +24,7 @@
bonds_.clear();
for (unsigned int i=0; i< ps_.size(); ++i) {
if (!ps_[i]->get_is_active()) continue;
- BondedDecorator di= BondedDecorator::cast(ps_[i]);
+ BondedDecorator di(ps_[i]);
ParticleIndex pi= ps_[i]->get_index();
for (unsigned int j=0; j< di.get_number_of_bonds(); ++j) {
BondedDecorator dj= di.get_bonded(j);
Index: kernel/src/score_states/NonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/NonbondedListScoreState.cpp (revision 524)
+++ kernel/src/score_states/NonbondedListScoreState.cpp (working copy)
@@ -15,22 +15,27 @@
namespace IMP
{
-NonbondedListScoreState::NonbondedListScoreState(FloatKey rk): rk_(rk)
+NonbondedListScoreState
+::NonbondedListScoreState(Float cut,
+ FloatKey rk): rk_(rk),
+ cutoff_(cut),
+ nbl_is_valid_(false)
{
- last_cutoff_=-1;
+ slack_=10;
+ num_steps_=0;
}
-
-
-
-
-void NonbondedListScoreState::propagate_particles(const Particles&ps)
-{
- clear_nbl();
- for (BondedListScoreStateIterator bli= bonded_lists_begin();
- bli != bonded_lists_end(); ++bli) {
- (*bli)->set_particles(ps);
+Particles NonbondedListScoreState
+::particles_with_radius(const Particles &in) const {
+ Particles ret;
+ if (rk_== FloatKey()) return ret;
+ ret.reserve(in.size());
+ for (unsigned int i=0; i< in.size(); ++i) {
+ if (in[i]->has_attribute(rk_)) {
+ ret.push_back(in[i]);
+ }
}
+ return ret;
}
namespace internal
@@ -45,7 +50,7 @@
} // namespace internal
-void NonbondedListScoreState::update()
+bool NonbondedListScoreState::update(Float mc)
{
IMP_LOG(VERBOSE, "Updating non-bonded list" << std::endl);
for (BondedListScoreStateIterator bli= bonded_lists_begin();
@@ -53,9 +58,21 @@
(*bli)->update();
}
- // if the list is not deleted, we need to scan for inactive particles
- nbl_.erase(std::remove_if(nbl_.begin(), nbl_.end(), internal::HasInactive()),
- nbl_.end());
+ if (mc > slack_ || nbl_.size() ==0) {
+ num_steps_=0;
+ set_nbl_is_valid(false);
+ slack_= next_slack_;
+ rebuild_nbl();
+ return true;
+ } else {
+ // if the list is not deleted, we need to scan for inactive particles
+ nbl_.erase(std::remove_if(nbl_.begin(), nbl_.end(),
+ internal::HasInactive()),
+ nbl_.end());
+ ++num_steps_;
+ next_slack_= mc/num_steps_ * 100.0;
+ return false;
+ }
}
void NonbondedListScoreState::show(std::ostream &out) const
Index: kernel/src/score_states/QuadraticBipartiteNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/QuadraticBipartiteNonbondedListScoreState.cpp (revision 524)
+++ kernel/src/score_states/QuadraticBipartiteNonbondedListScoreState.cpp (working copy)
@@ -1,66 +0,0 @@
-/**
- * \file QuadraticBipartiteNonbondedListScoreState.cpp
- * \brief Allow iteration through pairs of a set of atoms.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#include "IMP/score_states/QuadraticBipartiteNonbondedListScoreState.h"
-#include "IMP/decorators/XYZDecorator.h"
-#include "IMP/score_states/MaxChangeScoreState.h"
-
-namespace IMP
-{
-
-QuadraticBipartiteNonbondedListScoreState
-::QuadraticBipartiteNonbondedListScoreState(FloatKey rk,
- const Particles &ps0,
- const Particles &ps1): P(rk)
-{
- set_particles(ps0, ps1);
-}
-
-
-QuadraticBipartiteNonbondedListScoreState
-::QuadraticBipartiteNonbondedListScoreState(FloatKey rk): P(rk)
-{
-}
-
-void QuadraticBipartiteNonbondedListScoreState::rebuild_nbl(float cut)
-{
- IMP_LOG(TERSE, "Rebuilding QBNBL with lists of size " << na_
- << " and " << P::get_particles().size() -na_
- << " and cutoff " << cut << std::endl);
- for (unsigned int i=0; i< na_; ++i) {
- for (unsigned int j=na_; j < P::get_particles().size(); ++j) {
- P::handle_nbl_pair(P::get_particles()[i],
- P::get_particles()[j],
- cut);
- }
- }
- IMP_LOG(TERSE, "NBL has " << P::nbl_.size() << " pairs" << std::endl);
-}
-
-void QuadraticBipartiteNonbondedListScoreState
-::set_particles(const Particles &ps0,
- const Particles &ps1)
-{
- IMP_LOG(TERSE, "Setting QBNBLSS particles " << ps0.size()
- << " and " << ps1.size() << std::endl);
- Particles all(ps0);
- all.insert(all.end(), ps1.begin(), ps1.end());
- P::set_particles(all);
- na_= ps0.size();
-}
-
-void QuadraticBipartiteNonbondedListScoreState::update()
-{
- P::update();
-}
-
-void QuadraticBipartiteNonbondedListScoreState::show(std::ostream &out) const
-{
- out << "QuadraticBipartiteNonbondedList" << std::endl;
-}
-
-} // namespace IMP
Index: kernel/src/score_states/BipartiteNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (revision 0)
+++ kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (revision 0)
@@ -0,0 +1,128 @@
+/**
+ * \file BipartiteNonbondedListScoreState.cpp
+ * \brief Bipartiteow iteration through pairs of a set of s.
+ *
+ * Copyright 2007-8 Sali Lab. Bipartite rights reserved.
+ */
+
+#include "IMP/score_states/BipartiteNonbondedListScoreState.h"
+#include "IMP/decorators/XYZDecorator.h"
+#include "IMP/internal/utility.h"
+#include "IMP/internal/bbox_nbl_helpers.h"
+
+#include <vector>
+
+namespace IMP
+{
+
+BipartiteNonbondedListScoreState
+::BipartiteNonbondedListScoreState(Float cut,
+ FloatKey rk,
+ Algorithm a):
+ P(cut, rk), a_(a)
+{
+ FloatKeys ks;
+ ks.push_back(rk);
+ mc0_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mc1_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mcr_= new MaxChangeScoreState(ks);
+}
+
+BipartiteNonbondedListScoreState
+::BipartiteNonbondedListScoreState(Float cut, FloatKey rk,
+ const Particles &ps0,
+ const Particles &ps1,
+ Algorithm a):
+ P(cut, rk), a_(a)
+{
+ FloatKeys ks;
+ ks.push_back(rk);
+ mc0_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mc1_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mcr_= new MaxChangeScoreState(ks);
+ set_particles(ps0, ps1);
+}
+
+
+BipartiteNonbondedListScoreState::~BipartiteNonbondedListScoreState(){}
+
+void BipartiteNonbondedListScoreState::update() {
+ mc0_->update();
+ mc0_->update();
+ mcr_->update();
+ Float mc= std::max(mc0_->get_max(), mc1_->get_max());
+ if (P::update(mc+ mcr_->get_max())) {
+ mc0_->reset();
+ mc1_->reset();
+ mcr_->reset();
+ }
+}
+
+void BipartiteNonbondedListScoreState::process_sets(const Particles &p0,
+ const Particles &p1) {
+ if (a_== QUADRATIC) {
+ for (unsigned int j=0; j< p0.size(); ++j) {
+ for (unsigned int i=0; i< p1.size(); ++i) {
+ P::add_if_box_overlap(p1[i], p0[j]);
+ }
+ }
+ }
+#ifdef IMP_USE_CGAL
+ else if (a_== BBOX) {
+ internal::bipartite_bbox_scan(p0, p1, P::get_radius_key(),
+ P::get_slack(), P::get_cutoff(),
+ internal::NBLAddPairIfNonbonded(this));
+
+ }
+#endif
+ }
+
+void BipartiteNonbondedListScoreState::rebuild_nbl() {
+ IMP_LOG(TERSE, "Rebuilding QNBL with cutoff "
+ << P::get_cutoff() << std::endl);
+ process_sets(mc0_->get_particles(), mc1_->get_particles());
+ P::set_nbl_is_valid(true);
+ IMP_LOG(TERSE, "NBL has " << P::number_of_nonbonded()
+ << " pairs" << std::endl);
+}
+
+void BipartiteNonbondedListScoreState::set_particles(const Particles &ps0,
+ const Particles &ps1) {
+ mc0_->clear_particles();
+ mc0_->add_particles(ps0);
+ mc1_->clear_particles();
+ mc1_->add_particles(ps1);
+ mcr_->clear_particles();
+ mcr_->add_particles(P::particles_with_radius(ps0));
+ mcr_->add_particles(P::particles_with_radius(ps1));
+ P::set_nbl_is_valid(false);
+}
+
+
+void BipartiteNonbondedListScoreState::add_particles_0(const Particles &ps) {
+ if (P::get_nbl_is_valid()) process_sets(ps, mc1_->get_particles());
+ mc0_->add_particles(ps);
+ mcr_->add_particles(P::particles_with_radius(ps));
+}
+
+void BipartiteNonbondedListScoreState::add_particles_1(const Particles &ps) {
+ if (P::get_nbl_is_valid()) process_sets(ps, mc0_->get_particles());
+ mc1_->add_particles(ps);
+ mcr_->add_particles(P::particles_with_radius(ps));
+}
+
+void BipartiteNonbondedListScoreState::clear_particles() {
+ mc0_->clear_particles();
+ mc1_->clear_particles();
+ mcr_->clear_particles();
+ P::set_nbl_is_valid(false);
+ P::set_nbl_is_valid(true);
+}
+
+
+void BipartiteNonbondedListScoreState::show(std::ostream &out) const
+{
+ out << "BipartiteNonbondedListScoreState" << std::endl;
+}
+
+} // namespace IMP
Index: kernel/src/score_states/SConscript
===================================================================
--- kernel/src/score_states/SConscript (revision 524)
+++ kernel/src/score_states/SConscript (working copy)
@@ -1,11 +1,10 @@
Import('env')
-
-files = ['NonbondedListScoreState.cpp',
- 'MaxChangeScoreState.cpp', 'BondDecoratorListScoreState.cpp',
- 'AllNonbondedListScoreState.cpp',
- 'QuadraticBipartiteNonbondedListScoreState.cpp',
- 'QuadraticAllNonbondedListScoreState.cpp',
- 'QuadraticNonbondedListScoreState.cpp', 'GravityCenterScoreState.cpp']
-
-files = [File(x) for x in files]
+files=[]
+files.append(File( 'AllNonbondedListScoreState.cpp' ))
+files.append(File( 'BipartiteNonbondedListScoreState.cpp' ))
+files.append(File( 'BondDecoratorListScoreState.cpp' ))
+files.append(File( 'ChainBondedListScoreState.cpp' ))
+files.append(File( 'GravityCenterScoreState.cpp' ))
+files.append(File( 'MaxChangeScoreState.cpp' ))
+files.append(File( 'NonbondedListScoreState.cpp' ))
Return('files')
Index: kernel/src/score_states/QuadraticAllNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/QuadraticAllNonbondedListScoreState.cpp (revision 524)
+++ kernel/src/score_states/QuadraticAllNonbondedListScoreState.cpp (working copy)
@@ -1,58 +0,0 @@
-/**
- * \file QuadraticAllNonbondedListScoreState.cpp
- * \brief Allow iteration through pairs of a set of s.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#include "IMP/score_states/QuadraticAllNonbondedListScoreState.h"
-#include "IMP/decorators/XYZDecorator.h"
-
-#include <algorithm>
-
-namespace IMP
-{
-
-
-QuadraticAllNonbondedListScoreState
-::QuadraticAllNonbondedListScoreState(FloatKey radius,
- const Particles &ps): P(radius)
-{
- set_particles(ps);
-}
-
-QuadraticAllNonbondedListScoreState::~QuadraticAllNonbondedListScoreState()
-{
-}
-
-void QuadraticAllNonbondedListScoreState::set_particles(const Particles &ps)
-{
- P::set_particles(ps);
-}
-
-
-void QuadraticAllNonbondedListScoreState::update()
-{
- P::update();
-}
-
-
-void QuadraticAllNonbondedListScoreState::rebuild_nbl(Float cut)
-{
- IMP_LOG(TERSE, "Rebuilding QNBL with cutoff " << cut << std::endl);
- const Particles &moving= P::get_particles();
- for (unsigned int j=0; j< moving.size(); ++j) {
- for (unsigned int i=0; i< j; ++i) {
- P::handle_nbl_pair(moving[i], moving[j], cut);
- }
- }
- IMP_LOG(TERSE, "NBL has " << P::nbl_.size() << " pairs" << std::endl);
-}
-
-
-void QuadraticAllNonbondedListScoreState::show(std::ostream &out) const
-{
- out << "QuadraticAllNonbondedListScoreState" << std::endl;
-}
-
-} // namespace IMP
Index: kernel/src/score_states/ChainBondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/ChainBondedListScoreState.cpp (revision 0)
+++ kernel/src/score_states/ChainBondedListScoreState.cpp (revision 0)
@@ -0,0 +1,64 @@
+/**
+ * \file ChainBondedListScoreState.cpp
+ * \brief Allow iteration through pairs of a set of atoms.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ */
+
+#include "IMP/score_states/ChainBondedListScoreState.h"
+
+#include <algorithm>
+#include <sstream>
+
+namespace IMP
+{
+
+ChainBondedListScoreState::ChainBondedListScoreState()
+{
+ std::ostringstream oss;
+ oss << "ChainBLSS " << this;
+ cik_= IntKey(oss.str().c_str());
+ next_index_=0;
+}
+
+void ChainBondedListScoreState::update()
+{
+ IMP_LOG(TERSE, "Updating ChainBondedList assumed to be static" << std::endl);
+}
+
+void ChainBondedListScoreState::clear_chains()
+{
+ for (unsigned int i=0; i< chains_.size(); ++i) {
+ for (unsigned int j=0; j< chains_[i].size(); ++j) {
+ chains_[i][j]->set_value(cik_, -1);
+ }
+ }
+ chains_.clear();
+ next_index_=0;
+}
+
+void ChainBondedListScoreState::add_chain(const Particles &ps)
+{
+ chains_.push_back(internal::Vector<Particle*>(ps.begin(), ps.end()));
+ for (unsigned int i=0; i< chains_.back().size(); ++i) {
+ Particle *p= chains_.back()[i];
+ if (p->has_attribute(cik_)) {
+ p->set_value(cik_, next_index_);
+ } else {
+ p->add_attribute(cik_, next_index_);
+ }
+ ++next_index_;
+ }
+ ++next_index_;
+}
+
+
+bool ChainBondedListScoreState::are_bonded(Particle *a, Particle *b) const
+{
+ if (!a->has_attribute(cik_) || !b->has_attribute(cik_)) return false;
+ int ia= a->get_value(cik_);
+ int ib= b->get_value(cik_);
+ return std::abs(ia-ib) ==1;
+}
+
+} // namespace IMP
Index: kernel/src/score_states/MaxChangeScoreState.cpp
===================================================================
--- kernel/src/score_states/MaxChangeScoreState.cpp (revision 524)
+++ kernel/src/score_states/MaxChangeScoreState.cpp (working copy)
@@ -31,12 +31,15 @@
IMP_LIST_IMPL(MaxChangeScoreState, Particle, particle, Particle*,
{for (unsigned int i=0; i< keys_.size(); ++i) {
IMP_check(obj->has_attribute(keys_[i]),
- "Particle missing needed attribute",
+ "Particle missing needed attribute " << keys_[i]
+ << obj,
ValueException("Particle missing attribute"));
};
for (unsigned int i=0; i< origkeys_.size(); ++i) {
- obj->add_attribute(origkeys_[i],
- obj->get_value(keys_[i]), false);
+ if (!obj->has_attribute(origkeys_[i])) {
+ obj->add_attribute(origkeys_[i],
+ obj->get_value(keys_[i]), false);
+ }
}
}, {reset();});
Index: kernel/src/score_states/AllNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/AllNonbondedListScoreState.cpp (revision 524)
+++ kernel/src/score_states/AllNonbondedListScoreState.cpp (working copy)
@@ -7,101 +7,170 @@
#include "IMP/score_states/AllNonbondedListScoreState.h"
#include "IMP/decorators/XYZDecorator.h"
+#include "IMP/internal/utility.h"
+#include "IMP/internal/bbox_nbl_helpers.h"
-#include <algorithm>
+#include <vector>
namespace IMP
{
-static unsigned int min_grid_size=20;
+// Turn the default into an actuall algorithm and work around missing algorithms
+static AllNonbondedListScoreState::Algorithm
+translate_algorithm(AllNonbondedListScoreState::Algorithm a){
+#ifdef IMP_USE_CGAL
+ switch (a) {
+ case AllNonbondedListScoreState::DEFAULT:
+ return AllNonbondedListScoreState::BBOX;
+ default:
+ return a;
+ }
+#else
+ switch (a) {
+ case AllNonbondedListScoreState::BBOX:
+ IMP_WARN("AllNonbondedListScoreState::BBOX requires CGAL support. "
+ << "GRID used instead." << std::endl);
+ case AllNonbondedListScoreState::DEFAULT:
+ return AllNonbondedListScoreState::GRID;
+ default:
+ return a;
+ }
+#endif
+}
-AllNonbondedListScoreState
-::AllNonbondedListScoreState(FloatKey radius, const Particles &ps):
- P(radius)
+AllNonbondedListScoreState::AllNonbondedListScoreState(Float cut,
+ FloatKey rk,
+ const Particles &ps,
+ Algorithm a):
+ P(cut, rk), a_(translate_algorithm(a))
{
- set_particles(ps);
+ FloatKeys ks;
+ ks.push_back(rk);
+ mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mcr_= new MaxChangeScoreState(ks);
+ add_particles(ps);
}
-
-AllNonbondedListScoreState::~AllNonbondedListScoreState()
+AllNonbondedListScoreState::AllNonbondedListScoreState(Float cut,
+ FloatKey rk,
+ Algorithm a):
+ P(cut, rk), a_(translate_algorithm(a))
{
- cleanup(bins_);
+ FloatKeys ks;
+ ks.push_back(rk);
+ mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ mcr_= new MaxChangeScoreState(ks);
}
-float AllNonbondedListScoreState::side_from_r(float r) const
-{
- if (r==0) return 1;
- else return r*1.6;
+AllNonbondedListScoreState::~AllNonbondedListScoreState(){
}
-Particles AllNonbondedListScoreState::get_particles() const
-{
- Particles ret;
- for (unsigned int i=0; i< bins_.size(); ++i) {
- ret.insert(ret.end(), bins_[i].grid->get_particles().begin(),
- bins_[i].grid->get_particles().end());
+void AllNonbondedListScoreState::update() {
+ mc_->update();
+ mcr_->update();
+ Float mc=mc_->get_max()+ mcr_->get_max();
+ if (P::update(mc)) {
+ mc_->reset();
}
- return ret;
}
-void AllNonbondedListScoreState::set_particles(const Particles &ps)
-{
- NonbondedListScoreState::clear_nbl();
- cleanup(bins_);
- repartition_points(ps, bins_);
-}
-void AllNonbondedListScoreState::add_particles(const Particles &ps)
-{
- if (bins_.empty()) set_particles(ps);
- else {
-#ifndef NDEBUG
- for (unsigned int i=0; i< ps.size(); ++i) {
- for (unsigned int j=0; j< bins_.size(); ++j) {
- for (unsigned int k=0; k< bins_[j].grid->get_particles().size(); ++k) {
- IMP_assert(ps[i] != bins_[j].grid->get_particles()[k],
- "Can't add a particle that is already there");
-
- IMP_assert(ps[i]->get_index()
- != bins_[j].grid->get_particles()[k]->get_index(),
- "Same particle index, different particles.");
- }
+void AllNonbondedListScoreState::rebuild_nbl() {
+ IMP_LOG(TERSE, "Rebuilding QNBL with cutoff "
+ << P::get_cutoff() << std::endl);
+ if (a_== QUADRATIC) {
+ const Particles &moving= mc_->get_particles();
+ for (unsigned int j=0; j< moving.size(); ++j) {
+ for (unsigned int i=0; i< j; ++i) {
+ P::add_if_box_overlap(moving[i], moving[j]);
}
}
+ } else if (a_ == GRID) {
+ grid_rebuild_nbl();
+ } else if (a_== BBOX) {
+ internal::bbox_scan(mc_->get_particles(), P::get_radius_key(),
+ P::get_slack(), P::get_cutoff(),
+ internal::NBLAddPairIfNonbonded(this));
+
+ } else {
+ IMP_failure("Bad algorithm in AllNBL::rebuild", ErrorException());
+ }
+ set_nbl_is_valid(true);
+#ifndef NDEBUG
+ check_nbl();
#endif
+ IMP_LOG(TERSE, "NBL has " << P::number_of_nonbonded()
+ << " pairs" << std::endl);
+}
- for (unsigned int i=0; i< ps.size(); ++i) {
- float r= P::get_radius(ps[i]);
- bool found=false;
- for (unsigned int j=0; j< bins_.size(); ++j) {
- if (bins_[j].rmax >= r) {
- found=true;
- IMP_LOG(VERBOSE, "Adding particle "
- << ps[i]->get_index() << " to bin " << j << std::endl);
- bins_[j].grid->add_particle(ps[i]);
- break;
+void AllNonbondedListScoreState::set_particles(const Particles &ps) {
+ mc_->clear_particles();
+ mc_->add_particles(ps);
+ mcr_->clear_particles();
+ mcr_->add_particles(particles_with_radius(ps));
+ P::set_nbl_is_valid(false);
+}
+
+
+void AllNonbondedListScoreState::add_particles(const Particles &ps) {
+ if (P::get_nbl_is_valid()) {
+ if (a_== QUADRATIC || a_ == GRID) {
+ const Particles &moving= mc_->get_particles();
+ for (unsigned int j=0; j< moving.size(); ++j) {
+ for (unsigned int i=0; i< ps.size(); ++i) {
+ P::add_if_box_overlap(ps[i], moving[j]);
}
}
- if (!found) {
- bins_.back().rmax=r;
- bins_.back().grid->add_particle(ps[i]);
- }
+ } else if (a_== BBOX) {
+ internal::bipartite_bbox_scan(mc_->get_particles(), ps,
+ P::get_radius_key(),
+ P::get_slack(), P::get_cutoff(),
+ internal::NBLAddPairIfNonbonded(this));
}
}
- IMP_LOG(TERSE, "Destroying nbl in list due to additions"<< std::endl);
- NonbondedListScoreState::clear_nbl();
+ mcr_->add_particles(particles_with_radius(ps));
+ mc_->add_particles(ps);
}
+void AllNonbondedListScoreState::clear_particles() {
+ mc_->clear_particles();
+ mcr_->clear_particles();
+ P::set_nbl_is_valid(false);
+ P::set_nbl_is_valid(true);
+}
-void AllNonbondedListScoreState::repartition_points(const Particles &ps,
- std::vector<Bin> &out)
+void AllNonbondedListScoreState::show(std::ostream &out) const
{
- cleanup(out);
- if (ps.empty()) return;
+ out << "AllNonbondedListScoreState" << std::endl;
+}
+
+
+void AllNonbondedListScoreState::set_algorithm(Algorithm a) {
+ a_=translate_algorithm(a);
+ if (a_!= GRID) {
+ bins_.clear();
+ }
+}
+
+
+// methods for grid
+
+static unsigned int min_grid_size=20;
+
+float AllNonbondedListScoreState::grid_side_from_r(float r) const
+{
+ if (r==0) return 1;
+ else return r*1.6;
+}
+
+void AllNonbondedListScoreState::grid_partition_points()
+{
+ bins_.clear();
+ if (mc_->get_particles().empty()) return;
float minr=std::numeric_limits<float>::max(), maxr=0;
- for (unsigned int i=0; i< ps.size(); ++i) {
- float r= P::get_radius(ps[i]);
+ for (unsigned int i=0; i< mc_->get_particles().size(); ++i) {
+ float r= P::get_radius(mc_->get_particles()[i]);
if ( r > maxr) maxr=r;
if ( r > 0 && r < minr) minr=r;
}
@@ -116,13 +185,13 @@
cuts.push_back(2*maxr);
std::vector<Particles> ops(cuts.size());
- for (unsigned int i=0; i< ps.size(); ++i) {
- float r= P::get_radius(ps[i]);
+ for (unsigned int i=0; i< mc_->get_particles().size(); ++i) {
+ float r= P::get_radius(mc_->get_particles()[i]);
bool found=false;
for (unsigned int j=0; ; ++j) {
IMP_assert(j< cuts.size(), "Internal error in ASNBLSS");
if (cuts[j] >= r) {
- ops[j].push_back(ps[i]);
+ ops[j].push_back(mc_->get_particles()[i]);
found=true;
break;
}
@@ -138,156 +207,110 @@
}
for (unsigned int i=0; i< cuts.size(); ++i) {
if (ops[i].empty()) continue;
- out.push_back(Bin());
float rmax=0;
for (unsigned int j=0; j< ops[i].size(); ++j) {
rmax= std::max(rmax, P::get_radius(ops[i][j]));
}
- out.back().rmax= rmax;
- internal::ParticleGrid *pg
- = new internal::ParticleGrid(side_from_r(out.back().rmax));
- out.back().grid= pg;
- out.back().grid->add_particles(ops[i]);
+ bins_.push_back(new internal::ParticleGrid(grid_side_from_r(rmax), ops[i]));
}
- IMP_LOG(VERBOSE, "Created " << out.size() << " grids" << std::endl);
- for (unsigned int i=0; i< out.size(); ++i) {
- IMP_LOG(VERBOSE, out[i].rmax
- << ": " << *out[i].grid << std::endl);
+ IMP_LOG(VERBOSE, "Created " << bins_.size() << " grids" << std::endl);
+ for (unsigned int i=0; i< bins_.size(); ++i) {
+ IMP_LOG(VERBOSE, *bins_[i] << std::endl);
}
-
-#ifndef NDEBUG
- Particles all;
- for (unsigned int i=0; i< out.size(); ++i) {
- all.insert(all.end(), out[i].grid->get_particles().begin(),
- out[i].grid->get_particles().end());
- }
- std::sort(all.begin(), all.end());
- Particles::iterator it = std::unique(all.begin(), all.end());
- IMP_assert(it == all.end(), "Duplicate particles " << all.size());
- IMP_assert(all.size() == ps.size(), "Wrong number of particles at end "
- << all.size() << " " << ps.size());
-#endif
}
-void AllNonbondedListScoreState::cleanup(std::vector<Bin> &bins)
-{
- for (unsigned int i=0; i< bins.size(); ++i) {
- delete bins[i].grid;
- }
- bins.clear();
-}
-void AllNonbondedListScoreState::update()
+void AllNonbondedListScoreState
+::grid_generate_nbl(const internal::ParticleGrid *particle_bin,
+ const internal::ParticleGrid *grid_bin)
{
- IMP_LOG(TERSE, "Updating nonbonded list"<< std::endl);
- NonbondedListScoreState::update();
- bool bad=false;
- for (unsigned int i=0; i< bins_.size(); ++i) {
- bad = bins_[i].grid->update() || bad;
- IMP_LOG(VERBOSE, bins_[i].rmax << std::endl << *bins_[i].grid << std::endl);
- }
- if (bad) {
- IMP_LOG(TERSE, "Destroying nbl in list"<< std::endl);
- NonbondedListScoreState::clear_nbl();
- }
-}
-
-void AllNonbondedListScoreState::generate_nbl(const Bin &particle_bin,
- const Bin &grid_bin,
- float cut)
-{
- IMP_CHECK_OBJECT(particle_bin.grid);
- IMP_CHECK_OBJECT(grid_bin.grid);
- IMP_LOG(VERBOSE, "Generate nbl for " << particle_bin.rmax
- << " and " << grid_bin.rmax << std::endl);
- for (unsigned int k=0; k< particle_bin.grid->get_particles().size(); ++k) {
- Particle *p= particle_bin.grid->get_particles()[k];
- NonbondedListScoreState::AddToNBL f(this, p);
+ IMP_CHECK_OBJECT(particle_bin);
+ IMP_CHECK_OBJECT(grid_bin);
+ IMP_LOG(VERBOSE, "Generate nbl for pair " << std::endl);
+ for (internal::ParticleGrid::ParticleVoxelIterator
+ it= particle_bin->particle_voxels_begin();
+ it != particle_bin->particle_voxels_end(); ++it) {
+ Particle *p= it->first;
+ internal::NBLAddIfNonbonded f(this, p);
XYZDecorator d= XYZDecorator::cast(p);
internal::ParticleGrid::VirtualIndex index
- = grid_bin.grid->get_virtual_index(Vector3D(d.get_x(),
- d.get_y(),
- d.get_z()));
+ = grid_bin->get_virtual_index(Vector3D(d.get_x(),
+ d.get_y(),
+ d.get_z()));
IMP_LOG(VERBOSE, "Searching for " << p->get_index()
- << " from " << index
- << " of bin " << grid_bin.rmax << std::endl);
- grid_bin.grid->apply_to_nearby(f, index,
- cut+2*particle_bin.rmax + grid_bin.rmax,
- false);
+ << " from " << index << std::endl);
+ grid_bin->apply_to_nearby(f, index,
+ P::get_cutoff() + 2*P::get_slack(),
+ false);
}
}
-void AllNonbondedListScoreState::rebuild_nbl(Float cut)
+void AllNonbondedListScoreState::grid_rebuild_nbl()
{
- IMP_LOG(TERSE, "Rebuilding NBL with " << bins_.size() << " bins"
- << " and cutoff " << cut << std::endl);
+ IMP_LOG(TERSE, "Rebuilding NBL with Grid and cutoff "
+ << P::get_cutoff() << std::endl );
+ grid_partition_points();
+
for (unsigned int i=0; i< bins_.size(); ++i) {
for (unsigned int j=i+1; j< bins_.size(); ++j) {
- generate_nbl(bins_[i], bins_[j], cut);
+ grid_generate_nbl(bins_[i], bins_[j]);
}
internal::ParticleGrid::Index last_index;
for (internal::ParticleGrid::ParticleVoxelIterator it
- = bins_[i].grid->particle_voxels_begin();
- it != bins_[i].grid->particle_voxels_end(); ++it) {
+ = bins_[i]->particle_voxels_begin();
+ it != bins_[i]->particle_voxels_end(); ++it) {
IMP_LOG(VERBOSE, "Searching with particle " << it->first->get_index()
<< std::endl);
- NonbondedListScoreState::AddToNBL f(this, it->first);
- bins_[i].grid->apply_to_nearby(f, it->second,
- cut+3*bins_[i].rmax,
+ internal::NBLAddIfNonbonded f(this, it->first);
+ bins_[i]->apply_to_nearby(f, it->second,
+ P::get_cutoff()+2*P::get_slack(),
true);
+
if (it->second != last_index) {
+ internal::NBLAddPairIfNonbonded fp(this);
IMP_LOG(VERBOSE, "Searching in " << it->second
<< std::endl);
- bins_[i].grid->apply_to_cell_pairs(f, it->second);
+ bins_[i]->apply_to_cell_pairs(fp, it->second);
}
last_index=it->second;
}
}
- IMP_LOG(TERSE, "NBL has " << P::nbl_.size() << " pairs" << std::endl);
+ bins_.clear();
+ IMP_LOG(TERSE, "NBL has " << P::number_of_nonbonded()
+ << " pairs" << std::endl);
+}
-#ifndef NDEBUG
- {
- Particles ps;
- for (unsigned int i=0; i< bins_.size(); ++i) {
- if (bins_[i].grid) {
- ps.insert(ps.end(), bins_[i].grid->get_particles().begin(),
- bins_[i].grid->get_particles().end());
- }
- }
- for (unsigned int i=0; i< ps.size(); ++i) {
- XYZDecorator di= XYZDecorator::cast(ps[i]);
- for (unsigned int j=0; j< i; ++j) {
- XYZDecorator dj= XYZDecorator::cast(ps[j]);
- IMP_assert(ps[i] != ps[j], "Duplicate particles in grid");
- if (distance(di, dj) - P::get_radius(ps[i]) - P::get_radius(ps[j])
- <= cut && !are_bonded(ps[i], ps[j])) {
- bool found=false;
- for (NonbondedIterator nit= nbl_.begin();
- nit != nbl_.end(); ++nit) {
- if (nit->first == ps[i] && nit->second == ps[j]
- || nit->first == ps[j] && nit->second == ps[i]) {
- IMP_assert(!found, "Entry is in list twice");
- found=true;
- }
+
+// debugging
+void AllNonbondedListScoreState::check_nbl() const
+{
+ const Particles &ps= mc_->get_particles();
+ for (unsigned int i=0; i< ps.size(); ++i) {
+ XYZDecorator di= XYZDecorator::cast(ps[i]);
+ for (unsigned int j=0; j< i; ++j) {
+ XYZDecorator dj= XYZDecorator::cast(ps[j]);
+ IMP_assert(ps[i] != ps[j], "Duplicate particles in grid");
+ if (distance(di, dj) - P::get_radius(ps[i]) - P::get_radius(ps[j])
+ <= P::get_cutoff() && !are_bonded(ps[i], ps[j])) {
+ bool found=false;
+ for (NonbondedIterator nit= P::nonbonded_begin();
+ nit != P::nonbonded_end(); ++nit) {
+ if (nit->first == ps[i] && nit->second == ps[j]
+ || nit->first == ps[j] && nit->second == ps[i]) {
+ IMP_assert(!found, "Entry is in list twice");
+ found=true;
}
- IMP_assert(found, "Nonbonded list is missing "
- << ps[i]->get_index() << " " << di
- << " and " << ps[j]->get_index() << " "
- << dj << std::endl);
}
+ IMP_assert(found, "Nonbonded list is missing "
+ << ps[i]->get_index() << " " << di
+ << " and " << ps[j]->get_index() << " "
+ << dj << std::endl);
}
}
}
-#endif
}
-
-void AllNonbondedListScoreState::show(std::ostream &out) const
-{
- out << "AllNonbondedListScoreState" << std::endl;
-}
-
} // namespace IMP
Index: kernel/src/score_states/QuadraticNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/QuadraticNonbondedListScoreState.cpp (revision 524)
+++ kernel/src/score_states/QuadraticNonbondedListScoreState.cpp (working copy)
@@ -1,60 +0,0 @@
-/**
- * \file QuadraticNonbondedListScoreState.cpp
- * \brief Allow iteration through pairs of a set of s.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- */
-
-#include "IMP/score_states/QuadraticNonbondedListScoreState.h"
-#include "IMP/decorators/XYZDecorator.h"
-
-#include <algorithm>
-
-namespace IMP
-{
-
-QuadraticNonbondedListScoreState
-::QuadraticNonbondedListScoreState(FloatKey radius):
- P(radius), slack_(.1)
-{
- mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
-}
-
-QuadraticNonbondedListScoreState::~QuadraticNonbondedListScoreState()
-{
-}
-
-
-void QuadraticNonbondedListScoreState::update()
-{
- // placeholder to do tuning of slack
- NonbondedListScoreState::update();
- if (mc_->get_max() > slack_) {
- NonbondedListScoreState::clear_nbl();
- mc_->reset();
- }
-}
-
-void QuadraticNonbondedListScoreState
-::handle_nbl_pair( Particle *a, Particle *b,
- float d)
-{
- XYZDecorator da= XYZDecorator::cast(a);
- XYZDecorator db= XYZDecorator::cast(b);
- float ra= P::get_radius(a);
- float rb= P::get_radius(b);
- for (unsigned int i=0; i< 3; ++i) {
- float delta=std::abs(da.get_coordinate(i) - db.get_coordinate(i));
- if (delta -ra -rb > d-slack_) {
- IMP_LOG(VERBOSE, "Pair " << a->get_index()
- << " and " << b->get_index() << " rejected on coordinate "
- << i << std::endl);
- return ;
- }
- }
- IMP_LOG(VERBOSE, "Adding pair " << a->get_index()
- << " and " << b->get_index() << std::endl);
- P::add_to_nbl(a, b);
-}
-
-} // namespace IMP
Index: kernel/include/IMP/internal/ParticleGrid.h
===================================================================
--- kernel/include/IMP/internal/ParticleGrid.h (revision 524)
+++ kernel/include/IMP/internal/ParticleGrid.h (working copy)
@@ -25,26 +25,18 @@
// don't need ref counting since mc_ has the same set of points
typedef internal::Grid3D<Particles> Grid;
Grid grid_;
- internal::ObjectPointer<MaxChangeScoreState, true> mc_;
Float target_voxel_side_;
- bool grid_valid_;
- void build_grid();
+ void build_grid(const Particles &ps);
void audit_particles(const Particles &ps) const;
void add_particle_to_grid(Particle *p);
public:
ParticleGrid();
//! suggested grid edge size.
- ParticleGrid(Float sz);
+ ParticleGrid(Float sz, const Particles &ps);
Float get_voxel_size() const {return target_voxel_side_;}
- void add_particles(const Particles &ps);
- void add_particle(Particle *p);
- void clear_particles();
- const Particles& get_particles() const {return mc_->get_particles();}
- bool update();
-
void show(std::ostream &out) const;
typedef Grid::VirtualIndex VirtualIndex;
Index: kernel/src/internal/ParticleGrid.cpp
===================================================================
--- kernel/src/internal/ParticleGrid.cpp (revision 524)
+++ kernel/src/internal/ParticleGrid.cpp (working copy)
@@ -18,19 +18,20 @@
static const int target_cell_occupancy=10;
-ParticleGrid::ParticleGrid(float tvs): target_voxel_side_(tvs),
- grid_valid_(false)
+ ParticleGrid::ParticleGrid(float tvs,
+ const Particles &ps): target_voxel_side_(tvs)
{
IMP_assert(tvs >0, "Target voxel edge size must be positive");
- mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
+ build_grid(ps);
}
-ParticleGrid::ParticleGrid(): target_voxel_side_(0), grid_valid_(0)
+ParticleGrid::ParticleGrid(): target_voxel_side_(0)
{
}
-void ParticleGrid::build_grid()
+void ParticleGrid::build_grid(const Particles &ps)
{
+ audit_particles(ps);
IMP_LOG(TERSE, "Creating nonbonded grid..." << std::flush);
float mn[3]= {std::numeric_limits<float>::max(),
std::numeric_limits<float>::max(),
@@ -38,19 +39,19 @@
float mx[3]={-std::numeric_limits<float>::max(),
-std::numeric_limits<float>::max(),
-std::numeric_limits<float>::max()};
- for (unsigned int i = 0; i < mc_->get_particles().size(); ++i) {
- XYZDecorator d= XYZDecorator::cast(mc_->get_particles()[i]);
+ for (unsigned int i = 0; i < ps.size(); ++i) {
+ XYZDecorator d(ps[i]);
for (unsigned int j=0; j<3; ++j) {
if (d.get_coordinate(j)< mn[j]) mn[j]= d.get_coordinate(j);
if (d.get_coordinate(j)> mx[j]) mx[j]= d.get_coordinate(j);
}
}
- if (!mc_->get_particles().empty()) {
+ if (!ps.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<float>(target_cell_occupancy
*(maxdim*maxdim*maxdim
- /mc_->get_particles().size())),
+ /ps.size())),
.3333f);
if (vx > target_voxel_side_) {
IMP_LOG(VERBOSE, "Overroade target side of " << target_voxel_side_
@@ -62,89 +63,16 @@
Vector3D(mn[0], mn[1], mn[2]),
Vector3D(mx[0], mx[1], mx[2]),
Particles());
- for (unsigned int i = 0; i < mc_->get_particles().size(); ++i) {
- XYZDecorator d= XYZDecorator::cast(mc_->get_particles()[i]);
+ for (unsigned int i = 0; i < ps.size(); ++i) {
+ XYZDecorator d(ps[i]);
Vector3D v(d.get_x(), d.get_y(), d.get_z());
- grid_.get_voxel(grid_.get_index(v)).push_back(mc_->get_particles()[i]);
+ grid_.get_voxel(grid_.get_index(v)).push_back(ps[i]);
}
- grid_valid_=true;
- mc_->reset();
IMP_LOG(TERSE, "done." << std::endl);
}
-void ParticleGrid::add_particles(const Particles &ps)
-{
- audit_particles(ps);
- mc_->add_particles(ps);
- for (unsigned int i=0; i< ps.size(); ++i) {
- if (grid_valid_) {
- add_particle_to_grid(ps[i]);
- }
- }
-}
-void ParticleGrid::add_particle(Particle *p)
-{
- Particles ps(1, p);
- audit_particles(ps);
- mc_->add_particle(p);
-
- if (grid_valid_) {
- add_particle_to_grid(p);
- }
-}
-
-void ParticleGrid::add_particle_to_grid(Particle *p)
-{
- IMP_assert(grid_valid_, "Bad call of add particle to grid");
- XYZDecorator d= XYZDecorator::cast(p);
- Vector3D v(d.get_x(), d.get_y(), d.get_z());
- Grid::VirtualIndex vi= grid_.get_virtual_index(v);
- Grid::Index gi= grid_.get_index(vi);
- if (gi== Grid::Index()) {
- IMP_LOG(TERSE, "Adding particle off grid invalidates it "
- << v << " " << vi << std::endl);
- grid_valid_=false;
- grid_ = Grid();
- } else {
- grid_.get_voxel(gi).push_back(p);
- }
-}
-
-void ParticleGrid::clear_particles()
-{
- mc_->clear_particles();
-}
-
-bool ParticleGrid::update()
-{
- bool ret;
- if (!grid_valid_ || mc_->get_max() > target_voxel_side_) {
- IMP_LOG(TERSE, "Rebuilding particle grid\n");
- build_grid();
- ret= true;
- } else {
- IMP_LOG(TERSE, "Removing inactive particles\n");
- for (Grid::DataIterator dit= grid_.data_begin(); dit != grid_.data_end();
- ++dit) {
- remove_inactive_particles(*dit);
- }
- ret= false;
- }
- unsigned int ssz=0;
- for (Grid::DataIterator dit= grid_.data_begin(); dit != grid_.data_end();
- ++dit) {
- ssz+= dit->size();
- }
- // do this last since it has the ref counts
- mc_->update();
-
- IMP_assert(ssz== mc_->number_of_particles(), "Particle mismatch in PG");
-
- return ret;
-}
-
void ParticleGrid::audit_particles(const Particles &ps) const
{
for (unsigned int i=0; i< ps.size(); ++i) {
5
57
I have fixed a few bugs so I thought I should submit things. This
email lists the changes in addition to the un checked in ones from the
last patch.
API Changes:
- UnaryFunctions::evaluate_derivative now returns a pair of Floats
alleviating the need to use the swig hack and making the C++ and swig
syntax identical. Python code doesn't need to change but C++ code
does. I suggest using boost::tie(value, deriv) (from boost/tuple/
tuple.hpp) to capture the return values for minimal code change. This
one glues lots of the disparate changes together.
- the TransformPairScore has changed a bit to now functions take
Vector3Ds instead of three floats
- The randomize functions have been moved out of XYZDecorator into
Vector3D.h. This is a more generally useful location for them (which
did not exist when I first wrote them). Calls to
XYZDecorator::randomize_in_box should be replaced with calls to
XYZDecorator::set_coordinates(random_vector_in_box(lb, ub))
- per Ben's suggestion, the hierarchy_ and molecular_hierarchy_
prefixes were removed from some function names
Bug fixes:
- fixed the get_foos documentation
- fixed the hierarchy_get_internal_bonds function, which was not
finding all bonds before
- circular ref counted pointers with Optimizers/optimizer states.
Likewise for Model/Particle, Model/ScoreState (for when Model is
refcounted)
- BallMover was broken in the IMP repository. I shouldn't return
things by passing references to functions as one can easily loose the
return value.
Additions:
- There is a restraint which uses the Lowest n of a set of pair scores.
- an is_nan function which uses the built in one when compiling with
gcc and the lack of self equality check otherwise. Various places use
it now.
- a ParticleRefinerGuard which makes sure the refine and cleanup
functions are called in pairs by calling cleanup in its destructor.
- The BondCoverPartirticleRefiner takes an IntKey whose value is
propagated to the particles for use with the typed pair score
Not submitted things that might be useful:
- A mover to do kmeans clustering. This perhaps should be split into a
score state for storing the clustering and a mover to move things to
the center.
- a particle refiner that uses a lookup table
- a pair score which refines pairs of particles which are close under
some metric (can be used for hierarchical collision detection
- a pair score on the distance between two cylinders
- an optimization harness which runs various copies of your
optimization (in parallel if you have multiple cores at your disposal)
and keeps track of the best results.
The rest is various cleanups and new test cases and some extra checks
to avoid misuse. I also think that the BondCoverParticleRefiner should
be removed as it is not as interesting as hoped.
1
0
hi,
For some reason iterating over restraints like:
for(Restraints::iterator it = opt_mdl->get_restraints().begin();
it != opt_mdl->get_restraints().end(); it++) {
}
fails as *it == NULL, even though it contains data.
The problem is solved if iterating like:
for(unsigned int i =0;i<opt_mdl->get_restraints().size();i++){}
Keren.
3
5
People who are doing pseudo-atomic modeling may want to look at the
Martini force field. It uses several spheres per residue and allows
once to go back and forth between fully atomic and reduced
representations in many circumstances. Klaus Schulten's group has been
using it for various things and is participating in developing it.
1
0
These huge patch includes a few API changes, so please read the next
section. It includes all changes that were not checked in yet from the
last patch.
The patch includes automatically generated SConscript and IMP.h files
and all the tests pass.
API changes:
- The constructors for the nonbonded lists no longer take the radius key
as an argument. They default to XYZRDecorator::get_radius_key and the
value can be set using the set_radius_key method
- UnaryFunctions and Scores now have const evaluate methods. Things have
been updated accordingly. Note that errors in python about having the
wrong number of arguments for the constructor probably are a result of
pure virtual methods caused by the class not matching its parent any more.
- The arguments to the constructor of Linear were swapped to make it
more similar to Harmonic.
- IMP_failure takes an exception type as the third argument (rather than
an exception-typed expression)
- More changes to the names of the hierarchy and molecular hierarchy
decorator functions to make them more consistent. Those should be stable now
- TunnelRestraint is now TunnelSingletonScore. Not sure why I made it a
restraint before.
- As before there is now a ManualBondDecoratorListScoreState which is a
base class for the old one and doesn't scan for new bonds.
- PairChainListRestraint only supports one chain as was discussed
previously.
- Various methods were moved out of the IMP.Test class into IMP.test so
they can be used outside of the test class itself (for example in test
restraints)
API additions:
- Added an XYZRDecorator which has a radius and some functionality on
spheres. The various things which take radius keys now default to the
XYZR radius key
- yaml save and restore is added. Only the whole model can be restored
at once to avoid breaking invariants.
- There is now a PairRestraint which acts as the base for DistanceRestraint.
- various missing add_x methods were filled in.
- I added a function in log.h to control whether exception messages are
dumped to standard error in addition to being embedded in the exception.
The current default is yes. The python lib init code should probably set
it to false for python, but I don't know how to do that.
- Pointer is now implicitly convertible to a pointer. This removes a lot
of get calls and makes code look nicer. And I can't think of any reason
not to do this given how we use it and the fact that it is an intrusive
pointer.
- vector3Ds now have inplace operators (+=, -=, /=)
Bug fixes and cleanups:
- There are many minor cleanups to which headers are included, and
comments and things like that.
- typedef pair score test was removing all references to the model an
expecting the particles to still be around, which is not safe
- IMP.i was setting thisown on the wrong argument to
TypedPairScore::set_pair_score
- the derivatives are all cleared at once in the attribute table
- ObjectPointer had not been removed from SVN for some reason
- Grid3D now works with bool values
- MaxChangeScoreState now stores the base values internally in order to
avoid changing the set of attributes on the particles. Changing the
attributes broke the yaml reader.
- nbl_helpers now doesn't complain when NDEBUG is already defined.
- Things are cleaned up for when models are reference counted but they
are not at the moment due to swig's lack of real reference counting
Index: kernel/test/singleton_scores/test_tunnel.py
===================================================================
--- kernel/test/singleton_scores/test_tunnel.py (revision 0)
+++ kernel/test/singleton_scores/test_tunnel.py (working copy)
@@ -13,17 +13,17 @@
m= IMP.Model()
p= IMP.Particle()
m.add_particle(p)
- d= IMP.XYZDecorator.create(p)
- rk= IMP.FloatKey("radiusk")
- p.add_attribute(rk, 1, False)
+ d= IMP.XYZRDecorator.create(p)
+ d.set_radius(1)
f= IMP.HarmonicLowerBound(0, 1)
- tr= IMP.TunnelRestraint(f, rk)
- tr.set_height(10)
- tr.set_radius(5)
- tr.set_center(IMP.Vector3D(10,10,10))
- tr.add_particle(p)
- tr.set_coordinate(2)
- m.add_restraint(tr)
+ tss= IMP.TunnelSingletonScore(f)
+ tss.set_height(10)
+ tss.set_radius(5)
+ tss.set_center(IMP.Vector3D(10,10,10))
+ tss.set_coordinate(2)
+ sl= IMP.SingletonListRestraint(tss)
+ sl.add_particle(p)
+ m.add_restraint(sl)
m.evaluate(True)
d.set_coordinates(IMP.Vector3D(10,10,10))
self.assertEqual(m.evaluate(True), 0)
Property changes on: kernel/test/singleton_scores/test_tunnel.py
___________________________________________________________________
Added: svn:mergeinfo
Index: kernel/test/unary_functions/test_linear.py
===================================================================
--- kernel/test/unary_functions/test_linear.py (revision 626)
+++ kernel/test/unary_functions/test_linear.py (working copy)
@@ -9,7 +9,7 @@
"""Test that linear values are correct"""
for offset in (0.0, -1.0):
for slope in (0.0, -5.0, 3.5):
- func = IMP.Linear(slope, offset)
+ func = IMP.Linear(offset, slope)
for i in range(15):
val = -10.0 + 3.5 * i
scoreonly = func.evaluate(val)
@@ -29,7 +29,7 @@
def test_show(self):
"""Check Linear::show() method"""
- func = IMP.Linear(1.0)
+ func = IMP.Linear(0, 1.0)
func.show()
if __name__ == '__main__':
Index: kernel/test/particles/test_refcount.py
===================================================================
--- kernel/test/particles/test_refcount.py (revision 626)
+++ kernel/test/particles/test_refcount.py (working copy)
@@ -12,6 +12,8 @@
IMP.set_log_level(IMP.VERBOSE)
self.basenum= IMP.RefCountedObject.get_number_of_live_objects()
print "The base number of objects is " + str(self.basenum)
+ # set this to true if the model is ref counted
+ self.count_model=0
def _check_number(self, expected):
print "Expected "+str(expected)\
@@ -19,7 +21,7 @@
- self.basenum)
self.assertEqual(IMP.RefCountedObject.get_number_of_live_objects() - self.basenum,
expected,
- "wrong number of particles")
+ "wrong number of objects")
def __test_simple(self):
"""Check that ref counting of particles works within python"""
@@ -47,11 +49,12 @@
m= IMP.Model()
p= IMP.Particle()
pi= m.add_particle(p)
- self._check_number(1)
+ self._check_number(1+self.count_model)
m.remove_particle(pi)
- self._check_number(1)
self.assert_(not p.get_is_active(), "Removed particle is still active")
p=1
+ self._check_number(0+ self.count_model)
+ m=1
self._check_number(0)
# This test does not work since swig refcounting is broken
@@ -123,17 +126,17 @@
print "Add particle to mc"
mc.add_particle(p)
# also have the score state now
- self._check_number(2)
+ self._check_number(2+ self.count_model)
print "Remove from model"
m.remove_particle(pi)
- self._check_number(2)
+ self._check_number(2+ self.count_model)
p=1
- self._check_number(2)
+ self._check_number(2+ self.count_model)
print "Remove from mc"
mc.clear_particles()
- self._check_number(1)
+ self._check_number(1+ self.count_model)
mc=0
- self._check_number(0)
+ self._check_number(0+ self.count_model)
def test_skip(self):
"""Check that removed particles are skipped"""
@@ -148,6 +151,7 @@
self.assertEqual(len(ps), 0, "Should no particles particle")
def test_restraints(self):
+ """Check reference counting of restraints"""
m= IMP.Model()
r= IMP.ConstantRestraint(1)
s= IMP.RestraintSet()
@@ -160,7 +164,27 @@
m=0
self._check_number(0)
+ def __test_model(self):
+ """Check reference counting of models"""
+ # disabled due to the usual issues with swig
+ self._check_number(0)
+ m= IMP.Model()
+ o= IMP.ConjugateGradients()
+ self._check_number(1)
+ o.set_model(m)
+ self._check_number(1)
+ o=[]
+ self._check_number(1)
+ m=[]
+ self._check_number(0)
+ m= IMP.Model()
+ o= IMP.ConjugateGradients()
+ self._check_number(1)
+ o.set_model(m)
+ self._check_number(1)
+ m=[]
+ self._check_number(1)
+ o=[]
-
if __name__ == '__main__':
unittest.main()
Index: kernel/test/distance/test_distance.py
===================================================================
--- kernel/test/distance/test_distance.py (revision 626)
+++ kernel/test/distance/test_distance.py (working copy)
@@ -37,6 +37,7 @@
IMP.HarmonicLowerBound(mean, 0.1),
IMP.Harmonic(mean, 0.1)):
r = IMP.DistanceRestraint(sf, p1, p2)
+ r.set_was_owned(True)
self.rsrs.append(r)
def _make_restraints(self):
@@ -56,6 +57,7 @@
IMP.HarmonicLowerBound(3.0, 0.1), IMP.Harmonic(3.0, 0.1)):
r = IMP.DistanceRestraint(fs, self.particles[1],
self.particles[0])
+ r.set_was_owned(True)
self.rsrs.append(r)
# exceed lower bound
@@ -63,6 +65,7 @@
IMP.HarmonicLowerBound(5.0, 0.1), IMP.Harmonic(5.0, 0.1)):
r = IMP.DistanceRestraint(fs, self.particles[1],
self.particles[2])
+ r.set_was_owned(True)
self.rsrs.append(r)
# exceed upper bound
@@ -70,6 +73,7 @@
IMP.HarmonicLowerBound(4.0, 0.1), IMP.Harmonic(4.0, 0.1)):
r = IMP.DistanceRestraint(fs, self.particles[0],
self.particles[2])
+ r.set_was_owned(True)
self.rsrs.append(r)
def test_show(self):
@@ -77,6 +81,7 @@
r = IMP.DistanceRestraint( IMP.Harmonic(0.0, 0.1),
self.particles[1],
self.particles[0])
+ r.set_was_owned(True)
r.show()
def test_distance(self):
Index: kernel/test/restraints/test_angles.py
===================================================================
--- kernel/test/restraints/test_angles.py (revision 626)
+++ kernel/test/restraints/test_angles.py (working copy)
@@ -31,7 +31,7 @@
m.add_particle(p)
d= IMP.XYZDecorator.create(p)
l0.append(p)
- self.randomize_particles(l0, 20)
+ IMP.test.randomize_particles(l0, 20)
return l0
def create_angle_r(self, s, ps):
Index: kernel/test/restraints/test_list.py
===================================================================
--- kernel/test/restraints/test_list.py (revision 626)
+++ kernel/test/restraints/test_list.py (working copy)
@@ -11,16 +11,6 @@
def show(self, t):
print "One Singleton"
-class Linear(IMP.UnaryFunction):
- def __init__(self):
- IMP.UnaryFunction.__init__(self)
- def evaluate(self, feat):
- return feat
- def evaluate_deriv(self, feat):
- return feat, 1.0
- def show(self, *args):
- print "identity"
-
class TestList(IMP.test.TestCase):
def setUp(self):
IMP.test.TestCase.setUp(self)
@@ -49,7 +39,7 @@
d.set_z(1)
d.set_coordinates_are_optimized(True)
v= IMP.Vector3D(3,1,5)
- l= Linear()
+ l= IMP.Linear(0,1)
s= IMP.DistanceToSingletonScore(l, v)
r= IMP.SingletonListRestraint(s, m.get_particles())
m.add_restraint(r)
Index: kernel/test/restraints/test_pairchain.py
===================================================================
--- kernel/test/restraints/test_pairchain.py (revision 626)
+++ kernel/test/restraints/test_pairchain.py (working copy)
@@ -26,20 +26,14 @@
p= IMP.Particle()
m.add_particle(p)
ps0.append(p)
- ps1= IMP.Particles()
- for i in range(0,10):
- p= IMP.Particle()
- m.add_particle(p)
- ps1.append(p)
os= IndexDiff()
s= IMP.PairChainRestraint(os)
- s.add_chain(ps0)
- s.add_chain(ps1)
+ s.set_particles(ps0)
m.add_restraint(s)
score= m.evaluate(False)
print str(score)
- self.assertEqual(score, 18, "Wrong score")
- s.clear_chains()
+ self.assertEqual(score, 9, "Wrong score")
+ s.clear_particles()
self.assertEqual(m.evaluate(False), 0, "Should be no terms")
Index: kernel/test/restraints/test_tunnel.py
===================================================================
--- kernel/test/restraints/test_tunnel.py (revision 626)
+++ kernel/test/restraints/test_tunnel.py (working copy)
@@ -1,62 +0,0 @@
-import unittest
-import IMP
-import IMP.test
-import IMP.utils
-import math
-
-class TunnelTest(IMP.test.TestCase):
- """Tests for tunnel restraints"""
-
- def test_score(self):
- """Test derivatives and score of tunnel restraint"""
- IMP.set_log_level(IMP.VERBOSE)
- m= IMP.Model()
- p= IMP.Particle()
- m.add_particle(p)
- d= IMP.XYZDecorator.create(p)
- rk= IMP.FloatKey("radiusk")
- p.add_attribute(rk, 1, False)
- f= IMP.HarmonicLowerBound(0, 1)
- tr= IMP.TunnelRestraint(f, rk)
- tr.set_height(10)
- tr.set_radius(5)
- tr.set_center(IMP.Vector3D(10,10,10))
- tr.add_particle(p)
- tr.set_coordinate(2)
- m.add_restraint(tr)
- m.evaluate(True)
- d.set_coordinates(IMP.Vector3D(10,10,10))
- self.assertEqual(m.evaluate(True), 0)
-
- print "Test left"
- d.set_coordinates(IMP.Vector3D(4, 10, 10))
- self.assert_(m.evaluate(True)>0)
- self.assertEqual(d.get_coordinate_derivative(2), 0)
- self.assertEqual(d.get_coordinate_derivative(1), 0)
- print d.get_coordinate_derivative(0)
- self.assert_(d.get_coordinate_derivative(0) > 0)
-
- print "Test above"
- d.set_coordinates(IMP.Vector3D(10, 4, 10))
- self.assert_(m.evaluate(True)>0)
- self.assertEqual(d.get_coordinate_derivative(2), 0)
- self.assertEqual(d.get_coordinate_derivative(0), 0)
- print d.get_coordinate_derivative(1)
- self.assert_(d.get_coordinate_derivative(1) > 0)
-
- print "Test bottom"
- d.set_coordinates(IMP.Vector3D(30, 30, 3))
- self.assert_(m.evaluate(True)>0)
- self.assertEqual(d.get_coordinate_derivative(0), 0)
- self.assertEqual(d.get_coordinate_derivative(1), 0)
- self.assert_(d.get_coordinate_derivative(2) < 0)
-
- print "Test top"
- d.set_coordinates(IMP.Vector3D(30, 30, 17))
- self.assert_(m.evaluate(True)>0)
- self.assertEqual(d.get_coordinate_derivative(0), 0)
- self.assertEqual(d.get_coordinate_derivative(1), 0)
- self.assert_(d.get_coordinate_derivative(2) > 0)
-
-if __name__ == '__main__':
- unittest.main()
Index: kernel/test/particle_refiners/test_refine_once_ps.py
===================================================================
--- kernel/test/particle_refiners/test_refine_once_ps.py (revision 626)
+++ kernel/test/particle_refiners/test_refine_once_ps.py (working copy)
@@ -9,7 +9,7 @@
def test_rops(self):
- """Make sure that bond cover coordinates are correct"""
+ """Test refine one pair score"""
IMP.set_log_level(IMP.VERBOSE)
m= IMP.Model()
pp= IMP.Particle()
Index: kernel/test/particle_refiners/test_bond_pr.py
===================================================================
--- kernel/test/particle_refiners/test_bond_pr.py (revision 626)
+++ kernel/test/particle_refiners/test_bond_pr.py (working copy)
@@ -10,8 +10,8 @@
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)
+ ps= IMP.test.create_particles_in_box(m)
+ bds= IMP.test.create_chain(ps, 10)
bl= IMP.BondDecoratorListScoreState(ps)
ss= IMP.CoverBondsScoreState(bl, rk)
m.add_score_state(bl)
Index: kernel/test/states/test_nonbonded_list.py
===================================================================
--- kernel/test/states/test_nonbonded_list.py (revision 626)
+++ kernel/test/states/test_nonbonded_list.py (working copy)
@@ -11,16 +11,16 @@
def test_quadratic(self):
"""Test quadratic NBL"""
- ss='IMP.AllNonbondedListScoreState(md, self.rk, IMP.AllNonbondedListScoreState.QUADRATIC)'
+ ss='IMP.AllNonbondedListScoreState(md)'
#eval(ss)
- self.do_test_all(ss)
+ self.do_test_all(ss, IMP.AllNonbondedListScoreState.QUADRATIC)
def test_grid(self):
"""Test grid NBL"""
#IMP.set_log_level(IMP.VERBOSE)
- ss='IMP.AllNonbondedListScoreState(md, self.rk, IMP.AllNonbondedListScoreState.GRID)'
- self.do_test_all(ss)
+ ss='IMP.AllNonbondedListScoreState(md)'
+ self.do_test_all(ss,IMP.AllNonbondedListScoreState.GRID )
def test_bbox(self):
"""Test bbox NBL"""
@@ -29,18 +29,18 @@
except:
print "No CGAL support"
else:
- ss= 'IMP.AllNonbondedListScoreState(md, self.rk, IMP.AllNonbondedListScoreState.BBOX)'
- self.do_test_all(ss)
+ ss= 'IMP.AllNonbondedListScoreState(md)'
+ self.do_test_all(ss, IMP.AllNonbondedListScoreState.BBOX)
def test_default(self):
"""Test default NBL"""
- ss= 'IMP.AllNonbondedListScoreState(md, self.rk)'
- self.do_test_all(ss)
+ ss= 'IMP.AllNonbondedListScoreState(md)'
+ self.do_test_all(ss, IMP.AllNonbondedListScoreState.DEFAULT)
def test_bipartite_quadratic(self):
"""Test bipartite quadratic NBL"""
- ss='IMP.BipartiteNonbondedListScoreState(md, self.rk, IMP.BipartiteNonbondedListScoreState.QUADRATIC)'
- self.do_test_all_bi(ss)
+ ss='IMP.BipartiteNonbondedListScoreState(md)'
+ self.do_test_all_bi(ss, IMP.BipartiteNonbondedListScoreState.QUADRATIC)
def test_bipartite_bbox(self):
"""Test bipartite bbox NBL"""
@@ -49,27 +49,27 @@
except:
print "No CGAL support"
else:
- ss= 'IMP.BipartiteNonbondedListScoreState(md, self.rk, IMP.BipartiteNonbondedListScoreState.BBOX)'
- self.do_test_all_bi(ss)
+ ss= 'IMP.BipartiteNonbondedListScoreState(md)'
+ self.do_test_all_bi(ss, IMP.BipartiteNonbondedListScoreState.BBOX)
- def do_test_all(self, ss):
- self.do_test_bl(ss)
- self.do_test_distfilt(ss)
- self.do_test_spheres(ss)
+ def do_test_all(self, ss, algo):
+ self.do_test_bl(ss, algo)
+ self.do_test_distfilt(ss, algo)
+ self.do_test_spheres(ss, algo)
- def do_test_all_bi(self, ss):
- self.do_test_bi(ss)
- self.do_test_bi_update(ss)
+ def do_test_all_bi(self, ss, algo):
+ self.do_test_bi(ss, algo)
+ self.do_test_bi_update(ss, algo)
def make_spheres(self, m, num, lbv, ubv, minr, maxr):
- ps=self.create_particles_in_box(m, num, lbv, ubv)
+ ps=IMP.test.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 do_test_update(self, ss):
+ def do_test_update(self, ss, algo):
m= IMP.Model()
self.make_spheres(m, 20, [0,0,0], [10,10,10], .1, 1)
ds=[]
@@ -77,6 +77,7 @@
ds.append(IMP.XYZDecorator.cast(p))
md=5
s=eval(ss)
+ s.set_algorithm(algo)
s.set_particles(m.get_particles())
m.add_score_state(s)
o= IMP.test.ConstPairScore(1)
@@ -88,7 +89,7 @@
for d in ds:
d.randomize_in_sphere(d.get_vector(), 2.0)
- def do_test_bl(self, ss):
+ def do_test_bl(self, ss, algo):
"""Test the bond decorator list"""
m= IMP.Model()
bds=[]
@@ -99,6 +100,7 @@
IMP.custom_bond(bds[i-1], bds[i], 1, .1)
md= 20
s=eval(ss)
+ s.set_algorithm(algo)
s.set_particles(pts)
b= IMP.BondDecoratorListScoreState(pts)
s.add_bonded_list(b)
@@ -114,17 +116,18 @@
print "Score with bonds is " + str(score)
self.assertEqual(score, 190+1900-19, "Wrong score")
- def do_test_distfilt(self, ss):
+ def do_test_distfilt(self, ss, algo):
"""Test filtering based on distance in nonbonded list"""
#IMP.set_log_level(IMP.TERSE)
m= IMP.Model()
ps=IMP.Particles()
- 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])
+ ps= IMP.test.create_particles_in_box(m, 20, [0,0,0], [10,10,10])
+ pts= IMP.test.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_algorithm(algo)
s.set_particles(ps)
m.add_score_state(s)
o= IMP.test.ConstPairScore(1)
@@ -157,13 +160,14 @@
self.assertEqual(score, 2*190, "Wrong score after insert")
- def do_test_bi(self, ss):
+ def do_test_bi(self, ss, algo):
"""Test the bipartite nonbonded list and restraint which uses it"""
m= IMP.Model()
ps0=self.make_spheres(m, 5, [0,0,0], [10,10,10], .1, 1)
ps1=self.make_spheres(m, 5, [0,0,0], [10,10,10], .1, 1)
md=15
s=eval(ss)
+ s.set_algorithm(algo)
#IMP.QuadraticBipartiteNonbondedListScoreState(IMP.FloatKey(),
# ps0, ps1)
s.set_particles(ps0, ps1)
@@ -175,13 +179,14 @@
print score
self.assertEqual(score, 25, "Wrong score")
- def do_test_bi_update(self, ss):
+ def do_test_bi_update(self, ss, algo):
"""Test the bipartite nonbonded list and restraint which uses it"""
m= IMP.Model()
ps0=self.make_spheres(m, 5, [0,0,0], [10,10,10], .1, 1)
ps1=self.make_spheres(m, 5, [0,0,0], [10,10,10], .1, 1)
md=5
s=eval(ss)
+ s.set_algorithm(algo)
#IMP.QuadraticBipartiteNonbondedListScoreState(IMP.FloatKey(),
# ps0, ps1)
s.set_particles(ps0, ps1)
@@ -199,13 +204,14 @@
d.randomize_in_sphere(d.get_vector(), 1)
- def do_test_spheres(self, ss):
+ def do_test_spheres(self, ss, algo):
"""Test the nonbonded list of spheres (collision detection)"""
m= IMP.Model()
ps= self.make_spheres(m, 20, IMP.Vector3D(0,0,0),
IMP.Vector3D(10,10,10), 0, 100)
md= 1
s=eval(ss)
+ s.set_algorithm(algo)
s.set_particles(m.get_particles())
#IMP.AllNonbondedListScoreState(rk, m.get_particles())
m.add_score_state(s)
Index: kernel/test/optimizers/test_sd_optimizer.py
===================================================================
--- kernel/test/optimizers/test_sd_optimizer.py (revision 626)
+++ kernel/test/optimizers/test_sd_optimizer.py (working copy)
@@ -70,7 +70,7 @@
# Start off with all particles in close proximity (but not actually
# colocated, as the derivative of zero distance is zero):
- self.randomize_particles(self.particles, .01)
+ IMP.test.randomize_particles(self.particles, .01)
self.steepest_descent.optimize(50)
Index: kernel/test/decorators/test_yaml.py
===================================================================
--- kernel/test/decorators/test_yaml.py (revision 0)
+++ kernel/test/decorators/test_yaml.py (revision 0)
@@ -0,0 +1,47 @@
+import unittest
+import IMP
+import IMP.test
+
+class YamlTests(IMP.test.TestCase):
+ def _create_model(self):
+ IMP.set_log_level(IMP.VERBOSE)
+ m = IMP.Model()
+ p= IMP.Particle()
+ m.add_particle(p)
+ IMP.XYZDecorator.create(p)
+ p= IMP.Particle()
+ m.add_particle(p)
+ IMP.XYZDecorator.create(p)
+ return m
+ def test_yaml(self):
+ """Check writing to yaml """
+ m= self._create_model()
+ IMP.write_yaml(m)
+ def test_read(self):
+ """Check reading from yaml"""
+ m= self._create_model()
+ st="""particle: 0
+ float-attributes:
+ x: 0
+ y: 1
+ z: 2
+ int-attributes:
+ string-attributes:
+ particle-attributes:
+particle: 1
+ float-attributes:
+ x: 3
+ y: 4
+ z: 5
+ int-attributes:
+ string-attributes:
+ particle-attributes:
+"""
+ IMP.read_yaml(st, m)
+ IMP.write_yaml(m)
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
Index: kernel/test/pair_scores/test_typed_pair_score.py
===================================================================
--- kernel/test/pair_scores/test_typed_pair_score.py (revision 626)
+++ kernel/test/pair_scores/test_typed_pair_score.py (working copy)
@@ -7,9 +7,8 @@
class TypedPairScoreTests(IMP.test.TestCase):
"""Class to test TypedPairScore"""
- def _make_particles(self, types):
+ def _make_particles(self, m, types):
"""Make particles with the given types"""
- m = IMP.Model()
ps = [IMP.Particle() for i in types]
for p, typ in zip(ps, types):
m.add_particle(p)
@@ -21,15 +20,23 @@
ps = IMP.TypedPairScore(typekey)
cps = IMP.test.ConstPairScore(5)
ps.set_pair_score(cps, 0, 1)
- pa, pb = self._make_particles((0, 1))
+ # particles will be destroyed when the model goes away
+ m = IMP.Model()
+ pa, pb = self._make_particles(m, (0, 1))
da = IMP.DerivativeAccumulator()
# The ordering of the particles should not matter:
self.assertEqual(ps.evaluate(pa, pb, da), 5.0)
self.assertEqual(ps.evaluate(pb, pa, da), 5.0)
+ print "ps"
+ ps=[]
+ print "cps"
+ cps= []
+ print "done"
def test_invalid_type(self):
"""Check TypedPairScore behavior with invalid particle types"""
- pa, pb = self._make_particles((0, 1))
+ m = IMP.Model()
+ pa, pb = self._make_particles(m, (0, 1))
da = IMP.DerivativeAccumulator()
ps1 = IMP.TypedPairScore(typekey, True)
self.assertEqual(ps1.evaluate(pa, pb, da), 0.0)
Index: kernel/test/pair_scores/test_transform.py
===================================================================
--- kernel/test/pair_scores/test_transform.py (revision 626)
+++ kernel/test/pair_scores/test_transform.py (working copy)
@@ -71,7 +71,10 @@
d0.set_coordinates_are_optimized(True)
d1.set_coordinates_are_optimized(True)
tps= IMP.TransformedDistancePairScore(IMP.Harmonic(0,1))
- tps.set_translation(0,1,0)
+ cv= IMP.Vector3D(2,1,0)
+ tv= IMP.Vector3D(0,1,0)
+ tps.set_translation(tv[0], tv[1], tv[2])
+ tps.set_center(cv[0], cv[1], cv[2])
tps.set_rotation(1, 0, 0,
0, 0,-1,
0, 1, 0)
@@ -83,14 +86,16 @@
cg.optimize(100)
d0.show()
d1.show()
- vt= IMP.Vector3D(d1.get_vector()*IMP.Vector3D(1,0,0)+0,
- d1.get_vector()*IMP.Vector3D(0,0,-1)+1,
- d1.get_vector()*IMP.Vector3D(0,1,0)+0)
+ ncv= d1.get_vector()- cv
+ vt= IMP.Vector3D(ncv*IMP.Vector3D(1,0,0),
+ ncv*IMP.Vector3D(0,0,-1),
+ ncv*IMP.Vector3D(0,1,0))
+ fvt= vt+ tv+cv
print "trans"
- print str(vt[0]) + " " + str(vt[1])+" " + str(vt[2])
- self.assertEqual(vt[0], d0.get_coordinate(0))
- self.assertEqual(vt[1], d0.get_coordinate(1))
- self.assertEqual(vt[2], d0.get_coordinate(2))
+ print str(fvt[0]) + " " + str(fvt[1])+" " + str(fvt[2])
+ self.assertEqual(fvt[0], d0.get_coordinate(0))
+ self.assertEqual(fvt[1], d0.get_coordinate(1))
+ self.assertEqual(fvt[2], d0.get_coordinate(2))
if __name__ == '__main__':
unittest.main()
Index: kernel/test/connectivity/test_connectivity.py
===================================================================
--- kernel/test/connectivity/test_connectivity.py (revision 626)
+++ kernel/test/connectivity/test_connectivity.py (working copy)
@@ -26,8 +26,6 @@
IMP.set_log_level(IMP.VERBOSE)
m = IMP.Model()
- rk= IMP.FloatKey("radius")
-
p0=IMP.Particles()
p1=IMP.Particles()
p2=IMP.Particles()
@@ -35,28 +33,28 @@
for i in range(13):
p= IMP.Particle()
m.add_particle(p)
- d= IMP.XYZDecorator.create(p)
+ d= IMP.XYZRDecorator.create(p)
d.set_coordinates_are_optimized(True)
if i % 3 == 0:
p0.append(p)
- p.add_attribute(rk, 1);
+ d.set_radius(1);
elif i % 3 == 1:
p1.append(p)
- p.add_attribute(rk, 2);
+ d.set_radius(2);
else:
p2.append(p)
- p.add_attribute(rk, 3);
+ d.set_radius(3);
p= IMP.Particle()
m.add_particle(p)
- d= IMP.XYZDecorator.create(p)
+ d= IMP.XYZRDecorator.create(p)
d.set_coordinates_are_optimized(True)
p3.append(p)
- p.add_attribute(rk, 1);
+ d.set_radius(1);
o = IMP.ConjugateGradients()
o.set_threshold(1e-4)
o.set_model(m)
- self.randomize_particles(m.get_particles(), 50.0)
+ IMP.test.randomize_particles(m.get_particles(), 50.0)
# add connectivity restraints
Index: kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h
===================================================================
--- kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h (revision 626)
+++ kernel/include/IMP/singleton_scores/DistanceToSingletonScore.h (working copy)
@@ -27,7 +27,7 @@
DistanceToSingletonScore(UnaryFunction *f, const Vector3D& pt);
virtual ~DistanceToSingletonScore(){}
virtual Float evaluate(Particle *a,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
};
Index: kernel/include/IMP/singleton_scores/SConscript
===================================================================
--- kernel/include/IMP/singleton_scores/SConscript (revision 626)
+++ kernel/include/IMP/singleton_scores/SConscript (working copy)
@@ -1,9 +1,10 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['DistanceToSingletonScore.h', 'AttributeSingletonScore.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'singleton_scores')
+files=[
+ 'AttributeSingletonScore.h',
+ 'DistanceToSingletonScore.h',
+ 'TunnelSingletonScore.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'singleton_scores' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/singleton_scores/TunnelSingletonScore.h
===================================================================
--- kernel/include/IMP/singleton_scores/TunnelSingletonScore.h (revision 0)
+++ kernel/include/IMP/singleton_scores/TunnelSingletonScore.h (revision 0)
@@ -0,0 +1,79 @@
+/**
+ * \file TunnelSingletonScore.h \brief Tunnel restraint.
+ *
+ * Just return a constant.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#ifndef __IMP_TUNNEL_RESTRAINT_H
+#define __IMP_TUNNEL_RESTRAINT_H
+
+#include "../IMP_config.h"
+#include "../SingletonScore.h"
+#include "../Vector3D.h"
+#include "../UnaryFunction.h"
+#include "../Pointer.h"
+#include "../internal/kernel_version_info.h"
+
+namespace IMP
+{
+
+class PairScore;
+
+//! Score particles with respect to a tunnel.
+/** Particles with x,y,z coordinates and an optional radius are
+ prevented from being in a volume destribed by a slab from
+ (center[i]-height) to (center+height) on the ith coordinate with a
+ tunnel of radius r centered at center. To set which coordinate
+ is used use the get/set _coordinate functions.
+
+ Note that the UnaryFunction should look like a lower bound with 0
+ meaning that the particle is just touching the tunnel.
+
+ \ingroup restraint
+ */
+class IMPDLLEXPORT TunnelSingletonScore : public SingletonScore
+{
+ int coordinate_;
+ Vector3D center_;
+ Float height_;
+ Float radius_;
+ Pointer<UnaryFunction> f_;
+public:
+ TunnelSingletonScore(UnaryFunction* f);
+
+ void set_center(Vector3D c){
+ center_=c;
+ }
+ void set_height(Float h){
+ IMP_check(h >= 0,
+ "Height can't be negative",
+ ValueException);
+ height_=h;
+ }
+ void set_radius(Float h){
+ IMP_check(h >= 0,
+ "Radius can't be negative",
+ ValueException);
+ radius_=h;
+ }
+ void set_coordinate(unsigned int i) {
+ IMP_check(i < 3,
+ "Invalid coordinate value",
+ ValueException);
+ coordinate_=i;
+ }
+ unsigned int get_coordinate() const {
+ return coordinate_;
+ }
+
+ virtual Float evaluate(Particle *a,
+ DerivativeAccumulator *da) const;
+ virtual void show(std::ostream &out=std::cout) const;
+};
+
+} // namespace IMP
+
+#endif /* __IMP_TUNNEL_RESTRAINT_H */
Index: kernel/include/IMP/base_types.h
===================================================================
--- kernel/include/IMP/base_types.h (revision 626)
+++ kernel/include/IMP/base_types.h (working copy)
@@ -14,7 +14,6 @@
#include <string>
#include <vector>
-#include <map>
namespace IMP
{
Index: kernel/include/IMP/SingletonScore.h
===================================================================
--- kernel/include/IMP/SingletonScore.h (revision 626)
+++ kernel/include/IMP/SingletonScore.h (working copy)
@@ -34,7 +34,7 @@
virtual ~SingletonScore() {}
//! Compute the score for the particle and the derivative if needed.
virtual Float evaluate(Particle *a,
- DerivativeAccumulator *da) = 0;
+ DerivativeAccumulator *da) const = 0;
virtual void show(std::ostream &out=std::cout) const = 0;
};
Index: kernel/include/IMP/Model.h
===================================================================
--- kernel/include/IMP/Model.h (revision 626)
+++ kernel/include/IMP/Model.h (working copy)
@@ -28,6 +28,7 @@
/** All attribute data for particles is stored through indexing in the
model_data_ structure.
Currently no suport for constraints (e.g. rigid bodies).
+
\ingroup kernel
*/
class IMPDLLEXPORT Model: public Object
Index: kernel/include/IMP/UnaryFunction.h
===================================================================
--- kernel/include/IMP/UnaryFunction.h (revision 626)
+++ kernel/include/IMP/UnaryFunction.h (working copy)
@@ -28,7 +28,7 @@
/** \param[in] feature Value of feature being tested.
\return Score
*/
- virtual Float evaluate(Float feature) = 0;
+ virtual Float evaluate(Float feature) const = 0;
//! Calculate score and derivative with respect to the given feature.
/** \param[in] feature Value of feature being tested.
@@ -36,7 +36,7 @@
given feaure.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv) = 0;
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const = 0;
virtual void show(std::ostream &out=std::cout) const = 0;
};
Index: kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h (revision 0)
+++ kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h (revision 0)
@@ -0,0 +1,50 @@
+/**
+ * \file BondDecoratorListScoreState.h
+ * \brief Allow iteration through pairs of a set of atoms.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ */
+
+#ifndef __IMP_MANUAL_BOND_DECORATOR_LIST_SCORE_STATE_H
+#define __IMP_MANUAL_BOND_DECORATOR_LIST_SCORE_STATE_H
+
+#include "BondedListScoreState.h"
+#include "../decorators/bond_decorators.h"
+
+#include <vector>
+
+namespace IMP
+{
+
+class ManualBondDecoratorListScoreState;
+typedef Index<ManualBondDecoratorListScoreState> BondDecoratorListIndex;
+
+//! Keep track of particles that are connected by BondDecorator bonds.
+/** This class just keeps track of the bonds it has been told about.
+ Use the non-manual version if you want auto discovery of bonds.
+ \ingroup bond
+ */
+class IMPDLLEXPORT ManualBondDecoratorListScoreState:
+ public BondedListScoreState
+{
+ public:
+ //! Find bonds amongst the following points.
+ /** \param [in] ps The set of particles to use.
+ */
+ ManualBondDecoratorListScoreState(const BondDecorators &ps= BondDecorators());
+ virtual ~ManualBondDecoratorListScoreState(){}
+
+ virtual void set_particles(const Particles &ps) {}
+ virtual void add_particles(const Particles &ps) {}
+
+ IMP_LIST(public, BondDecorator, bond_decorator, BondDecorator);
+
+ virtual bool are_bonded(Particle *a, Particle *b) const;
+
+protected:
+ virtual void do_before_evaluate() {}
+};
+
+} // namespace IMP
+
+#endif /* __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/score_states/BondDecoratorListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BondDecoratorListScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/BondDecoratorListScoreState.h (working copy)
@@ -8,25 +8,21 @@
#ifndef __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
#define __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
-#include "BondedListScoreState.h"
+#include "ManualBondDecoratorListScoreState.h"
#include "../decorators/bond_decorators.h"
#include <vector>
namespace IMP
{
-
-class BondDecoratorListScoreState;
-typedef Index<BondDecoratorListScoreState> BondDecoratorListIndex;
-
//! Keep track of particles that are connected by BondDecorator bonds.
/** We also may want to add lazy rescanning of bonds rather than doing
it every update call and a faster lookup of bonds.
\ingroup bond
*/
-class IMPDLLEXPORT BondDecoratorListScoreState: public BondedListScoreState
+class IMPDLLEXPORT BondDecoratorListScoreState:
+ public ManualBondDecoratorListScoreState
{
- std::vector<BondDecorator> bonds_;
Particles ps_;
public:
//! Find bonds amongst the following points.
@@ -36,24 +32,8 @@
virtual ~BondDecoratorListScoreState(){}
virtual void set_particles(const Particles &ps);
+ virtual void add_particles(const Particles &ps);
- virtual bool are_bonded(Particle *a, Particle *b) const;
-
- //! This iterates through the pairs of bonded particles
- /** \note update() must be called first for this to be valid.
- */
- typedef std::vector<BondDecorator>::const_iterator BondIterator;
- BondIterator bonds_begin() const {
- return bonds_.begin();
- }
- BondIterator bonds_end() const {
- return bonds_.end();
- }
-
- unsigned int get_number_of_bonds() const {
- return bonds_.size();
- }
-
protected:
virtual void do_before_evaluate();
};
Index: kernel/include/IMP/score_states/NonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/NonbondedListScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/NonbondedListScoreState.h (working copy)
@@ -9,6 +9,7 @@
#define __IMP_NONBONDED_LIST_SCORE_STATE_H
#include "../ScoreState.h"
+#include "MaxChangeScoreState.h"
#include "../internal/kernel_version_info.h"
#include "../decorators/XYZDecorator.h"
#include "BondedListScoreState.h"
@@ -16,7 +17,6 @@
#include <boost/iterator/filter_iterator.hpp>
#include <vector>
-#include <limits>
namespace IMP
{
@@ -51,6 +51,7 @@
*/
unsigned int max_nbl_size_;
ParticlePairs nbl_;
+ Pointer<MaxChangeScoreState> mcr_;
struct NBLTooLargeException{};
@@ -184,12 +185,22 @@
BoxesOverlap boxes_overlap_object(float cut) const {
return BoxesOverlap(get_radius_object(), cut);
}
+
+ Float get_max_radius_change() const;
+
+ void reset_max_radius_change();
+
+ void update_max_radius_change(unsigned int i);
+
+ void add_particles_for_max_radius_change(const Particles &ps);
+ void clear_particles_for_max_radius_change();
+
public:
- NonbondedListScoreState(Float cutoff, FloatKey rk);
+ NonbondedListScoreState(Float cutoff);
~NonbondedListScoreState();
FloatKey get_radius_key() const {return rk_;}
- void set_radius_key(FloatKey rk) {rk_=rk;}
+ void set_radius_key(FloatKey rk);
//! Set the maximum allowable size for the NBL
/** The NBL will keep reducing the slack and trying to
Index: kernel/include/IMP/score_states/SConscript
===================================================================
--- kernel/include/IMP/score_states/SConscript (revision 626)
+++ kernel/include/IMP/score_states/SConscript (working copy)
@@ -1,12 +1,16 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['BondedListScoreState.h', 'NonbondedListScoreState.h',
- 'BipartiteNonbondedListScoreState.h', 'MaxChangeScoreState.h',
- 'BondDecoratorListScoreState.h', 'AllNonbondedListScoreState.h',
- 'GravityCenterScoreState.h', 'CoverBondsScoreState.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'score_states')
+files=[
+ 'AllNonbondedListScoreState.h',
+ 'BipartiteNonbondedListScoreState.h',
+ 'BondDecoratorListScoreState.h',
+ 'BondedListScoreState.h',
+ 'CoverBondsScoreState.h',
+ 'GravityCenterScoreState.h',
+ 'ManualBondDecoratorListScoreState.h',
+ 'MaxChangeScoreState.h',
+ 'NonbondedListScoreState.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'score_states' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/score_states/CoverBondsScoreState.h
===================================================================
--- kernel/include/IMP/score_states/CoverBondsScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/CoverBondsScoreState.h (working copy)
@@ -9,7 +9,7 @@
#define __IMP_COVER_BONDS_SCORE_STATE_H
#include "../ScoreState.h"
-#include "BondDecoratorListScoreState.h"
+#include "ManualBondDecoratorListScoreState.h"
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
@@ -30,13 +30,13 @@
*/
class IMPDLLEXPORT CoverBondsScoreState: public ScoreState
{
- Pointer<BondDecoratorListScoreState> bl_;
+ Pointer<ManualBondDecoratorListScoreState> bl_;
FloatKey rk_;
public:
/** Get the list of bonds from the BondDecoratorListScoreState. This list is
not owned and update is not called on this list automatically.
*/
- CoverBondsScoreState(BondDecoratorListScoreState *bl,
+ CoverBondsScoreState(ManualBondDecoratorListScoreState *bl,
FloatKey rk=FloatKey("radius"));
~CoverBondsScoreState();
Index: kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/BipartiteNonbondedListScoreState.h (working copy)
@@ -20,7 +20,9 @@
/** To iterate through the list of pairs use the NonbondedListScoreState::begin,
NonbondedListScoreState::end functions.
- The radius key can be the default key.
+ By default the XYZRDecorator radius is used as the radius. The radius key
+ can be set to FloatKey to force all particles to be point particles.
+ Particles without radius attribute are treated as points.
Changes in coordinates and radii are handled properly.
@@ -43,7 +45,7 @@
};
protected:
Algorithm a_;
- Pointer<MaxChangeScoreState> mc0_, mc1_, mcr_;
+ Pointer<MaxChangeScoreState> mc0_, mc1_;
void process_sets(const Particles &p0,
const Particles &p1);
@@ -57,8 +59,7 @@
\param[in] radius The key to use to get the radius
\param[in] a Which algorithm to use. The default is the best.
*/
- BipartiteNonbondedListScoreState(Float cutoff, FloatKey radius,
- Algorithm a=DEFAULT);
+ BipartiteNonbondedListScoreState(Float cutoff);
/** \param[in] cutoff The distance cutoff to use.
\param[in] radius The key to use to get the radius
\param[in] ps0 The first set.
@@ -66,10 +67,8 @@
\param[in] a Which algorithm to use. The default is the best.
*/
BipartiteNonbondedListScoreState(Float cutoff,
- FloatKey radius,
const Particles &ps0,
- const Particles &ps1,
- Algorithm a=DEFAULT);
+ const Particles &ps1);
~BipartiteNonbondedListScoreState();
IMP_SCORE_STATE(internal::kernel_version_info);
@@ -78,6 +77,12 @@
void add_particles_0(const Particles &ps);
//! Add the particles to the second set
void add_particles_1(const Particles &ps);
+
+ //! Add the particles to the first set
+ void add_particle_0(Particle* ps);
+ //! Add the particles to the second set
+ void add_particle_1(Particle* ps);
+
//! Remove all particles
void clear_particles();
//! Replace the set of particles
Index: kernel/include/IMP/score_states/AllNonbondedListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/AllNonbondedListScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/AllNonbondedListScoreState.h (working copy)
@@ -26,7 +26,9 @@
/** To iterate through the list of pairs use the NonbondedListScoreState::begin,
NonbondedListScoreState::end functions.
- The radius key can be the default key.
+ By default the XYZRDecorator radius is used as the radius. The radius key
+ can be set to FloatKey to force all particles to be point particles.
+ Particles without radius attribute are treated as points.
Changes in coordinates and radii are handled properly unless grid is used,
then changes in radii may not be handled properly.
@@ -50,7 +52,7 @@
};
protected:
Algorithm a_;
- Pointer<MaxChangeScoreState> mc_, mcr_;
+ Pointer<MaxChangeScoreState> mc_;
void check_nbl() const;
@@ -72,20 +74,12 @@
/** \param[in] cutoff The distance cutoff to use.
\param[in] radius The key to use to get the radius
- \param[in] a Which algorithm to use. The default is the best.
- */
- AllNonbondedListScoreState(Float cutoff,
- FloatKey radius,
- Algorithm a= DEFAULT);
- /** \param[in] cutoff The distance cutoff to use.
- \param[in] radius The key to use to get the radius
\param[in] ps A list of particles to use.
\param[in] a Which algorithm to use. The default is the best.
*/
AllNonbondedListScoreState(Float cutoff,
- FloatKey radius,
- const Particles &ps,
- Algorithm a= DEFAULT);
+ const Particles &ps= Particles());
+
~AllNonbondedListScoreState();
IMP_SCORE_STATE(internal::kernel_version_info);
@@ -97,6 +91,11 @@
//! Replace the set of particles
void set_particles(const Particles &ps);
+ //! hack
+ void add_particle(Particle *p) {
+ add_particles(Particles(1,p));
+ }
+
//! If there is CGAL support, a more efficient algorithm BBOX can be used
void set_algorithm(Algorithm a);
};
Index: kernel/include/IMP/score_states/MaxChangeScoreState.h
===================================================================
--- kernel/include/IMP/score_states/MaxChangeScoreState.h (revision 626)
+++ kernel/include/IMP/score_states/MaxChangeScoreState.h (working copy)
@@ -20,13 +20,14 @@
//! Keeps track of the maximum change of a set of attributes.
/** The score state maintains a list of particle and a list of
float attribute keys and keeps track of the maximum amount
- any of these have changed since the last time reset was called.
-
+ any of these have changed since the last time reset was called.
*/
class IMPDLLEXPORT MaxChangeScoreState: public ScoreState
{
FloatKeys keys_;
- FloatKeys origkeys_;
+ typedef internal::AttributeTable<internal::FloatAttributeTableTraits>
+ Table;
+ std::vector<Table> old_values_;
float max_change_;
public:
//! Track the changes with the specified keys.
Index: kernel/include/IMP/restraints/SingletonListRestraint.h
===================================================================
--- kernel/include/IMP/restraints/SingletonListRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/SingletonListRestraint.h (working copy)
@@ -38,6 +38,7 @@
using Restraint::add_particles;
using Restraint::clear_particles;
using Restraint::set_particles;
+ using Restraint::add_particle;
protected:
Pointer<SingletonScore> ss_;
Index: kernel/include/IMP/restraints/PairChainRestraint.h
===================================================================
--- kernel/include/IMP/restraints/PairChainRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/PairChainRestraint.h (working copy)
@@ -20,31 +20,26 @@
namespace IMP
{
-//! Restrain each pair of consecutive particles in each chain.
+//! Restrain each pair of consecutive particles in chain.
/** \ingroup restraint
*/
class IMPDLLEXPORT PairChainRestraint : public Restraint
{
public:
- //! Create the pair restraint.
+ //! Create the chain restraint.
/** \param[in] pair_score Pair score to apply.
*/
PairChainRestraint(PairScore* pair_score);
virtual ~PairChainRestraint(){}
- IMP_RESTRAINT(internal::kernel_version_info)
+ IMP_RESTRAINT(internal::kernel_version_info);
- //! Add a chain of particles
- /** Each two successive particles are restrained.
- */
- void add_chain(const Particles &ps);
+ using Restraint::add_particles;
+ using Restraint::set_particles;
+ using Restraint::clear_particles;
- //! Clear all the stored chains
- void clear_chains();
-
protected:
Pointer<PairScore> ts_;
- std::vector<unsigned int> chain_splits_;
};
} // namespace IMP
Index: kernel/include/IMP/restraints/SConscript
===================================================================
--- kernel/include/IMP/restraints/SConscript (revision 626)
+++ kernel/include/IMP/restraints/SConscript (working copy)
@@ -1,15 +1,20 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['ConnectivityRestraint.h',
- 'DistanceRestraint.h', 'AngleRestraint.h',
- 'DihedralRestraint.h', 'RestraintSet.h',
- 'NonbondedRestraint.h', 'BondDecoratorRestraint.h',
- 'SingletonListRestraint.h', 'PairListRestraint.h',
- 'TripletChainRestraint.h', 'PairChainRestraint.h',
- 'ConstantRestraint.h', 'TunnelRestraint.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'restraints')
+files=[
+ 'AngleRestraint.h',
+ 'BondDecoratorRestraint.h',
+ 'ConnectivityRestraint.h',
+ 'ConstantRestraint.h',
+ 'DihedralRestraint.h',
+ 'DistanceRestraint.h',
+ 'NonbondedRestraint.h',
+ 'PairChainRestraint.h',
+ 'PairListRestraint.h',
+ 'PairRestraint.h',
+ 'RestraintSet.h',
+ 'SingletonListRestraint.h',
+ 'TripletChainRestraint.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'restraints' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/restraints/TunnelRestraint.h
===================================================================
--- kernel/include/IMP/restraints/TunnelRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/TunnelRestraint.h (working copy)
@@ -1,83 +0,0 @@
-/**
- * \file TunnelRestraint.h \brief Tunnel restraint.
- *
- * Just return a constant.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- *
- */
-
-#ifndef __IMP_TUNNEL_RESTRAINT_H
-#define __IMP_TUNNEL_RESTRAINT_H
-
-#include "../IMP_config.h"
-#include "../Restraint.h"
-#include "../Vector3D.h"
-#include "../UnaryFunction.h"
-#include "../internal/kernel_version_info.h"
-
-namespace IMP
-{
-
-class PairScore;
-
-//! Restrain particles to a tunnel.
-/** Particles with x,y,z coordinates and an optional radius are
- prevented from being in a volume destribed by a slab from
- (center[i]-height) to (center+height) on the ith coordinate with a
- tunnel of radius r centered at center. To set which coordinate
- is used use the get/set _coordinate functions.
-
- Note that the UnaryFunction should look like a lower bound with 0
- meaning that the particle is just touching the tunnel.
-
- \ingroup restraint
- */
-class IMPDLLEXPORT TunnelRestraint : public Restraint
-{
- int coordinate_;
- Vector3D center_;
- Float height_;
- Float radius_;
- Pointer<UnaryFunction> f_;
- FloatKey rk_;
-public:
- TunnelRestraint(UnaryFunction* f, FloatKey rk);
-
- void set_center(Vector3D c){
- center_=c;
- }
- void set_height(Float h){
- IMP_check(h >= 0,
- "Height can't be negative",
- ValueException);
- height_=h;
- }
- void set_radius(Float h){
- IMP_check(h >= 0,
- "Radius can't be negative",
- ValueException);
- radius_=h;
- }
- void set_coordinate(unsigned int i) {
- IMP_check(i < 3,
- "Invalid coordinate value",
- ValueException);
- coordinate_=i;
- }
- unsigned int get_coordinate() const {
- return coordinate_;
- }
-
- using Restraint::add_particles;
- using Restraint::add_particle;
- using Restraint::set_particles;
- using Restraint::clear_particles;
- using Restraint::erase_particle;
-
- IMP_RESTRAINT(internal::kernel_version_info)
-};
-
-} // namespace IMP
-
-#endif /* __IMP_TUNNEL_RESTRAINT_H */
Index: kernel/include/IMP/restraints/NonbondedRestraint.h
===================================================================
--- kernel/include/IMP/restraints/NonbondedRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/NonbondedRestraint.h (working copy)
@@ -16,12 +16,11 @@
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
#include "../score_states/NonbondedListScoreState.h"
+#include "../PairScore.h"
namespace IMP
{
-class PairScore;
-
//! Apply a PairScore to all nonbonded pairs of particles
/**
\ingroup restraint
Index: kernel/include/IMP/restraints/BondDecoratorRestraint.h
===================================================================
--- kernel/include/IMP/restraints/BondDecoratorRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/BondDecoratorRestraint.h (working copy)
@@ -16,12 +16,11 @@
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
#include "../UnaryFunction.h"
+#include "../score_states/ManualBondDecoratorListScoreState.h"
namespace IMP
{
-class BondDecoratorListScoreState;
-
//! Restrain all pairs of non-bonded particles
/** This restraint currently only works for bonds which have their
length set explicitly. Eventually we should add a table for standard
@@ -40,7 +39,8 @@
\param[in] bl The BondDecoratorListScoreState to use to get the list
of bonds.
*/
- BondDecoratorRestraint(UnaryFunction *f, BondDecoratorListScoreState *bl);
+ BondDecoratorRestraint(UnaryFunction *f,
+ ManualBondDecoratorListScoreState *bl);
virtual ~BondDecoratorRestraint(){}
IMP_RESTRAINT(internal::kernel_version_info)
@@ -48,7 +48,7 @@
void set_function(UnaryFunction *f) {f_=f;}
protected:
- BondDecoratorListScoreState *bl_;
+ Pointer<ManualBondDecoratorListScoreState> bl_;
Pointer<UnaryFunction> f_;
};
Index: kernel/include/IMP/restraints/PairListRestraint.h
===================================================================
--- kernel/include/IMP/restraints/PairListRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/PairListRestraint.h (working copy)
@@ -39,6 +39,10 @@
void add_particle_pair(ParticlePair p);
void clear_particle_pairs();
void add_particle_pairs(const ParticlePairs &ps);
+ void set_particle_pairs(const ParticlePairs &ps) {
+ clear_particle_pairs();
+ add_particle_pairs(ps);
+ }
protected:
Pointer<PairScore> ss_;
Index: kernel/include/IMP/restraints/DistanceRestraint.h
===================================================================
--- kernel/include/IMP/restraints/DistanceRestraint.h (revision 626)
+++ kernel/include/IMP/restraints/DistanceRestraint.h (working copy)
@@ -10,7 +10,7 @@
#include "../IMP_config.h"
#include "../pair_scores/DistancePairScore.h"
-#include "../Restraint.h"
+#include "PairRestraint.h"
#include "../internal/kernel_version_info.h"
#include <iostream>
@@ -23,7 +23,7 @@
\note If the particles are closer than a certain distance, then
the contributions to the derivatives are set to 0.
*/
-class IMPDLLEXPORT DistanceRestraint : public Restraint
+class IMPDLLEXPORT DistanceRestraint : public PairRestraint
{
public:
//! Create the distance restraint.
@@ -35,11 +35,7 @@
Particle* p1, Particle* p2);
virtual ~DistanceRestraint() {}
- IMP_RESTRAINT(internal::kernel_version_info)
-
-protected:
- //! scoring function for this restraint
- DistancePairScore dp_;
+ void show(std::ostream &out=std::cout) const;
};
} // namespace IMP
Index: kernel/include/IMP/restraints/PairRestraint.h
===================================================================
--- kernel/include/IMP/restraints/PairRestraint.h (revision 0)
+++ kernel/include/IMP/restraints/PairRestraint.h (revision 0)
@@ -0,0 +1,47 @@
+/**
+ * \file PairRestraint.h \brief Pair restraint between two particles.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#ifndef __IMP_PAIR_RESTRAINT_H
+#define __IMP_PAIR_RESTRAINT_H
+
+#include "../IMP_config.h"
+#include "../PairScore.h"
+#include "../Restraint.h"
+#include "../Pointer.h"
+#include "../internal/kernel_version_info.h"
+
+#include <iostream>
+
+namespace IMP
+{
+
+//! Pair restraint between two particles
+/**
+ Apply a pair score to a pair of particles.
+ */
+class IMPDLLEXPORT PairRestraint : public Restraint
+{
+public:
+ //! Create the pair restraint.
+ /** \param[in] score_func Scoring function for the restraint.
+ \param[in] p1 Pointer to first particle in distance restraint.
+ \param[in] p2 Pointer to second particle in distance restraint.
+ */
+ PairRestraint(PairScore* score_func,
+ Particle* p1, Particle* p2);
+ virtual ~PairRestraint() {}
+
+ IMP_RESTRAINT(internal::kernel_version_info)
+
+protected:
+ //! scoring function for this restraint
+ Pointer<PairScore> dp_;
+};
+
+} // namespace IMP
+
+#endif /* __IMP_PAIR_RESTRAINT_H */
Index: kernel/include/IMP/Restraint.h
===================================================================
--- kernel/include/IMP/Restraint.h (revision 626)
+++ kernel/include/IMP/Restraint.h (working copy)
@@ -51,6 +51,11 @@
\note Physical restraints should use the units of kcal/mol for restraint
values and kcal/mol/A for derivatives.
+
+ \note Restraints will print a warning message if they are destroyed
+ without ever having been added to a model as this is an easy mistake
+ to make. To disable this warning for a particular restraint, call
+ set_was_owned(true).
*/
class IMPDLLEXPORT Restraint : public RefCountedObject
{
@@ -94,18 +99,31 @@
Model *get_model() const {
IMP_assert(model_,
"get_model() called before set_model()");
- return model_.get();
+ return model_;
}
+ /** A warning is printed if a restraint is destroyed
+ without ever having belonged to a restraint set or a model.
+ */
+ void set_was_owned(bool tf) {
+ was_owned_=tf;
+ }
+
IMP_LIST(protected, Particle, particle, Particle*)
private:
- Pointer<Model> model_;
+ // not ref counted as the model has a pointer to this
+ Model *model_;
/* True if restraint has not been deactivated.
If it is not active, evaluate should not be called
*/
bool is_active_;
+
+ /* keep track of whether the restraint ever was in a model.
+ Give warnings on destruction if it was not.
+ */
+ bool was_owned_;
};
IMP_OUTPUT_OPERATOR(Restraint);
Index: kernel/include/IMP/ParticleRefiner.h
===================================================================
--- kernel/include/IMP/ParticleRefiner.h (revision 626)
+++ kernel/include/IMP/ParticleRefiner.h (working copy)
@@ -34,7 +34,7 @@
//! 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);
+ virtual Particles get_refined(Particle *a) const;
//! Cleanup after refining
/** If da is non-NULL then the derivatives should be propagated
@@ -43,7 +43,7 @@
can be destroyed if they are temporary.
*/
virtual void cleanup_refined(Particle *a, Particles &b,
- DerivativeAccumulator *da=0) {}
+ DerivativeAccumulator *da=0) const {}
virtual void show(std::ostream &out=std::cout) const {
out << "ParticleRefiner base" << std::endl;
};
Index: kernel/include/IMP/optimizers/states/SConscript
===================================================================
--- kernel/include/IMP/optimizers/states/SConscript (revision 626)
+++ kernel/include/IMP/optimizers/states/SConscript (working copy)
@@ -1,10 +1,10 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['VRMLLogOptimizerState.h', 'CMMLogOptimizerState.h',
- 'VelocityScalingOptimizerState.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'optimizers', 'states')
+files=[
+ 'CMMLogOptimizerState.h',
+ 'VelocityScalingOptimizerState.h',
+ 'VRMLLogOptimizerState.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'optimizers', 'states' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/optimizers/SConscript
===================================================================
--- kernel/include/IMP/optimizers/SConscript (revision 626)
+++ kernel/include/IMP/optimizers/SConscript (working copy)
@@ -1,12 +1,16 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['ConjugateGradients.h', 'SteepestDescent.h', 'MolecularDynamics.h',
- 'MoverBase.h', 'MonteCarlo.h', 'Mover.h', 'BrownianDynamics.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'optimizers')
+files=[
+ 'BrownianDynamics.h',
+ 'ConjugateGradients.h',
+ 'MolecularDynamics.h',
+ 'MonteCarlo.h',
+ 'MoverBase.h',
+ 'Mover.h',
+ 'SteepestDescent.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'optimizers' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
-SConscript('states/SConscript')
-SConscript('movers/SConscript')
+SConscript('movers/SConscript' )
+SConscript('states/SConscript' )
Index: kernel/include/IMP/optimizers/movers/SConscript
===================================================================
--- kernel/include/IMP/optimizers/movers/SConscript (revision 626)
+++ kernel/include/IMP/optimizers/movers/SConscript (working copy)
@@ -1,8 +1,9 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['BallMover.h', 'NormalMover.h']
-
+files=[
+ 'BallMover.h',
+ 'NormalMover.h',
+ ]
includedir = os.path.join(env['includedir'], 'IMP', 'optimizers', 'movers' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/decorators/XYZDecorator.h
===================================================================
--- kernel/include/IMP/decorators/XYZDecorator.h (revision 626)
+++ kernel/include/IMP/decorators/XYZDecorator.h (working copy)
@@ -8,16 +8,13 @@
#ifndef __IMP_XYZ_DECORATOR_H
#define __IMP_XYZ_DECORATOR_H
-#include <vector>
-#include <deque>
-#include <limits>
-
-#include "../Particle.h"
-#include "../Model.h"
#include "../DecoratorBase.h"
#include "../Vector3D.h"
#include "utility.h"
+#include <vector>
+#include <limits>
+
namespace IMP
{
@@ -110,10 +107,7 @@
//! Get a vector containing the keys for x,y,z
/** This is quite handy for initializing movers and things.
*/
- static const FloatKeys get_xyz_keys() {
- decorator_initialize_static_data();
- return key_;
- }
+ IMP_DECORATOR_GET_KEY(FloatKeys, xyz_keys, key_)
//! Generate random coordinates in a sphere centered at the vector
void randomize_in_sphere(const Vector3D ¢er, float radius);
Index: kernel/include/IMP/decorators/XYZRDecorator.h
===================================================================
--- kernel/include/IMP/decorators/XYZRDecorator.h (revision 0)
+++ kernel/include/IMP/decorators/XYZRDecorator.h (revision 0)
@@ -0,0 +1,63 @@
+/**
+ * \file XYZRDecorator.h \brief Simple xyz decorator.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#ifndef __IMP_XYZR_DECORATOR_H
+#define __IMP_XYZR_DECORATOR_H
+
+#include "XYZDecorator.h"
+
+#include <vector>
+#include <deque>
+#include <limits>
+
+namespace IMP
+{
+
+//! A a decorator for a particle with x,y,z coordinates.
+/** \ingroup helper
+ */
+class IMPDLLEXPORT XYZRDecorator: public XYZDecorator
+{
+ IMP_DECORATOR(XYZRDecorator, XYZDecorator,
+ {
+ return p->has_attribute(radius_);
+ },
+ { p->add_attribute(radius_,0);
+ });
+
+protected:
+ static FloatKey radius_;
+
+public:
+ IMP_DECORATOR_GET_SET(radius, radius_, Float, Float);
+ IMP_DECORATOR_GET_KEY(FloatKey, radius_key, radius_);
+};
+
+IMP_OUTPUT_OPERATOR(XYZRDecorator);
+
+//! Compute the distance between a pair of particles
+/** \ingroup helper
+ */
+IMPDLLEXPORT Float distance(XYZRDecorator a, XYZRDecorator b);
+
+//! Set the coordinates and radius of the last to enclose the list
+/** \ingroup helper
+ \param[in] v The vector of XYZR objects to enclose
+ \param[out] b The one whose values should be set
+
+ \note this takes a Particles object rather than a vector of
+ something else since you can't easily cast vectors of
+ different things to one another. Well, you can cast vectors
+ of decorators in C++, but you can't in python without adding
+ explicit support.
+ */
+IMPDLLEXPORT void set_enclosing_sphere(const Particles &v,
+ XYZRDecorator b);
+
+} // namespace IMP
+
+#endif /* __IMP_XYZR_DECORATOR_H */
Index: kernel/include/IMP/decorators/HierarchyDecorator.h
===================================================================
--- kernel/include/IMP/decorators/HierarchyDecorator.h (revision 626)
+++ kernel/include/IMP/decorators/HierarchyDecorator.h (working copy)
@@ -19,6 +19,7 @@
#include <limits>
#include <vector>
#include <deque>
+#include <memory>
namespace IMP
{
@@ -135,14 +136,14 @@
\ingroup hierarchy
*/
IMPDLLEXPORT
-void breadth_first_traversal(HierarchyDecorator d, HierarchyVisitor &v);
+void breadth_first_traversal(HierarchyDecorator d, HierarchyVisitor *v);
//! Depth first traversal of the hierarchy
/** See breadth_first_traversal and HierarchyVisitor for more information
\ingroup hierarchy
*/
IMPDLLEXPORT
-void depth_first_traversal(HierarchyDecorator d, HierarchyVisitor &v);
+void depth_first_traversal(HierarchyDecorator d, HierarchyVisitor *v);
//! Apply functor F to each particle, traversing the hierarchy breadth first.
@@ -313,23 +314,35 @@
};
+/** This returns an auto_ptr so that the objects are cleaned up properly.
+ I have to pass a non-const ref (or a pointer) to the algorithms which
+ are getting the gather object. Returning an autoptr ensures that the
+ object is alive until after the function call has completed (if gather
+ is called in the parens for the function).
+
+ \internal
+*/
+template <class F, class Out>
+std::auto_ptr<Gather<F, Out> > gather(F f, Out out) {
+ return std::auto_ptr<Gather<F, Out> >(new Gather<F, Out>(f, out));
+}
+
} // namespace internal
//! Gather all the Particle* in the hierarchy which meet some criteria
/** \ingroup hierarchy
*/
-template <class Out, class F>
-Out hierarchy_gather(HierarchyDecorator h, F f, Out out)
+template <class F>
+Particles hierarchy_get(HierarchyDecorator h, F f)
{
- internal::Gather<F,Out> gather(f,out);
- depth_first_traversal(h, gather);
- return gather.get_out();
+ Particles ret;
+ depth_first_traversal(h, internal::gather(f,std::back_inserter(ret)).get());
+ return ret;
}
namespace internal
{
-
template <class K, class V>
struct MatchAttribute
{
@@ -341,20 +354,19 @@
else return o->get_value(k_) == v_;
}
};
+}
-} // namespace internal
-
//! Gather all the Particle* in the hierarchy which match on an attribute
/** \ingroup hierarchy
*/
-template <class Out, class K, class V>
-Out hierarchy_gather_by_attribute(HierarchyDecorator h, K k, V v, Out out)
+template <class K, class V>
+Particles hierarchy_get_by_attribute(HierarchyDecorator h, K k,
+ V v)
{
- internal::Gather<internal::MatchAttribute<K, V>,Out>
- gather(internal::MatchAttribute<K,V>(k,v),
- out);
- depth_first_traversal(h, gather);
- return gather.get_out();
+ Particles ret;
+ depth_first_traversal(h, gather(internal::MatchAttribute<K,V>(k,v),
+ std::back_inserter(ret)).get());
+ return ret;
}
@@ -380,20 +392,27 @@
}
};
+template <class K0, class V0, class K1, class V1>
+MatchAttributes<K0, V0, K1, V1>
+match_attributes(K0 k0, V0 v0,
+ K1 k1, V1 v1) {
+ return MatchAttributes<K0, V0, K1, V1>(k0, v0, k1, v1);
+}
+
} // namespace internal
//! Gather all the Particle* in the hierarchy which match on two attributes
/** \ingroup hierarchy
*/
-template <class Out, class K0, class V0, class K1, class V1>
-Out hierarchy_gather_by_attributes(HierarchyDecorator h, K0 k0,
- V0 v0, K1 k1, V1 v1, Out out)
+template <class K0, class V0, class K1, class V1>
+Particles hierarchy_get_by_attributes(HierarchyDecorator h, K0 k0,
+ V0 v0, K1 k1, V1 v1)
{
- internal::Gather<internal::MatchAttributes<K0, V0, K1, V1>,Out>
- gather(internal::MatchAttributes<K0,V0, K1, V1>(k0,v0, k1, v1),
- out);
- depth_first_traversal(h, gather);
- return gather.get_out();
+ Particles ret;
+ depth_first_traversal(h,
+ gather(internal::match_attributes(k0,v0, k1, v1),
+ std::back_inserter(ret)).get());
+ return ret;
}
Index: kernel/include/IMP/decorators/SConscript
===================================================================
--- kernel/include/IMP/decorators/SConscript (revision 626)
+++ kernel/include/IMP/decorators/SConscript (working copy)
@@ -1,11 +1,18 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['HierarchyDecorator.h', 'NameDecorator.h', 'utility.h',
- 'XYZDecorator.h', 'ResidueDecorator.h', 'AtomDecorator.h',
- 'MolecularHierarchyDecorator.h', 'bond_decorators.h', 'macros.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'decorators')
+files=[
+ 'AtomDecorator.h',
+ 'bond_decorators.h',
+ 'HierarchyDecorator.h',
+ 'macros.h',
+ 'MolecularHierarchyDecorator.h',
+ 'NameDecorator.h',
+ 'ResidueDecorator.h',
+ 'utility.h',
+ 'XYZDecorator.h',
+ 'XYZRDecorator.h',
+ 'yaml.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'decorators' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/decorators/yaml.h
===================================================================
--- kernel/include/IMP/decorators/yaml.h (revision 0)
+++ kernel/include/IMP/decorators/yaml.h (revision 0)
@@ -0,0 +1,49 @@
+#ifndef IMP_DECORATORS_YAML_H
+#define IMP_DECORATORS_YAML_H
+#include "../Particle.h"
+#include "../Model.h"
+
+namespace IMP
+{
+
+ //! Write the particle to a stream as a YAML stream
+ /** \param[in] p The particle to write
+ \param[in] out The stream to write to
+ \param[in] indent The base level of indentation
+ */
+ IMPDLLEXPORT void write_yaml(Particle *p,
+ std::ostream &out= std::cout,
+ std::string indent="");
+
+//! Write the model to a stream as a YAML stream
+ /** \param[in] m The model to write
+ \param[in] out The stream to write to
+ \param[in] indent The base level of indentation
+ */
+ IMPDLLEXPORT void write_yaml(Model *m,
+ std::ostream &out= std::cout,
+ std::string indent="");
+
+ //! Read the particle from a YAML stream
+ /** The model must already have particles matching all read particles.
+ Currently the particles must already have the same attributes
+ as are being read, but this probably should change due to lists
+ stored in attributes.
+
+ The intentended usage model is that the model (with restraints) is
+ initialized. Optimization is performed and then the model is written
+ out to a file. Some time later, when you want to reload the model,
+ you can reuse the initialization code to set up the restraints,
+ and then read in the values for the attributes.
+
+ \note The base indent is determined from the first line. */
+ IMPDLLEXPORT void read_yaml(std::istream &in,
+ Model *m);
+
+ //! primarily for debuggin*/
+ IMPDLLEXPORT void read_yaml(std::string contents,
+ Model *m);
+
+}
+
+#endif
Index: kernel/include/IMP/decorators/AtomDecorator.h
===================================================================
--- kernel/include/IMP/decorators/AtomDecorator.h (revision 626)
+++ kernel/include/IMP/decorators/AtomDecorator.h (working copy)
@@ -14,9 +14,6 @@
#include "utility.h"
#include "XYZDecorator.h"
-#include <vector>
-#include <deque>
-
namespace IMP
{
Index: kernel/include/IMP/decorators/macros.h
===================================================================
--- kernel/include/IMP/decorators/macros.h (revision 626)
+++ kernel/include/IMP/decorators/macros.h (working copy)
@@ -261,5 +261,15 @@
#define IMP_DECORATOR_ARRAY_INIT(DecoratorType, name) \
name##_data_.initialize();
+//! add a method to get a key
+/** One has to make sure to call the
+ decorator_initialize_static_data method first
+ */
+#define IMP_DECORATOR_GET_KEY(KeyType, key_name, variable_name)\
+ static KeyType get_##key_name() { \
+ decorator_initialize_static_data(); \
+ return variable_name; \
+ }
+
#endif /* __IMP_DECORATOR_MACROS_H */
Index: kernel/include/IMP/OptimizerState.h
===================================================================
--- kernel/include/IMP/OptimizerState.h (revision 626)
+++ kernel/include/IMP/OptimizerState.h (working copy)
@@ -60,11 +60,11 @@
Optimizer *get_optimizer() const {
IMP_assert(optimizer_,
"Must call set_optimizer before get_optimizer on state");
- return optimizer_.get();
+ return optimizer_;
}
protected:
- //! Stored optimizer
- Pointer<Optimizer> optimizer_;
+ //! Stored optimizer. Non-ref counted
+ Optimizer *optimizer_;
};
IMP_OUTPUT_OPERATOR(OptimizerState);
Index: kernel/include/IMP/pair_scores/SphereDistancePairScore.h
===================================================================
--- kernel/include/IMP/pair_scores/SphereDistancePairScore.h (revision 626)
+++ kernel/include/IMP/pair_scores/SphereDistancePairScore.h (working copy)
@@ -11,6 +11,7 @@
#include "../PairScore.h"
#include "../Pointer.h"
#include "../UnaryFunction.h"
+#include "../decorators/XYZRDecorator.h"
namespace IMP
{
@@ -24,10 +25,10 @@
FloatKey radius_;
public:
SphereDistancePairScore(UnaryFunction *f,
- FloatKey radius=FloatKey("radius"));
+ FloatKey radius= XYZRDecorator::get_radius_key());
virtual ~SphereDistancePairScore(){}
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
};
Index: kernel/include/IMP/pair_scores/TypedPairScore.h
===================================================================
--- kernel/include/IMP/pair_scores/TypedPairScore.h (revision 626)
+++ kernel/include/IMP/pair_scores/TypedPairScore.h (working copy)
@@ -38,7 +38,7 @@
virtual ~TypedPairScore() {}
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
@@ -48,7 +48,7 @@
be overridden in a subclass to automatically set the type of a particle,
e.g. from other particle attributes such as an atom or residue name.
*/
- virtual void set_particle_type(Particle *p) {}
+ virtual void set_particle_type(Particle *p) const {}
//! Set the PairScore to delegate to for a given pair of particle types.
/** \param[in] ps PairScore to use at evaluate time.
Index: kernel/include/IMP/pair_scores/SConscript
===================================================================
--- kernel/include/IMP/pair_scores/SConscript (revision 626)
+++ kernel/include/IMP/pair_scores/SConscript (working copy)
@@ -1,11 +1,12 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['DistancePairScore.h', 'SphereDistancePairScore.h',
- 'RefineOncePairScore.h', 'TypedPairScore.h',
- 'TransformedDistancePairScore.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'pair_scores')
+files=[
+ 'DistancePairScore.h',
+ 'RefineOncePairScore.h',
+ 'SphereDistancePairScore.h',
+ 'TransformedDistancePairScore.h',
+ 'TypedPairScore.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'pair_scores' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/pair_scores/DistancePairScore.h
===================================================================
--- kernel/include/IMP/pair_scores/DistancePairScore.h (revision 626)
+++ kernel/include/IMP/pair_scores/DistancePairScore.h (working copy)
@@ -25,8 +25,11 @@
DistancePairScore(UnaryFunction *f);
virtual ~DistancePairScore(){}
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
+ UnaryFunction *get_unary_function() const {
+ return f_;
+ }
};
} // namespace IMP
Index: kernel/include/IMP/pair_scores/RefineOncePairScore.h
===================================================================
--- kernel/include/IMP/pair_scores/RefineOncePairScore.h (revision 626)
+++ kernel/include/IMP/pair_scores/RefineOncePairScore.h (working copy)
@@ -34,7 +34,7 @@
RefineOncePairScore(ParticleRefiner *r, PairScore *f);
virtual ~RefineOncePairScore(){}
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
};
Index: kernel/include/IMP/pair_scores/TransformedDistancePairScore.h
===================================================================
--- kernel/include/IMP/pair_scores/TransformedDistancePairScore.h (revision 626)
+++ kernel/include/IMP/pair_scores/TransformedDistancePairScore.h (working copy)
@@ -25,6 +25,11 @@
The second particle, x, is transformed as R*(x-center)+ translation+center
+ \note While it would be nice to have this apply a general pair
+ score to the transformed particle, this would require either creating
+ a temporary particle or rewriting and then restoring the coordinates
+ of the particle being transformed. Neither of which sound appealing.
+
\ingroup pairscore
*/
class IMPDLLEXPORT TransformedDistancePairScore : public PairScore
@@ -36,7 +41,7 @@
TransformedDistancePairScore(UnaryFunction *f);
virtual ~TransformedDistancePairScore(){}
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
void set_rotation(float r00, float r01, float r02,
Index: kernel/include/IMP/internal/SConscript
===================================================================
--- kernel/include/IMP/internal/SConscript (revision 626)
+++ kernel/include/IMP/internal/SConscript (working copy)
@@ -1,14 +1,23 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['AttributeTable.h', 'graph_base.h', 'Grid3D.h', 'Vector.h',
- 'ref_counting.h', 'ObjectContainer.h', 'ParticleGrid.h',
- 'kernel_version_info.h', 'constants.h', 'units.h',
- 'utility.h', 'bbox_nbl_helpers.h',
- 'ArrayOnAttributesHelper.h', 'Unit.h', 'ExponentialNumber.h',
- 'evaluate_distance_pair_score.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'internal')
+files=[
+ 'ArrayOnAttributesHelper.h',
+ 'AttributeTable.h',
+ 'bbox_nbl_helpers.h',
+ 'constants.h',
+ 'evaluate_distance_pair_score.h',
+ 'ExponentialNumber.h',
+ 'graph_base.h',
+ 'Grid3D.h',
+ 'kernel_version_info.h',
+ 'ObjectContainer.h',
+ 'ParticleGrid.h',
+ 'ref_counting.h',
+ 'Unit.h',
+ 'units.h',
+ 'utility.h',
+ 'Vector.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'internal' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/internal/units.h
===================================================================
--- kernel/include/IMP/internal/units.h (revision 626)
+++ kernel/include/IMP/internal/units.h (working copy)
@@ -119,6 +119,12 @@
typedef Multiply<Multiply<Centimeter, Centimeter>::type,
Centimeter>::type CubicCentimeter;
typedef Divide<Gram, CubicCentimeter>::type GramPerCubicCentimeter;
+typedef Shift<Second, -9>::type Nanosecond;
+typedef Shift<Meter, -9>::type Nanometer;
+typedef Multiply<Multiply<Nanometer, Nanometer>::type,
+ Nanometer>::type CubicNanometer;
+typedef Shift<Second, -15>::type Femtosecond;
+typedef Divide<Piconewton, Nanometer>::type PiconewtonPerNanometer;
Index: kernel/include/IMP/internal/AttributeTable.h
===================================================================
--- kernel/include/IMP/internal/AttributeTable.h (revision 626)
+++ kernel/include/IMP/internal/AttributeTable.h (working copy)
@@ -183,6 +183,11 @@
map_[k.get_index()] = v;
}
+ void set_values(Value v) {
+ for (unsigned int i=0; i< size_; ++i) {
+ map_[i]=v;
+ }
+ }
void insert(Key k, Value v) {
IMP_assert(!contains(k),
Index: kernel/include/IMP/internal/Grid3D.h
===================================================================
--- kernel/include/IMP/internal/Grid3D.h (revision 626)
+++ kernel/include/IMP/internal/Grid3D.h (working copy)
@@ -139,6 +139,16 @@
}
};
+
+
+
+
+
+
+
+
+
+
//! Represent a real cell in a grid
/** These indexes represent an actual cell in the grid with no mapping.
They can only be constructed by the grid.
@@ -160,6 +170,16 @@
}
};
+
+
+
+
+
+
+
+
+
+
/** \brief A voxel grid in 3D space.
VT can be any class.
\internal
@@ -340,12 +360,12 @@
}
//! Get the data in a particular cell
- VoxelData& get_voxel(Index gi) {
+ typename std::vector<VT>::reference get_voxel(Index gi) {
return data_[index(gi)];
}
//! Get the data in a particular cell
- const VoxelData& get_voxel(Index gi) const {
+ typename std::vector<VT>::const_reference get_voxel(Index gi) const {
return data_[index(gi)];
}
Index: kernel/include/IMP/internal/ref_counting.h
===================================================================
--- kernel/include/IMP/internal/ref_counting.h (revision 626)
+++ kernel/include/IMP/internal/ref_counting.h (working copy)
@@ -27,7 +27,6 @@
template <class O>
static void eval(O* o) {
BOOST_STATIC_ASSERT((!boost::is_base_of<RefCountedObject, O >::value));
- IMP_LOG(VERBOSE, "Not refing particle " << o << std::endl);
}
};
@@ -36,8 +35,6 @@
{
template <class O>
static void eval(O* o) {
- IMP_LOG(VERBOSE, "Refing particle " << o->get_index()
- << o->get_ref_count() << std::endl);
o->assert_is_valid();
o->ref();
}
@@ -49,7 +46,6 @@
template <class O>
static void eval(O* o) {
BOOST_STATIC_ASSERT((!boost::is_base_of<RefCountedObject, O >::value));
- IMP_LOG(VERBOSE, "Not Unrefing object " << o << std::endl);
}
};
@@ -58,8 +54,6 @@
{
template <class O>
static void eval(O *o) {
- IMP_LOG(VERBOSE, "Unrefing particle " << o->get_index()
- << " " << o->get_ref_count() << std::endl);
o->assert_is_valid();
o->unref();
if (!o->get_has_ref()) {
@@ -104,9 +98,6 @@
template <class O>
void disown(O* o)
{
- /*IMP_LOG(VERBOSE, "Disown called with "
- << (boost::is_base_of<RefCountedObject, O >::value)
- << " for " << o << " " << o->get_ref_count() << std::endl);*/
o->unref();
if (!o->get_has_ref()) {
delete o;
@@ -118,10 +109,6 @@
template <class O>
void own(O* o)
{
- /*IMP_LOG(VERBOSE, "Own called with "
- << (boost::is_base_of<RefCountedObject, O >::value)
- << " for " << o
- << " " << o->get_ref_count() << std::endl);*/
if (boost::is_base_of<RefCountedObject, O >::value) {
// no checks
} else {
@@ -133,6 +120,9 @@
}
+
+
+
} // namespace internal
} // namespace IMP
Index: kernel/include/IMP/PairScore.h
===================================================================
--- kernel/include/IMP/PairScore.h (revision 626)
+++ kernel/include/IMP/PairScore.h (working copy)
@@ -32,7 +32,7 @@
virtual ~PairScore() {}
//! Compute the score for the pair and the derivative if needed.
virtual Float evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da) = 0;
+ DerivativeAccumulator *da) const = 0;
virtual void show(std::ostream &out=std::cout) const = 0;
};
Index: kernel/include/IMP/Key.h
===================================================================
--- kernel/include/IMP/Key.h (revision 626)
+++ kernel/include/IMP/Key.h (working copy)
@@ -70,7 +70,7 @@
typedef std::vector<Name> Name##s
-/** This must occur in exactly one .o in the internal namespace. Should
+/** This must occur in exactly one .o in the application. Should
be used in the IMP namespace.*/
#define IMP_DEFINE_KEY_TYPE(Name, Tag) \
namespace internal { \
Index: kernel/include/IMP/Vector3D.h
===================================================================
--- kernel/include/IMP/Vector3D.h (revision 626)
+++ kernel/include/IMP/Vector3D.h (working copy)
@@ -120,6 +120,27 @@
operator[](2) + o[2]);
}
+ //! Accumulate the vector
+ void operator+=(const Vector3D &o) {
+ vec_[0]+= o[0];
+ vec_[1]+= o[1];
+ vec_[2]+= o[2];
+ }
+
+ //! rescale the vector
+ void operator/=(float f) {
+ vec_[0]/= f;
+ vec_[1]/= f;
+ vec_[2]/= f;
+ }
+
+ //! rescale the vector
+ void operator*=(float f) {
+ vec_[0]*= f;
+ vec_[1]*= f;
+ vec_[2]*= f;
+ }
+
void show(std::ostream &out=std::cout) const {
out << "(" << operator[](0) << ", " << operator[](1) << ", "
<< operator[](2) << ")";
Index: kernel/include/IMP/exception.h
===================================================================
--- kernel/include/IMP/exception.h (revision 626)
+++ kernel/include/IMP/exception.h (working copy)
@@ -20,6 +20,7 @@
namespace IMP
{
+
//! The general base class for IMP exceptions
/** This way we can catch IMP exceptions without getting memory allocation
errors and everything. And it enforces having a description.
@@ -65,6 +66,7 @@
}
};
+
//! A general exception for an error in IMP.
/** \ingroup assert
*/
@@ -147,6 +149,10 @@
*/
IMPDLLEXPORT void check_fail(const char *msg);
+
+//! Control this through functions in Log.h
+extern bool print_exceptions;
+
} // namespace internal
} // namespace IMP
@@ -199,6 +205,10 @@
\param[in] exception Throw the object constructed by this expression.
\ingroup assert
*/
-#define IMP_failure(message, exception) {IMP_ERROR(message); throw exception;}
+#define IMP_failure(message, exception) { \
+ std::ostringstream oss; \
+ oss << message << std::endl; \
+ IMP::internal::check_fail(oss.str().c_str()); \
+ throw exception(oss.str().c_str());}
#endif /* __IMP_EXCEPTION_H */
Index: kernel/include/IMP/unary_functions/ClosedCubicSpline.h
===================================================================
--- kernel/include/IMP/unary_functions/ClosedCubicSpline.h (revision 626)
+++ kernel/include/IMP/unary_functions/ClosedCubicSpline.h (working copy)
@@ -36,7 +36,7 @@
\exception ValueException Feature is out of defined range.
\return Score
*/
- virtual Float evaluate(Float feature);
+ virtual Float evaluate(Float feature) const;
//! Calculate score and derivative with respect to the given feature.
/** \param[in] feature Value of feature being tested.
@@ -45,7 +45,7 @@
\exception ValueException Feature is out of defined range.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv);
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const;
void show(std::ostream &out=std::cout) const {
out << "Closed cubic spline of " << values_.size() << " values from "
Index: kernel/include/IMP/unary_functions/Linear.h
===================================================================
--- kernel/include/IMP/unary_functions/Linear.h (revision 626)
+++ kernel/include/IMP/unary_functions/Linear.h (working copy)
@@ -20,13 +20,15 @@
class Linear : public UnaryFunction
{
public:
- Linear(Float slope, Float offset=0) : slope_(slope), offset_(offset) {}
+ Linear(Float offset, Float slope) : slope_(slope), offset_(offset) {}
virtual ~Linear() {}
- virtual Float evaluate(Float feature) { return (feature-offset_)*slope_; }
+ virtual Float evaluate(Float feature) const {
+ return (feature-offset_)*slope_;
+ }
- virtual Float evaluate_deriv(Float feature, Float& deriv) {
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const {
deriv= slope_;
return evaluate(feature);
}
Index: kernel/include/IMP/unary_functions/WormLikeChain.h
===================================================================
--- kernel/include/IMP/unary_functions/WormLikeChain.h (revision 626)
+++ kernel/include/IMP/unary_functions/WormLikeChain.h (working copy)
@@ -43,7 +43,7 @@
/** \param[in] l Current length in Angstroms
\return Energy in kcal/mol
*/
- virtual Float evaluate(Float lf) {
+ virtual Float evaluate(Float lf) const {
static const unit::Picojoule zero=eval(unit::Angstrom(0));
unit::Angstrom l(lf);
if (l < unit::Angstrom(0)) l=unit::Angstrom(0);
@@ -65,7 +65,7 @@
\param[out] deriv force in kcal/angstrom mol
\return Score
*/
- virtual Float evaluate_deriv(Float fl, Float& deriv) {
+ virtual Float evaluate_deriv(Float fl, Float& deriv) const {
unit::Angstrom l(fl);
if (l < unit::Angstrom(0)) l=unit::Angstrom(0);
unit::Piconewton doubled;
Index: kernel/include/IMP/unary_functions/Cosine.h
===================================================================
--- kernel/include/IMP/unary_functions/Cosine.h (revision 626)
+++ kernel/include/IMP/unary_functions/Cosine.h (working copy)
@@ -39,7 +39,7 @@
/** \param[in] feature Value of feature being tested.
\return Score
*/
- virtual Float evaluate(Float feature);
+ virtual Float evaluate(Float feature) const;
//! Calculate score and derivative with respect to the given feature.
/** \param[in] feature Value of feature being tested.
@@ -47,7 +47,7 @@
the feature value.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv);
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const;
void show(std::ostream &out=std::cout) const {
out << "Cosine function with force " << force_constant_
Index: kernel/include/IMP/unary_functions/Harmonic.h
===================================================================
--- kernel/include/IMP/unary_functions/Harmonic.h (revision 626)
+++ kernel/include/IMP/unary_functions/Harmonic.h (working copy)
@@ -55,7 +55,7 @@
/** \param[in] feature Value of feature being tested.
\return Score
*/
- virtual Float evaluate(Float feature) {
+ virtual Float evaluate(Float feature) const {
Float d;
return evaluate_deriv(feature, d);
}
@@ -66,7 +66,7 @@
the feature value.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv) {
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const {
Float e = (feature - mean_);
deriv = k_ * e;
return 0.5 * k_ * e * e;
Index: kernel/include/IMP/unary_functions/HarmonicLowerBound.h
===================================================================
--- kernel/include/IMP/unary_functions/HarmonicLowerBound.h (revision 626)
+++ kernel/include/IMP/unary_functions/HarmonicLowerBound.h (working copy)
@@ -26,7 +26,7 @@
\param[in] feature Value of feature being tested.
\return Score
*/
- virtual Float evaluate(Float feature) {
+ virtual Float evaluate(Float feature) const {
if (feature >= Harmonic::get_mean()) {
return 0.0;
} else {
@@ -41,7 +41,7 @@
the feature value.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv) {
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const {
if (feature >= Harmonic::get_mean()) {
deriv = 0.0;
return 0.0;
Index: kernel/include/IMP/unary_functions/SConscript
===================================================================
--- kernel/include/IMP/unary_functions/SConscript (revision 626)
+++ kernel/include/IMP/unary_functions/SConscript (working copy)
@@ -1,11 +1,15 @@
+Import('env')
import os.path
-Import('env')
-
-files = ['Harmonic.h', 'HarmonicLowerBound.h', 'HarmonicUpperBound.h',
- 'OpenCubicSpline.h', 'ClosedCubicSpline.h', 'Cosine.h', 'Linear.h',
- 'WormLikeChain.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'unary_functions')
+files=[
+ 'ClosedCubicSpline.h',
+ 'Cosine.h',
+ 'Harmonic.h',
+ 'HarmonicLowerBound.h',
+ 'HarmonicUpperBound.h',
+ 'Linear.h',
+ 'OpenCubicSpline.h',
+ 'WormLikeChain.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'unary_functions' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/unary_functions/OpenCubicSpline.h
===================================================================
--- kernel/include/IMP/unary_functions/OpenCubicSpline.h (revision 626)
+++ kernel/include/IMP/unary_functions/OpenCubicSpline.h (working copy)
@@ -25,7 +25,7 @@
\param[in] minrange Feature value at first spline point
\param[in] spacing Distance (in feature space) between points
*/
- OpenCubicSpline(const std::vector<Float> &values, Float minrange,
+ OpenCubicSpline(const Floats &values, Float minrange,
Float spacing);
virtual ~OpenCubicSpline() {}
@@ -35,7 +35,7 @@
\exception ValueException Feature is out of defined range.
\return Score
*/
- virtual Float evaluate(Float feature);
+ virtual Float evaluate(Float feature) const;
//! Calculate score and derivative with respect to the given feature.
/** \param[in] feature Value of feature being tested.
@@ -44,7 +44,7 @@
\exception ValueException Feature is out of defined range.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv);
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const ;
void show(std::ostream &out=std::cout) const {
out << "Open cubic spline of " << values_.size() << " values from "
Index: kernel/include/IMP/unary_functions/HarmonicUpperBound.h
===================================================================
--- kernel/include/IMP/unary_functions/HarmonicUpperBound.h (revision 626)
+++ kernel/include/IMP/unary_functions/HarmonicUpperBound.h (working copy)
@@ -26,7 +26,7 @@
\param[in] feature Value of feature being tested.
\return Score
*/
- virtual Float evaluate(Float feature) {
+ virtual Float evaluate(Float feature) const {
if (feature <= Harmonic::get_mean()) {
return 0.0;
} else {
@@ -41,7 +41,7 @@
the feature value.
\return Score
*/
- virtual Float evaluate_deriv(Float feature, Float& deriv) {
+ virtual Float evaluate_deriv(Float feature, Float& deriv) const {
if (feature <= Harmonic::get_mean()) {
deriv = 0.0;
return 0.0;
Index: kernel/include/IMP/SConscript
===================================================================
--- kernel/include/IMP/SConscript (revision 626)
+++ kernel/include/IMP/SConscript (working copy)
@@ -1,28 +1,44 @@
+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',
- 'Object.h', 'Pointer.h', 'RefCountedObject.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP')
+files=[
+ 'base_types.h',
+ 'DecoratorBase.h',
+ 'DerivativeAccumulator.h',
+ 'exception.h',
+ 'IMP_config.h',
+ 'Index.h',
+ 'Key.h',
+ 'log.h',
+ 'macros.h',
+ 'Model.h',
+ 'Object.h',
+ 'Optimizer.h',
+ 'OptimizerState.h',
+ 'PairScore.h',
+ 'Particle.h',
+ 'ParticleRefiner.h',
+ 'Pointer.h',
+ 'random.h',
+ 'RefCountedObject.h',
+ 'Restraint.h',
+ 'ScoreState.h',
+ 'SingletonScore.h',
+ 'TripletScore.h',
+ 'UnaryFunction.h',
+ 'utility.h',
+ 'Vector3D.h',
+ 'VersionInfo.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('particle_refiners/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.h
===================================================================
--- kernel/include/IMP/Particle.h (revision 626)
+++ kernel/include/IMP/Particle.h (working copy)
@@ -98,7 +98,7 @@
/** \return all particle data in the model.
*/
Model* get_model() const {
- return model_.get();
+ return model_;
}
//! Add a Float attribute to this particle.
@@ -369,7 +369,8 @@
// Set pointer to model particle data.
void set_model(Model *md, ParticleIndex pi);
- Pointer<Model> model_;
+ // not ref counted as the model has a pointer to this
+ Model *model_;
// true if particle is active
bool is_active_;
Index: kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h
===================================================================
--- kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (revision 626)
+++ kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (working copy)
@@ -8,12 +8,14 @@
#ifndef __IMP_BOND_COVER_PARTICLE_REFINER_H
#define __IMP_BOND_COVER_PARTICLE_REFINER_H
+#include "../ParticleRefiner.h"
#include "../internal/kernel_version_info.h"
-#include "../ParticleRefiner.h"
namespace IMP
{
+class Particle;
+
//! 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
@@ -23,9 +25,11 @@
{
FloatKey rk_;
FloatKey vk_;
+ IntKey tk_;
public:
BondCoverParticleRefiner(FloatKey rk,
- FloatKey vk);
+ FloatKey vk,
+ IntKey tk=IntKey());
virtual ~BondCoverParticleRefiner() {}
Index: kernel/include/IMP/particle_refiners/SConscript
===================================================================
--- kernel/include/IMP/particle_refiners/SConscript (revision 626)
+++ kernel/include/IMP/particle_refiners/SConscript (working copy)
@@ -1,9 +1,9 @@
Import('env')
import os.path
-
-files=['BondCoverParticleRefiner.h', 'ChildrenParticleRefiner.h']
-
-# Install the include files
-includedir = os.path.join(env['includedir'], 'IMP', 'particle_refiners')
+files=[
+ 'BondCoverParticleRefiner.h',
+ 'ChildrenParticleRefiner.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'particle_refiners' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/triplet_scores/SConscript
===================================================================
--- kernel/include/IMP/triplet_scores/SConscript (revision 626)
+++ kernel/include/IMP/triplet_scores/SConscript (working copy)
@@ -1,9 +1,8 @@
-import os.path
Import('env')
-
-files = ['AngleTripletScore.h']
-
-# Install the include files:
-includedir = os.path.join(env['includedir'], 'IMP', 'triplet_scores')
+import os.path
+files=[
+ 'AngleTripletScore.h',
+ ]
+includedir = os.path.join(env['includedir'], 'IMP', 'triplet_scores' )
inst = env.Install(includedir, files)
env.Alias('install', inst)
Index: kernel/include/IMP/triplet_scores/AngleTripletScore.h
===================================================================
--- kernel/include/IMP/triplet_scores/AngleTripletScore.h (revision 626)
+++ kernel/include/IMP/triplet_scores/AngleTripletScore.h (working copy)
@@ -26,7 +26,7 @@
AngleTripletScore(UnaryFunction *f);
virtual ~AngleTripletScore(){}
virtual Float evaluate(Particle *a, Particle *b, Particle *c,
- DerivativeAccumulator *da);
+ DerivativeAccumulator *da) const;
virtual void show(std::ostream &out=std::cout) const;
};
Index: kernel/include/IMP/ScoreState.h
===================================================================
--- kernel/include/IMP/ScoreState.h (revision 626)
+++ kernel/include/IMP/ScoreState.h (working copy)
@@ -82,7 +82,7 @@
Model *get_model() const {
IMP_assert(model_,
"Must call set_model before get_model on state");
- return model_.get();
+ return model_;
}
protected:
@@ -120,8 +120,8 @@
unsigned int update_iteration_;
unsigned int after_iteration_;
- // all of the particle data
- Pointer<Model> model_;
+ // not ref counted or destructed
+ Model *model_;
std::string name_;
};
Index: kernel/include/IMP/TripletScore.h
===================================================================
--- kernel/include/IMP/TripletScore.h (revision 626)
+++ kernel/include/IMP/TripletScore.h (working copy)
@@ -33,7 +33,7 @@
virtual ~TripletScore() {}
//! Compute the score for the triplet and the derivative if needed.
virtual Float evaluate(Particle *a, Particle *b, Particle *c,
- DerivativeAccumulator *da) = 0;
+ DerivativeAccumulator *da) const = 0;
virtual void show(std::ostream &out=std::cout) const = 0;
};
Index: kernel/include/IMP/Pointer.h
===================================================================
--- kernel/include/IMP/Pointer.h (revision 626)
+++ kernel/include/IMP/Pointer.h (working copy)
@@ -103,8 +103,8 @@
return !o_;
}
- operator unspecified_bool() const {
- return o_ ? &This::operator! : 0;
+ operator O*() const {
+ return o_;
}
};
Index: kernel/include/IMP/log.h
===================================================================
--- kernel/include/IMP/log.h (revision 626)
+++ kernel/include/IMP/log.h (working copy)
@@ -183,6 +183,20 @@
+//! Print error messages
+/** If this is true, then failures of the IMP_check
+ macro will print their messages to std::cerr. This
+ should be true if the code is used from C++ and false
+ if used from python.
+ */
+IMPDLLEXPORT bool get_print_exception_messages();
+
+
+//! Turn on and off printing of error messages
+IMPDLLEXPORT void set_print_exception_messages(bool tf);
+
+
+
} // namespace IMP
#ifndef IMP_DISABLE_LOGGING
Index: kernel/include/IMP/macros.h
===================================================================
--- kernel/include/IMP/macros.h (revision 626)
+++ kernel/include/IMP/macros.h (working copy)
@@ -226,9 +226,9 @@
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); \
+ DerivativeAccumulator *da=0) const; \
/** Return a list of particles which refines the passed particle.*/ \
- virtual Particles get_refined(Particle *); \
+ virtual Particles get_refined(Particle *) const; \
virtual IMP::VersionInfo get_version_info() const { return version_info; }
//! Use the swap_with member function to swap two objects
Index: kernel/include/SConscript
===================================================================
--- kernel/include/SConscript (revision 626)
+++ kernel/include/SConscript (working copy)
@@ -1,11 +1,9 @@
Import('env')
-
-files = ['IMP.h']
-
-# Install the include files:
+import os.path
+files=[
+ 'IMP.h',
+ ]
includedir = env['includedir']
inst = env.Install(includedir, files)
env.Alias('install', inst)
-
-# Subdirectories
-SConscript('IMP/SConscript')
+SConscript('IMP/SConscript' )
Index: kernel/include/IMP.h
===================================================================
--- kernel/include/IMP.h (revision 626)
+++ kernel/include/IMP.h (working copy)
@@ -1,94 +1,116 @@
/**
- * \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/Object.h"
-#include "IMP/RefCountedObject.h"
-#include "IMP/Pointer.h"
-#include "IMP/UnaryFunction.h"
-#include "IMP/unary_functions/Harmonic.h"
-#include "IMP/unary_functions/HarmonicLowerBound.h"
-#include "IMP/unary_functions/HarmonicUpperBound.h"
-#include "IMP/unary_functions/OpenCubicSpline.h"
-#include "IMP/unary_functions/ClosedCubicSpline.h"
-#include "IMP/unary_functions/Cosine.h"
-#include "IMP/unary_functions/Linear.h"
-#include "IMP/unary_functions/WormLikeChain.h"
-#include "IMP/Model.h"
-#include "IMP/PairScore.h"
-#include "IMP/SingletonScore.h"
-#include "IMP/TripletScore.h"
-#include "IMP/Vector3D.h"
-#include "IMP/VersionInfo.h"
-#include "IMP/ParticleRefiner.h"
-#include "IMP/particle_refiners/BondCoverParticleRefiner.h"
-#include "IMP/particle_refiners/ChildrenParticleRefiner.h"
-#include "IMP/decorators/HierarchyDecorator.h"
-#include "IMP/decorators/MolecularHierarchyDecorator.h"
-#include "IMP/decorators/NameDecorator.h"
-#include "IMP/decorators/AtomDecorator.h"
-#include "IMP/decorators/ResidueDecorator.h"
-#include "IMP/decorators/XYZDecorator.h"
-#include "IMP/decorators/bond_decorators.h"
-#include "IMP/optimizers/SteepestDescent.h"
-#include "IMP/optimizers/ConjugateGradients.h"
-#include "IMP/optimizers/MolecularDynamics.h"
-#include "IMP/optimizers/BrownianDynamics.h"
-#include "IMP/optimizers/MonteCarlo.h"
-#include "IMP/optimizers/Mover.h"
-#include "IMP/optimizers/MoverBase.h"
-#include "IMP/optimizers/movers/BallMover.h"
-#include "IMP/optimizers/movers/NormalMover.h"
-#include "IMP/optimizers/states/VRMLLogOptimizerState.h"
-#include "IMP/optimizers/states/CMMLogOptimizerState.h"
-#include "IMP/optimizers/states/VelocityScalingOptimizerState.h"
-#include "IMP/pair_scores/DistancePairScore.h"
-#include "IMP/pair_scores/SphereDistancePairScore.h"
-#include "IMP/pair_scores/RefineOncePairScore.h"
-#include "IMP/pair_scores/TypedPairScore.h"
-#include "IMP/pair_scores/TransformedDistancePairScore.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/restraints/TunnelRestraint.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 <IMP/base_types.h>
+#include <IMP/DecoratorBase.h>
+#include <IMP/DerivativeAccumulator.h>
+#include <IMP/exception.h>
+#include <IMP/IMP_config.h>
+#include <IMP/Index.h>
+#include <IMP/Key.h>
+#include <IMP/log.h>
+#include <IMP/macros.h>
+#include <IMP/Model.h>
+#include <IMP/Object.h>
+#include <IMP/Optimizer.h>
+#include <IMP/OptimizerState.h>
+#include <IMP/PairScore.h>
+#include <IMP/Particle.h>
+#include <IMP/ParticleRefiner.h>
+#include <IMP/Pointer.h>
+#include <IMP/random.h>
+#include <IMP/RefCountedObject.h>
+#include <IMP/Restraint.h>
+#include <IMP/ScoreState.h>
+#include <IMP/SingletonScore.h>
+#include <IMP/TripletScore.h>
+#include <IMP/UnaryFunction.h>
+#include <IMP/utility.h>
+#include <IMP/Vector3D.h>
+#include <IMP/VersionInfo.h>
+#include <IMP/decorators/AtomDecorator.h>
+#include <IMP/decorators/bond_decorators.h>
+#include <IMP/decorators/HierarchyDecorator.h>
+#include <IMP/decorators/macros.h>
+#include <IMP/decorators/MolecularHierarchyDecorator.h>
+#include <IMP/decorators/NameDecorator.h>
+#include <IMP/decorators/ResidueDecorator.h>
+#include <IMP/decorators/utility.h>
+#include <IMP/decorators/XYZDecorator.h>
+#include <IMP/decorators/XYZRDecorator.h>
+#include <IMP/decorators/yaml.h>
+#include <IMP/internal/ArrayOnAttributesHelper.h>
+#include <IMP/internal/AttributeTable.h>
+#include <IMP/internal/bbox_nbl_helpers.h>
+#include <IMP/internal/constants.h>
+#include <IMP/internal/evaluate_distance_pair_score.h>
+#include <IMP/internal/ExponentialNumber.h>
+#include <IMP/internal/graph_base.h>
+#include <IMP/internal/Grid3D.h>
+#include <IMP/internal/kernel_version_info.h>
+#include <IMP/internal/ObjectContainer.h>
+#include <IMP/internal/ParticleGrid.h>
+#include <IMP/internal/ref_counting.h>
+#include <IMP/internal/Unit.h>
+#include <IMP/internal/units.h>
+#include <IMP/internal/utility.h>
+#include <IMP/internal/Vector.h>
+#include <IMP/optimizers/BrownianDynamics.h>
+#include <IMP/optimizers/ConjugateGradients.h>
+#include <IMP/optimizers/MolecularDynamics.h>
+#include <IMP/optimizers/MonteCarlo.h>
+#include <IMP/optimizers/MoverBase.h>
+#include <IMP/optimizers/Mover.h>
+#include <IMP/optimizers/SteepestDescent.h>
+#include <IMP/pair_scores/DistancePairScore.h>
+#include <IMP/pair_scores/RefineOncePairScore.h>
+#include <IMP/pair_scores/SphereDistancePairScore.h>
+#include <IMP/pair_scores/TransformedDistancePairScore.h>
+#include <IMP/pair_scores/TypedPairScore.h>
+#include <IMP/particle_refiners/BondCoverParticleRefiner.h>
+#include <IMP/particle_refiners/ChildrenParticleRefiner.h>
+#include <IMP/restraints/AngleRestraint.h>
+#include <IMP/restraints/BondDecoratorRestraint.h>
+#include <IMP/restraints/ConnectivityRestraint.h>
+#include <IMP/restraints/ConstantRestraint.h>
+#include <IMP/restraints/DihedralRestraint.h>
+#include <IMP/restraints/DistanceRestraint.h>
+#include <IMP/restraints/NonbondedRestraint.h>
+#include <IMP/restraints/PairChainRestraint.h>
+#include <IMP/restraints/PairListRestraint.h>
+#include <IMP/restraints/PairRestraint.h>
+#include <IMP/restraints/RestraintSet.h>
+#include <IMP/restraints/SingletonListRestraint.h>
+#include <IMP/restraints/TripletChainRestraint.h>
+#include <IMP/score_states/AllNonbondedListScoreState.h>
+#include <IMP/score_states/BipartiteNonbondedListScoreState.h>
+#include <IMP/score_states/BondDecoratorListScoreState.h>
+#include <IMP/score_states/BondedListScoreState.h>
+#include <IMP/score_states/CoverBondsScoreState.h>
+#include <IMP/score_states/GravityCenterScoreState.h>
+#include <IMP/score_states/ManualBondDecoratorListScoreState.h>
+#include <IMP/score_states/MaxChangeScoreState.h>
+#include <IMP/score_states/NonbondedListScoreState.h>
+#include <IMP/singleton_scores/AttributeSingletonScore.h>
+#include <IMP/singleton_scores/DistanceToSingletonScore.h>
+#include <IMP/singleton_scores/TunnelSingletonScore.h>
+#include <IMP/triplet_scores/AngleTripletScore.h>
+#include <IMP/unary_functions/ClosedCubicSpline.h>
+#include <IMP/unary_functions/Cosine.h>
+#include <IMP/unary_functions/Harmonic.h>
+#include <IMP/unary_functions/HarmonicLowerBound.h>
+#include <IMP/unary_functions/HarmonicUpperBound.h>
+#include <IMP/unary_functions/Linear.h>
+#include <IMP/unary_functions/OpenCubicSpline.h>
+#include <IMP/unary_functions/WormLikeChain.h>
+#include <IMP/optimizers/movers/BallMover.h>
+#include <IMP/optimizers/movers/NormalMover.h>
+#include <IMP/optimizers/states/CMMLogOptimizerState.h>
+#include <IMP/optimizers/states/VelocityScalingOptimizerState.h>
+#include <IMP/optimizers/states/VRMLLogOptimizerState.h>
#endif /* __IMP_H */
Index: kernel/doc/examples/chain.py
===================================================================
--- kernel/doc/examples/chain.py (revision 626)
+++ kernel/doc/examples/chain.py (working copy)
@@ -9,18 +9,17 @@
#IMP.set_log_level(IMP.VERBOSE)
np=20
radius =1.0
-rk= IMP.FloatKey("radius")
m= IMP.Model()
# The particles in the chain
chain= IMP.Particles()
for i in range(0,np):
p= IMP.Particle()
pi= m.add_particle(p)
- d= IMP.XYZDecorator.create(p)
+ d= IMP.XYZRDecorator.create(p)
d.randomize_in_box(IMP.Vector3D(0,0,0),
IMP.Vector3D(10,10,10))
d.set_coordinates_are_optimized(True)
- p.add_attribute(rk, radius, False)
+ d.set_radius(radius)
chain.append(p)
# create a bond between successive particles
@@ -36,15 +35,14 @@
p.show()
# Set up the nonbonded list
-nbl= IMP.AllNonbondedListScoreState(1, rk, chain)
+nbl= IMP.AllNonbondedListScoreState(1, chain)
nbli= m.add_score_state(nbl)
# This ScoreState uses the bonds constructed above to restrain
bl= IMP.BondDecoratorListScoreState(chain)
bli= nbl.add_bonded_list(bl)
# Set up excluded volume
-ps= IMP.SphereDistancePairScore(IMP.HarmonicLowerBound(0,1),
- rk)
+ps= IMP.SphereDistancePairScore(IMP.HarmonicLowerBound(0,1))
evr= IMP.NonbondedRestraint(ps, nbl)
evri= m.add_restraint(evr)
@@ -63,7 +61,7 @@
p= IMP.ParticlePair(chain[0], chain[-1])
pps= IMP.ParticlePairs()
pps.append(p)
-cr= IMP.PairListRestraint(IMP.SphereDistancePairScore(IMP.Harmonic(3,1), rk),
+cr= IMP.PairListRestraint(IMP.SphereDistancePairScore(IMP.Harmonic(3,1)),
pps)
cri=m.add_restraint(cr)
@@ -74,7 +72,6 @@
# Write the progression of states as the system is optimized to
# the files state.000.vrml, state.001.vrml etc.
vrml= IMP.VRMLLogOptimizerState("state.%03d.vrml", chain)
-vrml.set_radius_key(rk)
vrml.update()
vrml.set_skip_steps(100)
o.add_optimizer_state(vrml)
Index: kernel/src/exception.cpp
===================================================================
--- kernel/src/exception.cpp (revision 626)
+++ kernel/src/exception.cpp (working copy)
@@ -10,6 +10,12 @@
namespace IMP
{
+namespace internal {
+ // The error message is already in the exception
+ bool print_exceptions=true;
+}
+
+
static CheckLevel check_mode =
#ifdef NDEBUG
CHEAP;
@@ -30,12 +36,9 @@
namespace internal
{
-// The error message is already in the exception
-bool print_exceptions=false;
-
void assert_fail(const char *msg)
{
- if (print_exceptions) {
+ if (internal::print_exceptions) {
IMP_ERROR(msg);
}
throw ErrorException(msg);
@@ -43,11 +46,14 @@
void check_fail(const char *msg)
{
- if (print_exceptions) {
+ if (internal::print_exceptions) {
IMP_ERROR(msg);
}
}
} // namespace internal
+
+
+
} // namespace IMP
Index: kernel/src/singleton_scores/TunnelSingletonScore.cpp
===================================================================
--- kernel/src/singleton_scores/TunnelSingletonScore.cpp (revision 0)
+++ kernel/src/singleton_scores/TunnelSingletonScore.cpp (revision 0)
@@ -0,0 +1,103 @@
+/**
+ * \file TunnelSingletonScore.cpp \brief Tunnel restraint.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#include "IMP/singleton_scores/TunnelSingletonScore.h"
+#include "IMP/decorators/XYZRDecorator.h"
+
+namespace IMP
+{
+
+TunnelSingletonScore::TunnelSingletonScore(UnaryFunction *f) : f_(f)
+{
+ coordinate_=0;
+ center_=Vector3D(0,0,0);
+ height_=0;
+ radius_=0;
+}
+
+
+
+Float TunnelSingletonScore::evaluate(Particle *p,
+ DerivativeAccumulator *accum) const
+{
+ Float ret=0;
+ XYZDecorator d(p);
+ Float radius=0;
+ if ( p->has_attribute(XYZRDecorator::get_radius_key())) {
+ radius= p->get_value(XYZRDecorator::get_radius_key());
+ }
+ IMP_LOG(VERBOSE, "Tunnel restraint on particle " << d << std::endl);
+ Float hr= height_+radius;
+ if (d.get_coordinate(coordinate_) < center_[coordinate_] + hr
+ && d.get_coordinate(coordinate_) > center_[coordinate_] - hr) {
+ Float sd=0;
+ for (int i=1; i< 3; ++i) {
+ int oc= (i+coordinate_)%3;
+ sd+= square(d.get_coordinate(oc)- center_[oc]);
+ }
+ sd= std::sqrt(sd);
+ IMP_LOG(VERBOSE, "The distance is " << sd << " and radius "
+ << radius_ << std::endl);
+ if (sd > radius_-radius) {
+ Float rd= sd-radius_;
+ Float hdu= center_[coordinate_] + height_
+ - d.get_coordinate(coordinate_);
+ Float hdd= d.get_coordinate(coordinate_)
+ + height_- center_[coordinate_];
+ Vector3D deriv(0,0,0);
+ Float score=0;
+ Float deriv_scalar=0;
+ /*! \todo Clean up these tests so I am not dependent on two expressions
+ being the same and evaluating to the same thing */
+ // look below if changed
+ Float dist= -std::min(std::min(rd, hdu), hdd) - radius;
+ if (accum) {
+ score= f_->evaluate_deriv(dist, deriv_scalar);
+ } else {
+ score= f_->evaluate(dist);
+ }
+
+ // kind if evil
+ if (dist== -rd -radius) {
+ Vector3D v= (d.get_vector() - center_).get_unit_vector();
+ for (int i=0; i< 2; ++i) {
+ int oc= (i+coordinate_+1)%3;
+ deriv[oc]= v[oc]*deriv_scalar;
+ }
+ } else {
+ // kind of evil
+ if (dist == -hdu -radius) {
+ deriv_scalar= -deriv_scalar;
+ }
+ deriv[coordinate_]= deriv_scalar;
+ }
+
+ if (accum) {
+ for (unsigned int i=0; i< 3; ++i) {
+ d.add_to_coordinate_derivative(i, deriv[i], *accum);
+ }
+ }
+ ret+= score;
+ } else {
+ IMP_LOG(VERBOSE, "Particle " << p->get_index()
+ << " is in channel" << std::endl);
+ }
+ } else {
+ IMP_LOG(VERBOSE, "Particle " << p->get_index()
+ << " is outside of slab" << std::endl);
+ }
+ return ret;
+}
+
+void TunnelSingletonScore::show(std::ostream& out) const
+{
+ out << "Tunnel score :" << *f_
+ << " " << center_ << " " << height_ << " "
+ << coordinate_ << std::endl;
+}
+
+} // namespace IMP
Index: kernel/src/singleton_scores/SConscript
===================================================================
--- kernel/src/singleton_scores/SConscript (revision 626)
+++ kernel/src/singleton_scores/SConscript (working copy)
@@ -1,6 +1,7 @@
Import('env')
-
-files = ['DistanceToSingletonScore.cpp', 'AttributeSingletonScore.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'AttributeSingletonScore.cpp' ),
+ File( 'DistanceToSingletonScore.cpp' ),
+ File( 'TunnelSingletonScore.cpp' ),
+ ]
Return('files')
Index: kernel/src/singleton_scores/DistanceToSingletonScore.cpp
===================================================================
--- kernel/src/singleton_scores/DistanceToSingletonScore.cpp (revision 626)
+++ kernel/src/singleton_scores/DistanceToSingletonScore.cpp (working copy)
@@ -27,7 +27,7 @@
pt_(v){}
Float DistanceToSingletonScore::evaluate(Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
return internal::evaluate_distance_pair_score(XYZDecorator(b),
StaticD(pt_), da,
Index: kernel/src/Particle.cpp
===================================================================
--- kernel/src/Particle.cpp (revision 626)
+++ kernel/src/Particle.cpp (working copy)
@@ -15,6 +15,7 @@
Particle::Particle()
{
+ model_=NULL;
is_active_ = true;
}
@@ -43,9 +44,7 @@
void Particle::zero_derivatives()
{
- for (FloatKeyIterator it= float_keys_begin(); it != float_keys_end(); ++it) {
- derivatives_.set_value(*it, 0);
- }
+ derivatives_.set_values(0);
}
Index: kernel/src/unary_functions/Cosine.cpp
===================================================================
--- kernel/src/unary_functions/Cosine.cpp (revision 626)
+++ kernel/src/unary_functions/Cosine.cpp (working copy)
@@ -12,13 +12,13 @@
namespace IMP
{
-Float Cosine::evaluate(Float feature)
+Float Cosine::evaluate(Float feature) const
{
return std::abs(force_constant_)
- force_constant_ * std::cos(periodicity_ * feature + phase_);
}
-Float Cosine::evaluate_deriv(Float feature, Float& deriv)
+Float Cosine::evaluate_deriv(Float feature, Float& deriv) const
{
deriv = force_constant_ * periodicity_
* std::sin(periodicity_ * feature + phase_);
Index: kernel/src/unary_functions/OpenCubicSpline.cpp
===================================================================
--- kernel/src/unary_functions/OpenCubicSpline.cpp (revision 626)
+++ kernel/src/unary_functions/OpenCubicSpline.cpp (working copy)
@@ -43,7 +43,7 @@
}
-Float OpenCubicSpline::evaluate(Float feature)
+Float OpenCubicSpline::evaluate(Float feature) const
{
// check for feature in range
if (feature < minrange_ || feature > maxrange_) {
@@ -66,7 +66,7 @@
* (spacing_ * spacing_) / 6.;
}
-Float OpenCubicSpline::evaluate_deriv(Float feature, Float& deriv)
+Float OpenCubicSpline::evaluate_deriv(Float feature, Float& deriv) const
{
size_t lowbin = static_cast<size_t>((feature - minrange_) / spacing_);
// handle the case where feature ~= maxrange
Index: kernel/src/unary_functions/SConscript
===================================================================
--- kernel/src/unary_functions/SConscript (revision 626)
+++ kernel/src/unary_functions/SConscript (working copy)
@@ -1,6 +1,7 @@
Import('env')
-
-files = ['OpenCubicSpline.cpp', 'ClosedCubicSpline.cpp', 'Cosine.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'ClosedCubicSpline.cpp' ),
+ File( 'Cosine.cpp' ),
+ File( 'OpenCubicSpline.cpp' ),
+ ]
Return('files')
Index: kernel/src/unary_functions/ClosedCubicSpline.cpp
===================================================================
--- kernel/src/unary_functions/ClosedCubicSpline.cpp (revision 626)
+++ kernel/src/unary_functions/ClosedCubicSpline.cpp (working copy)
@@ -55,7 +55,7 @@
}
-Float ClosedCubicSpline::evaluate(Float feature)
+Float ClosedCubicSpline::evaluate(Float feature) const
{
// check for feature in range
if (feature < minrange_ || feature > maxrange_) {
@@ -82,7 +82,7 @@
* (spacing_ * spacing_) / 6.;
}
-Float ClosedCubicSpline::evaluate_deriv(Float feature, Float& deriv)
+Float ClosedCubicSpline::evaluate_deriv(Float feature, Float& deriv) const
{
size_t lowbin = static_cast<size_t>((feature - minrange_) / spacing_);
size_t highbin = lowbin + 1;
Index: kernel/src/Restraint.cpp
===================================================================
--- kernel/src/Restraint.cpp (revision 626)
+++ kernel/src/Restraint.cpp (working copy)
@@ -17,6 +17,7 @@
Restraint::Restraint()
{
+ model_=NULL;
is_active_ = true; // active by default
}
@@ -24,6 +25,12 @@
//! Destructor
Restraint::~Restraint()
{
+ if (!was_owned_) {
+ // can't use virtual functions in the destructor
+ std::cerr << "Restraint " << this << " is being destroyed "
+ << "without ever having been added to a model."
+ << std::endl;
+ }
}
@@ -43,9 +50,10 @@
{
IMP_assert(model==NULL || get_number_of_particles()==0
|| model == get_particle(0)->get_model()
- || (model_ && model_.get() == model),
+ || (model_ && model_ == model),
"Model* different from Particle Model*");
model_=model;
+ was_owned_=true;
}
void Restraint::show(std::ostream& out) const
Index: kernel/src/ScoreState.cpp
===================================================================
--- kernel/src/ScoreState.cpp (revision 626)
+++ kernel/src/ScoreState.cpp (working copy)
@@ -17,6 +17,7 @@
//! Constructor
ScoreState::ScoreState(std::string name) : name_(name)
{
+ model_=NULL;
update_iteration_= std::numeric_limits<unsigned int>::max();
after_iteration_= std::numeric_limits<unsigned int>::max();
IMP_LOG(VERBOSE, "ScoreState constructed " << name << std::endl);
Index: kernel/src/score_states/BondDecoratorListScoreState.cpp
===================================================================
--- kernel/src/score_states/BondDecoratorListScoreState.cpp (revision 626)
+++ kernel/src/score_states/BondDecoratorListScoreState.cpp (working copy)
@@ -21,7 +21,7 @@
{
IMP_LOG(TERSE, "Updating BondDecoratorList for "
<< ps_.size() << " particles" << std::endl);
- bonds_.clear();
+ std::vector<BondDecorator> bonds;
for (unsigned int i=0; i< ps_.size(); ++i) {
if (!ps_[i]->get_is_active()) continue;
BondedDecorator di(ps_[i]);
@@ -36,31 +36,26 @@
}
if (di < dj) {
IMP_LOG(VERBOSE, "Found bond " << di.get_bond(j) << std::endl);
- bonds_.push_back(di.get_bond(j));
+ bonds.push_back(di.get_bond(j));
}
}
}
- IMP_LOG(TERSE, "Found " << bonds_.size() << " bonds"<< std::endl);
+ ManualBondDecoratorListScoreState::set_bond_decorators(bonds);
+ IMP_LOG(TERSE, "Found " << bonds.size() << " bonds"<< std::endl);
}
void BondDecoratorListScoreState::set_particles(const Particles &ps)
{
ps_=ps;
std::sort(ps_.begin(), ps_.end());
- bonds_.clear();
+ clear_bond_decorators();
}
-
-bool BondDecoratorListScoreState::are_bonded(Particle *a, Particle *b) const
+void BondDecoratorListScoreState::add_particles(const Particles &ps)
{
- try {
- BondedDecorator da= BondedDecorator::cast(a);
- BondedDecorator db= BondedDecorator::cast(b);
- return get_bond(da, db) != BondDecorator();
- } catch (...) {
- IMP_LOG(VERBOSE, "Exception thrown in are_bonded"<< std::endl);
- }
- return false;
+ ps_.insert(ps_.end(), ps.begin(), ps.end());
+ std::sort(ps_.begin(), ps_.end());
+ clear_bond_decorators();
}
} // namespace IMP
Index: kernel/src/score_states/NonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/NonbondedListScoreState.cpp (revision 626)
+++ kernel/src/score_states/NonbondedListScoreState.cpp (working copy)
@@ -6,7 +6,7 @@
*/
#include "IMP/score_states/NonbondedListScoreState.h"
-#include "IMP/decorators/XYZDecorator.h"
+#include "IMP/decorators/XYZRDecorator.h"
#include "IMP/internal/Grid3D.h"
#include "IMP/score_states/MaxChangeScoreState.h"
@@ -32,16 +32,15 @@
NonbondedListScoreState
-::NonbondedListScoreState(Float cut,
- FloatKey rk): rk_(rk),
- cutoff_(cut),
- nbl_is_valid_(false)
+::NonbondedListScoreState(Float cut): cutoff_(cut),
+ nbl_is_valid_(false)
{
slack_=cutoff_;
number_of_updates_=1;
number_of_rebuilds_=0;
number_of_overflows_=0;
max_nbl_size_= std::numeric_limits<unsigned int>::max();
+ set_radius_key(XYZRDecorator::get_radius_key());
}
@@ -51,6 +50,48 @@
{
}
+void NonbondedListScoreState::set_radius_key(FloatKey rk) {
+ rk_=rk;
+ Particles old_particles;
+ if (mcr_) {
+ old_particles= mcr_->get_particles();
+ }
+ if (rk != FloatKey()) {
+ FloatKeys ks;
+ ks.push_back(rk);
+ mcr_= new MaxChangeScoreState(ks);
+ } else {
+ mcr_= new MaxChangeScoreState(FloatKeys());
+ }
+ mcr_->add_particles(old_particles);
+}
+
+
+Float NonbondedListScoreState::get_max_radius_change() const {
+ if (rk_ != FloatKey()) {
+ return mcr_->get_max();
+ } else {
+ return 0;
+ }
+}
+
+void NonbondedListScoreState::reset_max_radius_change() {
+ if (mcr_) mcr_->reset();
+}
+
+void NonbondedListScoreState::update_max_radius_change(unsigned int i) {
+ if (mcr_) mcr_->before_evaluate(i);
+}
+
+void NonbondedListScoreState
+::add_particles_for_max_radius_change(const Particles &ps) {
+ mcr_->add_particles(particles_with_radius(ps));
+}
+
+void NonbondedListScoreState::clear_particles_for_max_radius_change() {
+ mcr_->clear_particles();
+}
+
void NonbondedListScoreState::show_statistics(std::ostream &out) const
{
out << "Nonbonded list averaged "
Index: kernel/src/score_states/CoverBondsScoreState.cpp
===================================================================
--- kernel/src/score_states/CoverBondsScoreState.cpp (revision 626)
+++ kernel/src/score_states/CoverBondsScoreState.cpp (working copy)
@@ -14,8 +14,9 @@
{
-CoverBondsScoreState::CoverBondsScoreState(BondDecoratorListScoreState *bl,
- FloatKey rk): bl_(bl), rk_(rk)
+CoverBondsScoreState
+::CoverBondsScoreState(ManualBondDecoratorListScoreState *bl,
+ FloatKey rk): bl_(bl), rk_(rk)
{
}
@@ -25,8 +26,9 @@
void CoverBondsScoreState::do_before_evaluate()
{
- for (BondDecoratorListScoreState::BondIterator it= bl_->bonds_begin();
- it != bl_->bonds_end(); ++it) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator it
+ = bl_->bond_decorators_begin();
+ it != bl_->bond_decorators_end(); ++it) {
BondDecorator bd= *it;
BondedDecorator pa= bd.get_bonded(0);
BondedDecorator pb= bd.get_bonded(1);
@@ -62,8 +64,9 @@
void CoverBondsScoreState::after_evaluate(DerivativeAccumulator *dva)
{
if (dva) {
- for (BondDecoratorListScoreState::BondIterator it= bl_->bonds_begin();
- it != bl_->bonds_end(); ++it) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator it
+ = bl_->bond_decorators_begin();
+ it != bl_->bond_decorators_end(); ++it) {
XYZDecorator d(it->get_particle());
Vector3D deriv;
// divide derivatives equally between endpoints
@@ -84,7 +87,7 @@
void CoverBondsScoreState::show(std::ostream &out) const
{
- out << "CoverBondsScoreState on " << bl_->get_number_of_bonds()
+ out << "CoverBondsScoreState on " << bl_->get_number_of_bond_decorators()
<< " bonds " << std::endl;
}
Index: kernel/src/score_states/BipartiteNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (revision 626)
+++ kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (working copy)
@@ -15,8 +15,10 @@
namespace IMP
{
-//! Turn the default into an actual algorithm and work around missing algorithms
-/** This cannot be shared with AllNBL because that one has grid and this does
+
+
+// Turn the default into an actual algorithm and work around missing algorithms
+/* This cannot be shared with AllNBL because that one has grid and this does
not.
*/
static BipartiteNonbondedListScoreState::Algorithm
@@ -45,30 +47,21 @@
BipartiteNonbondedListScoreState
-::BipartiteNonbondedListScoreState(Float cut,
- FloatKey rk,
- Algorithm a):
- P(cut, rk), a_(translate_algorithm(a))
+::BipartiteNonbondedListScoreState(Float cut):
+ P(cut), a_(translate_algorithm(DEFAULT))
{
- FloatKeys ks;
- ks.push_back(rk);
mc0_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
mc1_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
- mcr_= new MaxChangeScoreState(ks);
}
BipartiteNonbondedListScoreState
-::BipartiteNonbondedListScoreState(Float cut, FloatKey rk,
+::BipartiteNonbondedListScoreState(Float cut,
const Particles &ps0,
- const Particles &ps1,
- Algorithm a):
- P(cut, rk), a_(translate_algorithm(a))
+ const Particles &ps1):
+ P(cut), a_(translate_algorithm(DEFAULT))
{
- FloatKeys ks;
- ks.push_back(rk);
mc0_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
mc1_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
- mcr_= new MaxChangeScoreState(ks);
set_particles(ps0, ps1);
}
@@ -79,7 +72,7 @@
{
mc0_->before_evaluate(ScoreState::get_before_evaluate_iteration());
mc0_->before_evaluate(ScoreState::get_before_evaluate_iteration());
- mcr_->before_evaluate(ScoreState::get_before_evaluate_iteration());
+ update_max_radius_change(ScoreState::get_before_evaluate_iteration());
Float mc= std::max(mc0_->get_max(), mc1_->get_max());
Float cost;
@@ -88,17 +81,19 @@
cost= 10*mc0_->get_number_of_particles()* mc1_->get_number_of_particles();
break;
case BBOX:
- cost= 1000 * mcr_->get_number_of_particles();
+ cost= 1000 * (mc0_->get_number_of_particles()
+ + mc1_->get_number_of_particles());
break;
default:
IMP_assert(0, "Bad algorithm");
- cost= 1000 * mcr_->get_number_of_particles();
+ cost= 1000 * (mc0_->get_number_of_particles()
+ + mc1_->get_number_of_particles());
}
- if (P::update(mc+ mcr_->get_max(), cost)) {
+ if (P::update(mc+ get_max_radius_change(), cost)) {
mc0_->reset();
mc1_->reset();
- mcr_->reset();
+ reset_max_radius_change();
}
IMP_IF_CHECK(EXPENSIVE) {
check_nbl();
@@ -123,7 +118,7 @@
break;
default:
IMP_failure("Can't find algorithm in BipartiteNonbondedListScoreState",
- ErrorException());
+ ErrorException);
}
}
@@ -150,9 +145,9 @@
mc0_->add_particles(ps0);
mc1_->clear_particles();
mc1_->add_particles(ps1);
- mcr_->clear_particles();
- mcr_->add_particles(P::particles_with_radius(ps0));
- mcr_->add_particles(P::particles_with_radius(ps1));
+ clear_particles_for_max_radius_change();
+ add_particles_for_max_radius_change(ps0);
+ add_particles_for_max_radius_change(ps1);
P::set_nbl_is_valid(false);
}
@@ -160,24 +155,36 @@
void BipartiteNonbondedListScoreState::add_particles_0(const Particles &ps)
{
if (P::get_nbl_is_valid()) process_sets(ps, mc1_->get_particles());
+ else P::set_nbl_is_valid(false);
mc0_->add_particles(ps);
- mcr_->add_particles(P::particles_with_radius(ps));
- P::set_nbl_is_valid(false);
+ add_particles_for_max_radius_change(ps);
}
void BipartiteNonbondedListScoreState::add_particles_1(const Particles &ps)
{
if (P::get_nbl_is_valid()) process_sets(ps, mc0_->get_particles());
+ else P::set_nbl_is_valid(false);
mc1_->add_particles(ps);
- mcr_->add_particles(P::particles_with_radius(ps));
- P::set_nbl_is_valid(false);
+ add_particles_for_max_radius_change(ps);
}
+
+void BipartiteNonbondedListScoreState::add_particle_0(Particle *ps)
+{
+ add_particles_0(Particles(1, ps));
+}
+
+void BipartiteNonbondedListScoreState::add_particle_1(Particle *ps)
+{
+ add_particles_1(Particles(1, ps));
+}
+
+
void BipartiteNonbondedListScoreState::clear_particles()
{
mc0_->clear_particles();
mc1_->clear_particles();
- mcr_->clear_particles();
+ clear_particles_for_max_radius_change();
P::set_nbl_is_valid(false);
P::set_nbl_is_valid(true);
}
Index: kernel/src/score_states/SConscript
===================================================================
--- kernel/src/score_states/SConscript (revision 626)
+++ kernel/src/score_states/SConscript (working copy)
@@ -1,10 +1,12 @@
Import('env')
-
-files = ['NonbondedListScoreState.cpp',
- 'MaxChangeScoreState.cpp', 'BondDecoratorListScoreState.cpp',
- 'AllNonbondedListScoreState.cpp',
- 'BipartiteNonbondedListScoreState.cpp',
- 'GravityCenterScoreState.cpp', 'CoverBondsScoreState.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'AllNonbondedListScoreState.cpp' ),
+ File( 'BipartiteNonbondedListScoreState.cpp' ),
+ File( 'BondDecoratorListScoreState.cpp' ),
+ File( 'CoverBondsScoreState.cpp' ),
+ File( 'GravityCenterScoreState.cpp' ),
+ File( 'ManualBondDecoratorListScoreState.cpp' ),
+ File( 'MaxChangeScoreState.cpp' ),
+ File( 'NonbondedListScoreState.cpp' ),
+ ]
Return('files')
Index: kernel/src/score_states/AllNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/AllNonbondedListScoreState.cpp (revision 626)
+++ kernel/src/score_states/AllNonbondedListScoreState.cpp (working copy)
@@ -18,7 +18,7 @@
{
-//! Turn the default into an actual algorithm and work around missing algorithms
+// Turn the default into an actual algorithm and work around missing algorithms
static AllNonbondedListScoreState::Algorithm
translate_algorithm(AllNonbondedListScoreState::Algorithm a)
{
@@ -44,29 +44,13 @@
AllNonbondedListScoreState::AllNonbondedListScoreState(Float cut,
- FloatKey rk,
- const Particles &ps,
- Algorithm a):
- P(cut, rk), a_(translate_algorithm(a))
+ const Particles &ps):
+ P(cut), a_(translate_algorithm(DEFAULT))
{
- FloatKeys ks;
- ks.push_back(rk);
mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
- mcr_= new MaxChangeScoreState(ks);
add_particles(ps);
}
-AllNonbondedListScoreState::AllNonbondedListScoreState(Float cut,
- FloatKey rk,
- Algorithm a):
- P(cut, rk), a_(translate_algorithm(a))
-{
- FloatKeys ks;
- ks.push_back(rk);
- mc_= new MaxChangeScoreState(XYZDecorator::get_xyz_keys());
- mcr_= new MaxChangeScoreState(ks);
-}
-
AllNonbondedListScoreState::~AllNonbondedListScoreState()
{
}
@@ -74,8 +58,8 @@
void AllNonbondedListScoreState::do_before_evaluate()
{
mc_->before_evaluate(ScoreState::get_before_evaluate_iteration());
- mcr_->before_evaluate(ScoreState::get_before_evaluate_iteration());
- Float mc=mc_->get_max()+ mcr_->get_max();
+ update_max_radius_change(ScoreState::get_before_evaluate_iteration());
+ Float mc=mc_->get_max()+ get_max_radius_change();
Float cost;
switch (a_){
case QUADRATIC:
@@ -89,12 +73,12 @@
cost = 2000 * mc_->get_number_of_particles();
break;
default:
- IMP_failure("Bad algorithm", ErrorException());
+ IMP_failure("Bad algorithm", ErrorException);
cost = 10 * mc_->get_number_of_particles();
}
if (P::update(mc, cost)) {
mc_->reset();
- mcr_->reset();
+ reset_max_radius_change();
}
IMP_IF_CHECK(EXPENSIVE) {
check_nbl();
@@ -121,7 +105,7 @@
internal::NBLAddPairIfNonbonded(this));
} else {
- IMP_failure("Bad algorithm in AllNBL::rebuild", ErrorException());
+ IMP_failure("Bad algorithm in AllNBL::rebuild", ErrorException);
}
set_nbl_is_valid(true);
IMP_LOG(TERSE, "NBL has " << P::get_number_of_nonbonded()
@@ -132,8 +116,8 @@
{
mc_->clear_particles();
mc_->add_particles(ps);
- mcr_->clear_particles();
- mcr_->add_particles(particles_with_radius(ps));
+ clear_particles_for_max_radius_change();
+ add_particles_for_max_radius_change(ps);
P::set_nbl_is_valid(false);
}
@@ -155,14 +139,14 @@
internal::NBLAddPairIfNonbonded(this));
}
}
- mcr_->add_particles(particles_with_radius(ps));
+ add_particles_for_max_radius_change(ps);
mc_->add_particles(ps);
}
void AllNonbondedListScoreState::clear_particles()
{
mc_->clear_particles();
- mcr_->clear_particles();
+ clear_particles_for_max_radius_change();
P::set_nbl_is_valid(false);
P::set_nbl_is_valid(true);
}
Index: kernel/src/score_states/MaxChangeScoreState.cpp
===================================================================
--- kernel/src/score_states/MaxChangeScoreState.cpp (revision 626)
+++ kernel/src/score_states/MaxChangeScoreState.cpp (working copy)
@@ -19,12 +19,6 @@
const Particles &ps): keys_(keys)
{
add_particles(ps);
- origkeys_.resize(keys_.size());
- std::ostringstream oss;
- oss << " MCSS base " << this;
- for (unsigned int i=0; i< keys_.size(); ++i) {
- origkeys_[i]= FloatKey((keys_[i].get_string()+oss.str()).c_str());
- }
}
@@ -35,12 +29,6 @@
<< obj,
ValueException);
};
- for (unsigned int i=0; i< origkeys_.size(); ++i) {
- if (!obj->has_attribute(origkeys_[i])) {
- obj->add_attribute(origkeys_[i],
- obj->get_value(keys_[i]), false);
- }
- }
}, {reset();});
void MaxChangeScoreState::do_before_evaluate()
@@ -48,12 +36,12 @@
max_change_=0;
// get rid of inactive particles and their stored values
internal::remove_inactive_particles(particle_vector_);
- for (ParticleIterator it= particles_begin(); it != particles_end(); ++it) {
- (*it)->assert_is_valid();
+ for (unsigned int i=0; i< get_number_of_particles(); ++i) {
+ get_particle(i)->assert_is_valid();
for (unsigned int j=0; j < keys_.size(); ++j) {
- Float v= (*it)->get_value(keys_[j]);
- Float ov= (*it)->get_value(origkeys_[j]);
- IMP_LOG(VERBOSE, "Particle " << (*it)->get_index()
+ Float v= get_particle(i)->get_value(keys_[j]);
+ Float ov= old_values_[i].get_value(keys_[j]);
+ IMP_LOG(VERBOSE, "Particle " << get_particle(i)->get_index()
<< " and attribute " << keys_[j]
<< " moved " << std::abs(v - ov) << std::endl);
max_change_= std::max(max_change_,
@@ -66,9 +54,15 @@
void MaxChangeScoreState::reset()
{
- for (ParticleIterator it= particles_begin(); it != particles_end(); ++it) {
+ Table t;
+ for (unsigned int i=0; i < keys_.size(); ++i) {
+ t.insert(keys_[i], 0);
+ }
+ old_values_.resize(get_number_of_particles(), t);
+ for (unsigned int i=0; i< get_number_of_particles(); ++i) {
for (unsigned int j=0; j < keys_.size(); ++j) {
- (*it)->set_value(origkeys_[j], (*it)->get_value(keys_[j]));
+ old_values_[i].set_value(keys_[j],
+ get_particle(i)->get_value(keys_[j]));
}
}
max_change_=0;
Index: kernel/src/score_states/ManualBondDecoratorListScoreState.cpp
===================================================================
--- kernel/src/score_states/ManualBondDecoratorListScoreState.cpp (revision 0)
+++ kernel/src/score_states/ManualBondDecoratorListScoreState.cpp (revision 0)
@@ -0,0 +1,41 @@
+#include "IMP/score_states/ManualBondDecoratorListScoreState.h"
+
+namespace IMP
+{
+ ManualBondDecoratorListScoreState
+ ::ManualBondDecoratorListScoreState(const BondDecorators &ps) {
+ set_bond_decorators(ps);
+ }
+
+ IMP_LIST_IMPL(ManualBondDecoratorListScoreState, BondDecorator,
+ bond_decorator, BondDecorator,
+ ,);
+
+ bool ManualBondDecoratorListScoreState::are_bonded(Particle *a,
+ Particle *b) const
+ {
+ if (BondedDecorator::is_instance_of(a)
+ && BondedDecorator::is_instance_of(b)) {
+ BondedDecorator da(a);
+ BondedDecorator db(b);
+ return get_bond(da, db) != BondDecorator();
+ } else if (BondDecorator::is_instance_of(a)
+ && BondDecorator::is_instance_of(b)){
+ // check if they are bonds which share an endpoint
+ /**
+ \todo Decide if the check for adject bonds should go elsewhere
+ */
+ BondDecorator da(a);
+ BondDecorator db(b);
+ Particle *a0= da.get_bonded(0).get_particle();
+ Particle *a1= da.get_bonded(1).get_particle();
+ Particle *b0= db.get_bonded(0).get_particle();
+ Particle *b1= db.get_bonded(1).get_particle();
+
+ return (a0== b0 || a0 == b1 || a1== b0 || a1 == b1);
+ } else {
+ return false;
+ }
+ }
+
+}
Index: kernel/src/restraints/TunnelRestraint.cpp
===================================================================
--- kernel/src/restraints/TunnelRestraint.cpp (revision 626)
+++ kernel/src/restraints/TunnelRestraint.cpp (working copy)
@@ -1,103 +0,0 @@
-/**
- * \file TunnelRestraint.cpp \brief Tunnel restraint.
- *
- * Copyright 2007-8 Sali Lab. All rights reserved.
- *
- */
-
-#include "IMP/restraints/TunnelRestraint.h"
-#include "IMP/decorators/XYZDecorator.h"
-
-namespace IMP
-{
-
-TunnelRestraint::TunnelRestraint(UnaryFunction *f, FloatKey r) : f_(f), rk_(r)
-{
- coordinate_=0;
- center_=Vector3D(0,0,0);
- height_=0;
- radius_=0;
-}
-
-
-
-Float TunnelRestraint::evaluate(DerivativeAccumulator *accum)
-{
- Float ret=0;
- for (Restraint::ParticleIterator it= Restraint::particles_begin();
- it != Restraint::particles_end(); ++it) {
- XYZDecorator d(*it);
- Float radius=0;
- if (rk_ != FloatKey() && (*it)->has_attribute(rk_)) {
- radius= (*it)->get_value(rk_);
- }
- IMP_LOG(VERBOSE, "Tunnel restraint on particle " << d << std::endl);
- Float hr= height_+radius;
- if (d.get_coordinate(coordinate_) < center_[coordinate_] + hr
- && d.get_coordinate(coordinate_) > center_[coordinate_] - hr) {
- Float sd=0;
- for (int i=1; i< 3; ++i) {
- int oc= (i+coordinate_)%3;
- sd+= square(d.get_coordinate(oc)- center_[oc]);
- }
- sd= std::sqrt(sd);
- IMP_LOG(VERBOSE, "The distance is " << sd << " and radius "
- << radius_ << std::endl);
- if (sd > radius_-radius) {
- Float rd= sd-radius_;
- Float hdu= center_[coordinate_] + height_
- - d.get_coordinate(coordinate_);
- Float hdd= d.get_coordinate(coordinate_)
- + height_- center_[coordinate_];
- Vector3D deriv(0,0,0);
- Float score=0;
- Float deriv_scalar=0;
- /*! \todo Clean up these tests so I am not dependent on two expressions
- being the same and evaluating to the same thing */
- // look below if changed
- Float dist= -std::min(std::min(rd, hdu), hdd) - radius;
- if (accum) {
- score= f_->evaluate_deriv(dist, deriv_scalar);
- } else {
- score= f_->evaluate(dist);
- }
-
- // kind if evil
- if (dist== -rd -radius) {
- Vector3D v= (d.get_vector() - center_).get_unit_vector();
- for (int i=0; i< 2; ++i) {
- int oc= (i+coordinate_+1)%3;
- deriv[oc]= v[oc]*deriv_scalar;
- }
- } else {
- // kind of evil
- if (dist == -hdu -radius) deriv_scalar= -deriv_scalar;
- deriv[coordinate_]= deriv_scalar;
- }
-
- if (accum) {
- for (unsigned int i=0; i< 3; ++i) {
- d.add_to_coordinate_derivative(i, deriv[i], *accum);
- }
- }
- ret+= score;
- } else {
- IMP_LOG(VERBOSE, "Particle " << (*it)->get_index()
- << " is in channel" << std::endl);
- }
- } else {
- IMP_LOG(VERBOSE, "Particle " << (*it)->get_index()
- << " is outside of slab" << std::endl);
- }
- }
- return ret;
-}
-
-void TunnelRestraint::show(std::ostream& out) const
-{
- out << "Tunnel restraint :" << f_
- << " " << center_ << " " << height_ << " "
- << coordinate_ << std::endl;
-}
-
-} // namespace IMP
Index: kernel/src/restraints/SConscript
===================================================================
--- kernel/src/restraints/SConscript (revision 626)
+++ kernel/src/restraints/SConscript (working copy)
@@ -1,11 +1,17 @@
Import('env')
-
-files = ['ConnectivityRestraint.cpp', 'RestraintSet.cpp',
- 'DistanceRestraint.cpp', 'AngleRestraint.cpp', 'DihedralRestraint.cpp',
- 'NonbondedRestraint.cpp', 'BondDecoratorRestraint.cpp',
- 'SingletonListRestraint.cpp', 'PairListRestraint.cpp',
- 'TripletChainRestraint.cpp', 'PairChainRestraint.cpp',
- 'ConstantRestraint.cpp', 'TunnelRestraint.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'AngleRestraint.cpp' ),
+ File( 'BondDecoratorRestraint.cpp' ),
+ File( 'ConnectivityRestraint.cpp' ),
+ File( 'ConstantRestraint.cpp' ),
+ File( 'DihedralRestraint.cpp' ),
+ File( 'DistanceRestraint.cpp' ),
+ File( 'NonbondedRestraint.cpp' ),
+ File( 'PairChainRestraint.cpp' ),
+ File( 'PairListRestraint.cpp' ),
+ File( 'PairRestraint.cpp' ),
+ File( 'RestraintSet.cpp' ),
+ File( 'SingletonListRestraint.cpp' ),
+ File( 'TripletChainRestraint.cpp' ),
+ ]
Return('files')
Index: kernel/src/restraints/ConnectivityRestraint.cpp
===================================================================
--- kernel/src/restraints/ConnectivityRestraint.cpp (revision 626)
+++ kernel/src/restraints/ConnectivityRestraint.cpp (working copy)
@@ -118,6 +118,8 @@
IMP_LOG(VERBOSE, "ConnectivityRestraint edge between "
<< get_particle(i)->get_index()
<< " and " << get_particle(j)->get_index() << std::endl);
+ IMP_LOG(VERBOSE, *get_particle(i) << std::endl
+ << *get_particle(j) << std::endl);
sum+= ps_->evaluate(get_particle(i),
get_particle(j),
accum);
Index: kernel/src/restraints/BondDecoratorRestraint.cpp
===================================================================
--- kernel/src/restraints/BondDecoratorRestraint.cpp (revision 626)
+++ kernel/src/restraints/BondDecoratorRestraint.cpp (working copy)
@@ -20,14 +20,15 @@
BondDecoratorRestraint
::BondDecoratorRestraint(UnaryFunction *f,
- BondDecoratorListScoreState *s): bl_(s),
- f_(f){}
+ ManualBondDecoratorListScoreState *s): bl_(s),
+ f_(f){}
Float BondDecoratorRestraint::evaluate(DerivativeAccumulator *accum)
{
Float sum=0;
- for (BondDecoratorListScoreState::BondIterator bi= bl_->bonds_begin();
- bi != bl_->bonds_end(); ++bi) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator bi
+ = bl_->bond_decorators_begin();
+ bi != bl_->bond_decorators_end(); ++bi) {
BondDecorator bd= *bi;
Float l= bd.get_length();
Float s= bd.get_stiffness();
@@ -64,7 +65,7 @@
{
out << "Bond decorator restraint with unary function ";
f_->show(out);
- out << " on " << bl_->get_number_of_bonds() << " bonds";
+ out << " on " << bl_->get_number_of_bond_decorators() << " bonds";
out << std::endl;
}
Index: kernel/src/restraints/DistanceRestraint.cpp
===================================================================
--- kernel/src/restraints/DistanceRestraint.cpp (revision 626)
+++ kernel/src/restraints/DistanceRestraint.cpp (working copy)
@@ -17,23 +17,10 @@
DistanceRestraint::DistanceRestraint(UnaryFunction* score_func,
Particle* p1, Particle* p2) :
- dp_(score_func)
+ PairRestraint(new DistancePairScore(score_func), p1, p2)
{
- add_particle(p1);
- add_particle(p2);
}
-//! Calculate the score for this distance restraint.
-/** \param[in] accum If not NULL, use this object to accumulate partial first
- derivatives.
- \return Current score.
- */
-Float DistanceRestraint::evaluate(DerivativeAccumulator *accum)
-{
- return dp_.evaluate(get_particle(0), get_particle(1), accum);
-}
-
-
//! Show the current restraint.
/** \param[in] out Stream to send restraint description to.
*/
@@ -49,7 +36,7 @@
out << " particles: " << get_particle(0)->get_index();
out << " and " << get_particle(1)->get_index();
out << " ";
- dp_.show(out);
+ dp_->show(out);
out << std::endl;
}
Index: kernel/src/restraints/PairRestraint.cpp
===================================================================
--- kernel/src/restraints/PairRestraint.cpp (revision 0)
+++ kernel/src/restraints/PairRestraint.cpp (revision 0)
@@ -0,0 +1,51 @@
+/**
+ * \file PairRestraint.cpp \brief Pair restraint between two particles.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#include "IMP/Particle.h"
+#include "IMP/Model.h"
+#include "IMP/log.h"
+#include "IMP/restraints/PairRestraint.h"
+#include "IMP/decorators/XYZDecorator.h"
+#include "IMP/PairScore.h"
+
+namespace IMP
+{
+
+PairRestraint::PairRestraint(PairScore* score_func,
+ Particle* p1, Particle* p2) :
+ dp_(score_func)
+{
+ add_particle(p1);
+ add_particle(p2);
+}
+
+Float PairRestraint::evaluate(DerivativeAccumulator *accum)
+{
+ return dp_->evaluate(get_particle(0), get_particle(1), accum);
+}
+
+
+//! Show the current restraint.
+/** \param[in] out Stream to send restraint description to.
+ */
+void PairRestraint::show(std::ostream& out) const
+{
+ if (get_is_active()) {
+ out << "pair restraint (active):" << std::endl;
+ } else {
+ out << "pair restraint (inactive):" << std::endl;
+ }
+
+ get_version_info().show(out);
+ out << " particles: " << get_particle(0)->get_index();
+ out << " and " << get_particle(1)->get_index();
+ out << " ";
+ dp_->show(out);
+ out << std::endl;
+}
+
+} // namespace IMP
Index: kernel/src/restraints/PairChainRestraint.cpp
===================================================================
--- kernel/src/restraints/PairChainRestraint.cpp (revision 626)
+++ kernel/src/restraints/PairChainRestraint.cpp (working copy)
@@ -21,51 +21,20 @@
PairChainRestraint::PairChainRestraint(PairScore* ts)
{
ts_ = ts;
- clear_chains();
}
-void PairChainRestraint::add_chain(const Particles &ps)
-{
- if (ps.size() <= 1) {
- IMP_WARN("Adding a chain of length 1 or less to the PairChainsRestraint"
- << " doesn't accomplish anything."<< std::endl);
- } else {
- Restraint::add_particles(ps);
- chain_splits_.back()= Restraint::get_number_of_particles();
- chain_splits_.push_back(Restraint::get_number_of_particles());
- }
-}
Float PairChainRestraint::evaluate(DerivativeAccumulator *accum)
{
- int cur_break=0;
- unsigned int i=1;
float score=0;
- while (i < Restraint::get_number_of_particles()) {
- /*IMP_LOG(VERBOSE, "Chain eval on "
- << Restraint::get_particle(i-2)->get_index()
- << Restraint::get_particle(i-1)->get_index()
- << Restraint::get_particle(i)->get_index()
- << " split is " << chain_splits_[cur_break]
- << std::endl);*/
+ for (unsigned int i=1; i< Restraint::get_number_of_particles(); ++i) {
score += ts_->evaluate(Restraint::get_particle(i-1),
Restraint::get_particle(i),
accum);
- if (chain_splits_[cur_break] == i) {
- i+=2;
- ++cur_break;
- } else {
- ++i;
- }
}
return score;
}
-void PairChainRestraint::clear_chains() {
- Restraint::clear_particles();
- chain_splits_.clear();
- chain_splits_.push_back(0);
-}
void PairChainRestraint::show(std::ostream& out) const
@@ -77,7 +46,6 @@
}
get_version_info().show(out);
- out << " " << chain_splits_.size()-1 << " chains" << std::endl;
ts_->show(out);
out << std::endl;
}
Index: kernel/src/ParticleRefiner.cpp
===================================================================
--- kernel/src/ParticleRefiner.cpp (revision 626)
+++ kernel/src/ParticleRefiner.cpp (working copy)
@@ -12,8 +12,8 @@
ParticleRefiner::~ParticleRefiner(){}
-Particles ParticleRefiner::get_refined(Particle *p) {
- throw ErrorException("Can't refine");
+Particles ParticleRefiner::get_refined(Particle *p) const {
+ IMP_failure("get_refined not implemented. Oops.", ErrorException);
return Particles();
}
Index: kernel/src/particle_refiners/BondCoverParticleRefiner.cpp
===================================================================
--- kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (revision 626)
+++ kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (working copy)
@@ -16,12 +16,11 @@
{
BondCoverParticleRefiner::BondCoverParticleRefiner(FloatKey rk,
- FloatKey vk): rk_(rk),
- vk_(vk)
+ FloatKey vk,
+ IntKey tk): rk_(rk),
+ vk_(vk),
+ tk_(tk)
{
- if (0) {
- BondCoverParticleRefiner t(rk, vk);
- }
}
@@ -35,7 +34,7 @@
/* n (4/3) pi (d/(2n))^3 = v
n^2= (4/3) pi (d/2)^3 / v
*/
-Particles BondCoverParticleRefiner::get_refined(Particle *p)
+Particles BondCoverParticleRefiner::get_refined(Particle *p) const
{
IMP_assert(get_can_refine(p), "Trying to refine the unrefinable");
@@ -98,6 +97,10 @@
XYZDecorator d= XYZDecorator::create(np);
d.set_coordinates(vb+ (1+2*i)*r* ud);
np->add_attribute(rk_, r, false);
+ if (tk_ != IntKey() && p->has_attribute(tk_)) {
+ np->add_attribute(tk_,
+ p->get_value(tk_));
+ }
ret.push_back(np);
}
return ret;
@@ -107,7 +110,7 @@
void BondCoverParticleRefiner::cleanup_refined(Particle *p,
Particles &ps,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
IMP_assert(get_can_refine(p), "Cleanup called with non-refinable particle");
BondDecorator bd(p);
Index: kernel/src/particle_refiners/SConscript
===================================================================
--- kernel/src/particle_refiners/SConscript (revision 626)
+++ kernel/src/particle_refiners/SConscript (working copy)
@@ -1,4 +1,6 @@
-files=['BondCoverParticleRefiner.cpp', 'ChildrenParticleRefiner.cpp']
-
-files = [File(x) for x in files]
+Import('env')
+files=[
+ File( 'BondCoverParticleRefiner.cpp' ),
+ File( 'ChildrenParticleRefiner.cpp' ),
+ ]
Return('files')
Index: kernel/src/particle_refiners/ChildrenParticleRefiner.cpp
===================================================================
--- kernel/src/particle_refiners/ChildrenParticleRefiner.cpp (revision 626)
+++ kernel/src/particle_refiners/ChildrenParticleRefiner.cpp (working copy)
@@ -23,7 +23,7 @@
}
-Particles ChildrenParticleRefiner::get_refined(Particle *p)
+Particles ChildrenParticleRefiner::get_refined(Particle *p) const
{
IMP_assert(get_can_refine(p), "Trying to refine the unrefinable");
HierarchyDecorator d(p);
@@ -38,7 +38,7 @@
void ChildrenParticleRefiner::cleanup_refined(Particle *,
Particles &,
- DerivativeAccumulator *)
+ DerivativeAccumulator *) const
{
// This space left intentionally blank
}
Index: kernel/src/triplet_scores/AngleTripletScore.cpp
===================================================================
--- kernel/src/triplet_scores/AngleTripletScore.cpp (revision 626)
+++ kernel/src/triplet_scores/AngleTripletScore.cpp (working copy)
@@ -15,7 +15,7 @@
AngleTripletScore::AngleTripletScore(UnaryFunction *f): f_(f){}
Float AngleTripletScore::evaluate(Particle *a, Particle *b, Particle *c,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
IMP_CHECK_OBJECT(f_.get());
IMP_CHECK_OBJECT(a);
Index: kernel/src/triplet_scores/SConscript
===================================================================
--- kernel/src/triplet_scores/SConscript (revision 626)
+++ kernel/src/triplet_scores/SConscript (working copy)
@@ -1,6 +1,5 @@
Import('env')
-
-files = ['AngleTripletScore.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'AngleTripletScore.cpp' ),
+ ]
Return('files')
Index: kernel/src/Log.cpp
===================================================================
--- kernel/src/Log.cpp (revision 626)
+++ kernel/src/Log.cpp (working copy)
@@ -14,4 +14,13 @@
/* Initialize singleton pointer to NULL */
Log* Log::logpt_ = NULL;
+
+bool get_print_exception_messages() {
+ return internal::print_exceptions;
+}
+
+void set_print_exception_messages(bool tf) {
+ internal::print_exceptions=tf;
+}
+
} // namespace IMP
Index: kernel/src/OptimizerState.cpp
===================================================================
--- kernel/src/OptimizerState.cpp (revision 626)
+++ kernel/src/OptimizerState.cpp (working copy)
@@ -15,6 +15,7 @@
//! Constructor
OptimizerState::OptimizerState()
{
+ optimizer_=NULL;
IMP_LOG(VERBOSE, "OptimizerState constructed " << std::endl);
}
Index: kernel/src/decorators/XYZRDecorator.cpp
===================================================================
--- kernel/src/decorators/XYZRDecorator.cpp (revision 0)
+++ kernel/src/decorators/XYZRDecorator.cpp (revision 0)
@@ -0,0 +1,102 @@
+/**
+ * \file XYZRDecorator.cpp \brief Simple xyzr decorator.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ *
+ */
+
+#include "IMP/decorators/XYZRDecorator.h"
+
+//#undef IMP_USE_CGAL
+
+#ifdef IMP_USE_CGAL
+#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
+#include <CGAL/Min_sphere_of_spheres_d.h>
+
+#endif
+
+namespace IMP
+{
+
+// These aren't statically initialized, as that way they may be initialized
+// before the table that caches them
+FloatKey XYZRDecorator::radius_;
+
+void XYZRDecorator::show(std::ostream &out, std::string prefix) const
+{
+ out << prefix << "(" << get_x()<< ", "
+ << get_y() << ", " << get_z() << ": " << get_radius() << ")";
+
+}
+
+
+
+IMP_DECORATOR_INITIALIZE(XYZRDecorator, XYZDecorator,
+ {
+ radius_= FloatKey("radius");
+ })
+
+
+Float distance(XYZRDecorator a, XYZRDecorator b)
+{
+ float d= distance(static_cast<XYZDecorator>(a),
+ static_cast<XYZDecorator>(b));
+ return d - a.get_radius() - b.get_radius();
+}
+
+
+void set_enclosing_sphere(const Particles &v,
+ XYZRDecorator out)
+{
+ IMP_check(!v.empty(), "Must pass some particles to have a bounding sphere",
+ ValueException);
+ for (unsigned int i=0; i< v.size(); ++i) {
+ XYZDecorator::cast(v[i]);
+ }
+ FloatKey rk= XYZRDecorator::get_radius_key();
+
+
+#ifdef IMP_USE_CGAL
+ typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
+ typedef CGAL::Min_sphere_of_spheres_d_traits_3<K, K::FT> Traits;
+ typedef CGAL::Min_sphere_of_spheres_d<Traits> Min_sphere;
+ typedef K::Point_3 Point;
+ typedef Traits::Sphere Sphere;
+
+ std::vector<Sphere> spheres;
+ for (unsigned int i=0; i< v.size(); ++i) {
+ // need cast to resolve ambiguity
+ XYZDecorator d(v[i]);
+ float r=0;
+ if (v[i]->has_attribute(rk)) r= v[i]->get_value(rk);
+
+ spheres.push_back(Sphere(Point(d.get_x(),
+ d.get_y(),
+ d.get_z()),
+ square(r)));
+ }
+ Min_sphere ms(spheres.begin(), spheres.end());
+
+ out.set_radius(ms.radius());
+ out.set_x(*ms.center_cartesian_begin());
+ out.set_y(*(ms.center_cartesian_begin()+1));
+ out.set_z(*(ms.center_cartesian_begin()+2));
+#else
+ Vector3D c(0,0,0);
+ for (unsigned int i=0; i< v.size(); ++i) {
+ XYZDecorator d(v[i]);
+ c+= d.get_vector();
+ }
+ c/=v.size();
+ out.set_coordinates(c);
+ float r=0;
+ for (unsigned int i=0; i< v.size(); ++i) {
+ float d= distance(XYZDecorator(v[i]), out);
+ if (v[i]->has_attribute(rk)) d+= v[i]->get_value(rk);
+ r= std::max(r, d);
+ }
+ out.set_radius(r);
+#endif
+}
+
+} // namespace IMP
Index: kernel/src/decorators/HierarchyDecorator.cpp
===================================================================
--- kernel/src/decorators/HierarchyDecorator.cpp (revision 626)
+++ kernel/src/decorators/HierarchyDecorator.cpp (working copy)
@@ -10,6 +10,7 @@
#include "IMP/decorators/NameDecorator.h"
#include <sstream>
+#include <memory>
namespace IMP
{
@@ -44,9 +45,9 @@
unsigned int count_hierarchy(HierarchyDecorator h)
{
- HierarchyCounter hc;
- depth_first_traversal(h,hc);
- return hc.get_count();
+ std::auto_ptr<HierarchyCounter> hc(new HierarchyCounter());
+ depth_first_traversal(h,hc.get());
+ return hc->get_count();
}
@@ -70,8 +71,8 @@
void HierarchyDecorator::validate() const
{
//std::cerr << "Checking hierarchy" << std::endl;
- internal::AssertHierarchy ah;
- depth_first_traversal(*this, ah);
+ std::auto_ptr<internal::AssertHierarchy> ah(new internal::AssertHierarchy());
+ depth_first_traversal(*this, ah.get());
}
@@ -95,7 +96,7 @@
})
-void breadth_first_traversal(HierarchyDecorator d, HierarchyVisitor &f)
+void breadth_first_traversal(HierarchyDecorator d, HierarchyVisitor *f)
{
std::deque<HierarchyDecorator> stack;
stack.push_back(d);
@@ -103,7 +104,7 @@
do {
HierarchyDecorator cur= stack.front();
stack.pop_front();
- if (f.visit(cur.get_particle())) {
+ if (f->visit(cur.get_particle())) {
//std::cerr << "Visiting particle " << cur.get_particle() << std::endl;
for (int i=cur.get_number_of_children()-1; i>=0; --i) {
stack.push_back(cur.get_child(i));
@@ -112,14 +113,14 @@
} while (!stack.empty());
}
-void depth_first_traversal(HierarchyDecorator d, HierarchyVisitor &f)
+void depth_first_traversal(HierarchyDecorator d, HierarchyVisitor *f)
{
std::vector<HierarchyDecorator> stack;
stack.push_back(d);
do {
HierarchyDecorator cur= stack.back();
stack.pop_back();
- if (f.visit(cur.get_particle())) {
+ if (f->visit(cur.get_particle())) {
for (int i=cur.get_number_of_children()-1; i>=0; --i) {
stack.push_back(cur.get_child(i));
}
@@ -144,16 +145,11 @@
Particles
-hierarchy_get_leaves(HierarchyDecorator mhd)
-{
- Particles out;
- hierarchy_gather(mhd, MHDMatchingLeaves(),
- std::back_inserter(out));
- return out;
+hierarchy_get_leaves(HierarchyDecorator mhd) {
+ return hierarchy_get(mhd, MHDMatchingLeaves());
}
-BondDecorators hierarchy_get_internal_bonds(HierarchyDecorator mhd)
-{
+BondDecorators hierarchy_get_internal_bonds(HierarchyDecorator mhd) {
Particles ps= hierarchy_get_all_descendants(mhd);
std::set<Particle*> sps(ps.begin(), ps.end());
BondDecorators ret;
@@ -186,12 +182,8 @@
} // namespace
Particles
-hierarchy_get_all_descendants(HierarchyDecorator mhd)
-{
- Particles out;
- hierarchy_gather(mhd, MHDMatchingAll(),
- std::back_inserter(out));
- return out;
+hierarchy_get_all_descendants(HierarchyDecorator mhd) {
+ return hierarchy_get(mhd, MHDMatchingAll());
}
} // namespace IMP
Index: kernel/src/decorators/yaml.cpp
===================================================================
--- kernel/src/decorators/yaml.cpp (revision 0)
+++ kernel/src/decorators/yaml.cpp (revision 0)
@@ -0,0 +1,272 @@
+#include <IMP/decorators/yaml.h>
+
+namespace IMP
+{
+
+ namespace {
+ struct DefaultWrite {
+ template <class T>
+ std::ostream & operator()(const T t,
+ std::ostream &out) const {
+ return out << t;
+ }
+ };
+ struct ParticleWrite {
+ std::ostream & operator()(Particle *p,
+ std::ostream &out) const {
+ return out << p->get_index().get_index();
+ }
+ };
+ struct FloatWrite {
+ std::ostream & operator()(Float t,
+ std::ostream &out) const {
+ // set format better
+ return out << t;
+ }
+ };
+
+ template <class It, class Write>
+ void write_attributes(std::string indent,
+ Particle *p,
+ It b, It e, Write w,
+ std::ostream &out) {
+ for (It c= b; c != e; ++c) {
+ /** \todo should escape things properly */
+ out << indent << c->get_string() << ": ";
+ w(p->get_value(*c), out) << "\n";
+ }
+ }
+
+ // skips empty lines
+ struct LineStream{
+ std::istream ∈
+ std::vector<std::string> line;
+ bool has_indent(std::string str, unsigned int indent) {
+ for (unsigned int i=0; i< indent; ++i) {
+ if (i== str.size()) return false;
+ if (str[i] != ' ') return false;
+ }
+ return true;
+ }
+ bool not_white(char buf[]) const {
+ for (int i=0; buf[i] != '\0'; ++i) {
+ if (buf[i] != ' ') return true;
+ }
+ return false;
+ }
+
+ LineStream(std::istream &init): in(init){}
+ operator bool() const {return !line.empty() || static_cast<bool>(in);}
+ std::string get_line(unsigned int min_indent) {
+ while (line.empty()) {
+ char buf[3000];
+ in.getline(buf, 3000);
+ if (!in) return std::string();
+ if (buf[0] == '#') continue;
+ if (not_white(buf)) {
+ line.push_back(buf);
+ }
+ }
+ if (has_indent(line.back(), min_indent)) {
+ std::string ret(line.back(), min_indent);
+ line.pop_back();
+ return ret;
+ } else {
+ IMP_LOG(VERBOSE, "Line \"" << line.back() << "\" lacks "
+ << min_indent << " spaces" << std::endl);
+ return std::string();
+ }
+ }
+ void push_line(std::string s) {
+ if (s.empty()) return;
+ for (unsigned int i=0; i< s.size(); ++i) {
+ if (s[i] != ' ') {
+ line.push_back(s);
+ return;
+ }
+ }
+ }
+ };
+
+ template <class K, class V>
+ struct DefaultRead {
+ void operator()(Particle *p, std::string key, std::string value) const {
+ IMP_LOG(VERBOSE,
+ "Reading values from pair " << key << " "
+ << value << std::endl);
+ K k(key.c_str());
+ std::istringstream iss(value.c_str());
+ V v;
+ iss >> v;
+ IMP_check(iss, "Error reading value. Got " << v , ValueException);
+ p->set_value(k, v);
+ }
+ };
+
+ struct ParticleRead {
+ void operator()(Particle *p, std::string key, std::string value) const {
+ IMP_LOG(VERBOSE,
+ "Reading values from pair " << key << " "
+ << value << std::endl);
+ ParticleKey k(key.c_str());
+ std::istringstream iss(value.c_str());
+ int i;
+ iss >> i;
+ IMP_check(iss, "Error reading value" , ValueException);
+ Particle *op= p->get_model()->get_particle(ParticleIndex(i));
+ p->set_value(k, op);
+ }
+ };
+
+ int get_next_indent(LineStream &in) {
+ std::string buf= in.get_line(0);
+ if (buf.empty()) return 0;
+ unsigned int i=0;
+ for (; i < buf.size() && buf[i] == ' '; ++i) {
+ }
+ in.push_line(buf);
+ return i;
+ }
+
+
+ template <class Read>
+ void read_attributes(Particle *p, LineStream &in,
+ int indent,
+ Read read) {
+ IMP_LOG(VERBOSE, "Reading attributes " << indent << std::endl);
+ int nindent= get_next_indent(in);
+ if (nindent <= indent) return;
+ indent=nindent;
+ IMP_LOG(VERBOSE, "Required indent is " << indent<< std::endl);
+ do {
+ std::string buf = in.get_line(indent);
+ if (buf.empty()) {
+ IMP_LOG(VERBOSE, "Done reading attributes" << std::endl);
+ return;
+ }
+ IMP_check(buf[0] != ' ', "Extra white space on line "
+ << buf, InvalidStateException);
+ std::istringstream iss(buf.c_str());
+ char key[2000];
+ iss.get(key, 2000, ':');
+ IMP_check(iss, "no : found in line " << buf,
+ ValueException);
+ char colon;
+ iss >> colon;
+ IMP_check(colon == ':', "No colon found" << buf,
+ ValueException);
+
+ char value[2000];
+ iss.getline(value, 2000);
+ IMP_check(iss, "Error reading line " << buf,
+ ValueException);
+ read(p, key, value);
+
+ } while (true);
+ }
+
+ void read_yaml(Model *m,
+ LineStream &in,
+ unsigned int indent) {
+ std::string buf=in.get_line(indent);
+ if (buf.empty()) return;
+ //IMP_LOG(VERBOSE, "Got line " << buf << std::endl);
+ //IMP_check(in, "Error reading particle line from yaml", ValueException);
+ int id;
+ int nread=sscanf(buf.c_str(), "particle: %d", &id);
+ IMP_check(nread==1, "Couldn't read id", InvalidStateException);
+ Particle *p= m->get_particle(id);
+ IMP_LOG(VERBOSE, "Reading particle " << id << std::endl);
+ unsigned int nindent= get_next_indent(in);
+ if (nindent <= indent) return;
+ indent=nindent;
+ while (in) {
+ std::string buf=in.get_line(indent);
+ if (buf.empty()) break;
+ IMP_check(buf[0] != ' ', "Indent error" << buf, InvalidStateException);
+
+ IMP_LOG(VERBOSE, "Looking for attributes in line " << buf << std::endl);
+ std::istringstream iss(buf);
+ std::string type;
+ iss >> type;
+ if (type.compare("float-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<FloatKey, Float>());
+ } else if (type.compare("int-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<IntKey, Int>());
+ } else if (type.compare("string-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<StringKey, String>());
+ } else if (type.compare("particle-attributes:")==0) {
+ read_attributes(p, in, indent, ParticleRead());
+ } else {
+ break;
+ }
+ }
+ IMP_LOG(VERBOSE, "Done reading particle " << id << std::endl);
+ }
+ }
+
+ static std::string indent_level=" ";
+
+ void write_yaml(Particle *p,
+ std::ostream &out,
+ std::string indent) {
+ out << indent << "particle: " << p->get_index().get_index() << "\n";
+ out << indent << indent_level << "float-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->float_keys_begin(),
+ p->float_keys_end(),
+ FloatWrite(),
+ out);
+ out << indent << indent_level << "int-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->int_keys_begin(),
+ p->int_keys_end(),
+ DefaultWrite(),
+ out);
+ out << indent << indent_level << "string-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->string_keys_begin(),
+ p->string_keys_end(),
+ DefaultWrite(),
+ out);
+ out << indent << indent_level << "particle-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->particle_keys_begin(),
+ p->particle_keys_end(),
+ ParticleWrite(),
+ out);
+ }
+
+ void write_yaml(Model *m,
+ std::ostream &out,
+ std::string indent) {
+ for (Model::ParticleIterator pit= m->particles_begin();
+ pit != m->particles_end(); ++pit) {
+ write_yaml(*pit, out, indent);
+ }
+ }
+
+ void read_yaml(std::istream &in,
+ Model *m) {
+ LineStream r(in);
+ unsigned int nread=0;
+ do {
+ read_yaml(m, r, get_next_indent(r));
+ ++nread;
+ } while (r);
+ IMP_check(nread== m->get_number_of_particles(),
+ "Read wrong number of particles. Model is corrupted. Bye.",
+ ErrorException);
+ }
+
+ void read_yaml(std::string contents,
+ Model *m) {
+ std::istringstream iss(contents.c_str());
+ IMP_LOG(VERBOSE, "Got string:\n" << contents << std::endl);
+ read_yaml(iss, m);
+ }
+}
Index: kernel/src/decorators/AtomDecorator.cpp
===================================================================
--- kernel/src/decorators/AtomDecorator.cpp (revision 626)
+++ kernel/src/decorators/AtomDecorator.cpp (working copy)
@@ -5,13 +5,13 @@
*
*/
+#include "IMP/decorators/AtomDecorator.h"
+#include "IMP/log.h"
+
#include <sstream>
#include <vector>
#include <limits>
-#include "IMP/decorators/AtomDecorator.h"
-#include "IMP/log.h"
-
namespace IMP
{
Index: kernel/src/decorators/ResidueDecorator.cpp
===================================================================
--- kernel/src/decorators/ResidueDecorator.cpp (revision 626)
+++ kernel/src/decorators/ResidueDecorator.cpp (working copy)
@@ -12,6 +12,7 @@
#include <sstream>
#include <vector>
+#include <iterator>
namespace IMP
{
Index: kernel/src/decorators/MolecularHierarchyDecorator.cpp
===================================================================
--- kernel/src/decorators/MolecularHierarchyDecorator.cpp (revision 626)
+++ kernel/src/decorators/MolecularHierarchyDecorator.cpp (working copy)
@@ -54,34 +54,12 @@
})
-namespace
-{
-
-struct MHDMatchingType
-{
- MHDMatchingType(MolecularHierarchyDecorator::Type t): t_(t){}
-
- bool operator()(Particle *p) const {
- MolecularHierarchyDecorator mhd= MolecularHierarchyDecorator::cast(p);
- if (mhd== MolecularHierarchyDecorator()) {
- return false;
- } else {
- return mhd.get_type()==t_;
- }
- }
-
- MolecularHierarchyDecorator::Type t_;
-};
-
-} // namespace
-
Particles molecular_hierarchy_get_by_type(MolecularHierarchyDecorator mhd,
MolecularHierarchyDecorator::Type t)
{
- Particles out;
- hierarchy_gather(mhd, MHDMatchingType(t),
- std::back_inserter(out));
- return out;
+ return hierarchy_get_by_attribute(mhd,
+ MolecularHierarchyDecorator::get_type_key(),
+ t);
}
@@ -156,5 +134,4 @@
return fd;
}
-
} // namespace IMP
Index: kernel/src/decorators/SConscript
===================================================================
--- kernel/src/decorators/SConscript (revision 626)
+++ kernel/src/decorators/SConscript (working copy)
@@ -1,8 +1,13 @@
Import('env')
-
-files = ['AtomDecorator.cpp', 'bond_decorators.cpp',
- 'HierarchyDecorator.cpp', 'NameDecorator.cpp', 'ResidueDecorator.cpp',
- 'MolecularHierarchyDecorator.cpp', 'XYZDecorator.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'AtomDecorator.cpp' ),
+ File( 'bond_decorators.cpp' ),
+ File( 'HierarchyDecorator.cpp' ),
+ File( 'MolecularHierarchyDecorator.cpp' ),
+ File( 'NameDecorator.cpp' ),
+ File( 'ResidueDecorator.cpp' ),
+ File( 'XYZDecorator.cpp' ),
+ File( 'XYZRDecorator.cpp' ),
+ File( 'yaml.cpp' ),
+ ]
Return('files')
Index: kernel/src/decorators/XYZDecorator.cpp
===================================================================
--- kernel/src/decorators/XYZDecorator.cpp (revision 626)
+++ kernel/src/decorators/XYZDecorator.cpp (working copy)
@@ -62,16 +62,9 @@
key_[2] = FloatKey("z");
})
-namespace {
- template <class T>
- T d(T a, T b){T d=a-b; return d*d;}
-}
-
Float distance(XYZDecorator a, XYZDecorator b)
{
- double d2= d(a.get_x(), b.get_x()) + d(a.get_y(), b.get_y())
- + d(a.get_z(), b.get_z());
- return std::sqrt(d2);
+ return (a.get_vector()-b.get_vector()).get_magnitude();
}
} // namespace IMP
Index: kernel/src/optimizers/states/SConscript
===================================================================
--- kernel/src/optimizers/states/SConscript (revision 626)
+++ kernel/src/optimizers/states/SConscript (working copy)
@@ -1,7 +1,7 @@
Import('env')
-
-files = ['VRMLLogOptimizerState.cpp', 'CMMLogOptimizerState.cpp',
- 'VelocityScalingOptimizerState.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'CMMLogOptimizerState.cpp' ),
+ File( 'VelocityScalingOptimizerState.cpp' ),
+ File( 'VRMLLogOptimizerState.cpp' ),
+ ]
Return('files')
Index: kernel/src/optimizers/states/VRMLLogOptimizerState.cpp
===================================================================
--- kernel/src/optimizers/states/VRMLLogOptimizerState.cpp (revision 626)
+++ kernel/src/optimizers/states/VRMLLogOptimizerState.cpp (working copy)
@@ -10,7 +10,7 @@
#include <sstream>
#include "IMP/optimizers/states/VRMLLogOptimizerState.h"
-#include "IMP/decorators/XYZDecorator.h"
+#include "IMP/decorators/XYZRDecorator.h"
namespace IMP
{
@@ -18,7 +18,7 @@
VRMLLogOptimizerState::VRMLLogOptimizerState(std::string filename,
const Particles &pis) :
filename_(filename), file_number_(0), call_number_(0),
- skip_steps_(0)
+ skip_steps_(0), radius_(XYZRDecorator::get_radius_key())
{
set_particles(pis);
}
Index: kernel/src/optimizers/MonteCarlo.cpp
===================================================================
--- kernel/src/optimizers/MonteCarlo.cpp (revision 626)
+++ kernel/src/optimizers/MonteCarlo.cpp (working copy)
@@ -39,7 +39,7 @@
Float MonteCarlo::optimize(unsigned int max_steps)
{
IMP_CHECK_OBJECT(this);
- if (cg_.get() != NULL) {
+ if (cg_) {
IMP_CHECK_OBJECT(cg_.get());
IMP_check(cg_->get_model() == get_model(),
"The model used by the local optimizer does not match "\
@@ -58,7 +58,7 @@
(*it)->propose_move(probability_);
}
Float next_energy;
- if (cg_.get() != NULL && num_local_steps_!= 0) {
+ if (cg_ && num_local_steps_!= 0) {
IMP_LOG(VERBOSE,
"MC Performing local optimization "<< std::flush);
IMP_CHECK_OBJECT(cg_.get());
Index: kernel/src/optimizers/SConscript
===================================================================
--- kernel/src/optimizers/SConscript (revision 626)
+++ kernel/src/optimizers/SConscript (working copy)
@@ -1,11 +1,12 @@
Import('env')
-
-states_files = SConscript('states/SConscript')
-movers_files = SConscript('movers/SConscript')
-
-files = ['SteepestDescent.cpp', 'ConjugateGradients.cpp',
- 'MolecularDynamics.cpp', 'MonteCarlo.cpp', 'MoverBase.cpp',
- 'BrownianDynamics.cpp'] + states_files + movers_files
-
-files = [File(x) for x in files]
+files=[
+ File( 'BrownianDynamics.cpp' ),
+ File( 'ConjugateGradients.cpp' ),
+ File( 'MolecularDynamics.cpp' ),
+ File( 'MonteCarlo.cpp' ),
+ File( 'MoverBase.cpp' ),
+ File( 'SteepestDescent.cpp' ),
+ SConscript( 'movers/SConscript' ),
+ SConscript( 'states/SConscript' ),
+ ]
Return('files')
Index: kernel/src/optimizers/movers/SConscript
===================================================================
--- kernel/src/optimizers/movers/SConscript (revision 626)
+++ kernel/src/optimizers/movers/SConscript (working copy)
@@ -1,6 +1,6 @@
Import('env')
-
-files = [ 'BallMover.cpp', 'NormalMover.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'BallMover.cpp' ),
+ File( 'NormalMover.cpp' ),
+ ]
Return('files')
Index: kernel/src/pair_scores/DistancePairScore.cpp
===================================================================
--- kernel/src/pair_scores/DistancePairScore.cpp (revision 626)
+++ kernel/src/pair_scores/DistancePairScore.cpp (working copy)
@@ -22,7 +22,7 @@
};
Float DistancePairScore::evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
return internal::evaluate_distance_pair_score(XYZDecorator(a),
XYZDecorator(b),
Index: kernel/src/pair_scores/RefineOncePairScore.cpp
===================================================================
--- kernel/src/pair_scores/RefineOncePairScore.cpp (revision 626)
+++ kernel/src/pair_scores/RefineOncePairScore.cpp (working copy)
@@ -20,7 +20,7 @@
PairScore *f): r_(r), f_(f) {}
Float RefineOncePairScore::evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
Particle* p[2]={a,b};
Particles ps[2];
Index: kernel/src/pair_scores/SConscript
===================================================================
--- kernel/src/pair_scores/SConscript (revision 626)
+++ kernel/src/pair_scores/SConscript (working copy)
@@ -1,8 +1,9 @@
Import('env')
-
-files = ['DistancePairScore.cpp', 'SphereDistancePairScore.cpp',
- 'RefineOncePairScore.cpp', 'TypedPairScore.cpp',
- 'TransformedDistancePairScore.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'DistancePairScore.cpp' ),
+ File( 'RefineOncePairScore.cpp' ),
+ File( 'SphereDistancePairScore.cpp' ),
+ File( 'TransformedDistancePairScore.cpp' ),
+ File( 'TypedPairScore.cpp' ),
+ ]
Return('files')
Index: kernel/src/pair_scores/TransformedDistancePairScore.cpp
===================================================================
--- kernel/src/pair_scores/TransformedDistancePairScore.cpp (revision 626)
+++ kernel/src/pair_scores/TransformedDistancePairScore.cpp (working copy)
@@ -83,12 +83,13 @@
};
Float TransformedDistancePairScore::evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
TransformParticle tb(r_,ri_, tc_,c_,b);
IMP_LOG(VERBOSE, "Transformed particle is "
<< tb.get_coordinate(0) << " " << tb.get_coordinate(1)
- << " " << tb.get_coordinate(2) << std::endl);
+ << " " << tb.get_coordinate(2)
+ << " from " << XYZDecorator(b) << std::endl);
return internal::evaluate_distance_pair_score(XYZDecorator(a),
tb,
da, f_.get(),
@@ -136,6 +137,14 @@
{
out << "TransformedDistancePairScore using ";
f_->show(out);
+ out << "With rotation:\n";
+ out << r_[0] << std::endl;
+ out << r_[1] << std::endl;
+ out << r_[2] << std::endl;
+ out << "and inverse rotation:\n";
+ out << ri_[0] << std::endl;
+ out << ri_[1] << std::endl;
+ out << ri_[2] << std::endl;
}
} // namespace IMP
Index: kernel/src/pair_scores/SphereDistancePairScore.cpp
===================================================================
--- kernel/src/pair_scores/SphereDistancePairScore.cpp (revision 626)
+++ kernel/src/pair_scores/SphereDistancePairScore.cpp (working copy)
@@ -29,7 +29,7 @@
};
Float SphereDistancePairScore::evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
IMP_check(a->has_attribute(radius_), "Particle " << a->get_index()
<< "missing radius in SphereDistancePairScore",
Index: kernel/src/pair_scores/TypedPairScore.cpp
===================================================================
--- kernel/src/pair_scores/TypedPairScore.cpp (revision 626)
+++ kernel/src/pair_scores/TypedPairScore.cpp (working copy)
@@ -11,7 +11,7 @@
{
Float TypedPairScore::evaluate(Particle *a, Particle *b,
- DerivativeAccumulator *da)
+ DerivativeAccumulator *da) const
{
if (!a->has_attribute(typekey_)) {
set_particle_type(a);
@@ -22,7 +22,7 @@
Int atype = a->get_value(typekey_);
Int btype = b->get_value(typekey_);
- ScoreMap::iterator psit =
+ ScoreMap::const_iterator psit =
score_map_.find(std::pair<Int,Int>(std::min(atype, btype),
std::max(atype, btype)));
if (psit == score_map_.end()) {
Index: kernel/src/internal/SConscript
===================================================================
--- kernel/src/internal/SConscript (revision 626)
+++ kernel/src/internal/SConscript (working copy)
@@ -1,7 +1,9 @@
Import('env')
-
-files = ['graph_base.cpp', 'ParticleGrid.cpp',
- 'kernel_version_info.cpp', 'constants.cpp', 'bbox_nbl_helpers.cpp']
-
-files = [File(x) for x in files]
+files=[
+ File( 'bbox_nbl_helpers.cpp' ),
+ File( 'constants.cpp' ),
+ File( 'graph_base.cpp' ),
+ File( 'kernel_version_info.cpp' ),
+ File( 'ParticleGrid.cpp' ),
+ ]
Return('files')
Index: kernel/src/internal/bbox_nbl_helpers.cpp
===================================================================
--- kernel/src/internal/bbox_nbl_helpers.cpp (revision 626)
+++ kernel/src/internal/bbox_nbl_helpers.cpp (working copy)
@@ -12,7 +12,9 @@
/* compile the CGAL code with NDEBUG since it doesn't have the
same level of control over errors as IMP
*/
+#ifndef NDEBUG
#define NDEBUG
+#endif
#ifdef IMP_USE_CGAL
#include <CGAL/box_intersection_d.h>
#include <vector>
@@ -76,7 +78,7 @@
CGAL::box_intersection_d( boxes0.begin(), boxes0.end(),
boxes1.begin(), boxes1.end(), ap);
#else
- IMP_failure( "IMP built without CGAL support.", ErrorException());
+ IMP_failure( "IMP built without CGAL support.", ErrorException);
#endif
}
@@ -91,7 +93,7 @@
CGAL::box_self_intersection_d( boxes.begin(), boxes.end(), ap);
#else
- IMP_failure("IMP built without CGAL support.", ErrorException());
+ IMP_failure("IMP built without CGAL support.", ErrorException);
#endif
}
Index: kernel/pyext/IMP/test.py
===================================================================
--- kernel/pyext/IMP/test.py (revision 626)
+++ kernel/pyext/IMP/test.py (working copy)
@@ -3,6 +3,40 @@
import IMP
+def create_particles_in_box( 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 randomize_particles(particles, deviation):
+ """Randomize the xyz coordinates of a list of particles"""
+ for p in particles:
+ d= IMP.XYZDecorator.cast(p)
+ d.set_x(random.uniform(-deviation, deviation))
+ d.set_y(random.uniform(-deviation, deviation))
+ d.set_z(random.uniform(-deviation, deviation))
+
+def create_chain(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 TestCase(unittest.TestCase):
"""Super class for IMP test cases"""
@@ -10,6 +44,8 @@
self.__check_level = IMP.get_check_level()
# Turn on expensive runtime checks while running the test suite:
IMP.set_check_level(IMP.EXPENSIVE)
+ # should go in library init code
+ IMP.set_print_exception_messages(False)
def tearDown(self):
# Restore original check level
@@ -33,14 +69,6 @@
p.add_attribute(IMP.FloatKey("z"), z, True)
return p
- def randomize_particles(self, particles, deviation):
- """Randomize the xyz coordinates of a list of particles"""
- for p in particles:
- d= IMP.XYZDecorator.cast(p)
- d.set_x(random.uniform(-deviation, deviation))
- d.set_y(random.uniform(-deviation, deviation))
- d.set_z(random.uniform(-deviation, deviation))
-
def particle_distance(self, p1, p2):
"""Return distance between two given particles"""
xkey = IMP.FloatKey("x")
@@ -73,30 +101,7 @@
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):
Index: kernel/pyext/IMP/modeller_intf.py
===================================================================
--- kernel/pyext/IMP/modeller_intf.py (revision 626)
+++ kernel/pyext/IMP/modeller_intf.py (working copy)
@@ -241,7 +241,7 @@
def _LinearGenerator(parameters, modalities):
(scale,) = parameters
- return IMP.Linear(scale)
+ return IMP.Linear(0,scale)
def _SplineGenerator(parameters, modalities):
(open, low, high, delta, lowderiv, highderiv) = parameters[:6]
Index: kernel/pyext/IMP.i
===================================================================
--- kernel/pyext/IMP.i (revision 626)
+++ kernel/pyext/IMP.i (working copy)
@@ -36,13 +36,16 @@
%pythonprepend Optimizer::add_optimizer_state %{
args[1].thisown=0
%}
+ %pythonprepend Optimizer::set_model %{
+ args[1].thisown=0
+ %}
%pythonprepend RestraintSet::add_restraint %{
args[1].thisown=0
%}
%pythonprepend NonbondedListScoreState::add_bonded_list %{
args[1].thisown=0
%}
- %pythonprepend TunnelRestraint::TunnelRestraint %{
+ %pythonprepend TunnelSingletonScore::TunnelSingletonScore %{
args[0].thisown=0
%}
%pythonprepend DistanceRestraint::DistanceRestraint %{
@@ -75,6 +78,9 @@
%pythonprepend PairChainRestraint::PairChainRestraint %{
args[0].thisown=0
%}
+ %pythonprepend PairRestraint::PairRestraint %{
+ args[0].thisown=0
+ %}
%pythonprepend ConnectivityRestraint::ConnectivityRestraint %{
args[0].thisown=0
%}
@@ -113,7 +119,7 @@
args[1].thisown=0
%}
%pythonprepend TypedPairScore::set_pair_score %{
- args[0].thisown=0
+ args[1].thisown=0
%}
%pythonprepend Particle::get_value %{
check_particle(args[0], args[1])
@@ -148,7 +154,10 @@
%feature("ref") Particle "$this->ref();"
%feature("unref") Particle "$this->unref(); if (! $this->get_has_ref()) delete $this;"
+/*%feature("ref") Model "$this->ref();"
+%feature("unref") Model "$this->unref(); if (! $this->get_has_ref()) delete $this;"*/
+
/* Don't wrap internal functions */
%ignore IMP::internal::evaluate_distance_pair_score;
%ignore IMP::internal::check_particles_active;
@@ -171,14 +180,6 @@
%include "IMP/base_types.h"
%include "IMP/VersionInfo.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/DerivativeAccumulator.h"
%include "IMP/Restraint.h"
%include "IMP/ScoreState.h"
@@ -190,6 +191,7 @@
%include "IMP/SingletonScore.h"
%include "IMP/TripletScore.h"
%include "IMP/Particle.h"
+%include "IMP/ParticleRefiner.h"
%include "Vector3D.i"
%include "IMP/DecoratorBase.h"
%include "IMP/decorators/bond_decorators.h"
@@ -198,8 +200,9 @@
%include "IMP/decorators/NameDecorator.h"
%include "IMP/decorators/ResidueDecorator.h"
%include "IMP/decorators/XYZDecorator.h"
+%include "IMP/decorators/XYZRDecorator.h"
%include "IMP/decorators/AtomDecorator.h"
-%include "IMP/ParticleRefiner.h"
+%include "IMP/decorators/yaml.h"
%include "IMP/particle_refiners/BondCoverParticleRefiner.h"
%include "IMP/particle_refiners/ChildrenParticleRefiner.h"
%include "IMP/Optimizer.h"
@@ -224,16 +227,18 @@
%include "IMP/particle_refiners/ChildrenParticleRefiner.h"
%include "IMP/singleton_scores/DistanceToSingletonScore.h"
%include "IMP/singleton_scores/AttributeSingletonScore.h"
-%include "IMP/triplet_scores/AngleTripletScore.h"
+%include "IMP/singleton_scores/TunnelSingletonScore.h"
%include "IMP/score_states/BondedListScoreState.h"
%include "IMP/score_states/MaxChangeScoreState.h"
%include "IMP/score_states/NonbondedListScoreState.h"
%include "IMP/score_states/AllNonbondedListScoreState.h"
+%include "IMP/score_states/ManualBondDecoratorListScoreState.h"
%include "IMP/score_states/BondDecoratorListScoreState.h"
%include "IMP/score_states/BipartiteNonbondedListScoreState.h"
%include "IMP/score_states/GravityCenterScoreState.h"
%include "IMP/score_states/CoverBondsScoreState.h"
%include "IMP/restraints/AngleRestraint.h"
+%include "IMP/restraints/PairRestraint.h"
%include "IMP/restraints/BondDecoratorRestraint.h"
%include "IMP/restraints/ConnectivityRestraint.h"
%include "IMP/restraints/ConstantRestraint.h"
@@ -245,7 +250,15 @@
%include "IMP/restraints/RestraintSet.h"
%include "IMP/restraints/SingletonListRestraint.h"
%include "IMP/restraints/TripletChainRestraint.h"
-%include "IMP/restraints/TunnelRestraint.h"
+%include "IMP/triplet_scores/AngleTripletScore.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"
namespace IMP {
%template(ParticleIndex) Index<ParticleTag>;
3
2
Here is a quick patch to change evaluate_deriv to evaluate_derivative
since we use the full name elsewhere and I kept mistyping it. It is
against the current SVN version.
BTW, domino run_all_tests.py is missing.
3
2
Here is a patch with various important and minor patches to embed.
These include
- change some of the io errors to throw exceptions rather than return
error codes as the error codes pretty much never checked in EMbed and
don't propagate out. It also checks error codes more often for good
measure)
- write error messages to stderr instead of standard output
- add a method to access a trilinearly interpolated density (so that
the returned values are continuous)
- initialize the data in density maps to 0 on construction
- add a version of get_origin with takes an int (like the get-max)
- add a few more error checks
- tweak the endian hack in MRCReader since it was not getting the
endianness right on my files.
5
12
Which are all grouped together since they can't be easily disentangled
at this point.
API changes:
- some new methods have been added to hierarchies and molecular
hierarchies and the names have been made slightly more consistent
- a new score state ManualBondDecoratorListScoreState which does not
rescan the particles to search for bonds. The old BondDecoratorList
inherits from this.
- the bond cover particle refiner now takes an optional intkey whose
value will be propagated to the created particles (so that the
typedpairscore can be used)
- vector3d now can be put in std::maps
- vrmllog now looks up colors in a map off of an index field and had
some function names changed to make them make more since. And it takes
particles refiners.
- there is now code to read and write particles to YAML streams (as that
makes way more sense for this sort of thing than xml). Individual
particles can be written, but only the whole model must be read at once.
- a few of the functions which used to be in the python class IMP.Test
are now in the module IMP.test
minor changes:
- various cleanups to header inclusions, and other sorts of things
- verbose no longer logs every reference increment and decrement
The SConscript files are not included in the patch.
Index: kernel/doc/examples/chain.py
===================================================================
--- kernel/doc/examples/chain.py (revision 623)
+++ kernel/doc/examples/chain.py (working copy)
@@ -74,7 +74,7 @@
# Write the progression of states as the system is optimized to
# the files state.000.vrml, state.001.vrml etc.
vrml= IMP.VRMLLogOptimizerState("state.%03d.vrml", chain)
-vrml.set_radius(rk)
+vrml.set_radius_key(rk)
vrml.update()
vrml.set_skip_steps(100)
o.add_optimizer_state(vrml)
Index: kernel/src/particle_refiners/BondCoverParticleRefiner.cpp
===================================================================
--- kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (revision 623)
+++ kernel/src/particle_refiners/BondCoverParticleRefiner.cpp (working copy)
@@ -16,12 +16,11 @@
{
BondCoverParticleRefiner::BondCoverParticleRefiner(FloatKey rk,
- FloatKey vk): rk_(rk),
- vk_(vk)
+ FloatKey vk,
+ IntKey tk): rk_(rk),
+ vk_(vk),
+ tk_(tk)
{
- if (0) {
- BondCoverParticleRefiner t(rk, vk);
- }
}
@@ -98,6 +97,10 @@
XYZDecorator d= XYZDecorator::create(np);
d.set_coordinates(vb+ (1+2*i)*r* ud);
np->add_attribute(rk_, r, false);
+ if (tk_ != IntKey() && p->has_attribute(tk_)) {
+ np->add_attribute(tk_,
+ p->get_value(tk_));
+ }
ret.push_back(np);
}
return ret;
Index: kernel/src/decorators/MolecularHierarchyDecorator.cpp
===================================================================
--- kernel/src/decorators/MolecularHierarchyDecorator.cpp (revision 623)
+++ kernel/src/decorators/MolecularHierarchyDecorator.cpp (working copy)
@@ -6,13 +6,14 @@
*
*/
-#include <sstream>
-
#include "IMP/decorators/MolecularHierarchyDecorator.h"
#include "IMP/decorators/NameDecorator.h"
#include "IMP/decorators/AtomDecorator.h"
#include "IMP/decorators/ResidueDecorator.h"
+#include <sstream>
+#include <set>
+
namespace IMP
{
@@ -72,10 +73,10 @@
MolecularHierarchyDecorator::Type t_;
};
-} // namespace internal
+} // namespace
-Particles get_particles(MolecularHierarchyDecorator mhd,
- MolecularHierarchyDecorator::Type t)
+Particles molecular_hierarchy_get_by_type(MolecularHierarchyDecorator mhd,
+ MolecularHierarchyDecorator::Type t)
{
Particles out;
hierarchy_gather(mhd, MHDMatchingType(t),
@@ -106,8 +107,9 @@
} // namespace
-ResidueDecorator get_residue(MolecularHierarchyDecorator mhd,
- unsigned int index)
+ResidueDecorator
+molecular_hierarchy_get_residue(MolecularHierarchyDecorator mhd,
+ unsigned int index)
{
IMP_check(mhd.get_type() == MolecularHierarchyDecorator::PROTEIN
|| mhd.get_type() == MolecularHierarchyDecorator::CHAIN
@@ -154,5 +156,4 @@
return fd;
}
-
} // namespace IMP
Index: kernel/src/decorators/yaml.cpp
===================================================================
--- kernel/src/decorators/yaml.cpp (revision 0)
+++ kernel/src/decorators/yaml.cpp (revision 0)
@@ -0,0 +1,273 @@
+#include <IMP/decorators/yaml.h>
+
+namespace IMP
+{
+
+ namespace {
+ struct DefaultWrite {
+ template <class T>
+ std::ostream & operator()(const T t,
+ std::ostream &out) const {
+ return out << t;
+ }
+ };
+ struct ParticleWrite {
+ std::ostream & operator()(Particle *p,
+ std::ostream &out) const {
+ return out << p->get_index();
+ }
+ };
+ struct FloatWrite {
+ std::ostream & operator()(Float t,
+ std::ostream &out) const {
+ // set format better
+ return out << t;
+ }
+ };
+
+ template <class It, class Write>
+ void write_attributes(std::string indent,
+ Particle *p,
+ It b, It e, Write w,
+ std::ostream &out) {
+ for (It c= b; c != e; ++c) {
+ /** \todo should escape things properly */
+ out << indent << c->get_string() << ": ";
+ w(p->get_value(*c), out) << "\n";
+ }
+ }
+
+ // skips empty lines
+ struct LineStream{
+ std::istream ∈
+ std::vector<std::string> line;
+ bool has_indent(std::string str, unsigned int indent) {
+ for (unsigned int i=0; i< indent; ++i) {
+ if (i== str.size()) return false;
+ if (str[i] != ' ') return false;
+ }
+ return true;
+ }
+ bool not_white(char buf[]) const {
+ for (int i=0; buf[i] != '\0'; ++i) {
+ if (buf[i] != ' ') return true;
+ }
+ return false;
+ }
+
+ LineStream(std::istream &init): in(init){}
+ operator bool() const {return !line.empty() || static_cast<bool>(in);}
+ std::string get_line(unsigned int min_indent) {
+ while (line.empty()) {
+ char buf[3000];
+ in.getline(buf, 3000);
+ if (!in) return std::string();
+ if (buf[0] == '#') continue;
+ if (not_white(buf)) {
+ line.push_back(buf);
+ }
+ }
+ if (has_indent(line.back(), min_indent)) {
+ std::string ret(line.back(), min_indent);
+ line.pop_back();
+ return ret;
+ } else {
+ IMP_LOG(VERBOSE, "Line \"" << line.back() << "\" lacks "
+ << min_indent << " spaces" << std::endl);
+ return std::string();
+ }
+ }
+ void push_line(std::string s) {
+ if (s.empty()) return;
+ for (unsigned int i=0; i< s.size(); ++i) {
+ if (s[i] != ' ') {
+ line.push_back(s);
+ return;
+ }
+ }
+ }
+ };
+
+ template <class K, class V>
+ struct DefaultRead {
+ void operator()(Particle *p, std::string key, std::string value) const {
+ IMP_LOG(VERBOSE,
+ "Reading values from pair " << key << " "
+ << value << std::endl);
+ K k(key.c_str());
+ std::istringstream iss(value.c_str());
+ V v;
+ iss >> v;
+ IMP_check(iss, "Error reading value. Got " << v , ValueException);
+ p->set_value(k, v);
+ }
+ };
+
+ struct ParticleRead {
+ void operator()(Particle *p, std::string key, std::string value) const {
+ IMP_LOG(VERBOSE,
+ "Reading values from pair " << key << " "
+ << value << std::endl);
+ ParticleKey k(key.c_str());
+ std::istringstream iss(value.c_str());
+ int i;
+ iss >> i;
+ IMP_check(iss, "Error reading value" , ValueException);
+ Particle *op= p->get_model()->get_particle(ParticleIndex(i));
+ p->set_value(k, op);
+ }
+ };
+
+ int get_next_indent(LineStream &in) {
+ std::string buf= in.get_line(0);
+ if (buf.empty()) return 0;
+ unsigned int i=0;
+ for (; i < buf.size() && buf[i] == ' '; ++i) {
+ }
+ in.push_line(buf);
+ return i;
+ }
+
+
+ template <class Read>
+ void read_attributes(Particle *p, LineStream &in,
+ int indent,
+ Read read) {
+ IMP_LOG(VERBOSE, "Reading attributes " << indent << std::endl);
+ int nindent= get_next_indent(in);
+ if (nindent <= indent) return;
+ indent=nindent;
+ IMP_LOG(VERBOSE, "Required indent is " << indent<< std::endl);
+ do {
+ std::string buf = in.get_line(indent);
+ if (buf.empty()) {
+ IMP_LOG(VERBOSE, "Done reading attributes" << std::endl);
+ return;
+ }
+ IMP_check(buf[0] != ' ', "Extra white space on line "
+ << buf, InvalidStateException);
+ std::istringstream iss(buf.c_str());
+ char key[2000];
+ iss.get(key, 2000, ':');
+ IMP_check(iss, "no : found in line " << buf,
+ ValueException);
+ char colon;
+ iss >> colon;
+ IMP_check(colon == ':', "No colon found" << buf,
+ ValueException);
+
+ char value[2000];
+ iss.getline(value, 2000);
+ read(p, key, value);
+
+ } while (true);
+ }
+
+
+ void read_yaml(Model *m,
+ LineStream &in,
+ unsigned int indent) {
+ std::string buf=in.get_line(indent);
+ if (buf.empty()) return;
+ //IMP_LOG(VERBOSE, "Got line " << buf << std::endl);
+ //IMP_check(in, "Error reading particle line from yaml", ValueException);
+ int id;
+ int nread=sscanf(buf.c_str(), "particle: %d", &id);
+ IMP_check(nread==1, "Couldn't read id", InvalidStateException);
+ Particle *p= m->get_particle(id);
+ IMP_LOG(VERBOSE, "Reading particle " << id << std::endl);
+ unsigned int nindent= get_next_indent(in);
+ if (nindent <= indent) return;
+ indent=nindent;
+ while (in) {
+ std::string buf=in.get_line(indent);
+ if (buf.empty()) break;
+ IMP_check(buf[0] != ' ', "Indent error" << buf, InvalidStateException);
+
+ IMP_LOG(VERBOSE, "Looking for attributes in line " << buf << std::endl);
+ std::istringstream iss(buf);
+ std::string type;
+ iss >> type;
+ if (type.compare("float-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<FloatKey, Float>());
+ } else if (type.compare("int-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<IntKey, Int>());
+ } else if (type.compare("string-attributes:")==0) {
+ read_attributes(p, in, indent, DefaultRead<StringKey, String>());
+ } else if (type.compare("particle-attributes:")==0) {
+ read_attributes(p, in, indent, ParticleRead());
+ } else {
+ break;
+ }
+ }
+ IMP_LOG(VERBOSE, "Done reading particle " << id << std::endl);
+ }
+
+
+ }
+
+ static std::string indent_level=" ";
+
+ void write_yaml(Particle *p,
+ std::ostream &out,
+ std::string indent) {
+ out << indent << "particle: " << p->get_index().get_index() << "\n";
+ out << indent << indent_level << "float-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->float_keys_begin(),
+ p->float_keys_end(),
+ FloatWrite(),
+ out);
+ out << indent << indent_level << "int-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->int_keys_begin(),
+ p->int_keys_end(),
+ DefaultWrite(),
+ out);
+ out << indent << indent_level << "string-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->string_keys_begin(),
+ p->string_keys_end(),
+ DefaultWrite(),
+ out);
+ out << indent << indent_level << "particle-attributes:\n";
+ write_attributes(indent+indent_level+" ",
+ p,
+ p->particle_keys_begin(),
+ p->particle_keys_end(),
+ ParticleWrite(),
+ out);
+ }
+
+ void write_yaml(Model *m,
+ std::ostream &out,
+ std::string indent) {
+ for (Model::ParticleIterator pit= m->particles_begin();
+ pit != m->particles_end(); ++pit) {
+ write_yaml(*pit, out, indent);
+ }
+ }
+
+ void read_yaml(std::istream &in,
+ Model *m) {
+ LineStream r(in);
+ unsigned int nread=0;
+ do {
+ read_yaml(m, r, get_next_indent(r));
+ ++nread;
+ } while (r);
+ IMP_check(nread== m->get_number_of_particles(),
+ "Read wrong number of particles. Model is corrupted. Bye.",
+ ErrorException);
+ }
+
+ void read_yaml(std::string contents,
+ Model *m) {
+ std::istringstream iss(contents.c_str());
+ IMP_LOG(VERBOSE, "Got string:\n" << contents << std::endl);
+ read_yaml(iss, m);
+ }
+}
Index: kernel/src/decorators/HierarchyDecorator.cpp
===================================================================
--- kernel/src/decorators/HierarchyDecorator.cpp (revision 623)
+++ kernel/src/decorators/HierarchyDecorator.cpp (working copy)
@@ -128,4 +128,70 @@
}
+
+namespace
+{
+
+struct MHDMatchingLeaves
+{
+ bool operator()(Particle *p) const {
+ HierarchyDecorator mhd(p);
+ return mhd.get_number_of_children()==0;
+ }
+};
+
+} // namespace
+
+
+Particles
+hierarchy_get_leaves(HierarchyDecorator mhd) {
+ Particles out;
+ hierarchy_gather(mhd, MHDMatchingLeaves(),
+ std::back_inserter(out));
+ return out;
+}
+
+BondDecorators hierarchy_get_internal_bonds(HierarchyDecorator mhd) {
+ Particles ps= hierarchy_get_all_descendants(mhd);
+ std::set<Particle*> sps(ps.begin(), ps.end());
+ BondDecorators ret;
+ for (unsigned int i=0; i< ps.size(); ++i) {
+ if (IMP::BondedDecorator::is_instance_of(ps[i])){
+ IMP::BondedDecorator b(ps[i]);
+ for (unsigned int i=0; i< b.get_number_of_bonds(); ++i) {
+ Particle *op= b.get_bonded(i).get_particle();
+ if (op < ps[i]
+ && sps.find(op) != sps.end()) {
+ ret.push_back(b.get_bond(i));
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+
+namespace
+{
+
+struct MHDMatchingAll
+{
+ bool operator()(Particle *) const {
+ return true;
+ }
+};
+
+}
+
+Particles
+hierarchy_get_all_descendants(HierarchyDecorator mhd) {
+ Particles out;
+ hierarchy_gather(mhd, MHDMatchingAll(),
+ std::back_inserter(out));
+ return out;
+}
+
+
+
+
} // namespace IMP
Index: kernel/src/restraints/BondDecoratorRestraint.cpp
===================================================================
--- kernel/src/restraints/BondDecoratorRestraint.cpp (revision 623)
+++ kernel/src/restraints/BondDecoratorRestraint.cpp (working copy)
@@ -20,14 +20,15 @@
BondDecoratorRestraint
::BondDecoratorRestraint(UnaryFunction *f,
- BondDecoratorListScoreState *s): bl_(s),
- f_(f){}
+ ManualBondDecoratorListScoreState *s): bl_(s),
+ f_(f){}
Float BondDecoratorRestraint::evaluate(DerivativeAccumulator *accum)
{
Float sum=0;
- for (BondDecoratorListScoreState::BondIterator bi= bl_->bonds_begin();
- bi != bl_->bonds_end(); ++bi) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator bi
+ = bl_->bond_decorators_begin();
+ bi != bl_->bond_decorators_end(); ++bi) {
BondDecorator bd= *bi;
Float l= bd.get_length();
Float s= bd.get_stiffness();
@@ -64,7 +65,7 @@
{
out << "Bond decorator restraint with unary function ";
f_->show(out);
- out << " on " << bl_->get_number_of_bonds() << " bonds";
+ out << " on " << bl_->get_number_of_bond_decorators() << " bonds";
out << std::endl;
}
Index: kernel/src/score_states/CoverBondsScoreState.cpp
===================================================================
--- kernel/src/score_states/CoverBondsScoreState.cpp (revision 623)
+++ kernel/src/score_states/CoverBondsScoreState.cpp (working copy)
@@ -14,8 +14,9 @@
{
-CoverBondsScoreState::CoverBondsScoreState(BondDecoratorListScoreState *bl,
- FloatKey rk): bl_(bl), rk_(rk)
+CoverBondsScoreState
+::CoverBondsScoreState(ManualBondDecoratorListScoreState *bl,
+ FloatKey rk): bl_(bl), rk_(rk)
{
}
@@ -25,8 +26,9 @@
void CoverBondsScoreState::do_before_evaluate()
{
- for (BondDecoratorListScoreState::BondIterator it= bl_->bonds_begin();
- it != bl_->bonds_end(); ++it) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator it
+ = bl_->bond_decorators_begin();
+ it != bl_->bond_decorators_end(); ++it) {
BondDecorator bd= *it;
BondedDecorator pa= bd.get_bonded(0);
BondedDecorator pb= bd.get_bonded(1);
@@ -62,8 +64,9 @@
void CoverBondsScoreState::after_evaluate(DerivativeAccumulator *dva)
{
if (dva) {
- for (BondDecoratorListScoreState::BondIterator it= bl_->bonds_begin();
- it != bl_->bonds_end(); ++it) {
+ for (BondDecoratorListScoreState::BondDecoratorIterator it
+ = bl_->bond_decorators_begin();
+ it != bl_->bond_decorators_end(); ++it) {
XYZDecorator d(it->get_particle());
Vector3D deriv;
// divide derivatives equally between endpoints
@@ -84,7 +87,7 @@
void CoverBondsScoreState::show(std::ostream &out) const
{
- out << "CoverBondsScoreState on " << bl_->get_number_of_bonds()
+ out << "CoverBondsScoreState on " << bl_->get_number_of_bond_decorators()
<< " bonds " << std::endl;
}
Index: kernel/src/score_states/AllNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/AllNonbondedListScoreState.cpp (revision 623)
+++ kernel/src/score_states/AllNonbondedListScoreState.cpp (working copy)
@@ -18,7 +18,7 @@
{
-//! Turn the default into an actual algorithm and work around missing algorithms
+// Turn the default into an actual algorithm and work around missing algorithms
static AllNonbondedListScoreState::Algorithm
translate_algorithm(AllNonbondedListScoreState::Algorithm a)
{
Index: kernel/src/score_states/BondDecoratorListScoreState.cpp
===================================================================
--- kernel/src/score_states/BondDecoratorListScoreState.cpp (revision 623)
+++ kernel/src/score_states/BondDecoratorListScoreState.cpp (working copy)
@@ -21,7 +21,7 @@
{
IMP_LOG(TERSE, "Updating BondDecoratorList for "
<< ps_.size() << " particles" << std::endl);
- bonds_.clear();
+ std::vector<BondDecorator> bonds;
for (unsigned int i=0; i< ps_.size(); ++i) {
if (!ps_[i]->get_is_active()) continue;
BondedDecorator di(ps_[i]);
@@ -36,31 +36,26 @@
}
if (di < dj) {
IMP_LOG(VERBOSE, "Found bond " << di.get_bond(j) << std::endl);
- bonds_.push_back(di.get_bond(j));
+ bonds.push_back(di.get_bond(j));
}
}
}
- IMP_LOG(TERSE, "Found " << bonds_.size() << " bonds"<< std::endl);
+ ManualBondDecoratorListScoreState::set_bond_decorators(bonds);
+ IMP_LOG(TERSE, "Found " << bonds.size() << " bonds"<< std::endl);
}
void BondDecoratorListScoreState::set_particles(const Particles &ps)
{
ps_=ps;
std::sort(ps_.begin(), ps_.end());
- bonds_.clear();
+ clear_bond_decorators();
}
-
-bool BondDecoratorListScoreState::are_bonded(Particle *a, Particle *b) const
+void BondDecoratorListScoreState::add_particles(const Particles &ps)
{
- try {
- BondedDecorator da= BondedDecorator::cast(a);
- BondedDecorator db= BondedDecorator::cast(b);
- return get_bond(da, db) != BondDecorator();
- } catch (...) {
- IMP_LOG(VERBOSE, "Exception thrown in are_bonded"<< std::endl);
- }
- return false;
+ ps_.insert(ps_.end(), ps.begin(), ps.end());
+ std::sort(ps_.begin(), ps_.end());
+ clear_bond_decorators();
}
} // namespace IMP
Index: kernel/src/score_states/ManualBondDecoratorListScoreState.cpp
===================================================================
--- kernel/src/score_states/ManualBondDecoratorListScoreState.cpp (revision 0)
+++ kernel/src/score_states/ManualBondDecoratorListScoreState.cpp (revision 0)
@@ -0,0 +1,41 @@
+#include "IMP/score_states/ManualBondDecoratorListScoreState.h"
+
+namespace IMP
+{
+ ManualBondDecoratorListScoreState
+ ::ManualBondDecoratorListScoreState(const BondDecorators &ps) {
+ set_bond_decorators(ps);
+ }
+
+ IMP_LIST_IMPL(ManualBondDecoratorListScoreState, BondDecorator,
+ bond_decorator, BondDecorator,
+ ,);
+
+ bool ManualBondDecoratorListScoreState::are_bonded(Particle *a,
+ Particle *b) const
+ {
+ if (BondedDecorator::is_instance_of(a)
+ && BondedDecorator::is_instance_of(b)) {
+ BondedDecorator da(a);
+ BondedDecorator db(b);
+ return get_bond(da, db) != BondDecorator();
+ } else if (BondDecorator::is_instance_of(a)
+ && BondDecorator::is_instance_of(b)){
+ // check if they are bonds which share an endpoint
+ /**
+ \todo Decide if the check for adject bonds should go elsewhere
+ */
+ BondDecorator da(a);
+ BondDecorator db(b);
+ Particle *a0= da.get_bonded(0).get_particle();
+ Particle *a1= da.get_bonded(1).get_particle();
+ Particle *b0= db.get_bonded(0).get_particle();
+ Particle *b1= db.get_bonded(1).get_particle();
+
+ return (a0== b0 || a0 == b1 || a1== b0 || a1 == b1);
+ } else {
+ return false;
+ }
+ }
+
+}
Index: kernel/src/score_states/BipartiteNonbondedListScoreState.cpp
===================================================================
--- kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (revision 623)
+++ kernel/src/score_states/BipartiteNonbondedListScoreState.cpp (working copy)
@@ -15,8 +15,10 @@
namespace IMP
{
-//! Turn the default into an actual algorithm and work around missing algorithms
-/** This cannot be shared with AllNBL because that one has grid and this does
+
+
+// Turn the default into an actual algorithm and work around missing algorithms
+/* This cannot be shared with AllNBL because that one has grid and this does
not.
*/
static BipartiteNonbondedListScoreState::Algorithm
Index: kernel/src/optimizers/states/VRMLLogOptimizerState.cpp
===================================================================
--- kernel/src/optimizers/states/VRMLLogOptimizerState.cpp (revision 623)
+++ kernel/src/optimizers/states/VRMLLogOptimizerState.cpp (working copy)
@@ -17,9 +17,10 @@
VRMLLogOptimizerState::VRMLLogOptimizerState(std::string filename,
const Particles &pis) :
- pis_(pis), filename_(filename), file_number_(0), call_number_(0),
+ filename_(filename), file_number_(0), call_number_(0),
skip_steps_(0)
{
+ set_particles(pis);
}
void VRMLLogOptimizerState::update()
@@ -44,13 +45,17 @@
if (!out) {
IMP_WARN("Error opening VRML log file " << buf);
} else {
- IMP_LOG(VERBOSE, "Writing " << pis_.size()
+ IMP_LOG(VERBOSE, "Writing " << get_number_of_particles()
<< " particles to file " << buf << "..." << std::flush);
- write(pis_, radius_, r_, g_, b_, out);
+ write(out, get_particles());
//IMP_LOG(TERSE, "done" << std::endl);
}
}
+IMP_LIST_IMPL(VRMLLogOptimizerState, Particle, particle, Particle*, ,);
+IMP_CONTAINER_IMPL(VRMLLogOptimizerState, ParticleRefiner, particle_refiner,
+ ParticleRefinerIndex ,,,);
+
static Float snap(Float f)
{
if (f < 0) return 0;
@@ -58,32 +63,50 @@
return f;
}
-void VRMLLogOptimizerState::write(const Particles &pis, FloatKey rk,
- FloatKey r, FloatKey g, FloatKey b,
- std::ostream &out)
+void VRMLLogOptimizerState::set_color(int c, Vector3D v) {
+ colors_[c]= Vector3D(snap(v[0]),
+ snap(v[1]),
+ snap(v[2]));
+}
+
+void VRMLLogOptimizerState::write(std::ostream &out, const Particles &ps) const
{
out << "#VRML V2.0 utf8\n";
out << "Group {\n";
out << "children [\n";
- for (unsigned int i = 0; i < pis.size(); ++i) {
+ for (Particles::const_iterator it = ps.begin(); it != ps.end(); ++it) {
+ Particle *p = *it;
+ bool wasrefined=false;
+ for (ParticleRefinerConstIterator prit= particle_refiners_begin();
+ prit != particle_refiners_end(); ++prit) {
+ if ((*prit)->get_can_refine(p)) {
+ Particles refined= (*prit)->get_refined(p);
+ write(out, refined);
+ (*prit)->cleanup_refined(p, refined, NULL);
+ wasrefined=true;
+ break;
+ }
+ }
+ if (wasrefined) continue;
try {
- Particle *p = pis[i];
XYZDecorator xyz = XYZDecorator::cast(p);
float x = xyz.get_x();
float y = xyz.get_y();
float z = xyz.get_z();
Float rv = -1, gv = -1, bv = -1;
- if (r != FloatKey() && b != FloatKey() && g != FloatKey()
- && p->has_attribute(r) && p->has_attribute(g)
- && p->has_attribute(b)) {
- rv = snap(p->get_value(r));
- gv = snap(p->get_value(g));
- bv = snap(p->get_value(b));
+ if (color_ != IntKey()
+ && p->has_attribute(color_)) {
+ int cv = p->get_value(color_);
+ if (colors_.find(cv) != colors_.end()) {
+ rv= colors_.find(cv)->second[0];
+ gv= colors_.find(cv)->second[1];
+ bv= colors_.find(cv)->second[2];
+ }
}
Float radius = .1;
- if (rk != FloatKey() && p->has_attribute(rk)) {
- radius = p->get_value(rk);
+ if (radius_ != FloatKey() && p->has_attribute(radius_)) {
+ radius = p->get_value(radius_);
//oss << ".sphere " << x << " " << y << " " << z << " " << r << "\n";
}
@@ -111,7 +134,7 @@
out << "}\n";
} catch (InvalidStateException &e) {
- IMP_WARN("Particle " << pis[i] << " does not have "
+ IMP_WARN("Particle " << p << " does not have "
<< " cartesian coordinates");
}
}
Index: kernel/pyext/IMP/test.py
===================================================================
--- kernel/pyext/IMP/test.py (revision 623)
+++ kernel/pyext/IMP/test.py (working copy)
@@ -3,6 +3,40 @@
import IMP
+def create_particles_in_box( 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 randomize_particles(particles, deviation):
+ """Randomize the xyz coordinates of a list of particles"""
+ for p in particles:
+ d= IMP.XYZDecorator.cast(p)
+ d.set_x(random.uniform(-deviation, deviation))
+ d.set_y(random.uniform(-deviation, deviation))
+ d.set_z(random.uniform(-deviation, deviation))
+
+def create_chain(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 TestCase(unittest.TestCase):
"""Super class for IMP test cases"""
@@ -33,14 +67,6 @@
p.add_attribute(IMP.FloatKey("z"), z, True)
return p
- def randomize_particles(self, particles, deviation):
- """Randomize the xyz coordinates of a list of particles"""
- for p in particles:
- d= IMP.XYZDecorator.cast(p)
- d.set_x(random.uniform(-deviation, deviation))
- d.set_y(random.uniform(-deviation, deviation))
- d.set_z(random.uniform(-deviation, deviation))
-
def particle_distance(self, p1, p2):
"""Return distance between two given particles"""
xkey = IMP.FloatKey("x")
@@ -73,30 +99,7 @@
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):
Index: kernel/include/IMP.h
===================================================================
--- kernel/include/IMP.h (revision 623)
+++ kernel/include/IMP.h (working copy)
@@ -1,94 +1,114 @@
/**
- * \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/Object.h"
-#include "IMP/RefCountedObject.h"
-#include "IMP/Pointer.h"
-#include "IMP/UnaryFunction.h"
-#include "IMP/unary_functions/Harmonic.h"
-#include "IMP/unary_functions/HarmonicLowerBound.h"
-#include "IMP/unary_functions/HarmonicUpperBound.h"
-#include "IMP/unary_functions/OpenCubicSpline.h"
-#include "IMP/unary_functions/ClosedCubicSpline.h"
-#include "IMP/unary_functions/Cosine.h"
-#include "IMP/unary_functions/Linear.h"
-#include "IMP/unary_functions/WormLikeChain.h"
-#include "IMP/Model.h"
-#include "IMP/PairScore.h"
-#include "IMP/SingletonScore.h"
-#include "IMP/TripletScore.h"
-#include "IMP/Vector3D.h"
-#include "IMP/VersionInfo.h"
-#include "IMP/ParticleRefiner.h"
-#include "IMP/particle_refiners/BondCoverParticleRefiner.h"
-#include "IMP/particle_refiners/ChildrenParticleRefiner.h"
-#include "IMP/decorators/HierarchyDecorator.h"
-#include "IMP/decorators/MolecularHierarchyDecorator.h"
-#include "IMP/decorators/NameDecorator.h"
-#include "IMP/decorators/AtomDecorator.h"
-#include "IMP/decorators/ResidueDecorator.h"
-#include "IMP/decorators/XYZDecorator.h"
-#include "IMP/decorators/bond_decorators.h"
-#include "IMP/optimizers/SteepestDescent.h"
-#include "IMP/optimizers/ConjugateGradients.h"
-#include "IMP/optimizers/MolecularDynamics.h"
-#include "IMP/optimizers/BrownianDynamics.h"
-#include "IMP/optimizers/MonteCarlo.h"
-#include "IMP/optimizers/Mover.h"
-#include "IMP/optimizers/MoverBase.h"
-#include "IMP/optimizers/movers/BallMover.h"
-#include "IMP/optimizers/movers/NormalMover.h"
-#include "IMP/optimizers/states/VRMLLogOptimizerState.h"
-#include "IMP/optimizers/states/CMMLogOptimizerState.h"
-#include "IMP/optimizers/states/VelocityScalingOptimizerState.h"
-#include "IMP/pair_scores/DistancePairScore.h"
-#include "IMP/pair_scores/SphereDistancePairScore.h"
-#include "IMP/pair_scores/RefineOncePairScore.h"
-#include "IMP/pair_scores/TypedPairScore.h"
-#include "IMP/pair_scores/TransformedDistancePairScore.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/restraints/TunnelRestraint.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 <IMP/base_types.h>
+#include <IMP/DecoratorBase.h>
+#include <IMP/DerivativeAccumulator.h>
+#include <IMP/exception.h>
+#include <IMP/IMP_config.h>
+#include <IMP/Index.h>
+#include <IMP/Key.h>
+#include <IMP/log.h>
+#include <IMP/macros.h>
+#include <IMP/Model.h>
+#include <IMP/Object.h>
+#include <IMP/Optimizer.h>
+#include <IMP/OptimizerState.h>
+#include <IMP/PairScore.h>
+#include <IMP/Particle.h>
+#include <IMP/ParticleRefiner.h>
+#include <IMP/Pointer.h>
+#include <IMP/random.h>
+#include <IMP/RefCountedObject.h>
+#include <IMP/Restraint.h>
+#include <IMP/ScoreState.h>
+#include <IMP/SingletonScore.h>
+#include <IMP/TripletScore.h>
+#include <IMP/UnaryFunction.h>
+#include <IMP/utility.h>
+#include <IMP/Vector3D.h>
+#include <IMP/VersionInfo.h>
+#include <IMP/decorators/AtomDecorator.h>
+#include <IMP/decorators/bond_decorators.h>
+#include <IMP/decorators/HierarchyDecorator.h>
+#include <IMP/decorators/macros.h>
+#include <IMP/decorators/MolecularHierarchyDecorator.h>
+#include <IMP/decorators/NameDecorator.h>
+#include <IMP/decorators/ResidueDecorator.h>
+#include <IMP/decorators/utility.h>
+#include <IMP/decorators/XYZDecorator.h>
+#include <IMP/decorators/yaml.h>
+#include <IMP/internal/ArrayOnAttributesHelper.h>
+#include <IMP/internal/AttributeTable.h>
+#include <IMP/internal/bbox_nbl_helpers.h>
+#include <IMP/internal/constants.h>
+#include <IMP/internal/evaluate_distance_pair_score.h>
+#include <IMP/internal/ExponentialNumber.h>
+#include <IMP/internal/graph_base.h>
+#include <IMP/internal/Grid3D.h>
+#include <IMP/internal/kernel_version_info.h>
+#include <IMP/internal/ObjectContainer.h>
+#include <IMP/internal/ParticleGrid.h>
+#include <IMP/internal/ref_counting.h>
+#include <IMP/internal/Unit.h>
+#include <IMP/internal/units.h>
+#include <IMP/internal/utility.h>
+#include <IMP/internal/Vector.h>
+#include <IMP/optimizers/BrownianDynamics.h>
+#include <IMP/optimizers/ConjugateGradients.h>
+#include <IMP/optimizers/MolecularDynamics.h>
+#include <IMP/optimizers/MonteCarlo.h>
+#include <IMP/optimizers/MoverBase.h>
+#include <IMP/optimizers/Mover.h>
+#include <IMP/optimizers/SteepestDescent.h>
+#include <IMP/pair_scores/DistancePairScore.h>
+#include <IMP/pair_scores/RefineOncePairScore.h>
+#include <IMP/pair_scores/SphereDistancePairScore.h>
+#include <IMP/pair_scores/TransformedDistancePairScore.h>
+#include <IMP/pair_scores/TypedPairScore.h>
+#include <IMP/particle_refiners/BondCoverParticleRefiner.h>
+#include <IMP/particle_refiners/ChildrenParticleRefiner.h>
+#include <IMP/restraints/AngleRestraint.h>
+#include <IMP/restraints/BondDecoratorRestraint.h>
+#include <IMP/restraints/ConnectivityRestraint.h>
+#include <IMP/restraints/ConstantRestraint.h>
+#include <IMP/restraints/DihedralRestraint.h>
+#include <IMP/restraints/DistanceRestraint.h>
+#include <IMP/restraints/NonbondedRestraint.h>
+#include <IMP/restraints/PairChainRestraint.h>
+#include <IMP/restraints/PairListRestraint.h>
+#include <IMP/restraints/RestraintSet.h>
+#include <IMP/restraints/SingletonListRestraint.h>
+#include <IMP/restraints/TripletChainRestraint.h>
+#include <IMP/restraints/TunnelRestraint.h>
+#include <IMP/score_states/AllNonbondedListScoreState.h>
+#include <IMP/score_states/BipartiteNonbondedListScoreState.h>
+#include <IMP/score_states/BondDecoratorListScoreState.h>
+#include <IMP/score_states/BondedListScoreState.h>
+#include <IMP/score_states/CoverBondsScoreState.h>
+#include <IMP/score_states/GravityCenterScoreState.h>
+#include <IMP/score_states/ManualBondDecoratorListScoreState.h>
+#include <IMP/score_states/MaxChangeScoreState.h>
+#include <IMP/score_states/NonbondedListScoreState.h>
+#include <IMP/singleton_scores/AttributeSingletonScore.h>
+#include <IMP/singleton_scores/DistanceToSingletonScore.h>
+#include <IMP/triplet_scores/AngleTripletScore.h>
+#include <IMP/unary_functions/ClosedCubicSpline.h>
+#include <IMP/unary_functions/Cosine.h>
+#include <IMP/unary_functions/Harmonic.h>
+#include <IMP/unary_functions/HarmonicLowerBound.h>
+#include <IMP/unary_functions/HarmonicUpperBound.h>
+#include <IMP/unary_functions/Linear.h>
+#include <IMP/unary_functions/OpenCubicSpline.h>
+#include <IMP/unary_functions/WormLikeChain.h>
+#include <IMP/optimizers/movers/BallMover.h>
+#include <IMP/optimizers/movers/NormalMover.h>
+#include <IMP/optimizers/states/CMMLogOptimizerState.h>
+#include <IMP/optimizers/states/VelocityScalingOptimizerState.h>
+#include <IMP/optimizers/states/VRMLLogOptimizerState.h>
#endif /* __IMP_H */
Index: kernel/include/IMP/internal/ref_counting.h
===================================================================
--- kernel/include/IMP/internal/ref_counting.h (revision 623)
+++ kernel/include/IMP/internal/ref_counting.h (working copy)
@@ -27,7 +27,6 @@
template <class O>
static void eval(O* o) {
BOOST_STATIC_ASSERT((!boost::is_base_of<RefCountedObject, O >::value));
- IMP_LOG(VERBOSE, "Not refing particle " << o << std::endl);
}
};
@@ -36,8 +35,6 @@
{
template <class O>
static void eval(O* o) {
- IMP_LOG(VERBOSE, "Refing particle " << o->get_index()
- << o->get_ref_count() << std::endl);
o->assert_is_valid();
o->ref();
}
@@ -49,7 +46,6 @@
template <class O>
static void eval(O* o) {
BOOST_STATIC_ASSERT((!boost::is_base_of<RefCountedObject, O >::value));
- IMP_LOG(VERBOSE, "Not Unrefing object " << o << std::endl);
}
};
@@ -58,8 +54,6 @@
{
template <class O>
static void eval(O *o) {
- IMP_LOG(VERBOSE, "Unrefing particle " << o->get_index()
- << " " << o->get_ref_count() << std::endl);
o->assert_is_valid();
o->unref();
if (!o->get_has_ref()) {
@@ -104,9 +98,6 @@
template <class O>
void disown(O* o)
{
- /*IMP_LOG(VERBOSE, "Disown called with "
- << (boost::is_base_of<RefCountedObject, O >::value)
- << " for " << o << " " << o->get_ref_count() << std::endl);*/
o->unref();
if (!o->get_has_ref()) {
delete o;
@@ -118,10 +109,6 @@
template <class O>
void own(O* o)
{
- /*IMP_LOG(VERBOSE, "Own called with "
- << (boost::is_base_of<RefCountedObject, O >::value)
- << " for " << o
- << " " << o->get_ref_count() << std::endl);*/
if (boost::is_base_of<RefCountedObject, O >::value) {
// no checks
} else {
@@ -133,6 +120,9 @@
}
+
+
+
} // namespace internal
} // namespace IMP
Index: kernel/include/IMP/internal/units.h
===================================================================
--- kernel/include/IMP/internal/units.h (revision 623)
+++ kernel/include/IMP/internal/units.h (working copy)
@@ -119,6 +119,12 @@
typedef Multiply<Multiply<Centimeter, Centimeter>::type,
Centimeter>::type CubicCentimeter;
typedef Divide<Gram, CubicCentimeter>::type GramPerCubicCentimeter;
+typedef Shift<Second, -9>::type Nanosecond;
+typedef Shift<Meter, -9>::type Nanometer;
+typedef Multiply<Multiply<Nanometer, Nanometer>::type,
+ Nanometer>::type CubicNanometer;
+typedef Shift<Second, -15>::type Femtosecond;
+typedef Divide<Piconewton, Nanometer>::type PiconewtonPerNanometer;
Index: kernel/include/IMP/internal/Grid3D.h
===================================================================
--- kernel/include/IMP/internal/Grid3D.h (revision 623)
+++ kernel/include/IMP/internal/Grid3D.h (working copy)
@@ -139,6 +139,16 @@
}
};
+
+
+
+
+
+
+
+
+
+
//! Represent a real cell in a grid
/** These indexes represent an actual cell in the grid with no mapping.
They can only be constructed by the grid.
@@ -160,6 +170,16 @@
}
};
+
+
+
+
+
+
+
+
+
+
/** \brief A voxel grid in 3D space.
VT can be any class.
\internal
@@ -340,12 +360,12 @@
}
//! Get the data in a particular cell
- VoxelData& get_voxel(Index gi) {
+ typename std::vector<VT>::reference get_voxel(Index gi) {
return data_[index(gi)];
}
//! Get the data in a particular cell
- const VoxelData& get_voxel(Index gi) const {
+ typename std::vector<VT>::const_reference get_voxel(Index gi) const {
return data_[index(gi)];
}
Index: kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h
===================================================================
--- kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (revision 623)
+++ kernel/include/IMP/particle_refiners/BondCoverParticleRefiner.h (working copy)
@@ -8,12 +8,14 @@
#ifndef __IMP_BOND_COVER_PARTICLE_REFINER_H
#define __IMP_BOND_COVER_PARTICLE_REFINER_H
+#include "../ParticleRefiner.h"
#include "../internal/kernel_version_info.h"
-#include "../ParticleRefiner.h"
namespace IMP
{
+class Particle;
+
//! 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
@@ -23,9 +25,11 @@
{
FloatKey rk_;
FloatKey vk_;
+ IntKey tk_;
public:
BondCoverParticleRefiner(FloatKey rk,
- FloatKey vk);
+ FloatKey vk,
+ IntKey tk=IntKey());
virtual ~BondCoverParticleRefiner() {}
Index: kernel/include/IMP/decorators/MolecularHierarchyDecorator.h
===================================================================
--- kernel/include/IMP/decorators/MolecularHierarchyDecorator.h (revision 623)
+++ kernel/include/IMP/decorators/MolecularHierarchyDecorator.h (working copy)
@@ -16,6 +16,7 @@
#include "../Model.h"
#include "utility.h"
#include "HierarchyDecorator.h"
+#include "bond_decorators.h"
namespace IMP
{
@@ -43,8 +44,8 @@
- TRAJECTORY is an ordered set of UNIVERSES
*/
enum Type {UNKNOWN=-1, ATOM, RESIDUE, NUCLEICACID, FRAGMENT,
- CHAIN, PROTEIN, NUCLEOTIDE, MOLECULE,
- UNIVERSE, UNIVERSES, TRAJECTORY
+ CHAIN, PROTEIN, NUCLEOTIDE, MOLECULE, ASSEMBLY,
+ COLLECTION, UNIVERSE, UNIVERSES, TRAJECTORY
};
Type get_type() const {
@@ -76,10 +77,16 @@
return "nucleotide";
case MOLECULE:
return "molecule";
+ case ASSEMBLY:
+ return "assembly";
+ case COLLECTION:
+ return "collection";
case UNIVERSE:
return "universe";
case UNIVERSES:
return "universes";
+ case TRAJECTORY:
+ return "trajectory";
default:
IMP_assert(0, "Invalid MolecularHierarchyDecorator type");
return std::string();
@@ -132,6 +139,12 @@
}
}
+
+ static IntKey get_type_key() {
+ decorator_initialize_static_data();
+ return type_key_;
+ }
+
};
typedef std::vector<MolecularHierarchyDecorator> MolecularHierarchyDecorators;
@@ -142,8 +155,9 @@
in the molecular hierarchy
\ingroup hierarchy
*/
-IMPDLLEXPORT Particles get_particles(MolecularHierarchyDecorator mhd,
- MolecularHierarchyDecorator::Type t);
+IMPDLLEXPORT Particles
+molecular_hierarchy_get_by_type(MolecularHierarchyDecorator mhd,
+ MolecularHierarchyDecorator::Type t);
class ResidueDecorator;
@@ -160,8 +174,8 @@
\ingroup hierarchy
*/
IMPDLLEXPORT ResidueDecorator
-get_residue(MolecularHierarchyDecorator mhd,
- unsigned int index);
+molecular_hierarchy_get_residue(MolecularHierarchyDecorator mhd,
+ unsigned int index);
//! Create a fragment containing the specified nodes
Index: kernel/include/IMP/decorators/bond_decorators.h
===================================================================
--- kernel/include/IMP/decorators/bond_decorators.h (revision 623)
+++ kernel/include/IMP/decorators/bond_decorators.h (working copy)
@@ -128,6 +128,8 @@
IMP_OUTPUT_OPERATOR(BondedDecorator);
+typedef std::vector<BondDecorator> BondDecorators;
+
inline BondedDecorator BondDecorator::get_bonded(unsigned int i) const
{
Particle *p= graph_get_node(get_particle(), i,
Index: kernel/include/IMP/decorators/yaml.h
===================================================================
--- kernel/include/IMP/decorators/yaml.h (revision 0)
+++ kernel/include/IMP/decorators/yaml.h (revision 0)
@@ -0,0 +1,49 @@
+#ifndef IMP_DECORATORS_YAML_H
+#define IMP_DECORATORS_YAML_H
+#include "../Particle.h"
+#include "../Model.h"
+
+namespace IMP
+{
+
+ //! Write the particle to a stream as a YAML stream
+ /** \param[in] p The particle to write
+ \param[in] out The stream to write to
+ \param[in] indent The base level of indentation
+ */
+ IMPDLLEXPORT void write_yaml(Particle *p,
+ std::ostream &out= std::cout,
+ std::string indent="");
+
+//! Write the model to a stream as a YAML stream
+ /** \param[in] m The model to write
+ \param[in] out The stream to write to
+ \param[in] indent The base level of indentation
+ */
+ IMPDLLEXPORT void write_yaml(Model *m,
+ std::ostream &out= std::cout,
+ std::string indent="");
+
+ //! Read the particle from a YAML stream
+ /** The model must already have particles matching all read particles.
+ Currently the particles must already have the same attributes
+ as are being read, but this probably should change due to lists
+ stored in attributes.
+
+ The intentended usage model is that the model (with restraints) is
+ initialized. Optimization is performed and then the model is written
+ out to a file. Some time later, when you want to reload the model,
+ you can reuse the initialization code to set up the restraints,
+ and then read in the values for the attributes.
+
+ \note The base indent is determined from the first line. */
+ IMPDLLEXPORT void read_yaml(std::istream &in,
+ Model *m);
+
+ //! primarily for debuggin*/
+ IMPDLLEXPORT void read_yaml(std::string contents,
+ Model *m);
+
+}
+
+#endif
Index: kernel/include/IMP/decorators/HierarchyDecorator.h
===================================================================
--- kernel/include/IMP/decorators/HierarchyDecorator.h (revision 623)
+++ kernel/include/IMP/decorators/HierarchyDecorator.h (working copy)
@@ -9,16 +9,17 @@
#ifndef __IMP_HIERARCHY_DECORATOR_H
#define __IMP_HIERARCHY_DECORATOR_H
-#include <limits>
-#include <vector>
-#include <deque>
-
#include "../Particle.h"
#include "../Model.h"
#include "../DecoratorBase.h"
#include "../internal/ArrayOnAttributesHelper.h"
#include "utility.h"
+#include "bond_decorators.h"
+#include <limits>
+#include <vector>
+#include <deque>
+
namespace IMP
{
@@ -326,6 +327,71 @@
}
+namespace internal
+{
+ template <class K, class V>
+ struct MatchAttribute {
+ K k_;
+ V v_;
+ MatchAttribute(K k, V v): k_(k), v_(v){}
+ bool operator()(Particle *o) {
+ if (!o->has_attribute(k_)) return false;
+ else return o->get_value(k_) == v_;
+ }
+ };
+}
+
+//! Gather all the Particle* in the hierarchy which match on an attribute
+/** \ingroup hierarchy
+ */
+template <class Out, class K, class V>
+Out hierarchy_gather_by_attribute(HierarchyDecorator h, K k,
+ V v, Out out)
+{
+ internal::Gather<internal::MatchAttribute<K, V>,Out>
+ gather(internal::MatchAttribute<K,V>(k,v),
+ out);
+ depth_first_traversal(h, gather);
+ return gather.get_out();
+}
+
+
+namespace internal
+{
+ template <class K0, class V0, class K1, class V1>
+ struct MatchAttributes {
+ K0 k0_;
+ V0 v0_;
+ K1 k1_;
+ V1 v1_;
+ MatchAttributes(K0 k0, V0 v0,
+ K1 k1, V1 v1): k0_(k0), v0_(v0),
+ k1_(k1), v1_(v1){}
+ bool operator()(Particle *o) {
+ if (!o->has_attribute(k0_)) return false;
+ else if (o->get_value(k0_) != v0_) return false;
+ else if (!o->has_attribute(k1_)) return false;
+ else if (o->get_value(k1_) != v1_) return false;
+ return true;
+ }
+ };
+}
+
+//! Gather all the Particle* in the hierarchy which match on two attributes
+/** \ingroup hierarchy
+ */
+template <class Out, class K0, class V0, class K1, class V1>
+Out hierarchy_gather_by_attributes(HierarchyDecorator h, K0 k0,
+ V0 v0, K1 k1, V1 v1, Out out)
+{
+ internal::Gather<internal::MatchAttributes<K0, V0, K1, V1>,Out>
+ gather(internal::MatchAttributes<K0,V0, K1, V1>(k0,v0, k1, v1),
+ out);
+ depth_first_traversal(h, gather);
+ return gather.get_out();
+}
+
+
//! Find the first node which matches some criteria
/** \ingroup hierarchy
*/
@@ -352,6 +418,21 @@
return HD();
}
+
+
+//! Get all the leaves of the bit of hierarchy
+IMPDLLEXPORT Particles
+hierarchy_get_leaves(HierarchyDecorator mhd);
+
+//! Get the bonds internal to this tree
+IMPDLLEXPORT BondDecorators
+hierarchy_get_internal_bonds(HierarchyDecorator mhd);
+
+//! Get all the particles in the subtree
+IMPDLLEXPORT Particles
+hierarchy_get_all_descendants(HierarchyDecorator mhd);
+
+
namespace internal
{
Index: kernel/include/IMP/restraints/PairListRestraint.h
===================================================================
--- kernel/include/IMP/restraints/PairListRestraint.h (revision 623)
+++ kernel/include/IMP/restraints/PairListRestraint.h (working copy)
@@ -39,6 +39,10 @@
void add_particle_pair(ParticlePair p);
void clear_particle_pairs();
void add_particle_pairs(const ParticlePairs &ps);
+ void set_particle_pairs(const ParticlePairs &ps) {
+ clear_particle_pairs();
+ add_particle_pairs(ps);
+ }
protected:
Pointer<PairScore> ss_;
Index: kernel/include/IMP/restraints/BondDecoratorRestraint.h
===================================================================
--- kernel/include/IMP/restraints/BondDecoratorRestraint.h (revision 623)
+++ kernel/include/IMP/restraints/BondDecoratorRestraint.h (working copy)
@@ -16,12 +16,11 @@
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
#include "../UnaryFunction.h"
+#include "../score_states/ManualBondDecoratorListScoreState.h"
namespace IMP
{
-class BondDecoratorListScoreState;
-
//! Restrain all pairs of non-bonded particles
/** This restraint currently only works for bonds which have their
length set explicitly. Eventually we should add a table for standard
@@ -40,7 +39,8 @@
\param[in] bl The BondDecoratorListScoreState to use to get the list
of bonds.
*/
- BondDecoratorRestraint(UnaryFunction *f, BondDecoratorListScoreState *bl);
+ BondDecoratorRestraint(UnaryFunction *f,
+ ManualBondDecoratorListScoreState *bl);
virtual ~BondDecoratorRestraint(){}
IMP_RESTRAINT(internal::kernel_version_info)
@@ -48,7 +48,7 @@
void set_function(UnaryFunction *f) {f_=f;}
protected:
- BondDecoratorListScoreState *bl_;
+ Pointer<ManualBondDecoratorListScoreState> bl_;
Pointer<UnaryFunction> f_;
};
Index: kernel/include/IMP/restraints/NonbondedRestraint.h
===================================================================
--- kernel/include/IMP/restraints/NonbondedRestraint.h (revision 623)
+++ kernel/include/IMP/restraints/NonbondedRestraint.h (working copy)
@@ -16,12 +16,11 @@
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
#include "../score_states/NonbondedListScoreState.h"
+#include "../PairScore.h"
namespace IMP
{
-class PairScore;
-
//! Apply a PairScore to all nonbonded pairs of particles
/**
\ingroup restraint
Index: kernel/include/IMP/score_states/CoverBondsScoreState.h
===================================================================
--- kernel/include/IMP/score_states/CoverBondsScoreState.h (revision 623)
+++ kernel/include/IMP/score_states/CoverBondsScoreState.h (working copy)
@@ -9,7 +9,7 @@
#define __IMP_COVER_BONDS_SCORE_STATE_H
#include "../ScoreState.h"
-#include "BondDecoratorListScoreState.h"
+#include "ManualBondDecoratorListScoreState.h"
#include "../internal/kernel_version_info.h"
#include "../Pointer.h"
@@ -30,13 +30,13 @@
*/
class IMPDLLEXPORT CoverBondsScoreState: public ScoreState
{
- Pointer<BondDecoratorListScoreState> bl_;
+ Pointer<ManualBondDecoratorListScoreState> bl_;
FloatKey rk_;
public:
/** Get the list of bonds from the BondDecoratorListScoreState. This list is
not owned and update is not called on this list automatically.
*/
- CoverBondsScoreState(BondDecoratorListScoreState *bl,
+ CoverBondsScoreState(ManualBondDecoratorListScoreState *bl,
FloatKey rk=FloatKey("radius"));
~CoverBondsScoreState();
Index: kernel/include/IMP/score_states/BondDecoratorListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/BondDecoratorListScoreState.h (revision 623)
+++ kernel/include/IMP/score_states/BondDecoratorListScoreState.h (working copy)
@@ -8,25 +8,21 @@
#ifndef __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
#define __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H
-#include "BondedListScoreState.h"
+#include "ManualBondDecoratorListScoreState.h"
#include "../decorators/bond_decorators.h"
#include <vector>
namespace IMP
{
-
-class BondDecoratorListScoreState;
-typedef Index<BondDecoratorListScoreState> BondDecoratorListIndex;
-
//! Keep track of particles that are connected by BondDecorator bonds.
/** We also may want to add lazy rescanning of bonds rather than doing
it every update call and a faster lookup of bonds.
\ingroup bond
*/
-class IMPDLLEXPORT BondDecoratorListScoreState: public BondedListScoreState
+class IMPDLLEXPORT BondDecoratorListScoreState:
+ public ManualBondDecoratorListScoreState
{
- std::vector<BondDecorator> bonds_;
Particles ps_;
public:
//! Find bonds amongst the following points.
@@ -36,24 +32,8 @@
virtual ~BondDecoratorListScoreState(){}
virtual void set_particles(const Particles &ps);
+ virtual void add_particles(const Particles &ps);
- virtual bool are_bonded(Particle *a, Particle *b) const;
-
- //! This iterates through the pairs of bonded particles
- /** \note update() must be called first for this to be valid.
- */
- typedef std::vector<BondDecorator>::const_iterator BondIterator;
- BondIterator bonds_begin() const {
- return bonds_.begin();
- }
- BondIterator bonds_end() const {
- return bonds_.end();
- }
-
- unsigned int get_number_of_bonds() const {
- return bonds_.size();
- }
-
protected:
virtual void do_before_evaluate();
};
Index: kernel/include/IMP/score_states/MaxChangeScoreState.h
===================================================================
--- kernel/include/IMP/score_states/MaxChangeScoreState.h (revision 623)
+++ kernel/include/IMP/score_states/MaxChangeScoreState.h (working copy)
@@ -22,6 +22,9 @@
float attribute keys and keeps track of the maximum amount
any of these have changed since the last time reset was called.
+ \todo Move the stored bits back into this class out of the
+ attributes.
+
*/
class IMPDLLEXPORT MaxChangeScoreState: public ScoreState
{
Index: kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h
===================================================================
--- kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h (revision 0)
+++ kernel/include/IMP/score_states/ManualBondDecoratorListScoreState.h (revision 0)
@@ -0,0 +1,50 @@
+/**
+ * \file BondDecoratorListScoreState.h
+ * \brief Allow iteration through pairs of a set of atoms.
+ *
+ * Copyright 2007-8 Sali Lab. All rights reserved.
+ */
+
+#ifndef __IMP_MANUAL_BOND_DECORATOR_LIST_SCORE_STATE_H
+#define __IMP_MANUAL_BOND_DECORATOR_LIST_SCORE_STATE_H
+
+#include "BondedListScoreState.h"
+#include "../decorators/bond_decorators.h"
+
+#include <vector>
+
+namespace IMP
+{
+
+class ManualBondDecoratorListScoreState;
+typedef Index<ManualBondDecoratorListScoreState> BondDecoratorListIndex;
+
+//! Keep track of particles that are connected by BondDecorator bonds.
+/** This class just keeps track of the bonds it has been told about.
+ Use the non-manual version if you want auto discovery of bonds.
+ \ingroup bond
+ */
+class IMPDLLEXPORT ManualBondDecoratorListScoreState:
+ public BondedListScoreState
+{
+ public:
+ //! Find bonds amongst the following points.
+ /** \param [in] ps The set of particles to use.
+ */
+ ManualBondDecoratorListScoreState(const BondDecorators &ps= BondDecorators());
+ virtual ~ManualBondDecoratorListScoreState(){}
+
+ virtual void set_particles(const Particles &ps) {}
+ virtual void add_particles(const Particles &ps) {}
+
+ IMP_LIST(public, BondDecorator, bond_decorator, BondDecorator);
+
+ virtual bool are_bonded(Particle *a, Particle *b) const;
+
+protected:
+ virtual void do_before_evaluate() {}
+};
+
+} // namespace IMP
+
+#endif /* __IMP_BOND_DECORATOR_LIST_SCORE_STATE_H */
Index: kernel/include/IMP/optimizers/states/VRMLLogOptimizerState.h
===================================================================
--- kernel/include/IMP/optimizers/states/VRMLLogOptimizerState.h (revision 623)
+++ kernel/include/IMP/optimizers/states/VRMLLogOptimizerState.h (working copy)
@@ -14,8 +14,13 @@
#include "../../IMP_config.h"
#include "../../base_types.h"
#include "../../OptimizerState.h"
+#include "../../ParticleRefiner.h"
#include "../../internal/kernel_version_info.h"
+#include "../../Vector3D.h"
+#include <boost/tuple/tuple.hpp>
+#include <map>
+
namespace IMP
{
@@ -50,39 +55,38 @@
//! The float key to use for the radius
/** Particles without such an attribute are drawn as fixed sized markers.
*/
- void set_radius(FloatKey k) {
+ void set_radius_key(FloatKey k) {
radius_=k;
}
+
//! The three color components
/** Color values should be between 0 and 1. They will be snapped if needed.
*/
- void set_color(FloatKey r, FloatKey g, FloatKey b) {
- r_=r; g_=g; b_=b;
+ void set_color_key(IntKey k) {
+ color_=k;
}
- //! Set the particles to use.
- void set_particles(const Particles &pis) {
- pis_=pis;
- }
+ //! Add a value to the color mappre
+ void set_color(int c, Vector3D v);
+
+ IMP_LIST(public, Particle, particle, Particle*);
+ IMP_CONTAINER(ParticleRefiner, particle_refiner, ParticleRefinerIndex);
+
//! Force it to write the next file
void write_next_file();
void write(std::string name) const;
+protected:
//! A helper function to just write a list of particles to a file
- static void write(const Particles &pis,
- FloatKey radius, FloatKey r,
- FloatKey g, FloatKey b,
- std::ostream &out);
-
-protected:
- Particles pis_;
+ void write(std::ostream &out, const Particles &ps) const;
std::string filename_;
int file_number_;
int call_number_;
int skip_steps_;
FloatKey radius_;
- FloatKey r_, g_, b_;
+ IntKey color_;
+ std::map<int, Vector3D > colors_;
};
} // namespace IMP
Index: kernel/include/IMP/Vector3D.h
===================================================================
--- kernel/include/IMP/Vector3D.h (revision 623)
+++ kernel/include/IMP/Vector3D.h (working copy)
@@ -124,6 +124,15 @@
out << "(" << operator[](0) << ", " << operator[](1) << ", "
<< operator[](2) << ")";
}
+
+ bool operator<(const Vector3D &o) const {
+ for (unsigned int i=0; i< 3; ++i) {
+ if (operator[](i) < o[i]) return true;
+ else if (operator[](i) > o[i]) return false;
+ }
+ return false;
+ }
+
private:
Float vec_[3];
};
Index: kernel/test/particle_refiners/test_bond_pr.py
===================================================================
--- kernel/test/particle_refiners/test_bond_pr.py (revision 623)
+++ kernel/test/particle_refiners/test_bond_pr.py (working copy)
@@ -10,8 +10,8 @@
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)
+ ps= IMP.test.create_particles_in_box(m)
+ bds= IMP.test.create_chain(ps, 10)
bl= IMP.BondDecoratorListScoreState(ps)
ss= IMP.CoverBondsScoreState(bl, rk)
m.add_score_state(bl)
Index: kernel/test/decorators/test_yaml.py
===================================================================
--- kernel/test/decorators/test_yaml.py (revision 0)
+++ kernel/test/decorators/test_yaml.py (revision 0)
@@ -0,0 +1,47 @@
+import unittest
+import IMP
+import IMP.test
+
+class YamlTests(IMP.test.TestCase):
+ def _create_model(self):
+ IMP.set_log_level(IMP.VERBOSE)
+ m = IMP.Model()
+ p= IMP.Particle()
+ m.add_particle(p)
+ IMP.XYZDecorator.create(p)
+ p= IMP.Particle()
+ m.add_particle(p)
+ IMP.XYZDecorator.create(p)
+ return m
+ def test_yaml(self):
+ """Check writing to yaml """
+ m= self._create_model()
+ IMP.write_yaml(m)
+ def test_read(self):
+ """Check reading from yaml"""
+ m= self._create_model()
+ st="""particle: 0
+ float-attributes:
+ x: 0
+ y: 1
+ z: 2
+ int-attributes:
+ string-attributes:
+ particle-attributes:
+particle: 1
+ float-attributes:
+ x: 3
+ y: 4
+ z: 5
+ int-attributes:
+ string-attributes:
+ particle-attributes:
+"""
+ IMP.read_yaml(st, m)
+ IMP.write_yaml(m)
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
Index: kernel/test/restraints/test_angles.py
===================================================================
--- kernel/test/restraints/test_angles.py (revision 623)
+++ kernel/test/restraints/test_angles.py (working copy)
@@ -31,7 +31,7 @@
m.add_particle(p)
d= IMP.XYZDecorator.create(p)
l0.append(p)
- self.randomize_particles(l0, 20)
+ IMP.test.randomize_particles(l0, 20)
return l0
def create_angle_r(self, s, ps):
Index: kernel/test/connectivity/test_connectivity.py
===================================================================
--- kernel/test/connectivity/test_connectivity.py (revision 623)
+++ kernel/test/connectivity/test_connectivity.py (working copy)
@@ -56,7 +56,7 @@
o = IMP.ConjugateGradients()
o.set_threshold(1e-4)
o.set_model(m)
- self.randomize_particles(m.get_particles(), 50.0)
+ IMP.test.randomize_particles(m.get_particles(), 50.0)
# add connectivity restraints
Index: kernel/test/modeller/test_pdb_read.py
===================================================================
--- kernel/test/modeller/test_pdb_read.py (revision 623)
+++ kernel/test/modeller/test_pdb_read.py (working copy)
@@ -33,7 +33,7 @@
self.assertEqual(i_num_atom_type, f_num_atom_type, "too many atom types")
self.assertEqual(1377, hc.get_count(),
"Wrong number of particles created")
- rd= IMP.get_residue(mp, 29)
+ rd= IMP.molecular_hierarchy_get_residue(mp, 29)
self.assertEqual(rd.get_index(), 29);
def test_bonds(self):
@@ -41,8 +41,8 @@
m = IMP.Model()
mp= IMP.pdb.read_pdb('modeller/single_protein.pdb', m)
#mp= IMP.MolecularHierarchyDecorator.cast(p)
- all_atoms= IMP.get_particles(mp,
- IMP.MolecularHierarchyDecorator.ATOM);
+ all_atoms= IMP.molecular_hierarchy_get_by_type(mp,
+ IMP.MolecularHierarchyDecorator.ATOM);
self.assertEqual(1221, all_atoms.size(),
"Wrong number of atoms found in protein")
Index: kernel/test/states/test_vrml_log.py
===================================================================
--- kernel/test/states/test_vrml_log.py (revision 623)
+++ kernel/test/states/test_vrml_log.py (working copy)
@@ -7,7 +7,7 @@
IMP.test.TestCase.setUp(self)
IMP.set_log_level(IMP.TERSE)
- def _testit(self, rk, r,g,b, pref):
+ def _testit(self, rk, pref):
"""Test logging to a VRML file"""
m= IMP.Model()
o= IMP.SteepestDescent()
@@ -24,15 +24,11 @@
p1= IMP.Particle()
m.add_particle(p1)
d1= IMP.XYZDecorator.create(p1)
- p1.add_attribute(r, 1.0, False)
- p1.add_attribute(g, 0.0, False)
- p1.add_attribute(b, 0.0, False)
d1.set_x(1)
d1.set_y(1)
d1.set_z(1)
a= IMP.VRMLLogOptimizerState(nm, IMP.Particles([p0,p1]))
- a.set_radius(rk)
- a.set_color(r, g, b)
+ a.set_radius_key(rk)
o.add_optimizer_state(a)
a.update()
@@ -41,16 +37,11 @@
def test_1(self):
"""Testing the VRML log"""
self._testit(IMP.FloatKey("radius"),
- IMP.FloatKey("red"),
- IMP.FloatKey("green"),
- IMP.FloatKey("blue"), "test1")
+ "test1")
def test_2(self):
"""Testing the VRML log with new attribute names"""
self._testit(IMP.FloatKey("another_radius"),
- IMP.FloatKey("red5"),
- IMP.FloatKey("green5"),
- IMP.FloatKey("blue5"),
"test1")
def test_skip(self):
"""Test skipping steps in the VRML log"""
Index: kernel/test/states/test_nonbonded_list.py
===================================================================
--- kernel/test/states/test_nonbonded_list.py (revision 623)
+++ kernel/test/states/test_nonbonded_list.py (working copy)
@@ -64,7 +64,7 @@
self.do_test_bi_update(ss)
def make_spheres(self, m, num, lbv, ubv, minr, maxr):
- ps=self.create_particles_in_box(m, num, lbv, ubv)
+ ps=IMP.test.create_particles_in_box(m, num, lbv, ubv)
for p in ps:
p.add_attribute(self.rk, random.uniform(minr, maxr), False)
return ps
@@ -119,8 +119,8 @@
#IMP.set_log_level(IMP.TERSE)
m= IMP.Model()
ps=IMP.Particles()
- 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])
+ ps= IMP.test.create_particles_in_box(m, 20, [0,0,0], [10,10,10])
+ pts= IMP.test.create_particles_in_box(m, 20, [160,160,160], [170,170,170])
for p in pts:
ps.append(p)
md=15
Index: kernel/test/optimizers/test_sd_optimizer.py
===================================================================
--- kernel/test/optimizers/test_sd_optimizer.py (revision 623)
+++ kernel/test/optimizers/test_sd_optimizer.py (working copy)
@@ -70,7 +70,7 @@
# Start off with all particles in close proximity (but not actually
# colocated, as the derivative of zero distance is zero):
- self.randomize_particles(self.particles, .01)
+ IMP.test.randomize_particles(self.particles, .01)
self.steepest_descent.optimize(50)
Index: kernel/pyext/IMP.i
===================================================================
--- kernel/pyext/IMP.i (revision 623)
+++ kernel/pyext/IMP.i (working copy)
@@ -192,13 +192,14 @@
%include "IMP/Particle.h"
%include "Vector3D.i"
%include "IMP/DecoratorBase.h"
+%include "IMP/decorators/bond_decorators.h"
%include "IMP/decorators/HierarchyDecorator.h"
%include "IMP/decorators/MolecularHierarchyDecorator.h"
%include "IMP/decorators/NameDecorator.h"
%include "IMP/decorators/ResidueDecorator.h"
%include "IMP/decorators/XYZDecorator.h"
-%include "IMP/decorators/bond_decorators.h"
%include "IMP/decorators/AtomDecorator.h"
+%include "IMP/decorators/yaml.h"
%include "IMP/ParticleRefiner.h"
%include "IMP/particle_refiners/BondCoverParticleRefiner.h"
%include "IMP/particle_refiners/ChildrenParticleRefiner.h"
@@ -229,6 +230,7 @@
%include "IMP/score_states/MaxChangeScoreState.h"
%include "IMP/score_states/NonbondedListScoreState.h"
%include "IMP/score_states/AllNonbondedListScoreState.h"
+%include "IMP/score_states/ManualBondDecoratorListScoreState.h"
%include "IMP/score_states/BondDecoratorListScoreState.h"
%include "IMP/score_states/BipartiteNonbondedListScoreState.h"
%include "IMP/score_states/GravityCenterScoreState.h"
@@ -269,6 +271,8 @@
%template(ScoreStates) ::std::vector<ScoreState*>;
%template(OptimizerStates) ::std::vector<OptimizerState*>;
%template(ParticleIndexes) ::std::vector<ParticleIndex>;
+ %template(BondDecorators) ::std::vector<BondDecorator>;
+ %template(MolecularHiearchyDecorators) ::std::vector<MolecularHierarchyDecorator>;
%template(FloatKeys) ::std::vector<FloatKey>;
%template(StringKeys) ::std::vector<StringKey>;
%template(IntKeys) ::std::vector<IntKey>;
1
0