LOOS  v2.3.2
peakify.cpp
1 /*
2  Peakify.cpp
3 
4  Creates a PDB representing peaks in the grid...
5 
6  Usage: peakify threshold <input.grid >output.pdb
7 */
8 
9 
10 /*
11  This file is part of LOOS.
12 
13  LOOS (Lightweight Object-Oriented Structure library)
14  Copyright (c) 2009, 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 <DensityGrid.hpp>
34 #include <GridUtils.hpp>
35 
36 using namespace std;
37 using namespace loos;
38 using namespace loos::DensityTools;
39 
40 
41 int main(int argc, char *argv[]) {
42  if (argc != 2) {
43  cerr <<
44  "Usage- peakify threshold <foo.grid >peaks.pdb\n"
45  "\n"
46  "Given a double-precision floating point grid of density values\n"
47  "and a threshold, this tool writes out a PDB representing the density\n"
48  "peaks. The algorithm for finding the peaks uses a flood-fill to find\n"
49  "unique blobs of density. For each blob, the center of mass becomes a\n"
50  "pseudo-atom in the output PDB (with atom name \"UNK\" and residue name \"GRD\").\n"
51  "Note that these are really blob centers, as opposed to the point of maximum\n"
52  "density within a blob.\n";
53  exit(-1);
54  }
55 
56  double thresh = strtod(argv[1], 0);
57 
58  string hdr = invocationHeader(argc, argv);
60  cin >> grid;
61 
62  cerr << "Read in grid " << grid.gridDims() << "\n";
63 
64  DensityGrid<int> blobs(grid.minCoord(), grid.maxCoord(), grid.gridDims());
65 
66  PDB pdb;
67  vector<GCoord> peaks = findPeaks(grid, Threshold<double>(thresh));
68  for (uint i = 0; i < peaks.size(); ++i) {
69  pAtom atom(new Atom(i+1, "UNK", peaks[i]));
70  atom->resid(i+1);
71  atom->resname("UNK");
72  atom->segid("BLOB");
73 
74  pdb.append(atom);
75  }
76 
77  pdb.remarks().add(hdr);
78  cout << pdb;
79 }
STL namespace.
Basic Atom class for handling atom properties.
Definition: Atom.hpp:50
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
Functor that is true if value is greater than or equal to threshold.
Definition: GridUtils.hpp:44
Namespace for Density package.
Definition: DensityGrid.hpp:48
PDB reading/writing class.
Definition: pdb.hpp:69
std::vector< loos::GCoord > findPeaks(const DensityGrid< T > &grid, DensityGrid< int > &blobs, const Functor &op)
Find peaks in a grid given the criteria defined by the passed functor.
Definition: GridUtils.hpp:136
Namespace for most things not already encapsulated within a class.