Implementation of custom external field

GROMACS version: 2022.1
GROMACS modification: Intended

Dear all,

I would like to implement a custom external potential to be included in the force calculations. By potential I mean a spatially varying field, not pairwise interactions. Such a field should be able to act on certain (index) groups of particles. In a sense, what I would like to achieve is a generalization of functionalities like the flat bottom position restraint. Indeed, our use cases cannot be covered by the implemented position restraints, pulling or density-guided simulations (I think so at least). Therefore I would like to implement an additional module in GROMACS. I have a quite naive view of the code base, so I would like to find the least intrusive solution that still leverages the DD and acceleration capabilities of the MD engine. I am grateful for any suggestions that prevent me from running into a completely wrong direction.

As a first alternative, I have been looking into the gmxapi python interface and the sample_restraint plugin code.It is a really great tool, but there seems to be a lot of boilerplate tailored towards pair restraints based on the IRestraintPotential interface. If I understood correctly, modules of this specific form get wrapped by RestraintForceProviders in the MDRunner. However, I would like to implement a module that relies on single particle coordinates as provided by the generic IForceProvider interface. Is it possible to create such an object an bind it to an md session via gmxapi? Is this even an intended use case for the API?

Secondly, I have also been looking into the applied_forces modules, particularly electricfield and densityfitting. These classes seem to provide the interface and get the data that I need. Would it be a viable option to implement an additional module like that directly in the GROMACS library and then “register” it in tpxio and mdmodules?

Thanks a lot and kind regards,
Max

Hello,

Implementing this based on the current electric field module sounds like it will be the most painless approach. You can start with copying the code from there and then modify it to your needs. This will also take care of handling the writing to/reading from TPR files.

Cheers

Paul

There has been a lot of interest along these lines recently. It is probably time to replace the IRestraintPotential interface with a more complete version of IForceProvider.

The IRestraintPotential interface is intentionally limited to meet concerns about API stability. You can read and apply forces to as many sites as you like, but (as you observe) it is not well suited for large numbers of interactions.

However, there has not been much discussion on specific concerns. Currently, the IForceProvider interface is pretty stable, but the input and output parameter types are subject to change without warning. We could probably achieve a satisfactorily stable API by letting the parameter types be arbitrarily opaque and providing free functions to access the various data.

I will put together a proposal for the next development cycle. I would welcome suggestions of specific data you need to read or write, and whether there are constraints on the data localization or decomposability/parallelizability of your calculations. I encourage you to join the developer mailing list. I have opened Public API for ForceProviders (#4596) · Issues · GROMACS / GROMACS · GitLab to try to centralize discussion.

In the mean time, your best bet is to use the electric field module as a guide for a new IMDModule implementation in a fork.

Thanks a lot for your helpful feedback! I will let you know about my specific data needs and potential constraints during the development process.