2 * This file is part of the GROMACS molecular simulation package.
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.
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.
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.
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.
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.
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.
37 * Implements functions in selhelp.h.
39 * \author Teemu Murtola <teemu.murtola@gmail.com>
40 * \ingroup module_selection
51 #include <boost/scoped_ptr.hpp>
53 #include "gromacs/onlinehelp/helptopic.h"
54 #include "gromacs/onlinehelp/helpwritercontext.h"
55 #include "gromacs/utility/exceptions.h"
56 #include "gromacs/utility/file.h"
57 #include "gromacs/utility/gmxassert.h"
58 #include "gromacs/utility/stringutil.h"
60 #include "selmethod.h"
68 static const char name[];
69 static const char title[];
70 static const char *const text[];
73 const char CommonHelpText::name[] = "selections";
74 const char CommonHelpText::title[] =
75 "Selection syntax and usage";
76 const char *const CommonHelpText::text[] = {
77 "Selections are used to select atoms/molecules/residues for analysis.",
78 "In contrast to traditional index files, selections can be dynamic, i.e.,",
79 "select different atoms for different trajectory frames. The GROMACS",
80 "manual contains a short introductory section to selections in the",
81 "Analysis chapter, including suggestions on how to get familiar with",
82 "selections if you are new to the concept. The subtopics listed below",
83 "provide more details on the technical and syntactic aspects of",
86 "Each analysis tool requires a different number of selections and the",
87 "selections are interpreted differently. The general idea is still the",
88 "same: each selection evaluates to a set of positions, where a position",
89 "can be an atom position or center-of-mass or center-of-geometry of",
90 "a set of atoms. The tool then uses these positions for its analysis to",
91 "allow very flexible processing. Some analysis tools may have limitations",
92 "on the types of selections allowed."
95 struct ArithmeticHelpText
97 static const char name[];
98 static const char title[];
99 static const char *const text[];
102 const char ArithmeticHelpText::name[] = "arithmetic";
103 const char ArithmeticHelpText::title[] =
104 "Arithmetic expressions in selections";
105 const char *const ArithmeticHelpText::text[] = {
106 "Basic arithmetic evaluation is supported for numeric expressions.",
107 "Supported operations are addition, subtraction, negation, multiplication,",
108 "division, and exponentiation (using ^).",
109 "Result of a division by zero or other illegal operations is undefined.",
112 struct CmdLineHelpText
114 static const char name[];
115 static const char title[];
116 static const char *const text[];
119 const char CmdLineHelpText::name[] = "cmdline";
120 const char CmdLineHelpText::title[] =
121 "Specifying selections from command line";
122 const char *const CmdLineHelpText::text[] = {
123 "If no selections are provided on the command line, you are prompted to",
124 "type the selections interactively (a pipe can also be used to provide",
125 "the selections in this case for most tools). While this works well for",
126 "testing, it is easier to provide the selections from the command line",
127 "if they are complex or for scripting.[PAR]",
129 "Each tool has different command-line arguments for specifying selections",
130 "(listed by [TT][PROGRAM] help <tool>[tt]).",
131 "You can either pass a single string containing all selections (separated",
132 "by semicolons), or multiple strings, each containing one selection.",
133 "Note that you need to quote the selections to protect them from the",
136 "If you set a selection command-line argument, but do not provide any",
137 "selections, you are prompted to type the selections for that argument",
138 "interactively. This is useful if that selection argument is optional,",
139 "in which case it is not normally prompted for.[PAR]",
141 "To provide selections from a file, use [TT]-sf file.dat[tt] in the place",
142 "of the selection for a selection argument (e.g.,",
143 "[TT]-select -sf file.dat[tt]). In general, the [TT]-sf[tt] argument reads",
144 "selections from the provided file and assigns them to selection arguments",
145 "that have been specified up to that point, but for which no selections",
146 "have been provided.",
147 "As a special case, [TT]-sf[tt] provided on its own, without preceding",
148 "selection arguments, assigns the selections to all (yet unset) required",
149 "selections (i.e., those that would be promted interactively if no",
150 "selections are provided on the command line).[PAR]",
152 "To use groups from a traditional index file, use argument [TT]-n[tt]",
153 "to provide a file. See the \"syntax\" subtopic for how to use them.",
154 "If this option is not provided, default groups are generated.",
155 "The default groups are generated with the same logic as for",
156 "non-selection tools.",
158 "Depending on the tool, two additional command-line arguments may be",
159 "available to control the behavior:",
161 "* [TT]-seltype[tt] can be used to specify the default type of",
162 " positions to calculate for each selection.",
163 "* [TT]-selrpos[tt] can be used to specify the default type of",
164 " positions used in selecting atoms by coordinates.",
166 "See the \"positions\" subtopic for more information on these options.",
169 struct EvaluationHelpText
171 static const char name[];
172 static const char title[];
173 static const char *const text[];
176 const char EvaluationHelpText::name[] = "evaluation";
177 const char EvaluationHelpText::title[] =
178 "Selection evaluation and optimization";
179 const char *const EvaluationHelpText::text[] = {
180 "Boolean evaluation proceeds from left to right and is short-circuiting",
181 "i.e., as soon as it is known whether an atom will be selected, the",
182 "remaining expressions are not evaluated at all.",
183 "This can be used to optimize the selections: you should write the",
184 "most restrictive and/or the most inexpensive expressions first in",
185 "boolean expressions.",
186 "The relative ordering between dynamic and static expressions does not",
187 "matter: all static expressions are evaluated only once, before the first",
188 "frame, and the result becomes the leftmost expression.[PAR]",
190 "Another point for optimization is in common subexpressions: they are not",
191 "automatically recognized, but can be manually optimized by the use of",
192 "variables. This can have a big impact on the performance of complex",
193 "selections, in particular if you define several index groups like this::",
195 " rdist = distance from com of resnr 1 to 5;",
196 " resname RES and rdist < 2;",
197 " resname RES and rdist < 4;",
198 " resname RES and rdist < 6;",
200 "Without the variable assignment, the distances would be evaluated three",
201 "times, although they are exactly the same within each selection.",
202 "Anything assigned into a variable becomes a common subexpression that",
203 "is evaluated only once during a frame.",
204 "Currently, in some cases the use of variables can actually lead to a small",
205 "performance loss because of the checks necessary to determine for which",
206 "atoms the expression has already been evaluated, but this should not be",
210 struct ExamplesHelpText
212 static const char name[];
213 static const char title[];
214 static const char *const text[];
217 const char ExamplesHelpText::name[] = "examples";
218 const char ExamplesHelpText::title[] =
219 "Selection examples";
220 const char *const ExamplesHelpText::text[] = {
221 "Below, examples of different types of selections are given.",
223 "* Selection of all water oxygens::",
225 " resname SOL and name OW",
227 "* Centers of mass of residues 1 to 5 and 10::",
229 " res_com of resnr 1 to 5 10",
231 "* All atoms farther than 1 nm of a fixed position::",
233 " not within 1 of [1.2, 3.1, 2.4]",
235 "* All atoms of a residue LIG within 0.5 nm of a protein (with a custom name)::",
237 " \"Close to protein\" resname LIG and within 0.5 of group \"Protein\"",
239 "* All protein residues that have at least one atom within 0.5 nm of a residue LIG::",
241 " group \"Protein\" and same residue as within 0.5 of resname LIG",
243 "* All RES residues whose COM is between 2 and 4 nm from the COM of all of them::",
245 " rdist = res_com distance from com of resname RES",
246 " resname RES and rdist >= 2 and rdist <= 4",
248 // TODO: Make it possible to use links below.
249 "* Selection like with duplicate atoms like C1 C2 C2 C3 C3 C4 ... C8 C9::",
251 " name \"C[1-8]\" merge name \"C[2-9]\"",
253 " This can be used with [TT]gmx distance[tt] to compute C1-C2, C2-C3 etc.",
256 "* Selection with atoms in order C2 C1::",
258 " name C1 C2 permute 2 1",
260 " This can be used with [TT]gmx gangle[tt] to get C2->C1 vectors instead of",
263 "* Selection with COMs of two index groups::",
265 " com of group 1 plus com of group 2",
267 " This can be used with [TT]gmx distance[tt] to compute the distance between",
270 "* Fixed vector along x (can be used as a reference with [TT]gmx gangle[tt])::",
272 " [0, 0, 0] plus [1, 0, 0]",
274 "* The following examples explain the difference between the various",
275 " position types. This selection selects a position for each residue",
276 " where any of the three atoms C[123] has [TT]x < 2[tt]. The positions",
277 " are computed as the COM of all three atoms.",
278 " This is the default behavior if you just write [TT]res_com of[tt]. ::",
280 " part_res_com of name C1 C2 C3 and x < 2",
282 " This selection does the same, but the positions are computed as COM",
283 " positions of whole residues::",
285 " whole_res_com of name C1 C2 C3 and x < 2",
287 " Finally, this selection selects the same residues, but the positions",
288 " are computed as COM of exactly those atoms atoms that match the",
289 " [TT]x < 2[tt] criterion::",
291 " dyn_res_com of name C1 C2 C3 and x < 2",
293 "* Without the [TT]of[tt] keyword, the default behavior is different from",
294 " above, but otherwise the rules are the same::",
296 " name C1 C2 C3 and res_com x < 2",
298 " works as if [TT]whole_res_com[tt] was specified, and selects the three",
299 " atoms from residues whose COM satisfiex [TT]x < 2[tt].",
302 " name C1 C2 C3 and part_res_com x < 2",
304 " instead selects residues based on the COM computed from the C[123] atoms.",
307 struct KeywordsHelpText
309 static const char name[];
310 static const char title[];
311 static const char *const text[];
314 const char KeywordsHelpText::name[] = "keywords";
315 const char KeywordsHelpText::title[] =
316 "Selection keywords";
317 const char *const KeywordsHelpText::text[] = {
318 "The following selection keywords are currently available.",
319 "For keywords marked with a star, additional help is available through",
320 "a subtopic KEYWORD, where KEYWORD is the name of the keyword.",
323 struct LimitationsHelpText
325 static const char name[];
326 static const char title[];
327 static const char *const text[];
330 const char LimitationsHelpText::name[] = "limitations";
331 const char LimitationsHelpText::title[] =
332 "Selection limitations";
333 const char *const LimitationsHelpText::text[] = {
334 "* Some analysis programs may require a special structure for the input",
335 " selections (e.g., some options of [TT]gmx gangle[tt] require the index",
336 " group to be made of groups of three or four atoms).",
337 " For such programs, it is up to the user to provide a proper selection",
338 " expression that always returns such positions.",
340 "* All selection keywords select atoms in increasing order, i.e., you can",
341 " consider them as set operations that in the end return the atoms in",
342 " sorted numerical order. For example, the following selections select",
343 " the same atoms in the same order::",
350 " atomnr 10 11 12 13",
351 " atomnr 12 13 10 11",
355 " If you need atoms/positions in a different order, you can:",
357 " * use external index groups (for some static selections),",
358 " * use the [TT]permute[tt] keyword to change the final order, or",
359 " * use the [TT]merge[tt] or [TT]plus[tt] keywords to compose the",
360 " final selection from multiple distinct selections.",
362 "* Due to technical reasons, having a negative value as the first value in",
363 " expressions like ::",
365 " charge -1 to -0.7",
367 " result in a syntax error. A workaround is to write ::",
369 " charge {-1 to -0.7}",
373 "* When [TT]name[tt] selection keyword is used together with PDB input",
374 " files, the behavior may be unintuitive. When GROMACS reads in a PDB",
375 " file, 4 character atom names that start with a digit are transformed",
376 " such that, e.g., 1HG2 becomes HG21, and the latter is what is matched",
377 " by the [TT]name[tt] keyword. Use [TT]pdbname[tt] to match the atom name",
378 " as it appears in the input PDB file.",
381 struct PositionsHelpText
383 static const char name[];
384 static const char title[];
385 static const char *const text[];
388 const char PositionsHelpText::name[] = "positions";
389 const char PositionsHelpText::title[] =
390 "Specifying positions in selections";
391 const char *const PositionsHelpText::text[] = {
392 "Possible ways of specifying positions in selections are:[PAR]",
394 "1. A constant position can be defined as [TT][XX, YY, ZZ][tt], where",
395 "[TT]XX[tt], [TT]YY[tt] and [TT]ZZ[tt] are real numbers.[PAR]",
397 "2. [TT]com of ATOM_EXPR [pbc][tt] or [TT]cog of ATOM_EXPR [pbc][tt]",
398 "calculate the center of mass/geometry of [TT]ATOM_EXPR[tt]. If",
399 "[TT]pbc[tt] is specified, the center is calculated iteratively to try",
400 "to deal with cases where [TT]ATOM_EXPR[tt] wraps around periodic",
401 "boundary conditions.[PAR]",
403 "3. [TT]POSTYPE of ATOM_EXPR[tt] calculates the specified positions for",
404 "the atoms in [TT]ATOM_EXPR[tt].",
405 "[TT]POSTYPE[tt] can be [TT]atom[tt], [TT]res_com[tt], [TT]res_cog[tt],",
406 "[TT]mol_com[tt] or [TT]mol_cog[tt], with an optional prefix [TT]whole_[tt]",
407 "[TT]part_[tt] or [TT]dyn_[tt].",
408 "[TT]whole_[tt] calculates the centers for the whole residue/molecule,",
409 "even if only part of it is selected.",
410 "[TT]part_[tt] prefix calculates the centers for the selected atoms, but",
411 "uses always the same atoms for the same residue/molecule. The used atoms",
412 "are determined from the the largest group allowed by the selection.",
413 "[TT]dyn_[tt] calculates the centers strictly only for the selected atoms.",
414 "If no prefix is specified, whole selections default to [TT]part_[tt] and",
415 "other places default to [TT]whole_[tt].",
416 "The latter is often desirable to select the same molecules in different",
417 "tools, while the first is a compromise between speed ([TT]dyn_[tt]",
418 "positions can be slower to evaluate than [TT]part_[tt]) and intuitive",
421 "4. [TT]ATOM_EXPR[tt], when given for whole selections, is handled as 3.",
422 "above, using the position type from the command-line argument",
423 "[TT]-seltype[tt].[PAR]",
425 "Selection keywords that select atoms based on their positions, such as",
426 "[TT]dist from[tt], use by default the positions defined by the",
427 "[TT]-selrpos[tt] command-line option.",
428 "This can be overridden by prepending a [TT]POSTYPE[tt] specifier to the",
429 "keyword. For example, [TT]res_com dist from POS[tt] evaluates the",
430 "residue center of mass distances. In the example, all atoms of a residue",
431 "are either selected or not, based on the single distance calculated.",
434 struct SyntaxHelpText
436 static const char name[];
437 static const char title[];
438 static const char *const text[];
441 const char SyntaxHelpText::name[] = "syntax";
442 const char SyntaxHelpText::title[] =
444 const char *const SyntaxHelpText::text[] = {
445 "A set of selections consists of one or more selections, separated by",
446 "semicolons. Each selection defines a set of positions for the analysis.",
447 "Each selection can also be preceded by a string that gives a name for",
448 "the selection for use in, e.g., graph legends.",
449 "If no name is provided, the string used for the selection is used",
450 "automatically as the name.[PAR]",
452 "For interactive input, the syntax is slightly altered: line breaks can",
453 "also be used to separate selections. \\ followed by a line break can",
454 "be used to continue a line if necessary.",
455 "Notice that the above only applies to real interactive input,",
456 "not if you provide the selections, e.g., from a pipe.[PAR]",
458 "It is possible to use variables to store selection expressions.",
459 "A variable is defined with the following syntax::",
463 "where [TT]EXPR[tt] is any valid selection expression.",
464 "After this, [TT]VARNAME[tt] can be used anywhere where [TT]EXPR[tt]",
465 "would be valid.[PAR]",
467 "Selections are composed of three main types of expressions, those that",
468 "define atoms ([TT]ATOM_EXPR[tt]), those that define positions",
469 "([TT]POS_EXPR[tt]), and those that evaluate to numeric values",
470 "([TT]NUM_EXPR[tt]). Each selection should be a [TT]POS_EXPR[tt]",
471 "or a [TT]ATOM_EXPR[tt] (the latter is automatically converted to",
472 "positions). The basic rules are as follows:",
474 "* An expression like [TT]NUM_EXPR1 < NUM_EXPR2[tt] evaluates to an",
475 " [TT]ATOM_EXPR[tt] that selects all the atoms for which the comparison",
477 "* Atom expressions can be combined with boolean operations such as",
478 " [TT]not ATOM_EXPR[tt], [TT]ATOM_EXPR and ATOM_EXPR[tt], or",
479 " [TT]ATOM_EXPR or ATOM_EXPR[tt]. Parentheses can be used to alter the",
480 " evaluation order.",
481 "* [TT]ATOM_EXPR[tt] expressions can be converted into [TT]POS_EXPR[tt]",
482 " expressions in various ways, see the \"positions\" subtopic for more",
484 "* [TT]POS_EXPR[tt] can be converted into [TT]NUM_EXPR[tt] using syntax",
485 " like \"[TT]x of POS_EXPR[tt]\". Currently, this is only supported for single",
486 " positions like in expression \"[TT]x of cog of ATOM_EXPR[tt]\".",
489 "Some keywords select atoms based on string values such as the atom name.",
490 "For these keywords, it is possible to use wildcards ([TT]name \"C*\"[tt])",
491 "or regular expressions (e.g., [TT]resname \"R[AB]\"[tt]).",
492 "The match type is automatically guessed from the string: if it contains",
493 "other characters than letters, numbers, '*', or '?', it is interpreted",
494 "as a regular expression.",
495 "To force the matching to use literal string matching, use",
496 "[TT]name = \"C*\"[tt] to match a literal C*.",
497 "To force other type of matching, use '?' or '~' in place of '=' to force",
498 "wildcard or regular expression matching, respectively.[PAR]",
500 "Strings that contain non-alphanumeric characters should be enclosed in",
501 "double quotes as in the examples. For other strings, the quotes are",
502 "optional, but if the value conflicts with a reserved keyword, a syntax",
503 "error will occur. If your strings contain uppercase letters, this should",
506 "Index groups provided with the [TT]-n[tt] command-line option or",
507 "generated by default can be accessed with [TT]group NR[tt] or",
508 "[TT]group NAME[tt], where [TT]NR[tt] is a zero-based index of the group",
509 "and [TT]NAME[tt] is part of the name of the desired group.",
510 "The keyword [TT]group[tt] is optional if the whole selection is",
511 "provided from an index group.",
512 "To see a list of available groups in the interactive mode, press enter",
513 "in the beginning of a line.",
525 * Help topic implementation for an individual selection method.
527 * \ingroup module_selection
529 class KeywordDetailsHelpTopic : public AbstractSimpleHelpTopic
532 //! Initialize help topic for the given selection method.
533 KeywordDetailsHelpTopic(const std::string &name,
534 const gmx_ana_selmethod_t &method)
535 : name_(name), method_(method)
539 virtual const char *name() const
541 return name_.c_str();
543 virtual const char *title() const
545 return method_.help.helpTitle;
549 virtual std::string helpText() const
551 return joinStrings(method_.help.help,
552 method_.help.help + method_.help.nlhelp, "\n");
557 const gmx_ana_selmethod_t &method_;
559 GMX_DISALLOW_COPY_AND_ASSIGN(KeywordDetailsHelpTopic);
563 * Custom help topic for printing a list of selection keywords.
565 * \ingroup module_selection
567 class KeywordsHelpTopic : public CompositeHelpTopic<KeywordsHelpText>
572 virtual void writeHelp(const HelpWriterContext &context) const;
576 * Container for known selection methods.
578 * The first item in the pair is the name of the selection method, and
579 * the second points to the static data structure that describes the
581 * The name in the first item may differ from the name of the static
582 * data structure if an alias is defined for that method.
584 typedef std::vector<std::pair<std::string,
585 const gmx_ana_selmethod_t *> >
589 * Prints markup for starting a list of keywords.
591 void writeKeywordListStart(const HelpWriterContext &context,
592 const char *heading) const;
594 * Prints markup for ending a list of keywords.
596 void writeKeywordListEnd(const HelpWriterContext &context,
597 const char *extraInfo) const;
600 * Prints a brief list of keywords (selection methods) available.
602 * \param[in] context Context for printing the help.
603 * \param[in] type Only methods that return this type are printed.
604 * \param[in] bModifiers If false, \ref SMETH_MODIFIER methods are
605 * excluded, otherwise only them are printed.
607 void printKeywordList(const HelpWriterContext &context,
608 e_selvalue_t type, bool bModifiers) const;
611 * Prints the detailed help for keywords for rst export.
613 void writeKeywordSubTopics(const HelpWriterContext &context) const;
618 KeywordsHelpTopic::KeywordsHelpTopic()
620 // TODO: This is not a very elegant way of getting the list of selection
621 // methods, but this needs to be rewritten in any case if/when #652 is
623 boost::scoped_ptr<SelectionParserSymbolTable> symtab(
624 new SelectionParserSymbolTable);
625 gmx_ana_selmethod_register_defaults(symtab.get());
627 SelectionParserSymbolIterator symbol
628 = symtab->beginIterator(SelectionParserSymbol::MethodSymbol);
629 while (symbol != symtab->endIterator())
631 const std::string &symname = symbol->name();
632 const gmx_ana_selmethod_t *method = symbol->methodValue();
633 methods_.push_back(std::make_pair(std::string(symname), method));
634 if (method->help.nlhelp > 0 && method->help.help != NULL)
636 addSubTopic(HelpTopicPointer(
637 new KeywordDetailsHelpTopic(symname, *method)));
643 void KeywordsHelpTopic::writeHelp(const HelpWriterContext &context) const
645 context.writeTextBlock(helpText());
646 context.writeTextBlock("");
648 // Print the list of keywords
649 writeKeywordListStart(context, "Keywords that select atoms by an integer property:");
650 printKeywordList(context, INT_VALUE, false);
651 writeKeywordListEnd(context, "(use in expressions or like \"atomnr 1 to 5 7 9\")");
653 writeKeywordListStart(context, "Keywords that select atoms by a numeric property:");
654 printKeywordList(context, REAL_VALUE, false);
655 writeKeywordListEnd(context, "(use in expressions or like \"occupancy 0.5 to 1\")");
657 writeKeywordListStart(context, "Keywords that select atoms by a string property:");
658 printKeywordList(context, STR_VALUE, false);
659 writeKeywordListEnd(context, "(use like \"name PATTERN [PATTERN] ...\")");
661 writeKeywordListStart(context, "Additional keywords that directly select atoms:");
662 printKeywordList(context, GROUP_VALUE, false);
663 writeKeywordListEnd(context, NULL);
665 writeKeywordListStart(context, "Keywords that directly evaluate to positions:");
666 printKeywordList(context, POS_VALUE, false);
667 writeKeywordListEnd(context, "(see also \"positions\" subtopic)");
669 writeKeywordListStart(context, "Additional keywords:");
670 printKeywordList(context, POS_VALUE, true);
671 printKeywordList(context, NO_VALUE, true);
672 writeKeywordListEnd(context, NULL);
674 writeKeywordSubTopics(context);
677 void KeywordsHelpTopic::writeKeywordListStart(const HelpWriterContext &context,
678 const char *heading) const
680 context.writeTextBlock(heading);
681 if (context.outputFormat() == eHelpOutputFormat_Rst)
683 context.writeTextBlock("");
684 context.writeTextBlock("::");
685 context.writeTextBlock("");
689 void KeywordsHelpTopic::writeKeywordListEnd(const HelpWriterContext &context,
690 const char *extraInfo) const
692 if (context.outputFormat() == eHelpOutputFormat_Rst)
694 context.writeTextBlock("");
696 if (!isNullOrEmpty(extraInfo))
698 context.writeTextBlock(extraInfo);
700 context.writeTextBlock("");
703 void KeywordsHelpTopic::printKeywordList(const HelpWriterContext &context,
705 bool bModifiers) const
707 File &file = context.outputFile();
708 MethodList::const_iterator iter;
709 for (iter = methods_.begin(); iter != methods_.end(); ++iter)
711 const gmx_ana_selmethod_t &method = *iter->second;
712 const bool bIsModifier
713 = (method.flags & SMETH_MODIFIER) != 0;
714 if (method.type == type && bModifiers == bIsModifier)
716 const bool bHasHelp = (method.help.nlhelp > 0 && method.help.help != NULL);
717 const bool bPrintStar
718 = bHasHelp && context.outputFormat() == eHelpOutputFormat_Console;
719 file.writeString(formatString(" %c ", bPrintStar ? '*' : ' '));
720 if (method.help.syntax != NULL)
722 file.writeLine(method.help.syntax);
726 std::string symname = iter->first;
727 if (symname != method.name)
729 symname.append(formatString(" (synonym for %s)", method.name));
731 file.writeLine(symname);
737 void KeywordsHelpTopic::writeKeywordSubTopics(const HelpWriterContext &context) const
739 if (context.outputFormat() != eHelpOutputFormat_Rst)
743 std::set<std::string> usedSymbols;
744 MethodList::const_iterator iter;
745 for (iter = methods_.begin(); iter != methods_.end(); ++iter)
747 const gmx_ana_selmethod_t &method = *iter->second;
749 = (method.help.nlhelp > 0 && method.help.help != NULL);
750 if (!bHasHelp || usedSymbols.count(iter->first) > 0)
756 if (method.help.helpTitle != NULL)
758 title = method.help.helpTitle;
761 title.append(iter->first);
762 MethodList::const_iterator mergeIter = iter;
763 for (++mergeIter; mergeIter != methods_.end(); ++mergeIter)
765 if (mergeIter->second->help.help == method.help.help)
768 title.append(mergeIter->first);
769 usedSymbols.insert(mergeIter->first);
773 const HelpTopicInterface *subTopic = findSubTopic(iter->first.c_str());
774 GMX_RELEASE_ASSERT(subTopic != NULL, "Keyword subtopic no longer exists");
775 HelpWriterContext subContext(context);
776 subContext.enterSubSection(title);
777 subTopic->writeHelp(subContext);
778 context.writeTextBlock("");
785 HelpTopicPointer createSelectionHelpTopic()
787 CompositeHelpTopicPointer root(new CompositeHelpTopic<CommonHelpText>);
788 root->registerSubTopic<SimpleHelpTopic<CmdLineHelpText> >();
789 root->registerSubTopic<SimpleHelpTopic<SyntaxHelpText> >();
790 root->registerSubTopic<SimpleHelpTopic<PositionsHelpText> >();
791 root->registerSubTopic<SimpleHelpTopic<ArithmeticHelpText> >();
792 root->registerSubTopic<KeywordsHelpTopic>();
793 root->registerSubTopic<SimpleHelpTopic<EvaluationHelpText> >();
794 root->registerSubTopic<SimpleHelpTopic<LimitationsHelpText> >();
795 root->registerSubTopic<SimpleHelpTopic<ExamplesHelpText> >();