2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
<!DOCTYPE html>
<!-- [if IE 8]><html class="no - js lt - ie9" lang="en" > <![endif] -->
<!-- [if gt IE 8]><! --> < html class = "no-js" lang = "en" > <!-- <![endif] -->
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
2015-12-21 23:20:41 +08:00
< title > variable command — LAMMPS documentation< / title >
2015-07-30 22:53:28 +08:00
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
< link rel = "stylesheet" href = "_static/css/theme.css" type = "text/css" / >
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
< link rel = "stylesheet" href = "_static/sphinxcontrib-images/LightBox2/lightbox2/css/lightbox.css" type = "text/css" / >
2006-09-22 00:22:34 +08:00
2015-07-30 22:53:28 +08:00
2015-12-21 23:20:41 +08:00
< link rel = "top" title = "LAMMPS documentation" href = "index.html" / >
2015-07-30 22:53:28 +08:00
< script src = "_static/js/modernizr.min.js" > < / script >
< / head >
< body class = "wy-body-for-nav" role = "document" >
< div class = "wy-grid-for-nav" >
< nav data-toggle = "wy-nav-shift" class = "wy-nav-side" >
< div class = "wy-side-nav-search" >
< a href = "Manual.html" class = "icon icon-home" > LAMMPS
< / a >
< div role = "search" >
< form id = "rtd-search-form" class = "wy-form" action = "search.html" method = "get" >
< input type = "text" name = "q" placeholder = "Search docs" / >
< input type = "hidden" name = "check_keywords" value = "yes" / >
< input type = "hidden" name = "area" value = "default" / >
< / form >
< / div >
< / div >
< div class = "wy-menu wy-menu-vertical" data-spy = "affix" role = "navigation" aria-label = "main navigation" >
< ul >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_intro.html" > 1. Introduction< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_start.html" > 2. Getting Started< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_commands.html" > 3. Commands< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_packages.html" > 4. Packages< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_accelerate.html" > 5. Accelerating LAMMPS performance< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_howto.html" > 6. How-to discussions< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_example.html" > 7. Example problems< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_perf.html" > 8. Performance & scalability< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_tools.html" > 9. Additional tools< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_modify.html" > 10. Modifying & extending LAMMPS< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_python.html" > 11. Python interface to LAMMPS< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_errors.html" > 12. Errors< / a > < / li >
< li class = "toctree-l1" > < a class = "reference internal" href = "Section_history.html" > 13. Future and history< / a > < / li >
< / ul >
< / div >
< / nav >
< section data-toggle = "wy-nav-shift" class = "wy-nav-content-wrap" >
< nav class = "wy-nav-top" role = "navigation" aria-label = "top navigation" >
< i data-toggle = "wy-nav-top" class = "fa fa-bars" > < / i >
< a href = "Manual.html" > LAMMPS< / a >
< / nav >
< div class = "wy-nav-content" >
< div class = "rst-content" >
< div role = "navigation" aria-label = "breadcrumbs navigation" >
< ul class = "wy-breadcrumbs" >
< li > < a href = "Manual.html" > Docs< / a > » < / li >
< li > variable command< / li >
< li class = "wy-breadcrumbs-aside" >
< a href = "http://lammps.sandia.gov" > Website< / a >
< a href = "Section_commands.html#comm" > Commands< / a >
< / li >
< / ul >
< hr / >
< / div >
< div role = "main" class = "document" itemscope = "itemscope" itemtype = "http://schema.org/Article" >
< div itemprop = "articleBody" >
< div class = "section" id = "variable-command" >
< span id = "index-0" > < / span > < h1 > variable command< a class = "headerlink" href = "#variable-command" title = "Permalink to this headline" > ¶< / a > < / h1 >
< div class = "section" id = "syntax" >
< h2 > Syntax< a class = "headerlink" href = "#syntax" title = "Permalink to this headline" > ¶< / a > < / h2 >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable name style args ...
< / pre > < / div >
< / div >
< ul class = "simple" >
< li > name = name of variable to define< / li >
< li > style = < em > delete< / em > or < em > index< / em > or < em > loop< / em > or < em > world< / em > or < em > universe< / em > or
< em > uloop< / em > or < em > string< / em > or < em > format< / em > or < em > getenv< / em > or < em > file< / em > or < em > atomfile< / em > or < em > python< / em > or < em > equal< / em > or < em > atom< / em > < / li >
< / ul >
< pre class = "literal-block" >
< em > delete< / em > = no args
2015-07-31 00:49:30 +08:00
< em > index< / em > args = one or more strings
< em > loop< / em > args = N
N = integer size of loop, loop from 1 to N inclusive
< em > loop< / em > args = N pad
N = integer size of loop, loop from 1 to N inclusive
pad = all values will be same length, e.g. 001, 002, ..., 100
< em > loop< / em > args = N1 N2
N1,N2 = loop from N1 to N2 inclusive
< em > loop< / em > args = N1 N2 pad
N1,N2 = loop from N1 to N2 inclusive
pad = all values will be same length, e.g. 050, 051, ..., 100
< em > world< / em > args = one string for each partition of processors
< em > universe< / em > args = one or more strings
< em > uloop< / em > args = N
N = integer size of loop
< em > uloop< / em > args = N pad
N = integer size of loop
pad = all values will be same length, e.g. 001, 002, ..., 100
< em > string< / em > arg = one string
< em > format< / em > args = vname fstr
vname = name of equal-style variable to evaluate
fstr = C-style format string
< em > getenv< / em > arg = one string
< em > file< / em > arg = filename
< em > atomfile< / em > arg = filename
< em > python< / em > arg = function
< em > equal< / em > or < em > atom< / em > args = one formula containing numbers, thermo keywords, math operations, group functions, atom values and vectors, compute/fix/variable references
numbers = 0.0, 100, -5.4, 2.8e-4, etc
2015-09-25 04:29:42 +08:00
constants = PI, version, on, off, true, false, yes, no
2015-07-31 00:49:30 +08:00
thermo keywords = vol, ke, press, etc from < a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a >
math operators = (), -x, x+y, x-y, x*y, x/y, x^y, x%y,
x == y, x != y, x & lt y, x & lt= y, x & gt y, x & gt= y, x & & y, x || y, !x
math functions = sqrt(x), exp(x), ln(x), log(x), abs(x),
sin(x), cos(x), tan(x), asin(x), acos(x), atan(x), atan2(y,x),
random(x,y,z), normal(x,y,z), ceil(x), floor(x), round(x)
ramp(x,y), stagger(x,y), logfreq(x,y,z), logfreq2(x,y,z),
stride(x,y,z), stride2(x,y,z,a,b,c),
vdisplace(x,y), swiggle(x,y,z), cwiggle(x,y,z)
group functions = count(group), mass(group), charge(group),
xcm(group,dim), vcm(group,dim), fcm(group,dim),
bound(group,dir), gyration(group), ke(group),
angmom(group,dim), torque(group,dim),
inertia(group,dimdim), omega(group,dim)
region functions = count(group,region), mass(group,region), charge(group,region),
xcm(group,dim,region), vcm(group,dim,region), fcm(group,dim,region),
bound(group,dir,region), gyration(group,region), ke(group,reigon),
angmom(group,dim,region), torque(group,dim,region),
inertia(group,dimdim,region), omega(group,dim,region)
special functions = sum(x), min(x), max(x), ave(x), trap(x), slope(x), gmask(x), rmask(x), grmask(x,y), next(x)
2015-09-25 04:29:42 +08:00
feature functions = is_active(category,feature,exact), is_defined(category,id,exact)
2015-07-31 00:49:30 +08:00
atom value = id[i], mass[i], type[i], mol[i], x[i], y[i], z[i], vx[i], vy[i], vz[i], fx[i], fy[i], fz[i], q[i]
atom vector = id, mass, type, mol, x, y, z, vx, vy, vz, fx, fy, fz, q
compute references = c_ID, c_ID[i], c_ID[i][j]
fix references = f_ID, f_ID[i], f_ID[i][j]
variable references = v_name, v_name[i]
2015-07-30 22:53:28 +08:00
< / pre >
< / div >
< div class = "section" id = "examples" >
< h2 > Examples< a class = "headerlink" href = "#examples" title = "Permalink to this headline" > ¶< / a > < / h2 >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable x index run1 run2 run3 run4 run5 run6 run7 run8
2007-07-03 22:58:21 +08:00
variable LoopVar loop $n
2008-01-03 03:25:15 +08:00
variable beta equal temp/3.0
2008-01-19 07:12:55 +08:00
variable b1 equal x[234]+0.5*vol
2015-07-30 22:53:28 +08:00
variable b1 equal " x[234] + 0.5*vol"
2008-01-03 03:25:15 +08:00
variable b equal xcm(mol1,x)/2.0
variable b equal c_myTemp
2009-12-10 05:20:59 +08:00
variable b atom x*y/vol
2011-06-08 01:15:11 +08:00
variable foo string myfile
2015-03-18 00:05:28 +08:00
variable myPy python increase
2012-11-10 09:17:45 +08:00
variable f file values.txt
2008-01-09 07:21:32 +08:00
variable temp world 300.0 310.0 320.0 ${Tfinal}
2006-12-20 00:44:20 +08:00
variable x universe 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
2010-10-07 00:29:13 +08:00
variable x uloop 15 pad
2013-12-03 08:23:55 +08:00
variable str format x %.6g
2015-07-30 22:53:28 +08:00
variable x delete
< / pre > < / div >
< / div >
< / div >
< div class = "section" id = "description" >
< h2 > Description< a class = "headerlink" href = "#description" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > This command assigns one or more strings to a variable name for
evaluation later in the input script or during a simulation.< / p >
< p > Variables can thus be useful in several contexts. A variable can be
2013-07-25 08:09:27 +08:00
defined and then referenced elsewhere in an input script to become
part of a new input command. For variable styles that store multiple
2015-07-30 22:53:28 +08:00
strings, the < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command can be used to increment which
string is assigned to the variable. Variables of style < em > equal< / em > store
2013-07-25 08:09:27 +08:00
a formula which when evaluated produces a single numeric value which
2015-07-30 22:53:28 +08:00
can be output either directly (see the < a class = "reference internal" href = "print.html" > < em > print< / em > < / a > , < a class = "reference internal" href = "fix_print.html" > < em > fix print< / em > < / a > , and < a class = "reference internal" href = "run.html" > < em > run every< / em > < / a > commands) or as part
of thermodynamic output (see the < a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a >
command), or used as input to an averaging fix (see the < a class = "reference internal" href = "fix_ave_time.html" > < em > fix ave/time< / em > < / a > command). Variables of style < em > atom< / em > store
2010-05-08 00:29:19 +08:00
a formula which when evaluated produces one numeric value per atom
2015-07-30 22:53:28 +08:00
which can be output to a dump file (see the < a class = "reference internal" href = "dump.html" > < em > dump custom< / em > < / a >
command) or used as input to an averaging fix (see the < a class = "reference internal" href = "fix_ave_spatial.html" > < em > fix ave/spatial< / em > < / a > and < a class = "reference internal" href = "fix_ave_atom.html" > < em > fix ave/atom< / em > < / a >
commands). Variables of style < em > atomfile< / em > can be used anywhere in an
2013-07-25 05:27:24 +08:00
input script that atom-style variables are used; they get their
2015-03-18 00:05:28 +08:00
per-atom values from a file rather than from a formula. Variables can
be hooked to Python functions using code you provide, so that the
2015-07-30 22:53:28 +08:00
variable gets its value from the evaluation of the Python code.< / p >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > As discussed in < a class = "reference internal" href = "Section_commands.html#cmd-2" > < span > Section 3.2< / span > < / a > of the
manual, an input script can use “ immediate” variables, specified as
$(formula) with parenthesis, where the formula has the same syntax as
equal-style variables described on this page. This is a convenient
way to evaluate a formula immediately without using the variable
command to define a named variable and then evaluate that
variable. See below for a more detailed discussion of this feature.< / p >
2015-07-30 22:53:28 +08:00
< / div >
< p > In the discussion that follows, the “ name” of the variable is the
2007-02-21 08:18:01 +08:00
arbitrary string that is the 1st argument in the variable command.
2008-01-03 03:25:15 +08:00
This name can only contain alphanumeric characters and underscores.
2015-07-30 22:53:28 +08:00
The “ string” is one or more of the subsequent arguments. The “ string”
2007-07-03 22:58:21 +08:00
can be simple text as in the 1st example above, it can contain other
2008-01-03 03:25:15 +08:00
variables as in the 2nd example, or it can be a formula as in the 3rd
2015-07-30 22:53:28 +08:00
example. The “ value” is the numeric quantity resulting from
2007-07-03 22:58:21 +08:00
evaluation of the string. Note that the same string can generate
different values when it is evaluated at different times during a
2015-07-30 22:53:28 +08:00
simulation.< / p >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > When the input script line is encountered that defines a
variable of style < em > equal< / em > or < em > atom< / em > or < em > python< / em > that contains a
formula or Python code, the formula is NOT immediately evaluated. It
will be evaluated every time when the variable is < strong > used< / strong > instead. If
you simply want to evaluate a formula in place you can use as
so-called. See the section below about “ Immediate Evaluation of
Variables” for more details on the topic. This is also true of a
< em > format< / em > style variable since it evaluates another variable when it is
invoked.< / p >
2015-07-30 22:53:28 +08:00
< / div >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > Variables of style < em > equal< / em > and < em > atom< / em > can be used as inputs to
various other LAMMPS commands which evaluate their formulas as needed,
e.g. at different timesteps during a < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > . Variables of
style < em > python< / em > can be used in place of an equal-style variable so long
as the associated Python function, as defined by the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "python.html" > < em > python< / em > < / a > command, returns a numeric value. Thus any
2015-03-18 00:05:28 +08:00
command that states it can use an equal-style variable as an argument,
can also use such a python-style variable. This means that when the
LAMMPS command evaluates the variable, the Python function will be
2015-07-30 22:53:28 +08:00
executed.< / p >
< / div >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > When a variable command is encountered in the input script and
the variable name has already been specified, the command is ignored.
This means variables can NOT be re-defined in an input script (with
two exceptions, read further). This is to allow an input script to be
processed multiple times without resetting the variables; see the
< a class = "reference internal" href = "jump.html" > < em > jump< / em > < / a > or < a class = "reference internal" href = "include.html" > < em > include< / em > < / a > commands. It also means
that using the < a class = "reference internal" href = "Section_start.html#start-7" > < span > command-line switch< / span > < / a > -var
will override a corresponding index variable setting in the input
2015-07-30 22:53:28 +08:00
script.< / p >
< / div >
< p > There are two exceptions to this rule. First, variables of style
< em > string< / em > , < em > getenv< / em > , < em > equal< / em > , < em > atom< / em > , and < em > python< / em > ARE redefined each
2015-03-18 00:05:28 +08:00
time the command is encountered. This allows these style of variables
to be redefined multiple times in an input script. In a loop, this
2015-07-30 22:53:28 +08:00
means the formula associated with an < em > equal< / em > or < em > atom< / em > style variable
2015-03-18 00:05:28 +08:00
can change if it contains a substitution for another variable, e.g. $x
2015-07-30 22:53:28 +08:00
or v_x.< / p >
< p > Second, as described below, if a variable is iterated on to the end of
its list of strings via the < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command, it is removed
2008-03-01 09:13:20 +08:00
from the list of active variables, and is thus available to be
2015-07-30 22:53:28 +08:00
re-defined in a subsequent variable command. The < em > delete< / em > style does
the same thing.< / p >
< hr class = "docutils" / >
< p > < a class = "reference internal" href = "Section_commands.html#cmd-2" > < span > This section< / span > < / a > of the manual explains how
2007-02-21 09:05:23 +08:00
occurrences of a variable name in an input script line are replaced by
2015-07-30 22:53:28 +08:00
the variable’ s string. The variable name can be referenced as $x if
the name “ x” is a single character, or as ${LoopVar} if the name
“ LoopVar” is one or more characters.< / p >
< p > As described below, for variable styles < em > index< / em > , < em > loop< / em > , < em > file< / em > ,
< em > universe< / em > , and < em > uloop< / em > , which string is assigned to a variable can be
incremented via the < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command. When there are no more
2012-11-10 09:17:45 +08:00
strings to assign, the variable is exhausted and a flag is set that
2015-07-30 22:53:28 +08:00
causes the next < a class = "reference internal" href = "jump.html" > < em > jump< / em > < / a > command encountered in the input
2012-11-10 09:17:45 +08:00
script to be skipped. This enables the construction of simple loops
2015-07-30 22:53:28 +08:00
in the input script that are iterated over and then exited from.< / p >
< p > As explained above, an exhausted variable can be re-used in an input
script. The < em > delete< / em > style also removes the variable, the same as if
2008-10-07 22:45:58 +08:00
it were exhausted, allowing it to be redefined later in the input
script or when the input script is looped over. This can be useful
2015-07-30 22:53:28 +08:00
when breaking out of a loop via the < a class = "reference internal" href = "if.html" > < em > if< / em > < / a > and < a class = "reference internal" href = "jump.html" > < em > jump< / em > < / a >
commands before the variable would become exhausted. For example,< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > label loop
2008-10-07 22:45:58 +08:00
variable a loop 5
2015-07-30 22:53:28 +08:00
print " A = $a"
if " $a > 2" then " jump in.script break"
next a
jump in.script loop
label break
variable a delete
< / pre > < / div >
< / div >
< hr class = "docutils" / >
< p > This section describes how all the various variable styles are defined
and what they store. Except for the < em > equal< / em > and < em > atom< / em > styles,
which are explaine in the next section.< / p >
< p > Many of the styles store one or more strings. Note that a single
2015-03-18 00:05:28 +08:00
string can contain spaces (multiple words), if it is enclosed in
quotes in the variable command. When the variable is substituted for
in another input script command, its returned string will then be
2015-07-30 22:53:28 +08:00
interpreted as multiple arguments in the expanded command.< / p >
< p > For the < em > index< / em > style, one or more strings are specified. Initially,
2006-09-22 00:22:34 +08:00
the 1st string is assigned to the variable. Each time a
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command is used with the variable name, the next
2006-09-22 00:22:34 +08:00
string is assigned. All processors assign the same string to the
2015-07-30 22:53:28 +08:00
variable.< / p >
< p > < em > Index< / em > style variables with a single string value can also be set by
using the command-line switch -var; see < a class = "reference internal" href = "Section_start.html#start-7" > < span > this section< / span > < / a > for details.< / p >
< p > The < em > loop< / em > style is identical to the < em > index< / em > style except that the
2010-06-29 02:11:30 +08:00
strings are the integers from 1 to N inclusive, if only one argument N
is specified. This allows generation of a long list of runs
(e.g. 1000) without having to list N strings in the input script.
2015-07-30 22:53:28 +08:00
Initially, the string “ 1” is assigned to the variable. Each time a
< a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command is used with the variable name, the next
string (“ 2” , “ 3” , etc) is assigned. All processors assign the same
string to the variable. The < em > loop< / em > style can also be specified with
2010-06-29 02:11:30 +08:00
two arguments N1 and N2. In this case the loop runs from N1 to N2
inclusive, and the string N1 is initially assigned to the variable.
2015-07-30 22:53:28 +08:00
N1 < = N2 and N2 > = 0 is required.< / p >
< p > For the < em > world< / em > style, one or more strings are specified. There must
be one string for each processor partition or “ world” . See < a class = "reference internal" href = "Section_start.html#start-7" > < span > this section< / span > < / a > of the manual for information on
running LAMMPS with multiple partitions via the “ -partition”
2006-09-22 00:22:34 +08:00
command-line switch. This variable command assigns one string to each
world. All processors in the world are assigned the same string. The
2015-07-30 22:53:28 +08:00
next command cannot be used with < em > equal< / em > style variables, since there
2006-09-22 00:22:34 +08:00
is only one value per world. This style of variable is useful when
you wish to run different simulations on different partitions, or when
performing a parallel tempering simulation (see the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "temper.html" > < em > temper< / em > < / a > command), to assign different temperatures to
different partitions.< / p >
< p > For the < em > universe< / em > style, one or more strings are specified. There
2006-09-22 00:22:34 +08:00
must be at least as many strings as there are processor partitions or
2015-07-30 22:53:28 +08:00
“ worlds” . See < a class = "reference internal" href = "Section_start.html#start-7" > < span > this page< / span > < / a > for information
on running LAMMPS with multiple partitions via the “ -partition”
2006-09-22 00:22:34 +08:00
command-line switch. This variable command initially assigns one
2015-07-30 22:53:28 +08:00
string to each world. When a < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command is encountered
2006-09-22 00:22:34 +08:00
using this variable, the first processor partition to encounter it, is
2007-02-21 08:18:01 +08:00
assigned the next available string. This continues until all the
variable strings are consumed. Thus, this command can be used to run
2006-09-22 00:22:34 +08:00
50 simulations on 8 processor partitions. The simulations will be run
one after the other on whatever partition becomes available, until
2015-07-30 22:53:28 +08:00
they are all finished. < em > Universe< / em > style variables are incremented
using the files “ tmp.lammps.variable” and “ tmp.lammps.variable.lock”
which you will see in your directory during such a LAMMPS run.< / p >
< p > The < em > uloop< / em > style is identical to the < em > universe< / em > style except that the
2007-02-21 08:18:01 +08:00
strings are the integers from 1 to N. This allows generation of long
list of runs (e.g. 1000) without having to list N strings in the input
2015-07-30 22:53:28 +08:00
script.< / p >
< p > For the < em > string< / em > style, a single string is assigned to the variable.
The only difference between this and using the < em > index< / em > style with a
single string is that a variable with < em > string< / em > style can be redefined.
2012-11-10 09:17:45 +08:00
E.g. by another command later in the input script, or if the script is
2015-07-30 22:53:28 +08:00
read again in a loop.< / p >
< p > For the < em > format< / em > style, an equal-style variable is specified along
with a C-style format string, e.g. “ %f” or “ %.10g” , which must be
2013-12-03 08:23:55 +08:00
appropriate for formatting a double-precision floating-point value.
This allows an equal-style variable to be formatted specifically for
2015-07-30 22:53:28 +08:00
output as a string, e.g. by the < a class = "reference internal" href = "print.html" > < em > print< / em > < / a > command, if the
default format “ %.15g” has too much precision.< / p >
< p > For the < em > getenv< / em > style, a single string is assigned to the variable
2013-10-30 23:57:57 +08:00
which should be the name of an environment variable. When the
variable is evaluated, it returns the value of the environment
variable, or an empty string if it not defined. This style of
variable can be used to adapt the behavior of LAMMPS input scripts via
environment variable settings, or to retrieve information that has
2015-07-30 22:53:28 +08:00
been previously stored with the < a class = "reference internal" href = "shell.html" > < em > shell putenv< / em > < / a > command.
2013-10-30 23:57:57 +08:00
Note that because environment variable settings are stored by the
2015-07-30 22:53:28 +08:00
operating systems, they persist beyond a < a class = "reference internal" href = "clear.html" > < em > clear< / em > < / a > command.< / p >
< p > For the < em > file< / em > style, a filename is provided which contains a list of
2012-11-10 09:17:45 +08:00
strings to assign to the variable, one per line. The strings can be
2013-07-25 04:47:56 +08:00
numeric values if desired. See the discussion of the next() function
2012-11-10 09:17:45 +08:00
below for equal-style variables, which will convert the string of a
2015-07-30 22:53:28 +08:00
file-style variable into a numeric value in a formula.< / p >
< p > When a file-style variable is defined, the file is opened and the
2012-11-10 09:17:45 +08:00
string on the first line is read and stored with the variable. This
means the variable can then be evaluated as many times as desired and
will return that string. There are two ways to cause the next string
2015-07-30 22:53:28 +08:00
from the file to be read: use the < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command or the
2012-11-10 09:17:45 +08:00
next() function in an equal- or atom-style variable, as discussed
2015-07-30 22:53:28 +08:00
below.< / p >
< p > The rules for formatting the file are as follows. A comment character
“ #” can be used anywhere on a line; text starting with the comment
character is stripped. Blank lines are skipped. The first “ word” of
a non-blank line, delimited by white space, is the “ string” assigned
to the variable.< / p >
< p > For the < em > atomfile< / em > style, a filename is provided which contains one or
2013-07-25 04:47:56 +08:00
more sets of values, to assign on a per-atom basis to the variable.
2015-07-30 22:53:28 +08:00
The format of the file is described below.< / p >
< p > When an atomfile-style variable is defined, the file is opened and the
2013-07-25 04:47:56 +08:00
first set of per-atom values are read and stored with the variable.
This means the variable can then be evaluated as many times as desired
and will return those values. There are two ways to cause the next
set of per-atom values from the file to be read: use the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command or the next() function in an atom-style
variable, as discussed below.< / p >
< p > The rules for formatting the file are as follows. Each time a set of
2013-07-25 04:47:56 +08:00
per-atom values is read, a non-blank line is searched for in the file.
2015-07-30 22:53:28 +08:00
A comment character “ #” can be used anywhere on a line; text starting
2013-07-25 04:47:56 +08:00
with the comment character is stripped. Blank lines are skipped. The
2015-07-30 22:53:28 +08:00
first “ word” of a non-blank line, delimited by white space, is read as
2013-07-25 04:47:56 +08:00
the count N of per-atom lines to immediately follow. N can be be the
total number of atoms in the system, or only a subset. The next N
2015-07-30 22:53:28 +08:00
lines have the following format< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > ID value
< / pre > < / div >
< / div >
< p > where ID is an atom ID and value is the per-atom numeric value that
will be assigned to that atom. IDs can be listed in any order.< / p >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > Every time a set of per-atom lines is read, the value for all
atoms is first set to 0.0. Thus values for atoms whose ID does not
appear in the set, will remain 0.0.< / p >
2015-07-30 22:53:28 +08:00
< / div >
< p > For the < em > python< / em > style a Python function name is provided. This needs
to match a function name specified in a < a class = "reference internal" href = "python.html" > < em > python< / em > < / a > command
which returns a value to this variable as defined by its < em > return< / em >
keyword. For exampe these two commands would be self-consistent:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable foo python myMultiply
python myMultiply return v_foo format f file funcs.py
< / pre > < / div >
< / div >
< p > The two commands can appear in either order so long as both are
specified before the Python function is invoked for the first time.< / p >
< p > Each time the variable is evaluated, the associated Python function is
2015-03-18 00:05:28 +08:00
invoked, and the value it returns is also returned by the variable.
Since the Python function can use other LAMMPS variables as input, or
query interal LAMMPS quantities to perform its computation, this means
2015-07-30 22:53:28 +08:00
the variable can return a different value each time it is evaluated.< / p >
< p > The type of value stored in the variable is determined by the < em > format< / em >
keyword of the < a class = "reference internal" href = "python.html" > < em > python< / em > < / a > command. It can be an integer
2015-03-18 00:05:28 +08:00
(i), floating point (f), or string (s) value. As mentioned above, if
it is a numeric value (integer or floating point), then the
python-style variable can be used in place of an equal-style variable
anywhere in an input script, e.g. as an argument to another command
2015-07-30 22:53:28 +08:00
that allows for equal-style variables.< / p >
< hr class = "docutils" / >
< p > For the < em > equal< / em > and < em > atom< / em > styles, a single string is specified which
2008-01-03 03:25:15 +08:00
represents a formula that will be evaluated afresh each time the
variable is used. If you want spaces in the string, enclose it in
double quotes so the parser will treat it as a single argument. For
2015-07-30 22:53:28 +08:00
< em > equal< / em > style variables the formula computes a scalar quantity, which
2008-01-03 03:25:15 +08:00
becomes the value of the variable whenever it is evaluated. For
2015-07-30 22:53:28 +08:00
< em > atom< / em > style variables the formula computes one quantity for each
atom whenever it is evaluated.< / p >
< p > Note that < em > equal< / em > and < em > atom< / em > variables can produce different values at
2007-02-21 08:18:01 +08:00
different stages of the input script or at different times during a
2015-07-30 22:53:28 +08:00
run. For example, if an < em > equal< / em > variable is used in a < a class = "reference internal" href = "fix_print.html" > < em > fix print< / em > < / a > command, different values could be printed each
2009-01-06 06:26:31 +08:00
timestep it was invoked. If you want a variable to be evaluated
immediately, so that the result is stored by the variable instead of
2015-07-30 22:53:28 +08:00
the string, see the section below on “ Immediate Evaluation of
Variables” .< / p >
< p > The next command cannot be used with < em > equal< / em > or < em > atom< / em > style
variables, since there is only one string.< / p >
< p > The formula for an < em > equal< / em > or < em > atom< / em > variable can contain a variety
2007-02-21 08:18:01 +08:00
of quantities. The syntax for each kind of quantity is simple, but
2007-02-10 05:37:30 +08:00
multiple quantities can be nested and combined in various ways to
build up formulas of arbitrary complexity. For example, this is a
2015-07-30 22:53:28 +08:00
valid (though strange) variable formula:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable x equal " pe + c_MyTemp / vol^(1/3)"
< / pre > < / div >
< / div >
< p > Specifically, an formula can contain numbers, thermo keywords, math
2010-04-24 04:00:32 +08:00
operators, math functions, group functions, region functions, atom
values, atom vectors, compute references, fix references, and
2015-07-30 22:53:28 +08:00
references to other variables.< / p >
< hr class = "docutils" / >
< p > Most of the formula elements produce a scalar value. A few produce a
2010-08-05 05:36:27 +08:00
per-atom vector of values. These are the atom vectors, compute
references that represent a per-atom vector, fix references that
represent a per-atom vector, and variables that are atom-style
variables. Math functions that operate on scalar values produce a
2010-08-18 05:58:29 +08:00
scalar value; math function that operate on per-atom vectors do so
2015-07-30 22:53:28 +08:00
element-by-element and produce a per-atom vector.< / p >
< p > A formula for equal-style variables cannot use any formula element
2010-08-05 05:36:27 +08:00
that produces a per-atom vector. A formula for an atom-style variable
can use formula elements that produce either a scalar value or a
2011-06-22 21:15:24 +08:00
per-atom vector. Atom-style variables are evaluated by other commands
2015-07-30 22:53:28 +08:00
that define a < a class = "reference internal" href = "group.html" > < em > group< / em > < / a > on which they operate, e.g. a
< a class = "reference internal" href = "dump.html" > < em > dump< / em > < / a > or < a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > or < a class = "reference internal" href = "fix.html" > < em > fix< / em > < / a > command.
2011-06-22 21:15:24 +08:00
When they invoke the atom-style variable, only atoms in the group are
inlcuded in the formula evaluation. The variable evaluates to 0.0 for
2015-07-30 22:53:28 +08:00
atoms not in the group.< / p >
2015-09-03 04:41:18 +08:00
< p > Constants are set at compile time and cannot be changed. < em > PI< / em > will
2015-09-25 04:29:42 +08:00
return the number 3.14159265358979323846; < em > on< / em > , < em > true< / em > or < em > yes< / em > will
return 1.0; < em > off< / em > , < em > false< / em > or < em > no< / em > will return 0.0; < em > version< / em > will
return a numeric version code of the current LAMMPS version (e.g.
version 2 Sep 2015 will return the number 20150902). The corresponding
value for newer versions of LAMMPS will be larger, for older versions
of LAMMPS will be smaller. This can be used to have input scripts
adapt automatically to LAMMPS versions, when non-backwards compatible
syntax changes are introduced. Here is an illustrative example (which
will not work, since the < em > version< / em > has been introduced more recently):< / p >
2015-09-03 04:41:18 +08:00
< div class = "highlight-python" > < div class = "highlight" > < pre > if $(version< 20140513) then " communicate vel yes" else " comm_modify vel yes"
< / pre > < / div >
< / div >
2015-07-30 22:53:28 +08:00
< p > The thermo keywords allowed in a formula are those defined by the
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style custom< / em > < / a > command. Thermo keywords that
require a < a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > to calculate their values such as
“ temp” or “ press” , use computes stored and invoked by the
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a > command. This means that you can
2009-12-04 01:57:33 +08:00
only use those keywords in a variable if the style you are using with
the thermo_style command (and the thermo keywords associated with that
style) also define and use the needed compute. Note that some thermo
keywords use a compute indirectly to calculate their value (e.g. the
enthalpy keyword uses temp, pe, and pressure). If a variable is
2009-12-10 05:20:59 +08:00
evaluated directly in an input script (not during a run), then the
values accessed by the thermo keyword must be current. See the
2015-07-30 22:53:28 +08:00
discussion below about “ Variable Accuracy” .< / p >
< hr class = "docutils" / >
< div class = "section" id = "math-operators" >
< h3 > Math Operators< a class = "headerlink" href = "#math-operators" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Math operators are written in the usual way, where the “ x” and “ y” in
2010-08-05 05:36:27 +08:00
the examples can themselves be arbitrarily complex formulas, as in the
2015-07-30 22:53:28 +08:00
examples above. In this syntax, “ x” and “ y” can be scalar values or
per-atom vectors. For example, “ ke/natoms” is the division of two
scalars, where “ vy+vz” is the element-by-element sum of two per-atom
vectors of y and z velocities.< / p >
< p > Operators are evaluated left to right and have the usual C-style
precedence: unary minus and unary logical NOT operator ” !” have the
highest precedence, exponentiation “ ^” is next; multiplication and
division and the modulo operator “ %” are next; addition and
subtraction are next; the 4 relational operators “ < ” , “ < =” , “ > ” , and
“ > =” are next; the two remaining relational operators “ ==” and ” !=”
are next; then the logical AND operator “ & & ” ; and finally the logical
OR operator “ ||” has the lowest precedence. Parenthesis can be used
2014-05-16 05:05:40 +08:00
to group one or more portions of a formula and/or enforce a different
2015-07-30 22:53:28 +08:00
order of evaluation than what would occur with the default precedence.< / p >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > Because a unary minus is higher precedence than exponentiation,
the formula “ -2^2” will evaluate to 4, not -4. This convention is
compatible with some programming languages, but not others. As
mentioned, this behavior can be easily overridden with parenthesis;
the formula “ -(2^2)” will evaluate to -4.< / p >
2015-07-30 22:53:28 +08:00
< / div >
< p > The 6 relational operators return either a 1.0 or 0.0 depending on
2010-11-19 02:30:31 +08:00
whether the relationship between x and y is TRUE or FALSE. For
2015-07-30 22:53:28 +08:00
example the expression x< 10.0 in an atom-style variable formula will
2010-04-24 04:00:32 +08:00
return 1.0 for all atoms whose x-coordinate is less than 10.0, and 0.0
2010-11-19 01:49:30 +08:00
for the others. The logical AND operator will return 1.0 if both its
2010-11-19 02:30:31 +08:00
arguments are non-zero, else it returns 0.0. The logical OR operator
will return 1.0 if either of its arguments is non-zero, else it
returns 0.0. The logical NOT operator returns 1.0 if its argument is
2015-07-30 22:53:28 +08:00
0.0, else it returns 0.0.< / p >
< p > These relational and logical operators can be used as a masking or
2010-11-19 02:30:31 +08:00
selection operation in a formula. For example, the number of atoms
2010-08-06 22:48:24 +08:00
whose properties satifsy one or more criteria could be calculated by
2010-04-24 04:18:34 +08:00
taking the returned per-atom vector of ones and zeroes and passing it
2015-07-30 22:53:28 +08:00
to the < a class = "reference internal" href = "compute_reduce.html" > < em > compute reduce< / em > < / a > command.< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "math-functions" >
< h3 > Math Functions< a class = "headerlink" href = "#math-functions" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Math functions are specified as keywords followed by one or more
parenthesized arguments “ x” , “ y” , “ z” , each of which can themselves be
2010-08-05 05:36:27 +08:00
arbitrarily complex formulas. In this syntax, the arguments can
2010-08-18 05:58:29 +08:00
represent scalar values or per-atom vectors. In the latter case, the
math operation is performed on each element of the vector. For
2015-07-30 22:53:28 +08:00
example, “ sqrt(natoms)” is the sqrt() of a scalar, where “ sqrt(y*z)”
2010-08-18 05:58:29 +08:00
yields a per-atom vector with each element being the sqrt() of the
2015-07-30 22:53:28 +08:00
product of one atom’ s y and z coordinates.< / p >
< p > Most of the math functions perform obvious operations. The ln() is
the natural log; log() is the base 10 log.< / p >
< p > The random(x,y,z) function takes 3 arguments: x = lo, y = hi, and z =
2010-10-13 01:58:24 +08:00
seed. It generates a uniform random number between lo and hi. The
normal(x,y,z) function also takes 3 arguments: x = mu, y = sigma, and
z = seed. It generates a Gaussian variate centered on mu with
variance sigma^2. In both cases the seed is used the first time the
internal random number generator is invoked, to initialize it. For
equal-style variables, every processor uses the same seed so that they
each generate the same sequence of random numbers. For atom-style
variables, a unique seed is created for each processor, based on the
specified seed. This effectively generates a different random number
2015-07-30 22:53:28 +08:00
for each atom being looped over in the atom-style variable.< / p >
2015-12-11 01:23:56 +08:00
< div class = "admonition note" >
< p class = "first admonition-title" > Note< / p >
< p class = "last" > Internally, there is just one random number generator for all
equal-style variables and one for all atom-style variables. If you
define multiple variables (of each style) which use the random() or
normal() math functions, then the internal random number generators
will only be initialized once, which means only one of the specified
seeds will determine the sequence of generated random numbers.< / p >
2015-07-30 22:53:28 +08:00
< / div >
< p > The ceil(), floor(), and round() functions are those in the C math
2010-10-07 02:12:34 +08:00
library. Ceil() is the smallest integer not less than its argument.
Floor() if the largest integer not greater than its argument. Round()
2015-07-30 22:53:28 +08:00
is the nearest integer to its argument.< / p >
< p > The ramp(x,y) function uses the current timestep to generate a value
2010-10-13 01:58:24 +08:00
linearly intepolated between the specified x,y values over the course
2015-07-30 22:53:28 +08:00
of a run, according to this formula:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "n" > value< / span > < span class = "o" > =< / span > < span class = "n" > x< / span > < span class = "o" > +< / span > < span class = "p" > (< / span > < span class = "n" > y< / span > < span class = "o" > -< / span > < span class = "n" > x< / span > < span class = "p" > )< / span > < span class = "o" > *< / span > < span class = "p" > (< / span > < span class = "n" > timestep< / span > < span class = "o" > -< / span > < span class = "n" > startstep< / span > < span class = "p" > )< / span > < span class = "o" > /< / span > < span class = "p" > (< / span > < span class = "n" > stopstep< / span > < span class = "o" > -< / span > < span class = "n" > startstep< / span > < span class = "p" > )< / span >
< / pre > < / div >
< / div >
< p > The run begins on startstep and ends on stopstep. Startstep and
stopstep can span multiple runs, using the < em > start< / em > and < em > stop< / em > keywords
of the < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command. See the < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command for
details of how to do this.< / p >
< p > The stagger(x,y) function uses the current timestep to generate a new
timestep. X,y > 0 and x > y are required. The generated timesteps
2010-10-13 01:58:24 +08:00
increase in a staggered fashion, as the sequence
x,x+y,2x,2x+y,3x,3x+y,etc. For any current timestep, the next
timestep in the sequence is returned. Thus if stagger(1000,100) is
2015-07-30 22:53:28 +08:00
used in a variable by the < a class = "reference internal" href = "dump_modify.html" > < em > dump_modify every< / em > < / a >
command, it will generate the sequence of output timesteps:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "mi" > 100< / span > < span class = "p" > ,< / span > < span class = "mi" > 1000< / span > < span class = "p" > ,< / span > < span class = "mi" > 1100< / span > < span class = "p" > ,< / span > < span class = "mi" > 2000< / span > < span class = "p" > ,< / span > < span class = "mi" > 2100< / span > < span class = "p" > ,< / span > < span class = "mi" > 3000< / span > < span class = "p" > ,< / span > < span class = "n" > etc< / span >
< / pre > < / div >
< / div >
< p > The logfreq(x,y,z) function uses the current timestep to generate a
new timestep. X,y,z > 0 and y < z are required. The generated
2014-12-23 07:37:18 +08:00
timesteps are on a base-z logarithmic scale, starting with x, and the
y value is how many of the z-1 possible timesteps within one
logarithmic interval are generated. I.e. the timesteps follow the
sequence x,2x,3x,...y*x,x*z,2x*z,3x*z,...y*x*z,x*z^2,2x*z^2,etc. For
any current timestep, the next timestep in the sequence is returned.
2015-07-30 22:53:28 +08:00
Thus if logfreq(100,4,10) is used in a variable by the < a class = "reference internal" href = "dump_modify.html" > < em > dump_modify every< / em > < / a > command, it will generate this sequence of
output timesteps:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "mi" > 100< / span > < span class = "p" > ,< / span > < span class = "mi" > 200< / span > < span class = "p" > ,< / span > < span class = "mi" > 300< / span > < span class = "p" > ,< / span > < span class = "mi" > 400< / span > < span class = "p" > ,< / span > < span class = "mi" > 1000< / span > < span class = "p" > ,< / span > < span class = "mi" > 2000< / span > < span class = "p" > ,< / span > < span class = "mi" > 3000< / span > < span class = "p" > ,< / span > < span class = "mi" > 4000< / span > < span class = "p" > ,< / span > < span class = "mi" > 10000< / span > < span class = "p" > ,< / span > < span class = "mi" > 20000< / span > < span class = "p" > ,< / span > < span class = "n" > etc< / span >
< / pre > < / div >
< / div >
< p > The logfreq2(x,y,z) function is similar to logfreq, except a single
2014-12-23 07:37:18 +08:00
logarithmic interval is divided into y equally-spaced timesteps and
2015-07-30 22:53:28 +08:00
all of them are output. Y < z is not required. Thus, if
logfreq2(100,18,10) is used in a variable by the < a class = "reference internal" href = "dump_modify.html" > < em > dump_modify every< / em > < / a > command, then the interval between 100 and
2014-12-23 07:37:18 +08:00
1000 is divided as 900/18 = 50 steps, and it will generate the
2015-07-30 22:53:28 +08:00
sequence of output timesteps:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "mi" > 100< / span > < span class = "p" > ,< / span > < span class = "mi" > 150< / span > < span class = "p" > ,< / span > < span class = "mi" > 200< / span > < span class = "p" > ,< / span > < span class = "o" > ...< / span > < span class = "mi" > 950< / span > < span class = "p" > ,< / span > < span class = "mi" > 1000< / span > < span class = "p" > ,< / span > < span class = "mi" > 1500< / span > < span class = "p" > ,< / span > < span class = "mi" > 2000< / span > < span class = "p" > ,< / span > < span class = "o" > ...< / span > < span class = "mi" > 9500< / span > < span class = "p" > ,< / span > < span class = "mi" > 10000< / span > < span class = "p" > ,< / span > < span class = "mi" > 15000< / span > < span class = "p" > ,< / span > < span class = "n" > etc< / span >
< / pre > < / div >
< / div >
< p > The stride(x,y,z) function uses the current timestep to generate a new
timestep. X,y > = 0 and z > 0 and x < = y are required. The generated
2014-11-19 23:07:55 +08:00
timesteps increase in increments of z, from x to y, i.e. it generates
2012-05-18 06:25:44 +08:00
the sequece x,x+z,x+2z,...,y. If y-x is not a multiple of z, then
similar to the way a for loop operates, the last value will be one
that does not exceed y. For any current timestep, the next timestep
2014-11-19 23:07:55 +08:00
in the sequence is returned. Thus if stride(1000,2000,100) is used
2015-07-30 22:53:28 +08:00
in a variable by the < a class = "reference internal" href = "dump_modify.html" > < em > dump_modify every< / em > < / a > command, it
will generate the sequence of output timesteps:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "mi" > 1000< / span > < span class = "p" > ,< / span > < span class = "mi" > 1100< / span > < span class = "p" > ,< / span > < span class = "mi" > 1200< / span > < span class = "p" > ,< / span > < span class = "o" > ...< / span > < span class = "p" > ,< / span > < span class = "mi" > 1900< / span > < span class = "p" > ,< / span > < span class = "mi" > 2000< / span >
< / pre > < / div >
< / div >
< p > The stride2(x,y,z,a,b,c) function is similar to the stride() function
2014-11-19 23:07:55 +08:00
except it generates two sets of strided timesteps, one at a coarser
level and one at a finer level. Thus it is useful for debugging,
e.g. to produce output every timestep at the point in simulation when
2015-07-30 22:53:28 +08:00
a problem occurs. X,y > = 0 and z > 0 and x < = y are required, as are
a,b > = 0 and c > 0 and a < b. Also, a > = x and b < = y are required so
2014-11-19 23:07:55 +08:00
that the second stride is inside the first. The generated timesteps
increase in increments of z, starting at x, until a is reached. At
that point the timestep increases in increments of c, from a to b,
then after b, increments by z are resumed until y is reached. For any
current timestep, the next timestep in the sequence is returned. Thus
if stride(1000,2000,100,1350,1360,1) is used in a variable by the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "dump_modify.html" > < em > dump_modify every< / em > < / a > command, it will generate the
sequence of output timesteps:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > 1000,1100,1200,1300,1350,1351,1352, ... 1359,1360,1400,1500, ... ,2000
< / pre > < / div >
< / div >
< p > The vdisplace(x,y) function takes 2 arguments: x = value0 and y =
2012-05-24 21:38:41 +08:00
velocity, and uses the elapsed time to change the value by a linear
displacement due to the applied velocity over the course of a run,
2015-07-30 22:53:28 +08:00
according to this formula:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "n" > value< / span > < span class = "o" > =< / span > < span class = "n" > value0< / span > < span class = "o" > +< / span > < span class = "n" > velocity< / span > < span class = "o" > *< / span > < span class = "p" > (< / span > < span class = "n" > timestep< / span > < span class = "o" > -< / span > < span class = "n" > startstep< / span > < span class = "p" > )< / span > < span class = "o" > *< / span > < span class = "n" > dt< / span >
< / pre > < / div >
< / div >
< p > where dt = the timestep size.< / p >
< p > The run begins on startstep. Startstep can span multiple runs, using
the < em > start< / em > keyword of the < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command. See the
< a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command for details of how to do this. Note that the
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a > keyword elaplong =
timestep-startstep.< / p >
< p > The swiggle(x,y,z) and cwiggle(x,y,z) functions each take 3 arguments:
2012-05-24 21:38:41 +08:00
x = value0, y = amplitude, z = period. They use the elapsed time to
oscillate the value by a sin() or cos() function over the course of a
2015-07-30 22:53:28 +08:00
run, according to one of these formulas, where omega = 2 PI / period:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > < span class = "n" > value< / span > < span class = "o" > =< / span > < span class = "n" > value0< / span > < span class = "o" > +< / span > < span class = "n" > Amplitude< / span > < span class = "o" > *< / span > < span class = "n" > sin< / span > < span class = "p" > (< / span > < span class = "n" > omega< / span > < span class = "o" > *< / span > < span class = "p" > (< / span > < span class = "n" > timestep< / span > < span class = "o" > -< / span > < span class = "n" > startstep< / span > < span class = "p" > )< / span > < span class = "o" > *< / span > < span class = "n" > dt< / span > < span class = "p" > )< / span >
< span class = "n" > value< / span > < span class = "o" > =< / span > < span class = "n" > value0< / span > < span class = "o" > +< / span > < span class = "n" > Amplitude< / span > < span class = "o" > *< / span > < span class = "p" > (< / span > < span class = "mi" > 1< / span > < span class = "o" > -< / span > < span class = "n" > cos< / span > < span class = "p" > (< / span > < span class = "n" > omega< / span > < span class = "o" > *< / span > < span class = "p" > (< / span > < span class = "n" > timestep< / span > < span class = "o" > -< / span > < span class = "n" > startstep< / span > < span class = "p" > )< / span > < span class = "o" > *< / span > < span class = "n" > dt< / span > < span class = "p" > ))< / span >
< / pre > < / div >
< / div >
< p > where dt = the timestep size.< / p >
< p > The run begins on startstep. Startstep can span multiple runs, using
the < em > start< / em > keyword of the < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command. See the
< a class = "reference internal" href = "run.html" > < em > run< / em > < / a > command for details of how to do this. Note that the
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a > keyword elaplong =
timestep-startstep.< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "group-and-region-functions" >
< h3 > Group and Region Functions< a class = "headerlink" href = "#group-and-region-functions" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Group functions are specified as keywords followed by one or two
parenthesized arguments. The first argument < em > ID< / em > is the group-ID.
The < em > dim< / em > argument, if it exists, is < em > x< / em > or < em > y< / em > or < em > z< / em > . The < em > dir< / em >
argument, if it exists, is < em > xmin< / em > , < em > xmax< / em > , < em > ymin< / em > , < em > ymax< / em > , < em > zmin< / em > , or
< em > zmax< / em > . The < em > dimdim< / em > argument, if it exists, is < em > xx< / em > or < em > yy< / em > or < em > zz< / em >
or < em > xy< / em > or < em > yz< / em > or < em > xz< / em > .< / p >
< p > The group function count() is the number of atoms in the group. The
2010-05-29 00:45:33 +08:00
group functions mass() and charge() are the total mass and charge of
the group. Xcm() and vcm() return components of the position and
velocity of the center of mass of the group. Fcm() returns a
component of the total force on the group of atoms. Bound() returns
the min/max of a particular coordinate for all atoms in the group.
Gyration() computes the radius-of-gyration of the group of atoms. See
2015-07-30 22:53:28 +08:00
the < a class = "reference internal" href = "compute_gyration.html" > < em > compute gyration< / em > < / a > command for a definition
2010-05-29 00:45:33 +08:00
of the formula. Angmom() returns components of the angular momentum
2010-11-24 22:43:25 +08:00
of the group of atoms around its center of mass. Torque() returns
components of the torque on the group of atoms around its center of
mass, based on current forces on the atoms. Inertia() returns one of
2012-11-27 22:41:21 +08:00
6 components of the symmetric inertia tensor of the group of atoms
around its center of mass, ordered as Ixx,Iyy,Izz,Ixy,Iyz,Ixz.
Omega() returns components of the angular velocity of the group of
2015-07-30 22:53:28 +08:00
atoms around its center of mass.< / p >
< p > Region functions are specified exactly the same way as group functions
except they take an extra final argument < em > IDR< / em > which is the region ID.
2014-10-28 01:32:33 +08:00
The function is computed for all atoms that are in both the group and
2015-07-30 22:53:28 +08:00
the region. If the group is “ all” , then the only criteria for atom
inclusion is that it be in the region.< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "special-functions" >
< h3 > Special Functions< a class = "headerlink" href = "#special-functions" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Special functions take specific kinds of arguments, meaning their
arguments cannot be formulas themselves.< / p >
< p > The sum(x), min(x), max(x), ave(x), trap(x), and slope(x) functions
each take 1 argument which is of the form “ c_ID” or “ c_ID[N]” or
“ f_ID” or “ f_ID[N]” . The first two are computes and the second two
2014-02-05 02:59:28 +08:00
are fixes; the ID in the reference should be replaced by the ID of a
compute or fix defined elsewhere in the input script. The compute or
fix must produce either a global vector or array. If it produces a
2015-07-30 22:53:28 +08:00
global vector, then the notation without “ [N]” should be used. If
it produces a global array, then the notation with “ [N]” should be
2010-08-18 05:58:29 +08:00
used, when N is an integer, to specify which column of the global
2015-07-30 22:53:28 +08:00
array is being referenced.< / p >
< p > These functions operate on the global vector of inputs and reduce it
2010-10-13 23:00:13 +08:00
to a single scalar value. This is analagous to the operation of the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "compute_reduce.html" > < em > compute reduce< / em > < / a > command, which invokes the same
functions on per-atom and local vectors.< / p >
< p > The sum() function calculates the sum of all the vector elements. The
2010-08-18 05:58:29 +08:00
min() and max() functions find the minimum and maximum element
respectively. The ave() function is the same as sum() except that it
2015-07-30 22:53:28 +08:00
divides the result by the length of the vector.< / p >
< p > The trap() function is the same as sum() except the first and last
2014-02-05 02:59:28 +08:00
elements are multiplied by a weighting factor of 1/2 when performing
the sum. This effectively implements an integration via the
trapezoidal rule on the global vector of data. I.e. consider a set of
points, equally spaced by 1 in their x coordinate: (1,V1), (2,V2),
..., (N,VN), where the Vi are the values in the global vector of
length N. The integral from 1 to N of these points is trap(). When
appropriately normalized by the timestep size, this function is useful
for calculating integrals of time-series data, like that generated by
2015-07-30 22:53:28 +08:00
the < a class = "reference internal" href = "fix_ave_correlate.html" > < em > fix ave/correlate< / em > < / a > command.< / p >
< p > The slope() function uses linear regression to fit a line to the set
2014-02-05 02:59:28 +08:00
of points, equally spaced by 1 in their x coordinate: (1,V1), (2,V2),
..., (N,VN), where the Vi are the values in the global vector of
length N. The returned value is the slope of the line. If the line
2015-07-30 22:53:28 +08:00
has a single point or is vertical, it returns 1.0e20.< / p >
< p > The gmask(x) function takes 1 argument which is a group ID. It
2010-10-13 23:00:13 +08:00
can only be used in atom-style variables. It returns a 1 for
2015-07-30 22:53:28 +08:00
atoms that are in the group, and a 0 for atoms that are not.< / p >
< p > The rmask(x) function takes 1 argument which is a region ID. It can
2010-10-13 23:00:13 +08:00
only be used in atom-style variables. It returns a 1 for atoms that
2015-07-30 22:53:28 +08:00
are in the geometric region, and a 0 for atoms that are not.< / p >
< p > The grmask(x,y) function takes 2 arguments. The first is a group ID,
2010-10-13 23:00:13 +08:00
and the second is a region ID. It can only be used in atom-style
variables. It returns a 1 for atoms that are in both the group and
2015-07-30 22:53:28 +08:00
region, and a 0 for atoms that are not in both.< / p >
< p > The next(x) function takes 1 argument which is a variable ID (not
“ v_foo” , just “ foo” ). It must be for a file-style or atomfile-style
2013-07-25 04:47:56 +08:00
variable. Each time the next() function is invoked (i.e. each time
the equal-style or atom-style variable is evaluated), the following
2015-07-30 22:53:28 +08:00
steps occur.< / p >
< p > For file-style variables, the current string value stored by the
2013-07-25 04:47:56 +08:00
file-style variable is converted to a numeric value and returned by
the function. And the next string value in the file is read and
stored. Note that if the line previously read from the file was not a
numeric string, then it will typically evaluate to 0.0, which is
2015-07-30 22:53:28 +08:00
likely not what you want.< / p >
< p > For atomfile-style variables, the current per-atom values stored by
2013-07-25 04:47:56 +08:00
the atomfile-style variable are returned by the function. And the
2015-07-30 22:53:28 +08:00
next set of per-atom values in the file is read and stored.< / p >
< p > Since file-style and atomfile-style variables read and store the first
2013-07-25 04:47:56 +08:00
line of the file or first set of per-atoms values when they are
defined in the input script, these are the value(s) that will be
returned the first time the next() function is invoked. If next() is
invoked more times than there are lines or sets of lines in the file,
2015-07-30 22:53:28 +08:00
the variable is deleted, similar to how the < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > command
operates.< / p >
< / div >
< hr class = "docutils" / >
2015-09-25 04:29:42 +08:00
< div class = "section" id = "feature-functions" >
< h3 > Feature Functions< a class = "headerlink" href = "#feature-functions" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Feature functions allow to probe the running LAMMPS executable for
whether specific features are either active, defined, or available.
The functions take two arguments, a < em > category< / em > and a corresponding
< em > argument< / em > . The arguments are strings thus cannot be formulas
themselves (only $-style immediate variable expansion is possible).
Return value is either 1.0 or 0.0 depending on whether the function
evaluates to true or false, respectively.< / p >
< p > The < em > is_active()< / em > function allows to query for active settings which
are grouped by categories. Currently supported categories and
arguments are:< / p >
< ul class = "simple" >
< li > < em > package< / em > (argument = < em > cuda< / em > or < em > gpu< / em > or < em > intel< / em > or < em > kokkos< / em > or < em > omp< / em > )< / li >
< li > < em > newton< / em > (argument = < em > pair< / em > or < em > bond< / em > or < em > any< / em > )< / li >
< li > < em > pair< / em > (argument = < em > single< / em > or < em > respa< / em > or < em > manybody< / em > or < em > tail< / em > or < em > shift< / em > )< / li >
< li > < em > comm_style< / em > (argument = < em > brick< / em > or < em > tiled< / em > )< / li >
< li > < em > min_style< / em > (argument = any of the compiled in minimizer styles)< / li >
< li > < em > run_style< / em > (argument = any of the compiled in run styles)< / li >
< li > < em > atom_style< / em > (argument = any of the compiled in atom styles)< / li >
< li > < em > pair_style< / em > (argument = any of the compiled in pair styles)< / li >
< li > < em > bond_style< / em > (argument = any of the compiled in bond styles)< / li >
< li > < em > angle_style< / em > (argument = any of the compiled in angle styles)< / li >
< li > < em > dihedral_style< / em > (argument = any of the compiled in dihedral styles)< / li >
< li > < em > improper_style< / em > (argument = any of the compiled in improper styles)< / li >
< li > < em > kspace_style< / em > (argument = any of the compiled in kspace styles)< / li >
< / ul >
< p > Most of the settings are self-explanatory, the < em > single< / em > argument in the
< em > pair< / em > category allows to check whether a pair style supports a
Pair::single() function as needed by compute group/group and others
features or LAMMPS, < em > respa< / em > allows to check whether the inner/middle/outer
mode of r-RESPA is supported. In the various style categories,
the checking is also done using suffix flags, if available and enabled.< / p >
< p > Example 1: disable use of suffix for pppm when using GPU package (i.e. run it on the CPU concurrently to running the pair style on the GPU), but do use the suffix otherwise (e.g. with USER-OMP).< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > pair_style lj/cut/coul/long 14.0
if $(is_active(package,gpu)) then " suffix off"
kspace_style pppm
< / pre > < / div >
< / div >
< p > Example 2: use r-RESPA with inner/outer cutoff, if supported by pair style, otherwise fall back to using pair and reducing the outer time step< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > timestep $(2.0*(1.0+*is_active(pair,respa))
if $(is_active(pair,respa)) then " run_style respa 4 3 2 2 improper 1 inner 2 5.5 7.0 outer 3 kspace 4" else " run_style respa 3 3 2 improper 1 pair 2 kspace 3"
< / pre > < / div >
< / div >
< p > The < em > is_defined()< / em > function allows to query categories like < em > compute< / em > ,
< em > dump< / em > , < em > fix< / em > , < em > group< / em > , < em > region< / em > , and < em > variable< / em > whether an entry
with the provided name or id is defined.< / p >
< p > The < em > is_available()< / em > function allows to query whether a specific
optional feature is available, i.e. compiled in. This currently
works for the following categories: < em > command< / em > , < em > compute< / em > , < em > fix< / em > ,
and < em > pair_style< / em > . For all categories except < em > command< / em > also appending
active suffixes is tried before reporting failure.< / p >
< / div >
< hr class = "docutils" / >
2015-07-30 22:53:28 +08:00
< div class = "section" id = "atom-values-and-vectors" >
< h3 > Atom Values and Vectors< a class = "headerlink" href = "#atom-values-and-vectors" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Atom values take an integer argument I from 1 to N, where I is the
2014-05-03 01:31:04 +08:00
atom-ID, e.g. x[243], which means use the x coordinate of the atom
with ID = 243. Or they can take a variable name, specified as v_name,
where name is the name of the variable, like x[v_myIndex]. The
variable can be of any style except atom or atom-file variables. The
variable is evaluated and the result is expected to be numeric and is
cast to an integer (i.e. 3.4 becomes 3), to use an an index, which
2015-07-30 22:53:28 +08:00
must be a value from 1 to N. Note that a “ formula” cannot be used as
2014-05-03 01:31:04 +08:00
the argument between the brackets, e.g. x[243+10] or
x[v_myIndex+1] are not allowed. To do this a single variable can be
2015-07-30 22:53:28 +08:00
defined that contains the needed formula.< / p >
< p > Note that the 0 < atom-ID < = N, where N is the largest atom ID
2014-12-17 23:51:50 +08:00
in the system. If an ID is specified for an atom that does not
2015-07-30 22:53:28 +08:00
currently exist, then the generated value is 0.0.< / p >
< p > Atom vectors generate one value per atom, so that a reference like
“ vx” means the x-component of each atom’ s velocity will be used when
evaluating the variable.< / p >
< p > The meaning of the different atom values and vectors is mostly
2014-05-02 23:34:15 +08:00
self-explanatory. Mol refers to the molecule ID of an atom, and is
2015-07-30 22:53:28 +08:00
only defined if an < a class = "reference internal" href = "atom_style.html" > < em > atom_style< / em > < / a > is being used that
defines molecule IDs.< / p >
< p > Note that many other atom attributes can be used as inputs to a
variable by using the < a class = "reference internal" href = "compute_property_atom.html" > < em > compute property/atom< / em > < / a > command and then specifying
a quantity from that compute.< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "compute-references" >
< h3 > Compute References< a class = "headerlink" href = "#compute-references" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Compute references access quantities calculated by a
< a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > . The ID in the reference should be replaced by
2009-12-10 05:20:59 +08:00
the ID of a compute defined elsewhere in the input script. As
2015-07-30 22:53:28 +08:00
discussed in the doc page for the < a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > command,
2009-12-10 05:20:59 +08:00
computes can produce global, per-atom, or local values. Only global
and per-atom values can be used in a variable. Computes can also
2010-08-11 22:30:24 +08:00
produce a scalar, vector, or array. An equal-style variable can only
use scalar values, which means a global scalar, or an element of a
global or per-atom vector or array. Atom-style variables can use the
same scalar values. They can also use per-atom vector values. A
vector value can be a per-atom vector itself, or a column of an
per-atom array. See the doc pages for individual computes to see what
2015-07-30 22:53:28 +08:00
kind of values they produce.< / p >
< p > Examples of different kinds of compute references are as follows.
2009-12-10 05:20:59 +08:00
There is no ambiguity as to what a reference means, since computes
2015-07-30 22:53:28 +08:00
only produce global or per-atom quantities, never both.< / p >
< table border = "1" class = "docutils" >
< colgroup >
< col width = "10%" / >
< col width = "90%" / >
< / colgroup >
< tbody valign = "top" >
< tr class = "row-odd" > < td > c_ID< / td >
< td > global scalar, or per-atom vector< / td >
< / tr >
< tr class = "row-even" > < td > c_ID[I]< / td >
< td > Ith element of global vector, or atom I’ s value in per-atom vector, or Ith column from per-atom array< / td >
< / tr >
< tr class = "row-odd" > < td > c_ID[I][J]< / td >
< td > I,J element of global array, or atom I’ s Jth value in per-atom array< / td >
< / tr >
< / tbody >
< / table >
< p > For I and J, integers can be specified or a variable name, specified
2014-05-03 01:31:04 +08:00
as v_name, where name is the name of the variable. The rules for this
2015-07-30 22:53:28 +08:00
syntax are the same as for the “ Atom Values and Vectors” discussion
above.< / p >
< p > If a variable containing a compute is evaluated directly in an input
2014-05-03 01:31:04 +08:00
script (not during a run), then the values accessed by the compute
2015-07-30 22:53:28 +08:00
must be current. See the discussion below about “ Variable Accuracy” .< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "fix-references" >
< h3 > Fix References< a class = "headerlink" href = "#fix-references" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Fix references access quantities calculated by a < a class = "reference internal" href = "compute.html" > < em > fix< / em > < / a > .
2009-12-10 05:20:59 +08:00
The ID in the reference should be replaced by the ID of a fix defined
elsewhere in the input script. As discussed in the doc page for the
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "fix.html" > < em > fix< / em > < / a > command, fixes can produce global, per-atom, or local
2009-12-10 05:20:59 +08:00
values. Only global and per-atom values can be used in a variable.
Fixes can also produce a scalar, vector, or array. An equal-style
2010-08-11 22:30:24 +08:00
variable can only use scalar values, which means a global scalar, or
an element of a global or per-atom vector or array. Atom-style
variables can use the same scalar values. They can also use per-atom
vector values. A vector value can be a per-atom vector itself, or a
column of an per-atom array. See the doc pages for individual fixes
2015-07-30 22:53:28 +08:00
to see what kind of values they produce.< / p >
< p > The different kinds of fix references are exactly the same as the
compute references listed in the above table, where “ < a href = "#id1" > < span class = "problematic" id = "id2" > c_< / span > < / a > ” is replaced
by “ < a href = "#id3" > < span class = "problematic" id = "id4" > f_< / span > < / a > ” . Again, there is no ambiguity as to what a reference means,
since fixes only produce global or per-atom quantities, never both.< / p >
< table border = "1" class = "docutils" >
< colgroup >
< col width = "10%" / >
< col width = "90%" / >
< / colgroup >
< tbody valign = "top" >
< tr class = "row-odd" > < td > f_ID< / td >
< td > global scalar, or per-atom vector< / td >
< / tr >
< tr class = "row-even" > < td > f_ID[I]< / td >
< td > Ith element of global vector, or atom I’ s value in per-atom vector, or Ith column from per-atom array< / td >
< / tr >
< tr class = "row-odd" > < td > f_ID[I][J]< / td >
< td > I,J element of global array, or atom I’ s Jth value in per-atom array< / td >
< / tr >
< / tbody >
< / table >
< p > For I and J, integers can be specified or a variable name, specified
2014-05-03 01:31:04 +08:00
as v_name, where name is the name of the variable. The rules for this
2015-07-30 22:53:28 +08:00
syntax are the same as for the “ Atom Values and Vectors” discussion
above.< / p >
< p > If a variable containing a fix is evaluated directly in an input
2009-12-10 05:20:59 +08:00
script (not during a run), then the values accessed by the fix should
2015-07-30 22:53:28 +08:00
be current. See the discussion below about “ Variable Accuracy” .< / p >
< p > Note that some fixes only generate quantities on certain timesteps.
2008-01-09 07:13:53 +08:00
If a variable attempts to access the fix on non-allowed timesteps, an
2015-07-30 22:53:28 +08:00
error is generated. For example, the < a class = "reference internal" href = "fix_ave_time.html" > < em > fix ave/time< / em > < / a >
2008-01-09 07:13:53 +08:00
command may only generate averaged quantities every 100 steps. See
2015-07-30 22:53:28 +08:00
the doc pages for individual fix commands for details.< / p >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "variable-references" >
< h3 > Variable References< a class = "headerlink" href = "#variable-references" title = "Permalink to this headline" > ¶< / a > < / h3 >
< p > Variable references access quantities stored or calculated by other
2012-11-10 09:17:45 +08:00
variables, which will cause those variables to be evaluated. The name
in the reference should be replaced by the name of a variable defined
2015-07-30 22:53:28 +08:00
elsewhere in the input script.< / p >
< p > As discussed on this doc page, equal-style variables generate a global
2013-07-25 04:47:56 +08:00
scalar numeric value; atom-style and atomfile-style variables generate
a per-atom vector of numeric values; all other variables store a
string. The formula for an equal-style variable can use any style of
variable except an atom-style or atomfile-style (unless only a single
value from the variable is accessed via a subscript). If a
string-storing variable is used, the string is converted to a numeric
value. Note that this will typically produce a 0.0 if the string is
not a numeric string, which is likely not what you want. The formula
for an atom-style variable can use any style of variable, including
2015-07-30 22:53:28 +08:00
other atom-style or atomfile-style variables.< / p >
< p > Examples of different kinds of variable references are as follows.
2009-12-10 05:20:59 +08:00
There is no ambiguity as to what a reference means, since variables
2015-07-30 22:53:28 +08:00
produce only a global scalar or a per-atom vector, never both.< / p >
< table border = "1" class = "docutils" >
< colgroup >
< col width = "24%" / >
< col width = "76%" / >
< / colgroup >
< tbody valign = "top" >
< tr class = "row-odd" > < td > v_name< / td >
< td > scalar, or per-atom vector< / td >
< / tr >
< tr class = "row-even" > < td > v_name[I]< / td >
< td > atom I’ s value in per-atom vector< / td >
< / tr >
< / tbody >
< / table >
< p > For I, an integer can be specified or a variable name, specified as
2014-05-03 01:31:04 +08:00
v_name, where name is the name of the variable. The rules for this
2015-07-30 22:53:28 +08:00
syntax are the same as for the “ Atom Values and Vectors” discussion
above.< / p >
< hr class = "docutils" / >
< p > < strong > Immediate Evaluation of Variables:< / strong > < / p >
< p > If you want an equal-style variable to be evaluated immediately, it
2014-07-31 22:28:22 +08:00
may be the case that you do not need to define a variable at all. See
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "Section_commands.html#cmd-2" > < span > Section 3.2< / span > < / a > of the manual, which
describes the use of “ immediate” variables in an input script,
2014-07-31 22:28:22 +08:00
specified as $(formula) with parenthesis, where the formula has the
same syntax as equal-style variables described on this page. This
effectively evaluates a formula immediately without using the variable
2015-07-30 22:53:28 +08:00
command to define a named variable.< / p >
< p > More generally, there is a difference between referencing a variable
with a leading $ sign (e.g. $x or ${abc}) versus with a leading “ < a href = "#id5" > < span class = "problematic" id = "id6" > v_< / span > < / a > ”
2014-07-31 22:28:22 +08:00
(e.g. v_x or v_abc). The former can be used in any input script
command, including a variable command. The input script parser
evaluates the reference variable immediately and substitutes its value
2015-07-30 22:53:28 +08:00
into the command. As explained in < span class = "xref std std-ref" > Section commands 3.2< / span > for “ Parsing rules” , you can also use
un-named “ immediate” variables for this purpose. For example, a
2014-07-31 22:28:22 +08:00
string like this $((xlo+xhi)/2+sqrt(v_area)) in an input script
command evaluates the string between the parenthesis as an equal-style
2015-07-30 22:53:28 +08:00
variable formula.< / p >
< p > Referencing a variable with a leading “ < a href = "#id7" > < span class = "problematic" id = "id8" > v_< / span > < / a > ” is an optional or required
kind of argument for some commands (e.g. the < a class = "reference internal" href = "fix_ave_spatial.html" > < em > fix ave/spatial< / em > < / a > or < a class = "reference internal" href = "dump.html" > < em > dump custom< / em > < / a > or
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a > commands) if you wish it to evaluate
2009-01-06 06:26:31 +08:00
a variable periodically during a run. It can also be used in a
variable formula if you wish to reference a second variable. The
second variable will be evaluated whenever the first variable is
2015-07-30 22:53:28 +08:00
evaluated.< / p >
< p > As an example, suppose you use this command in your input script to
define the variable “ v” as< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable v equal vol
< / pre > < / div >
< / div >
< p > before a run where the simulation box size changes. You might think
this will assign the initial volume to the variable “ v” . That is not
2009-01-06 06:26:31 +08:00
the case. Rather it assigns a formula which evaluates the volume
2015-07-30 22:53:28 +08:00
(using the thermo_style keyword “ vol” ) to the variable “ v” . If you
use the variable “ v” in some other command like < a class = "reference internal" href = "fix_ave_time.html" > < em > fix ave/time< / em > < / a > then the current volume of the box will be
evaluated continuously during the run.< / p >
< p > If you want to store the initial volume of the system, you can do it
this way:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable v equal vol
variable v0 equal $v
< / pre > < / div >
< / div >
< p > The second command will force “ v” to be evaluated (yielding the
initial volume) and assign that value to the variable “ v0” . Thus the
command< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > thermo_style custom step v_v v_v0
< / pre > < / div >
< / div >
< p > would print out both the current and initial volume periodically
during the run.< / p >
< p > Note that it is a mistake to enclose a variable formula in double
quotes if it contains variables preceeded by $ signs. For example,< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable vratio equal " ${vfinal}/${v0}"
< / pre > < / div >
< / div >
< p > This is because the quotes prevent variable substitution (see < a class = "reference internal" href = "Section_commands.html#cmd-2" > < span > this section< / span > < / a > on parsing input script
commands), and thus an error will occur when the formula for “ vratio”
is evaluated later.< / p >
< hr class = "docutils" / >
< p > < strong > Variable Accuracy:< / strong > < / p >
< p > Obviously, LAMMPS attempts to evaluate variables containing formulas
(< em > equal< / em > and < em > atom< / em > style variables) accurately whenever the
2009-01-06 06:26:31 +08:00
evaluation is performed. Depending on what is included in the
2015-07-30 22:53:28 +08:00
formula, this may require invoking a < a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > , either
2009-01-06 06:26:31 +08:00
directly or indirectly via a thermo keyword, or accessing a value
2009-02-17 22:58:00 +08:00
previously calculated by a compute, or accessing a value calculated
2015-07-30 22:53:28 +08:00
and stored by a < a class = "reference internal" href = "fix.html" > < em > fix< / em > < / a > . If the compute is one that calculates
2009-02-17 22:58:00 +08:00
the pressure or energy of the system, then these quantities need to be
tallied during the evaluation of the interatomic potentials (pair,
2015-07-30 22:53:28 +08:00
bond, etc) on timesteps that the variable will need the values.< / p >
< p > LAMMPS keeps track of all of this during a < a class = "reference internal" href = "run.html" > < em > run< / em > < / a > or < a class = "reference internal" href = "minimize.html" > < em > energy minimization< / em > < / a > . An error will be generated if you
2009-01-06 06:26:31 +08:00
attempt to evaluate a variable on timesteps when it cannot produce
2015-07-30 22:53:28 +08:00
accurate values. For example, if a < a class = "reference internal" href = "thermo_style.html" > < em > thermo_style custom< / em > < / a > command prints a variable which accesses
values stored by a < a class = "reference internal" href = "fix_ave_time.html" > < em > fix ave/time< / em > < / a > command and the
2009-01-06 06:26:31 +08:00
timesteps on which thermo output is generated are not multiples of the
2015-07-30 22:53:28 +08:00
averaging frequency used in the fix command, then an error will occur.< / p >
< p > An input script can also request variables be evaluated before or
2009-02-17 22:58:00 +08:00
after or in between runs, e.g. by including them in a
2015-07-30 22:53:28 +08:00
< a class = "reference internal" href = "print.html" > < em > print< / em > < / a > command. In this case, if a compute is needed to
2009-02-17 22:58:00 +08:00
evaluate a variable (either directly or indirectly), LAMMPS will not
invoke the compute, but it will use a value previously calculated by
2014-03-18 06:52:40 +08:00
the compute, and can do this only if it was invoked on the current
timestep. Fixes will always provide a quantity needed by a variable,
but the quantity may or may not be current. This leads to one of
2015-07-30 22:53:28 +08:00
three kinds of behavior:< / p >
< p > (1) The variable may be evaluated accurately. If it contains
2009-02-17 22:58:00 +08:00
references to a compute or fix, and these values were calculated on
the last timestep of a preceeding run, then they will be accessed and
2015-07-30 22:53:28 +08:00
used by the variable and the result will be accurate.< / p >
< p > (2) LAMMPS may not be able to evaluate the variable and will generate
2012-08-28 23:27:10 +08:00
an error message stating so. For example, if the variable requires a
2015-07-30 22:53:28 +08:00
quantity from a < a class = "reference internal" href = "compute.html" > < em > compute< / em > < / a > that has not been invoked on
2014-03-18 06:52:40 +08:00
the current timestep, LAMMPS will generate an error. This means, for
example, that such a variable cannot be evaluated before the first run
has occurred. Likewise, in between runs, a variable containing a
compute cannot be evaluated unless the compute was invoked on the last
2015-07-30 22:53:28 +08:00
timestep of the preceding run, e.g. by thermodynamic output.< / p >
< p > One way to get around this problem is to perform a 0-timestep run
before using the variable. For example, these commands< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > variable t equal temp
print " Initial temperature = $t"
run 1000
< / pre > < / div >
< / div >
< p > will generate an error if the run is the first run specified in the
input script, because generating a value for the “ t” variable requires
a compute for calculating the temperature to be invoked.< / p >
< p > However, this sequence of commands would be fine:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > run 0
2009-01-06 06:26:31 +08:00
variable t equal temp
2015-07-30 22:53:28 +08:00
print " Initial temperature = $t"
run 1000
< / pre > < / div >
< / div >
< p > The 0-timestep run initializes and invokes various computes, including
2009-01-06 06:26:31 +08:00
the one for temperature, so that the value it stores is current and
2015-07-30 22:53:28 +08:00
can be accessed by the variable “ t” after the run has completed. Note
2009-01-06 06:26:31 +08:00
that a 0-timestep run does not alter the state of the system, so it
does not change the input state for the 1000-timestep run that
2009-02-17 22:58:00 +08:00
follows. Also note that the 0-timestep run must actually use and
2015-07-30 22:53:28 +08:00
invoke the compute in question (e.g. via < a class = "reference internal" href = "thermo_style.html" > < em > thermo< / em > < / a > or
< a class = "reference internal" href = "dump.html" > < em > dump< / em > < / a > output) in order for it to enable the compute to be
2010-05-06 04:19:26 +08:00
used in a variable after the run. Thus if you are trying to print a
2014-03-18 06:52:40 +08:00
variable that uses a compute you have defined, you can insure it is
2010-05-06 04:19:26 +08:00
invoked on the last timestep of the preceding run by including it in
2015-07-30 22:53:28 +08:00
thermodynamic output.< / p >
< p > Unlike computes, < a class = "reference internal" href = "fix.html" > < em > fixes< / em > < / a > will never generate an error if
2009-02-17 22:58:00 +08:00
their values are accessed by a variable in between runs. They always
return some value to the variable. However, the value may not be what
you expect if the fix has not yet calculated the quantity of interest
2015-07-30 22:53:28 +08:00
or it is not current. For example, the < a class = "reference internal" href = "fix_indent.html" > < em > fix indent< / em > < / a >
2009-01-06 06:26:31 +08:00
command stores the force on the indenter. But this is not computed
until a run is performed. Thus if a variable attempts to print this
2009-02-17 22:58:00 +08:00
value before the first run, zeroes will be output. Again, performing
2015-07-30 22:53:28 +08:00
a 0-timestep run before printing the variable has the desired effect.< / p >
< p > (3) The variable may be evaluated incorrectly and LAMMPS may have no
2012-08-28 23:27:10 +08:00
way to detect this has occurred. Consider the following sequence of
2015-07-30 22:53:28 +08:00
commands:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > pair_coeff 1 1 1.0 1.0
2009-01-06 06:26:31 +08:00
run 1000
pair_coeff 1 1 1.5 1.0
variable e equal pe
2015-07-30 22:53:28 +08:00
print " Final potential energy = $e"
< / pre > < / div >
< / div >
< p > The first run is performed using one setting for the pairwise
potential defined by the < a class = "reference internal" href = "pair_style.html" > < em > pair_style< / em > < / a > and
< a class = "reference internal" href = "pair_coeff.html" > < em > pair_coeff< / em > < / a > commands. The potential energy is
evaluated on the final timestep and stored by the < a class = "reference internal" href = "compute_pe.html" > < em > compute pe< / em > < / a > compute (this is done by the
< a class = "reference internal" href = "thermo_style.html" > < em > thermo_style< / em > < / a > command). Then a pair coefficient is
2009-01-06 06:26:31 +08:00
changed, altering the potential energy of the system. When the
2015-07-30 22:53:28 +08:00
potential energy is printed via the “ e” variable, LAMMPS will use the
potential energy value stored by the < a class = "reference internal" href = "compute_pe.html" > < em > compute pe< / em > < / a >
2009-01-06 06:26:31 +08:00
compute, thinking it is current. There are many other commands which
could alter the state of the system between runs, causing a variable
2015-07-30 22:53:28 +08:00
to evaluate incorrectly.< / p >
< p > The solution to this issue is the same as for case (2) above, namely
2009-02-17 22:58:00 +08:00
perform a 0-timestep run before the variable is evaluated to insure
2009-01-06 06:26:31 +08:00
the system is up-to-date. For example, this sequence of commands
would print a potential energy that reflected the changed pairwise
2015-07-30 22:53:28 +08:00
coefficient:< / p >
< div class = "highlight-python" > < div class = "highlight" > < pre > pair_coeff 1 1 1.0 1.0
2009-01-06 06:26:31 +08:00
run 1000
pair_coeff 1 1 1.5 1.0
run 0
variable e equal pe
2015-07-30 22:53:28 +08:00
print " Final potential energy = $e"
< / pre > < / div >
< / div >
< / div >
< / div >
< hr class = "docutils" / >
< div class = "section" id = "restrictions" >
< h2 > Restrictions< a class = "headerlink" href = "#restrictions" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > Indexing any formula element by global atom ID, such as an atom value,
2008-01-09 07:13:53 +08:00
requires the atom style to use a global mapping in order to look up
the vector indices. By default, only atom styles with molecular
2015-07-30 22:53:28 +08:00
information create global maps. The < a class = "reference internal" href = "atom_modify.html" > < em > atom_modify map< / em > < / a > command can override the default.< / p >
< p > All < em > universe< / em > - and < em > uloop< / em > -style variables defined in an input script
must have the same number of values.< / p >
< / div >
< div class = "section" id = "related-commands" >
< h2 > Related commands< a class = "headerlink" href = "#related-commands" title = "Permalink to this headline" > ¶< / a > < / h2 >
< p > < a class = "reference internal" href = "next.html" > < em > next< / em > < / a > , < a class = "reference internal" href = "jump.html" > < em > jump< / em > < / a > , < a class = "reference internal" href = "include.html" > < em > include< / em > < / a > ,
< a class = "reference internal" href = "temper.html" > < em > temper< / em > < / a > , < a class = "reference internal" href = "fix_print.html" > < em > fix print< / em > < / a > , < a class = "reference internal" href = "print.html" > < em > print< / em > < / a > < / p >
< p > < strong > Default:< / strong > none< / p >
< / div >
< / div >
< / div >
< / div >
< footer >
< hr / >
< div role = "contentinfo" >
< p >
2015-12-11 01:23:56 +08:00
© Copyright 2013 Sandia Corporation.
2015-07-30 22:53:28 +08:00
< / p >
< / div >
Built with < a href = "http://sphinx-doc.org/" > Sphinx< / a > using a < a href = "https://github.com/snide/sphinx_rtd_theme" > theme< / a > provided by < a href = "https://readthedocs.org" > Read the Docs< / a > .
< / footer >
< / div >
< / div >
< / section >
< / div >
< script type = "text/javascript" >
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
2015-12-21 23:20:41 +08:00
VERSION:'',
2015-07-30 22:53:28 +08:00
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
< / script >
< script type = "text/javascript" src = "_static/jquery.js" > < / script >
< script type = "text/javascript" src = "_static/underscore.js" > < / script >
< script type = "text/javascript" src = "_static/doctools.js" > < / script >
< script type = "text/javascript" src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" > < / script >
< script type = "text/javascript" src = "_static/sphinxcontrib-images/LightBox2/lightbox2/js/jquery-1.11.0.min.js" > < / script >
< script type = "text/javascript" src = "_static/sphinxcontrib-images/LightBox2/lightbox2/js/lightbox.min.js" > < / script >
< script type = "text/javascript" src = "_static/sphinxcontrib-images/LightBox2/lightbox2-customize/jquery-noconflict.js" > < / script >
< script type = "text/javascript" src = "_static/js/theme.js" > < / script >
< script type = "text/javascript" >
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
< / script >
< / body >
< / html >