LOOS  v2.3.2
utils_structural.cpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 #include <iomanip>
26 #include <vector>
27 
28 
29 #include <utils_structural.hpp>
30 #include <Coord.hpp>
31 #include <pdb.hpp>
32 #include <dcd.hpp>
33 #include <pdb_remarks.hpp>
34 #include <sfactories.hpp>
35 
36 namespace loos {
37 
38  // Note: This *should* not throw a range_error, although in principal,
39  // the Remarks::operator[] does a range check and could...
40 
42  int n = r.size();
43  int i;
44 
45  GCoord c(99999.99, 99999.99, 99999.99);
46 
47  for (i=0; i<n; i++) {
48  std::string s = r[i];
49  if (s.substr(0, 6) == " XTAL ") {
50  std::stringstream is(s.substr(5));
51  if (!(is >> c.x()))
52  throw(ParseError("Unable to parse " + s));
53  if (!(is >> c.y()))
54  throw(ParseError("Unable to parse " + s));
55  if (!(is >> c.z()))
56  throw(ParseError("Unable to parse " + s));
57 
58  break;
59  }
60  }
61 
62  return(c);
63  }
64 
65 
66 
67  // Note: This *should* not throw, although in principal,
68  // the Remarks::operator[] does a range check and could...
69 
70  bool remarksHasBox(const Remarks& r) {
71  int n = r.size();
72  for (int i = 0; i<n; i++) {
73  std::string s = r[i];
74  if (s.size() < 6)
75  continue;
76  if (s.substr(0, 6) == " XTAL ")
77  return(true);
78  }
79  return(false);
80  }
81 
82 
83 
84  AtomicGroup loadStructureWithCoords(const std::string& model_name, const std::string& coord_name) {
85  AtomicGroup model = createSystem(model_name);
86  if (!coord_name.empty()) {
87  AtomicGroup coords = createSystem(coord_name);
88  model.copyCoordinatesFrom(coords);
89  }
90 
91  if (! model.hasCoords())
92  throw(LOOSError("Error- no coordinates found in specified model(s)"));
93 
94  return(model);
95  }
96 
97  AtomicGroup loadStructureWithCoords(const std::string& model_name, const std::string& type, const std::string& coord_name) {
98  AtomicGroup model = createSystem(model_name, type);
99  if (!coord_name.empty()) {
100  AtomicGroup coords = createSystem(coord_name);
101  model.copyCoordinatesFrom(coords);
102  }
103 
104  if (! model.hasCoords())
105  throw(LOOSError("Error- no coordinates found in specified model(s)"));
106 
107  return(model);
108  }
109 
110 
111 
112  std::vector<uint> assignTrajectoryFrames(const pTraj& traj, const std::string& frame_index_spec, uint skip, uint stride) {
113  std::vector<uint> frames;
114 
115  if (frame_index_spec.empty())
116  for (uint i=skip; i<traj->nframes(); i += stride)
117  frames.push_back(i);
118  else
119  frames = parseRangeList<uint>(frame_index_spec);
120 
121  return(frames);
122  }
123 
124 
125 
126 };
Basic 3-D coordinates class.
Definition: Coord.hpp:36
AtomicGroup loadStructureWithCoords(const std::string &model_name, const std::string &coord_name)
Loads a structure and optional coordinates.
void copyCoordinatesFrom(const AtomicGroup &g, const uint offset=0, const uint length=0)
Copy coordinates from g into current group.
AtomicGroup createSystem(const std::string &filename)
Factory function for reading in structure files.
Definition: sfactories.cpp:115
GCoord boxFromRemarks(const Remarks &r)
Extract the Alan-style box-size from a PDB Remarks block.
Generic LOOS exception.
Definition: exceptions.hpp:40
Exception when parsing input data.
Definition: exceptions.hpp:64
Class for handling groups of Atoms (pAtoms, actually)
Definition: AtomicGroup.hpp:87
Class for handling PDB Remarks.
Definition: pdb_remarks.hpp:41
Namespace for most things not already encapsulated within a class.
bool remarksHasBox(const Remarks &r)
Checks to see if a Remarks block has an Alan-style box size in it.
bool hasCoords(void) const
Do all the atoms in the group have coordinates?
std::vector< uint > assignTrajectoryFrames(const pTraj &traj, const std::string &frame_index_spec, uint skip, uint stride)
Builds a list of trajectory indices (frame_index_spec supercedes skip)