kassonlab / gmxapi

(outdated) fork of https://gitlab.com/gromacs/gromacs
http://gmxapi.org/
Other
52 stars 13 forks source link

commandline_operation should be able to read from STDIN #255

Closed sperezconesa closed 4 years ago

sperezconesa commented 4 years ago

Dear gmxapi users, I am trying to wrap trajectories trough python and I get an error when gmx is asking for user input through the commandline for example. If I run:

trjconv = gmx.commandline_operation('gmx',
                                arguments=['trjconv', '-skip', '10', '-pbc', 'cluster'],
                                input_files={'-f': 'traj_comp.xtc',
                                             '-n': 'index.ndx',
                                             '-s': 'topol.tpr',
                                            },
                                output_files={'-o': 'kk.xtc'}
                                   )
trjconv.run()

I get as outpu:

  gmx trjconv -skip 20 -pbc cluster -f traj_comp.xtc -n index.ndx -s topol.tpr -o kk.xtc

Will write xtc: Compressed trajectory (portable xdr format): xtc
Reading file topol.tpr, VERSION 2019.5 (single precision)
Reading file topol.tpr, VERSION 2019.5 (single precision)
Group     0 (            all) has 57691 elements
Group     1 (        protein) has  5940 elements
Group     2 ( waters_or_ions) has 33103 elements
Group     3 (resname_DOPE_DOPG) has 18648 elements
Group     4 (         waters) has 33045 elements
Group     5 (     not_waters) has 24646 elements
Group     6 (           PROA) has  1485 elements
Group     7 (           PROB) has  1485 elements
Group     8 (           PROC) has  1485 elements
Group     9 (           PROD) has  1485 elements
Group    10 (            OH2) has 11015 elements
Select a group: 
-------------------------------------------------------
Program:     gmx trjconv, version 2019.4
Source file: src/gromacs/topology/index.cpp (line 923)

Fatal error:
Cannot read from input

How can I select the group? Thanks a lot! Sergio

eirrgang commented 4 years ago

Thank you for the alert!

I'm looking at http://manual.gromacs.org/2019-current/onlinehelp/gmx-trjconv.html and I don't see a way to specify the group from the command line and avoid terminal I/O. A proper solution to this may require modernization of the facilities accessible through trjconv.

Do you have a suggestion for an update to the gmxapi.commandline_operation() interface that would address your issue? Would it be sufficient to allow a string to be passed to STDIN?

Also, note that this sort of functionality (trjconv) is not very vigorously supported by GROMACS developers, but is part of the core purpose of projects like MDAnalysis and MDTraj.

sperezconesa commented 4 years ago

I'm looking at http://manual.gromacs.org/2019-current/onlinehelp/gmx-trjconv.html and I don't see a way to specify the group from the command line and avoid terminal I/O. A proper solution to this may require modernization of the facilities accessible through trjconv.

Trjconv according to the gmx output when you run it will be severely modified in the future (I am not sure if they have an ETA on this...). Probably they should keep this in mind.

Do you have a suggestion for an update to the gmxapi.commandline_operation() interface that would address your issue? Would it be sufficient to allow a string to be passed to STDIN?

This would be enough, it is essentially what I used to do using subprocess or another library that calls the the terminal.

Also, note that this sort of functionality (trjconv) is not very vigorously supported by GROMACS developers, but is part of the core purpose of projects like MDAnalysis and MDTraj. I use MDAnalysis all the time but I like to use trjconv for the initial trajectory modifications since it is much faster than MDAnalysis. After I do this, most stuff I do with MDAnalysis.

Thanks for the help and I really like the work you have done with the API. I look forward to meeting you in Stockholm in a few weeks.

peterkasson commented 4 years ago

Permitting a string input for command-line operations sounds like the right solution.

Best, --Peter

eirrgang commented 4 years ago

How about this?

Arguments

stdin (str): String input to send to STDIN (terminal input) of the executable.

Multiline text sent to stdin should be joined into a single string (e.g. '\n'.join(list_of_strings)). If multiple strings are provided to stdin, gmxapi will assume an ensemble, and will run one operation for each provided string.

Only string input (:py:func:str) is currently supported. If you have a use case that requires streaming input or binary input, please open an issue or contact the author(s).

sperezconesa commented 4 years ago

This looks awesome!

eirrgang commented 4 years ago

The change has been merged to GROMACS master branch. I will abandon PR #257 and merge from upstream. I will update pypi with a gmxapi 0.2b1 tomorrow, but you can test the new package from the GROMACS master branch or the PR branch. Please let us know if it does not work as expected.

eirrgang commented 4 years ago

I have updated PyPI with a prerelease package that you can install with pip install --pre gmxapi==0.2.0a1

To weigh in on whether this should be back-ported to gmxapi 0.1 and GROMACS 2020 release branches, please comment at https://redmine.gromacs.org/issues/3393

sperezconesa commented 4 years ago

I have tryed it out and it works great! I have never used redmine. Should I just comment on why I find this is usefull and should be incorporated to the repository? Do some people believe it shouldn't?

peterkasson commented 4 years ago

Thanks! The question to be discussed on redmine, if I understand correctly, is whether this is a sufficient "bugfix" to incorporate into Gromacs 2020 or whether it counts more as a "new feature" and should be kept in Gromacs master and targeted towards Gromacs 2021.

Best, --Peter


Peter Kasson, MD, PhD Associate Professor Departments of Molecular Physiology and Biological Physics and of Biomedical Engineering University of Virginia and Department of Cell and Molecular Biology, Uppsala University

On Tue, Feb 25, 2020 at 7:33 AM Sergio Pérez Conesa < notifications@github.com> wrote:

I have tryed it out and it works great! I have never used redmine. Should I just comment on why I find this is usefull and should be incorporated to the repository? Do some people believe it shouldn't?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kassonlab/gmxapi/issues/255?email_source=notifications&email_token=ACRWZNJBQQAIJ5Y4JEGZPFLREU23TA5CNFSM4KWTUNKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEM4NF3Y#issuecomment-590926575, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRWZNMSSS2ST6ZVC2QS7Q3REU23TANCNFSM4KWTUNKA .

eirrgang commented 4 years ago

Right, sorry for the lack of clarity.

The question is basically "should GROMACS 2020.1 (or 2020.2) include a gmxapi 0.1.1 version with this feature?" or "will this be a pre-release feature until gmxapi 0.2 is tagged, which might not happen until GROMACS 2021 is released?"

If you are happy the way things are, then I can revise my suggested install command for posterity.

To get the most recent gmxapi package, including pre-release versions, you can run

 pip install --upgrade --pre gmxapi

To update if and only if an official 0.2+ tagged release is available, you could use

pip install --upgrade "gmxapi>=0.2.0a1"