Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vall_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/fragment/picking_old/vall/vall_io.hh
11 /// @brief reading/writing of Vall libraries
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 // AUTO-REMOVED #include <time.h>
15 // unit headers
17 
18 // type headers
19 #include <core/types.hh>
20 
21 // package headers
23 
24 // project headers
25 #include <basic/Tracer.hh>
26 
27 // utility headers
28 #include <utility/exit.hh>
29 #include <utility/io/izstream.hh>
30 
31 // C++ headers
32 #include <sstream>
33 #include <string>
34 
35 #include <utility/vector1.hh>
36 
37 
38 #ifdef WIN32
39  #include <ctime>
40 #endif
41 
42 namespace core {
43 namespace fragment {
44 namespace picking_old {
45 namespace vall {
46 
47 
48 // Tracer instance for this file
49 // Named after the original location of this code
50 static basic::Tracer TR( "core.fragment.picking_old.vall.vall_io" );
51 
52 
53 /// @brief load standard Vall library from file
54 /// @param[in] filename
55 /// @param[out] vall
56 /// @remarks Currently a difference in id (pdb name) or resi (residue sequence id)
57 /// will start a new stretch of lines defining a VallSection
58 void vall_library_from_file( std::string const & filename, VallLibrary & library, core::Size const preallocate ) {
59  using core::Size;
60 
61  utility::io::izstream stream( filename );
62  if ( !stream ) {
63  utility_exit_with_message( "can't open file: " + filename );
64  }
65 
66  // statistics
67  Size n_lines = 0;
68  Size prior_library_size = library.size();
69  Size prior_n_residues = library.n_residues();
70 
71  TR << "Reading Vall library from " << filename << " ... " << std::endl;
72 
73  time_t time_start = time( NULL );
74 
75  std::string prior_id;
76  Size prior_resi;
77  VallResidue current_residue;
79 
80  // try to reduce number of allocation events if requested
81  if ( preallocate > 0 ) {
82  library.reserve( preallocate );
83  }
84 
85  // parse Vall from file
86  std::string line;
87  while ( getline( stream, line ) ) {
88  ++n_lines;
89  prior_id = current_residue.id();
90  prior_resi = current_residue.resi();
91 
92  current_residue.fill_from_string( line );
93 
94  // check for start of new continuous stretch
95  if ( ( current_residue.resi() != prior_resi + 1 ) || ( current_residue.id() != prior_id ) ) {
96  if ( section.size() > 0 ) {
97  library.add_section( section );
98  }
99  section.clear(); // new section
100  }
101 
102  section.append_residue( current_residue );
103 
104  if ( n_lines % 100000 == 0 ) {
105  TR << " " << n_lines << std::endl;
106  }
107  }
108 
109  if ( section.size() > 0 ) { // handle final set of entries
110  library.add_section( section );
111  }
112 
113  // free unused allocated memory
114  if ( library.size() <= ( preallocate / 2 ) ) { // heuristic
115  library.tighten_memory( false ); // entire library
116  } else {
117  library.tighten_memory(); // books only
118  }
119 
120  time_t time_end = time( NULL );
121 
122  TR << "... done. Read " << n_lines << " lines. Time elapsed: " << ( time_end - time_start ) << " seconds." << std::endl;
123  TR << "Prior library contained " << prior_library_size << " sections totaling " << prior_n_residues << " residues." << std::endl;
124  TR << "Added " << library.size() << " sections to library totaling " << library.n_residues() << " residues." << std::endl;
125 }
126 
127 
128 } // vall
129 } // picking_old
130 } // fragment
131 } // core
132