LOOS  v2.3.2
contained.cpp
1 /*
2  contained.cpp
3 
4  Tracks the number of atoms within a blob over time...
5 
6  usage:
7  contained model trajectory selection grid
8 */
9 
10 
11 /*
12  This file is part of LOOS.
13 
14  LOOS (Lightweight Object-Oriented Structure library)
15  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
16  Department of Biochemistry and Biophysics
17  School of Medicine & Dentistry, University of Rochester
18 
19  This package (LOOS) is free software: you can redistribute it and/or modify
20  it under the terms of the GNU General Public License as published by
21  the Free Software Foundation under version 3 of the License.
22 
23  This package is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  GNU General Public License for more details.
27 
28  You should have received a copy of the GNU General Public License
29  along with this program. If not, see <http://www.gnu.org/licenses/>.
30 */
31 
32 
33 
34 
35 #include <loos.hpp>
36 
37 #include <boost/tuple/tuple.hpp>
38 #include <limits>
39 #include <list>
40 
41 #include <DensityGrid.hpp>
42 #include <DensityTools.hpp>
43 
44 
45 using namespace std;
46 using namespace loos;
47 using namespace loos::DensityTools;
48 
49 string fullHelpMessage(void) {
50  string msg =
51  "\n"
52  "SYNOPSIS\n"
53  "\n"
54  "\tCount the number of atoms that are within density for an int-grid.\n"
55  "\n"
56  "DESCRIPTION\n"
57  "\n"
58  "\tThis tool generates a time-series representing the number of atoms\n"
59  "that are within density for each frame in a trajectory. Density is\n"
60  "defined as any non-zero grid element.\n"
61  "\nEXAMPLES\n"
62  "\tblobid --threshold 1 <foo.grid >foo_id.grid\n"
63  "\tpick_blob_blob --model foo.pdb --selection 'resid == 65' <foo_id.grid >foo_picked.grid\n"
64  "\tcontained --selection 'name == \"OH2\"' foo_picked.grid\n"
65  "This example first segments (thresholds) the density at 1.0, and then finds the blob\n"
66  "closest to residue 65. The number of water oxygens at each time-step in the trajectory\n"
67  "that are within this blob near residue 65 is written out.\n"
68  "\n"
69  "NOTES\n\n"
70  "\tThis tool only works with integer grids (i.e. a grid that has already been\n"
71  "segmented into blobs), NOT raw density.\n"
72  "SEE ALSO\n\n"
73  "\tblobid, pick_blob\n";
74 
75  return(msg);
76 }
77 
78 
79 
80 int main(int argc, char *argv[]) {
81  string hdr = invocationHeader(argc, argv);
82  opts::BasicOptions *basic_opts = new opts::BasicOptions(fullHelpMessage());
83  opts::BasicSelection *basic_selection = new opts::BasicSelection;
86  ropts->addArgument("grid", "grid-name");
87 
88  opts::AggregateOptions options;
89  options.add(basic_opts).add(basic_selection).add(basic_traj).add(ropts);
90  if (!options.parse(argc, argv)) {
91  exit(0);
92  }
93 
94  AtomicGroup model = basic_traj->model;
95  pTraj traj = basic_traj->trajectory;
96  AtomicGroup subset = selectAtoms(model, basic_selection->selection);
97  vector<uint> frames = basic_traj->frameList();
98 
99 
100 
101  cout << "# " << hdr << endl;
102  cout << "# frame n\n";
103  DensityGrid<int> grid;
104 
105  string grid_name = ropts->value("grid");
106  ifstream ifs(grid_name.c_str());
107  if (!ifs) {
108  cerr << "Error- cannot open " << grid_name << endl;
109  exit(-1);
110  }
111  ifs >> grid;
112 
113  for (vector<uint>::iterator i = frames.begin(); i != frames.end(); ++i) {
114  traj->readFrame(*i);
115  traj->updateGroupCoords(subset);
116 
117  long n = 0;
118  for (AtomicGroup::iterator j = subset.begin(); j != subset.end(); ++j) {
119  DensityGridpoint point = grid.gridpoint((*j)->coords());
120  if (!grid.inRange(point))
121  continue;
122  if (grid(point) != 0)
123  ++n;
124  }
125 
126  cout << *i << " " << n << endl;
127  }
128 }
129 
Trajectory with either a –range or –skip.
Provides simple way to add command-line arguments (required options)
Provides a single LOOS selection (–selection)
void addArgument(const std::string &name, const std::string &description)
Add a required argument given a name (tag) and a description (currently unused)
STL namespace.
bool parse(int argc, char *argv[])
Parses a command line, returning true if parsing was ok.
AtomicGroup model
Model that describes the trajectory.
Options common to all tools (including –fullhelp)
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
Namespace for Density package.
Definition: DensityGrid.hpp:48
std::string value(const std::string &s) const
Retrieve the value for an argument.
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
std::vector< uint > frameList() const
Returns the list of frames the user requested.
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.