MD Simulation With Two Ligands in GROMACS, Step by Step
Skip to content

GROMACS MD With Two Ligands: Topology, Index, Restraints

GROMACS MD With Two Ligands: Topology, Index, Restraints

To run a GROMACS MD simulation with two ligands, parameterise each ligand separately, give each a unique [ moleculetype ] name, merge their atom types into one block included right after the force field, paste both ligands’ coordinates into the complex .gro in the same order as [ molecules ], then build one coupling group containing the protein and both ligands and a position restraint file for each ligand.

Every standard protein-ligand tutorial stops at one ligand. Real projects often need two: a cofactor plus an inhibitor, an allosteric modulator next to an orthosteric one, or two copies of the same fragment found in a crystal structure. The single-ligand recipe almost works, which is the trap. grompp then stops with a redefined moleculetype, an atom count that does not match, or a coupling group that leaves one ligand out. This guide from the StemSkills Lab team (10+ years in structural bioinformatics, drug design and molecular modelling) walks through the setup for two ligands, what changes at each step compared with one ligand, and the exact grompp messages that point at each mistake.

It assumes you can already run the one-ligand workflow from our protein-ligand MD simulation tutorial, which follows Justin Lemkul’s widely used GROMACS protein-ligand complex tutorial (published as part of a tutorial suite in Living Journal of Computational Molecular Science, 2018). The full skill path sits in our GROMACS molecular dynamics guide.

What changes when a GROMACS system has two ligands instead of one?

Five things change, and everything else (solvation, ions, minimisation, equilibration, production) stays the same:

  1. Two ligand topologies, each with its own [ moleculetype ] name.
  2. One merged set of ligand atom types, because both ligands usually reuse many of the same types.
  3. Two blocks of coordinates in the complex .gro, in a fixed order.
  4. Two lines in [ molecules ] (or one line with a count of 2 for two copies of the same ligand).
  5. Index groups and restraints that cover both ligands.

In this guide the two ligands are called LIA and LIB. These are placeholder residue names; use the three-letter codes from your own structure. If one of your two molecules is a cofactor that your force field already contains as a residue (heme in some CHARMM36 ports, for example), pdb2gmx handles it and you only have one ligand to add. Our cofactor simulation guide covers that case.

How do I parameterise two ligands for the same simulation?

Parameterise each ligand on its own, from its own coordinates, with the same tool and force field family for both. For CHARMM36 that usually means CGenFF (via the CGenFF server and the cgenff_charmm2gmx conversion script used in the Lemkul tutorial); for AMBER force fields it usually means GAFF2 through ACPYPE or antechamber. Our ligand parameterisation guide covers both routes.

Three rules matter more with two ligands than with one:

  • Take coordinates from the complex, not from a fresh 3D build. Each ligand must come out of the docked pose or crystal structure you want to simulate, with hydrogens added. If you docked them, extract both poses from the same docking result or the same complex PDB.
  • Check each ligand’s quality score separately. CGenFF reports a penalty for every charge and parameter assigned by analogy. The CGenFF documentation treats penalties below 10 as fair, 10 to 50 as needing some basic validation, and above 50 as poor analogy that needs careful validation (the force field itself is described in Vanommeslaeghe et al., J Comput Chem 2010). One well-parameterised ligand does not rescue a badly parameterised second one.
  • Never mix families. A CGenFF ligand next to a GAFF ligand in one topology means two sets of combination rules and 1-4 scaling factors. grompp may run, but the physics is wrong.

For CGenFF output you end up with a .itp (the molecule) and a .prm (extra parameters) per ligand. For ACPYPE output the atom types sit at the top of each ligand’s .itp in an [ atomtypes ] block.

How do I give each ligand a unique moleculetype name?

Open each ligand .itp and look at the [ moleculetype ] line. Parameterisation tools often name every molecule after the residue name you gave them, and if both ligands came out as LIG, grompp stops with:

moleculetype LIG is redefined

Rename one of them consistently in three places: the name under [ moleculetype ] in its .itp, the residue name column in its .itp [ atoms ] block, and the residue name in its .gro coordinates. Then use the same name in [ molecules ]. A typical edit looks like:

[ moleculetype ]
; name   nrexcl
LIB      3

The residue name does not strictly have to match the moleculetype name, but keeping them identical makes index selections such as r LIB predictable later.

