So I am writing a command to flip bonds and I want call delete_bonds and create_bonds to do this

So I have a c++ code which creates a mesh and using mc decides which bonds to flip. So I created a command for lammps which calls the external script and gets which bonds to join and which to delete.

using namespace LAMMPS_NS;

// Constructor
BondDataCommand::BondDataCommand(LAMMPS *lmp) : Command(lmp) {}


void BondDataCommand::command(int narg, char **arg)
{
    process_bond_data();
}

void BondDataCommand::process_bond_data() 
{
    // Assuming intValues contains atom IDs whose bonds need to be deleted
    std::vector<int> intValues = getIntValues(exec("./main"));

}


So here intValues has 4 int values. First two are the ids of atoms between which the bonds are to be created and next two for which the bonds to be deleted. I think this is stupid idea and maybe a better way to do this but I want to call the delete_bonds and create_bonds to do this but to delete_bonds I have to create a group with the atom ids. Is there a way to easily do this thing?
And while calling this c++ external script which is a serial script cause any kind of issue apart from some increase in runtime. Not familiar with MPI. And I know this all sounds kind of stupid and not the most strightforward approach

You should take a look at ‘fix bond/react’

Thanks for the suggestion but I did write the code something like this

// Constructor
BondDataCommand::BondDataCommand(LAMMPS *lmp) : Command(lmp) {}

// Command method
void BondDataCommand::command(int narg, char **arg)
{
    process_bond_data();
}


void BondDataCommand::process_bond_data() 
{
  // Assuming intValues contains atom IDs for bond operations
  std::vector<int> intValues = getIntValues(exec("./main"));
  const char *rem_list[] = {"rem","multi","remove"};
  // delete_bonds group_id multi remove
  lmp->input->one("group rem id " + std::to_string(intValues[2]) + " " + std::to_string(intValues[3]));
  delete_bond(3,rem_list);
  lmp->input->one("create_bonds single/bond 1 " + std::to_string(intValues[0])+ " " + std::to_string(intValues[1]) );
}

So here the delete_bond() function is the same as used by delete_bonds command and then I make different bonds. But now the problem I am facing is Lammps is giving me this error

ERROR on proc 0: New bond exceeded bonds per atom in create_bonds (src/create_bonds.cpp:370)
Last command: create_bonds single/bond 1 67 75

Any ideas how to fix this?
Thanks

LAMMPS allocates memory for a fixed number of bonds per atom at the start of a simulation (for efficiency, since most simulations do not involve atoms having large numbers of bonds).

If you are adding bonds, you need to tell LAMMPS beforehand to “reserve” more bonds per atom. You can do this with, for example, the extra/bonds/per/atom setting in read_data: read_data command — LAMMPS documentation

2 Likes

Please note that this usually also requires increasing the extra/special/per/atom property, often by an even larger number.

In general, it is not a big problem to choose these values much larger than needed to be on the safe side. It just increases the communication cost by a tiny bit.

1 Like

Thanks it worked

Thanks i did increase the extra/special/per/atom to be 20 twice as extra/bonds/per/atom which I set to 10 as for my system the maximum number of bonds per atom would be 6. So increasing it to 10 would be ok.