Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the line length for the command in the top #314

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Limit the line length for the command in the top
Martinize2 writes the command it has been invoked with in
the header of the TOP file it writes. If that command is too
long, then it can pass the maximum line length that grompp
can read.

This commit truncate the command if it passes the limit.
  • Loading branch information
jbarnoud committed Sep 29, 2020
commit ee0e873474e7268b0b28a685fa11fec9c265638c
10 changes: 9 additions & 1 deletion bin/martinize2
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,17 @@ def entry():
LOGGER.debug("Writing molecule {}.", molecule, type='step')

# Write the topology if requested
# grompp has a limit in the number of character it can read per line
# (due to the size limit of a buffer somewhere in its implementation).
# The command line can be longer than this limit and therefore
# prevent grompp from reading the topology.
gromacs_char_limit = 4000 # the limit is actually 4095, but I play safe
command = ' '.join(sys.argv)
if len(command) > gromacs_char_limit:
command = command[:gromacs_char_limit] + ' ...'
Comment on lines +693 to +696
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set it to 80, and linebreak properly. Keep printing the complete command, just linewrap it.
Also see: https://docs.python.org/3/library/textwrap.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but:

  1. it is a fairly rare corner case so it should not affect the general case
  2. the line, once wrapped, will make a header that will be very long and push the relevant information (the topology) far bellow
  3. the line can be easily copy-pasted, which is not the case if it is wrapped because the comment character will pollute the text block; I am fine with if a pathologic line cannot be copied, but I'd rather not affect the legit ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good arguments. Approved.

header = [
'This file was generated using the following command:',
' '.join(sys.argv),
command,
VERSION,
]
if None not in ss_sequence:
Expand Down