467 lines
37 KiB
HTML
467 lines
37 KiB
HTML
<!DOCTYPE html>
|
|
<html class="writer-html5" lang="en" >
|
|
<head>
|
|
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>if command — LAMMPS documentation</title>
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/sphinx-design.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/css/lammps.css" type="text/css" />
|
|
<link rel="shortcut icon" href="_static/lammps.ico"/>
|
|
<link rel="canonical" href="https://docs.lammps.org/if.html" />
|
|
<!--[if lt IE 9]>
|
|
<script src="_static/js/html5shiv.min.js"></script>
|
|
<![endif]-->
|
|
|
|
<script src="_static/jquery.js?v=5d32c60e"></script>
|
|
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
|
|
<script src="_static/documentation_options.js?v=5929fcd5"></script>
|
|
<script src="_static/doctools.js?v=9bcbadda"></script>
|
|
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
|
|
<script src="_static/design-tabs.js?v=f930bc37"></script>
|
|
<script async="async" src="_static/mathjax/es5/tex-mml-chtml.js?v=cadf963e"></script>
|
|
<script src="_static/js/theme.js"></script>
|
|
<link rel="index" title="Index" href="genindex.html" />
|
|
<link rel="search" title="Search" href="search.html" />
|
|
<link rel="next" title="improper_coeff command" href="improper_coeff.html" />
|
|
<link rel="prev" title="hyper command" href="hyper.html" />
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav">
|
|
<div class="wy-grid-for-nav">
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search" >
|
|
|
|
|
|
|
|
<a href="Manual.html">
|
|
|
|
<img src="_static/lammps-logo.png" class="logo" alt="Logo"/>
|
|
</a>
|
|
<div class="lammps_version">Version: <b>19 Nov 2024</b></div>
|
|
<div class="lammps_release">git info: </div>
|
|
<div role="search">
|
|
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
|
<input type="text" name="q" placeholder="Search docs" aria-label="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="Navigation menu">
|
|
<p class="caption" role="heading"><span class="caption-text">User Guide</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="Intro.html">1. Introduction</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Install.html">2. Install LAMMPS</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Build.html">3. Build LAMMPS</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Run_head.html">4. Run LAMMPS</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Commands.html">5. Commands</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Packages.html">6. Optional packages</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Speed.html">7. Accelerate performance</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Howto.html">8. Howto discussions</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Examples.html">9. Example scripts</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Tools.html">10. Auxiliary tools</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Errors.html">11. Errors</a></li>
|
|
</ul>
|
|
<p class="caption" role="heading"><span class="caption-text">Programmer Guide</span></p>
|
|
<ul>
|
|
<li class="toctree-l1"><a class="reference internal" href="Library.html">1. LAMMPS Library Interfaces</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Python_head.html">2. Use Python with LAMMPS</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Modify.html">3. Modifying & extending LAMMPS</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Developer.html">4. Information for Developers</a></li>
|
|
</ul>
|
|
<p class="caption" role="heading"><span class="caption-text">Command Reference</span></p>
|
|
<ul class="current">
|
|
<li class="toctree-l1 current"><a class="reference internal" href="commands_list.html">Commands</a><ul class="current">
|
|
<li class="toctree-l2"><a class="reference internal" href="angle_coeff.html">angle_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="angle_style.html">angle_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="angle_write.html">angle_write command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="atom_modify.html">atom_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="atom_style.html">atom_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="balance.html">balance command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="bond_coeff.html">bond_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="bond_style.html">bond_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="bond_write.html">bond_write command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="boundary.html">boundary command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="change_box.html">change_box command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="clear.html">clear command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="comm_modify.html">comm_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="comm_style.html">comm_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="compute.html">compute command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="compute_modify.html">compute_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="create_atoms.html">create_atoms command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="create_bonds.html">create_bonds command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="create_box.html">create_box command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="delete_atoms.html">delete_atoms command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="delete_bonds.html">delete_bonds command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dielectric.html">dielectric command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dihedral_coeff.html">dihedral_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dihedral_style.html">dihedral_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dihedral_write.html">dihedral_write command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dimension.html">dimension command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="displace_atoms.html">displace_atoms command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="dynamical_matrix.html">dynamical_matrix command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="echo.html">echo command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="fix.html">fix command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="fix_modify.html">fix_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="fitpod_command.html">fitpod command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="geturl.html">geturl command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="group.html">group command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="group2ndx.html">group2ndx command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="group2ndx.html#ndx2group-command">ndx2group command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="hyper.html">hyper command</a></li>
|
|
<li class="toctree-l2 current"><a class="current reference internal" href="#">if command</a><ul>
|
|
<li class="toctree-l3"><a class="reference internal" href="#syntax">Syntax</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#examples">Examples</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#description">Description</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#restrictions">Restrictions</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#related-commands">Related commands</a></li>
|
|
<li class="toctree-l3"><a class="reference internal" href="#default">Default</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l2"><a class="reference internal" href="improper_coeff.html">improper_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="improper_style.html">improper_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="include.html">include command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="info.html">info command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="jump.html">jump command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="kim_commands.html">kim command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="kspace_modify.html">kspace_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="kspace_style.html">kspace_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="label.html">label command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="labelmap.html">labelmap command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="lattice.html">lattice command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="log.html">log command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="mass.html">mass command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="mdi.html">mdi command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_modify.html">min_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_spin.html">min_style spin command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_spin.html#min-style-spin-cg-command">min_style spin/cg command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_spin.html#min-style-spin-lbfgs-command">min_style spin/lbfgs command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html">min_style cg command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-hftn-command">min_style hftn command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-sd-command">min_style sd command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-quickmin-command">min_style quickmin command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-fire-command">min_style fire command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-spin-command"><span class="xref std std-doc">min_style spin</span> command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-spin-cg-command"><span class="xref std std-doc">min_style spin/cg</span> command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="min_style.html#min-style-spin-lbfgs-command"><span class="xref std std-doc">min_style spin/lbfgs</span> command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="minimize.html">minimize command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="molecule.html">molecule command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="neb.html">neb command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="neb_spin.html">neb/spin command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="neigh_modify.html">neigh_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="neighbor.html">neighbor command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="newton.html">newton command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="next.html">next command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="package.html">package command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="pair_coeff.html">pair_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="pair_modify.html">pair_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="pair_style.html">pair_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="pair_write.html">pair_write command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="partition.html">partition command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="plugin.html">plugin command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="prd.html">prd command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="print.html">print command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="processors.html">processors command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="python.html">python command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="quit.html">quit command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="read_data.html">read_data command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="read_dump.html">read_dump command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="read_restart.html">read_restart command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="region.html">region command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="replicate.html">replicate command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="rerun.html">rerun command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="reset_atoms.html">reset_atoms command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="reset_timestep.html">reset_timestep command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="restart.html">restart command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="run.html">run command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="run_style.html">run_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="set.html">set command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="shell.html">shell command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="special_bonds.html">special_bonds command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="suffix.html">suffix command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="tad.html">tad command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="temper.html">temper command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="temper_grem.html">temper/grem command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="temper_npt.html">temper/npt command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="thermo.html">thermo command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="thermo_modify.html">thermo_modify command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="thermo_style.html">thermo_style command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="third_order.html">third_order command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="timer.html">timer command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="timestep.html">timestep command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="uncompute.html">uncompute command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="undump.html">undump command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="unfix.html">unfix command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="units.html">units command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="variable.html">variable command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="velocity.html">velocity command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="write_coeff.html">write_coeff command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="write_data.html">write_data command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="write_dump.html">write_dump command</a></li>
|
|
<li class="toctree-l2"><a class="reference internal" href="write_restart.html">write_restart command</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="toctree-l1"><a class="reference internal" href="fixes.html">Fix Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="computes.html">Compute Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="pairs.html">Pair Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="bonds.html">Bond Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="angles.html">Angle Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="dihedrals.html">Dihedral Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="impropers.html">Improper Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="dumps.html">Dump Styles</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="fix_modify_atc_commands.html">fix_modify AtC commands</a></li>
|
|
<li class="toctree-l1"><a class="reference internal" href="Bibliography.html">Bibliography</a></li>
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
|
<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 style-external-links">
|
|
<div role="navigation" aria-label="Page navigation">
|
|
<ul class="wy-breadcrumbs">
|
|
<li><a href="Manual.html" class="icon icon-home" aria-label="Home"></a></li>
|
|
<li class="breadcrumb-item"><a href="commands_list.html">Commands</a></li>
|
|
<li class="breadcrumb-item active">if command</li>
|
|
<li class="wy-breadcrumbs-aside">
|
|
<a href="https://www.lammps.org"><img src="_static/lammps-logo.png" width="64" height="16" alt="LAMMPS Homepage"></a> | <a href="Commands_all.html">Commands</a>
|
|
</li>
|
|
</ul><div class="rst-breadcrumbs-buttons" role="navigation" aria-label="Sequential page navigation">
|
|
<a href="hyper.html" class="btn btn-neutral float-left" title="hyper command" accesskey="p"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
|
<a href="improper_coeff.html" class="btn btn-neutral float-right" title="improper_coeff command" accesskey="n">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
|
</div>
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<p><span class="math notranslate nohighlight">\(\renewcommand{\AA}{\text{Å}}\)</span></p>
|
|
<section id="if-command">
|
|
<span id="index-0"></span><h1>if command<a class="headerlink" href="#if-command" title="Link to this heading"></a></h1>
|
|
<section id="syntax">
|
|
<h2>Syntax<a class="headerlink" href="#syntax" title="Link to this heading"></a></h2>
|
|
<div class="highlight-LAMMPS notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="n">boolean</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="n">t1</span><span class="w"> </span><span class="n">t2</span><span class="w"> </span><span class="n">...</span><span class="w"> </span><span class="k">elif</span><span class="w"> </span><span class="n">boolean</span><span class="w"> </span><span class="n">f1</span><span class="w"> </span><span class="n">f2</span><span class="w"> </span><span class="n">...</span><span class="w"> </span><span class="k">elif</span><span class="w"> </span><span class="n">boolean</span><span class="w"> </span><span class="n">f1</span><span class="w"> </span><span class="n">f2</span><span class="w"> </span><span class="n">...</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="n">e1</span><span class="w"> </span><span class="n">e2</span><span class="w"> </span><span class="n">...</span>
|
|
</pre></div>
|
|
</div>
|
|
<ul class="simple">
|
|
<li><p>boolean = a Boolean expression evaluated as TRUE or FALSE (see below)</p></li>
|
|
<li><p>then = required word</p></li>
|
|
<li><p>t1,t2,…,tN = one or more LAMMPS commands to execute if condition is met, each enclosed in quotes</p></li>
|
|
<li><p>elif = optional word, can appear multiple times</p></li>
|
|
<li><p>f1,f2,…,fN = one or more LAMMPS commands to execute if elif condition is met, each enclosed in quotes (optional arguments)</p></li>
|
|
<li><p>else = optional argument</p></li>
|
|
<li><p>e1,e2,…,eN = one or more LAMMPS commands to execute if no condition is met, each enclosed in quotes (optional arguments)</p></li>
|
|
</ul>
|
|
</section>
|
|
<section id="examples">
|
|
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading"></a></h2>
|
|
<div class="highlight-LAMMPS notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="s">"${steps} > 1000"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="n">quit</span>
|
|
<span class="k">if</span><span class="w"> </span><span class="s">"${myString} == a10"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="n">quit</span>
|
|
<span class="k">if</span><span class="w"> </span><span class="s">"$x <= $y"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="s">"print 'X is smaller = $x'"</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s">"print 'Y is smaller = $y'"</span>
|
|
<span class="k">if</span><span class="w"> </span><span class="s">"(${eng} > 0.0) || ($n < 1000)"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"timestep 0.005"</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="k">elif</span><span class="w"> </span><span class="nv">$n</span><span class="o"><</span><span class="m">10000</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"timestep 0.01"</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="k">else</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"timestep 0.02"</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"print 'Max step reached'"</span>
|
|
<span class="k">if</span><span class="w"> </span><span class="s">"${eng} > ${eng_previous}"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="s">"jump file1"</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="s">"jump file2"</span>
|
|
</pre></div>
|
|
</div>
|
|
</section>
|
|
<section id="description">
|
|
<h2>Description<a class="headerlink" href="#description" title="Link to this heading"></a></h2>
|
|
<p>This command provides an if-then-else capability within an input
|
|
script. A Boolean expression is evaluated and the result is TRUE or
|
|
FALSE. Note that as in the examples above, the expression can contain
|
|
variables, as defined by the <a class="reference internal" href="variable.html"><span class="doc">variable</span></a> command, which
|
|
will be evaluated as part of the expression. Thus a user-defined
|
|
formula that reflects the current state of the simulation can be used
|
|
to issue one or more new commands.</p>
|
|
<p>If the result of the Boolean expression is TRUE, then one or more
|
|
commands (t1, t2, …, tN) are executed. If it is FALSE, then Boolean
|
|
expressions associated with successive elif keywords are evaluated
|
|
until one is found to be true, in which case its commands (f1, f2,
|
|
…, fN) are executed. If no Boolean expression is TRUE, then the
|
|
commands associated with the else keyword, namely (e1, e2, …, eN),
|
|
are executed. The elif and else keywords and their associated
|
|
commands are optional. If they are not specified and the initial
|
|
Boolean expression is FALSE, then no commands are executed.</p>
|
|
<p>The syntax for Boolean expressions is described below.</p>
|
|
<p>Each command (t1, f1, e1, etc.) can be any valid LAMMPS input script
|
|
command. If the command is more than one word, it must enclosed in
|
|
quotes, so it will be treated as a single argument, as in the examples
|
|
above.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>If a command itself requires a quoted argument (e.g., a
|
|
<a class="reference internal" href="print.html"><span class="doc">print</span></a> command), then double and single quotes can be used
|
|
and nested in the usual manner, as in the examples above and below.
|
|
The <a class="reference internal" href="Commands_parse.html"><span class="doc">Commands parse</span></a> page has more details on
|
|
using quotes in arguments. Only one of level of nesting is allowed,
|
|
but that should be sufficient for most use cases.</p>
|
|
</div>
|
|
<p>Note that by using the line continuation character “&”, the if command
|
|
can be spread across many lines, though it is still a single command:</p>
|
|
<div class="highlight-LAMMPS notranslate"><div class="highlight"><pre><span></span><span class="k">if</span><span class="w"> </span><span class="s">"$a < $b"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"print 'Minimum value = $a'"</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"run 1000"</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="k">else</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">'print "Minimum value = $b"'</span><span class="w"> </span><span class="o">&</span>
|
|
<span class="w"> </span><span class="s">"minimize 0.001 0.001 1000 10000"</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Note that if one of the commands to execute is <a class="reference internal" href="quit.html"><span class="doc">quit</span></a>, as in
|
|
the first example above, then executing the command will cause LAMMPS
|
|
to halt.</p>
|
|
<p>Note that by jumping to a label in the same input script, the if
|
|
command can be used to break out of a loop. See the <a class="reference internal" href="variable.html"><span class="doc">variable delete</span></a> command for info on how to delete the associated
|
|
loop variable, so that it can be re-used later in the input script.</p>
|
|
<p>Here is an example of a loop which checks every 1000 steps if the
|
|
system temperature has reached a certain value, and if so, breaks out
|
|
of the loop to finish the run. Note that any variable could be
|
|
checked, so long as it is current on the timestep when the run
|
|
completes. As explained on the <a class="reference internal" href="variable.html"><span class="doc">variable</span></a> doc page,
|
|
this can be ensured by including the variable in thermodynamic output.</p>
|
|
<div class="highlight-LAMMPS notranslate"><div class="highlight"><pre><span></span><span class="k">variable </span><span class="nv nv-Identifier">myTemp</span><span class="w"> </span><span class="n">equal</span><span class="w"> </span><span class="n">temp</span>
|
|
<span class="k">label </span><span class="sc">loop</span>
|
|
<span class="k">variable </span><span class="nv nv-Identifier">a</span><span class="w"> </span><span class="n">loop</span><span class="w"> </span><span class="m">1000</span>
|
|
<span class="k">run</span><span class="w"> </span><span class="m">1000</span>
|
|
<span class="k">if</span><span class="w"> </span><span class="s">"${myTemp} < 300.0"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="s">"jump SELF break"</span>
|
|
<span class="k">next </span><span class="nv nv-Identifier">a</span>
|
|
<span class="k">jump </span><span class="sc">SELF</span><span class="w"> </span><span class="n">loop</span>
|
|
<span class="k">label </span><span class="sc">break</span>
|
|
<span class="k">print</span><span class="w"> </span><span class="s">"ALL DONE"</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Here is an example of a double loop which uses the if and
|
|
<a class="reference internal" href="jump.html"><span class="doc">jump</span></a> commands to break out of the inner loop when a
|
|
condition is met, then continues iterating through the outer loop.</p>
|
|
<div class="highlight-LAMMPS notranslate"><div class="highlight"><pre><span></span><span class="k">label </span><span class="sc">loopa</span>
|
|
<span class="k">variable </span><span class="nv nv-Identifier">a</span><span class="w"> </span><span class="n">loop</span><span class="w"> </span><span class="m">5</span>
|
|
<span class="w"> </span><span class="k">label </span><span class="sc">loopb</span>
|
|
<span class="w"> </span><span class="k">variable </span><span class="nv nv-Identifier">b</span><span class="w"> </span><span class="n">loop</span><span class="w"> </span><span class="m">5</span>
|
|
<span class="w"> </span><span class="n">print</span><span class="w"> </span><span class="s">"A,B = $a,$b"</span>
|
|
<span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="m">10000</span>
|
|
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="s">"$b > 2"</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="s">"jump SELF break"</span>
|
|
<span class="w"> </span><span class="k">next </span><span class="nv nv-Identifier">b</span>
|
|
<span class="w"> </span><span class="k">jump </span><span class="sc">in.script</span><span class="w"> </span><span class="n">loopb</span>
|
|
<span class="w"> </span><span class="k">label </span><span class="sc">break</span>
|
|
<span class="w"> </span><span class="k">variable </span><span class="nv nv-Identifier">b</span><span class="w"> </span><span class="n">delete</span>
|
|
<span class="k">next </span><span class="nv nv-Identifier">a</span>
|
|
<span class="k">jump </span><span class="sc">SELF</span><span class="w"> </span><span class="n">loopa</span>
|
|
</pre></div>
|
|
</div>
|
|
<hr class="docutils" />
|
|
<p>The Boolean expressions for the if and elif keywords have a C-like
|
|
syntax. Note that each expression is a single argument within the if
|
|
command. Thus if you want to include spaces in the expression for
|
|
clarity, you must enclose the entire expression in quotes.</p>
|
|
<p>An expression is built out of numbers (which start with a digit or
|
|
period or minus sign) or strings (which start with a letter and can
|
|
contain alphanumeric characters, underscores, or forward slashes):</p>
|
|
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>0.2, 100, 1.0e20, -15.4, ...
|
|
InP, myString, a123, ab_23_cd, lj/cut, ...
|
|
</pre></div>
|
|
</div>
|
|
<p>and Boolean operators:</p>
|
|
<pre class="literal-block">A == B, A != B, A < B, A <= B, A > B, A >= B, A && B, A || B, A |^ B, !A</pre>
|
|
<p>Each A and B is a number or string or a variable reference like <code class="docutils literal notranslate"><span class="pre">$a</span></code> or
|
|
<code class="docutils literal notranslate"><span class="pre">${abc}</span></code>, or A or B can be another Boolean expression.</p>
|
|
<p>Note that all variables used will be substituted for before the
|
|
Boolean expression in evaluated. A variable can produce a number,
|
|
like an <a class="reference internal" href="variable.html"><span class="doc">equal-style variable</span></a>, or it can produce a
|
|
string, like an <a class="reference internal" href="variable.html"><span class="doc">index-style variable</span></a>.</p>
|
|
<p>The Boolean operators <code class="docutils literal notranslate"><span class="pre">==</span></code> and <code class="docutils literal notranslate"><span class="pre">!=</span></code> can operate on a pair or strings
|
|
or numbers. They cannot compare a number to a string. All the other
|
|
Boolean operations can only operate on numbers.</p>
|
|
<p>Expressions are evaluated left to right and have the usual C-style
|
|
precedence: the unary logical NOT operator <code class="docutils literal notranslate"><span class="pre">!</span></code> has the highest
|
|
precedence, the 4 relational operators <code class="docutils literal notranslate"><span class="pre"><</span></code>, <code class="docutils literal notranslate"><span class="pre"><=</span></code>, <code class="docutils literal notranslate"><span class="pre">></span></code>, and <code class="docutils literal notranslate"><span class="pre">>=</span></code> are
|
|
next; the two remaining relational operators <code class="docutils literal notranslate"><span class="pre">==</span></code> and <code class="docutils literal notranslate"><span class="pre">!=</span></code> are next;
|
|
then the logical AND operator <code class="docutils literal notranslate"><span class="pre">&&</span></code>; and finally the logical OR
|
|
operator <code class="docutils literal notranslate"><span class="pre">||</span></code> and logical XOR (exclusive or) operator <code class="docutils literal notranslate"><span class="pre">|^</span></code> have
|
|
the lowest precedence. Parenthesis can be used to group one or more
|
|
portions of an expression and/or enforce a different order of
|
|
evaluation than what would occur with the default precedence.</p>
|
|
<p>When the six relational operators (first six in list above) compare two
|
|
numbers, they return either a 1.0 or 0.0 depending on whether the
|
|
relationship between A and B is TRUE or FALSE.</p>
|
|
<p>When the three logical operators (last three in list above) compare two numbers,
|
|
they also return either a 1.0 or 0.0 depending on whether the
|
|
relationship between A and B is TRUE or FALSE (or just A). The
|
|
logical AND operator will return 1.0 if both its 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 XOR operator will return 1.0 if one of its arguments is zero
|
|
and the other non-zero, else it returns 0.0. The logical NOT operator
|
|
returns 1.0 if its argument is 0.0, else it returns 0.0. The 3
|
|
logical operators can only be used to operate on numbers, not on
|
|
strings.</p>
|
|
<p>The overall Boolean expression produces a TRUE result if the numeric
|
|
result is non-zero. If the result is zero, the expression result is
|
|
FALSE.</p>
|
|
<div class="admonition note">
|
|
<p class="admonition-title">Note</p>
|
|
<p>If the Boolean expression is a single numeric value with no Boolean
|
|
operators, it will be FALSE if the value = 0.0, otherwise TRUE. If
|
|
the Boolean expression is a single string, an error message will be
|
|
issued.</p>
|
|
</div>
|
|
</section>
|
|
<hr class="docutils" />
|
|
<section id="restrictions">
|
|
<h2>Restrictions<a class="headerlink" href="#restrictions" title="Link to this heading"></a></h2>
|
|
<p>none</p>
|
|
</section>
|
|
<section id="related-commands">
|
|
<h2>Related commands<a class="headerlink" href="#related-commands" title="Link to this heading"></a></h2>
|
|
<p><a class="reference internal" href="variable.html"><span class="doc">variable</span></a>, <a class="reference internal" href="print.html"><span class="doc">print</span></a></p>
|
|
</section>
|
|
<section id="default">
|
|
<h2>Default<a class="headerlink" href="#default" title="Link to this heading"></a></h2>
|
|
<p>none</p>
|
|
</section>
|
|
</section>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
|
|
<a href="hyper.html" class="btn btn-neutral float-left" title="hyper command" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
|
<a href="improper_coeff.html" class="btn btn-neutral float-right" title="improper_coeff command" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
|
|
</div>
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>© Copyright 2003-2025 Sandia Corporation.</p>
|
|
</div>
|
|
|
|
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
|
|
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
|
|
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
|
|
</footer>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
<script>
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(false);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |