Fix gcmc and fix shake not using same molecule template ID

When two separate molecule commands were used

molecule ch4 mol.ch4.txt # 1st molecule command

thanks for reporting. this is indeed a bug in fix gcmc.

the following change to fix gcmc should make it work:

diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp
index e0a269b…fbe6b6b 100644
— a/src/MC/fix_gcmc.cpp
+++ b/src/MC/fix_gcmc.cpp
@@ -501,7 +501,7 @@ void FixGCMC::init()
if (ifix < 0) error->all(FLERR,“Fix gcmc rigid fix does not exist”);
fixrigid = modify->fix[ifix];
int tmp;

  • if (onemols != (Molecule **) fixrigid->extract(“onemol”,tmp))
  • if (&onemols[imol] != (Molecule **) fixrigid->extract(“onemol”,tmp))
    error->all(FLERR,
    "Fix gcmc and fix rigid/small not using "
    “same molecule template ID”);
    @@ -516,7 +516,7 @@ void FixGCMC::init()
    if (ifix < 0) error->all(FLERR,“Fix gcmc shake fix does not exist”);
    fixshake = modify->fix[ifix];
    int tmp;
  • if (onemols != (Molecule **) fixshake->extract(“onemol”,tmp))
  • if (&onemols[imol] != (Molecule **) fixshake->extract(“onemol”,tmp))
    error->all(FLERR,"Fix gcmc and fix shake not using "
    “same molecule template ID”);
    }
    @@ -1397,12 +1397,13 @@ void FixGCMC::attempt_molecule_insertion()

// FixRigidSmall::set_molecule stores rigid body attributes
// FixShake::set_molecule stores shake info for molecule

According to the changes suggested by Axel, I changed the src/MC/fix_gcmc.cpp in lammps-stable-31Mar2017 at these places:

(1) @@ -501,7 +501,7 @@ void FixGCMC::init()
//if (onemols != (Molecule **) fixrigid->extract(“onemol”,tmp))

if (&onemols[imol] != (Molecule **) fixrigid->extract(“onemol”,tmp))

(2) @@ -516,7 +516,7 @@ void FixGCMC::init()
//if (onemols != (Molecule **) fixshake->extract(“onemol”,tmp))

if (&onemols[imol] != (Molecule **) fixshake->extract(“onemol”,tmp))

(3) @@ -1397,12 +1397,13 @@ void FixGCMC::attempt_molecule_insertion()

// if (rigidflag)

// fixrigid->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat);

// else if (shakeflag)

// fixshake->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat);

for (int submol = 0; submol < nmol; ++submol)

{

if (rigidflag)

fixrigid->set_molecule(nlocalprev,maxtag_all,submol,com_coord,vnew,quat);

else if (shakeflag)

fixshake->set_molecule(nlocalprev,maxtag_all,submol,com_coord,vnew,quat);

}

(4) @@ -2058,11 +2059,12 @@ void FixGCMC::attempt_molecule_insertion_full()

// if (rigidflag)

// fixrigid->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat);

// else if (shakeflag)

// fixshake->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat);

for (int submol = 0; submol < nmol; ++submol) {

if (rigidflag)

fixrigid->set_molecule(nlocalprev,maxtag_all,submol,com_coord,vnew,quat);

else if (shakeflag)

fixshake->set_molecule(nlocalprev,maxtag_all,submol,com_coord,vnew,quat);

}

And then recompiled the LAMMPS executable:

$make clean-all

$make mpi

However, this error ”Fix gcmc and fix shake not using same molecule template ID” still occurs when I’m trying to use two separate molecule command with fix gcmc.

According to the changes suggested by Axel, I changed the
src/MC/fix_gcmc.cpp in * lammps-stable-31Mar2017* at

these places:

​[...]​

And then recompiled the LAMMPS executable:

$make clean-all

​you are missing a command here:

make package-update

which will update the copy of fix_gcmc.cpp that will be compiled.

$make mpi

However, this error ”Fix gcmc and fix shake not using same molecule
template ID” still occurs when I’m trying to use two separate molecule
command with fix gcmc.

​yes, because you compiled the unmodified installed version of the file.

axel.​

Based on Axel’s suggestion, I changed the src/MC/fix_gcmc.cpp and recompiled the LAMMPS.

Now, the new executable lammps works fine and the bug “Fix gcmc and fix shake not using same molecule template ID” is eliminated! Thanks to Axel Kohlmeyer!

Now I arranged the recompiling process (version: lammps-stable-31Mar2017) as the following procedures :

  1. Change the src/MC/fix_gcmc.cpp file as suggested by Axel at : https://sourceforge.net/p/lammps/mailman/message/35868292/
    (attention should be paid, that one should not make a backup of the fix_gcmc.cpp file or other “extra cpp files” in this src/MC directory, otherwise the compiling process would engage an error when the compiler detected extra cpp files! At first, I made this mistake by backup the fix_gcmc.cpp and the compiler gives me error until I removed this backup file.)

  2. Clean the object files:
    $make clean-all

  3. Update the MC package after changes in the fix_gcmc.cpp
    $make package-update

  4. Build the executable:
    $make mpi