# Defining position restraints in itp/mdp

**URL:** <https://gromacs.bioexcel.eu/t/defining-position-restraints-in-itp-mdp/11030>\
**Category:** User discussions\
**Created:** [January 14, 2025, 10:17am UTC](https://gromacs.bioexcel.eu/t/defining-position-restraints-in-itp-mdp/11030 "2025-01-14T10:17:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![csbrasnett](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@csbrasnett](https://gromacs.bioexcel.eu/u/csbrasnett)\
**Post date:** [January 14, 2025, 10:17am UTC](https://gromacs.bioexcel.eu/t/defining-position-restraints-in-itp-mdp/11030/1 "2025-01-14T10:17:04Z")

</div>

GROMACS version: 2024.4  
GROMACS modification: No

We have an ongoing discussion in the [vermouth discussion forum](https://github.com/marrink-lab/vermouth-martinize/discussions/639) about defining the strength of position restraints flexibly away from a default.

I can see that this can be done by having a section in a molecule itp along the lines of:

```auto
[position_restraints]
#ifdef POSRES
1 1 POSRES_FC POSRES_FC POSRES_FC
5 1 POSRES_FC POSRES_FC POSRES_FC
...

```

then in the mdp including `-define = -DPOSRES_FC=1000` to specify the strength of the restraint, as described [here](https://gromacs.bioexcel.eu/t/define-position-restraints-in-mdp/1176).

If the value is not passed from the mdp, then there needs to be a default, otherwise grompp raises an error. Trivially, this can be done as:

```auto
[position_restraints]
#ifdef POSRES
#ifndef POSRES_FC
1 1 1000 1000 1000 
5 1 1000 1000 1000 
...
#else
1 1 POSRES_FC POSRES_FC POSRES_FC
5 1 POSRES_FC POSRES_FC POSRES_FC 
...

```

This is an issue for vermouth development, because Vermouth does not (currently) handle nested #ifdef statements. What I’d really want to be able to do is instead have something at the top of the molecule itp file that redoes the #define there, along the lines of:

```auto
#ifndef POSRES_FC
#define = -DPOSRES_FC=1000
#endif

```

so that if the defines is missing from the mdp, the default is specified at the top of the itp. However, this seems to cause the same warning, so I don’t think grompp is processing this in the itp, so I think I’m messing up the syntax somehow. Is it possible to use the #define syntax like this, and if so, how is it possible to implement it?

---

<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 17, 2025, 8:19am UTC](https://gromacs.bioexcel.eu/t/defining-position-restraints-in-itp-mdp/11030/2 "2025-01-17T08:19:17Z")

</div>

The syntax is not the same when you use `#define` statements and when you set the definitions in the .mdp file. See [File formats - GROMACS 2024.2 documentation](https://manual.gromacs.org/2024.2/reference-manual/topologies/topology-file-formats.html#ifdef-statements). Does it work with:

```auto
#ifndef POSRES_FC
#define POSRES_FC 1000
#endif

```

?

---

<div class="post-metadata">

**Author:** ![csbrasnett](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@csbrasnett](https://gromacs.bioexcel.eu/u/csbrasnett)\
**Post date:** [January 17, 2025, 9:04am UTC](https://gromacs.bioexcel.eu/t/defining-position-restraints-in-itp-mdp/11030/3 "2025-01-17T09:04:57Z")

</div>

that seems to work, thanks!
