14 #include <core/init/init.hh>
16 #include <core/pose/Pose.hh>
17 #include <core/pose/util.hh>
18 #include <core/pose/annotated_sequence.hh>
20 #include <core/scoring/ScoreFunctionFactory.hh>
21 #include <core/scoring/ScoreFunction.hh>
22 #include <core/scoring/ScoreType.hh>
24 #include <protocols/viewer/viewers.hh>
26 #include <protocols/moves/SimulatedTempering.hh>
27 #include <protocols/stepwise/modeler/rna/helix/RNA_HelixAssembler.hh>
28 #include <protocols/stepwise/sampler/rna/RNA_MC_Suite.hh>
29 #include <protocols/stepwise/sampler/rna/RNA_MC_MultiSuite.hh>
39 #include <basic/options/keys/out.OptionKeys.gen.hh>
40 #include <basic/options/keys/score.OptionKeys.gen.hh>
41 #include <basic/options/keys/in.OptionKeys.gen.hh>
48 using namespace protocols;
49 using namespace protocols::stepwise;
50 using namespace basic::options::OptionKeys;
58 OPT_KEY( RealVector, st_weights )
60 OPT_KEY( Boolean, save_score_terms )
62 OPT_KEY( Integer, n_intermediate_dump )
73 n_elem_ =
static_cast<Size>( ( max -
min ) / spacing ) + 1;
74 for (
Size i = 1; i <= n_elem_; ++i ) hist_.push_back( 0 );
79 if ( value <= min_ ) {
81 }
else if ( value >= max_ ) {
84 bin_index =
static_cast<Size>( ( value - min_ ) / spacing_ ) + 1;
86 hist_[bin_index] += n_items;
90 for (
Size i = 0; i <= n_elem_; ++i ) hist_[i] = 0;
95 for (
Size i = 1; i <= n_elem_; ++i ) {
96 scores.push_back( min_ + spacing_ * ( i - 0.5 ) );
111 using namespace scoring;
113 if ( !scoretypes.empty() )
return scoretypes;
116 scoretypes.push_back( fa_atr );
117 scoretypes.push_back( fa_rep );
118 scoretypes.push_back( fa_intra_rep );
119 scoretypes.push_back( fa_stack );
120 scoretypes.push_back( rna_torsion );
121 scoretypes.push_back( hbond_sc );
122 scoretypes.push_back( lk_nonpolar );
123 scoretypes.push_back( geom_sol_fast );
124 scoretypes.push_back( stack_elec );
125 scoretypes.push_back( fa_elec_rna_phos_phos );
132 scoring::ScoreFunctionOP
const scorefxn
134 using namespace scoring;
136 scores.push_back( ( *scorefxn )( pose ) );
138 for (
Size i = 1; i<= score_types.size(); ++i ) {
139 scores.push_back( scorefxn->score_by_scoretype(
140 pose, score_types[i],
false ) );
149 using namespace scoring;
150 data.push_back( count );
151 data.insert( data.end(), scores.begin(), scores.end() );
157 if ( temp < 0 )
return -1;
158 if ( is_bp )
return 5 * temp / n_rsd;
159 return 6 *
pow( temp / n_rsd, 0.75 );
164 std::string
const & out_filename,
168 out_filename.c_str(), std::ios::out | std::ios::binary );
169 out.
write( (
const char*) &out_vector[1],
sizeof(
T) * out_vector.size() );
175 std::string
const & out_filename,
181 out_filename.c_str(), std::ios::out | std::ios::binary );
183 out.write( (
const char*) &dim1,
sizeof(
Size) );
184 out.write( (
const char*) &dim2,
sizeof(
Size) );
185 out.write( (
const char*) &out_vector[1],
sizeof(
T) * out_vector.size() );
191 sampler::rna::RNA_MC_MultiSuite & sampler,
192 moves::SimulatedTempering
const & tempering,
196 Size const n_rsd( bp_rsd.size() + dangling_rsd.size() );
197 Real const temp( tempering.temperature() );
200 for (
Size i = 1; i <= bp_rsd.size(); ++ i ) {
201 sampler.set_gaussian_stdev( bp_stdev, bp_rsd[i] );
203 for (
Size i = 1; i <= dangling_rsd.size(); ++ i ) {
204 sampler.set_gaussian_stdev( dangling_stdev, dangling_rsd[i] );
209 std::string
const & seq1,
210 std::string
const & seq2,
213 protocols::stepwise::modeler::rna::helix::RNA_HelixAssembler assembler;
214 assembler.use_phenix_geo(
true );
215 PoseOP
pose( assembler.build_init_pose( seq1, seq2 ) );
216 add_variant_type_to_pose_residue( *
pose, chemical::VIRTUAL_PHOSPHATE, 1 );
217 if ( seq1 !=
"" && seq2 !=
"" ) {
218 add_variant_type_to_pose_residue(
219 *
pose, chemical::VIRTUAL_PHOSPHATE, len1 + 1 );
225 using namespace scoring;
227 return score_types.size() + 2;
232 using namespace protocols::stepwise::sampler::rna;
233 using namespace protocols::moves;
234 using namespace scoring;
243 if ( temps_.size() != orig_weights.size() ) {
244 weights_.push_back( 0 );
246 weights_.insert( weights_.end(), orig_weights.begin(),
247 orig_weights.end() );
251 std::string
const & seq1_(
option[seq1]() );
252 std::string
const & seq2_(
option[seq2]() );
253 Size const len1( get_sequence_len( seq1_ ) );
254 Size const len2( get_sequence_len( seq2_ ) );
261 scorefxn = ScoreFunctionFactory::create_score_function( RNA_HIRES_WTS );
270 Size const total_len( len1 + len2 );
271 for (
Size i = 1; i <= total_len; ++i ) {
272 if ( i > n_bp && i <= total_len - n_bp ) {
273 dangling_rsd.push_back( i );
275 bp_rsd.push_back( i );
280 RNA_MC_MultiSuite sampler;
281 for (
Size i = 1; i <= total_len; ++i ) {
282 bool const sample_near_a_form( bp_rsd.has_value( i ) );
283 if ( i == 1 || ( i > len1 && i != total_len ) ) {
284 RNA_MC_SuiteOP suite_sampler(
new RNA_MC_Suite( i ) );
285 suite_sampler->set_sample_bb( i != 1 );
286 suite_sampler->set_sample_lower_nucleoside(
true );
287 suite_sampler->set_sample_upper_nucleoside(
false );
288 suite_sampler->set_sample_near_a_form( sample_near_a_form );
289 suite_sampler->set_a_form_range(
option[a_form_range]() );
290 sampler.add_external_loop_rotamer( suite_sampler );
292 RNA_MC_SuiteOP suite_sampler(
new RNA_MC_Suite( i - 1 ) );
293 suite_sampler->set_sample_bb( len1 == total_len || i != total_len );
294 suite_sampler->set_sample_lower_nucleoside(
false );
295 suite_sampler->set_sample_upper_nucleoside(
true );
296 suite_sampler->set_sample_near_a_form( sample_near_a_form );
297 suite_sampler->set_a_form_range(
option[a_form_range]() );
298 sampler.add_external_loop_rotamer( suite_sampler );
302 sampler.apply( pose );
305 SimulatedTempering tempering( pose,
scorefxn, temps_, weights_ );
310 Size curr_counts( 1 );
315 temps_.size(), null_arr_ );
317 Real const min( -100.05 ),
max( 800.05 ), spacing( 0.1 );
322 Size n_accept_total( 0 ), n_t_jumps_accept( 0 );
323 Size const t_jump_interval( 10 );
324 Size const n_t_jumps( n_cycle_ / t_jump_interval );
325 Size temp_id( tempering.temp_id() );
326 bool const is_save_scores(
option[save_score_terms]() );
330 Real min_score( 99999 );
332 std::cout <<
"Start the main sampling loop." << std::endl;
333 if (
option[dump_pdb]() ) pose.dump_pdb(
"init.pdb" );
335 Size const n_dump =
option[n_intermediate_dump]();
340 for (
Size n = 1; n <= n_cycle_; ++n ) {
342 sampler.apply( pose );
343 if ( tempering.boltzmann( pose ) || n == n_cycle_ ) {
346 hist_list[temp_id].add(
scores[1], curr_counts );
348 if ( n == n_cycle_ )
break;
355 if ( n_dump != 0 && n * (n_dump + 1) /
double(n_cycle_) >= curr_dump ) {
356 std::ostringstream oss;
357 oss <<
"intermediate" <<
'_' << curr_dump <<
".pdb";
358 pose.dump_pdb(oss.str());
365 if ( n % t_jump_interval == 0 && tempering.t_jump() ) {
368 hist_list[temp_id].add(
scores[1], curr_counts );
371 temp_id = tempering.temp_id();
374 if (
option[dump_pdb]() ) {
375 pose.dump_pdb(
"end.pdb" );
376 min_pose.dump_pdb(
"min.pdb" );
383 std::cout <<
"n_cycles: " << n_cycle_ << std::endl;
384 std::cout <<
"Accept rate: " << double( n_accept_total ) / n_cycle_
386 std::cout <<
"T_jump accept rate: " << double( n_t_jumps_accept ) / n_t_jumps
390 std::cout <<
"Time in sampler: " << time_in_test << std::endl;
392 for (
Size i = 1; i <= temps_.size(); ++i ) {
393 if ( is_save_scores ) {
394 std::ostringstream oss;
395 oss <<
option[out_prefix]() <<
'_' << std::fixed << std::setprecision(2)
396 << temps_[i] <<
".bin.gz";
401 std::ostringstream oss;
402 oss <<
option[out_prefix]() <<
'_' << std::fixed << std::setprecision(2)
403 << temps_[i] <<
".hist.gz";
408 std::ostringstream oss1;
409 oss1 <<
option[out_prefix]() <<
"_hist_scores.gz";
422 main(
int argc,
char * argv [] )
424 using namespace core;
426 NEW_OPT( seq1,
"sequence 1 to model, 3' to 5' ",
"" );
427 NEW_OPT( seq2,
"sequence 2 to model, 3' to 5' ",
"" );
428 NEW_OPT( n_cycle,
"cycle number for random sampling", 0 );
429 NEW_OPT( a_form_range,
"Range of sampling near A-form for duplexes.", 60.0);
430 NEW_OPT( temps,
"Simulated tempering temperatures", null_real_vector );
431 NEW_OPT( st_weights,
"Simulated tempering weights", null_real_vector );
432 NEW_OPT( out_prefix,
"prefix for the out file",
"turner" );
434 "Save scores and individual score terms"
435 " of all sampled conformers",
false );
436 NEW_OPT( dump_pdb,
"Dump pdb files",
false );
438 "Number of intermediate conformations to be dumped", 0 );
442 protocols::viewer::viewer_main(
my_main );
444 std::cout <<
"caught exception " << e.
msg() << std::endl;
virtual std::string const msg() const
Real gaussian_stdev(Real const n_rsd, Real const temp, bool const is_bp)
void set_gaussian_stdev(sampler::rna::RNA_MC_MultiSuite &sampler, moves::SimulatedTempering const &tempering, utility::vector1< Size > const &bp_rsd, utility::vector1< Size > const &dangling_rsd)
utility::vector1< Size > hist_
BooleanOptionKey const user("options:user")
utility::vector1< Size > get_hist() const
#define runtime_assert(_Expression)
Assert that the condition holds. Evaluated for both debug and release builds.
common derived classes for thrown exceptions
void fill_data(utility::vector1< float > &data, Size const count, utility::vector1< float > &scores)
Histogram(Real const min, Real const max, Real const spacing)
rule< Scanner, options_closure::context_t > options
#define OPT_KEY(type, key)
utility::vector1< scoring::ScoreType > const & get_scoretypes()
Output file stream wrapper for uncompressed and compressed files.
void close()
Close the ofstream and reset the state.
PoseOP pose_setup(std::string const &seq1, std::string const &seq2, Size const len1)
utility::vector1< Real > get_scores() const
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
#define NEW_OPT(akey, help, adef)
void vector2disk_in2d(std::string const &out_filename, Size const dim1, Size const dim2, utility::vector1< T > const &out_vector)
int main(int argc, char *argv[])
ocstream cout(std::cout)
Wrapper around std::cout.
ozstream & write(char const *str, std::streamsize const count)
Write a string.
BooleanOptionKey const exit("options:exit")
void vector2disk_in1d(std::string const &out_filename, utility::vector1< T > const &out_vector)
ozstream: Output file stream wrapper for uncompressed and compressed files
void update_scores(utility::vector1< float > &scores, Pose &pose, scoring::ScoreFunctionOP const scorefxn)
void init()
set global 'init_was_called' to true
Program options global and initialization function.
void add(float const value, Size const n_items)
rule< Scanner, option_closure::context_t > option