I would like to use IMP to restrict some proteins to be close to a
membrane (but not in the membrane).
Usually we do this by defining the membrane as a fixed object and
restraining the particles relative to it. For example the membrane
restraint you found assumes an infinite membrane in the xy plane, and
simply restrains particles by their z coordinates. Another example would
be a pore where the membrane is represented by a torus and particles are
restrained based on their distance to its surface. See the IMP.npc
module for those restraints (although those are for PMI1; they would
need some minor modifications to work with modern PMI).
I was checking out the
IMP.pmi.MembraneRestraint class, but no clue about its usage.
Normally you would not use the C++ class directly, but the Python
wrapper, in IMP.pmi.basic.restraints. That's fairly well documented: