Feature #1744

Add C preprocessor like functionality to mdp files

Added by James Barnett over 5 years ago. Updated about 2 years ago.

Target version:


GROMACS currently does this for topology files with #include, #if, #define, etc. Depending on the application, some sets of simulations can have .mdp files that are almost identical except for a couple of modification. For example, running an NVT equilibration, then and NPT equilbiration, and lastly an NPT production run. The cutoffs, constraints, etc. are very likely the same in all of the files for many use cases, so they could benefit from an '#include' functionality, and even benefit from '#if' statements. There is already a 'define' directive in mdp files, but it is only used in topologies, as far as I can tell.

I saw on the Feature Wishlist ( a desire to do mdp chaining, so maybe this could be related to that (although the link is broken there, so I don't know all the details). Looking through how GROMACS reads in mdp files and top files I can see they are treated differently, so I don't know the level of difficulty of this proposal.


#1 Updated by Mark Abraham over 5 years ago

There'd need to be some upgrade of the .mdp parsing gear, but at least in principle we could implement something like

gmx grompp -usual -stuff -define "NVT=1;POSRE=off"

to support an .mdp containing something like

#if NVT
pcoupltype = no
#elsif NPT-first
pcoupltype = Berendsen
tau-p = whatever
#elsif NPT-second
pcoupltype = Nose-Hoover
tau-p = whatever
#error "Need a simulation type in the .mdp file"

perhaps preserving the existing define field of the .mdp (but have it only act upon the topology).

That does seem to violate "one tool, one function" principles, though. Building the .mdp from whatever inputs is a valid function. It makes sense to combine it with the .tpr compilation so long as "building" is simple (ie. like now, just read in the file and use it), but adding conditionality to it might suggest having a separate tool, and if so that should be (e.g.) a Python script, which is what a user can already do themselves...

It also makes it harder to share a grompp workflow - now you need all the files, and the contents of gmx grompp -define and that does not seem like an advantage to me. For example, bug reports are even less likely to have all the relevant data for reproduction and testing...

#2 Updated by Erik Lindahl over 5 years ago

I think this is something we should include as part of the process when we move to XML (or something similar), but to avoid changing formats twice in a relatively short timeframe we probably shouldn't introduce it in the old mdp files.

#3 Updated by Berk Hess over 5 years ago

C preprocessing is very bug prone, so I strongly prefer some other mechanism for switching setups in mdp files.

#4 Updated by Roland Schulz over 5 years ago

If we use Python as new input format (such as e.g. sphinx) we would automatically get this.

#5 Updated by Mark Abraham about 2 years ago

  • Status changed from New to Rejected

Our API-focused future seems like a better approach for this. A user can load the mdp and modify settings as they move between stages of their workflow.

Also available in: Atom PDF