Two copies of the same ligand are different. They share one [ moleculetype ] and one .itp include. Do not duplicate the .itp. You only list the molecule twice (or once with a count of 2) in [ molecules ].

Where do the two ligand files go in topol.top?

The rule is the same define-before-use order described in the GROMACS topology file format reference: every [ *types ] directive must appear before the first [ moleculetype ]. With two ligands, that means all ligand atom types and parameter types go into the topology immediately after the force field include, before the protein. A working layout for a CHARMM36 system:

; Include forcefield parameters
#include "./charmm36-jul2022.ff/forcefield.itp"

; Ligand parameters (all [ *types ] blocks, both ligands)
#include "ligands.prm"

; Protein (written by pdb2gmx)
[ moleculetype ]
...
#ifdef POSRES
#include "posre.itp"
#endif

; Ligand A
#include "lia.itp"
#ifdef POSRES_LIG
#include "posre_lia.itp"
#endif

; Ligand B
#include "lib.itp"
#ifdef POSRES_LIG
#include "posre_lib.itp"
#endif

; Water and ions
#include "./charmm36-jul2022.ff/tip3p.itp"
#include "./charmm36-jul2022.ff/ions.itp"

[ system ]
Protein with two ligands in water

[ molecules ]
; Compound        #mols
Protein_chain_A   1
LIA               1
LIB               1

The force field directory name will match whatever port you downloaded. If your protein has several chains, pdb2gmx writes one .itp per chain and the protein part looks different; our GROMACS topology file explained walks through that layout line by line.

How do I merge duplicate atomtypes from two ligand files?

Two drug-like ligands parameterised in the same family almost always share types (aromatic carbons, aromatic hydrogens, carbonyl oxygens). If each ligand’s types are included as written, the shared lines are defined twice. grompp then warns that the type was defined previously and has now been defined again, which counts toward the warning limit and stops the run.

Build one merged file instead:

  1. Copy the [ atomtypes ] block from ligand A into ligands.prm (or ligands_atomtypes.itp, the name does not matter).
  2. Append the lines from ligand B’s [ atomtypes ] block under the same header, skipping any type name already present.
  3. If a type name appears in both files with different numbers, stop. That usually means the ligands came from different tools or versions. Re-parameterise one so both use the same source.
  4. Repeat for [ bondtypes ], [ angletypes ] and [ dihedraltypes ] if your .prm files contain them (CGenFF .prm files usually do).
  5. Delete the original [ atomtypes ] blocks from inside the ligand .itp files (ACPYPE puts them there), so the only copy is the merged one near the top.

Forgetting step 5 produces the classic Invalid order for directive atomtypes error, because ligand B’s .itp now carries an [ atomtypes ] block that lands after a [ moleculetype ]. To see exactly where each directive ended up after every include is expanded, add -pp processed.top to any grompp call and search the output.

Want the guided, hands-on version?

Our live Molecular Modeling & MD Simulations cohort bootcamp takes you from zero to running real docking and MD workflows, with a portfolio project for your grad-school applications.

Join the waitlist (free) →

How do I combine the protein and both ligands into one coordinate file?

Convert each ligand’s coordinate file to .gro and paste the atom lines into the protein’s .gro, in the order you will list them in [ molecules ]:

gmx editconf -f lia_ini.pdb -o lia.gro
gmx editconf -f lib_ini.pdb -o lib.gro
  1. Open processed.gro (the protein from pdb2gmx).
  2. Paste the atom lines of lia.gro (everything except its title line, its atom count line and its last box line) just above the protein’s final box line.
  3. Paste the atom lines of lib.gro directly after them.
  4. Update the atom count on line 2 to the protein count plus both ligand counts.
  5. Save as complex.gro.

The order is what grompp checks, not the atom numbers in the first columns. The GROMACS run-time errors page states that [ molecules ] must match the coordinate file “in terms of both numbers and order of the molecules”. Protein, then LIA, then LIB in the .gro means Protein, LIA, LIB in [ molecules ], in that order.

Before solvating, look at the merged complex in a viewer to confirm both ligands sit in their pockets and neither overlaps the protein. Then continue exactly as for one ligand: gmx editconf for the box, gmx solvate and gmx genion with -p topol.top so they append water and ion counts after your ligand lines. If either ligand carries a net charge, genion’s neutralisation accounts for it automatically, as long as both ligand .itp files are included.

