-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlammps-tutorials.tex
4669 lines (4144 loc) · 206 KB
/
lammps-tutorials.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% LIVECOMS ARTICLE TEMPLATE FOR BEST PRACTICES GUIDE
%%% ADAPTED FROM ELIFE ARTICLE TEMPLATE (8/10/2017)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% PREAMBLE
\documentclass[9pt,tutorial]{livecoms}
% Use the 'onehalfspacing' option for 1.5 line spacing
% Use the 'doublespacing' option for 2.0 line spacing
% Use the 'lineno' option for adding line numbers.
% Use the 'pubversion' option for adding the citation and publication information to the document footer, when the DOI is assigned and the article is added to a live issue.
% The 'bestpractices' option for indicates that this is a best practices guide.
% Omit the bestpractices option to remove the marking as a LiveCoMS paper.
% Please note that these options may affect formatting.
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{fancyvrb}
\usepackage{float}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{array}
\usepackage{booktabs}
\usepackage{times}
\usepackage{subcaption}
\usepackage{mathtools}
\usepackage{menukeys}
\usepackage{microtype}
\usepackage{tcolorbox}
\usepackage{newverbs}
\usepackage[title]{appendix}
\usepackage{csquotes}
\usepackage[
type={CC},
modifier={by-nc-sa},
version={4.0},
]{doclicense}
\usepackage{wrapfig}
\usepackage{geometry}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\DeclareSIUnit\Molar{M}
\usepackage[italic]{mathastext}
\graphicspath{{figures/}}
% avoid single line at top or bottom of column
\clubpenalty1000
\widowpenalty1000
\displaywidowpenalty=1000
\definecolor{listing}{rgb}{0.95,0.95,0.95}
\definecolor{command}{rgb}{0.15,0.15,0.15}
\definecolor{download}{rgb}{0.039,0.616,0.851}
\definecolor{note}{rgb}{1,0.988,0.93}
\definecolor{note_listing}{rgb}{0.94,0.925,0.86}
\lstset{
basicstyle=\small\color{command}, % Use default font + small size and command color
numbers=none, % No number on the side
frame=single, % Enable a frame
framerule=0pt, % Invisible frame frame
framesep=5pt, % Space between text and frame
backgroundcolor=\color{listing}, % Set background color to listing
xleftmargin=5pt, % Extra left margin for spacing
xrightmargin=5pt, % Extra right margin for spacing
columns=fullflexible, %flexible or fixed or fullflexible
}
\newtcolorbox{note}{
%basicstyle=\small\color{command}, % Use default font + small size and command color
colback=note, % Background color (matches listings)
colframe=note, % Set frame color to match the background
boxrule=0pt, % Frame thickness
sharp corners, % Square corners
left=5pt, % Extra left padding
right=5pt, % Extra right padding
top=5pt, % Extra top padding
bottom=5pt, % Extra bottom padding
}
\DisableLigatures{encoding = *, family = *} % Deal with ligature problem when copy-pasting "fi"
\renewcommand{\floatpagefraction}{0.8} % At least 80% of a page must be used by floats
\renewcommand{\textfraction}{0.1} % At least 10% of a page must contain text
\newcommand{\lmpcmd}[1]{\hspace{0pt}\colorbox{listing}{\textcolor{command}{\small{#1}}}\hspace{0pt}} % lammps command
% \newcommand{\lmpcmd}[1]{\hspace{0pt}\colorbox{listing}{\textcolor{command}{\texttt{#1}}}\hspace{0pt}} % lammps command
\newcommand{\lmpcmdnote}[1]{\hspace{0pt}\colorbox{note_listing}{\textcolor{command}{\small{#1}}}\hspace{0pt}} % lammps command inside note
\newcommand{\flrcmd}[1]{\textcolor{command}{\texttt{#1}}} % folder in monopace
\newcommand{\flecmd}[1]{\textcolor{command}{\texttt{#1}}} % files name in monopace
\newcommand{\guicmd}[1]{\textcolor{command}{\texttt{«#1»}}} % LAMMPS-GUI commands in French quotation monopace
\newcommand{\dwlcmd}[1]{\textcolor{download}{\texttt{#1}}} % downloadable files in monopace blue
% The DisableLigatures command above turns the longer dash (--) into two dashes.
% This works around it by using \lammpsgui{} instead and making the longer dash explicit.
\newcommand{\lammpsgui}{\textsf{LAMMPS\textendash GUI}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% IMPORTANT USER CONFIGURATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\versionnumber}{1.0} % you should update the minor version number in preprints and major version number of submissions.
% Do not add a newline in the next command, no matter how long the repository name is, as it will break the link in the PDF.
\newcommand{\githubrepository}{\url{https://github.com/lammpstutorials/lammpstutorials-article}} %this should be the main github repository for this article
\newcommand{\filepath}{https://raw.githubusercontent.com/lammpstutorials/lammpstutorials-article/main/files/}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ARTICLE SETUP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{A Set of Tutorials for the LAMMPS Simulation Package [Article v\versionnumber]}
\author[1*]{Simon Gravelle}
\affil[1]{University Grenoble Alpes, CNRS, LIPhy, Grenoble, 38000, France}
\corr{[email protected]}{S.G.}
\orcid{Simon Gravelle}{0000-0003-2149-6706}
\author[2]{Jacob R.~Gissinger}
\affil[2]{Stevens Institute of Technology, Hoboken, NJ 07030, USA}
\orcid{Jacob R.~Gissinger}{0000-0003-0031-044X}
\author[3]{Axel Kohlmeyer}
\affil[3]{Institute for Computational Molecular Science, Temple University, Philadelphia, PA 19122, USA}
\orcid{Axel Kohlmeyer}{0000-0001-6204-6475}
\blurb{This LiveCoMS document is maintained online on GitHub at
\githubrepository; to provide feedback, suggestions, or help improve
it, please visit the GitHub repository and participate via the issue
tracker.}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% PUBLICATION INFORMATION
%%% Fill out these parameters when available
%%% These are used when the "pubversion" option is invoked
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pubDOI{10.XXXX/YYYYYYY}
\pubvolume{<volume>}
\pubissue{<issue>}
\pubyear{<year>}
\articlenum{<number>}
\datereceived{Day Month Year}
\dateaccepted{Day Month Year}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ARTICLE START
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{frontmatter}
\maketitle
\begin{abstract}
The availability of open-source molecular simulation software packages
allows scientists and engineers to focus on running and analyzing
simulations without having to write, parallelize, and validate their
own simulation software. While molecular simulations thus become
accessible to a larger audience, the ``black box'' nature of such
software packages and wide array of options and features can make it
challenging to use them correctly, particularly for beginners in the
topic of MD simulations. LAMMPS is one such versatile molecular
simulation code, designed for modeling particle-based systems across a
broad range of materials science and computational chemistry
applications, including atomistic, coarse-grained, mesoscale,
grid-free continuum, and discrete element models. LAMMPS is capable
of efficiently running simulations of varying sizes from small desktop
computers to large-scale supercomputing environments. Its flexibility
and extensibility make it ideal for complex and extensive simulations
of atomic and molecular systems, and beyond. This article introduces
a suite of tutorials designed to make learning LAMMPS more accessible
to new users. The first four tutorials cover the basics of running
molecular simulations in LAMMPS with systems of varying complexities.
The second four tutorials address more advanced molecular simulation
techniques, specifically the use of a reactive force field, grand
canonical Monte Carlo, enhanced sampling, and the REACTER protocol.
In addition, we introduce \lammpsgui{}, an enhanced cross-platform
graphical text editor specifically designed for use with LAMMPS and
able to run LAMMPS directly on the edited input. \lammpsgui{} is used
as the primary tool in the tutorials to edit inputs, run LAMMPS,
extract data, and visualize the simulated systems.
\end{abstract}
\end{frontmatter}
\section{Introduction}
Molecular simulations can be used to model a large variety of
atomic and coarse-grained systems, including solids, fluids, polymers,
and biomolecules, as well as complex interfaces and multi-component
systems. While various molecular modeling methods exist, molecular dynamics (MD) and
Monte Carlo (MC) are most commonly used. MD is the preferred method for
obtaining the accurate dynamics of a system, as it relies on solving
Newton's equations of motion. For systems with many degrees of freedom
or complex energy landscapes, the MC method can be a better choice than
MD because it allows for efficiently exploring a configuration space
without being confined by the accessible time scale. MC involves
performing random changes to the system configuration that are either
accepted or rejected based on energy criteria
\cite{frenkel2023understanding, allen2017computer}. Molecular simulations allow for
measuring a broad variety of properties, including structural properties
(e.g.,~bond length distribution, coordination numbers, radial
distribution functions), thermodynamic properties (e.g.,~temperature,
pressure, volume), dynamic behaviors (e.g.,~diffusion coefficient,
viscosity), and mechanical responses (e.g.,~elastic constant, Poisson
ratio). Some of these quantities can be directly compared with
experimental data, enabling the validation of the simulated system,
while others, available only through simulations, are often useful for
interpreting experimental data~\cite{van2008molecular}.
LAMMPS (Large-scale Atomic/Molecular Massively Parallel Simulator)
\cite{lammps_home} is a highly flexible and parallel open-source molecular simulation
tool. Over the years, a broad variety of particle interaction models
have been implemented in LAMMPS, enabling it to model a wide range of
systems, including atomic, polymeric, biological, metallic, reactive, granular,
mesoscale, grid-free continuum, and coarse-grained systems
\cite{thompson2022lammps}. LAMMPS can be used on a single CPU core, a
multi-socket and multi-core server, an HPC cluster, or a high-end
supercomputing system. It can efficiently handle complex and large-scale
simulations, including hybrid MPI-OpenMP parallelization
and MPI + GPU acceleration (for a subset of its functionality).
LAMMPS requires users to write detailed input files, a task that can be
particularly challenging for new users. Although its documentation
extensively describes all available features~\cite{lammps_docs},
navigating it can be challenging. Much of the information may be
unnecessary for common use cases, and the detailed manual can often feel
overwhelming. Beyond the intrinsic complexity of LAMMPS, performing
accurate simulations requires several complex, system-specific decisions
regarding the physics to be modeled, such as selecting the thermodynamic
ensemble (e.g.,~microcanonical, grand canonical), determining the
simulation duration, and choosing the sets of parameters describing the
interactions between atoms (the so-called force field)
\cite{wong2016good, van2018validation, prasad2018best}. While these
choices are independent of the simulation software, they may
occasionally be constrained by the features available in a given
package. The tutorials in this article aim to flatten the learning
curve and guide users in performing accurate and reliable molecular
simulations with LAMMPS.
\subsection{Scope}
This set of tutorials consists of eight tutorials arranged in order of
increasing difficulty. The novelties associated with each tutorial are
briefly described below.
In \hyperref[lennard-jones-label]{tutorial 1}, the structure of LAMMPS
input files is illustrated through the creation of a simple atomic
Lennard-Jones fluid system. Basic LAMMPS commands are used to set up
interactions between atoms, perform an energy minimization, and finally
run a simple MD simulation in the microcanonical (NVE) and canonical (NVT)
ensembles.
In \hyperref[carbon-nanotube-label]{tutorial 2}, a more complex system
is introduced in which atoms are connected by bonds: a small carbon
nanotube. The use of both classical and reactive force fields (here,
OPLS-AA~\cite{jorgensenDevelopmentTestingOPLS1996} and
AIREBO~\cite{stuart2000reactive}, respectively) is illustrated. An
external deformation is applied to the CNT, and its deformation is
measured. This tutorial also demonstrates the use of an external tool
to visualize breaking bonds, and show the possibility to import
LAMMPS-generated YAML log files into Python.
In \hyperref[all-atom-label]{tutorial 3}, two components\textemdash liquid water
(flexible three-point model) and a polymer molecule\textemdash are merged and
equilibrated. A long-range solver is used to handle the electrostatic
interactions accurately, and the system is equilibrated in the
isothermal-isobaric (NPT) ensemble; then, a stretching force is applied
to the polymer. Through this relatively complex solvated polymer
system, the tutorial demonstrates how to use type labels to make
molecule files more generic and easier to manage~\cite{gissinger2024type}.
In \hyperref[sheared-confined-label]{tutorial 4}, an electrolyte is
confined between two walls, illustrating the specifics of simulating
systems with fluid-solid interfaces. With the rigid four-point
TIP4P/2005~\cite{abascal2005general} water model, this tutorial uses a
more complex water model than \hyperref[all-atom-label]{tutorial 3}. A
non-equilibrium MD is performed by imposing shear on the fluid through
moving the walls, and the fluid velocity profile is extracted.
In \hyperref[reactive-silicon-dioxide-label]{tutorial 5}, the ReaxFF
reactive force field is used, specifically designed to simulate chemical
reactions by dynamically adjusting atomic interactions
\cite{van2001reaxff}. ReaxFF includes charge equilibration (QEq), a
method that allows the partial charges of atoms to adjust according to
their local environment.
In \hyperref[gcmc-silica-label]{tutorial 6}, a Monte Carlo simulation in
the grand canonical ensemble is implemented to demonstrate how LAMMPS
can be used to simulate an open system that exchanges particles with a
reservoir.
In \hyperref[umbrella-sampling-label]{tutorial 7}, an advanced free
energy method called umbrella sampling is implemented. By calculating
an energy barrier, this tutorial describes a protocol
for addressing energy landscapes that are difficult to sample using
classical MD or MC methods.
In \hyperref[bond-react-label]{tutorial 8}, a CNT embedded in
nylon-6,6 polymer melt is simulated. The
REACTER protocol is used to model the polymerization of nylon, and the formation
of water molecules is tracked over time~\cite{gissinger2020reacter}.
\section{Prerequisites}
\subsection{Background knowledge}
This set of tutorials assumes no prior knowledge of the LAMMPS software
itself. To complete the tutorials, a text editor and a suitable LAMMPS
executable are required. We use \lammpsgui{}~\cite{lammps_gui_docs}
here, as it offers features that make it particularly convenient for
tutorials, but other console or graphical text editors, such as GNU
nano, vi/vim, Emacs, Notepad, Gedit, and Visual Studio Code can also be
used. LAMMPS can be executed either directly from \lammpsgui{}
(\hyperref[using-lammps-gui-label]{Appendix~\ref{using-lammps-gui-label}})
or from a command prompt
(\hyperref[command-line-label]{Appendix~\ref{command-line-label}}), the
latter of which requires some familiarity with executing commands from a
terminal or command-line prompt.
In addition, prior knowledge of the theoretical basics of molecular
simulations and statistical physics is highly beneficial. Users may
refer to textbooks such as \textit{Understanding Molecular Simulation} by
Daan Frenkel and Berend Smit~\cite{frenkel2023understanding}, as well as
\textit{Computer Simulation of Liquids} by Michael Allen and Dominic
Tildesley~\cite{allen2017computer}. To better understand
the fundamental concepts behind the soft matter systems simulated in these
tutorials, users can also refer to \textit{Basic Concepts for Simple and
Complex Liquids} by Jean-Louis Barrat and Jean-Pierre Hansen
\cite{barrat2003basic}, as well as \textit{Theory of Simple Liquids:
with Applications to Soft Matter} by Jean-Pierre Hansen and Ian Ranald
McDonald~\cite{hansen2013theory}. For more resources, the SklogWiki
platform provies a wide range of information on statistical mechanics
and molecular simulations~\cite{sklogwiki_main_page}.
\subsection{Software/system requirements}
The LAMMPS stable release version 29Aug2024\_update2~\cite{lammps_code}
and the matching \lammpsgui{} software version 1.6.12 are required to
follow the tutorials, as they include features that were first
introduced in these versions. For Linux (x86\_64 CPU), macOS (BigSur or
later), and Windows (10 and 11) you can download a precompiled LAMMPS
package from the LAMMPS release page on
GitHub~\cite{lammps_github_release}. Select a package with `GUI' in the
file name, which includes both, \lammpsgui{} and the LAMMPS command-line
executable. These precompiled packages are designed to be portable, and
therefore omit support for parallel execution with MPI. Instructions
for installing \lammpsgui{} and using its most relevant features for the
tutorials are provided in
\hyperref[using-lammps-gui-label]{Appendix~\ref{using-lammps-gui-label}}.
LAMMPS versions are generally backward compatible, meaning that older
input files typically work the same with newer versions of LAMMPS.
However, forward compatibility is not as strong, so input files written
for a newer version may not always work with older versions. As a
result, it is usually possible to follow this tutorial with more recent
releases of \lammpsgui{} and LAMMPS; older versions may require some
(minor) adjustments. These tutorials will be periodically updated to
ensure compatibility and benefit from new features in the latest stable
version of LAMMPS.
For some tutorials, external tools are required for plotting and
visualization, as the corresponding functionality in \lammpsgui{} is
limited. Suitable tools for plotting include Python with
Pandas/Matplotlib~\cite{van1995python,hunter2007Matplotlib}, XmGrace,
Gnuplot, Microsoft Excel, or LibreOffice Calc. For visualization,
suitable tools include VMD~\cite{vmd_home,humphrey1996vmd} and
OVITO~\cite{ovito_home,stukowski2009visualization}.
\subsection{About \lammpsgui{}}
\lammpsgui{} is a graphical text editor, enhanced for editing LAMMPS
input files and linked to the LAMMPS library, allowing it to run LAMMPS
directly. The text editor functions similarly to other graphical
editors, such as Notepad or Gedit, but offers the following enhancements
specifically for LAMMPS:
\begin{itemize}
\item Wizard dialogs to set up these tutorials
\item Auto-completion of LAMMPS commands and options
\item Context-sensitive online help
\item Syntax highlighting for LAMMPS input files
\item Syntax-aware line indentation
\item Visualization using LAMMPS' built-in renderer
\item Start and stop simulations via mouse or keyboard
\item Monitoring of simulation progress
\item Dynamic capture of LAMMPS output in a text window
\item Automatic plotting of thermodynamic data during runs
\item Capture of ``dump image'' outputs for animations
\item Export of thermodynamic data for external plotting
\item Inspection of binary restart files
\end{itemize}
\hyperref[using-lammps-gui-label]{Appendix~\ref{using-lammps-gui-label}}
contains basic instructions for installation and using \lammpsgui{} with
the tutorials presented here. A complete description of all \lammpsgui{}
features can be found in the LAMMPS manual~\cite{lammps_gui_docs}.
\section{Content and links}
The tutorials described in this article can be accessed at
\href{https://lammpstutorials.github.io}{lammpstutorials.github.io},
where additional exercises with solutions are also provided. All files
and inputs required to follow the tutorials are available from a
dedicated GitHub organization account,
\href{https://github.com/lammpstutorials}{github.com/lammpstutorials}.
These files can also be downloaded by clicking \guicmd{Start LAMMPS Tutorial X}
(where \texttt{X} = 1...8) from the \guicmd{Tutorials} menu of \lammpsgui{}.
In the following, all LAMMPS input or console commands are formatted
with a \lmpcmd{colored background}. Keyboard shortcuts and
file names are formatted in \flecmd{monospace}, and \lammpsgui{} options and menus
are displayed in \guicmd{quoted monospace}.
% S.G.: I removed "folder names" because all folders will eventually be removed (TO CONTROL BEFORE SUBMITTING)
% S.G.: I removed "Section titles" as well because it seems to be using a different style
\subsection{Tutorial 1: Lennard-Jones fluid}
\label{lennard-jones-label}
The objective of this tutorial is to perform simple MD simulations
using LAMMPS. The system consists of a Lennard-Jones fluid composed of
neutral particles with two different effective diameters, contained
within a cubic box with periodic boundary conditions
(Fig.~\ref{fig:LJ-avatar}). In this tutorial, basic MD simulations in
the microcanonical (NVE) and canonical (NVT) ensembles are performed,
and basic quantities are calculated, including the potential and kinetic
energies.
\subsubsection{My first input}
To run a simulation using LAMMPS, you need to write an input script
containing a series of commands for LAMMPS to execute, similar to Python
or Bash scripts. For clarity, the input scripts for this tutorial will
be divided into five categories, which will be filled out step by step.
To set up this tutorial, select \guicmd{Start LAMMPS Tutorial 1} from
the \guicmd{Tutorials} menu of \lammpsgui{}, and follow the
instructions. This will select (or create, if needed) a folder, place
the initial input file \flecmd{initial.lmp} in it, and open the file in
the \lammpsgui{} \guicmd{Editor} window. It should display the following
content:
\begin{lstlisting}
# PART A - ENERGY MINIMIZATION
# 1) Initialization
# 2) System definition
# 3) Settings
# 4) Visualization
# 5) Run
\end{lstlisting}
Everything that appears after a hash symbol ($\#$) is a comment
and ignored by LAMMPS. \lammpsgui{} will color such comments in red.
These five categories are not required in every input script and do not
necessarily need to be in that exact order. For instance, the \lmpcmd{Settings}
and the \lmpcmd{Visualization} categories could be inverted, or
the \lmpcmd{Visualization} category could be omitted. However, note that
LAMMPS reads input files from top to bottom and processes each command
\emph{immediately}. Therefore, the \lmpcmd{Initialization} and
\lmpcmd{System definition} categories must appear at the top of the
input, and the \lmpcmd{Run} category must appear at the bottom. Also, the
specifics of some commands can change after global settings are modified, so the
order of commands in the input script is important.
\paragraph{Initialization}
In the first section of the script, called \lmpcmd{Initialization},
global parameters for the simulation are defined, such as units, boundary conditions
(e.g.,~periodic or non-periodic), and atom types (e.g.,~uncharged point particles
or extended spheres with a radius and angular velocities). These commands must be
executed \emph{before} creating the simulation box or they will cause
an error. Similarly, many LAMMPS commands may only be
entered \emph{after} the simulation box is defined. Only a limited
number of commands may be used in both cases. Update the \flecmd{initial.lmp} file
so that the \lmpcmd{Initialization} section appears as follows:
\begin{lstlisting}
# 1) Initialization
units lj
dimension 3
atom_style atomic
boundary p p p
\end{lstlisting}
\begin{figure}
\centering
\includegraphics[width=0.85\linewidth]{GUI-1.png}
\caption{Screenshot of the \lammpsgui{} \guicmd{Editor} window during
\hyperref[lennard-jones-label]{Tutorial 1}. The pop-up menu is the
context menu for right-clicking on the \lmpcmd{units lj} command.}
\label{fig:GUI-1}
\end{figure}
The first line, \lmpcmd{units lj}, specifies the use of \emph{reduced}
units, where all quantities are dimensionless. This unit system is a
popular choice for simulations that explore general statistical
mechanical principles, as it emphasizes relative differences between
parameters rather than representing any specific material. The second
line, \lmpcmd{dimension 3}, specifies that the simulation is conducted
in 3D space, as opposed to 2D, where atoms are confined to move only in
the xy-plane. The third line, \lmpcmd{atom\_style atomic}, designates
the atomic style for representing simple, individual point particles.
In this style, each particle is treated as a point with a mass, making
it the most basic atom style. Other atom styles can incorporate
additional attributes for atoms, such as charges, bonds, or molecule
IDs, depending on the requirements of the simulated model. The last
line, \lmpcmd{boundary p p p}, indicates that periodic boundary
conditions are applied along all three directions of space, where the
three p stand for $x$, $y$, and $z$, respectively. Alternatives are
fixed non-periodic (f), shrink-wrapped non-periodic (s), and
shrink-wrapped non-periodic with minimum (m). For non-periodic
boundaries, different options can be assigned to each dimension, making
configurations like \lmpcmd{boundary p p fm} valid for systems such as
slab geometries.
\begin{note}
Strictly speaking, none of the four commands specified in the
Initialization section are mandatory, as they correspond to the
default settings for their respective global properties. However,
explicitly specifying these defaults is considered good practice to
avoid confusion when sharing input files with other LAMMPS users.
\end{note}
Each LAMMPS command is accompanied by extensive online documentation
that details the different options for that command. From the
\lammpsgui{} editor buffer, you can access the documentation by
right-clicking on a line containing a command (e.g.,~\lmpcmd{units lj})
and selecting \guicmd{View Documentation for `units'}. This action
should prompt your web browser to open the corresponding URL for the
online manual. A screenshot of this context menu is shown in
Fig.~\ref{fig:GUI-1}.
\paragraph{System definition}
\begin{figure}
\centering
\includegraphics[width=0.55\linewidth]{LJ-avatar}
\caption{The binary mixture simulated in
\hyperref[lennard-jones-label]{Tutorial 1}, with the atoms of type 1
represented as small green spheres and lge atoms of type 2 as large
blue spheres.}
\label{fig:LJ-avatar}
\end{figure}
The next step is to create the simulation box and populate it with
atoms. Modify the \lmpcmd{System definition} category of
\flecmd{initial.lmp} as shown below:
\begin{lstlisting}
# 2) System definition
region simbox block -20 20 -20 20 -20 20
create_box 2 simbox
create_atoms 1 random 1500 34134 simbox overlap 0.3
create_atoms 2 random 100 12756 simbox overlap 0.3
\end{lstlisting}
The first line, \lmpcmd{region simbox (...)}, defines a region named
\lmpcmd{simbox} that is a block (i.e.,~a rectangular cuboid) extending
from -20 to 20 units along all three spatial dimensions. The second
line, \lmpcmd{create\_box 2 simbox}, initializes a simulation box based
on the region \lmpcmd{simbox} and reserves space for two types of atoms.
\begin{note}
From this point on, any command referencing an atom type larger than 2
will trigger an error. While it is possible to allocate more atom
types than needed, you must assign a mass and provide force field
parameters for each atom type. Failing to do so will cause LAMMPS to
terminate with an error.
\end{note}
The third line, \lmpcmd{create\_atoms (\dots)}, generates 1500 atoms of
type 1 at random positions within the \lmpcmd{simbox} region. The
integer 34134 is a seed for the internal random number generator, which
can be changed to produce different sequences of random numbers and,
consequently, different initial atom positions. The fourth line adds
100 atoms of type 2. Both \lmpcmd{create\_atoms} commands use the
optional argument \lmpcmd{overlap 0.3}, which enforces a minimum
distance of 0.3 units between the randomly placed atoms. This
constraint helps avoid ``close contacts'' between atoms, which can lead
to excessively large forces and simulation instability.
\paragraph{Settings}
Next, we specify the settings for the two atom types. Modify the
\lmpcmd{Settings} category of \flecmd{initial.lmp} as follows:
\begin{lstlisting}
# 3) Settings
mass 1 1.0
mass 2 5.0
pair_style lj/cut 4.0
pair_coeff 1 1 1.0 1.0
pair_coeff 2 2 0.5 3.0
\end{lstlisting}
The two \lmpcmd{mass} commands assign a mass of 1.0 and 5.0 units to the
atoms of type 1 and 2, respectively. The third line,
\lmpcmd{pair\_style lj/cut 4.0}, specifies that the atoms will be
interacting through a Lennard-Jones (LJ) potential with a cut-off equal
to $r_c = 4.0$ length units~\cite{wang2020lennard,fischer2023history}:
\begin{equation}
E_{ij} (r) = 4 \epsilon_{ij} \left[ \left( \dfrac{\sigma_{ij}}{r} \right)^{12}
- \left( \dfrac{\sigma_{ij}}{r} \right)^{6} \right], ~ \text{for} ~ r < r_c,
\label{eq:LJ}
\end{equation}
where $r$ is the inter-particle distance, $\epsilon_{ij}$ is
the depth of the potential well that determines the interaction strength, and
$\sigma_{ij}$ is the distance at which the potential energy equals zero.
The indexes $i$ and $j$ refer to pairs of particle types.
The fourth line, \lmpcmd{pair\_coeff 1 1 1.0 1.0}, specifies the
Lennard-Jones coefficients for interactions between pairs of atoms
of type 1: the energy parameter $\epsilon_{11} = 1.0$ and
the distance parameter $\sigma_{11} = 1.0$. Similarly, the last line
sets the Lennard-Jones coefficients for interactions between atoms
of type 2, $\epsilon_{22} = 0.5$, and $\sigma_{22} = 3.0$.
\begin{note}
By default, LAMMPS calculates the cross coefficients for different atom
types using geometric average: $\epsilon_{ij} = \sqrt{\epsilon_{ii} \epsilon_{jj}}$,
$\sigma_{ij} = \sqrt{\sigma_{ii} \sigma_{jj}}$. In the present case,
$\epsilon_{12} = \sqrt{1.0 \times 0.5} = 0.707$, and
$\sigma_{12} = \sqrt{1.0 \times 3.0} = 1.732$.
\end{note}
\paragraph{Single-point energy}
The system is now fully parameterized, and the input is ready to compute
forces. Let us complete the two remaining categories,
\lmpcmd{Visualization} and \lmpcmd{Run}, by adding the following lines
to \flecmd{initial.lmp}:
\begin{lstlisting}
# 4) Visualization
thermo 10
thermo_style custom step etotal press
# 5) Run
run 0 post no
\end{lstlisting}
The \lmpcmd{thermo 10} command instructs LAMMPS to print thermodynamic
information to the console every specified number of steps, in this case,
every 10 simulation steps. The \lmpcmd{thermo\_style custom} command
defines the specific outputs, which in this case are the step number
(\lmpcmd{step}), total energy $E$ (\lmpcmd{etotal}), and pressure $p$ (\lmpcmd{press}).
The \lmpcmd{run 0 post no} command instructs LAMMPS to initialize forces and energy
without actually running the simulation. The \lmpcmd{post no} option disables
the post-run summary and statistics output.
You can now run LAMMPS. The simulation should finish quickly, and with the default
settings, \lammpsgui{} will open two windows: one displaying the console
output and another with a chart. The \guicmd{Output} window will display information from
the executed commands, including the total energy and pressure at step 0,
as specified by the thermodynamic data request. Since no actual simulation
steps were performed, the \guicmd{Charts} window will be empty.
\paragraph{Snapshot Image}
\begin{figure}
\centering
\includegraphics[width=0.55\linewidth]{LJ}
\caption{The binary mixture simulated in \hyperref[lennard-jones-label]{Tutorial 1}.
This image was generated directly from the \lammpsgui{}. Atoms of
type 1 are represented as small red spheres, atoms of type 2 as large
green spheres, and the edges of the simulation box are represented as blue sticks.}
\label{fig:LJ}
\end{figure}
At this point, you can create a snapshot image of the current system
using the \guicmd{Image Viewer} window, which can be accessed by
clicking the \guicmd{Create Image} button in the \guicmd{Run} menu. The
image viewer works by instructing LAMMPS to render an image of the
current system using its internal rendering library via the \lmpcmd{dump
image} command. The resulting image is then displayed, with various
buttons available to adjust the view and rendering style. The image
shown in Fig.~\ref{fig:LJ} was created this way. This will always
capture the current state of the system. Save the image for future
comparisons.
\paragraph{Energy minimization}
Now, replace the \lmpcmd{run 0 post no} command line with the
following \lmpcmd{minimize} command:
\begin{lstlisting}
# 5) Run
minimize 1.0e-6 1.0e-6 1000 10000
\end{lstlisting}
This tells LAMMPS to perform an energy minimization of the system.
Specifically, LAMMPS will compute the forces on all atoms and then update their
positions according to a selected algorithm, aiming to reduce
the potential energy. By default, LAMMPS uses the conjugate gradient (CG)
algorithm~\cite{hestenes1952methods}. The simulation will stop as soon
as the minimizer algorithm cannot find a way to lower the potential
energy. % SG: I don't think that its true, its rather the algorithm
% will stop when one of the four criteria is met. Axel, what do you think?
% I propose to replace by "when specific convergence criteria are met"
Note that, except for trivial systems, minimization algorithms will find a
local minimum rather than the global minimum.
Run the minimization and observe that \lammpsgui{} captures the output
and update the chart in real time (see Fig.~\ref{fig:chart-log}). This run executes quickly (depending
on your computer's capabilities), but \lammpsgui{} may fail to capture some
of the thermodynamic data. In that
case, use the \guicmd{Preferences} dialog to reduce the data update
interval and switch to single-threaded, unaccelerated execution in the
\guicmd{Accelerators} tab. You can repeat the run; each new attempt will start
fresh, resetting the system and re-executing the script from the beginning.
\begin{figure}
\centering
\includegraphics[width=\linewidth]{chart-and-output.png}
\caption{\guicmd{Charts} (left) and \guicmd{Output} (right) windows of \lammpsgui{}
after performing the minimization simulation of \hyperref[lennard-jones-label]{Tutorial 1}.}
\label{fig:chart-log}
\end{figure}
The potential energy, $U$, decreases from a positive value to a negative value
(Figs.~\ref{fig:chart-log} and~\ref{fig:evolution-energy}\,a). Note that
during energy minization, the potential energy equals the total energy
of the system, $E = U$, since the kinetic energy, $K$, is zero. The
initially positive potential energy is expected, as the atoms are
created at random positions within the simulation box, with some in very
close proximity to each other. This proximity results in a large
initial potential energy due to the repulsive branch of the
Lennard-Jones potential [i.e.,~the term in $1/r^{12}$ in
Eq.~\eqref{eq:LJ}]. As the energy minimization progresses, the energy
decreases - first rapidly - then more gradually, before plateauing at a
negative value. This indicates that the atoms have moved to reasonable
distances from one another.
Create and save a snapshot image of the simulation state after the
minimization, and compare it to the initial image. You should observe
that the atoms are ``clumping together'' as they move toward positions
of lower potential energy.
\begin{note}
Since the \lmpcmd{thermo\_style} command also includes the \lmpcmd{press}
keyword, you can switch from plotting the total energy to
displaying the pressure by selecting \guicmd{Press} in the \guicmd{Select data}
drop-down menu of the \guicmd{Charts} window.
\end{note}
\paragraph{Molecular dynamics}
After energy minimization, any overlapping atoms are displaced, and
the system is ready for a molecular dynamics simulation. To continue
from the result of the minimization step, append the MD simulation
commands to the same input script, \flecmd{initial.lmp}. Add the
following lines immediately after the \lmpcmd{minimize} command:
\begin{lstlisting}
# PART B - MOLECULAR DYNAMICS
# 4) Visualization
thermo 50
thermo_style custom step temp etotal pe ke press
\end{lstlisting}
Since LAMMPS reads inputs from top to bottom, these lines will
be executed \emph{after} the energy minimization. Therefore,
there is no need to re-initialize or re-define the
system. The \lmpcmd{thermo} command is called a second time to
update the output frequency from 10 to 50 as soon as \lmpcmd{PART B} of
the simulation starts. In addition, a new \lmpcmd{thermo\_style}
command is introduced to specify the thermodynamic information LAMMPS should
print during during \lmpcmd{PART B}. This adjustment is made because, during
molecular dynamics, the system exhibits a non-zero temperature $T$ (and
consequently a non-zero kinetic energy $K$, keyword \lmpcmd{ke}), which are useful to monitor.
The \lmpcmd{pe} keyword represents the potential energy of the system, $E$, such that
$U + K = E$.
Then, add a second \lmpcmd{Run} category by including the following
lines in \lmpcmd{PART B} of \flecmd{initial.lmp}:
\begin{lstlisting}
# 5) Run
fix mynve all nve
timestep 0.005
run 50000
\end{lstlisting}
The \lmpcmd{fix nve} command updates the positions and velocities of the
atoms in the group \lmpcmd{all} at every step. The group \lmpcmd{all}
is a default group that contains all atoms. The last two lines specify
the value of the \lmpcmd{timestep} and the number of steps for the
\lmpcmd{run}, respectively, for a total duration of 250 time units.
\begin{note}
Since no other fix commands alter forces or velocities, and periodic
boundary conditions are applied in all directions, the MD simulation
will be performed in the microcanonical (NVE) ensemble, which
maintains a constant number of particles and a fixed box volume. In
this ensemble, the system does not exchange energy with anything
outside the simulation box.
\end{note}
Run the simulation using LAMMPS. Initially, there is no equilibrium
between potential and kinetic energy, as the potential energy
decreases while the kinetic energy increases. After approximately
40\,000 steps, the values for both kinetic and potential energy
plateau, indicating that the system has reached equilibrium, with
the total energy fluctuating around a certain constant value.
Now, we change the \lmpcmd{Run} section to (note the smaller number of
MD steps):
\begin{lstlisting}
# 5) Run
fix mynve all nve
fix mylgv all langevin 1.0 1.0 0.1 10917
timestep 0.005
run 15000
\end{lstlisting}
The new command adds a Langevin thermostat to the atoms in the group
\lmpcmd{all}, with a target temperature of 1.0 temperature units
throughout the run (the two numbers represent the target temperature at
the beginning and at the end of the run, which results in a temperature
ramp if they differ)~\cite{schneider1978molecular}. A \lmpcmd{damping}
parameter of 0.1 is used. It determines how rapidly the temperature is
relaxed to its desired value. In a Langevin thermostat, the atoms are
subject to friction and random noise (in the form of randomly added
velocities). Since a constant friction term removes more kinetic energy
from fast atoms and less from slow atoms, the system will eventually
reach a dynamic equilibrium where the kinetic energy removed and added
are about the same. The number 10917 is a seed used to initialize the
random number generator used inside of \lmpcmd{fix langevin}; you can
change it to perform statistically independent simulations. In the
presence of a thermostat, the MD simulation will be performed in the
canonical or NVT ensemble.
\begin{figure}
\centering
\includegraphics[width=\linewidth]{LJ-energy}
\caption{(a) Potential energy, $U$, of the binary mixture as a function of the
step during energy minimization in \hyperref[lennard-jones-label]{Tutorial 1}.
(b) Potential energy, $U$, as a function of time during molecular dynamics in
the NVT ensemble. (c) Kinetic energy, $K$, during energy minimization.
(d) Kinetic energy, $K$, during molecular dynamics.}
\label{fig:evolution-energy}
\end{figure}
Run the simulation again using \lammpsgui{}. From the information
printed in the \guicmd{Output} window, one can see that the temperature
starts from 0 but rapidly reaches the requested value and
stabilizes itself near $T=1$ temperature units. One can also observe that
the potential energy, $U$, rapidly decreases during energy
minimization (see also Fig.~\ref{fig:evolution-energy}\,a). After
the molecular dynamics simulation starts, $U$ increases until
it reaches a plateau value of about -0.25. The kinetic energy,
$K$, is equal to zero during energy minimization and then
increases rapidly during molecular dynamics until it reaches
a plateau value of about 1.5 (Fig.~\ref{fig:evolution-energy}\,d).
\paragraph{Trajectory visualization}
\begin{figure}
\centering
\includegraphics[width=0.55\linewidth]{LJ-cylinder}
\caption{Visualization of the improved binary mixture input after minimization
during \hyperref[lennard-jones-label]{Tutorial 1}. Colors are the same as in
Fig.~\ref{fig:LJ}.}
\label{fig:improved-min}
\end{figure}
So far, the simulation has been mostly monitored through the analysis of
thermodynamic information. To better follow the evolution of the system
and visualize the trajectories of the atoms, let us use the \lmpcmd{dump
image} command to create snapshot images during the simulation. We
have already explored the \guicmd{Image Viewer} window. Open it again
and adjust the visualization to your liking using the available buttons.
Now you can copy the commands used to create this visualization to the
clipboard by either using the \guicmd{Ctrl-D} keyboard shortcut or
selecting \guicmd{Copy dump image command} from the \guicmd{File} menu.
This text can be pasted into the into the \lmpcmd{Visualization} section
of \lmpcmd{PART B} of the \flecmd{initial.lmp} file. This may look like
the following:
\begin{lstlisting}
dump viz all image 100 myimage-*.ppm type type &
size 800 800 zoom 1.452 shiny 0.7 fsaa yes &
view 80 10 box yes 0.025 axes no 0.0 0.0 &
center s 0.483725 0.510373 0.510373
dump_modify viz pad 9 boxcolor royalblue &
backcolor white adiam 1 1.6 adiam 2 4.8
\end{lstlisting}
This command tells LAMMPS to generate NetPBM format images every 100
steps. The two \lmpcmd{type} keywords are for \lmpcmd{color} and
\lmpcmd{diameter}, respectively. Run the \flecmd{initial.lmp} using
LAMMPS again, and a new window named \guicmd{Slide Show} will pop up.
It will show each image created by the \lmpcmd{dump image} as it is
created. After the simulation is finished (or stopped), the slideshow
viewer allows you to animate the trajectory by cycling through the
images. The window also allows you to export the animation to a movie
(provided the FFMpeg program is installed) and to bulk delete those
image files.
The rendering of the system can be further adjusted using the many
options of the \lmpcmd{dump image} command. For instance, the value for the
\lmpcmd{shiny} keyword is used to adjust the shininess of the atoms, the
\lmpcmd{box} keyword adds or removes a representation of the box, and
the \lmpcmd{view} and \lmpcmd{zoom} keywords adjust the camera (and so
on).
\subsubsection{Improving the script}
Let us improve the input script and perform more advanced operations,
such as specifying initial positions for the atoms and restarting the
simulation from a previously saved configuration.
\paragraph{Control the initial atom positions}
Open the \flecmd{improved.min.lmp}, which was downloaded during the
tutorial setup. This file contains the \lmpcmd{Part A} of the
\flecmd{initial.lmp} file, but \emph{without} any
commands in the \lmpcmd{System definition} section:
\begin{lstlisting}
# 1) Initialization
units lj
dimension 3
atom_style atomic
boundary p p p
# 2) System definition
# 3) Settings
mass 1 1.0
mass 2 10.0
pair_style lj/cut 4.0
pair_coeff 1 1 1.0 1.0
pair_coeff 2 2 0.5 3.0
# 4) Visualization
thermo 10
thermo_style custom step etotal press
# 5) Run
minimize 1.0e-6 1.0e-6 1000 10000
\end{lstlisting}
We want to create the atoms of types 1 and 2 in two separate
regions. To achieve this, we need to add two \lmpcmd{region} commands and then
reintroduce the \lmpcmd{create\_atoms} commands, this time using the new
regions instead of the simulation box region to place the atoms:
\begin{lstlisting}
# 2) System definition
region simbox block -20 20 -20 20 -20 20
create_box 2 simbox
# for creating atoms
region cyl_in cylinder z 0 0 10 INF INF side in
region cyl_out cylinder z 0 0 10 INF INF side out
create_atoms 1 random 1000 34134 cyl_out
create_atoms 2 random 150 12756 cyl_in
\end{lstlisting}
The \lmpcmd{side in} and \lmpcmd{side out} keywords are used to define
regions representing the inside and outside of the cylinder of radius
10 length units. Then, append a sixth section titled \lmpcmd{Save system} at the end
of the file, ensuring that the \lmpcmd{write\_data} command is placed \emph{after}
the \lmpcmd{minimize} command:
\begin{lstlisting}
# 6) Save system
write_data improved.min.data
\end{lstlisting}
\begin{note}
A key improvement to the input is the addition of the
\lmpcmd{write\_data} command. This command writes the state of the
system to a text file called \flecmd{improved.min.data}. This
\flecmd{.data} file will be used later to restart the simulation from
the final state of the energy minimization step, eliminating the need
to repeat the system creation and minimization.
\end{note}
Run the \flecmd{improved.min.lmp} file using \lammpsgui{}. At the end
of the simulation, a file called \flecmd{improved.min.data} is created.
You can view the contents of this file from \lammpsgui{}, by
right-clicking on the file name in the editor and selecting the entry
\guicmd{View file improved.min.data}.
The created \flecmd{.data} file contains all the information necessary
to restart the simulation, such as the number of atoms, the box size,
the masses, and the pair coefficients. This \flecmd{.data} file also
contains the final positions of the atoms within the \lmpcmd{Atoms}
section. The first five columns of the \lmpcmd{Atoms} section
correspond (from left to right) to the atom indexes (from 1 to the total
number of atoms, 1150), the atom types (1 or 2 here), and the positions
of the atoms $x$, $y$, $z$. The last three columns are image flags that
keep track of which atoms crossed the periodic boundary. The exact
format of each line in the \lmpcmd{Atoms} section depends on the choice
of \lmpcmd{atom\_style}, which determines which per-atom data is set and
stored internally in LAMMPS.
\begin{note}
Instead of the \lmpcmdnote{write\_data} command, you can also use the
\lmpcmdnote{write\_restart} command to save the state
of the simulation to a binary restart file. Binary restart files are
more compact, faster to write, and contain more information, making them often
more convenient to use. For example, the choice of \lmpcmdnote{atom\_style}
or \lmpcmdnote{pair\_style} is recorded, so those commands do not need to be issued
before reading the restart. Note however that restart files are not expected to be
portable across LAMMPS versions or platforms. Therefore, in these tutorials,
and with the exception of \hyperref[all-atom-label]{Tutorial 3}, we primarily use \lmpcmdnote{write\_data} to provide you with a reference
copy of the data file that works regardless of your LAMMPS version and platform.
\end{note}
\paragraph{Restarting from a saved configuration}
To continue a simulation from the saved configuration, open the
\flecmd{improved.md.lmp} file, which was downloaded during the tutorial setup.
This file contains the \textit{Initialization} part from \flecmd{initial.lmp}
and \flecmd{improved.min.lmp}:
\begin{lstlisting}
# 1) Initialization
units lj