I want to simulate a long polymer which collapses. I start with an extended polymer ( and so I have a huge box to begin with and lots of water) and as the simulation progresses, the polymer collapses (so now the polymer takes a much smaller volume and can be simulated in a much smaller box).
I waste a lot of computation in simulating waters that are not useful once the polymer has collapsed.
What I would like to do is, somehow change the box size as the simulation runs and the box size would be a distance cut off from the center of mass of the polymer. So when the polymer collapses, the box size becomes small and I simulate less water molecules. I think this will help me finish my simulations much faster.
Let me know if this is possible in LAMMPS. If yes, then how to do it.
This option, in the way you describe it, does not exist. There are significant problems with that: removing water from the simulation requires re-equilibration and around the area where you remove the water, you have the equivalent of an implosion and thus will generate disruptive phonons. I am not sure how much you can reduce that effect by removing water molecules at a very slow rate with fix evaporate. But at the same time you would have to simulate with fix npt, so the box dimensions can adjust when water is removed.
As second possible approach would be to determine an “inactive water” region and use neigh_modify exclude to remove those atoms from the neighborlist and thus non-bonded force computation and then do time integration on the remaining atoms. This way you are avoid some of the problems from removing atoms, but now have to contend with the fact that you are freezing part of your system to 0K. You will have to break down your simulation into chunks and then update the regions and groups before the next chunk is run.
I’ve been thinking about your simulation problem and to add some comment on the answer of @akohlmey, I don’t know how you could physically interpret the results. There are some simulation protocols mimicking grand canonical ensemble in MD, but as far as I know, none is implemented in LAMMPS and there are tricky to set up, be it with MC coupling or not.
However, depending on what relies behind vague statements like:
I have a huge box to begin with and lots of water
There might be room for some optimization in your simulation setup. What is a “huge box”? Does it have to be huge if your polymer starts extended? Which fixes do you use? Maybe you can make a rectangular box with its long side parallel to your extended polymer and let it relax in all directions at a given pressure with sides long enough so that the polymer molecule does not interact with itself along the other directions. You might already gain some computation time by removing some water there.
Once your polymer is sufficiently contracted you can start a new LAMMPS run where you preserve the polymer’s configuration, delete unwanted waters and shrink the box as desired, and then integrate just the waters to thermalize them sufficiently before “unfreezing” the polymer and resuming.
This is how every proteineer starts their runs from a PDB file, so it’s a defensible procedure.
Of course, the “collapsed” trajectories will technically sample from a completely different ensemble to your original simulation. It is on you to convince your reviewers (and yourself) that, effectively, you have avoided any finite size artifacts – or in an alternative chemical thermodynamics picture, that despite an effective bulk concentration increase the collapsed polymer still shows effectively infinite-dilution solute behaviour.
But also, if you are worried about simulating unwanted waters, have … you considered GROMACS? It may be perfectly usable for your intended simulations, and much faster.