# How to put distance restraints into topology file

**URL:** <https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086>\
**Category:** User discussions\
**Tags:** mdrun, restraints\
**Created:** [May 7, 2024, 10:35am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086 "2024-05-07T10:35:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliara](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@juliara](https://gromacs.bioexcel.eu/u/juliara)\
**Post date:** [May 7, 2024, 10:35am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/1 "2024-05-07T10:35:34Z")

</div>

Hi everyone,

I am trying to restrain the distance between two atoms in a molecule, with just 102 atoms. To be more specific, I want to restrain a MG (number 22) from Chlorophyll with a carbon atom (number 14) from Histidine, to make sure, that their bond stays at the same distance in an optimization. Can some provide an example, of how I can define the restraint in [molecule type]? My topology file ist contained in the following:  
[acpype\_newbondCLAHIS.top](https://gromacs.bioexcel.eu/uploads/short-url/qL1ATLp0k0Z0A7785j9JPMPfe8m.top) (74.9 KB)

---

<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:** [May 7, 2024, 4:30pm UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/2 "2024-05-07T16:30:01Z")

</div>

One way is to add intermolecular interactions to your topology. See if [Imposing restraints between protein and ligand](https://gromacs.bioexcel.eu/t/imposing-restraints-between-protein-and-ligand/8072) and [https://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html](https://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html) helps.

The other alternative is to use the pull settings in the mdp file, see [https://manual.gromacs.org/documentation/current/user-guide/mdp-options.html#com-pulling](https://manual.gromacs.org/documentation/current/user-guide/mdp-options.html#com-pulling) and [https://manual.gromacs.org/current/reference-manual/special/pulling.html](https://manual.gromacs.org/current/reference-manual/special/pulling.html).

---

<div class="post-metadata">

**Author:** ![juliara](https://avatars.discourse-cdn.com/v4/letter/j/278dde/32.png) [@juliara](https://gromacs.bioexcel.eu/u/juliara)\
**Post date:** [May 7, 2024, 7:50pm UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/3 "2024-05-07T19:50:37Z")

</div>

Thank you so much, it has worked!

---

<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:** [May 8, 2024, 6:56am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/4 "2024-05-08T06:56:29Z")

</div>

I’m glad to hear that!

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 5, 2025, 6:21pm UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/5 "2025-01-05T18:21:30Z")

</div>

I am restraining atoms of my ligand and protein as:  
[distance\_restraints]  
; ai aj type index type’ low up1 up2 fac  
1610 4651 1 0 1 0.25 0.25 0.25 10.0  
4648 578 1 0 1 0.25 0.25 0.25 10.0  
1623 578 1 0 1 0.25 0.25 0.25 10.0

and i get error as: Atom index (1610) in distance\_restraints out of bounds (1-11). This probably means that you have inserted topology section  
“distance\_restraints” in a part belonging to a different molecule than you intended to. In that case move the “distance\_restraints” section to the right molecule.  
can someone help me with this.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 5, 2025, 6:23pm UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/6 "2025-01-05T18:23:08Z")

</div>

the protein and ligand are two distinct entities in the topology file;  
i also prepared posre file using genrestr (–disre) and supplied the posre.itp files to the topol.top files; yet i got the same error.  
Any help is appreciated.

---

<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:** [January 7, 2025, 7:48am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/7 "2025-01-07T07:48:48Z")

</div>

The distance restraints, that you are using, are for restraints within one molecule and the atom numbers are the internal atom numbers in that molecule.

See the answers above in this thread and read the links.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 8:05am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/9 "2025-01-07T08:05:02Z")

</div>

Thanks Magnus for your reply.  
I am trying to restrain atoms of ligands and atoms of protein;  
ligand atoms (4650, 4646) and protein atoms (1610, 1624, 579).  
I am trying to align my ligand along a reaction coordinate, and so I want to keep 1610-4650 at 0.25 nm (currently at 0.32 nm), 1624-4646 at 0.33 nm (currently at 0.45nm) and 579-4646 at 0.33 nm (currently at 0.65nm); i achieved the atom numbers from the gro file; is it correct? I do not understand the meaning of “internal atom numbers in that molecule”.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 8:06am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/10 "2025-01-07T08:06:15Z")

</div>

i am doing this during the nvt equilibration step

---

<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:** [January 7, 2025, 8:11am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/11 "2025-01-07T08:11:02Z")

</div>

Just make sure that you are using `[intermolecular_interactions]` not `[distance_restraints]` (as told in the links above) and I think you should be fine.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 10:07am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/14 "2025-01-07T10:07:24Z")

</div>

