Any way to "Copy" a region/union referencing deleted regions causes LAMMPS to hang

Hi LAMMPS users,

I am attempting to build a function (in python) that takes an input of a list of bounds (xlo, xhi, ylo, yhi, zlo, zhi) and a LAMMPS object and constructs a unioned set of regions representing what would happen if regions obeyed periodic boundaries. However, I’m running into the following problem:

If I define a region as the union of some other regions (e.g. region my_region union 2 foo bar), and then delete “foo” and “bar”, attempting to perform any operations on “my_region” (e.g. variable baz equal count(all,my_region) followed by lmp.extract_variable(baz, 0, 0)) causes python (and I assume LAMMPS) to consume all the available memory on the machine and hang forever. In short,

from lammps import lammps
lmp = lammps()
lmp.file(“in.some_example_file”)
lmp.command(“region foo block 1 2 1 2 1 2”)
lmp.command(“region bar block 3 4 3 4 3 4”)
lmp.command(“region my_region union 2 foo bar”)
lmp.command(“region foo delete”)
lmp.command(“region bar delete”)
lmp.command(“variable baz equal count(all, my_region)”)
lmp.extract_variable(“baz”, 0, 0)

And then everything hangs. Note that using lmp.command(“print $baz”) also causes the program to hang.

I have tested this sequence of events on some of the example in.foo files provided with LAMMPS and this behavior still persists, so I do not believe it is my specific code, though I can provide code if you’d like. My LAMMPS version is LAMMPS (24 Apr 2013). I am currently updating my LAMMPS to the most recent version and will test again, but none of the patches since my last update seem to address the issue.

I assume this is because “union” doesn’t copy the regions, but instead creates some sort of reference to them? Is there any way to truly “Copy” a region (e.g. like listb = lista[:] in python)? I ask because I’d like my function to leave only one name in the region namespace occupied so that other parts of my code that I write don’t risk trying to create region entries that are (secretly) occupied.

If this isn’t a functionality likely to be included anytime soon, is there any patch that can be implemented to generate a warning/error when the regions comprising a union are deleted (or if said deleted regions are later called upon) rather than letting LAMMPS hang itself? While I do not doubt that this behavior could be anticipated and avoided by any advanced user, it was very frustrating to encounter and not know why my code was taking down the node it was running on and I suspect I am not the only one to have ever made this mistake.

If there is a mistake I’m making on my end causing this behavior please do let me know, and if so I apologize in advance for wasting your time.

Thanks!

Elizabeth Decolvenaere
Graduate Student, Peters and Gordon Groups
Department of Chemical Engineering
University of California, Santa Barbara

I assume this is because “union” doesn’t copy the regions, but instead creates some sort of reference to them? Is there any way >to truly “Copy” a region (e.g. like listb = lista[:] in python)? I ask because I’d like my function to leave only one name in the region >namespace occupied so that other parts of my code that I write don’t risk trying to create region entries that are (secretly) >occupied.

yes, regions that are unions or intersections do keep a list of the sub-regions that define
them. So you cannot later delete those sub-regions and expect the Union region to work.

We never thought to check for that, b/c we never imagined a user would delete the
sub-regions. Why do you want to do that? There are no “secret” regions in LAMMPS
so there is no danger of a name conflict. Since your program or your input script
defines all the regions, it’s not complicated to keep track of the names to insure
you don’t re-use a region ID (which LAMMPS would flag as an error).

I’ll put a warning on the region doc page about not deleting sub-regions and add
a few error checks. But it would be inefficient to make the error check
every time a region method was invoked and there would be ways from an external
program to sidestep the error checks.

Steve