16 #include "boinc_win.h"
25 #include <protocols/boinc/boinc.hh>
26 #include <core/scoring/rms_util.hh>
29 #include <core/types.hh>
30 #include <core/init/init.hh>
36 #include <basic/options/keys/boinc.OptionKeys.gen.hh>
45 #include "boinc_api.h"
46 #include "graphics2.h"
47 #include "graphics_data.h"
49 #include <core/io/serialization/serialize_pose.hh>
50 #include <core/pose/Pose.hh>
51 #include <core/conformation/Residue.fwd.hh>
52 #include <protocols/boinc/boinc_shmem.hh>
53 #include <protocols/viewer/viewers.hh>
54 #include <protocols/viewer/GraphicsState.hh>
56 #include <basic/options/keys/out.OptionKeys.gen.hh>
57 #include <basic/options/keys/in.OptionKeys.gen.hh>
58 #include <basic/options/keys/boinc.OptionKeys.gen.hh>
78 #include <GLUT/glut.h>
80 #include <glut/glut.h>
93 float native_window_size = { 28 };
94 int default_aspect_width = 6;
95 int default_aspect_height = 4;
96 float aspect_width, aspect_height;
102 std::string where_in_window;
103 GLfloat nativerotation[16], lowrotation[16], bestrotation[16], currentrotation[16];
104 bool const allow_rotation =
true;
106 float default_text_color[4] = {1., 1., 1., 1.};
107 float default_structure_text_color[4] = {.5f, .5f, .5f, 1.0f};
109 float wu_text_box_height = 0.0;
110 std::vector<std::string> wu_desc_rows;
112 float wu_desc_rows_per_small_box = 6.0;
115 bool randomly_cycle_appearance(
true);
118 APP_INIT_DATA app_init_data;
120 protocols::boinc::BoincSharedMemory* shmem = NULL;
124 std::vector<float> low_rmsd_vector;
125 std::vector<float> low_energy_vector;
126 std::vector<float> last_accepted_rmsd_vector;
127 std::vector<float> last_accepted_energy_vector;
128 std::vector<float> model_rmsd_vector;
129 std::vector<float> model_energy_vector;
131 float last_accepted_rmsd;
132 float low_energy_rmsd;
133 unsigned int last_low_energy_update_cnt;
134 unsigned int last_model_cnt;
136 enum GraphicsPoseType {
143 protocols::viewer::GraphicsState current_gs;
147 static core::Size current_pose_ghost_nres = 0;
150 bool native_exists(
false);
151 bool ghost_exists(
false);
152 static core::pose::PoseOP nativeposeOP;
153 static core::pose::PoseOP currentposeOP;
154 static core::pose::PoseOP currentposeghostOP;
155 static core::pose::PoseOP lastacceptedposeOP;
156 static core::pose::PoseOP lowenergyposeOP;
159 int low_viewport_x, low_viewport_y, low_viewport_width, low_viewport_height;
160 int native_viewport_x, native_viewport_y, native_viewport_width, native_viewport_height;
161 int best_viewport_x, best_viewport_y, best_viewport_width, best_viewport_height;
162 int current_viewport_x, current_viewport_y, current_viewport_width, current_viewport_height;
166 void scale(
const int & iw,
const int & ih) {
167 using namespace graphics;
168 float aspect_ratio = (
float)aspect_width/(
float)aspect_height;
169 float w=(
float)iw, h=(
float)ih;
171 if ( h*aspect_ratio >
w ) {
173 ys = (
w/aspect_ratio)/h;
175 xs = (h*aspect_ratio)/
w;
178 glScalef(xs, ys*aspect_ratio, 1.0
f);
184 void mode_ortho_start() {
185 glDisable(GL_DEPTH_TEST);
186 glMatrixMode(GL_PROJECTION);
189 glOrtho(0, 1, 0, 1, 0, 1);
190 glMatrixMode(GL_MODELVIEW);
199 glMatrixMode(GL_MODELVIEW);
200 glGetIntegerv(GL_VIEWPORT, (GLint*)viewport);
201 scale(viewport[2], viewport[3]);
204 void mode_ortho_done() {
205 glMatrixMode(GL_PROJECTION);
207 glMatrixMode(GL_MODELVIEW);
212 void get_bounds( std::vector< float >
const & t,
float & mn,
float & mx ) {
213 if ( !t.size() )
return;
221 for (
int i = t.size()-1; i >=
std::max(
int(0),
int( t.size()-LOOKBACK)); --i ) {
262 std::vector<float>
const & xdata,
263 std::vector<float>
const & ydata,
269 using namespace graphics;
271 protocols::viewer::draw_black_bg();
273 unsigned int total_steps = xdata.size();
274 if ( ydata.size() < total_steps ) total_steps = ydata.size();
276 if ( total_steps > 0 ) {
278 glMatrixMode(GL_PROJECTION);
281 float maxdatax =
log(1.0+xmax-xmin);
282 float mindatax =
log(1.0);
283 float maxdatay =
log(1.0+ymax-ymin);
284 float mindatay =
log(1.0);
286 gluOrtho2D( mindatax, maxdatax, mindatay, maxdatay );
287 glMatrixMode(GL_MODELVIEW);
288 glDisable( GL_DEPTH_TEST );
292 glBegin( GL_POINTS );
294 for (
unsigned int step = 0; step < total_steps; step++ ) {
295 float x = xdata[step];
296 float y = ydata[step];
298 if ( x > 0 ) x =
log(1.0+x);
301 if ( y > 0 ) y =
log(1.0+y);
307 int decoys = (native_exists) ? model_rmsd_vector.size() : model_energy_vector.size();
310 glBegin( GL_POINTS );
311 glColor3f(0.8
f,0.13
f,0.0
f);
312 for (
int step = 0; step < decoys; step++ ) {
313 float x = (native_exists) ? model_rmsd_vector[step] : model_energy_vector[step];
314 float y = model_energy_vector[step];
317 if ( x > 0 ) x =
log(1.0+x);
320 if ( y > 0 ) y =
log(1.0+y);
338 glEnable( GL_DEPTH_TEST );
343 void start_rotate( GLfloat decoyrotation[16]) {
345 glMultMatrixf(decoyrotation);
352 void do_the_rotation(
const int & x,
const int & y,
const int & left,
const int & middle,
353 const int & right, GLfloat decoyrotation[16],
const float & this_window_size ) {
354 using namespace graphics;
356 double delta_y = y-mouse_y;
357 double delta_x = x-mouse_x;
360 double axis_x = delta_y;
361 double axis_y = delta_x;
362 double userangle = sqrt(delta_x*delta_x + delta_y*delta_y);
364 glMatrixMode(GL_MODELVIEW);
374 glRotatef(userangle,axis_x,axis_y,0.0);
375 glMultMatrixf(decoyrotation);
376 glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation);
379 }
else if ( right ) {
380 double s = exp( 1.0* (
double) delta_y*0.01);
381 glMatrixMode(GL_MODELVIEW);
383 glMultMatrixf(decoyrotation);
385 glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation);
388 }
else if ( middle ) {
390 glGetIntegerv(GL_VIEWPORT,viewport);
391 glMatrixMode(GL_MODELVIEW);
392 double xscale = (this_window_size * 2.0)/(viewport[2]);
393 double yscale = (this_window_size * 2.0)/(viewport[3]);
395 glTranslatef( delta_x * xscale, -delta_y * yscale, 0);
396 glMultMatrixf(decoyrotation);
397 glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation);
406 void app_graphics_resize(
int w,
int h){
407 using namespace graphics;
408 glViewport(0, 0, w, h);
412 void boinc_app_mouse_move(
int x,
int y,
int left,
int middle,
int right) {
413 using namespace graphics;
415 if ( !allow_rotation )
return;
419 if ( where_in_window ==
"native" ) {
420 do_the_rotation( x, y, left, middle, right, nativerotation, native_window_size);
422 if ( where_in_window ==
"low" ) {
423 do_the_rotation( x, y, left, middle, right, lowrotation,
window_size);
425 if ( where_in_window ==
"current" ) {
426 do_the_rotation( x, y, left, middle, right, currentrotation,
window_size);
428 if ( where_in_window ==
"best" ) {
429 do_the_rotation( x, y, left, middle, right, bestrotation,
window_size);
434 void boinc_app_mouse_button(
int x,
int y,
int,
int is_down) {
435 using namespace graphics;
437 if ( !allow_rotation )
return;
447 if ( mouse_x > native_viewport_x && mouse_x < native_viewport_x + native_viewport_width &&
448 mouse_y > window_height - native_viewport_y - native_viewport_height&& mouse_y < window_height - native_viewport_y ) {
449 where_in_window =
"native";
451 ( mouse_x > low_viewport_x && mouse_x < low_viewport_x + low_viewport_width &&
452 mouse_y > window_height - low_viewport_y -low_viewport_height && mouse_y < window_height - low_viewport_y ) {
453 where_in_window =
"low";
455 ( mouse_x > current_viewport_x && mouse_x < current_viewport_x + current_viewport_width &&
456 mouse_y > window_height - current_viewport_y - current_viewport_height && mouse_y < window_height - current_viewport_y ) {
457 where_in_window =
"current";
459 ( mouse_x > best_viewport_x && mouse_x < best_viewport_x + best_viewport_width &&
460 mouse_y > window_height - best_viewport_y - best_viewport_height && mouse_y < window_height - best_viewport_y ) {
461 where_in_window =
"best";
463 where_in_window =
"";
468 void boinc_app_key_press(
int key,
int
470 using namespace graphics;
471 using namespace protocols::viewer;
472 if ( key == 67 || key == 99 ) {
473 current_gs.Color_mode = ColorMode ( current_gs.Color_mode + 1 );
474 if ( current_gs.Color_mode > RESIDUE_CPK_COLOR ) current_gs.Color_mode = RAINBOW_COLOR;
476 if ( key == 66 || key == 98 ) {
477 current_gs.BBdisplay_state = BBdisplayState ( current_gs.BBdisplay_state + 1 );
478 if ( current_gs.BBdisplay_state > SHOW_BBSPHERES ) current_gs.BBdisplay_state = SHOW_NOBB;
480 if ( key == 83 || key == 115 ) {
481 current_gs.SCdisplay_state = SCdisplayState ( current_gs.SCdisplay_state + 1 );
482 if ( current_gs.SCdisplay_state > SHOW_SCSPHERES ) current_gs.SCdisplay_state = SHOW_NOSC;
487 void boinc_app_key_release(
int,
int){}
490 void app_graphics_init() {
491 using namespace graphics;
493 using namespace basic::options::OptionKeys;
497 protocols::boinc::Boinc::get_semaphore();
504 if ( !
option[ OptionKeys::boinc::noshmem ]() ) {
505 protocols::boinc::Boinc::attach_shared_memory();
506 shmem = protocols::boinc::Boinc::get_shmem();
508 protocols::boinc::Boinc::wait_for_shared_memory_initialization();
514 std::string wu_name = app_init_data.wu_name;
515 if ( wu_name.length() > 0 ) wu_desc_rows.push_back( wu_name );
517 if ( shmem && shmem->wu_desc_exists ) {
518 if ( !protocols::boinc::Boinc::wait_semaphore() ) {
519 std::vector<std::string> tmp_wu_desc_rows;
520 core::io::serialization::BUFFER
b((
char*)(&shmem->wu_desc_buf ),protocols::boinc::WU_DESC_TEXT_BUFSIZE);
522 wu_desc_rows.insert(wu_desc_rows.end(), tmp_wu_desc_rows.begin(), tmp_wu_desc_rows.end());
523 protocols::boinc::Boinc::unlock_semaphore();
528 if ( !protocols::boinc::Boinc::wait_semaphore() ) {
529 randomly_cycle_appearance = shmem->randomly_cycle_appearance;
530 protocols::boinc::Boinc::unlock_semaphore();
533 if ( !randomly_cycle_appearance ) {
534 current_gs.SCdisplay_state = protocols::viewer::graphics_states_param::SHOW_SCSPHERES;
535 current_gs.BBdisplay_state = protocols::viewer::graphics_states_param::SHOW_BBSPHERES;
536 current_gs.Color_mode = protocols::viewer::graphics_states_param::RAINBOW_COLOR;
539 aspect_width =
float(default_aspect_width);
540 aspect_height =
float(default_aspect_height);
541 if ( wu_desc_rows.size() > 0 ) {
543 wu_text_box_height =
float(wu_desc_rows.size())/wu_desc_rows_per_small_box;
544 aspect_height += wu_text_box_height;
548 boinc_set_windows_icon(
"boinc_rosetta32",
"boinc_rosetta32");
552 protocols::boinc::Boinc::read_and_set_project_prefs();
553 boinc_max_fps = protocols::boinc::Boinc::get_project_pref_max_gfx_fps();
554 boinc_max_gfx_cpu_frac = protocols::boinc::Boinc::get_project_pref_max_gfx_cpu()/100.0;
557 if (
option[ OptionKeys::boinc::max_fps ].
user() ) {
558 boinc_max_fps =
option[ OptionKeys::boinc::max_fps ]();
560 if (
option[ OptionKeys::boinc::max_cpu ].
user() ) {
561 boinc_max_gfx_cpu_frac = (double)
option[ OptionKeys::boinc::max_cpu ]()/100.0;
564 glClearColor (0.0, 0.0, 0.0, 0.0);
565 glMatrixMode(GL_PROJECTION);
569 glMatrixMode(GL_MODELVIEW);
570 glGetFloatv(GL_MODELVIEW_MATRIX, nativerotation);
571 glGetFloatv(GL_MODELVIEW_MATRIX, lowrotation);
572 glGetFloatv(GL_MODELVIEW_MATRIX, currentrotation);
573 glGetFloatv(GL_MODELVIEW_MATRIX, bestrotation);
575 glEnable( GL_DEPTH_TEST );
576 glEnable(GL_LINE_SMOOTH);
578 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
579 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
580 glEnable(GL_NORMALIZE);
588 writeStrokeString(
const std::string & text_string, GLfloat *col,
const float & xpos,
const float & ypos,
int scalefactor=350 ) {
592 sprintf(buf,
"%s", text_string.c_str());
594 txf_render_string(.1, xpos, ypos, 0, scalefactor, col, 0, buf);
597 void display_text() {
598 using namespace graphics;
599 using namespace ObjexxFCL;
605 std::string mode_string =
"Stage: unknown";
607 if ( shmem->total_mc_trial_count == 0 && last_model_cnt == 0 ) {
610 static std::string initializing;
611 mode_string =
" Initializing";
612 initializing = (initializing.length() >= 10) ?
" ." : initializing +
" .";
613 mode_string += initializing;
614 }
else if ( shmem->total_mc_trial_count > 0 ) {
616 std::string mover_type;
617 if ( !protocols::boinc::Boinc::wait_semaphore() ) {
618 core::io::serialization::BUFFER
b((
char*)(&shmem->mover_type_text ),protocols::boinc::TEXT_BUFSIZE);
620 protocols::boinc::Boinc::unlock_semaphore();
622 mode_string =
"Stage: " + mover_type;
625 cpu_time = shmem->cpu_time;
626 float dt = dtime() - shmem->update_time;
628 boinc_close_window_and_quit(
"shmem not updated");
629 }
else if ( dt > 5 ) {
630 mode_string =
"App not running - exiting in 5 seconds";
631 }
else if ( shmem->status.suspended ) {
632 mode_string =
"App suspended";
636 glTranslatef( .01, 0.55, 0.0
f );
637 writeStrokeString( mode_string, default_text_color, 0.0
f, 0.0
f );
641 int hours =
int (cpu_time / 3600.0);
642 int minutes =
int ((cpu_time-3600*hours) / 60.0);
643 int seconds =
int ((cpu_time-3600*hours-60*minutes));
649 glTranslatef( .01, 0.45, 0.0
f );
650 writeStrokeString( cpu_time_str, default_text_color, 0.0
f, 0.0
f);
654 std::string user_string = app_init_data.user_name;
655 std::string user_total_credit_string =
ObjexxFCL::string_of(app_init_data.user_total_credit, 6);
656 std::string user_expavg_credit_string =
ObjexxFCL::string_of(app_init_data.user_expavg_credit , 6);
657 user_string = user_string +
" - Total credit: " + user_total_credit_string
658 +
" - RAC: " + user_expavg_credit_string;
661 glTranslatef( .01, 0.35, 0 );
662 writeStrokeString( user_string, default_text_color, 0.0
f, 0.0
f );
666 std::string team_string = app_init_data.team_name;
667 if ( team_string !=
"" ) {
669 glTranslatef( .01, .25, 0.0
f );
670 writeStrokeString( team_string, default_text_color, 0.0
f, 0.0
f);
676 std::string logo_string =
"Rosetta@home v" + appver +
" http://boinc.bakerlab.org/rosetta/";
679 glTranslatef( .01, .01, 0.0 );
680 writeStrokeString( logo_string, default_text_color, 0.0
f, 0.0
f, 275 );
688 std::string run_status_str;
690 float boinc_pct_complete = 100.0 * shmem->fraction_done;
691 run_status_str =
F( 7, 2, boinc_pct_complete ) +
"% Complete";
693 run_status_str =
"No shared mem";
697 glTranslatef( xshift, .55, 0.0
f );
698 writeStrokeString( run_status_str, default_text_color, 0.0
f, 0.0
f );
703 std::string ntrials_string =
"Model: " +
string_of(shmem->model_count, 4) +
704 " Step: " +
string_of(shmem->total_mc_trial_count);
706 glTranslatef( xshift, .45, 0.0
f );
707 writeStrokeString( ntrials_string, default_text_color, 0.0
f, 0.0
f );
711 std::string score_string2 =
"Accepted Energy: " +
string_of(shmem->last_accepted_energy, 7);
713 glTranslatef( xshift, .35, 0.0
f );
714 writeStrokeString( score_string2, default_text_color, 0.0
f, 0.0
f );
717 double lowenergytextypos = 0.25;
720 if ( native_exists ) {
721 lowenergytextypos = 0.15;
722 std::string acc_rmsd_string =
"Accepted RMSD: " +
string_of(last_accepted_rmsd, 4);
724 glTranslatef( xshift, .25, 0.0
f );
725 writeStrokeString( acc_rmsd_string, default_text_color, 0.0
f, 0.0
f );
730 std::string score_string3 =
"Low Energy: " +
string_of(shmem->low_energy, 7);
732 glTranslatef( xshift, lowenergytextypos, 0.0
f );
733 writeStrokeString( score_string3, default_text_color, 0.0
f, 0.0
f );
737 if ( native_exists ) {
738 std::string low_rmsd_string =
"Low RMSD: " +
string_of(low_energy_rmsd, 4);
740 glTranslatef( xshift, .05, 0.0
f );
741 writeStrokeString( low_rmsd_string, default_text_color, 0.0
f, 0.0
f );
748 Structure_display (
const graphics::GraphicsPoseType & graphics_pose_type,
const float & this_window_size )
750 using namespace graphics;
751 if ( !shmem || !current_pose_nres )
return;
753 float y_min_screen = - this_window_size;
754 float y_max_screen = + this_window_size;
755 float x_min_screen = - this_window_size;
756 float x_max_screen = + this_window_size;
759 protocols::viewer::draw_gradient_bg();
761 glMatrixMode(GL_PROJECTION);
763 glOrtho(x_min_screen, x_max_screen, y_min_screen, y_max_screen, -zmax, zmax);
764 glMatrixMode(GL_MODELVIEW);
766 switch( graphics_pose_type ){
768 start_rotate(currentrotation);
771 start_rotate(bestrotation);
774 start_rotate(lowrotation);
777 start_rotate(nativerotation);
781 switch( graphics_pose_type ){
783 protocols::viewer::draw_pose( *currentposeOP, current_gs );
784 if ( ghost_exists ) {
785 protocols::viewer::GraphicsState current_gs_ghost;
786 current_gs_ghost.BBdisplay_state = current_gs.BBdisplay_state;
787 current_gs_ghost.SCdisplay_state = current_gs.SCdisplay_state;
788 current_gs_ghost.Color_mode = protocols::viewer::graphics_states_param::GHOST_COLOR;
789 protocols::viewer::draw_pose( *currentposeghostOP, current_gs_ghost);
793 protocols::viewer::draw_pose( *lastacceptedposeOP, current_gs );
796 protocols::viewer::draw_pose( *lowenergyposeOP, current_gs );
799 protocols::viewer::draw_pose( *nativeposeOP, current_gs );
807 display_wu_desc(
const float & height ) {
808 using namespace graphics;
809 float rowheight =
float(small_box)/wu_desc_rows_per_small_box;
810 for (
unsigned int i=1; i <= wu_desc_rows.size(); i++ ) {
811 glViewport( 0, height - 3.0*small_box-rowheight*(
float)i, small_box*aspect_width, rowheight);
813 writeStrokeString( wu_desc_rows.at(i-1), default_text_color, 0.01, 0.0, 55);
819 void plot_timeseries(
820 std::vector<float>
const &
data,
821 std::vector<float>
const & data2,
822 bool const & vertical,
826 using namespace graphics;
828 protocols::viewer::draw_black_bg();
833 unsigned int total_steps;
834 total_steps = 10*(1+
int(data.size()/10));
835 total_steps =
std::max( (
unsigned int) (50), (
unsigned int)(
pow(4, 1+floor(
log(
float(data.size()) )/
log(4.0
f)) ) ) );
837 unsigned int LOOK_BACK =500;
838 if ( total_steps > LOOK_BACK ) {
839 total_steps = LOOK_BACK;
840 start_step = data.size() - total_steps;
842 start_step = data.size() - total_steps;
843 if ( start_step < 0 ) start_step = 0;
845 if ( data.size() > 0 ) {
846 float mindata,maxdata;
847 glMatrixMode(GL_PROJECTION);
851 maxdata =
log(1.0+max-min);
853 gluOrtho2D( mindata, maxdata, 0, total_steps-1 );
857 maxdata =
log(1.0+max-min);
861 gluOrtho2D( 0, total_steps-1, mindata, maxdata );
863 glMatrixMode(GL_MODELVIEW);
866 glDisable( GL_DEPTH_TEST );
870 glColor3f(0.0
f,1.0
f,0.0
f);
871 float min_point = 1e12;
873 glBegin( GL_LINE_STRIP );
874 for (
unsigned int step = start_step; step < data.size(); step++ ) {
876 float caged_data,
point = data[step];
877 if ( point < min_point ) min_point =
point;
881 if ( x > 0 ) x =
log(1.0+x);
882 y = (total_steps-1) - step+start_step;
883 caged_data =
std::min(maxdata,
std::max( (
float)mindata, (
float)x ) ) / (maxdata+0.001);
884 glColor3f(1.0-caged_data,1.0-caged_data,caged_data);
889 if ( y > 0 ) y =
log(1.0+y);
891 caged_data =
std::min(maxdata,
std::max( (
float)mindata, (
float)y ) ) / (maxdata+0.001);
892 glColor3f(1.0-caged_data,1.0-caged_data,caged_data);
903 void clear_trajectory() {
904 using namespace graphics;
905 static bool init =
false;
907 low_rmsd_vector.reserve(300000);
908 low_energy_vector.reserve(300000);
909 last_accepted_rmsd_vector.reserve(300000);
910 last_accepted_energy_vector.reserve(300000);
913 low_rmsd_vector.clear();
914 low_energy_vector.clear();
915 last_accepted_energy_vector.clear();
916 last_accepted_rmsd_vector.clear();
919 void get_shmem_structures() {
920 using namespace graphics;
921 if ( !shmem )
return;
924 if ( !protocols::boinc::Boinc::wait_semaphore() ) {
927 if ( shmem->native_pose_exists ) {
929 core::io::serialization::BUFFER bn((
char*)(&shmem->native_pose_buf ),protocols::boinc::POSE_BUFSIZE);
931 native_pose_nres = (*nativeposeOP).total_residue();
932 native_exists =
true;
936 if ( shmem->current_pose_exists ) {
937 core::io::serialization::BUFFER bc((
char*)(&shmem->current_pose_buf ),protocols::boinc::POSE_BUFSIZE);
939 current_pose_nres = (*currentposeOP).total_residue();
943 if ( shmem->current_pose_ghost_exists ) {
944 core::io::serialization::BUFFER bc((
char*)(&shmem->current_pose_ghost_buf ),protocols::boinc::POSE_BUFSIZE);
946 current_pose_ghost_nres = (*currentposeghostOP).total_residue();
951 if ( shmem->last_accepted_pose_exists ) {
952 core::io::serialization::BUFFER bla((
char*)(&shmem->last_accepted_pose_buf ),protocols::boinc::POSE_BUFSIZE);
954 if ( native_exists && (*lastacceptedposeOP).total_residue() > 0 ) {
955 last_accepted_rmsd = core::scoring::native_CA_rmsd( *nativeposeOP, *lastacceptedposeOP);
960 if ( shmem->low_energy_pose_exists ) {
961 core::io::serialization::BUFFER ble((
char*)(&shmem->low_energy_pose_buf ),protocols::boinc::POSE_BUFSIZE);
963 last_low_energy_update_cnt = shmem->low_energy_update_cnt;
964 if ( native_exists && (*lowenergyposeOP).total_residue() > 0 ) {
965 low_energy_rmsd = core::scoring::native_CA_rmsd( *nativeposeOP, *lowenergyposeOP);
970 if ( shmem->model_count != last_model_cnt ) {
972 model_energy_vector.push_back( shmem->model_low_energy );
973 if ( native_exists ) {
974 model_rmsd_vector.push_back( shmem->model_low_energy_rmsd );
977 last_model_cnt = shmem->model_count;
981 if ( shmem->total_mc_trial_count > 0 ) {
982 low_energy_vector.push_back( shmem->low_energy );
983 low_rmsd_vector.push_back( low_energy_rmsd );
984 last_accepted_energy_vector.push_back( shmem->last_accepted_energy );
985 last_accepted_rmsd_vector.push_back( last_accepted_rmsd );
988 max_pose_nres = (native_pose_nres > current_pose_nres) ? native_pose_nres : current_pose_nres;
990 protocols::boinc::Boinc::unlock_semaphore();
996 void draw_rosetta_screensaver(
int & width,
int & height )
998 using namespace graphics;
999 static int last_time_graphic_switch = time(NULL);
1001 glViewport(0 , 0, width, height );
1002 window_height = height;
1005 get_shmem_structures();
1008 if ( max_pose_nres > 0 ) {
1009 window_size = (current_pose_nres > 100) ? 0.7*(28 + ( current_pose_nres - 100)*0.15) : 28;
1010 native_window_size = (native_pose_nres > 100) ? 0.7*(28 + ( native_pose_nres - 100)*0.15) : 28;
1013 protocols::viewer::clear_bg();
1015 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1016 glViewport(0 , 0, width, height );
1017 glMatrixMode(GL_PROJECTION);
1019 gluOrtho2D(0 , 1, 0, 1);
1020 glMatrixMode(GL_MODELVIEW);
1021 glEnable( GL_DEPTH_TEST );
1023 if ( aspect >= aspect_width / aspect_height ) {
1025 small_box = int(height/aspect_height);
1028 small_box = int(width/aspect_width);
1030 int dim_main = 2*small_box;
1033 if ( wu_desc_rows.size() > 0 ) {
1036 glViewport( 0, height - 3*small_box - wu_text_box_height*small_box, small_box*aspect_width, wu_text_box_height*small_box );
1037 gluOrtho2D(0,1,0,aspect);
1038 glMatrixMode( GL_MODELVIEW );
1040 glColor3f( 0.5
f, 0.5
f, 0.5
f );
1041 glTranslatef( 0.0, 0.0, 0.0 );
1044 display_wu_desc( height );
1047 glViewport( 0, height - 4*small_box-
int(wu_text_box_height*small_box),
1048 int(small_box*aspect_width), small_box );
1052 glViewport( 0, height-4*small_box, small_box*6, small_box );
1057 current_viewport_x = 0;
1058 current_viewport_y = height-dim_main;
1059 current_viewport_width = current_viewport_height = dim_main;
1060 glViewport( current_viewport_x, current_viewport_y, current_viewport_width, current_viewport_height );
1062 protocols::viewer::draw_gradient_bg();
1066 best_viewport_x = dim_main;
1067 best_viewport_y = height-dim_main;
1068 best_viewport_width = best_viewport_height = dim_main;
1069 glViewport( best_viewport_x, best_viewport_y, best_viewport_width, best_viewport_height );
1071 protocols::viewer::draw_gradient_bg();
1074 if ( native_exists ) {
1076 low_viewport_x = 2 * dim_main;
1077 low_viewport_y = height - small_box;
1078 low_viewport_width = low_viewport_height = small_box;
1079 glViewport( low_viewport_x, low_viewport_y, low_viewport_width, low_viewport_height );
1081 protocols::viewer::draw_gradient_bg();
1084 native_viewport_x = 2 * dim_main;
1085 native_viewport_y = height - 2*small_box;
1086 native_viewport_width = native_viewport_height = small_box;
1087 glViewport( native_viewport_x, native_viewport_y, native_viewport_width, native_viewport_height );
1089 protocols::viewer::draw_gradient_bg();
1093 low_viewport_x = 2 * dim_main;
1094 low_viewport_y = height - dim_main;
1095 low_viewport_width = low_viewport_height = dim_main;
1096 glViewport( 2*dim_main, height-dim_main, dim_main, dim_main );
1098 protocols::viewer::draw_gradient_bg();
1102 using namespace graphics;
1103 using namespace protocols::viewer;
1107 if ( randomly_cycle_appearance ) {
1108 if ( (time(NULL) - last_time_graphic_switch) > 100 ) {
1109 last_time_graphic_switch = time(NULL);
1111 if ( rand() % 2 == 0 ) current_gs.BBdisplay_state = SHOW_CARTOON;
1112 else current_gs.BBdisplay_state = SHOW_BACKBONE;
1114 if ( rand() % 3 == 0 && max_pose_nres < 500 ) current_gs.SCdisplay_state = SHOW_STICK;
1115 else current_gs.SCdisplay_state = SHOW_NOSC;
1117 if ( current_gs.SCdisplay_state != SHOW_NOSC ) {
1118 int randnum = rand() % 4;
1119 if ( randnum == 0 ) current_gs.Color_mode = RAINBOW_COLOR;
1120 if ( randnum == 1 ) current_gs.Color_mode = RAINBOW_CPK_COLOR;
1121 if ( randnum == 2 ) current_gs.Color_mode = RESIDUE_CPK_COLOR;
1122 if ( randnum == 3 ) current_gs.Color_mode = CPK_COLOR;
1124 current_gs.Color_mode = RAINBOW_COLOR;
1131 float slowrotate = 0.8;
1132 glMatrixMode(GL_MODELVIEW);
1134 glRotatef(slowrotate,0,1,0.0);
1135 glMultMatrixf(graphics::nativerotation);
1136 glGetFloatv(GL_MODELVIEW_MATRIX, graphics::nativerotation);
1137 glMatrixMode(GL_MODELVIEW);
1139 glRotatef(slowrotate,0,1,0.0);
1140 glMultMatrixf(graphics::bestrotation);
1141 glGetFloatv(GL_MODELVIEW_MATRIX, graphics::bestrotation);
1142 glMatrixMode(GL_MODELVIEW);
1144 glRotatef(slowrotate,0,1,0.0);
1145 glMultMatrixf(graphics::currentrotation);
1146 glGetFloatv(GL_MODELVIEW_MATRIX, graphics::currentrotation);
1147 glMatrixMode(GL_MODELVIEW);
1149 glRotatef(slowrotate,0,1,0.0);
1150 glMultMatrixf(graphics::lowrotation);
1151 glGetFloatv(GL_MODELVIEW_MATRIX, graphics::lowrotation);
1154 current_viewport_x = 0;
1155 current_viewport_y = height-dim_main;
1156 current_viewport_width = current_viewport_height = dim_main;
1157 glViewport( current_viewport_x, current_viewport_y, current_viewport_width, current_viewport_height );
1160 glColor3f( 0.5
f, 0.5
f, 0.5
f );
1161 writeStrokeString(
"Searching...", default_structure_text_color, 0.0
f, 0.0
f, 280);
1165 best_viewport_x = dim_main;
1166 best_viewport_y = height-dim_main;
1167 best_viewport_width = best_viewport_height = dim_main;
1168 glViewport( best_viewport_x, best_viewport_y, best_viewport_width, best_viewport_height );
1171 glColor3f( 0.5
f, 0.5
f, 0.5
f );
1172 writeStrokeString(
"Accepted", default_structure_text_color, 0.0
f, 0.0
f, 280);
1175 float rms_min = 0.0;
1176 float rms_max = 0.0;
1177 get_bounds( last_accepted_rmsd_vector, rms_min, rms_max );
1178 if ( rms_max > 20 ) rms_max = 20.00;
1181 if ( rms_min < 1 ) rms_min = 0.01;
1183 float energy_min = 0;
1184 if ( last_accepted_energy_vector.size() >= 1 ) {
1185 energy_min = last_accepted_energy_vector[last_accepted_energy_vector.size()-1];
1187 float energy_max = energy_min;
1188 get_bounds( last_accepted_energy_vector, energy_min, energy_max );
1189 energy_max += 10.00;
1192 if ( native_exists ) {
1195 low_viewport_x = 2 * dim_main;
1196 low_viewport_y = height - small_box;
1197 low_viewport_width = low_viewport_height = small_box;
1198 glViewport( low_viewport_x, low_viewport_y, low_viewport_width, low_viewport_height );
1201 glColor3f( 0.5
f, 0.5
f, 0.5
f );
1202 writeStrokeString(
"Low Energy", default_structure_text_color, 0.0
f, 0.0
f, 200);
1206 native_viewport_x = 2 * dim_main;
1207 native_viewport_y = height - 2*small_box;
1208 native_viewport_width = native_viewport_height = small_box;
1209 glViewport( native_viewport_x, native_viewport_y, native_viewport_width, native_viewport_height );
1210 Structure_display(NATIVE, native_window_size);
1212 glColor3f( 0.5
f, 0.5
f, 0.5
f );
1213 writeStrokeString(
"Native", default_structure_text_color, 0.0
f, 0.0
f, 200);
1217 glViewport( 5*small_box, height-2*small_box, small_box, 2*small_box );
1218 plot_timeseries( last_accepted_rmsd_vector,low_rmsd_vector ,
true, rms_min, rms_max );
1220 writeStrokeString(
"RMSD", default_structure_text_color, 0.0
f, 0.0
f, 180 );
1225 low_viewport_x = 2 * dim_main;
1226 low_viewport_y = height - dim_main;
1227 low_viewport_width = low_viewport_height = dim_main;
1228 glViewport( 2*dim_main, height-dim_main, dim_main, dim_main );
1231 writeStrokeString(
"Low Energy", default_structure_text_color, 0.0
f, 0.0
f, 280);
1236 glViewport( 0, height-3*small_box, 5*small_box, small_box );
1237 plot_timeseries( last_accepted_energy_vector, low_energy_vector,
false, energy_min, energy_max );
1239 writeStrokeString(
"Accepted Energy", default_structure_text_color, 0.0
f, 0.0
f, 250 );
1243 glViewport( 5*small_box, height-3*small_box, small_box, small_box );
1244 if ( native_exists ) {
1245 plot_2D( last_accepted_rmsd_vector, last_accepted_energy_vector, rms_min, rms_max, energy_min, energy_max );
1261 void app_graphics_render(
int xs,
int ys,
double) { draw_rosetta_screensaver( xs, ys ); }
1263 #if _MSC_VER >= 1400
1265 RosettaInvalidParameterHandler(
1266 const wchar_t* expression,
1267 const wchar_t*
function,
1268 const wchar_t* file,
1275 "Invalid parameter detected in function %s. File: %s Line: %d\n",
1290 int main(
int argc,
char** argv) {
1293 using namespace graphics;
1295 using namespace basic::options::OptionKeys;
1296 std::cerr <<
"Starting graphics.." << std::endl;
1298 option.add_relevant( OptionKeys::boinc::graphics );
1299 option.add_relevant( OptionKeys::boinc::fullscreen );
1300 option.add_relevant( OptionKeys::boinc::max_fps );
1301 option.add_relevant( OptionKeys::boinc::max_cpu );
1302 option.add_relevant( OptionKeys::boinc::noshmem );
1307 boinc_init_graphics_diagnostics(
1308 BOINC_DIAG_DUMPCALLSTACKENABLED |
1309 BOINC_DIAG_HEAPCHECKENABLED |
1310 BOINC_DIAG_MEMORYLEAKCHECKENABLED |
1311 BOINC_DIAG_REDIRECTSTDERR |
1312 BOINC_DIAG_REDIRECTSTDOUT |
1313 BOINC_DIAG_TRACETOSTDERR
1316 boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS);
1321 #if _MSC_VER >= 1400
1326 _set_invalid_parameter_handler(RosettaInvalidParameterHandler);
1336 protocols::boinc::Boinc::instance();
1346 option[out::mute].value(
"all");
1350 boinc_parse_init_data_file();
1351 boinc_get_init_data(app_init_data);
1359 boinc_graphics_loop(argc, argv);
1362 boinc_finish_diag();
1365 std::cout <<
"caught exception " << e.
msg() << std::endl;
1370 #else // BOINC_GRAPHICS!
1375 std::cout <<
"Build with boinc api (scons extras=boinc,static)!" << std::endl;
ocstream cerr(std::cerr)
Wrapper around std::cerr.
virtual std::string const msg() const
cmplx w(cmplx z, double relerr)
basic::options::IntegerOptionKey const window_size("window_size")
std::istream & read_binary(std::istream &stream, FArray1< T > &a)
Read an FArray1 from a binary file.
BooleanOptionKey const user("options:user")
double log(double x, double base)
Computes log(x) in the given base.
common derived classes for thrown exceptions
Program exit functions and macros.
utility::keys::lookup::key< KeyType > const key
Input file stream wrapper for uncompressed and compressed files.
rule< Scanner, options_closure::context_t > options
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
ocstream cout(std::cout)
Wrapper around std::cout.
vector1: std::vector with 1-based indexing
std::string string_of(Fstring const &s)
string of an Fstring
void init()
set global 'init_was_called' to true
Program options global and initialization function.
numeric::xyzVector< core::Real > point
rule< Scanner, option_closure::context_t > option