Running gromacs with python

GROMACS version: 2020
GROMACS modification: No
Here post your question

Dear all,

I am trying to run python by following this link:

I have successfully applied gmxapi into my gromacs. However, when I am trying to run the simple command:

import gmxapi as gmx
simulation_input = gmx.read_tpr(topol.tpr)
md = gmx.mdrun(simulation_input)

I have this error:

NameError: name ‘topol’ is not defined

I am working in the same directory as the python code and the topol.tpr definitely in that directory. Can someone give me a clue on how to solve that problem?

Furthermore, my second question is, whether the python code will run “gmx rama”, as I read the document that not all command can run by python. Thank you very much.



Hi Ben,

I forwarded your issue to the person developing the gromacs python API, Eric Irrgang. We’re currently very busy preparing the GROMACS 2021 beta release that is due in a few days, so it might take a few days for Eric to step in.


I don’t recall whether this reached me and got resolved through other channels, but I see that no answer has been posted in this forum.

Unless there were copy-paste errors, you have a syntax error in your script. The file name needs to be quoted (as a string). Otherwise it looks like you are referencing the tpr member of the topol object, which apparently does not exist.


import gmxapi as gmx
simulation_input = gmx.read_tpr('topol.tpr')
md = gmx.mdrun(simulation_input)

gmx rama does not have a direct Python interface, but you should be able to use it through the command-line wrapper.

It looks like that has already been addressed at Python gmxapi.error

Hi Eric,

Yes, I have solved the problem. Thank you very much.



1 Like