# How to apply position constraint for a particular molecule?

**URL:** <https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943>\
**Category:** User discussions\
**Created:** [October 3, 2022, 6:25am UTC](https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943 "2022-10-03T06:25:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivangi](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shivangi](https://gromacs.bioexcel.eu/u/Shivangi)\
**Post date:** [October 3, 2022, 6:25am UTC](https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943/1 "2022-10-03T06:25:44Z")

</div>

Hi everyone  
I am working on a problem containg few acid molecules at air water interface. I want to apply position restraint for acid during NVT/NPT equilibrium phase.  
So, I prepared the interface and placed the acid on its surface manually. To apply the position restraint i created the posre.itp file by using genresre command. when i am using grompp to equilibrate this system i am getting error as follows:  
Fatal error:  
Syntax error - File restr.itp, line 3  
Last line read:  
‘[position\_restraints]’  
Invalid order for directive position\_restraints  
It seems that there is some problem in my itp file or in topology. I don’t know how to solve it.  
--------------------------------------------------------.top file---------------------------------------------------------------------  
#include “oplsaa.ff/forcefield.itp”

#ifdef POSRES  
#include “restr.itp”  
#endif

#include “oplsaa.ff/tip3p.itp”  
[system]  
; Name  
HNO3 in water

[molecules]  
; Compound #mols  
SOL 499  
HNO3 1

---------------------------------------------------------------posre.itp-------------------------------------------------------------  
; position restraints for non-Water of 216H2O,WATJP01,SPC216,SPC-MODEL,300K,BOX(M)=1.86206NM,WFVG,MAR. 1984

[position\_restraints]  
; i funct fcx fcy fcz  
1498 1 1000 1000 1000  
1499 1 1000 1000 1000  
1500 1 1000 1000 1000  
1501 1 1000 1000 1000  
1502 1 1000 1000 1000  
~  
This problem has bothered me for one week. Any suggestion would be of great help to me. Thanks a lot!

---

<div class="post-metadata">

**Author:** ![nano](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@nano](https://gromacs.bioexcel.eu/u/nano)\
**Post date:** [October 3, 2022, 4:35pm UTC](https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943/2 "2022-10-03T16:35:54Z")

</div>

You need to append the directive to your acid itp file (which seems not included). e.g.,

```auto
; normal itp
.......

[position_restraints]
; note the index
1 1 1000 1000 1000
2 1 1000 1000 1000
3 1 1000 1000 1000
4 1 1000 1000 1000
5 1 1000 1000 1000

```

---

<div class="post-metadata">

**Author:** ![Shivangi](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Shivangi](https://gromacs.bioexcel.eu/u/Shivangi)\
**Post date:** [October 4, 2022, 4:32am UTC](https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943/3 "2022-10-04T04:32:13Z")

</div>

Hi nano,  
Thank for the message. As you pointed out, I added the directive to acid itp file but i am getting the error  
“ERROR 1 [file topo\_h.top, line 28]:  
Atom index (1) in position\_restraints out of bounds (1-0). This probably means that you have inserted topology section “position\_restraints” in a part belonging to a different molecule than you intended to.”

i want to restraint the acid molecule. Here is my topology file

#include “oplsaa.ff/forcefield.itp”  
[moleculetype]  
; name nrexcl  
HNO3 3

[atoms]  
N opls\_966 0.968 1  
O1 opls\_761 -0.408 1  
O2 opls\_761 -0.497 1  
O3 opls\_023 -0.526 1  
H opls\_024 0.463 1

[bonds]  
N O1  
N O2  
N O3  
O2 H

[angles]  
O3 N O2  
O1 N O2  
O1 N O3  
H O2 N

[position\_restraints]  
; note the index  
1 1 1000 1000 1000  
2 1 1000 1000 1000  
3 1 1000 1000 1000  
4 1 1000 1000 1000  
5 1 1000 1000 1000

#include “oplsaa.ff/tip3p.itp”

[system]  
; Name  
HNO3 in water

[molecules]  
; Compound #mols  
SOL 499  
HNO3 1

I tried checking it twice-thrice but couldn’t find error. Kindly help me to figure out what’s wrong in my topol.top file?

---

<div class="post-metadata">

**Author:** ![jalemkul](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/jalemkul/32/18_2.png) [@jalemkul](https://gromacs.bioexcel.eu/u/jalemkul)\
**Post date:** [October 4, 2022, 1:41pm UTC](https://gromacs.bioexcel.eu/t/how-to-apply-position-constraint-for-a-particular-molecule/4943/4 "2022-10-04T13:41:21Z")

</div>

> [@Shivangi](#):
>
> [moleculetype]  
> ; name nrexcl  
> HNO3 3
> 
> [atoms]  
> N opls\_966 0.968 1  
> O1 opls\_761 -0.408 1  
> O2 opls\_761 -0.497 1  
> O3 opls\_023 -0.526 1  
> H opls\_024 0.463 1
> 
> [bonds]  
> N O1  
> N O2  
> N O3  
> O2 H
> 
> [angles]  
> O3 N O2  
> O1 N O2  
> O1 N O3  
> H O2 N

This `[moleculetype]` definition is syntactically incorrect. It appears to be somewhat of a hybrid of `.rtp` and actual topology entry. Atoms need to be numbered, and all bonds, angles, etc. need to be specified by numbers, not atom names. You’re getting a fatal error because there are essentially zero atoms correctly defined, so you cannot apply restraints.
