For a while I have been thinking it would be nice to add another layer of indirection for particle storage in IMP. The idea would be that we add some base classes like: class ParticleContainer { //provide virtual get_number, get, find etc. } class ParticlePairContainer; class ParticleSetContainer;
Then restraints would internally have a appropriate particle container. The nice thing would be that you could then choose to share containers between restraints and states as needed, reducing the number of things that need to be updated when something changes.
This could be implemented without changing the existing API since we could leave the exiting get/set methods in the restraints. And just add a method to set the container if you want it shared.
NonbondedListRestraint would go away we we would just have PairListRestraint (you just set the ParticlePairContainer in the restraint to be the NonbondedList). Likewise, the BondedList base class goes away and the BondDecoratorListRestraint.
We can have containers that are collections of containers so you really only have to update things in one place.
We could get rid of the problematic get_particles sorts of methods that we add for python since we can always just return this container (and I am sure we can figure out how to make it iterable).
We could probably do something clever with the get_interacting_particles method so that, in most cases, it just returns the Restraints ParticleContainer instance.
Would anyone else find this extra level of indirection useful?