Book Image

Extending and Modifying LAMMPS Writing Your Own Source Code

By : Dr. Shafat Mubin, Jichen Li
Book Image

Extending and Modifying LAMMPS Writing Your Own Source Code

By: Dr. Shafat Mubin, Jichen Li

Overview of this book

LAMMPS is one of the most widely used tools for running simulations for research in molecular dynamics. While the tool itself is fairly easy to use, more often than not you’ll need to customize it to meet your specific simulation requirements. Extending and Modifying LAMMPS bridges this learning gap and helps you achieve this by writing custom code to add new features to LAMMPS source code. Written by ardent supporters of LAMMPS, this practical guide will enable you to extend the capabilities of LAMMPS with the help of step-by-step explanations of essential concepts, practical examples, and self-assessment questions. This LAMMPS book provides a hands-on approach to implementing associated methodologies that will get you up and running and productive in no time. You’ll begin with a short introduction to the internal mechanisms of LAMMPS, and gradually transition to an overview of the source code along with a tutorial on modifying it. As you advance, you’ll understand the structure, syntax, and organization of LAMMPS source code, and be able to write your own source code extensions to LAMMPS that implement features beyond the ones available in standard downloadable versions. By the end of this book, you’ll have learned how to add your own extensions and modifications to the LAMMPS source code that can implement features that suit your simulation requirements.
Table of Contents (21 chapters)
1
Section 1: Getting Started with LAMMPS
4
Section 2: Understanding the Source Code Structure
11
Section 3: Modifying the Source Code

Exploring the Variable class

In this section, we will outline the Variable class and its source code in the variable.cpp and variable.h files. This class can assign variables in order to store constants or calculate atom and group properties, among other functionalities (see https://lammps.sandia.gov/doc/variable.html).

A variable can return scalar values or arrays of values that are useful for conveying information from one part of the script to another during a simulation run. An equal style variable sets the variable to a provided constant value or to a formula that performs a mathematical calculation or extracts a group, atom, region, compute, fix property, and more. The following screenshot from the set() method shows the relevant code:

Figure 8.5 – Code snippet from the Variable::set() method showing the equal style variables

As you can see, upon detecting the equal keyword (line 401), the find() method is used to locate the name of the variable...