# 9.2.3. Gromacs selections¶

Write MDAnalysis.core.groups.AtomGroup selection to a ndx file that defines a Gromacs index group. To be used in Gromacs like this:

<GROMACS_COMMAND> -n macro.ndx


The index groups are named mdanalysis001, mdanalysis002, etc.

class MDAnalysis.selections.gromacs.SelectionWriter(filename, mode='w', numterms=None, preamble=None, **kwargs)[source]

Set up for writing to filename.

Parameters: filename – output file mode – create a new file (“w”), or append (“a”) to existing file [“w”] numterms – number of individual index numbers per line for output formats that write multiple entries in one line. If set to 0 or False then no special formatting is done [8] preamble – string that is written as a comment at the top of the file [] kwargs – use as defaults for write()
close()

Close the file

New in version 0.16.0.

comment(s)

Return string s interpolated into the comment format string.

If no SelectionWriterBase.commentfmt is defined (None) then the empty string is returned because presumably there is no way to enter comments into the file.

A newline is appended to non-empty strings.

write(selection, number=None, name=None, frame=None, mode=None)

Write selection to the output file.

Parameters: selection – a MDAnalysis.core.groups.AtomGroup number – selection will be named “mdanalysis” (None auto increments between writes; useful when appending) [None] name – selection will be named name (instead of numbered) [None] frame – write selection of this frame (or the current one if None [None]
write_preamble()

Write a header, depending on the file format.

class MDAnalysis.selections.gromacs.SelectionWriter(filename, mode='w', numterms=None, preamble=None, **kwargs)[source]

Set up for writing to filename.

Parameters: filename – output file mode – create a new file (“w”), or append (“a”) to existing file [“w”] numterms – number of individual index numbers per line for output formats that write multiple entries in one line. If set to 0 or False then no special formatting is done [8] preamble – string that is written as a comment at the top of the file [] kwargs – use as defaults for write()
close()

Close the file

New in version 0.16.0.

comment(s)

Return string s interpolated into the comment format string.

If no SelectionWriterBase.commentfmt is defined (None) then the empty string is returned because presumably there is no way to enter comments into the file.

A newline is appended to non-empty strings.

write(selection, number=None, name=None, frame=None, mode=None)

Write selection to the output file.

Parameters: selection – a MDAnalysis.core.groups.AtomGroup number – selection will be named “mdanalysis” (None auto increments between writes; useful when appending) [None] name – selection will be named name (instead of numbered) [None] frame – write selection of this frame (or the current one if None [None]
write_preamble()

Write a header, depending on the file format.