;  
; File ‘topol.top’ was generated  
; By user: anwesh (540)  
; On host: habilis  
; At date: Tue Jan 7 11:42:43 2025  
;  
; This is a standalone topology file  
;  
; Created by:  
; :-) GROMACS - gmx pdb2gmx, 2019.4 (-:  
;   
; Executable: /home/compchem/gromacs-2019.4/bin/gmx  
; Data prefix: /home/compchem/gromacs-2019.4  
; Working dir: /home/anwesh/hld\_project/md\_lig\_crys  
; Command line:  
; gmx pdb2gmx -f protein.pdb -o protein.gro -ignh  
; Force field was read from the standard GROMACS share directory.  
;

; Include forcefield parameters  
#include “amber03.ff/forcefield.itp”

; Include ligand parameters  
#include “TCP.prm”

[moleculetype]  
; Name nrexcl  
Protein\_chain\_A 3

[atoms]

[bonds]

[pairs]

[angles]

[dihedrals]

[dihedrals]

; Include Position restraint file  
#ifdef POSRES  
#include “posre.itp”  
#endif

; Include ligand topology  
#include “TCP.itp”

; Ligand position restraints  
#ifdef POSRES\_LIG  
#include “posre\_TCP.itp”  
#endif

; Include water topology  
#include “amber03.ff/tip3p.itp”

#ifdef POSRES\_WATER  
; Position restraint for each water oxygen  
[position\_restraints]  
; i funct fcx fcy fcz  
1 1 1000 1000 1000  
#endif

; Include topology for ions  
#include “amber03.ff/ions.itp”

[system]  
; Name  
Protein in water

[molecules]  
; Compound #mols  
Protein\_chain\_A 1  
TCP 1  
SOL 15304  
NA 17

; restraints for distances  
[intermolecular\_interactions]  
;[distance\_restraints]  
; ai aj type index type’ low up1 up2 fac  
1610 4650 1 1 1 0.25 0.25 0.25 500  
1624 4646 1 1 1 0.33 0.33 0.33 500  
579 4646 1 1 1 0.33 0.33 0.33 500

Dear Magnus, this is how my topol.top file looks like, and i get following error:  
Software inconsistency error:  
unknown directive

---

<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:** [January 7, 2025, 10:52am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/15 "2025-01-07T10:52:07Z")

</div>

I don’t see why you get an “unknown directive” error. Hopefully that is fixed in more recent versions of GROMACS. But you’ll also have to modify the parameters. The intermolecular\_interactions should follow the format of `bonds` of the specified type, in your case func. type 1. See [File formats - GROMACS 2024.4 documentation](https://manual.gromacs.org/current/reference-manual/topologies/topology-file-formats.html) for more details.

---

<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:** [January 7, 2025, 10:57am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/16 "2025-01-07T10:57:04Z")

</div>

I realise that intermolecular\_interactions can probably use all kinds of bonded interactions etc (not just bonds), perhaps even distance\_restraints. You can probably do:

```auto
; restraints for distances
[intermolecular_interactions]
[distance_restraints]
; ai aj type index type’ low up1 up2 fac
1610 4650 1 1 1 0.25 0.25 0.25 500
1624 4646 1 1 1 0.33 0.33 0.33 500
579 4646 1 1 1 0.33 0.33 0.33 500

```

and keep the current parameters.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 10:59am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/17 "2025-01-07T10:59:05Z")

</div>

i tried, this one also does not work:  
Distance restraint index 1 occurs twice

* * *

Program: gmx grompp, version 2019.4  
Source file: src/gromacs/gmxpreprocess/readir.cpp (line 3741)

Fatal error:  
Found 1 double distance restraint indices,  
probably the parameters for multiple pairs in one restraint are not identical

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 11:03am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/18 "2025-01-07T11:03:58Z")

</div>

it works only like this:  
; restraints for distances  
[intermolecular\_interactions]  
[distance\_restraints]  
; ai aj type index type’ low up1 up2 fac  
1610 4650 1 1 1 0.25 0.25 0.25 500  
;1624 4646 1 1 1 0.33 0.33 0.33 500  
;579 4646 1 1 1 0.33 0.33 0.33 500

But i need to impose all of them simultaneously.

---

<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:** [January 7, 2025, 11:12am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/19 "2025-01-07T11:12:12Z")

</div>

I must admit I’m not sure then. I’ve never used the distance\_restraints, they’re more complex than what is usually required. Couldn’t you manage with:

```auto
; restraints for distances
[intermolecular_interactions]
[bonds]
; ai aj type b0 kb
1610 4650 1 0.25 500
1624 4646 1 0.33 500
579 4646 1 0.33 500

```

?

Check that the distances and force constants in my suggestion are correct as well.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 11:13am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/20 "2025-01-07T11:13:15Z")

</div>

i will try this and let you know, thanks for your prompt response.

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 11:15am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/21 "2025-01-07T11:15:11Z")

</div>

the fc is as per choice; while the distances are set so as the atoms come this close while dynamics; i tried as per your suggestions, and got followiing error:

* * *

Program: gmx grompp, version 2019.4  
Source file: src/gromacs/gmxpreprocess/convparm.cpp (line 593)

Fatal error:  
The intermolecular\_interaction can not contain chemically bonding interactions

---

<div class="post-metadata">

**Author:** ![apandey29](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@apandey29](https://gromacs.bioexcel.eu/u/apandey29)\
**Post date:** [January 7, 2025, 11:16am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/22 "2025-01-07T11:16:08Z")

</div>

It will be good if we can find a way to impose simultaneous intermolecular distance restraints.

---

<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:** [January 7, 2025, 11:53am UTC](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086/23 "2025-01-07T11:53:25Z")

</div>

Sorry, it should have been:

```auto
; restraints for distances
[intermolecular_interactions]
[bonds]
; ai aj type b0 kb
1610 4650 6 0.25 500
1624 4646 6 0.33 500
579 4646 6 0.33 500

```

as type 1 generates exclusions, which cannot be used in intermolecular\_interactions.

But regarding the simultaneous distance restraints, as far as I understand, that is only required if they contribute to the same NOE signal, and I presume at least one atom would have to be the same in that case. Do you use NOE at all, or are your restraints just to keep the atoms at the correct distance? I don’t think there’d be any problem if you do:

```auto
; restraints for distances
[intermolecular_interactions]
[distance_restraints]
; ai aj type index type’ low up1 up2 fac
1610 4650 1 0 1 0.25 0.25 0.25 500
1624 4646 1 1 1 0.33 0.33 0.33 500
579 4646 1 2 1 0.33 0.33 0.33 500

```

[Next page](https://gromacs.bioexcel.eu/t/how-to-put-distance-restraints-into-topology-file/9086.md?page=2)
