Add subsection depth to HelpWriterContext
[alexxy/gromacs.git] / src / gromacs / selection / selhelp.cpp
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
5  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6  * and including many others, as listed in the AUTHORS file in the
7  * top-level source directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 /*! \internal \file
36  * \brief
37  * Implements functions in selhelp.h.
38  *
39  * \author Teemu Murtola <teemu.murtola@gmail.com>
40  * \ingroup module_selection
41  */
42 #include "gmxpre.h"
43
44 #include "selhelp.h"
45
46 #include <string>
47 #include <utility>
48 #include <vector>
49
50 #include <boost/scoped_ptr.hpp>
51
52 #include "gromacs/onlinehelp/helptopic.h"
53 #include "gromacs/onlinehelp/helpwritercontext.h"
54 #include "gromacs/utility/exceptions.h"
55 #include "gromacs/utility/file.h"
56 #include "gromacs/utility/stringutil.h"
57
58 #include "selmethod.h"
59 #include "symrec.h"
60
61 namespace
62 {
63
64 struct CommonHelpText
65 {
66     static const char        name[];
67     static const char        title[];
68     static const char *const text[];
69 };
70
71 const char        CommonHelpText::name[]  = "selections";
72 const char        CommonHelpText::title[] =
73     "Selection syntax and usage";
74 const char *const CommonHelpText::text[] = {
75     "Selections are used to select atoms/molecules/residues for analysis.",
76     "In contrast to traditional index files, selections can be dynamic, i.e.,",
77     "select different atoms for different trajectory frames. The GROMACS",
78     "manual contains a short introductory section to selections in the",
79     "Analysis chapter, including suggestions on how to get familiar with",
80     "selections if you are new to the concept. The subtopics listed below",
81     "provide more details on the technical and syntactic aspects of",
82     "selections.[PAR]",
83
84     "Each analysis tool requires a different number of selections and the",
85     "selections are interpreted differently. The general idea is still the",
86     "same: each selection evaluates to a set of positions, where a position",
87     "can be an atom position or center-of-mass or center-of-geometry of",
88     "a set of atoms. The tool then uses these positions for its analysis to",
89     "allow very flexible processing. Some analysis tools may have limitations",
90     "on the types of selections allowed."
91 };
92
93 struct ArithmeticHelpText
94 {
95     static const char        name[];
96     static const char        title[];
97     static const char *const text[];
98 };
99
100 const char        ArithmeticHelpText::name[]  = "arithmetic";
101 const char        ArithmeticHelpText::title[] =
102     "Arithmetic expressions in selections";
103 const char *const ArithmeticHelpText::text[] = {
104     "Basic arithmetic evaluation is supported for numeric expressions.",
105     "Supported operations are addition, subtraction, negation, multiplication,",
106     "division, and exponentiation (using ^).",
107     "Result of a division by zero or other illegal operations is undefined.",
108 };
109
110 struct CmdLineHelpText
111 {
112     static const char        name[];
113     static const char        title[];
114     static const char *const text[];
115 };
116
117 const char        CmdLineHelpText::name[]  = "cmdline";
118 const char        CmdLineHelpText::title[] =
119     "Specifying selections from command line";
120 const char *const CmdLineHelpText::text[] = {
121     "If no selections are provided on the command line, you are prompted to",
122     "type the selections interactively (a pipe can also be used to provide",
123     "the selections in this case for most tools). While this works well for",
124     "testing, it is easier to provide the selections from the command line",
125     "if they are complex or for scripting.[PAR]",
126
127     "Each tool has different command-line arguments for specifying selections",
128     "(listed by [TT][PROGRAM] help <tool>[tt]).",
129     "You can either pass a single string containing all selections (separated",
130     "by semicolons), or multiple strings, each containing one selection.",
131     "Note that you need to quote the selections to protect them from the",
132     "shell.[PAR]",
133
134     "If you set a selection command-line argument, but do not provide any",
135     "selections, you are prompted to type the selections for that argument",
136     "interactively. This is useful if that selection argument is optional,",
137     "in which case it is not normally prompted for.[PAR]",
138
139     "To provide selections from a file, use [TT]-sf file.dat[tt] in the place",
140     "of the selection for a selection argument (e.g.,",
141     "[TT]-select -sf file.dat[tt]). In general, the [TT]-sf[tt] argument reads",
142     "selections from the provided file and assigns them to selection arguments",
143     "that have been specified up to that point, but for which no selections",
144     "have been provided.",
145     "As a special case, [TT]-sf[tt] provided on its own, without preceding",
146     "selection arguments, assigns the selections to all (yet unset) required",
147     "selections (i.e., those that would be promted interactively if no",
148     "selections are provided on the command line).[PAR]",
149
150     "To use groups from a traditional index file, use argument [TT]-n[tt]",
151     "to provide a file. See the \"syntax\" subtopic for how to use them.",
152     "If this option is not provided, default groups are generated.",
153     "The default groups are generated by reading selections from a file",
154     "[TT]defselection.dat[tt]. If such a file is found in the current",
155     "directory, it is used instead of the one provided by default.[PAR]",
156
157     "Depending on the tool, two additional command-line arguments may be",
158     "available to control the behavior:",
159     "",
160     " * [TT]-seltype[tt] can be used to specify the default type of",
161     "   positions to calculate for each selection.",
162     " * [TT]-selrpos[tt] can be used to specify the default type of",
163     "   positions used in selecting atoms by coordinates.",
164     "",
165     "See the \"positions\" subtopic for more information on these options.",
166 };
167
168 struct EvaluationHelpText
169 {
170     static const char        name[];
171     static const char        title[];
172     static const char *const text[];
173 };
174
175 const char        EvaluationHelpText::name[]  = "evaluation";
176 const char        EvaluationHelpText::title[] =
177     "Selection evaluation and optimization";
178 const char *const EvaluationHelpText::text[] = {
179     "Boolean evaluation proceeds from left to right and is short-circuiting",
180     "i.e., as soon as it is known whether an atom will be selected, the",
181     "remaining expressions are not evaluated at all.",
182     "This can be used to optimize the selections: you should write the",
183     "most restrictive and/or the most inexpensive expressions first in",
184     "boolean expressions.",
185     "The relative ordering between dynamic and static expressions does not",
186     "matter: all static expressions are evaluated only once, before the first",
187     "frame, and the result becomes the leftmost expression.[PAR]",
188
189     "Another point for optimization is in common subexpressions: they are not",
190     "automatically recognized, but can be manually optimized by the use of",
191     "variables. This can have a big impact on the performance of complex",
192     "selections, in particular if you define several index groups like this::",
193     "",
194     "  rdist = distance from com of resnr 1 to 5;",
195     "  resname RES and rdist < 2;",
196     "  resname RES and rdist < 4;",
197     "  resname RES and rdist < 6;",
198     "",
199     "Without the variable assignment, the distances would be evaluated three",
200     "times, although they are exactly the same within each selection.",
201     "Anything assigned into a variable becomes a common subexpression that",
202     "is evaluated only once during a frame.",
203     "Currently, in some cases the use of variables can actually lead to a small",
204     "performance loss because of the checks necessary to determine for which",
205     "atoms the expression has already been evaluated, but this should not be",
206     "a major problem.",
207 };
208
209 struct ExamplesHelpText
210 {
211     static const char        name[];
212     static const char        title[];
213     static const char *const text[];
214 };
215
216 const char        ExamplesHelpText::name[]  = "examples";
217 const char        ExamplesHelpText::title[] =
218     "Selection examples";
219 const char *const ExamplesHelpText::text[] = {
220     // TODO: Once there are more tools available, use examples that invoke
221     // tools and explain what the selections do in those tools.
222     "Below, examples of increasingly complex selections are given.[PAR]",
223
224     "Selection of all water oxygens::",
225     "",
226     "  resname SOL and name OW",
227     "",
228
229     "Centers of mass of residues 1 to 5 and 10::",
230     ""
231     "  res_com of resnr 1 to 5 10",
232     "",
233
234     "All atoms farther than 1 nm of a fixed position::",
235     "",
236     "  not within 1 of [1.2, 3.1, 2.4]",
237     "",
238
239     "All atoms of a residue LIG within 0.5 nm of a protein (with a custom name)::",
240     "",
241     "  \"Close to protein\" resname LIG and within 0.5 of group \"Protein\"",
242     "",
243
244     "All protein residues that have at least one atom within 0.5 nm of a residue LIG::",
245     "",
246     "  group \"Protein\" and same residue as within 0.5 of resname LIG",
247     "",
248
249     "All RES residues whose COM is between 2 and 4 nm from the COM of all of them::",
250     "",
251     "  rdist = res_com distance from com of resname RES",
252     "  resname RES and rdist >= 2 and rdist <= 4",
253     "",
254
255     "Selection like C1 C2 C2 C3 C3 C4 ... C8 C9 (e.g., for g_bond)::",
256     "",
257     "  name \"C[1-8]\" merge name \"C[2-9]\"",
258 };
259
260 struct KeywordsHelpText
261 {
262     static const char        name[];
263     static const char        title[];
264     static const char *const text[];
265 };
266
267 const char        KeywordsHelpText::name[]  = "keywords";
268 const char        KeywordsHelpText::title[] =
269     "Selection keywords";
270 const char *const KeywordsHelpText::text[] = {
271     "The following selection keywords are currently available.",
272     "For keywords marked with a star, additional help is available through",
273     "a subtopic KEYWORD, where KEYWORD is the name of the keyword.",
274 };
275
276 struct LimitationsHelpText
277 {
278     static const char        name[];
279     static const char        title[];
280     static const char *const text[];
281 };
282
283 const char        LimitationsHelpText::name[]  = "limitations";
284 const char        LimitationsHelpText::title[] =
285     "Selection limitations";
286 const char *const LimitationsHelpText::text[] = {
287     "* Some analysis programs may require a special structure for the input",
288     "  selections (e.g., some options of [TT]gmx gangle[tt] require the index",
289     "  group to be made of groups of three or four atoms).",
290     "  For such programs, it is up to the user to provide a proper selection",
291     "  expression that always returns such positions.",
292     "",
293     "* All selection keywords select atoms in increasing order, i.e., you can",
294     "  consider them as set operations that in the end return the atoms in",
295     "  sorted numerical order.  For example, the following selections select",
296     "  the same atoms in the same order::",
297     "",
298     "    resname RA RB RC",
299     "    resname RB RC RA",
300     "",
301     "  ::",
302     "",
303     "    atomnr 10 11 12 13",
304     "    atomnr 12 13 10 11",
305     "    atomnr 10 to 13",
306     "    atomnr 13 to 10",
307     "",
308     "  If you need atoms/positions in a different order, you can:",
309     "",
310     "  * use external index groups (for some static selections),",
311     "  * use the [TT]permute[tt] keyword to change the final order, or",
312     "  * use the [TT]merge[tt] or [TT]plus[tt] keywords to compose the",
313     "    final selection from multiple distinct selections.",
314     "",
315     "* Due to technical reasons, having a negative value as the first value in",
316     "  expressions like ::",
317     "",
318     "    charge -1 to -0.7",
319     "",
320     "  result in a syntax error. A workaround is to write ::",
321     "",
322     "    charge {-1 to -0.7}",
323     "",
324     "  instead.",
325     "",
326     "* When [TT]name[tt] selection keyword is used together with PDB input",
327     "  files, the behavior may be unintuitive. When GROMACS reads in a PDB",
328     "  file, 4 character atom names that start with a digit are transformed",
329     "  such that, e.g., 1HG2 becomes HG21, and the latter is what is matched",
330     "  by the [TT]name[tt] keyword. Use [TT]pdbname[tt] to match the atom name",
331     "  as it appears in the input PDB file.",
332 };
333
334 struct PositionsHelpText
335 {
336     static const char        name[];
337     static const char        title[];
338     static const char *const text[];
339 };
340
341 const char        PositionsHelpText::name[]  = "positions";
342 const char        PositionsHelpText::title[] =
343     "Specifying positions in selections";
344 const char *const PositionsHelpText::text[] = {
345     "Possible ways of specifying positions in selections are:[PAR]",
346
347     "1. A constant position can be defined as [TT][XX, YY, ZZ][tt], where",
348     "[TT]XX[tt], [TT]YY[tt] and [TT]ZZ[tt] are real numbers.[PAR]",
349
350     "2. [TT]com of ATOM_EXPR [pbc][tt] or [TT]cog of ATOM_EXPR [pbc][tt]",
351     "calculate the center of mass/geometry of [TT]ATOM_EXPR[tt]. If",
352     "[TT]pbc[tt] is specified, the center is calculated iteratively to try",
353     "to deal with cases where [TT]ATOM_EXPR[tt] wraps around periodic",
354     "boundary conditions.[PAR]",
355
356     "3. [TT]POSTYPE of ATOM_EXPR[tt] calculates the specified positions for",
357     "the atoms in [TT]ATOM_EXPR[tt].",
358     "[TT]POSTYPE[tt] can be [TT]atom[tt], [TT]res_com[tt], [TT]res_cog[tt],",
359     "[TT]mol_com[tt] or [TT]mol_cog[tt], with an optional prefix [TT]whole_[tt]",
360     "[TT]part_[tt] or [TT]dyn_[tt].",
361     "[TT]whole_[tt] calculates the centers for the whole residue/molecule,",
362     "even if only part of it is selected.",
363     "[TT]part_[tt] prefix calculates the centers for the selected atoms, but",
364     "uses always the same atoms for the same residue/molecule. The used atoms",
365     "are determined from the the largest group allowed by the selection.",
366     "[TT]dyn_[tt] calculates the centers strictly only for the selected atoms.",
367     "If no prefix is specified, whole selections default to [TT]part_[tt] and",
368     "other places default to [TT]whole_[tt].",
369     "The latter is often desirable to select the same molecules in different",
370     "tools, while the first is a compromise between speed ([TT]dyn_[tt]",
371     "positions can be slower to evaluate than [TT]part_[tt]) and intuitive",
372     "behavior.[PAR]",
373
374     "4. [TT]ATOM_EXPR[tt], when given for whole selections, is handled as 3.",
375     "above, using the position type from the command-line argument",
376     "[TT]-seltype[tt].[PAR]",
377
378     "Selection keywords that select atoms based on their positions, such as",
379     "[TT]dist from[tt], use by default the positions defined by the",
380     "[TT]-selrpos[tt] command-line option.",
381     "This can be overridden by prepending a [TT]POSTYPE[tt] specifier to the",
382     "keyword. For example, [TT]res_com dist from POS[tt] evaluates the",
383     "residue center of mass distances. In the example, all atoms of a residue",
384     "are either selected or not, based on the single distance calculated.",
385 };
386
387 struct SyntaxHelpText
388 {
389     static const char        name[];
390     static const char        title[];
391     static const char *const text[];
392 };
393
394 const char        SyntaxHelpText::name[]  = "syntax";
395 const char        SyntaxHelpText::title[] =
396     "Selection syntax";
397 const char *const SyntaxHelpText::text[] = {
398     "A set of selections consists of one or more selections, separated by",
399     "semicolons. Each selection defines a set of positions for the analysis.",
400     "Each selection can also be preceded by a string that gives a name for",
401     "the selection for use in, e.g., graph legends.",
402     "If no name is provided, the string used for the selection is used",
403     "automatically as the name.[PAR]",
404
405     "For interactive input, the syntax is slightly altered: line breaks can",
406     "also be used to separate selections. \\ followed by a line break can",
407     "be used to continue a line if necessary.",
408     "Notice that the above only applies to real interactive input,",
409     "not if you provide the selections, e.g., from a pipe.[PAR]",
410
411     "It is possible to use variables to store selection expressions.",
412     "A variable is defined with the following syntax::",
413     "",
414     "  VARNAME = EXPR ;",
415     "",
416     "where [TT]EXPR[tt] is any valid selection expression.",
417     "After this, [TT]VARNAME[tt] can be used anywhere where [TT]EXPR[tt]",
418     "would be valid.[PAR]",
419
420     "Selections are composed of three main types of expressions, those that",
421     "define atoms ([TT]ATOM_EXPR[tt]s), those that define positions",
422     "([TT]POS_EXPR[tt]s), and those that evaluate to numeric values",
423     "([TT]NUM_EXPR[tt]s). Each selection should be a [TT]POS_EXPR[tt]",
424     "or a [TT]ATOM_EXPR[tt] (the latter is automatically converted to",
425     "positions). The basic rules are as follows:",
426     "",
427     " * An expression like [TT]NUM_EXPR1 < NUM_EXPR2[tt] evaluates to an",
428     "   [TT]ATOM_EXPR[tt] that selects all the atoms for which the comparison",
429     "   is true.",
430     " * Atom expressions can be combined with boolean operations such as",
431     "   [TT]not ATOM_EXPR[tt], [TT]ATOM_EXPR and ATOM_EXPR[tt], or",
432     "   [TT]ATOM_EXPR or ATOM_EXPR[tt]. Parentheses can be used to alter the",
433     "   evaluation order.",
434     " * [TT]ATOM_EXPR[tt] expressions can be converted into [TT]POS_EXPR[tt]",
435     "   expressions in various ways, see the \"positions\" subtopic for more",
436     "   details.",
437     " * [TT]POS_EXPR[tt] can be converted into [TT]NUM_EXPR[tt] using syntax",
438     "   like \"x of POS_EXPR\". Currently, this is only supported for single",
439     "   positions like in expression \"x of cog of ATOM_EXPR\".",
440     "",
441
442     "Some keywords select atoms based on string values such as the atom name.",
443     "For these keywords, it is possible to use wildcards ([TT]name \"C*\"[tt])",
444     "or regular expressions (e.g., [TT]resname \"R[AB]\"[tt]).",
445     "The match type is automatically guessed from the string: if it contains",
446     "other characters than letters, numbers, '*', or '?', it is interpreted",
447     "as a regular expression.",
448     "To force the matching to use literal string matching, use",
449     "[TT]name = \"C*\"[tt] to match a literal C*.",
450     "To force other type of matching, use '?' or '~' in place of '=' to force",
451     "wildcard or regular expression matching, respectively.[PAR]",
452
453     "Strings that contain non-alphanumeric characters should be enclosed in",
454     "double quotes as in the examples. For other strings, the quotes are",
455     "optional, but if the value conflicts with a reserved keyword, a syntax",
456     "error will occur. If your strings contain uppercase letters, this should",
457     "not happen.[PAR]",
458
459     "Index groups provided with the [TT]-n[tt] command-line option or",
460     "generated by default can be accessed with [TT]group NR[tt] or",
461     "[TT]group NAME[tt], where [TT]NR[tt] is a zero-based index of the group",
462     "and [TT]NAME[tt] is part of the name of the desired group.",
463     "The keyword [TT]group[tt] is optional if the whole selection is",
464     "provided from an index group.",
465     "To see a list of available groups in the interactive mode, press enter",
466     "in the beginning of a line.",
467 };
468
469 } // namespace
470
471 namespace gmx
472 {
473
474 namespace
475 {
476
477 /*! \internal \brief
478  * Help topic implementation for an individual selection method.
479  *
480  * \ingroup module_selection
481  */
482 class KeywordDetailsHelpTopic : public AbstractSimpleHelpTopic
483 {
484     public:
485         //! Initialize help topic for the given selection method.
486         KeywordDetailsHelpTopic(const std::string         &name,
487                                 const gmx_ana_selmethod_t &method)
488             : name_(name), method_(method)
489         {
490         }
491
492         virtual const char *name() const
493         {
494             return name_.c_str();
495         }
496         virtual const char *title() const
497         {
498             return NULL;
499         }
500
501     protected:
502         virtual std::string helpText() const
503         {
504             return joinStrings(method_.help.help,
505                                method_.help.help + method_.help.nlhelp, "\n");
506         }
507
508     private:
509         std::string                name_;
510         const gmx_ana_selmethod_t &method_;
511
512         GMX_DISALLOW_COPY_AND_ASSIGN(KeywordDetailsHelpTopic);
513 };
514
515 /*! \internal \brief
516  * Custom help topic for printing a list of selection keywords.
517  *
518  * \ingroup module_selection
519  */
520 class KeywordsHelpTopic : public CompositeHelpTopic<KeywordsHelpText>
521 {
522     public:
523         KeywordsHelpTopic();
524
525         virtual void writeHelp(const HelpWriterContext &context) const;
526
527     private:
528         /*! \brief
529          * Container for known selection methods.
530          *
531          * The first item in the pair is the name of the selection method, and
532          * the second points to the static data structure that describes the
533          * method.
534          * The name in the first item may differ from the name of the static
535          * data structure if an alias is defined for that method.
536          */
537         typedef std::vector<std::pair<std::string,
538                                       const gmx_ana_selmethod_t *> >
539             MethodList;
540
541         /*! \brief
542          * Prints a brief list of keywords (selection methods) available.
543          *
544          * \param[in] context  Context for printing the help.
545          * \param[in] type     Only methods that return this type are printed.
546          * \param[in] bModifiers  If false, \ref SMETH_MODIFIER methods are
547          *      excluded, otherwise only them are printed.
548          */
549         void printKeywordList(const HelpWriterContext &context,
550                               e_selvalue_t type, bool bModifiers) const;
551
552         MethodList              methods_;
553 };
554
555 KeywordsHelpTopic::KeywordsHelpTopic()
556 {
557     // TODO: This is not a very elegant way of getting the list of selection
558     // methods, but this needs to be rewritten in any case if/when #652 is
559     // implemented.
560     boost::scoped_ptr<SelectionParserSymbolTable> symtab(
561             new SelectionParserSymbolTable);
562     gmx_ana_selmethod_register_defaults(symtab.get());
563
564     SelectionParserSymbolIterator symbol
565         = symtab->beginIterator(SelectionParserSymbol::MethodSymbol);
566     while (symbol != symtab->endIterator())
567     {
568         const std::string         &symname = symbol->name();
569         const gmx_ana_selmethod_t *method  = symbol->methodValue();
570         methods_.push_back(std::make_pair(std::string(symname), method));
571         if (method->help.nlhelp > 0 && method->help.help != NULL)
572         {
573             addSubTopic(HelpTopicPointer(
574                                 new KeywordDetailsHelpTopic(symname, *method)));
575         }
576         ++symbol;
577     }
578 }
579
580 void KeywordsHelpTopic::writeHelp(const HelpWriterContext &context) const
581 {
582     if (context.outputFormat() != eHelpOutputFormat_Console)
583     {
584         GMX_THROW(NotImplementedError(
585                           "Selection help is not implemented for this output format"));
586     }
587     // TODO: The markup here is not really appropriate, and printKeywordList()
588     // still prints raw text, but these are waiting for discussion of the
589     // markup format in #969.
590     context.writeTextBlock(helpText());
591     context.writeTextBlock("");
592
593     // Print the list of keywords
594     context.writeTextBlock("Keywords that select atoms by an integer property:");
595     context.writeTextBlock("(use in expressions or like \"atomnr 1 to 5 7 9\")");
596     printKeywordList(context, INT_VALUE, false);
597     context.writeTextBlock("");
598
599     context.writeTextBlock("Keywords that select atoms by a numeric property:");
600     context.writeTextBlock("(use in expressions or like \"occupancy 0.5 to 1\")");
601     printKeywordList(context, REAL_VALUE, false);
602     context.writeTextBlock("");
603
604     context.writeTextBlock("Keywords that select atoms by a string property:");
605     context.writeTextBlock("(use like \"name PATTERN [PATTERN] ...\")");
606     printKeywordList(context, STR_VALUE, false);
607     context.writeTextBlock("");
608
609     context.writeTextBlock("Additional keywords that directly select atoms:");
610     printKeywordList(context, GROUP_VALUE, false);
611     context.writeTextBlock("");
612
613     context.writeTextBlock("Keywords that directly evaluate to positions:");
614     context.writeTextBlock("(see also \"positions\" subtopic)");
615     printKeywordList(context, POS_VALUE, false);
616     context.writeTextBlock("");
617
618     context.writeTextBlock("Additional keywords:");
619     printKeywordList(context, POS_VALUE, true);
620     printKeywordList(context, NO_VALUE, true);
621 }
622
623 void KeywordsHelpTopic::printKeywordList(const HelpWriterContext &context,
624                                          e_selvalue_t             type,
625                                          bool                     bModifiers) const
626 {
627     File &file = context.outputFile();
628     MethodList::const_iterator iter;
629     for (iter = methods_.begin(); iter != methods_.end(); ++iter)
630     {
631         const gmx_ana_selmethod_t &method = *iter->second;
632         bool bIsModifier                  = (method.flags & SMETH_MODIFIER) != 0;
633         if (method.type == type && bModifiers == bIsModifier)
634         {
635             bool bHasHelp = (method.help.nlhelp > 0 && method.help.help != NULL);
636             file.writeString(formatString(" %c ", bHasHelp ? '*' : ' '));
637             if (method.help.syntax != NULL)
638             {
639                 file.writeLine(method.help.syntax);
640             }
641             else
642             {
643                 std::string symname = iter->first;
644                 if (symname != method.name)
645                 {
646                     symname.append(formatString(" (synonym for %s)", method.name));
647                 }
648                 file.writeLine(symname);
649             }
650         }
651     }
652 }
653
654 }   // namespace
655
656 //! \cond libapi */
657 HelpTopicPointer createSelectionHelpTopic()
658 {
659     CompositeHelpTopicPointer root(new CompositeHelpTopic<CommonHelpText>);
660     root->registerSubTopic<SimpleHelpTopic<ArithmeticHelpText> >();
661     root->registerSubTopic<SimpleHelpTopic<CmdLineHelpText> >();
662     root->registerSubTopic<SimpleHelpTopic<EvaluationHelpText> >();
663     root->registerSubTopic<SimpleHelpTopic<ExamplesHelpText> >();
664     root->registerSubTopic<KeywordsHelpTopic>();
665     root->registerSubTopic<SimpleHelpTopic<LimitationsHelpText> >();
666     root->registerSubTopic<SimpleHelpTopic<PositionsHelpText> >();
667     root->registerSubTopic<SimpleHelpTopic<SyntaxHelpText> >();
668     return move(root);
669 }
670 //! \endcond
671
672 } // namespace gmx