LOOS  v2.3.2
traj_calc.cpp
1 /*
2  traj_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 trajectory
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 // ***EDIT***
85 void calculate(const AtomicGroup& structure) {
86  // Do something here with an atom...
87 }
88 
89 
90 
91 
92 int main(int argc, char *argv[]) {
93 
94  // Store the invocation information for logging later
95  string header = invocationHeader(argc, argv);
96 
97  // Build up the command-line options for this tool by instantiating
98  // the appropriate OptionsPackage objects...
99 
100  // Basic options should be used by all tools. It provides help,
101  // verbosity, and the ability to read options from a config file
103 
104  // This tool can operate on a subset of atoms. The BasicSelection
105  // object provides the "--selection" option.
107 
108  // The BasicTrajectory object handles specifying a trajectory as
109  // well as a "--skip" option that lets the tool skip the first
110  // number of frames (i.e. equilibration). It creates a pTraj object
111  // that is already primed for reading...
113 
114  // ***EDIT***
115  // Tool-specific options can be included here...
116  ToolOptions* topts = new ToolOptions;
117 
118  // ***EDIT***
119  // All of the OptionsPackages are combined via the AggregateOptions
120  // object. First instantiate it, then add the desired
121  // OptionsPackage objects. The order is important. We recommend
122  // you progress from general (Basic and Selection) to more specific
123  // (model) and finally the tool options.
124  opts::AggregateOptions options;
125  options.add(bopts).add(sopts).add(tropts).add(topts);
126 
127  // Parse the command-line. If an error occurred, help will already
128  // be displayed and it will return a FALSE value.
129  if (!options.parse(argc, argv))
130  exit(-1);
131 
132  // Pull the model from the options object (it will include coordinates)
133  AtomicGroup model = tropts->model;
134 
135  // Pull out the trajectory...
136  pTraj traj = tropts->trajectory;
137 
138  // Select the desired atoms to operate over...
139  AtomicGroup subset = selectAtoms(model, sopts->selection);
140 
141  // Now iterate over all frames in the trajectory (excluding the skip
142  // region)
143  while (traj->readFrame()) {
144 
145  // Update the coordinates ONLY for the subset of atoms we're
146  // interested in...
147  traj->updateGroupCoords(subset);
148 
149  // ***EDIT***
150  // Now calculate something with the AtomicGroup
151  calculate(subset);
152  }
153 
154  // ***EDIT***
155  // Output results...
156 
157 }
pTraj trajectory
The trajectory, primed by the –skip value (if specified)
Namespace for encapsulating options processing.
Provides a single LOOS selection (–selection)
STL namespace.
AtomicGroup model
Model that describes the trajectory.
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
Basic trajectory with a –skip option.
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
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.