Becksteinlab / GromacsWrapper

GromacsWrapper wraps system calls to GROMACS tools into thin Python classes (GROMACS 4.6.5 - 2024 supported).
https://gromacswrapper.readthedocs.org
GNU General Public License v3.0
169 stars 53 forks source link

Error when giving input parameters to g_traj #7

Closed ezitoc closed 12 years ago

ezitoc commented 12 years ago

I get this error message when running the command gromacs.g_traj in a python script:

Traceback (most recent call last): File "run.py", line 32, in gromacs.g_traj(f=MOL+"-md.trj", s=MOL+"-md.tpr", of="force.xvg", noz="", noy="", input=("6", "q")) File "/usr/local/lib/python2.7/dist-packages/GromacsWrapper-0.2.4-py2.7.egg/gromacs/core.py", line 265, in call return self.run(_args,kwargs) File "/usr/local/lib/python2.7/dist-packages/GromacsWrapper-0.2.4-py2.7.egg/gromacs/core.py", line 84, in run return self._run_command(args, **_kwargs) File "/usr/local/lib/python2.7/dist-packages/GromacsWrapper-0.2.4-py2.7.egg/gromacs/core.py", line 451, in _run_command self.check_failure(result, command_string=p.command_string) File "/usr/local/lib/python2.7/dist-packages/GromacsWrapper-0.2.4-py2.7.egg/gromacs/core.py", line 402, in check_failure raise GromacsError(rc, msg) gromacs.GromacsError: [Errno 255] Gromacs tool failed Command invocation: printf "6\nq\n" | g_traj -of force.xvg -s esfera-md.tpr -noy -noz -f esfera-md.trj

shell returned 1

The problem arises when i run the command "printf "6\nq\n" | g_traj -of force.xvg -s esfera-md.tpr -noy -noz -f esfera-md.trj" in shell (bash), as it works as desired.

orbeckst commented 12 years ago

Hi,

Does the the command return status 1 when you run it in the shell? I.e., what is the output of

"printf "6\nq\n" | g_traj -of force.xvg -s esfera-md.tpr -noy -noz -f esfera-md.trj
echo "return status: $?"

If so then then is there a problem with g_traj (independent of GromacsWrapper)? Could you paste all output that you get from g_traj?


By the way, you can write the GromacsWrapper line slightly more compact as

gromacs.g_traj(f=MOL+"-md.trj", s=MOL+"-md.tpr", of="force.xvg", z=False, y=False, input=[6])

because True/False can be used to toggle switches (you could also say noz=True...) and input values are automatically converted to strings.

ezitoc commented 12 years ago

Thanks for the response,

when i run:

"printf "6\nq\n" | g_traj -of force.xvg -s esfera-md.tpr -noy -noz -f esfera-md.trj

in bash, the command works perfectly, and i don't get any command return status 1, so i supposed the problem arises when using pipelines. Recently I have been reading the documentation and found the following:



In order to chain different commands via pipes one must use the special
PopenWithInput object (see GromacsCommand.Popen() method) instead of
the simple call described here and first construct the pipeline explicitly and then call the
PopenWithInput.communicate() method.
STDOUT and PIPE are objects provided by the subprocess module. Any python stream
can be provided and manipulated. This allows for chaining of commands. Use
from subprocess import PIPE, STDOUT
when requiring these special streams (and the special boolean switches True/False cannot do what you need.)

As I am new to Python i really don't know how to try this way. Thanks!

orbeckst commented 12 years ago

when i run:

"printf "6\nq\n" | g_traj -of force.xvg -s esfera-md.tpr -noy -noz -f esfera-md.trj

in bash, the command works perfectly, and i don't get any command return status 1,

When running from the shell, the return status is only stored in the variable $? so could you please show what exactly you get when you run the above command and then immediately afterwards type

echo $?

This should print a number to the screen.


Don't worry about the docs on special constructs for pipes. For the simple case of providing input = [6,] etc this is all handled by GromacsWrapper. The log file shows the equivalent commandline using pipes (printf "6\n" | g_traj ...) but internally it is already done "properly".

By the way, I was able to run your command on a test trajectory without problems

gromacs.g_traj(s=PDB, f=XTC, of="force.xvg", y=False, z=False, input=[6])

so it doesn't seem to be the case that gromacs.g_traj always fails.

ezitoc commented 12 years ago

I got it!!

I don't know why but just running:

gromacs.g_traj(f=MOL+"-md.trj", s=MOL+"-md.tpr", of="force.xvg", z=False, y=False, input=[6])

worked just fine. And just to answer your request, when i ran echo $? immediately after g_traj i got:

return status: 0
Thanks for your help and your time!