How do I make index groups for two ligands?

You need one group containing the protein and both ligands, for temperature coupling and centre-of-mass removal. Ligands of a few dozen atoms each are too small to couple to their own thermostat, which is why the single-ligand tutorial couples the ligand with the protein. With two ligands, add both:

gmx make_ndx -f em.gro -o index.ndx
> 1 | r LIA
> 22 | r LIB
> name 23 Protein_LIA_LIB
> q

Group 1 is Protein by default, but the numbers 22 and 23 here are examples. make_ndx prints the new group’s number after every command; use the numbers on your own screen. Our make_ndx index groups tutorial explains the selection syntax.

Then set both coupling directives in every .mdp that uses a thermostat (NVT, NPT, production):

tc-grps    = Protein_LIA_LIB Water_and_ions
comm-grps  = Protein_LIA_LIB Water_and_ions

Pass the index file to grompp with -n index.ndx. While you are in make_ndx, it is also worth saving the separate r LIA and r LIB groups; you will want them for per-ligand analysis later.

How do I add position restraints for each ligand?

pdb2gmx writes posre.itp for the protein only. Each ligand needs its own restraint file, generated from that ligand’s own coordinate file, because the atom indices in a restraint file count from 1 inside the molecule, not inside the whole system. For ligand A:

gmx make_ndx -f lia.gro -o index_lia.ndx
> 0 & ! a H*
> q
gmx genrestr -f lia.gro -n index_lia.ndx -o posre_lia.itp -fc 1000 1000 1000

Choose the heavy-atom group you just made when genrestr asks. Repeat with lib.gro to get posre_lib.itp. The force constant of 1000 kJ mol-1 nm-2 in each direction matches the protein restraints pdb2gmx writes; the gmx genrestr documentation lists the other options.

Each include goes directly after its own ligand .itp, as in the topology layout above, so it attaches to the right [ moleculetype ]. Both blocks can share one define name. Switch them on in the NVT and NPT .mdp files with:

define = -DPOSRES -DPOSRES_LIG

If you would rather release one ligand before the other (for example, to let a weakly bound fragment settle while the cofactor stays restrained), give each block its own define, such as POSRES_LIA and POSRES_LIB, and list only the ones you want active. For two copies of the same ligand, one restraint file covers both copies, because it is attached to the shared moleculetype.

Which setup do I need for my two-ligand system?

Your systemMoleculetypes[ molecules ] linesRestraint filesMost common mistake
Two different ligands, same parameterisation tool2, unique names2 (one per ligand)2Duplicate atomtypes or duplicate LIG names
Two copies of the same ligand, adjacent in the .gro11, with count 21Including the .itp twice (redefined moleculetype)
Two copies of the same ligand, separated by other molecules in the .gro12, matching the .gro order1A single count of 2 that does not match the coordinate order
Built-in cofactor plus one ligandCofactor handled by pdb2gmx, 1 ligandProtein plus 1 ligand1 for the ligand (protein posre.itp covers the cofactor if it is part of the protein molecule)Parameterising a cofactor the force field already contains
Ligands from two different force field familiesDo not run. Re-parameterise one ligand so both use the same family.

What do the grompp errors mean, and how do I fix them?

Each of these messages is printed by grompp (the wording comes from the GROMACS source), and each points back to one step above. For errors that are not specific to two ligands, see our list of common GROMACS errors and fixes.

  • moleculetype LIG is redefined: both ligand .itp files use the same name, or the same .itp is included twice. Rename one ligand, or remove the second include for two copies of one ligand.
  • Invalid order for directive atomtypes: an [ atomtypes ] block is still inside a ligand .itp that is included after the protein. Move it into the merged parameter file near the top.
  • A warning that an atomtype or bonded type was defined previously and has now been defined again: the two ligands’ type blocks overlap. Remove the duplicate lines from the merged file. Do not silence this with -maxwarn until you have confirmed the duplicated lines are identical.
  • number of coordinates in coordinate file (...) does not match topology (...): one ligand is in the .gro but not in [ molecules ], or the reverse, or the atom count on line 2 of complex.gro was not updated before solvation.
  • atom name ... does not match warnings, followed by a count of non-matching atom names: the .gro order and the [ molecules ] order differ, often LIB pasted before LIA. Reorder [ molecules ] to match. The run-time errors page says that in almost every case this warning “should not be ignored”.
  • ... atoms are not part of any of the T-Coupling groups: the second ligand is missing from your coupling group, usually because the group was built with only 1 | r LIA. Rebuild it with both ligands.
  • Atom index ... in position_restraints out of bounds: a restraint file was generated on complex.gro instead of the ligand’s own .gro, or its include sits under the wrong [ moleculetype ]. Regenerate it from the ligand file and place it right after that ligand’s .itp.

