Active force problem.

Skip to first unread message

Ye Zhang

Apr 11, 2022, 8:48:42 AM4/11/22
to hoomd-users


I'm using `md.force.Active and md.force.custom_force to simulate active matter system with brownian integrater


active =
active.active_force['A'] = (10,0,0)
rotational_diffusion_updater = active.create_diffusion_updater(rotational_diffusion=1,trigger=1)

I want to change the active force during the simulation, so according to the document on active force,


class CustomActiveForce_2D(
 def __init__(self,f_array,theta_array,rotation_diff):
   self.f_array = f_array.reshape((-1,1))
   self.theta_array = theta_array.reshape((-1,1))
   self.rotation_diff = rotation_diff
 def update_force(self):
   self.active_f = self.f_array*np.column_stack([np.cos(self.theta_array),
 def set_forces(self,timestep):
   with self.cpu_local_force_arrays as arrays:
     arrays.force[:] =self.active_f
active_N = snapshot.particles.N
f_array =  10*np.ones((active_N,1))
custom_active =CustomActiveForce_2D(f_array = f_array,
                        theta_array= 2*np.pi*(np.random.random((snapshot.particles.N,1))-0.5),
integrator.integrate_rotational_dof = True

But the result of the two methods is different when keeping the constants the same.

It's there anything wrong with my code?

Thanks for your help~

Joshua Anderson

Apr 11, 2022, 1:58:54 PM4/11/22
Ye Zhang,

I'm not surprised the two implementations provide different results. You are generating different random numbers than HOOMD's. I can't say whether anything is wrong with your code. Only you can make such a judgement.

Here is HOOMD's implementation if you want to compare:
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
> --
> 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
> <>

Ye Zhang

Apr 12, 2022, 4:41:37 AM4/12/22
to hoomd-users
thanks for your help~ I'm trying to solve this problem

Joshua Anderson

Apr 12, 2022, 6:23:08 AM4/12/22
Problem descriptions must describe the behavior you get vs the expected behavior. Without such a description, we can only guess at what you intend to accomplish with your code and only guess at what your code actually does. Normally, people on the mailing list don't waste time offering such guesses.

I did think of another guess to offer: You store theta in index order. HOOMD reorders particles in memory, so theta[i] will apply to particle with tag t1 on one timestep and tag t2 on the next. To completely replicate, you should use the particle orientation to track the direction of the force vector. This enables support for MPI domain decomposition as well.
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

> To view this discussion on the web visit

Ye Zhang

Apr 14, 2022, 7:22:41 AM4/14/22
to hoomd-users
thanks for your help~

Ramalingam Kailasham

May 15, 2023, 1:59:30 PM5/15/23
to hoomd-users
Hi All

I recently got started with using HOOMD to simulate active Brownian particles. I agree with Joshua's recommendation that using the particle orientation (quaternion) to update the active force is the correct way to go about implementing active forces in a custom manner. 

With regards to Ye Zhang's code, the formulae appear correct. However, the custom force is sampling "theta" from a random distribution at each timestep, while one would want the updated theta to remember the value of the theta from the previous timestep. This is the reason that working with the particle orientations is preferred. 

Hope that helps


Reply all
Reply to author
0 new messages