# How to update topology file after insert-molecules?

**URL:** https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206
**Category:** User discussions
**Created:** [May 23, 2021, 1:30pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206 "2021-05-23T13:30:10Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![lanselibai](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@lanselibai](https://gromacs.bioexcel.eu/u/lanselibai)
#### Post date: [May 23, 2021, 1:30pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/1 "2021-05-23T13:30:10Z")

</div>

GROMACS version:2021  
GROMACS modification: /No  
Here post your question

To insert the ligand, I put` ligand.gro, ligand.top, ligand.itp` files to the working directory (correct?). Then I use:  
`gmx insert-molecules -f protein_newbox.gro -nmol 26 -ci ligand.gro -o protein_ligand.gro`

This only results in a new gro file, while the `topol.top` file is not updated. I will need to manually add certain lines to the `topol.top` file to reflect the adding of ligands. How to do this exactly? What else do I need to do?

Why there is not a way to automatically update the `topol.top` file for `insert-molecules`, e.g. `-p topol.top`?

---

<div class="post-metadata">

### Author: ![Teslim](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@Teslim](https://gromacs.bioexcel.eu/u/Teslim)
#### Post date: [May 23, 2021, 2:27pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/2 "2021-05-23T14:27:16Z")

</div>

You can manually do this in topol.top file. Go to ligand.top, type #include “ligand.itp” to add your forcefield file. Also, go to the number of molecules section, type name ref and the number of molecules

---

<div class="post-metadata">

### Author: ![lanselibai](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@lanselibai](https://gromacs.bioexcel.eu/u/lanselibai)
#### Post date: [May 23, 2021, 4:11pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/3 "2021-05-23T16:11:37Z")

</div>

> [@Teslim](#):
>
> Also, go to the number of molecules section,

Thank you. What I have done is

(`protein.pdb, ligand.gro, ligand.top, ligand.itp` are in the working directory)

```
    gmx pdb2gmx -f protein.pdb -o protein_processed.gro -water tip3p -ignh -merge interactive
    gmx editconf -f protein_processed.gro -o protein_newbox.gro -c -d 1.0 -bt dodecahedron
    gmx insert-molecules -f protein_newbox.gro -nmol 26 -ci ligand.gro -o protein_ligand.gro

```

) in the `ligand.top`, go to `[molecules]`, change “`nmols`” to 26  
) in the` ligand.top`, `#include "ligand.itp"` is already there

```
gmx solvate -cp protein_ligand.gro -cs spc216.gro -o protein_solv.gro -p topol.top
gmx grompp -f ions.mdp -c protein_solv.gro -p topol.top -o ions.tpr -maxwarn 1

```

But I got error:

```
Fatal error:
number of coordinates in coordinate file (protein_solv.gro, 332025)
             does not match topology (topol.top, 331167)

```

So I think I need to manually modify the `topol.top`, instead of `ligand.top`? How to do it?

---

<div class="post-metadata">

### Author: ![lanselibai](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@lanselibai](https://gromacs.bioexcel.eu/u/lanselibai)
#### Post date: [May 23, 2021, 7:54pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/4 "2021-05-23T19:54:07Z")

</div>

I think I got the solution.

Add  
`#include "ligand.itp"`  
under  
`#include "amber14sb.ff/forcefield.itp"`

Add  
`#include "ligand.top"`  
before  
`#include "amber14sb.ff/tip3p.itp"`

Add  
`ligand 26`  
to the last line

Then, in the `ligand.top`, disable the sections of `[defaults], #include "ligand.itp", [molecules]`

---

<div class="post-metadata">

### Author: ![Teslim](https://avatars.discourse-cdn.com/v4/letter/t/f1d935/32.png) [@Teslim](https://gromacs.bioexcel.eu/u/Teslim)
#### Post date: [May 23, 2021, 9:58pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/5 "2021-05-23T21:58:34Z")

</div>

That’s the better approach. After using the insert molecules command, you gotta manual edit your topology file!

---

<div class="post-metadata">

### Author: ![apurbapal](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@apurbapal](https://gromacs.bioexcel.eu/u/apurbapal)
#### Post date: [February 29, 2024, 12:51pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/6 "2024-02-29T12:51:28Z")

</div>

Dear lanselibai,  
Did this strategy worked and in the ligand.top file how you disable the following section. why you add ligand 26 in the last line?

---

<div class="post-metadata">

### Author: ![MagnusL](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/magnusl/32/2380_2.png) [@MagnusL](https://gromacs.bioexcel.eu/u/MagnusL)
#### Post date: [February 29, 2024, 1:45pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/7 "2024-02-29T13:45:50Z")

</div>

There were 26 copies of the ligand molecule inserted into the system.

---

<div class="post-metadata">

### Author: ![apurbapal](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@apurbapal](https://gromacs.bioexcel.eu/u/apurbapal)
#### Post date: [February 29, 2024, 2:45pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/8 "2024-02-29T14:45:05Z")

</div>

Thank you for your reply. Got the point. But how we can manually edit the topol.top file and ligand.top file so no further syntax error will not appear. For your reference I have upload the ligand. top file. Please let me know if you need dany further information.  
[UNL\_GMX.top](https://gromacs.bioexcel.eu/uploads/short-url/iucapndu71GNNnnGoaTD8q12Qkb.top) (442 Bytes)  
o

---

<div class="post-metadata">

### Author: ![MagnusL](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/magnusl/32/2380_2.png) [@MagnusL](https://gromacs.bioexcel.eu/u/MagnusL)
#### Post date: [February 29, 2024, 5:12pm UTC](https://gromacs.bioexcel.eu/t/how-to-update-topology-file-after-insert-molecules/2206/9 "2024-02-29T17:12:31Z")

</div>

Just make sure that the order of the interaction definitions are correct.  
I would suggest reading the thread at [Including parameters of a new molecule in gromacs topology files](https://gromacs.bioexcel.eu/t/including-parameters-of-a-new-molecule-in-gromacs-topology-files/8166/1) as well as [https://manual.gromacs.org/documentation/current/reference-manual/topologies/topology-file-formats.html](https://manual.gromacs.org/documentation/current/reference-manual/topologies/topology-file-formats.html) and [GROMACS File Formats: Understanding topology, itp, and gro files - Compchems](https://www.compchems.com/gromacs-file-formats-understanding-topology-itp-and-gro-files/#gro-file-format).
