How to use constant force and langevin?

Skip to first unread message


Jul 7, 2020, 8:17:45 AM7/7/20
to hoomd-users
I am new to Hoomd and I need help.

I would like to add a constant force to my current simulation that is using langevin integrator.

I added constant using the following command and as discribed in the following link, that doesn't seem to be working:[2.5,5.0,2.1],group=all);

class, fy=None, fz=None, fvec=None, tvec=None, group=None, callback=None)

Constant force.

  • fvec (tuple) – force vector (in force units)
  • tvec (tuple) – torque vector (in torque units)
  • fx (float) – x component of force, retained for backwards compatibility
  • fy (float) – y component of force, retained for backwards compatibility
  • fz (float) – z component of force, retained for backwards compatibility
  • group ( – Group for which the force will be set.
  • callback (callable) – A python callback invoked every time the forces are computed

constant specifies that a constant force should be added to every particle in the simulation or optionally to all particles in a group.


Forces are kept constant during the simulation. If a callback should re-compute particle forces every time step, it needs to overwrite the old forces of all particles with new values.

Ibrahim Guiagoussou

Jul 7, 2020, 12:05:51 PM7/7/20
I also did tried class with differenec is diffusion coefficient value... I am expecting different value for the diffusion coefficient value when using or not using the constant force...
What am I doing wrong?

class, group, f_lst=None, t_lst=None, orientation_link=True, orientation_reverse_link=False, rotation_diff=0, constraint=None)

The following are the two commandes I tries:

Case I: uning force.constant...
snapshot =,, particle_types=['A']);
snapshot.particles.position[:,:] = positions;
snapshot.particles.velocity[:,:] = velocities;
system = hoomd.init.read_snapshot(snapshot);
# specify Lennard-Jones interactions between particle pairs
nl =;
lj =, nlist=nl);
lj.pair_coeff.set('A', 'A', epsilon=epsilon, sigma=sigma);
all =;
groupA ='A');;,5.0,2.1),group=all);
langevinIntegrator =, kT=kT, seed=seed);
langevinIntegrator.set_gamma('A', gamma=gamma);,5.0,2.5),group=all);
# seed=2011, group=groupA, f_lst=forces, orientation_link=False);
hoomd.analyze.callback(callback=pullSystemConfigurationData(system, particleData), period=periodAnalyze);
hoomd.dump.gsd(f"{filename}.gsd", period=periodGSD, group=all, overwrite=True);
# run 100,000 time steps;

Case I: uning saame code as before and using instead of force.constant(...)
#,5.0,2.1),group=all); seed=2011, group=groupA, f_lst=forces, orientation_link=False);

What am I doing wrong?
Your help is very appreciated...

You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Ibrahim Guiagoussou
(403) 774-8444 / (403) 690-6868
Calgary, Alberta, Canada

Joshua Anderson

Jul 9, 2020, 8:33:25 AM7/9/20

I can only guess since you don’t say how you are measuring diffusion or what values you get vs what you expect. What is the peclet number for your active matter simulation? Maybe your active and constant forces are too small to really effect a change over the Langevin damping. I would suggest trying different force magnitudes and visualizing the simulation trajectory to see how the behavior changes. 

Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

On Jul 7, 2020, at 12:06 PM, Ibrahim Guiagoussou <> wrote:

Ibrahim Guiagoussou

Aug 2, 2020, 2:34:46 PM8/2/20
The script is working fine...
I was mistaken when I use a simple linear registration slope and the following equations
MSD(t) = 2Dt=slope.t and MSD(t) = <x^2>(t)-<x>^2(t)
Where MSD is the mean-square-displacement, <...> the average overall particles at a step t...
Thanks for all

You received this message because you are subscribed to a topic in the Google Groups "hoomd-users" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit

Avishek Kumar

May 19, 2023, 9:03:41 PMMay 19
to hoomd-users

Will you please let me know why you have written force.constant twice in the HOOMD script?

Avishek Kumar
Reply all
Reply to author
0 new messages