Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Field.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 // :noTabs=false:tabSize=4:indentSize=4:
4 //
5 // (c) Copyright Rosetta Commons Member Institutions.
6 // (c) This file is part of the Rosetta software suite and is made available under license.
7 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
8 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
9 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
10 
11 /// @file core/io/pdb/Field.cc
12 ///
13 /// @brief Each line of a PDB file is a Record which is divided into Fields
14 /// @author Matthew O'Meara (mattjomeara@gmail.com)
15 
16 #include <core/io/pdb/Field.hh>
17 
18 // Utitility headers
19 #include <utility/tools/make_map.hh>
20 
21 
22 namespace core {
23 namespace io {
24 namespace pdb {
25 
26 
27 using std::string;
28 using std::ostream;
29 
30 /// @brief various constructors - only for convenience.
32  type(""),
33  value(""),
34  start(0),
35  end(0)
36 {}
37 
39  type(""),
40  value(""),
41  start(s),
42  end(e)
43 {}
44 
45 Field::Field(string t, Size s, Size e) :
46  type(t),
47  value(""),
48  start(s),
49  end(e)
50 {}
51 
52 /// @brief read field value from given string.
53 void
54 Field::getValueFrom(string source) {
55  value = string(source.begin()+start-1, source.begin()+end);
56 }
57 
58 
59 /// @brief Debug output.
60 std::ostream&
62  std::ostream &os,
63  Field const & F
64 ) {
65  os << "[" << F.start << ", " << F.end << "]=" << F.value << "";
66  return os;
67 }
68 
69 /// @details static holder for collection of Fields.
71 
72 /// @details check if records table was init, init table otherwise
73 /// return reference to private static records collection
74 /// @remarks See http://www.wwpdb.org/docs.html#format for details.
76 {
77  if( PDB_Records_.size() == 0 ) {
78  PDB_Records_ = utility::tools::make_map<string, Record>(
79  // Title Section
80  "HEADER", utility::tools::make_map<string, Field>(
81  "type", Field( 1, 6),
82  "classification", Field(11, 50),
83  "depDate", Field(51, 59),
84  "idCode", Field(63, 66) ),
85 
86  "TITLE ", utility::tools::make_map<string, Field>(
87  "type", Field( 1, 6),
88  "continuation", Field( 9, 10),
89  "title", Field(11, 70) ),
90 
91  "COMPND", utility::tools::make_map<string, Field>(
92  "type", Field( 1, 6),
93  "continuation", Field( 9, 10),
94  "compound", Field(11, 70) ),
95 
96  "KEYWDS", utility::tools::make_map<string, Field>(
97  "type", Field( 1, 6),
98  "continuation", Field( 9, 10),
99  "keywords", Field(11, 70) ),
100 
101  "EXPDTA", utility::tools::make_map<string, Field>(
102  "type", Field( 1, 6),
103  "continuation", Field( 9, 10),
104  "technique", Field(11, 70) ),
105 
106  "REMARK", utility::tools::make_map<string, Field>(
107  "type", Field( 1, 6),
108  "remarkNum", Field( 8, 10),
109  "value", Field(12, 70) ), // non-standard name
110 
111  // Primary Structure Section
112 
113  // Heterogen Section
114  "HETNAM", utility::tools::make_map<string, Field>(
115  "type", Field( 1, 6),
116  "continuation", Field( 9, 10),
117  "hetID", Field(12, 14), // LString(3): HET identifier, right-justified
118  "text", Field(16, 70) // String: chemical name
119  ),
120 
121  // Secondary Structure Section
122 
123  // Connectivity Annotation Section
124  "SSBOND", utility::tools::make_map<string, Field>(
125  "type", Field( 1, 6),
126  "serNum", Field( 8, 10), // Integer
127  "CYS", Field(12, 14),
128  "chainID1", Field(16, 16), // Character
129  "seqNum1", Field(18, 21), // Integer
130  "icode1", Field(22, 22), // AChar
131  "CYS", Field(26, 28),
132  "chainID2", Field(30, 30), // Character
133  "seqNum2", Field(32, 35), // Integer
134  "icode2", Field(36, 36), // AChar
135  "sym1", Field(60, 65), // SymOP
136  "sym2", Field(67, 72) // SymOP
137  ),
138  "LINK ", utility::tools::make_map<string, Field>(
139  "type", Field( 1, 6),
140  "name1", Field(13, 16), // Atom
141  "altLoc1", Field(17, 17), // Character
142  "resName1", Field(18, 20), // Residue name
143  "chainID1", Field(22, 22), // Character
144  "resSeq1", Field(23, 26), // Integer
145  "iCode1", Field(27, 27), // AChar
146  "name2", Field(43, 46), // Atom
147  "altLoc2", Field(47, 47), // Character
148  "resName2", Field(48, 50), // Residue name
149  "chainID2", Field(52, 52), // Character
150  "resSeq2", Field(53, 56), // Integer
151  "iCode2", Field(57, 57), // AChar
152  "sym1", Field(60, 65), // SymOP
153  "sym2", Field(67, 72), // SymOP
154  "length", Field(74, 78) // Real(5.2)
155  ),
156 
157  // Miscellaneous Features Section
158 
159  // Crystallographic & Coordinate Transformation Section
160 
161  // Coordinate Section
162  "MODEL ", utility::tools::make_map<string, Field>(
163  "type", Field( 1, 6),
164  "serial", Field( 7, 80) ),
165 
166  "ATOM ", utility::tools::make_map<string, Field>(
167  "type", Field( 1, 6),
168  "serial", Field( 7, 11), // Integer
169  "name", Field(13, 16), // Atom
170  "altLoc", Field(17, 17), // Character
171  "resName", Field(18, 20), // Residue name
172  "chainID", Field(22, 22), // Character
173  "resSeq", Field(23, 26), // Integer
174  "iCode", Field(27, 27), // AChar
175  "x", Field(31, 38), // Real(8.3)
176  "y", Field(39, 46), // Real(8.3)
177  "z", Field(47, 54), // Real(8.3)
178  "occupancy", Field(55, 60), // Real(6.2)
179  "tempFactor", Field(61, 66), // Real(6.2)
180  //"segID", Field(73, 76),
181  "element", Field(77, 78), // LString(2)
182  "charge", Field(79, 80) // LString(2)
183  ),
184  "HETATM", utility::tools::make_map<string, Field>(
185  "type", Field( 1, 6),
186  "serial", Field( 7, 11), // Integer
187  "name", Field(13, 16), // Atom
188  "altLoc", Field(17, 17), // Character
189  "resName", Field(18, 20), // Residue name
190  "chainID", Field(22, 22), // Character
191  "resSeq", Field(23, 26), // Integer
192  "iCode", Field(27, 27), // AChar
193  "x", Field(31, 38), // Real(8.3)
194  "y", Field(39, 46), // Real(8.3)
195  "z", Field(47, 54), // Real(8.3)
196  "occupancy", Field(55, 60), // Real(6.2)
197  "tempFactor", Field(61, 66), // Real(6.2)
198  //"segID", Field(73, 76),
199  "element", Field(77, 78), // LString(2)
200  "charge", Field(79, 80) // LString(2)
201  ),
202  "TER ", utility::tools::make_map<string, Field>(
203  "type", Field( 1, 6),
204  "serial", Field( 7, 11),
205  "resName", Field(18, 20),
206  "chainID", Field(22, 22),
207  "resSeq", Field(23, 26),
208  "iCode", Field(27, 27) ),
209 
210  // Connectivity Section
211 
212  // Bookkeeping Section
213 
214  // Unknown Type
215  "UNKNOW", utility::tools::make_map<string, Field>(
216  "type", Field( 1, 6),
217  "info", Field( 7, 80) )
218  );
219  }
220  return PDB_Records_;
221 }
222 
223 
224 /// @details Debug printing, serializing to Tracer like object.
225 std::ostream&
226 operator <<(std::ostream &os,Record const & R) {
227  for(Record::const_iterator p=R.begin(); p!=R.end(); p++ ) {
228  os << "<Record>{" << p->first << ":" << p->second
229  << "}\n";
230  }
231 
232  return os;
233 }
234 
235 
236 } // namespace
237 } // namespace
238 } // namespace