LOOS  v2.3.2
DensityOptions.hpp
1 // -------------------------------------------------
2 // Density Package specific tool options
3 // -------------------------------------------------
4 
5 /*
6  This file is part of LOOS.
7 
8  LOOS (Lightweight Object-Oriented Structure library)
9  Copyright (c) 2011, Tod D. Romo, Alan Grossfield
10  Department of Biochemistry and Biophysics
11  School of Medicine & Dentistry, University of Rochester
12 
13  This package (LOOS) is free software: you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation under version 3 of the License.
16 
17  This package is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 
27 
28 #if !defined(LOOS_DENSITY_OPTIONS_HPP)
29 #define LOOS_DENSITY_OPTIONS_HPP
30 
31 #include <boost/format.hpp>
32 
33 
34 #include <loos.hpp>
35 #include <DensityGrid.hpp>
36 #include <internal-water-filter.hpp>
37 
38 namespace loos {
39 
40  namespace OptionsFramework {
41 
43 
55  class BasicWater : public OptionsPackage {
56  /*
57  Grids used as masks are integer grids. They should only contain values from
58  [0,max_grid_mask_value].
59  */
60  static const int max_grid_mask_value = 0xff;
61  public:
62  BasicWater() :
63  pad(1.0),
64  radius(10.0),
65  water_string("name == 'OH2'"),
66  prot_string("name == 'CA'"),
67  grid_name(""),
68  filter_mode("axis"),
69  bulked_spec(""),
70  zrange_spec(""),
71  filter_func(0)
72  { }
73 
74  void addGeneric(po::options_description& opts) {
75  opts.add_options()
76  ("water,W", po::value<std::string>(&water_string)->default_value(water_string), "Water selection")
77  ("prot,P", po::value<std::string>(&prot_string)->default_value(prot_string), "Protein selection")
78  ("pad", po::value<double>(&pad)->default_value(pad), "Pad (for bounding box)")
79  ("bulked", po::value<std::string>(&bulked_spec)->default_value(bulked_spec), "Add bulk water (z-slices between cutoff and bounding box) [pad,zmin:zmax]")
80  ("radius,R", po::value<double>(&radius)->default_value(radius), "Radius (for principal axis filter and radius filter)")
81  ("zrange", po::value<std::string>(&zrange_spec)->default_value(zrange_spec), "Clamp the volume to integrate over in Z (min:max)")
82  ("grid,G", po::value<std::string>(&grid_name)->default_value(grid_name), "Name of grid to use in grid-mode (for internal waters)")
83  ("mode,M", po::value<std::string>(&filter_mode)->default_value(filter_mode), "Mode (axis|box|radius|core|grid)");
84  }
85 
86  bool postConditions(po::variables_map& map) {
87  if (filter_mode == "axis") {
89  } else if (filter_mode == "box") {
91  } else if (filter_mode == "radius") {
93  } else if (filter_mode == "core") {
95  } else if (filter_mode == "grid") {
96  if (grid_name.empty()) {
97  std::cerr << "ERROR - you must specify a grid to use when using grid-mode\n";
98  return(false);
99  }
100 
101  std::ifstream ifs(grid_name.c_str());
102  if (!ifs) {
103  std::cerr << "Error- cannot open grid file '" << grid_name << "' for reading." << std::endl;
104  return(false);
105  }
106 
107  ifs >> the_grid;
108  std::cerr << "Read in grid with size " << the_grid.gridDims() << std::endl;
109  if (!validateGridMask(the_grid)) {
110  std::cerr << "\n***WARNING***WARNING***WARNING***\n\n"
111  << "The grid '" << grid_name
112  << "' does not appear to be a grid mask. Your output will be suspect!\n"
113  << "Make sure the grid is an integer grid (e.g. from blobid or pick_block).\n"
114  << "If there are many unique blobs in the grid, then you may see this warning\n"
115  << "in which case you should reconsider how you ran blobid.\n"
116  << "Use --fullhelp for more information.\n"
117  << "\n***WARNING***WARNING***WARNING***\n\n";
118  }
119 
120 
121 
123 
124  } else {
125  std::cerr << "ERROR - unknown mode " << filter_mode << std::endl;
126  return(false);
127  }
128 
129  // Handle "decoration"
130  if (!zrange_spec.empty()) {
131  double zmin, zmax;
132  int i = sscanf(zrange_spec.c_str(), "%lf:%lf", &zmin, &zmax);
133  if (i != 2) {
134  std::cerr << boost::format("ERROR - unable to parse range '%s'\n") % zrange_spec;
135  return(false);
136  }
137 
139  }
140 
141  if (!bulked_spec.empty()) {
142  double zmin, zmax, pad;
143  int i = sscanf(bulked_spec.c_str(), "%lf,%lf:%lf", &pad, &zmin, &zmax);
144  if (i != 3) {
145  std::cerr << boost::format("ERROR - unable to parse bulk range '%s'\n") % bulked_spec;
146  return(false);
147  }
148 
150  }
151 
152 
153  return(true);
154  }
155 
156  std::string print() const {
157  std::ostringstream oss;
158 
159  oss << boost::format("water='%s', prot='%s', pad=%f, bulked='%s', radius=%f, zrange='%s', grid='%s', mode='%s'")
160  % water_string
161  % prot_string
162  % pad
163  % (bulked_spec.empty() ? "undef" : bulked_spec)
164  % radius
165  % (zrange_spec.empty() ? "undef" : zrange_spec)
166  % (grid_name.empty() ? "undef" : grid_name)
167  % filter_mode;
168 
169  return(oss.str());
170  }
171 
172 
173  ~BasicWater() {
174  if (filter_func)
175  delete filter_func;
176  filter_func = 0;
177  }
178 
180  double zmin, zmax;
182  double pad;
184  double radius;
186  std::string water_string, prot_string, grid_name, filter_mode;
188  std::string bulked_spec, zrange_spec;
193 
194  private:
195 
196  bool validateGridMask(const DensityTools::DensityGrid<int>& grid) {
197  for (long i=0; i<grid.size(); ++i)
198  if (grid(i) < 0 || grid(i) > max_grid_mask_value)
199  return(false);
200 
201  return(true);
202  }
203 
204  };
205 
206 
207  };
208 
209 };
210 
211 
212 #endif
Options specific to tools that work with water/internal-water.
Pick waters inside a bounding box.
Namespace for encapsulating options processing.
double zmin
Parameters sent to various decorators.
std::string print() const
Returns a string listing the encapsulated options, suitable for logging.
std::string bulked_spec
User-specified strings (used internally by the WaterFilter decorators)
Restrict waters to be within a given z-range.
std::string water_string
User-specified strings.
double pad
Extra padding for water.
Base interface for water filter/picker.
DensityTools::DensityGrid< int > the_grid
Grid mask for internal waters.
DensityTools::WaterFilterBase * filter_func
Filter for determining internal waters.
double radius
Optional parameter used in by the WaterFilter.
Add bulk water back into the mask/map.
Pick waters within a given radius of a group of atoms.
Namespace for most things not already encapsulated within a class.
Pick waters that are within a radius of the principal axis for a molecule.
Pick waters that are within a radius of the core axis for a molecule.
void addGeneric(po::options_description &opts)
Appends generic options (those that the user can see)
bool postConditions(po::variables_map &map)
Post-processing of options returning true if there were no problems, otherwise false.
Pick waters based on a grid-mask.