How do I analyse each ligand separately after the run?

Use the per-ligand index groups you saved. Typical analyses for a two-ligand system:

  • Ligand RMSD for each ligand, fitting on the protein backbone and calculating on LIA, then on LIB. Our ligand RMSD guide covers the fit-versus-calculate group choice.
  • The distance between the two ligands, which shows whether one displaces or stacks against the other:
    gmx distance -s md.tpr -f md_center.xtc -n index.ndx -select 'com of resname LIA plus com of resname LIB' -oall lia_lib_dist.xvg
  • Interaction energy of each ligand with the protein, by setting energygrps to the protein and both ligand groups and rerunning the trajectory with gmx mdrun -rerun. Energy groups are not supported with GPU non-bonded calculations, which is why the rerun step is needed; see our protein-ligand interaction energy tutorial.
  • Hydrogen bonds per ligand, running gmx hbond once with Protein and LIA, once with Protein and LIB. See GROMACS hydrogen bond analysis for protein-ligand complexes.

Before any of these, centre the trajectory on the protein-plus-ligands group with gmx trjconv -pbc mol -center so neither ligand appears split across the box boundary.

Where this fits: the two-ligand setup is step 6 (MD setup) of the staged path in our computational biology skills roadmap, after docking and before trajectory analysis and binding free energy.

Frequently asked questions

Can I simulate two ligands in GROMACS with one topology file?

Yes. A single topol.top includes both ligand .itp files, a merged block of ligand parameter types near the top, and one [ molecules ] line per ligand. Each ligand still needs its own .itp with a unique [ moleculetype ] name unless both are copies of the same molecule.

Do two copies of the same ligand need two .itp files?

No. Two copies share one [ moleculetype ], one .itp include and one restraint file. List the molecule with a count of 2 if the copies sit next to each other in the .gro, or as two separate lines if other molecules come between them.

Should each ligand get its own temperature coupling group?

No. Small ligands have too few degrees of freedom for stable coupling on their own. Put the protein and both ligands in one group, such as Protein_LIA_LIB, and the solvent and ions in a second group.

Can one ligand come from CGenFF and the other from GAFF?

Not in a meaningful simulation. CHARMM and AMBER families use different combination rules and 1-4 scaling, set once per topology in [ defaults ]. Parameterise both ligands for the same force field family as the protein.

How long should a two-ligand simulation run?

Treat it like any protein-ligand run, but check both ligands for convergence, not just the protein. If one ligand is still drifting at the end, extend the run. Our guide on how long to run an MD simulation explains the convergence checks.

Written by the StemSkills Lab team, with 10+ years of experience in sequence and structural bioinformatics, drug discovery and design, and multiscale molecular modelling.

Want the guided, hands-on version?

Our live Molecular Modeling & MD Simulations cohort bootcamp takes you from zero to running real docking and MD workflows, with a portfolio project for your grad-school applications.

Join the waitlist (free) →

Think you know Molecular Dynamics (GROMACS)?
Take the free StemSkills assessment and earn a verifiable certificate you can download and add to your LinkedIn profile.
Start the free assessment

Keep going

Dihedral Angle Analysis in GROMACS: gmx angle and gmx chi Track ligand torsions with gmx angle and side-chain rotamer flips with gmx chi, build the 4-atom index group… Disulfide Engineering in a Vaccine Construct with DbD2 Learn when a disulfide bond earns its place in a multi-epitope vaccine model, and run Disulfide by Design… GROMACS Position Restraints: gmx genrestr and POSRES Restrain your ligand during NVT and NPT with gmx genrestr, place the #ifdef POSRES block correctly, and fix…
See live workshops