LOOS  v2.3.2
heavy-ca.cpp
1 /*
2  heavy-ca
3 
4  Given a PDB where masses are stored in the occupancy field, reduce
5  the structure to CA's only where the mass of the CA is the sum of
6  the mass of all atoms in the corresponding residue...
7 
8  Usage- heavy-ca selection model >output
9 
10 */
11 
12 
13 /*
14  This file is part of LOOS.
15 
16  LOOS (Lightweight Object-Oriented Structure library)
17  Copyright (c) 2009 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 loos;
40 using namespace std;
41 
42 
43 
44 string fullHelpMessage(void) {
45  string msg =
46  "\n"
47  "SYNOPSIS\n"
48  "\n"
49  "Store whole residue mass in CA occupancy field\n"
50  "\n"
51  "DESCRIPTION\n"
52  "\n"
53  "Given a PDB where masses are stored in the occupancy field, reduce\n"
54  "the structure to CA's only where the mass of the CA is the sum of\n"
55  "the mass of all atoms in the corresponding residue.\n"
56  "\n"
57  "Note: The selection string in this tool is used to decide which\n"
58  " residues to sum the mass of. So 'name==\"CA\"' will return\n"
59  " a mass of 12 in the occupancy field. \n"
60  "\n"
61  //
62  "EXAMPLES\n"
63  "\n"
64  "heavy-ca 'segid==\"PROT\"' model.pdb > newmodel.pdb'\n"
65  "\tMasses in the occupancy field of model.pdb are \n"
66  "\tsummed over each residue in segid PROT and placed\n"
67  "\ton the CA in newmodel.pdb.\n"
68  "\n"
69  "heavy-ca 'segid==\"PROT\" && !(hydrogen)' model.pdb > newmodel.pdb'\n"
70  "\tSame as above, but hydrogen atoms are excluded \n"
71  "\tfrom the summation.\n"
72  "\n"
73  "SEE ALSO\n"
74  "\n"
75  "Packages/ElasticNetworks/psf-masses - \n"
76  "\tThis tool will take the masses from a PSF file\n"
77  "\tand place them in the occupancy field of a PDB\n"
78  "\n"
79  "\n";
80 
81  return(msg);
82 }
83 
84 
85 
86 int main(int argc, char *argv[]) {
87  if (argc != 3) {
88  cerr << "Usage- heavy-ca selection pdb >output\n";
89  cerr << fullHelpMessage();
90  exit(0);
91  }
92 
93 
94  string hdr = invocationHeader(argc, argv);
95 
96  string selection(argv[1]);
97  AtomicGroup structure = createSystem(argv[2]);
98 
99  AtomicGroup model = selectAtoms(structure, selection);
100 
101  vector<AtomicGroup> residues = model.splitByResidue();
102  AtomicGroup heavy;
103 
104  for (vector<AtomicGroup>::iterator j = residues.begin(); j != residues.end(); ++j) {
105  AtomicGroup grp = (*j).select(AtomNameSelector("CA"));
106  if (grp.empty()) {
107  cerr << "ERROR- could not find a CA in the following residue:\n";
108  cerr << *j;
109  exit(-1);
110  }
111 
112  pAtom ca = grp[0];
113  double mass = 0.0;
114  for (AtomicGroup::iterator i = (*j).begin(); i != (*j).end(); ++i)
115  mass += (*i)->occupancy();
116 
117  ca->occupancy(mass);
118  heavy.append(ca);
119  }
120 
121 
122  PDB outpdb = PDB::fromAtomicGroup(heavy);
123  outpdb.remarks().add(hdr);
124  cout << outpdb;
125 }
Remarks & remarks(void)
Accessor for the remarks object...
Definition: pdb.cpp:547
AtomicGroup select(const AtomSelector &sel) const
Return a group consisting of atoms for which sel predicate returns true...
void add(const std::string s)
Add a remark.
Definition: pdb_remarks.cpp:52
std::vector< AtomicGroup > splitByResidue(void) const
Returns a vector of AtomicGroups, each comprising a single residue.
AtomicGroup & append(pAtom pa)
Append the atom onto the group.
STL namespace.
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
std::string invocationHeader(int argc, char *argv[])
Create an invocation header.
Definition: utils.cpp:124
PDB reading/writing class.
Definition: pdb.hpp:69
AtomicGroup selectAtoms(const AtomicGroup &source, const std::string selection)
Applies a string-based selection to an atomic group...
Definition: utils.cpp:195
static PDB fromAtomicGroup(const AtomicGroup &)
Class method for creating a PDB from an AtomicGroup.
Definition: pdb.cpp:528
Predicate for selecting atoms based on explicit name matching.
Definition: Selectors.hpp:75
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Namespace for most things not already encapsulated within a class.