Use hoomd.hpmc.external.user.CPPExternalPotential but with global property parameters

Skip to first unread message

ch wang

May 16, 2023, 1:01:50 PM5/16/23
to hoomd-users
Dear all,

When building an external potential using hoomd.hpmc.external.user.CPPExternalPotential to run hpmc simulations, I found the built-in parameters, like r_i, diameter can't meet my potential energy function. I want to use global property parameters, like the number of particles in solid phase. Is it possible to pass Python code to external potential, or are there other better ways to implement this purpose?

Thank you in advance.


Joshua Anderson

May 18, 2023, 9:03:30 AM5/18/23

You can embed constant parameters in your source code. f-strings are one convenient way to do this.

For computed global parameters, there aren't any good options currently. For CPP pair potentials, you can write a custom Updater that sets `param_array` entries. However,  `CPPExternalPotential` does not provide a similar `param_array`. You could modify the C++ code to add it (if you do, please submit a pull request to make this available to others in HOOMD releases). 

Note that the CustomUpdater would change parameters only when your updater is triggered and not with every individual trial move. This breaks detailed balance and will impact the accuracy of your calculation. There is no way to solve this in HOOMD, which is designed around the assumption that all trial moves can be evaluated using *only* the local state.

You mention the "number of particles in the solid phase". Perhaps umbrella sampling would be a more appropriate solution? You can structure umbrella sampling to operate at the level of timesteps (accepting rejecting whole series of timesteps) thereby maintaining detailed balance and removing the need for variable parameters in an external potential.
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

Reply all
Reply to author
0 new messages