Open oliviertrottier opened 1 year ago
I can't remember if your use case (only gmx_mpi
) came up before. But I am a bit surprised that tools.Grompp
was not defined. It should have been the equivalent of gmx_mpi grompp
(or at least that's how it's supposed to work!).
Are you able to run (in the shell)
$ . /usr/local/gromacs/bin/GMXRC
$ gmx_mpi grompp -h
If that doesn't work then tools.Grompp
will not be created.
I was able to run these lines without problems but the loading problem was still happening.
I looked at the tools.py file to understand how the commands are loaded and it seemed it's just reading the output of {driver} -quiet help command
to define the commands from the defined driver
. That was working fine and all the commands were loading properly.
However, I noticed when these commands are parsed, suffix
is appended only when the append_suffix
option is set to to true in the configs file. I then added append_suffix = false
in my gromacswrapper.cfg
and it worked! I can now load cbook and all the methods are not suffixed with _mpi
. I am guessing that will only work if only one driver
is specified in the tools
option.
Here are the relevant lines of tools.py
starting from line 435:
append = config.cfg.getboolean("Gromacs", "append_suffix", fallback=True)
tools = {}
for driver in drivers:
suffix = driver.partition("_")[2]
try:
out = subprocess.check_output([driver, "-quiet", "help", "commands"])
for line in out.splitlines()[5:-1]:
line = str(
line.decode("ascii")
) # Python 3: byte string -> str, Python 2: normal string
if len(line) > 4:
if (line[4] != " ") and (" " in line[4:]):
name = line[4 : line.index(" ", 4)]
fancy = make_valid_identifier(name)
if suffix and append:
fancy = "{0!s}_{1!s}".format(fancy, suffix)
tools[fancy] = tool_factory(fancy, name, driver)
I am glad that you managed to get it working.
Do you have a suggestion how we could improve either the code or the documentation? If you want to update https://github.com/Becksteinlab/GromacsWrapper/blob/main/doc/sphinx/source/configuration.txt then that would be especially helpful.
Like I mentioned in my first post, it would be useful to be able to change the base Gromacs command dynamically with a function in gromacs.tools
. I looked at gromacs.tools
and it seems it would be rather simple to do that. All Gromacs commands are subclassing Command
which defines the base Gromacs command through the driver
attribute. The function could simply loop through all GromacsCommand
instances defined gromacs.tools
which are not suffixed and redefine their driver
attribute with the user input. For example, if set_driver
is such command, one could then use the same codebase to use gmx_mpi
on a cluster and use gmx
when running on another computer without an mpi
installation:
if using_cluster:
gromacs.tools.set_driver('gmx_mpi')
else:
gromacs.tools.set_driver('gmx')
# Run set of commands using non-suffixed tools...
I doubt that I myself will have time to do much on this issue in the near future. If you want to contribute code then please do and open a PR. I am happy to review it (just ping me with @orbeckst
to get my attention).
Thank you for offering the opportunity to contribute. I will be happy to write some code to hopefully make the package more portable. I am currently in a rush right now to write another code for my research. I'll ping you when I open the PR.
Hi, I am fairly new to using Gromacs and stumbled upon the
gromacswrapper
package, which I find super useful and well documented. I wanted to use some of the cookbook recipes, but I am not able to loadcbook
. Here is the error message I get when I try to importcbook
fromgromacs
:Here are my configurations in
~./gromacswrapper.cfg
.I only have one gromacs installation, which is the
_mpi
version. I noticed that all the attributes are suffixed with_mpi
. That seems to be the cause of the problem since python cannot find the non-suffixed version. Is there a way to use thegromacswrapper
classes in a gromacs-command-agnostic way? I would like to write one codebase that I can use for multiple gromacs installations without having to change the suffix of all the attributes that I am using.