How to create an index file in GROMACS

The gmx make_ndx command

 

Molecular Dynamics recently established itself as one of the most important techniques in molecular biology, and several programs, including GROMACS, are commonly used to perform simulations.

In a previous article I introduced you to the basic functions and commands of the program. They are mostly required to simply set up and run an MD simulation.

However, one of the main advantage of GROMACS is that it also comes with a number of useful tools to “play” with your system.

In this article, you can find a general overview of the gmx make_ndx command. A useful tool that you may find helpful for your routine investigations.

 

Description
This command is used to create some special index groups within your system.

 

Let’s start from the basics.

GROMACS comes with different file formats that are needed to perform different actions. One of them is the ndx file format.

This file is simply composed by different sets of atoms.

By default GROMACS creates a default index file for your system. This means that when you don’t specify an index file GROMACS will use the default one.

In most cases, the default index file provided by GROMACS will do just fine.

However, in some others, this might not be enough, and you will need to create your own index file with some special groups of atoms that you need for your investigations.

Here I will demonstrate how to create, edit and use index files through different example and explaining the commands to manipulate them.

 

 

Let’s assume that you have a large system but you are interested in taking into account just a small part of it.

What you can do in GROMACS is to generate an index file (index.ndx), and create a new group containing only the parts you are interested in.

You can use the gmx make_ndx command like this.

1
gmx make_ndx -f system.gro -o index.ndx
Syntax
  1. Call the program with gmx
  2. Select the make_ndx command
  3. Select the -f flag and provide the starting structure (system.gro)
  4. Call the -o flag and decide how you want to name the output file (index.ndx)

 

Once the program runs you will be prompted a list of groups. Something resembling this text below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
  0 System              : 260572 atoms
  1 Protein             :  4382 atoms
  2 Protein-H           :  2144 atoms
  3 C-alpha             :   268 atoms
  4 Backbone            :   804 atoms
  5 MainChain           :  1073 atoms
  6 MainChain+Cb        :  1336 atoms
  7 MainChain+H         :  1334 atoms
  8 SideChain           :  3048 atoms
  9 SideChain-H         :  1071 atoms
 10 Prot-Masses         :  4382 atoms
 11 non-Protein         : 256190 atoms
 12 Other               : 255828 atoms
 13 CHL1                : 51507 atoms
 14 POPC                : 47682 atoms
 15 Na+                 :   221 atoms
 16 Cl-                 :   141 atoms
 17 TP3                 : 156639 atoms

 

The names of the groups are quite self explanatory.

In the bottom of the screen you will find a series of commands that you can use to create new groups for your analysis.

To add a special index composed of the Protein (group 1) and the lipids CHL1 (group 13) , and POPC (group 14) you can enter the following:

1
1 | 13 | 14

 

You can press Enter to see an updated version of the groups in the index file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  0 System              : 260572 atoms
  1 Protein             :  4382 atoms
  2 Protein-H           :  2144 atoms
  3 C-alpha             :   268 atoms
  4 Backbone            :   804 atoms
  5 MainChain           :  1073 atoms
  6 MainChain+Cb        :  1336 atoms
  7 MainChain+H         :  1334 atoms
  8 SideChain           :  3048 atoms
  9 SideChain-H         :  1071 atoms
 10 Prot-Masses         :  4382 atoms
 11 non-Protein         : 256190 atoms
 12 Other               : 255828 atoms
 13 CHL1                : 51507 atoms
 14 POPC                : 47682 atoms
 15 Na+                 :   221 atoms
 16 Cl-                 :   141 atoms
 17 TP3                 : 156639 atoms
 18 Protein_CHL1_POPC   : 103571 atoms 

 

As you can see we have a new selection named 18 Protein_CHL1_POPC. To rename this group to Protein_Lipids you can type:

1
name 18 Protein_Lipids
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
  0 System              : 260572 atoms
  1 Protein             :  4382 atoms
  2 Protein-H           :  2144 atoms
  3 C-alpha             :   268 atoms
  4 Backbone            :   804 atoms
  5 MainChain           :  1073 atoms
  6 MainChain+Cb        :  1336 atoms
  7 MainChain+H         :  1334 atoms
  8 SideChain           :  3048 atoms
  9 SideChain-H         :  1071 atoms
 10 Prot-Masses         :  4382 atoms
 11 non-Protein         : 256190 atoms
 12 Other               : 255828 atoms
 13 CHL1                : 51507 atoms
 14 POPC                : 47682 atoms
 15 Na+                 :   221 atoms
 16 Cl-                 :   141 atoms
 17 TP3                 : 156639 atoms
 18 Protein_Lipids      : 103571 atoms 

 

You can play with the selection tool in various ways.

For instance, you can also select a range of atoms you want to analyze. If you want to consider atoms 1 to 100 you have to type:

1
a 1-100

 

In the same fashion, you can select some residues in a protein.

1
r 1-100

 

You also have some more sophisticated ways of using the selection tool. For instance, if you want to select only the heavy atoms from the protein you can type:

1
1 & ! a H* 

which stands for group 1 and (&) not (!) atoms (a) hydrogens (H).

 

To view the complete list of groups again, simply press enter at the prompt. If you want to remove a selection, type del followed by the selection number:

1
del 19

 

When you are done remember to save and quit with q.

 

 

Of course, once you created your special index you can also modify it.

1
gmx make_ndx -f system.gro -n index.ndx
Syntax
  1. Call the program with gmx
  2. Select the make_ndx command
  3. Select the -f flag and provide the starting structure (system.gro)
  4. Call the -n flag and give GROMACS the index you previously created (index.ndx)

Now you can modify it as already highlighted above.

 

 

An index file is not useful by itself. It needs to be passed to other GROMACS commands to run some specific analysis.

This is generally achieved by passing an index file via the -n flag.

You can find some practical use cases of index files in other articles in this website.

Here I show you how to use an index file to analyze the trajectory of a specific part of the system.

You can also use it to calculate the RMSD for some particular regions as showed here.