[lammps-users] Referencing simulation box parameters

Hi Tyler,

Why not just define some variables that you use for the box lengths, and also some variables that are half the box lengths? Then these half box length variables can be used to make groups referencing to the center of the box. I have used this several times when wanting to define various groups, e.g. cylinders.

variable r equal 3 # radius of cylinder (in lattice constants)
variable l equal 10 # length of material, x-dim (in lattice constants)
variable w equal 15 # width of material, y-dim (in lattice constants)
variable d equal 5 # height of material, z-dim (in lattice constants)
variable l2 equal $l/2 # half length
variable w2 equal $w/2 # half width
variable d2 equal $d/2 # half height
[other commands...]
region box block 0 $l 0 $w 0 d \[other commands\.\.\.\] region mycylinder cylinder y {l2} ${d2} r {w2} INF #dimension x-coord y-coord radius lo hi

I find it very useful to define box length parameters as variables for use later on in the script. Or, of course, you can make a script that generates your input files, and which calculates all values and put them directly in there. The choice is yours! :slight_smile:

Christer H. Ersland.

Hey Christer,
That’d certainly work if I could arbitrarily choose box parameters, but unfortunately I’m working with a system where the box geometry is important. Good idea though, thanks.

I don't understand why Christer's suggestion doesn't work for you.
If you can write a formula for what you want a region param
to be as a function of the simulation box params (orthogonal
or triclinic), then you can encode that formula in a variable,
and use that variable when you invoke the region command.
Is there some box param you need that isn't accessible to
a variable definition?


Hi Steve,
I think I might not have been clear in describing what I was looking for. I was hoping to do something like

variable xhi equal
variable xlo equal

so that I could define, say,
variable l equal {xhi}-{xlo}
variable w equal {yhi}-{ylo}
variable d equal {zhi}-{zlo}

and proceed as Chister does, rather than manually entering in values for $l, $w, and $d (or, say, defining them with command line variables, or some other way to externally enter them).

But I don’t see a way to reference box parameters read from a data file, except as EDGE in a region definition (and I haven’t figured out a way to then make variables from that region’s parameters).

It sounded like Christer was suggesting defining variables in the input script for use in defining the simulation box there, so I noted that unfortunately I’m reading in data files in which I’ve already specified box geometry and can’t redefine my box in my input script.

Sorry for the confusion, I ought to have been clearer. I’m just grepping to get the box parameters and passing them as command line variables, which works fine and is perfectly easy, I’d just been wondering if there were a way to do reference box parameters read from a data file within an input script.