[lammps-users] Calling a fix from the source code of another modified fix

Dear LAMMPs users,

I wonder if it is possible to call a fix (fix addtorque) from the source code of a custom fix that I’m modifying.

I saw that one can invoke input script commands using the c++ API through,

    lmp->input->one("<input script command>");

However I don't know if it is possible to use the interface from inside lammps own source code.

I was hoping at some point in my fix cpp file I could just do:

    lmp->input->one("fix addtorque ...")

The reason I want to do this is that the torque applied is computed inside the cpp and I can't not figure a way to access it from the input script.

Excuse me if this doesn't even make sense, I have not worked with interfaces before.

Kind regards,

Yes, that should be possible, but it would be simpler to call modify->add_fix(). Please note that you should not do this from within the constructor of your custom fix. I suggest you look for other examples of creating/managing a fix from inside the C++ code to see how this can be done.
But since you are programming in C++ you could just also directly add to the forces on atoms in the same way that fix addtorque does. That would avoid the overhead of keeping track of the fix and deleting it in the destructor.

try: grep ‘modify->add_fix’ src/.cpp src//*.cpp

Hi Axel,

Thank you for your quick response. Yes, adding the force to the atoms directly is something I thought about, but since the calculation is quite thorough I thought that lammps could do it for me.

Could you point me to these examples of creating/managing a fix from inside the C++ code?

Thank you again,

Hi Axel,

Thank you for your quick response. Yes, adding the force to the atoms directly is something I thought about, but since the calculation is quite thorough I thought that lammps could do it for me.

most of the code in fix addtorque is about handling the command line and querying variables etc.
the code in its post_force() function is rather compact and straightforward.

Thank you very much! :slight_smile: