Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SilentStructFactory.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/io/silent/SilentStructFactory.cc
11 /// @brief Factory for creating various types of silent.
12 /// @author Greg Taylor <gktaylor@u.washington.edu>
13 
14 // Unit headers
17 
18 #include <basic/options/option.hh>
19 #include <basic/options/keys/out.OptionKeys.gen.hh>
20 #include <basic/options/keys/in.OptionKeys.gen.hh>
21 
22 // AUTO-REMOVED #include <core/pose/Pose.hh>
23 #include <core/pose/util.hh>
24 
25 // Package headers
28 
29 #include <basic/Tracer.hh>
30 
31 #include <utility/vector1.hh>
32 
33 
34 namespace core {
35 namespace io {
36 namespace silent {
37 
38 static basic::Tracer tr("core.io.silent");
39 
40 SilentStructFactory * SilentStructFactory::instance_( 0 );
41 
42 /// @details Private constructor insures correctness of singleton.
44 
47 {
48  if ( instance_ == 0 ) {
50  }
51  return instance_;
52 }
53 
54 void
56 {
57  ss_types_[ creator->keyname() ] = creator;
58 }
59 
60 void
62  std::ostream & out
63 ) {
64  out << "Available silent struct types:" << std::endl;
65  for(
66  std::map< std::string, io::silent::SilentStructCreatorCOP >::const_iterator
67  it = ss_types_.begin(), ite = ss_types_.end(); it != ite; ++it
68  ) {
69  out << "\t" << it->first << std::endl;
70  }
71 }
72 
73 
74 bool
76  std::string const & type_name
77 ) {
78  return ss_types_.find(type_name) != ss_types_.end();
79 }
80 
83 {
84  tr.Trace << "generate silent struct of type " << type_name << std::endl;
85  SilentStructCreatorMap::const_iterator iter = ss_types_.find( type_name );
86  if ( iter != ss_types_.end() ) {
87  return iter->second->create_silent_struct();
88  } else {
89 
90  using std::string;
91  using utility::vector1;
92  string msg("SilentStructFactory::get_instance()->get_silent_struct: ");
93  msg += type_name + " does not name a known SilentStructType --> " +
94  "check spelling or register new SilentStruct type in SilentStructFactory!";
95 
96  msg += "known types are:\n";
98  for ( vector1< string >::const_iterator it = types.begin(), end = types.end(); it != end; ++it ) {
99  msg += *it + "\n";
100  }
101 
102  utility_exit_with_message( msg );
103  }
104  return 0;
105 }
106 
109  using std::string;
110  using utility::vector1;
111 
112  vector1< string > ss_names;
113  for ( SilentStructCreatorMap::const_iterator
114  it = ss_types_.begin(), end = ss_types_.end(); it != end; ++it ) {
115  ss_names.push_back( it->first );
116  }
117 
118  return ss_names;
119 }
120 
122 {
123  ss_types_[ creator->keyname() ] = creator;
124 }
125 
128 {
129  SilentStructCreatorMap::const_iterator iter = ss_types_.find( type_name );
130  if ( iter != ss_types_.end() ) {
131  return iter->second;
132  } else {
133 
134  using std::string;
135  using utility::vector1;
136  string msg("SilentStructFactory::get_creator: ");
137  msg += type_name + " does not name a known SilentStructType --> " +
138  "check spelling or register new SilentStruct type in SilentStructFactory!";
139 
140  msg += "known types are:\n";
142  for ( vector1< string >::const_iterator it = types.begin(), end = types.end(); it != end; ++it ) {
143  msg += *it + "\n";
144  }
145 
146  utility_exit_with_message( msg );
147  }
148  return 0;
149 }
150 
152  using namespace basic::options;
153  using namespace basic::options::OptionKeys;
154 
155  return get_silent_struct( option[ in::file::silent_struct_type ]() );
156 }
157 
159  using namespace basic::options;
160  using namespace basic::options::OptionKeys;
161  return get_silent_struct( option[ out::file::silent_struct_type ]() );
162 }
164  using namespace basic::options;
165  using namespace basic::options::OptionKeys;
166 
167  bool already_binary( option[ out::file::silent_struct_type ]().find( "binary" ) != std::string::npos );
168  bool const score_only( option[ out::file::silent_struct_type ]() == "score" );
169 
170  // if the user has explicitly set the output type, honor the request
171  if ( option[ out::file::silent_struct_type ].user() ){
172  return get_silent_struct( option[ out::file::silent_struct_type ]() ) ;
173  }
174 
175  // if not, decide for the user or use the default
176  if ( !score_only && !already_binary && !core::pose::is_ideal_pose(pose) ) {
177  std::string binary_string( "binary" );
178  if ( option[ out::file::silent_struct_type ]() == "rna" ) {
179  binary_string = "binary_rna";
180  };
181  tr.Info << "detected attempt to write non-ideal pose to silent-file..."
182  << "Automatically switching to " << binary_string << " silent-struct type" << std::endl;
183  return get_silent_struct( binary_string );
184  }
185 
186  // use default
187  return get_silent_struct( option[ out::file::silent_struct_type ]() ) ;
188 }
189 
190 
191 
192 } // silent
193 } // io
194 } // core