LOOS  v2.3.2
side-nodes.cpp
1 /*
2  side-nodes
3 
4  (c) 2010 Tod D. Romo, Grossfield Lab
5  Department of Biochemistry
6  University of Rochster School of Medicine and Dentistry
7 
8 
9  Usage:
10  side-nodes selection model >output.pdb
11 
12 */
13 
14 
15 /*
16  This file is part of LOOS.
17 
18  LOOS (Lightweight Object-Oriented Structure library)
19  Copyright (c) 2010 Tod D. Romo
20  Department of Biochemistry and Biophysics
21  School of Medicine & Dentistry, University of Rochester
22 
23  This package (LOOS) is free software: you can redistribute it and/or modify
24  it under the terms of the GNU General Public License as published by
25  the Free Software Foundation under version 3 of the License.
26 
27  This package is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  GNU General Public License for more details.
31 
32  You should have received a copy of the GNU General Public License
33  along with this program. If not, see <http://www.gnu.org/licenses/>.
34 
35 */
36 
37 
38 #include <loos.hpp>
39 
40 
41 using namespace std;
42 using namespace loos;
43 
44 
45 pAtom findMatch(const pAtom& probe, const AtomicGroup& grp) {
46  for (AtomicGroup::const_iterator i = grp.begin(); i != grp.end(); ++i)
47  if ((*i)->name() == probe->name() && (*i)->id() == probe->id()
48  && (*i)->resname() == probe->resname() && (*i)->resid() == probe->resid()
49  && (*i)->segid() == probe->segid())
50  return(*i);
51 
52  pAtom null;
53  return(null);
54 }
55 
56 
57 
58 int main(int argc, char *argv[]) {
59 
60  if (argc == 1) {
61  cout << "Usage- side-nodes selection model [psf] >output.pdb\n";
62  exit(0);
63  }
64 
65  string hdr = invocationHeader(argc, argv);
66  int k = 1;
67  string selection(argv[k++]);
68  AtomicGroup model = createSystem(argv[k++]);
69  AtomicGroup subset = selectAtoms(model, selection);
70  if (argc > k) {
71  AtomicGroup structure = createSystem(argv[k++]);
72  for (AtomicGroup::iterator i = subset.begin(); i != subset.end(); ++i) {
73  pAtom match = findMatch(*i, structure);
74  if (!match) {
75  cerr << "ERROR- no match found for atom " << **i << endl;
76  exit(-1);
77  }
78 
79  if (!match->checkProperty(Atom::massbit)) {
80  cerr << "ERROR- Atom has no mass: " << *match << endl;
81  exit(-1);
82  }
83 
84  (*i)->mass(match->mass());
85  }
86  }
87 
88  vector<AtomicGroup> residues = subset.splitByResidue();
89  AtomicGroup cg_sites;
90  int currid = model.maxId();
91 
92  for (vector<AtomicGroup>::iterator vi = residues.begin(); vi != residues.end(); ++vi) {
93  // First, pick off the CA
94  AtomicGroup CA = vi->select(AtomNameSelector("CA"));
95  if (CA.empty()) {
96  cerr << "Error- cannot find CA.\n" << *vi;
97  exit(-10);
98  }
99  CA[0]->occupancy(CA[0]->mass());
100  cg_sites += CA[0];
101 
102  AtomicGroup sidechain = vi->select(NotSelector(BackboneSelector()));
103  if (sidechain.empty()) {
104  cerr << "Warning- No sidechain atoms for:\n" << *vi;
105  continue;
106  }
107 
108  GCoord c = sidechain.centerOfMass();
109  pAtom pa(new Atom(++currid, "CGS", c));
110  pa->resid(CA[0]->resid());
111  pa->resname(CA[0]->resname());
112  pa->segid(CA[0]->segid());
113  double m = sidechain.totalMass();
114  pa->occupancy(m);
115 
116  cg_sites += pa;
117  }
118 
119  PDB pdb = PDB::fromAtomicGroup(cg_sites);
120  pdb.remarks().add(hdr);
121  cout << pdb;
122 }
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.
STL namespace.
Predicate for selecting backbone.
Definition: Selectors.hpp:53
Basic Atom class for handling atom properties.
Definition: Atom.hpp:50
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
GCoord centerOfMass(void) const
Center of mass of the group (in group coordinates)
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
Negates a selection predicate.
Definition: Selectors.hpp:112
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.