Reading the output of gmx.commandline_operation with a KeyError

GROMACS version: 2022.4
GROMACS modification: No
System: Ubuntu

Background:
I can run a md simulation with installed gmx.
I can run a md simulation using gmxapi if I have a .tpr file.

Hi, I have an issue making a .tpr file using gmx.commandline_operation.
Following is my code:

import gmxapi as gmx
import os

cmd_dir = “/home/user/test/”

grompp = gmx.commandline_operation(‘gmx’, [‘grompp’],
{‘-f’: os.path.join(cmd_dir, ‘minimization.mdp’),
‘-p’: os.path.join(cmd_dir,‘solutioin.top’),
‘-c’: os.path.join(cmd_dir,‘solution.gro’),},
{‘-o’: os.path.join(cmd_dir, ‘solution.tpr’)})

tpr_input = grompp.output.file[‘-o’].result()

This is the error I get.
Traceback (most recent call last):
File “/home/fswang/documents/md_network/test/test/test.py”, line 12, in
tpr_input = grompp.output.file[‘-o’].result()
File “/home/fswang/myvenv/lib/python3.10/site-packages/gmxapi/operation.py”, line 1602, in result
self.resource_manager.update_output()
File “/home/fswang/myvenv/lib/python3.10/site-packages/gmxapi/operation.py”, line 1120, in update_output
result = self.function(source)
File “/home/fswang/myvenv/lib/python3.10/site-packages/gmxapi/operation.py”, line 1682, in
function=lambda value, key=item: value[key])
KeyError: ‘-o’

I’m eager to know how to solve this issue.

Thanks,
Fu-Sheng

Hello Fu-Sheng. I’m sorry it has taken so long for anyone to respond to you. There is a similar discussion in the issue tracking system right now. Please see Problems with .output.file["-o"].result for commandline_operation functions (#4826) · Issues · GROMACS / GROMACS · GitLab

I hope that the initial comments help you to resolve the problem.

However, we recognize that the KeyError you got is not very helpful. Do you have any preferences on what we should replace it with? For a failed command, should outputs be None? Or should you get an exception when you execute result()? Other ideas?

See this specific comment thread.

Feel free to share ideas or comment either here in this forum or at the GitLab issue.