Re: [IMP-dev] Annoyance with current restraint design
To: "IMP developers' list" <>
Subject: Re: [IMP-dev] Annoyance with current restraint design
From: Ben Webb <>
Date: Tue, 18 Dec 2007 12:29:02 -0800
Daniel Russel wrote:
I have some restraints which I want to have be semi-dynamic, meaning,
I want to be able to reset the list of particles which they act on.
This doesn't work so cleanly with restraints taking lists of
ParticleIndexes as then you need one version of set_particles to be
called from the constructor (where the Restraint::model_ is not set)
and another version to be called by outsiders after the model pointer
has been set (or pass the model pointer to both and ignore the stored
This seems like a reason for writing restraints which take Particles
rather than ParticleIndexes.
Agreed. As we already discussed, Particle* is easier to pass from Python
than ParticleIndex anyway. The only downsides are that
1) There's no easy way to check for a 'bad' particle this way (a corrupt
Particle could have a pointer to the model, but the model may not have
the corresponding pointer to the Particle). With particle indexes of
course you just check whether the index is in range.
2) This works only as long as the model's particle storage is
std::vector<Particle*>. For example, we couldn't switch to
std::vector<Particle> because then the Particle* could change when the
vector is resized.
3) To be really careful, we should add checks that all particles live in
the same model.
I don't think these are huge problems, however.
"It is a capital mistake to theorize before one has data."
- Sir Arthur Conan Doyle