[lammps-users] Force-Addition & Fix External Command with Python script

I need to apply additional forces to the molecules in my simulation. A new force (from Surface Potential) has to be calculated for each molecule. I was earlier using the python script for calculations and then using fix addforce in the input script. Now, I need to operate with more than 31 molecules, and thus LAMMPS is restricting me to form more than 31 groups. Can the force be added in any other ways, if I am calculating all of them from python (like by using molecule id)?
I also came across the fix external command, and I think I can make it work here.
I wanted to know, how to use the fix external command when I need to define the callback function in the Python script? Is there any restriction in naming the function in python, as it is not defined in the command line?

Thanks in advance!
Deepak Somani

Using fix external would be overkill for the scenario you describe.
You could be using fix python/invoke to add a callback function to the post_force step.

As you can see from the documentation, the function name is arbitrary, it just has to be present in the python interpreter that you are using and it must take the two arguments as shown and then manipulate the force array from within the python code, i.e. get access to per-atom data via lmp.extract_atom() or lmp.numpy_extract_atom() and then compute and add your forces, energy, and virial contributions.

If you still want to use fix external, you are strongly encouraged to use the 30 July 2021 version of LAMMPS since it contains an updated fix external library interface with corrections and extensions to the library interface and the python module, that allow to correctly include and set per-atom energy and the virial from the callback. in older LAMMPS versions the library interface support and thus the python module support was incomplete, had inconsistencies, and was not documented. so the full feature set of fix external was only accessible from C++.