Help regarding LAMMPS HMC using C

Hello

I am working on creating a Hybrid Monte Carlo (HMC) code in LAMMPS using C programming language for running a NPT system.
I have a working HMC code for a NVT system. I am trying to make it into a NPT system but am facing difficulty in passing the changed box length into lammps.

In HMC using python we are able to pass on variables from the code to lammps directly as shown below:

lmp.command(“change_box all x final 0.0 %.10f y final 0.0 .%10f z final 0.0 %.10f units box” % (box_new, box_new, box_new))

But I can’t find a similar command to use in C. In the LAMMPS documentation for C we have a similar command to above as

lammps_command(void *handle, const char *cmd)

where *handle is the loaded lammps instance and *cmd is the lammps command input we want to execute, Here the lammps command input given as argument should be a char string with lammps commands like “run 0” .So as you can see I cannot pass the box_new variable similar to the way done in python

The problem I face is that I want to pass a variable from the code box_new to lammps to change box dimensions. I tried writing the lammps_command in the syntax similar to the python lmp.command but it returned error saying lammps_command takes in only two arguments.

Basically I want a command equivalent to the lmp.command (used for python) I shared above for C.

I hope I have been able to explain my problem properly, if not please do ask.

Hope someone can help me regarding this.

There is not enough information here starting with what “LAMMPS HMC” is. Without sufficient context, it is not possible to provide meaningful advice.

There are examples in the LAMMPS manual and the LAMMPS source showing how to use the library interface.

For more specific information, it would be required to have some concrete example code that can be compiled and tested.

Please also note that you need to use triple backquotes “```” to prevent the forum software from typesetting whatever text you quote.

That is not a LAMMPS problem but a C programming problem. You can easily generate a custom string using malloc() and sprintf() and then free() after calling lammps_command()

Mind you, in the Python example, the string expansion and replacement with the values is not done by LAMMPS but by Python.

Mind you there also is: lammps_reset_box()

1 Like

Thanks alot, I will try this.