6.5. Base classes for the selection writers¶
Specialized SelectionWriters are derived from
SelectionWriter
. Override the _write_head()
,
_translate()
, and _write_tail()
methods.
-
class
MDAnalysis.selections.base.
SelectionWriter
(filename, mode='wa', numterms=None, preamble=None, **kwargs)[source]¶ Export a selection in MDAnalysis to a format usable in an external package.
The
SelectionWriter
writes a selection string to a file that can be used in another package such as VMD, PyMOL, Gromacs or CHARMM. In this way, analysis and visualization can be done with the best or most convenient tools at hand.SelectionWriter
is a base class and child classes are derived with the appropriate customizations for the package file format.Set up for writing to filename.
Arguments: - filename
output file
- mode
overwrite (“w”) for every write, append (“a”) to existing file, or overwrite an existing file and then append (“wa”) [“wa”]
- 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()
-
__init__
(filename, mode='wa', numterms=None, preamble=None, **kwargs)[source]¶ Set up for writing to filename.
Arguments: - filename
output file
- mode
overwrite (“w”) for every write, append (“a”) to existing file, or overwrite an existing file and then append (“wa”) [“wa”]
- 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()
-
_translate
(atoms, **kwargs)[source]¶ Translate atoms into a list of native selection terms.
build list of ALL selection terms as if this was a single line, e.g.
['index 12 |', 'index 22 |', 'index 33']
only one term per atom!!
terms must be strings
- something like::
” ”.join(terms)
must work
-
comment
(s)[source]¶ Return string s interpolated into the comment format string.
If no
SelectionWriter.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)[source]¶ Write selection to the output file.
Arguments: - selection
- number
selection will be named “mdanalysis<number>” (
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
]
-
MDAnalysis.selections.base.
join
(seq, string='', func=None)[source]¶ Create a list from sequence.
string is appended to each element but the last.
func is applied to every element before appending string.
-
MDAnalysis.selections.base.
get_writer
(filename, defaultformat)[source]¶ Return a
SelectionWriter
for filename or a defaultformat.