Specify velocity for group as function of total energy?

I am interested in running a series of simulations in which I vary the total energy of a group at the initial time.

Is there a way to initialize the atoms, compute potential energy, and then assign kinetic energy to the group as the difference between the desired total and computed potential energy (some total value of kinetic energy which would then be distributed over the group)? I have not been able to find an obvious answer using the set, fix and/or velocity commands.

I imagine that this would have to be implemented carefully to avoid attempting to assign negative kinetic energy.

I am interested in running a series of simulations in which I vary the total
energy of a group at the initial time.
Is there a way to initialize the atoms, compute potential energy, and then
assign kinetic energy to the group as the difference between the desired
total and computed potential energy (some total value of kinetic energy
which would then be distributed over the group)? I have not been able to
find an obvious answer using the set, fix and/or velocity commands.

considering that the kinetic energy of an atom is 1/2*m*v**2 it should
be easy to derive an expression for that.
if you are *very* lazy, you could just assign an *arbitrary*
temperature, compute the kinetic energy of that, and then determine a
scaling factor that reduces it just to the desired kinetic energy
(don't forget that: v ~ sqrt(E_kin)).

axel.