Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SilentFileLoader.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 
11 /// @file core/io/silent/SilentFileLoader.hh
12 /// @brief Load a silent file from an input stream and a SilentFileOptions object
13 /// @author Matthew O'Meara (mattjomeara@gmail.com)
14 
15 // Unit Headers
18 #include <basic/resource_manager/ResourceOptions.hh>
19 
20 // Project Headers
24 #include <core/pose/Pose.hh>
25 
26 // Platform Headers
27 #include <core/types.hh>
28 #include <utility/excn/Exceptions.hh>
29 #include <basic/Tracer.hh>
30 
31 // C++ Headers
32 #include <string>
33 
34 static basic::Tracer TR("core.io.silent.SilentFileLoader");
35 
36 namespace core {
37 namespace io {
38 namespace silent {
39 
40 using pose::Pose;
41 using pose::PoseOP;
42 using basic::resource_manager::ResourceOP;
43 using basic::resource_manager::ResourceLoaderOP;
44 using basic::resource_manager::ResourceOptions;
45 using basic::resource_manager::ResourceOptionsOP;
46 using basic::resource_manager::LocatorID;
47 using std::istream;
48 using std::string;
49 
50 ///// SilentFileLoaderCreator /////
52 
54 
55 ResourceLoaderOP
57  return new SilentFileLoader;
58 }
59 
60 string
62  return "SilentFile";
63 }
64 
65 //// SilentFileLoader /////
67 
69 
71  SilentFileLoader const &) {}
72 
73 ResourceOP
75  ResourceOptions const & options,
76  LocatorID const & locator_id,
77  istream & istream
78 ) const {
79 
80  if ( ! dynamic_cast< SilentFileOptions const * >( &options ) ) {
81  throw utility::excn::EXCN_Msg_Exception(
82  "SilentFileLoader expected to get a SilentFileOptions object, "
83  "but was given a ResourceOptions of type '" + options.type() + "', "
84  "which has the name '" + options.name() + "'." );
85  }
86  SilentFileOptions const & resource_options(
87  static_cast< SilentFileOptions const & >( options ));
88 
90  std::string line;
91  while(getline(istream, line)) {
92  lines.push_back(line);
93  }
94 
95  SilentStructOP ss(
96  SilentStructFactory::get_instance()->get_silent_struct(
97  resource_options.get_silent_struct_type()));
98 
99  SilentFileData container;
100 
101  if(!(ss->init_from_lines(lines, container))) {
102  throw utility::excn::EXCN_BadInput( "SilentFileLoader failed to load silent file with locator_id '" + locator_id + "'." );
103  }
104 
105  PoseOP pose( new Pose());
106  ss->fill_pose(*pose);
107 
108  if(pose->total_residue() == 0){
109  TR.Warning
110  << "Loading Pose with SilentFileLoader for the "
111  << "locator_id '" << locator_id << "', "
112  << "but the resulting pose does not have any residues." << std::endl;
113  TR.Warning
114  << "Also note that the input stream has '" << lines.size() << "'" << std::endl;
115  }
116 
117  return pose;
118 }
119 
120 ResourceOptionsOP
122 ) const {
123  return new SilentFileOptions();
124 }
125 
126 } // namespace
127 } // namespace
128 } // namespace
129