LOOS  v2.3.2
gridmask.cpp
1 /*
2  gridmask.cpp
3 
4 
5  Given an int grid that represents picked blobs, use this as a mask
6  against a double grid...
7 */
8 
9 
10 /*
11  This file is part of LOOS.
12 
13  LOOS (Lightweight Object-Oriented Structure library)
14  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
15  Department of Biochemistry and Biophysics
16  School of Medicine & Dentistry, University of Rochester
17 
18  This package (LOOS) is free software: you can redistribute it and/or modify
19  it under the terms of the GNU General Public License as published by
20  the Free Software Foundation under version 3 of the License.
21 
22  This package is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  GNU General Public License for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with this program. If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 
32 #include <loos.hpp>
33 #include <boost/format.hpp>
34 #include <boost/tuple/tuple.hpp>
35 #include <algorithm>
36 #include <sstream>
37 #include <limits>
38 
39 #include <DensityGrid.hpp>
40 
41 using namespace std;
42 using namespace loos;
43 using namespace DensityTools;
44 
45 
46 /*
47  * Applies a mask to an edm grid. This can select a particular
48  * region within the grid.
49  *
50  * Example:
51  * gridmask < foo_grid foo_picked > masked_foo
52  * This will apply the mask called \"foo_picked\" to the grid
53  * \"foo_grid\" and write out a new grid, \"masked_foo\". This
54  * assumes foo_picked was created with the \"pick_blob\" tool.
55  *
56  * This output my be converted to an xplor map and then used for
57  * visualization within pymol.
58  *
59 */
60 
61 
62 
63 int main(int argc, char *argv[]) {
64  if (argc != 2) {
65  cerr <<
66  "SYNOPSIS\n\tExtracts a region of density given a mask grid\n"
67  "\nDESCRIPTION\n\tThis tool will zero out any unwanted density\n"
68  "given a density grid and a grid mask. The grid mask is an integer\n"
69  "grid. Any non-zero element of the grid mask means that the corresponding\n"
70  "density from the density grid will be copied to the output grid.\n"
71  "All other locations will have a zero density value. (Think of an alpha-mask\n"
72  "in gimp or photoshop).\n"
73  "\nEXAMPLES\n\tgridmask <density.grid mask.grid >masked_density.grid\n"
74  "This will apply the mask.grid mask to the density.grid, writing the output\n"
75  "to masked_density.grid\n"
76  "\n"
77  "\tblobid --threshold 1 <foo.grid >foo_id.grid\n"
78  "\tpick_blob --model foo.pdb --selection 'resid == 65' <foo_id.grid >foo_picked.grid\n"
79  "\tgridmask <foo.grid foo_picked.grid >foo_masked.grid\n"
80  "This example will first threshold the density at 1.0, then it will find the blob\n"
81  "closest to residue 65. This blob is then used as a mask for the original density\n"
82  "grid. foo_picked.grid therefore contains the actual density values, but with\n"
83  "all extraneous density removed.\n";
84 
85  cerr << "Usage- gridmask <edm_grid mask_grid >masked_edm_grid\n";
86  exit(-1);
87  }
88 
89  DensityGrid<int> mask;
90  ifstream ifs(argv[1]);
91  if (!ifs) {
92  cerr << "Error - cannot open " << argv[1] << " for reading.\n";
93  exit(-10);
94  }
95 
96  ifs >> mask;
97 
99  cin >> data;
100 
101  DensityGridpoint dims = data.gridDims();
102  DensityGridpoint ddims = mask.gridDims();
103  if (dims != ddims) {
104  cerr << "Error - differing dimensions between mask and density grids.\n";
105  exit(-10);
106  }
107 
108  long k = dims[0] * dims[1] * dims[2];
109  for (long i=0; i<k; i++)
110  if (!mask(i))
111  data(i) = 0.0;
112 
113  cout << data;
114 }
STL namespace.
Namespace for most things not already encapsulated within a class.