LOOS  v2.3.2
model_calc.cpp
1 /*
2  model_calc.cpp
3 
4  (c) 2011 Tod D. Romo, Grossfield Lab
5  Department of Biochemistry
6  University of Rochster School of Medicine and Dentistry
7 
8 
9  C++ template for writing a tool that performs a calculation on a model
10 */
11 
12 
13 /*
14  This file is part of LOOS.
15 
16  LOOS (Lightweight Object-Oriented Structure library)
17  Copyright (c) 2011 Tod D. Romo
18  Department of Biochemistry and Biophysics
19  School of Medicine & Dentistry, University of Rochester
20 
21  This package (LOOS) is free software: you can redistribute it and/or modify
22  it under the terms of the GNU General Public License as published by
23  the Free Software Foundation under version 3 of the License.
24 
25  This package is distributed in the hope that it will be useful,
26  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  GNU General Public License for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with this program. If not, see <http://www.gnu.org/licenses/>.
32 
33 */
34 
35 
36 
37 #include <loos.hpp>
38 
39 using namespace std;
40 using namespace loos;
41 
42 namespace opts = loos::OptionsFramework;
43 namespace po = loos::OptionsFramework::po;
44 
45 
46 
47 // ----------------------------------------------------------------
48 // ***EDIT***
49 // The following code is for implementing tool-specific
50 // options if the tool requires them. If not, this section can be
51 // deleted.
52 
53 double option1;
54 int option2;
55 
56 
57 // The following conditional prevents this class from appearing in the
58 // Doxygen documentation for LOOS:
59 //
60 // @cond TOOLS_INTERNAL
61 class ToolOptions : public opts::OptionsPackage {
62 public:
63 
64  // Change these options to reflect what your tool needs
65  void addGeneric(po::options_description& o) {
66  o.add_options()
67  ("option1", po::value<double>(&option1)->default_value(0.0), "Tool Option #1")
68  ("option2", po::value<int>(&option2)->default_value(42), "Tool option #2");
69  }
70 
71  // The print() function returns a string that describes what all the
72  // options are set to (for logging purposes)
73  string print() const {
74  ostringstream oss;
75  oss << boost::format("option1=%f, option2=%d") % option1 % option2;
76  return(oss.str());
77  }
78 
79 };
80 // @endcond
81 // ----------------------------------------------------------------
82 
83 
84 
85 
86 int main(int argc, char *argv[]) {
87 
88  // Store the invocation information for logging later
89  string header = invocationHeader(argc, argv);
90 
91  // Build up the command-line options for this tool by instantiating
92  // the appropriate OptionsPackage objects...
93 
94  // Basic options should be used by all tools. It provides help,
95  // verbosity, and the ability to read options from a config file
97 
98  // This tool can operate on a subset of atoms. The BasicSelection
99  // object provides the "--selection" option.
101 
102  // ModelWithCoords handles reading in a model and optionally drawing
103  // the coordinates from another file (for example, using a PSF file
104  // with a PDB)
106 
107  // ***EDIT***
108  // Tool-specific options can be included here...
109  ToolOptions* topts = new ToolOptions;
110 
111  // ***EDIT***
112  // All of the OptionsPackages are combined via the AggregateOptions
113  // object. First instantiate it, then add the desired
114  // OptionsPackage objects. The order is important. We recommend
115  // you progress from general (Basic and Selection) to more specific
116  // (model) and finally the tool options.
117  opts::AggregateOptions options;
118  options.add(bopts).add(sopts).add(mopts).add(topts);
119 
120  // Parse the command-line. If an error occurred, help will already
121  // be displayed and it will return a FALSE value.
122  if (!options.parse(argc, argv))
123  exit(-1);
124 
125  // Pull the model from the options object (it will include coordinates)
126  AtomicGroup model = mopts->model;
127 
128  // Select the desired atoms to operate over...
129  AtomicGroup subset = selectAtoms(model, sopts->selection);
130 
131  // ***EDIT***
132  // Now iterate over all atoms in the subset and perform some
133  // computation...
134  for (AtomicGroup::iterator atom = subset.begin(); atom != subset.end(); ++atom) {
135  // Perform some calculation...
136  // calculateSomething(*atom)
137  }
138 
139  // ***EDIT***
140  // output results
141 }
Namespace for encapsulating options processing.
Provides a single LOOS selection (–selection)
STL namespace.
bool parse(int argc, char *argv[])
Parses a command line, returning true if parsing was ok.
Options common to all tools (including –fullhelp)
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
Request a model with coordinates.
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.
Combines a set of OptionsPackages.
AggregateOptions & add(OptionsPackage *pack)
Add a pointer to an OptionsPackage that will be used for options.