Gromacs
2018.8
|
#include <gromacs/selection/selectioncollection.h>
Collection of selections.
This class is the main interface to the core of the selection engine. It is used to initialize and manage a collection of selections that share the same topology. Selections within one collection can share variables and can be optimized together. Selections from two different collections do not interact.
The constructor creates an empty selection collection object. To initialize the object, either call initOptions(), or both setReferencePosType() and setOutputPosType(). See these methods for more details on the initialization options.
After setting the default values, one or more selections can be parsed with one or more calls to parseInteractive(), parseFromStdin(), parseFromFile(), and/or parseFromString(). After all selections are parsed, the topology must be set with setTopology() unless requiresTopology() returns false (the topology can also be set earlier). setIndexGroups() must also be called if external index group references are used in the selections; it can be called at any point before compile(). Once all selections are parsed, they must be compiled all at once using compile().
After compilation, dynamic selections have the maximum number of atoms they can evaluate to, but positions have undefined values (see Selection and SelectionPosition). evaluate() can be used to update the selections for a new frame. evaluateFinal() can be called after all the frames have been processed to restore the selection values back to the ones they were after compile().
At any point, requiresTopology() can be called to see whether the information provided so far requires loading the topology. Similarly, requiresIndexGroups() tells whether external index groups are requires. printTree() can be used to print the internal representation of the selections (mostly useful for debugging).
Note that for trajectory analysis using TrajectoryAnalysisModule, the SelectionCollection object is managed by Gromacs, and Selection objects are obtained from SelectionOption.
Classes | |
class | Impl |
Private implemention class for SelectionCollection. More... | |
Public Types | |
enum | SelectionTypeOption { IncludeSelectionTypeOption, AlwaysAtomSelections } |
Flag for initOptions() to select how to behave with -seltype option. More... | |
Public Member Functions | |
SelectionCollection () | |
Creates an empty selection collection. More... | |
void | initOptions (IOptionsContainer *options, SelectionTypeOption selectionTypeOption) |
Initializes options for setting global properties on the collection. More... | |
void | setReferencePosType (const char *type) |
Sets the default reference position handling for a selection collection. More... | |
void | setOutputPosType (const char *type) |
Sets the default reference position handling for a selection collection. More... | |
void | setDebugLevel (int debugLevel) |
Sets the debugging level for the selection collection. More... | |
SelectionTopologyProperties | requiredTopologyProperties () const |
Returns what topology information is required for evaluation. More... | |
bool | requiresIndexGroups () const |
Returns true if the collection requires external index groups. More... | |
void | setTopology (gmx_mtop_t *top, int natoms) |
Sets the topology for the collection. More... | |
void | setIndexGroups (gmx_ana_indexgrps_t *grps) |
Sets the external index groups to use for the selections. More... | |
SelectionList | parseFromStdin (int count, bool bInteractive, const std::string &context) |
Parses selection(s) from standard input. More... | |
SelectionList | parseInteractive (int count, TextInputStream *inputStream, TextOutputStream *outputStream, const std::string &context) |
Parses selection(s) interactively using provided streams. More... | |
SelectionList | parseFromFile (const std::string &filename) |
Parses selection(s) from a file. More... | |
SelectionList | parseFromString (const std::string &str) |
Parses selection(s) from a string. More... | |
void | compile () |
Prepares the selections for evaluation and performs optimizations. More... | |
void | evaluate (t_trxframe *fr, t_pbc *pbc) |
Evaluates selections in the collection. More... | |
void | evaluateFinal (int nframes) |
Evaluates the largest possible index groups from dynamic selections. More... | |
void | printTree (FILE *fp, bool bValues) const |
Prints a human-readable version of the internal selection element tree. More... | |
void | printXvgrInfo (FILE *fp) const |
Prints the selection strings into an XVGR file as comments. More... | |
Friends | |
class | SelectionCompiler |
Needed for the compiler to freely modify the collection. | |
class | SelectionEvaluator |
Needed for the evaluator to freely modify the collection. | |
Flag for initOptions() to select how to behave with -seltype option.
Enumerator | |
---|---|
IncludeSelectionTypeOption |
Add the option for the user to select default value for setOutputPosType(). |
AlwaysAtomSelections |
Do not add the option, selections will always select atoms by default. |
gmx::SelectionCollection::SelectionCollection | ( | ) |
Creates an empty selection collection.
std::bad_alloc | if out of memory. |
void gmx::SelectionCollection::compile | ( | ) |
Prepares the selections for evaluation and performs optimizations.
InconsistentInputError | if topology is required but not set. |
InvalidInputError | if setIndexGroups() has not been called and there are index group references. |
unspecified | if compilation fails (TODO: list/reduce these). |
Before compilation, selections should have been added to the collection using the parseFrom*() functions. The compiled selection collection can be passed to evaluate() to evaluate the selection for a frame. Before the compiled selection is evaluated, the selections indicate the maximal set of atoms/positions to which they can be evaluated; see Selection.
If an error occurs, the collection is cleared.
The covered fraction information is initialized to CFRAC_NONE for all selections.
void gmx::SelectionCollection::evaluate | ( | t_trxframe * | fr, |
t_pbc * | pbc | ||
) |
Evaluates selections in the collection.
[in] | fr | Frame for which the evaluation should be carried out. |
[in] | pbc | PBC data, or NULL if no PBC should be used. |
unspeficied | Multiple possible exceptions to indicate evaluation failure (TODO: enumerate). |
void gmx::SelectionCollection::evaluateFinal | ( | int | nframes | ) |
Evaluates the largest possible index groups from dynamic selections.
[in] | nframes | Total number of frames. |
This method restores the selections to the state they were after compile().
nframes
should equal the number of times evaluate() has been called.
Does not throw.
void gmx::SelectionCollection::initOptions | ( | IOptionsContainer * | options, |
SelectionTypeOption | selectionTypeOption | ||
) |
Initializes options for setting global properties on the collection.
[in,out] | options | Options object to initialize. |
[in] | selectionTypeOption | Whether to add option to influence setOutputPosType(). |
std::bad_alloc | if out of memory. |
Adds options to options
that can be used to set the default position types (see setReferencePosType() and setOutputPosType()) and debugging flags.
SelectionList gmx::SelectionCollection::parseFromFile | ( | const std::string & | filename | ) |
Parses selection(s) from a file.
[in] | filename | Name of the file to parse selections from. |
std::bad_alloc | if out of memory. |
InvalidInputError | if there is a parsing error. |
The returned objects remain valid for the lifetime of the selection collection. Some information about the selections only becomes available once compile() has been called; see Selection.
SelectionList gmx::SelectionCollection::parseFromStdin | ( | int | count, |
bool | bInteractive, | ||
const std::string & | context | ||
) |
Parses selection(s) from standard input.
[in] | count | Number of selections to parse (if -1, parse as many as provided by the user). |
[in] | bInteractive | Whether the parser should behave interactively. |
[in] | context | Context to print for interactive input. |
std::bad_alloc | if out of memory. |
InvalidInputError | if there is a parsing error (an interactive parser only throws this if too few selections are provided and the user forced the end of input). |
The returned objects remain valid for the lifetime of the selection collection. Some information about the selections only becomes available once compile() has been called; see Selection.
The string provided to context
should be such that it can replace the three dots in "Specify selections ...:". It can be empty.
SelectionList gmx::SelectionCollection::parseFromString | ( | const std::string & | str | ) |
Parses selection(s) from a string.
[in] | str | String to parse selections from. |
std::bad_alloc | if out of memory. |
InvalidInputError | if there is a parsing error. |
The returned objects remain valid for the lifetime of the selection collection. Some information about the selections only becomes available once compile() has been called; see Selection.
SelectionList gmx::SelectionCollection::parseInteractive | ( | int | count, |
TextInputStream * | inputStream, | ||
TextOutputStream * | outputStream, | ||
const std::string & | context | ||
) |
Parses selection(s) interactively using provided streams.
[in] | count | Number of selections to parse (if -1, parse as many as provided by the user). |
[in] | inputStream | Stream to use for input. |
[in] | outputStream | Stream to use for output (if NULL, the parser runs non-interactively and does not produce any status messages). |
[in] | context | Context to print for interactive input. |
std::bad_alloc | if out of memory. |
InvalidInputError | if there is a parsing error (an interactive parser only throws this if too few selections are provided and the user forced the end of input). |
Works the same as parseFromStdin(), except that the caller can provide streams to use instead of stdin
and stderr
.
Mainly usable for unit testing interactive input.
void gmx::SelectionCollection::printTree | ( | FILE * | fp, |
bool | bValues | ||
) | const |
Prints a human-readable version of the internal selection element tree.
[in] | fp | File handle to receive the output. |
[in] | bValues | If true, the evaluated values of selection elements are printed as well. |
The output is very techical, and intended for debugging purposes.
Does not throw.
void gmx::SelectionCollection::printXvgrInfo | ( | FILE * | fp | ) | const |
Prints the selection strings into an XVGR file as comments.
[in] | fp | Output file. |
Does not throw.
SelectionTopologyProperties gmx::SelectionCollection::requiredTopologyProperties | ( | ) | const |
Returns what topology information is required for evaluation.
Before the parser functions have been called, the return value is based just on the position types set. After parser functions have been called, the return value also takes into account the selection keywords used. After the compiler has been called, the return value is final and also considers possible force evaluation requested for the selections.
Does not throw.
bool gmx::SelectionCollection::requiresIndexGroups | ( | ) | const |
Returns true if the collection requires external index groups.
The return value is false
after setIndexGroups() has been called.
Does not throw.
void gmx::SelectionCollection::setDebugLevel | ( | int | debugLevel | ) |
Sets the debugging level for the selection collection.
[in] | debugLevel | Debug level to set (0 = no debug information). |
initOptions() creates debugging options that can also be used to set the debug level. These are normally hidden, but if this method is called before initOptions() with a non-zero debugLevel
, they are made visible.
Mostly useful for debugging tools.
Does not throw.
void gmx::SelectionCollection::setIndexGroups | ( | gmx_ana_indexgrps_t * | grps | ) |
Sets the external index groups to use for the selections.
[in] | grps | Index groups to use for the selections. |
std::bad_alloc | if out of memory. |
InconsistentInputError | if a group reference cannot be resolved. |
Only the first call to this method can have a non-NULL grps
. At this point, any selections that have already been provided are searched for references to external groups, and the references are replaced by the contents of the groups. If any referenced group cannot be found in grps
(or if grps
is NULL and there are any references), InconsistentInputError is thrown.
The selection collection keeps a reference to grps
until this method is called with a NULL grps
. If this method is not called before compile(), it is automatically called as setIndexGroups(NULL).
void gmx::SelectionCollection::setOutputPosType | ( | const char * | type | ) |
Sets the default reference position handling for a selection collection.
[in] | type | Default selection output position type (one of the strings acceptable for PositionCalculationCollection::typeFromEnum()). |
InternalError | if type is invalid. |
Should be called before calling the parser functions, unless initOptions() has been called. In the latter case, can still be used to override the default value (before initOptions() is called) and/or the value provided through the Options object.
Strong exception safety.
void gmx::SelectionCollection::setReferencePosType | ( | const char * | type | ) |
Sets the default reference position handling for a selection collection.
[in] | type | Default selection reference position type (one of the strings acceptable for PositionCalculationCollection::typeFromEnum()). |
InternalError | if type is invalid. |
Should be called before calling the parser functions, unless initOptions() has been called. In the latter case, can still be used to override the default value (before initOptions() is called) and/or the value provided through the Options object.
Strong exception safety.
void gmx::SelectionCollection::setTopology | ( | gmx_mtop_t * | top, |
int | natoms | ||
) |
Sets the topology for the collection.
[in] | top | Topology data. |
[in] | natoms | Number of atoms. If <=0, the number of atoms in the topology is used. |
Either the topology must be provided, or natoms
must be > 0.
natoms
determines the largest atom index that can be selected by the selection: even if the topology contains more atoms, they will not be selected.
Does not throw currently, but this is subject to change when more underlying code is converted to C++.