Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
io.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file core/scoring/packstat/io.cc
11 ///
12 /// @brief
13 /// @author will sheffler
14 
16 
19 
20 // AUTO-REMOVED #include "numeric/io.hh"
21 
22 #include <cstring>
23 #include <iostream>
24 #include <sstream>
25 
26 #include <numeric/xyzVector.io.hh>
27 
28 
29 namespace core {
30 namespace scoring {
31 namespace packstat {
32 
33 
34 std::istream &
36  std::istream & in,
37  SimplePDB & pdb
38 ) {
39  SimplePDB_Atom atom;
40  while( in >> atom ) {
41  // std::cerr << "reading line" << std::endl;
42  if( atom.num == -123456 ) {
43  // std::cerr << "/*TER or*/ ENDMDL" << std::endl;
44  break; // hit a /*TER or*/ ENDMDL, so stop
45  }
46  if( atom.num != -12345 ) {
47  pdb.atoms_.push_back(atom);
48  }
49  }
51  return in;
52 }
53 
54 std::ostream &
56  std::ostream & out,
57  SimplePDB const & pdb
58 ) {
59  out << "SimplePDB:" << std::endl;
60  for( SPAtomCIter i = pdb.atoms_.begin(); i != pdb.atoms_.end(); ++i ) {
61  out << " " << *i << std::endl;
62  }
63  return out;
64 }
65 
66 template<class T>
67 void read_stoopid(char * buf, size_t start, size_t end, T & field ) {
68  if( start == end ) {
69  field = buf[start];
70  return;
71  }
72  char smbuf[99];
73  for( int i = 0; i < 99; ++i ) smbuf[i] = 0;
74  strncpy(smbuf,buf+start,end-start+1);
75  std::istringstream iss(smbuf);
76  iss >> field;
77 }
78 
79 /*
80 reads an atom record like this, assuming chain is col 21 and all others present
81  11 13
82 ATOM 12 N GLU A 2 -13.565 31.875 -5.182 1.00 51.33 N
83 ATOM 391 CG1AILE A 63 0.107 41.079 16.997 0.50 20.29 C
84 
85 */
86 std::istream &
88  std::istream & in_raw,
89  SimplePDB_Atom & atom
90 ) {
91  using namespace std;
92  char buf[999];
93  in_raw.getline(buf,999);
94  atom.whole_line = buf;
95  // std::cerr << "read line: " << buf << std::endl;
96 // istringstream in(buf);
97 // in >> atom.ATOM;
98  atom.ATOM = atom.whole_line.substr( 0, 6 );
99  if( atom.ATOM != "ATOM " && atom.ATOM != "HETATM" ) { // not an atom
100  // std::cerr << "failed to read ATOM or HETATM! atom.ATOM is '" << atom.ATOM << "'" << std::endl;
101  atom.num = -12345;
102  if( /*atom.ATOM == "TER" ||*/ atom.ATOM == "ENDMDL" ) {
103  atom.num = -123456;
104  }
105  return in_raw;
106  }
107  read_stoopid<int >(buf, 6,10,atom.num );
108  read_stoopid<string>(buf,11,16,atom.type);
109  read_stoopid<string>(buf,17,20,atom.res );
110  read_stoopid<char >(buf,21,21,atom.chain );
111  read_stoopid<int >(buf,22,26,atom.resnum );
112  read_stoopid<PackstatReal >(buf,29,37,atom.x );
113  read_stoopid<PackstatReal >(buf,38,45,atom.y );
114  read_stoopid<PackstatReal >(buf,46,54,atom.z );
115  read_stoopid<PackstatReal >(buf,55,59,atom.occ );
116  read_stoopid<PackstatReal >(buf,60,65,atom.bfac );
117  read_stoopid<string>(buf,66,99,atom.lastcol );
118  return in_raw;
119 }
120 
121 
122 std::ostream &
124  std::ostream & out,
125  SimplePDB_Atom const & atom
126 ) {
127  out << atom.ATOM << " "
128  << atom.num << " "
129  << atom.type << " "
130  << atom.res << " "
131  << atom.resnum << " "
132  << atom.chain << " "
133  << atom.num << " "
134  << atom.x << " "
135  << atom.y << " "
136  << atom.z << " "
137  << atom.occ << " "
138  << atom.bfac << " "
139  << atom.lastcol;
140  return out;
141 }
142 
143 std::ostream &
145  std::ostream & out,
146  Sphere const & sphere
147 ) {
148  out << "Sphere( " << sphere.xyz << ", " << sphere.radius << " )";
149  return out;
150 }
151 
152 
153 
154 } // namespace packstat
155 } // namespace scoring
156 } // namespace core