Running LAMMPS as a client code to perform Grand Canonical Monte Carlo moves and VASP as a server code

Dear Steve and Axel,

Please find attached the fix_client_gcmc.cpp, fix_client_gcmc.h, message_w_gcmc.cpp files that I have created. I added these files to the src/MESSAGE directory, and tried to build LAMMPS again to include this new fix, but it threw an error. I briefly list my edits below:

  1. From LAMMPS documentation and the fix_gcmc.cpp file, I saw that it has a energy_full() method that calculates the energy of the configuration using fix_nvt. Since we want to use VASP, I edited this function to do so. I essentially copied the post_force() method from the fix_client_md.cpp file into this method, which sends the coordinates to VASP, and receives the energy.

  2. I also copied other functions, variables and enumerators from fix_client_md.cpp which I understand are necessary for LAMMPS to communicate coordinates with VASP and receive energy, namely-

a. Copied the error checks and variables defined in the FixClientMD() constructor into the FixGCMC() constructor

b. Copied memory->destroy(xpbc) from the FixClientMD() destructor into the FixGCMC() destructor

c. Copied commands from init() in fix_client_md.cpp into init() of fix_gcmc.cpp

d. Commented out the lines that calculate force and energy in energy_full() since VASP does this for us (lines 2333-2354 and 2362 in fix_gcmc.cpp)

e. Copied setup(), compute_scalar(), pack_coords(), pack_box(), receive_fev() from fix_client_md.cpp into fix_gcmc.cpp

f. Edited receive_fev() to return energy (in fix_client_md.cpp, it does not return anything) as the energy needs to be returned so that LAMMPS GCMC can decide whether to accept or reject the trial move.

g. I made all these changes in the file fix_client_gcmc.cpp (so I did not alter fix_gcmc.cpp directly). Everything else is mostly the same from fix_gcmc.cpp.

h. I also edited message.cpp to validate gcmc as a supported protocol (new file- message_w_gcmc.cpp).

In the attached files, I have commented my edits with ‘// begin edit’ and ‘// end of edit’ to make the edits easier to find since the number of lines of code is quite long.

When I tried building LAMMPS again with these new files, the error I get is-

…/fix_client_gcmc.cpp(2452): error #547: nonstandard form for taking the address of a member function

energy = receive_fev(vflag);

…/fix_client_gcmc.cpp(2452): error: expression must be a modifiable lvalue

energy = receive_fev(vflag);

…/fix_client_gcmc.cpp(2460): error #547: nonstandard form for taking the address of a member function

return energy;

…/fix_client_gcmc.cpp(2460): error: return value type does not match the function type

return energy;

…/fix_client_gcmc.cpp(2754): error #547: nonstandard form for taking the address of a member function

energy = receive_fev(vflag);

…/fix_client_gcmc.cpp(2754): error: expression must be a modifiable lvalue

energy = receive_fev(vflag);

…/fix_client_gcmc.cpp(2863): error: operand of “*” must be a pointer

return *eng;

So my questions are –

  1. Could you please tell me what this error is caused by? I think it is because I define “double FixClientGCMC::receive_fev(int vflag)” to return *eng. I thought eng=econvert * cs->unpack_double(ENERGY) returns a pointer to the energy value and not the energy value itself, so I return *eng. But it seems like eng is not a pointer.

  2. Could you please tell me if the rest of the edits I have made are generally correct or flag any major errors in my understanding?

Thank you so much for your help ! Any insight is greatly appreciated !

Regards,

Vrindaa

fix_client_gcmc.cpp (90.4 KB)

fix_client_gcmc.h (10.2 KB)

message_w_gcmc.cpp (3.54 KB)

I can only comment on the error messages. Those are due to careless programming.

  1. “energy” is a member function of your fix class and you didn’t declare a local variable to override it and
    It would be best programming practice to use a (local) variable with a different name to avoid confusion.
  2. “eng” is a class member of type double. you cannot dereference a non-pointer.

As for whether your code is correct or not in general, i don’t have the time to debug, test, and review your code while it is still under development and contains mistakes that are obviously due to lack of quite basic programming expertise. Perhaps Steve has some because he wrote the original code in the package and may remember by heart what the flow of control and data is. I would have to first figure this out by myself and there are more pressing projects that I can spend that time on.
I am giving you the pointers where to look for the compile errors this time as a courtesy, but don’t expect me in the future to correct other similar compilation failures. Sorting things like that are generally considered the responsibility of the person that is doing the programming.

Axel.

Hi Axel,

Thank you for pointing out the mistakes! It seems to have compiled successfully now. I am working on testing it.

Regards,

Vrindaa