Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
minirosetta_graphics.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
11 /// @brief
12 
13 #ifdef BOINC_GRAPHICS
14 #include <utility/io/izstream.hh>
15 #ifdef _WIN32
16 #include "boinc_win.h"
17 #else
18 #include <math.h>
19 #endif
20 
21 #if _MSC_VER >= 1400
22 #endif
23 
24 
25 #include <protocols/boinc/boinc.hh>
26 #include <core/scoring/rms_util.hh>
27 
28 
29 #include <core/types.hh>
30 #include <core/init/init.hh>
31 
32 // avoid having to create the static protocol movers
33 //#include <protocols/init/init.hh>
34 
35 #include <basic/options/option.hh>
36 #include <basic/options/keys/boinc.OptionKeys.gen.hh>
37 
38 #include <utility/exit.hh>
39 
40 #include "parse.h"
41 #include "util.h"
42 #include "gutil.h"
43 #include "boinc_gl.h"
44 #include "app_ipc.h"
45 #include "boinc_api.h"
46 #include "graphics2.h"
47 #include "graphics_data.h"
48 
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>
55 
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>
59 
60 #undef read
61 
62 // Project headers
63 #include <utility/vector1.hh>
65 
66 #include <vector>
67 
68 // New boinc specific options
69 
70 #include <basic/Tracer.hh>
71 
72 // ObjexxFCL Headers
73 #include <ObjexxFCL/format.hh>
74 #include <ObjexxFCL/Fstring.hh>
76 
77 #ifdef MAC
78 #include <GLUT/glut.h>
79 #elif _WIN32
80 #include <glut/glut.h>
81 #else
82 #include "GL/glut.h"
83 #endif
84 
85 #include "txf_util.h"
86 
87 #ifdef __APPLE__
88 #include "boinc_mac_app_icon.hh"
89 #endif
90 
91 namespace graphics {
92 float window_size = { 28 };
93 float native_window_size = { 28 };
94 int default_aspect_width = 6;
95 int default_aspect_height = 4;
96 float aspect_width, aspect_height;
97 float aspect;
98 int small_box;
99 int mouse_x, mouse_y;
100 bool mouse_down;
101 int window_height;
102 std::string where_in_window;
103 GLfloat nativerotation[16], lowrotation[16], bestrotation[16], currentrotation[16];
104 bool const allow_rotation = true;
105 
106 float default_text_color[4] = {1., 1., 1., 1.};
107 float default_structure_text_color[4] = {.5f, .5f, .5f, 1.0f};
108 
109 float wu_text_box_height = 0.0;
110 std::vector<std::string> wu_desc_rows;
111 // tinker with these to modify how the text is displayed
112 float wu_desc_rows_per_small_box = 6.0;
113 
114 // Variables associated with appearance:
115 bool randomly_cycle_appearance(true);
116 
117 // boinc data
118 APP_INIT_DATA app_init_data;
119 // shared memory
120 protocols::boinc::BoincSharedMemory* shmem = NULL;
121 
122 double cpu_time=0;
123 
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;
130 
131 float last_accepted_rmsd;
132 float low_energy_rmsd;
133 unsigned int last_low_energy_update_cnt;
134 unsigned int last_model_cnt;
135 
136 enum GraphicsPoseType {
137  CURRENT,
138  ACCEPTED,
139  LOW,
140  NATIVE
141 };
142 
143 protocols::viewer::GraphicsState current_gs;
144 
145 static core::Size max_pose_nres = 0;
146 static core::Size current_pose_nres = 0;
147 static core::Size current_pose_ghost_nres = 0;
148 static core::Size native_pose_nres = 0;
149 
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;
157 
158 // should probably make these maps, indexes by "low", etc.
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;
163 
164 }
165 
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;
170  float xs, ys;
171  if ( h*aspect_ratio > w ) {
172  xs = 1.0f;
173  ys = (w/aspect_ratio)/h;
174  } else {
175  xs = (h*aspect_ratio)/w;
176  ys = 1.0f;
177  }
178  glScalef(xs, ys*aspect_ratio, 1.0f);
179 }
180 
181 // call this to render 2D stuff, with 0..1x0..1 getting mapped
182 // to the full window. You must call ortho_done() when done.
183 //
184 void mode_ortho_start() {
185  glDisable(GL_DEPTH_TEST);
186  glMatrixMode(GL_PROJECTION);
187  glPushMatrix();
188  glLoadIdentity();
189  glOrtho(0, 1, 0, 1, 0, 1);
190  glMatrixMode(GL_MODELVIEW);
191  glPushMatrix();
192  glLoadIdentity();
193  gluLookAt(
194  0.0, 0.0, 1.0, // eye position
195  0, 0, 0, // where we're looking
196  0.0, 1.0, 0. // up is in positive Y direction
197  );
198  int viewport[4];
199  glMatrixMode(GL_MODELVIEW);
200  glGetIntegerv(GL_VIEWPORT, (GLint*)viewport);
201  scale(viewport[2], viewport[3]);
202 }
203 
204 void mode_ortho_done() {
205  glMatrixMode(GL_PROJECTION);
206  glPopMatrix();
207  glMatrixMode(GL_MODELVIEW);
208  glPopMatrix();
209  glLoadIdentity();
210 }
211 
212 void get_bounds( std::vector< float > const & t, float & mn, float & mx ) {
213  if ( !t.size() ) return;
214 
215  //OK, now look back -- if there was a huge jump at some point,
216  // ignore points in the trajectory before then.
217  int count(0);
218  int LOOKBACK = 500;
219  mn=t[t.size()-1];
220  mx=mn;
221  for ( int i = t.size()-1; i >= std::max(int(0),int( t.size()-LOOKBACK)); --i ) {
222  mn = std::min( mn, t[i]);
223  mx = std::max( mx, t[i]);
224  count++;
225  }
226  mn-=0.00;
227  mx+=0.00;
228  return;
229  /*
230  //How about using some estimate of the variance. This
231  // will help us figure out if a big jump occurred recently.
232  int const NUM_LOOK_BACK = 10000;
233  int const i_start = std::max( static_cast<int>(t.size()) - NUM_LOOK_BACK, 0);
234  int const i_end = t.size() - 1;
235  int const numpoints = i_end - i_start + 1;
236 
237  float x (0.0);
238  for ( int i=i_start+1; i<= i_end; ++i ) {
239  float const score_jump = std::abs(t[i+1] - t[i]);
240  if (score_jump < 10.0 ) x += score_jump;
241  }
242  float const avg_jump = x / numpoints; //This should be of order 1 (for energy).
243 
244  //OK, now look back -- if there was a huge jump at some point,
245  // ignore points in the trajectory before then.
246  mn = t[ i_end ];
247  mx = mn;
248  int count(0);
249  for ( int i = i_end-1; i >= i_start; --i ) {
250  if (std::abs(t[i+1] - t[i]) > 50.0*avg_jump) break;
251  mn = std::min( mn, t[i]);
252  mx = std::max( mx, t[i]);
253  count++;
254  }
255 
256  */
257 }
258 
259 
260 void
261 plot_2D(
262  std::vector<float> const & xdata,
263  std::vector<float> const & ydata,
264  float const xmin,
265  float const xmax,
266  float const ymin,
267  float const ymax
268 ) {
269  using namespace graphics;
270 
271  protocols::viewer::draw_black_bg();
272 
273  unsigned int total_steps = xdata.size();
274  if ( ydata.size() < total_steps ) total_steps = ydata.size();
275 
276  if ( total_steps > 0 ) {
277 
278  glMatrixMode(GL_PROJECTION);
279  glLoadIdentity();
280 
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);
285 
286  gluOrtho2D( mindatax, maxdatax, mindatay, maxdatay );
287  glMatrixMode(GL_MODELVIEW);
288  glDisable( GL_DEPTH_TEST );
289  glLoadIdentity();
290 
291  glPointSize( 2.0 );
292  glBegin( GL_POINTS );
293  glColor3f(.5,.5,.5);
294  for ( unsigned int step = 0; step < total_steps; step++ ) {
295  float x = xdata[step];
296  float y = ydata[step];
297  x -= xmin;
298  if ( x > 0 ) x = log(1.0+x);
299  else continue;
300  y -= ymin;
301  if ( y > 0 ) y = log(1.0+y);
302  else continue;
303  glVertex2f( x, y ) ;
304  }
305  glEnd();
306 
307  int decoys = (native_exists) ? model_rmsd_vector.size() : model_energy_vector.size();
308  if ( decoys > 0 ) {
309  glPointSize( 4.0 );
310  glBegin( GL_POINTS );
311  glColor3f(0.8f,0.13f,0.0f); //rust
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];
315  if ( x && y ) {
316  x -= xmin;
317  if ( x > 0 ) x = log(1.0+x);
318  else continue;
319  y -= ymin;
320  if ( y > 0 ) y = log(1.0+y);
321  else continue;
322 
323  glVertex2f( x, y );
324  }
325  }
326  glEnd();
327  }
328  /*
329  // cross hairs
330  glColor3f(.5,.5,.5);
331  glBegin( GL_LINES );
332  glVertex2f( xdata[total_steps-1], ymax ) ;
333  glVertex2f( xdata[total_steps-1], ymin );
334  glVertex2f( xmin, ydata[total_steps-1] );
335  glVertex2f( xmax, ydata[total_steps-1] );
336  glEnd();
337  */
338  glEnable( GL_DEPTH_TEST );
339  glLoadIdentity();
340  }
341 }
342 
343 void start_rotate( GLfloat decoyrotation[16]) {
344  glPushMatrix();
345  glMultMatrixf(decoyrotation);
346 }
347 
348 void end_rotate() {
349  glPopMatrix();
350 }
351 
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;
355 
356  double delta_y = y-mouse_y;
357  double delta_x = x-mouse_x;
358 
359  if ( left ) {
360  double axis_x = delta_y;
361  double axis_y = delta_x;
362  double userangle = sqrt(delta_x*delta_x + delta_y*delta_y);
363 
364  glMatrixMode(GL_MODELVIEW);
365  // Standard GLUT rotation is a postmultiplication - rotation around
366  // molecule's inertial frame -- and leads to
367  // non-intuitive behavior.
368  //glRotatef(userangle,axis_x,axis_y,0.0);
369 
370  //A premultiplication -- rotates around the axis the user actually sees.
371  // A little more complicated to code; unfortunately GLUT doesn't have a one-line
372  // function for it.
373  glLoadIdentity();
374  glRotatef(userangle,axis_x,axis_y,0.0);
375  glMultMatrixf(decoyrotation);
376  glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation); // Store current model view in decoyrotation
377  mouse_y = y;
378  mouse_x = x;
379  } else if ( right ) { //Zoom
380  double s = exp( 1.0* (double) delta_y*0.01);
381  glMatrixMode(GL_MODELVIEW);
382  glLoadIdentity();
383  glMultMatrixf(decoyrotation);
384  glScalef(s,s,s);
385  glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation); // Store current model view in decoyrotation
386  mouse_y = y;
387  mouse_x = x;
388  } else if ( middle ) { //Translate
389  GLint viewport[4];
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]);
394  glLoadIdentity();
395  glTranslatef( delta_x * xscale, -delta_y * yscale, 0);
396  glMultMatrixf(decoyrotation);
397  glGetFloatv(GL_MODELVIEW_MATRIX, decoyrotation);
398  mouse_y = y;
399  mouse_x = x;
400  } else {
401  mouse_down = false;
402  }
403 }
404 
405 // BOINC GRAPHICS API
406 void app_graphics_resize(int w, int h){
407  using namespace graphics;
408  glViewport(0, 0, w, h);
409 }
410 
411 // BOINC GRAPHICS API
412 void boinc_app_mouse_move(int x, int y, int left, int middle, int right) {
413  using namespace graphics;
414 
415  if ( !allow_rotation ) return;
416 
417  //if (!native_centered) return; // just rotate native for now
418  // Where are we? In low, native, accepted, or current?
419  if ( where_in_window == "native" ) {
420  do_the_rotation( x, y, left, middle, right, nativerotation, native_window_size);
421  }
422  if ( where_in_window == "low" ) {
423  do_the_rotation( x, y, left, middle, right, lowrotation, window_size);
424  }
425  if ( where_in_window == "current" ) {
426  do_the_rotation( x, y, left, middle, right, currentrotation, window_size);
427  }
428  if ( where_in_window == "best" ) {
429  do_the_rotation( x, y, left, middle, right, bestrotation, window_size);
430  }
431 }
432 
433 // BOINC GRAPHICS API
434 void boinc_app_mouse_button(int x, int y, int, int is_down) {
435  using namespace graphics;
436 
437  if ( !allow_rotation ) return;
438 
439  if ( is_down ) {
440  mouse_down = true;
441  mouse_x = x;
442  mouse_y = y;
443  } else {
444  mouse_down = false;
445  }
446 
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"; //native
450  } else if
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";
454  } else if
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";
458  } else if
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";
462  } else {
463  where_in_window = ""; //somewhere else
464  }
465 }
466 
467 // BOINC GRAPHICS API
468 void boinc_app_key_press(int key, int //lParam // system-specific key encodings
469 ){
470  using namespace graphics;
471  using namespace protocols::viewer;
472  if ( key == 67 || key == 99 ) { //'c' control color
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;
475  }
476  if ( key == 66 || key == 98 ) { //'b' control backbone display
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;
479  }
480  if ( key == 83 || key == 115 ) { //'s' control sidechain display
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;
483  }
484 }
485 
486 // BOINC GRAPHICS API
487 void boinc_app_key_release(int, int){}
488 
489 // BOINC GRAPHICS API
490 void app_graphics_init() {
491  using namespace graphics;
492  using namespace basic::options;
493  using namespace basic::options::OptionKeys;
494 
495  /* Open the Semaphore */
496  // for shared memory data sychronization
497  protocols::boinc::Boinc::get_semaphore();
498 
499  // boinc_graphics_get_shmem() must be called after
500  // boinc_parse_init_data_file()
501  // Put this in the main loop to allow retries if the
502  // worker application has not yet created shared memory
503  //
504  if ( !option[ OptionKeys::boinc::noshmem ]() ) {
505  protocols::boinc::Boinc::attach_shared_memory();
506  shmem = protocols::boinc::Boinc::get_shmem();
507  //Wait until the shared memory has been initialized:
508  protocols::boinc::Boinc::wait_for_shared_memory_initialization();
509  }
510 
511  // get workunit description
512 
513  // display work init name first
514  std::string wu_name = app_init_data.wu_name;
515  if ( wu_name.length() > 0 ) wu_desc_rows.push_back( wu_name );
516 
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);
521  core::io::serialization::read_binary(tmp_wu_desc_rows, b);
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();
524  }
525  }
526 
527  if ( shmem ) {
528  if ( !protocols::boinc::Boinc::wait_semaphore() ) {
529  randomly_cycle_appearance = shmem->randomly_cycle_appearance;
530  protocols::boinc::Boinc::unlock_semaphore();
531  }
532  }
533  if ( !randomly_cycle_appearance ) { //Set the appearance to spheres if we're not randomly cycling:
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;
537  }
538 
539  aspect_width = float(default_aspect_width);
540  aspect_height = float(default_aspect_height);
541  if ( wu_desc_rows.size() > 0 ) {
542  //small box is 1 aspect_height unit
543  wu_text_box_height = float(wu_desc_rows.size())/wu_desc_rows_per_small_box;
544  aspect_height += wu_text_box_height;
545  }
546 
547 #ifdef _WIN32
548  boinc_set_windows_icon("boinc_rosetta32","boinc_rosetta32");
549 #endif
550 
551  // read project specific prefs
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;
555 
556  // for testing
557  if ( option[ OptionKeys::boinc::max_fps ].user() ) {
558  boinc_max_fps = option[ OptionKeys::boinc::max_fps ]();
559  }
560  if ( option[ OptionKeys::boinc::max_cpu ].user() ) {
561  boinc_max_gfx_cpu_frac = (double)option[ OptionKeys::boinc::max_cpu ]()/100.0;
562  }
563 
564  glClearColor (0.0, 0.0, 0.0, 0.0);
565  glMatrixMode(GL_PROJECTION);
566  glLoadIdentity();
567  int size = 30;
568  glOrtho(-size, size, -size, size, -size, size);
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);
574 
575  glEnable( GL_DEPTH_TEST );
576  glEnable(GL_LINE_SMOOTH);
577  glEnable(GL_BLEND);
578  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
579  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
580  glEnable(GL_NORMALIZE);
581 
582  // Expects a .txf file to exist in run directory
583  // TEXT WILL NOT DISPLAY IF .txf FILE IS MISSING!!
584  txf_load_fonts(".");
585 }
586 
587 void
588 writeStrokeString( const std::string & text_string, GLfloat *col, const float & xpos, const float & ypos, int scalefactor=350 ) {
589  // USE NICE FONTS
590  // Requires .txf file in run directory
591  char buf[256];
592  sprintf(buf, "%s", text_string.c_str());
593  // FROM BOINC API fscale bigger is smaller
594  txf_render_string(.1, xpos, ypos, 0, scalefactor, col, 0, buf);
595 }
596 
597 void display_text() {
598  using namespace graphics;
599  using namespace ObjexxFCL;
600  using namespace ObjexxFCL::format;
601  ///////////////////////////////////////////////////////////////
602  // START LEFT COLUMN
603 
604  // STAGE TEXT
605  std::string mode_string = "Stage: unknown";
606  if ( shmem ) {
607  if ( shmem->total_mc_trial_count == 0 && last_model_cnt == 0 ) {
608  // initializing?
609  // show it's doing something
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 ) {
615  // Stage: mover type info
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();
621  }
622  mode_string = "Stage: " + mover_type;
623  }
624  // update cpu run time
625  cpu_time = shmem->cpu_time;
626  float dt = dtime() - shmem->update_time;
627  if ( dt > 10 ) {
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";
633  }
634  }
635  mode_ortho_start();
636  glTranslatef( .01, 0.55, 0.0f );
637  writeStrokeString( mode_string, default_text_color, 0.0f, 0.0f );
638  mode_ortho_done();
639 
640  // CPU TIME TEXT
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));
644  std::string cpu_time_str = "CPU time: " + ObjexxFCL::string_of(hours) + " hr "
645  + ObjexxFCL::string_of(minutes) + " min "
646  + ObjexxFCL::string_of(seconds) + " sec ";
647 
648  mode_ortho_start();
649  glTranslatef( .01, 0.45, 0.0f );
650  writeStrokeString( cpu_time_str, default_text_color, 0.0f, 0.0f);
651  mode_ortho_done();
652 
653  // USER TEXT
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;
659 
660  mode_ortho_start();
661  glTranslatef( .01, 0.35, 0 );
662  writeStrokeString( user_string, default_text_color, 0.0f, 0.0f );
663  mode_ortho_done();
664 
665  // TEAM TEXT
666  std::string team_string = app_init_data.team_name;
667  if ( team_string != "" ) {
668  mode_ortho_start();
669  glTranslatef( .01, .25, 0.0f );
670  writeStrokeString( team_string, default_text_color, 0.0f, 0.0f);
671  mode_ortho_done();
672  }
673 
674  // LOGO TEXT
675  std::string appver = ObjexxFCL::string_of(app_init_data.app_version/100.0, 3);
676  std::string logo_string = "Rosetta@home v" + appver + " http://boinc.bakerlab.org/rosetta/";
677 
678  mode_ortho_start();
679  glTranslatef( .01, .01, 0.0 );
680  writeStrokeString( logo_string, default_text_color, 0.0f, 0.0f, 275 );
681  mode_ortho_done();
682 
683  ///////////////////////////////////////////////////////////////
684  // START RIGHT COLUMN
685  float xshift = 2.7;
686 
687  // RUN STATUS - PERCENT COMPLETE TEXT
688  std::string run_status_str;
689  if ( shmem ) {
690  float boinc_pct_complete = 100.0 * shmem->fraction_done;
691  run_status_str = F( 7, 2, boinc_pct_complete ) + "% Complete";
692  } else {
693  run_status_str = "No shared mem";
694  }
695 
696  mode_ortho_start();
697  glTranslatef( xshift, .55, 0.0f );
698  writeStrokeString( run_status_str, default_text_color, 0.0f, 0.0f );
699  mode_ortho_done();
700 
701  // MODEL AND STEP TEXT
702  if ( shmem ) {
703  std::string ntrials_string = "Model: " + string_of(shmem->model_count, 4) +
704  " Step: " + string_of(shmem->total_mc_trial_count);
705  mode_ortho_start();
706  glTranslatef( xshift, .45, 0.0f );
707  writeStrokeString( ntrials_string, default_text_color, 0.0f, 0.0f );
708  mode_ortho_done();
709 
710  // LAST ACCEPTED ENERGY TEXT
711  std::string score_string2 = "Accepted Energy: " + string_of(shmem->last_accepted_energy, 7);
712  mode_ortho_start();
713  glTranslatef( xshift, .35, 0.0f );
714  writeStrokeString( score_string2, default_text_color, 0.0f, 0.0f );
715  mode_ortho_done();
716 
717  double lowenergytextypos = 0.25;
718 
719  // LAST ACCEPTED RMSD TEXT
720  if ( native_exists ) {
721  lowenergytextypos = 0.15;
722  std::string acc_rmsd_string = "Accepted RMSD: " + string_of(last_accepted_rmsd, 4);
723  mode_ortho_start();
724  glTranslatef( xshift, .25, 0.0f );
725  writeStrokeString( acc_rmsd_string, default_text_color, 0.0f, 0.0f );
726  mode_ortho_done();
727  }
728 
729  // LOW ENERGY TEXT
730  std::string score_string3 = "Low Energy: " + string_of(shmem->low_energy, 7);
731  mode_ortho_start();
732  glTranslatef( xshift, lowenergytextypos, 0.0f );
733  writeStrokeString( score_string3, default_text_color, 0.0f, 0.0f );
734  mode_ortho_done();
735 
736  // LOW ENERGY RMSD TEXT
737  if ( native_exists ) {
738  std::string low_rmsd_string = "Low RMSD: " + string_of(low_energy_rmsd, 4);
739  mode_ortho_start();
740  glTranslatef( xshift, .05, 0.0f );
741  writeStrokeString( low_rmsd_string, default_text_color, 0.0f, 0.0f );
742  mode_ortho_done();
743  }
744  }
745 }
746 
747 void
748 Structure_display ( const graphics::GraphicsPoseType & graphics_pose_type, const float & this_window_size )
749 {
750  using namespace graphics;
751  if ( !shmem || !current_pose_nres ) return;
752 
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;
757  float zmax = 300.0;
758 
759  protocols::viewer::draw_gradient_bg();
760 
761  glMatrixMode(GL_PROJECTION);
762  glLoadIdentity();
763  glOrtho(x_min_screen, x_max_screen, y_min_screen, y_max_screen, -zmax, zmax);
764  glMatrixMode(GL_MODELVIEW);
765 
766  switch( graphics_pose_type ){
767  case CURRENT :
768  start_rotate(currentrotation);
769  break;
770  case ACCEPTED :
771  start_rotate(bestrotation);
772  break;
773  case LOW :
774  start_rotate(lowrotation);
775  break;
776  case NATIVE :
777  start_rotate(nativerotation);
778  break;
779  }
780 
781  switch( graphics_pose_type ){
782  case CURRENT :
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);
790  }
791  break;
792  case ACCEPTED :
793  protocols::viewer::draw_pose( *lastacceptedposeOP, current_gs );
794  break;
795  case LOW :
796  protocols::viewer::draw_pose( *lowenergyposeOP, current_gs );
797  break;
798  case NATIVE :
799  protocols::viewer::draw_pose( *nativeposeOP, current_gs );
800  break;
801  }
802  glLoadIdentity();
803  end_rotate();
804 }
805 
806 void
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);
812  mode_ortho_start();
813  writeStrokeString( wu_desc_rows.at(i-1), default_text_color, 0.01, 0.0, 55);
814  mode_ortho_done();
815  }
816 }
817 
818 
819 void plot_timeseries(
820  std::vector<float> const & data,
821  std::vector<float> const & data2,
822  bool const & vertical,
823  float const & min,
824  float const & max
825 ) {
826  using namespace graphics;
827 
828  protocols::viewer::draw_black_bg();
829 
830  //int logsteps = int( ((float)log(float(data.size() )*5.0f) ) );
831  //unsigned int total_steps = pow( log(1),
832 
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.0f)) ) ) );
836  int start_step = 0;
837  unsigned int LOOK_BACK =500;
838  if ( total_steps > LOOK_BACK ) {
839  total_steps = LOOK_BACK;
840  start_step = data.size() - total_steps;
841  }
842  start_step = data.size() - total_steps;
843  if ( start_step < 0 ) start_step = 0;
844 
845  if ( data.size() > 0 ) {
846  float mindata,maxdata;
847  glMatrixMode(GL_PROJECTION);
848  glLoadIdentity();
849  if ( vertical ) {
850  //gluOrtho2D( min, max, 0, total_steps-1 );
851  maxdata =log(1.0+max-min);
852  mindata =log(1.0);
853  gluOrtho2D( mindata, maxdata, 0, total_steps-1 );
854 
855  } else {
856  //gluOrtho2D( 0, total_steps-1, min, max );
857  maxdata = log(1.0+max-min);
858  mindata = log(1.0);
859  //maxdata = max; //log(1+max-min);
860  //mindata = min; //log(1.0);
861  gluOrtho2D( 0, total_steps-1, mindata, maxdata );
862  }
863  glMatrixMode(GL_MODELVIEW);
864  // glColor3f(0.1f,0.7f,0.7f); //light blue
865  // glColor3f(1.0f,0.0f,0.0f); // red
866  glDisable( GL_DEPTH_TEST );
867  glLoadIdentity();
868  glColor3f(.5,.5,.5);
869 
870  glColor3f(0.0f,1.0f,0.0f); // yellow
871  float min_point = 1e12;
872  glLineWidth( 2.0 );
873  glBegin( GL_LINE_STRIP );
874  for ( unsigned int step = start_step; step < data.size(); step++ ) {
875  float x, y;
876  float caged_data,point = data[step];
877  if ( point < min_point ) min_point = point;
878  if ( vertical ) {
879  x = point;
880  x -= min;
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); // yellow
885  } else {
886  x = step-start_step;
887  y = point;
888  y -= min;
889  if ( y > 0 ) y = log(1.0+y);
890 
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); // yellow
893 
894  }
895  glVertex2f( x, y ) ;
896  }
897  glEnd();
898  glLineWidth( 1.0 );
899  glLoadIdentity();
900  }
901 }
902 
903 void clear_trajectory() {
904  using namespace graphics;
905  static bool init = false;
906  if ( ! init ) {
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);
911  init = true;
912  }
913  low_rmsd_vector.clear();
914  low_energy_vector.clear();
915  last_accepted_energy_vector.clear();
916  last_accepted_rmsd_vector.clear();
917 }
918 
919 void get_shmem_structures() {
920  using namespace graphics;
921  if ( !shmem ) return;
922 
923  // need to make sure we are in sync with the worker app
924  if ( !protocols::boinc::Boinc::wait_semaphore() ) {
925 
926  // get native pose
927  if ( shmem->native_pose_exists ) {
928  // get native
929  core::io::serialization::BUFFER bn((char*)(&shmem->native_pose_buf ),protocols::boinc::POSE_BUFSIZE);
930  core::io::serialization::read_binary(*nativeposeOP,bn);
931  native_pose_nres = (*nativeposeOP).total_residue();
932  native_exists = true;
933  }
934 
935  // get current pose
936  if ( shmem->current_pose_exists ) {
937  core::io::serialization::BUFFER bc((char*)(&shmem->current_pose_buf ),protocols::boinc::POSE_BUFSIZE);
938  core::io::serialization::read_binary(*currentposeOP,bc);
939  current_pose_nres = (*currentposeOP).total_residue();
940  }
941 
942  // get current pose "ghost" (overlay structure)
943  if ( shmem->current_pose_ghost_exists ) {
944  core::io::serialization::BUFFER bc((char*)(&shmem->current_pose_ghost_buf ),protocols::boinc::POSE_BUFSIZE);
945  core::io::serialization::read_binary(*currentposeghostOP,bc);
946  current_pose_ghost_nres = (*currentposeghostOP).total_residue();
947  ghost_exists = true;
948  }
949 
950  // get last accepted pose and calculate rmsd
951  if ( shmem->last_accepted_pose_exists ) {
952  core::io::serialization::BUFFER bla((char*)(&shmem->last_accepted_pose_buf ),protocols::boinc::POSE_BUFSIZE);
953  core::io::serialization::read_binary(*lastacceptedposeOP,bla);
954  if ( native_exists && (*lastacceptedposeOP).total_residue() > 0 ) {
955  last_accepted_rmsd = core::scoring::native_CA_rmsd( *nativeposeOP, *lastacceptedposeOP);
956  }
957  }
958 
959  // get low energy pose and calculate rmsd
960  if ( shmem->low_energy_pose_exists ) {
961  core::io::serialization::BUFFER ble((char*)(&shmem->low_energy_pose_buf ),protocols::boinc::POSE_BUFSIZE);
962  core::io::serialization::read_binary(*lowenergyposeOP,ble);
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);
966  }
967  }
968 
969  // next model? clear trajectory
970  if ( shmem->model_count != last_model_cnt ) {
971  // get low energy model rmsd and energy
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 );
975  }
976  clear_trajectory();
977  last_model_cnt = shmem->model_count;
978  }
979 
980  // get monte carlo trial info (resolved to graphics frame rate)
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 );
986  }
987 
988  max_pose_nres = (native_pose_nres > current_pose_nres) ? native_pose_nres : current_pose_nres;
989 
990  protocols::boinc::Boinc::unlock_semaphore();
991  }
992 
993 }
994 
995 
996 void draw_rosetta_screensaver( int & width, int & height )
997 {
998  using namespace graphics;
999  static int last_time_graphic_switch = time(NULL);
1000 
1001  glViewport(0 , 0, width, height );
1002  window_height = height; // needed to track mouse position.
1003  aspect = float(width)/float(height);
1004 
1005  get_shmem_structures(); // !!
1006 
1007  // users complaining that they can't see the whole protein...
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;
1011  }
1012 
1013  protocols::viewer::clear_bg();
1014 
1015  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1016  glViewport(0 , 0, width, height );
1017  glMatrixMode(GL_PROJECTION);
1018  glLoadIdentity();
1019  gluOrtho2D(0 , 1, 0, 1);
1020  glMatrixMode(GL_MODELVIEW);
1021  glEnable( GL_DEPTH_TEST );
1022 
1023  if ( aspect >= aspect_width / aspect_height ) {
1024  // add space to right side (wider than tall)
1025  small_box = int(height/aspect_height);
1026  } else {
1027  // add space to bottom (taller than wide)
1028  small_box = int(width/aspect_width);
1029  }
1030  int dim_main = 2*small_box;
1031 
1032  // Work Unit Description?
1033  if ( wu_desc_rows.size() > 0 ) {
1034 
1035  // generate box for description
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 );
1039  glLoadIdentity();
1040  glColor3f( 0.5f, 0.5f, 0.5f );
1041  glTranslatef( 0.0, 0.0, 0.0 );
1042  glLoadIdentity();
1043 
1044  display_wu_desc( height );
1045 
1046  // Main text box
1047  glViewport( 0, height - 4*small_box-int(wu_text_box_height*small_box),
1048  int(small_box*aspect_width), small_box );
1049  display_text();
1050 
1051  } else {
1052  glViewport( 0, height-4*small_box, small_box*6, small_box );
1053  display_text();
1054  }
1055 
1056  // SEARCHING BOX -- INITIALIZATION
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 );
1061  mode_ortho_start();
1062  protocols::viewer::draw_gradient_bg();
1063  mode_ortho_done();
1064 
1065  // ACCEPTED BOX -- INITIALIZATION
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 );
1070  mode_ortho_start();
1071  protocols::viewer::draw_gradient_bg();
1072  mode_ortho_done();
1073 
1074  if ( native_exists ) {
1075  // LOW ENERGY BOX (SMALL) -- INITIALIZATION
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 );
1080  mode_ortho_start();
1081  protocols::viewer::draw_gradient_bg();
1082  mode_ortho_done();
1083  // NATIVE BOX (SMALL) -- INITIALIZATION
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 );
1088  mode_ortho_start();
1089  protocols::viewer::draw_gradient_bg();
1090  mode_ortho_done();
1091  } else {
1092  // LOW ENERGY BOX (LARGE WITHOUT NATIVE) -- INITIALIZATION
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 );
1097  mode_ortho_start();
1098  protocols::viewer::draw_gradient_bg();
1099  mode_ortho_done();
1100  }
1101 
1102  using namespace graphics;
1103  using namespace protocols::viewer;
1104 
1105 
1106  // change view_type randomly
1107  if ( randomly_cycle_appearance ) {
1108  if ( (time(NULL) - last_time_graphic_switch) > 100 ) {
1109  last_time_graphic_switch = time(NULL);
1110 
1111  if ( rand() % 2 == 0 ) current_gs.BBdisplay_state = SHOW_CARTOON;
1112  else current_gs.BBdisplay_state = SHOW_BACKBONE;
1113 
1114  if ( rand() % 3 == 0 && max_pose_nres < 500 ) current_gs.SCdisplay_state = SHOW_STICK;
1115  else current_gs.SCdisplay_state = SHOW_NOSC;
1116 
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;
1123  } else {
1124  current_gs.Color_mode = RAINBOW_COLOR;
1125  }
1126  }
1127  }
1128 
1129  mode_ortho_done();
1130  // do slow changes
1131  float slowrotate = 0.8;
1132  glMatrixMode(GL_MODELVIEW);
1133  glLoadIdentity();
1134  glRotatef(slowrotate,0,1,0.0);
1135  glMultMatrixf(graphics::nativerotation);
1136  glGetFloatv(GL_MODELVIEW_MATRIX, graphics::nativerotation); // Store current model view in decoyrotation
1137  glMatrixMode(GL_MODELVIEW);
1138  glLoadIdentity();
1139  glRotatef(slowrotate,0,1,0.0);
1140  glMultMatrixf(graphics::bestrotation);
1141  glGetFloatv(GL_MODELVIEW_MATRIX, graphics::bestrotation); // Store current model view in decoyrotation
1142  glMatrixMode(GL_MODELVIEW);
1143  glLoadIdentity();
1144  glRotatef(slowrotate,0,1,0.0);
1145  glMultMatrixf(graphics::currentrotation);
1146  glGetFloatv(GL_MODELVIEW_MATRIX, graphics::currentrotation); // Store current model view in decoyrotation
1147  glMatrixMode(GL_MODELVIEW);
1148  glLoadIdentity();
1149  glRotatef(slowrotate,0,1,0.0);
1150  glMultMatrixf(graphics::lowrotation);
1151  glGetFloatv(GL_MODELVIEW_MATRIX, graphics::lowrotation); // Store current model view in decoyrotation
1152 
1153  // SEARCHING BOX
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 );
1158  Structure_display(CURRENT, window_size);
1159  mode_ortho_start();
1160  glColor3f( 0.5f, 0.5f, 0.5f );
1161  writeStrokeString( "Searching...", default_structure_text_color, 0.0f, 0.0f, 280);
1162  mode_ortho_done();
1163 
1164  // ACCEPTED BOX
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 );
1169  Structure_display(ACCEPTED, window_size);
1170  mode_ortho_start();
1171  glColor3f( 0.5f, 0.5f, 0.5f );
1172  writeStrokeString( "Accepted", default_structure_text_color, 0.0f, 0.0f, 280);
1173  mode_ortho_done();
1174 
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;
1179  rms_max += 1.00;
1180  rms_min -= 0.20;
1181  if ( rms_min < 1 ) rms_min = 0.01;
1182 
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];
1186  }
1187  float energy_max = energy_min;
1188  get_bounds( last_accepted_energy_vector, energy_min, energy_max );
1189  energy_max += 10.00;
1190  energy_min -= 1.00;
1191 
1192  if ( native_exists ) {
1193 
1194  // LOW ENERGY BOX (SMALL)
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 );
1199  Structure_display(LOW, window_size);
1200  mode_ortho_start();
1201  glColor3f( 0.5f, 0.5f, 0.5f );
1202  writeStrokeString( "Low Energy", default_structure_text_color, 0.0f, 0.0f, 200);
1203  mode_ortho_done();
1204 
1205  // NATIVE BOX (SMALL)
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);
1211  mode_ortho_start();
1212  glColor3f( 0.5f, 0.5f, 0.5f );
1213  writeStrokeString( "Native", default_structure_text_color, 0.0f, 0.0f, 200);
1214  mode_ortho_done();
1215 
1216  // RMSD TIME SERIES GRAPH BOX
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 );
1219  mode_ortho_start();
1220  writeStrokeString( "RMSD", default_structure_text_color, 0.0f, 0.0f, 180 );
1221  mode_ortho_done();
1222  } else {
1223 
1224  // LOW ENERGY BOX (LARGE WITHOUT NATIVE)
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 );
1229  Structure_display(LOW, window_size);
1230  mode_ortho_start();
1231  writeStrokeString( "Low Energy", default_structure_text_color, 0.0f, 0.0f, 280);
1232  mode_ortho_done();
1233  }
1234 
1235  // ENERGY TIME SERIES GRAPH BOX
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 );
1238  mode_ortho_start();
1239  writeStrokeString( "Accepted Energy", default_structure_text_color, 0.0f, 0.0f, 250 );
1240  mode_ortho_done();
1241 
1242  // ENERGY VS RMSD 2D PLOT
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 );
1246  }
1247 
1248 
1249  glFlush();
1250 }
1251 
1252 // BOINC GRAPHICS API
1253 // This will be called periodically in the graphics thread. It
1254 // should generate the current graphic. xs and ys are the X and Y
1255 // sizes of the window, and time_of_day is the relative time in
1256 // seconds. The function should return true if it actually drew
1257 // anything. It can refer to the user name, CPU time etc. obtained
1258 // from boinc_get_init_data(). Applications that don't do graphics
1259 // must also supply a dummy app_graphics_render() to link with the
1260 // API.
1261 void app_graphics_render(int xs, int ys, double) { draw_rosetta_screensaver( xs, ys ); }
1262 
1263 #if _MSC_VER >= 1400
1264 void
1265 RosettaInvalidParameterHandler(
1266  const wchar_t* expression,
1267  const wchar_t* function,
1268  const wchar_t* file,
1269  unsigned int line,
1270  uintptr_t pReserved
1271 )
1272 {
1273  fprintf(
1274  stderr,
1275  "Invalid parameter detected in function %s. File: %s Line: %d\n",
1276  function,
1277  file,
1278  line
1279  );
1280  fprintf(
1281  stderr,
1282  "Expression: %s\n",
1283  expression
1284  );
1285  DebugBreak();
1286 }
1287 #endif
1288 
1289 
1290 int main(int argc, char** argv) {
1291  try {
1292 
1293  using namespace graphics;
1294  using namespace basic::options;
1295  using namespace basic::options::OptionKeys;
1296  std::cerr << "Starting graphics.." << std::endl;
1297  // new boinc client specific options
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 );
1303 
1304 #ifdef _DEBUG
1305  // DIAGNOSTICS
1306  // http://boinc.berkeley.edu/trac/wiki/DiagnosticsApi
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
1314  );
1315 #else
1316  boinc_init_graphics_diagnostics(BOINC_DIAG_DEFAULTS);
1317 #endif
1318 
1319 
1320  // FROM rosetta++ main.cc
1321 #if _MSC_VER >= 1400
1322  // Every once and awhile something looks at a std::vector or some other
1323  // CRT/STL construct that throws an exception. In this case we should
1324  // dump whatever information we can and then bail. When we bail we
1325  // should dump as much data as possible.
1326  _set_invalid_parameter_handler(RosettaInvalidParameterHandler);
1327 #endif
1328 
1329 
1330 #ifdef __APPLE__
1331  // mac icon
1332  setMacIcon(argv[0], MacAppIconData, sizeof(MacAppIconData));
1333 #endif
1334 
1335  // create boinc object
1336  /*protocols::boinc::Boinc boinc_wu =*/ protocols::boinc::Boinc::instance();
1337 
1338  core::init::init( argc, argv );
1339 
1340  // avoid having to create the static protocol movers
1341  //protocols::init::init( argc, argv );
1342 
1343  // override database option and set to current directory
1344  option[in::path::database].value("minirosetta_database");
1345 #ifndef _DEBUG
1346  option[out::mute].value("all");
1347 #endif
1348  // BOINC GRAPHICS!
1349  // get BOINC app init data - user, team, etc. info
1350  boinc_parse_init_data_file();
1351  boinc_get_init_data(app_init_data);
1352 
1353  nativeposeOP = core::pose::PoseOP( new core::pose::Pose() );
1354  currentposeOP = core::pose::PoseOP( new core::pose::Pose() );
1355  currentposeghostOP = core::pose::PoseOP( new core::pose::Pose() );
1356  lowenergyposeOP = core::pose::PoseOP( new core::pose::Pose() );
1357  lastacceptedposeOP = core::pose::PoseOP( new core::pose::Pose() );
1358 
1359  boinc_graphics_loop(argc, argv);
1360 
1361 #ifdef _DEBUG
1362  boinc_finish_diag();
1363 #endif
1364  } catch ( utility::excn::EXCN_Base const & e ) {
1365  std::cout << "caught exception " << e.msg() << std::endl;
1366  return -1;
1367  }
1368 }
1369 
1370 #else // BOINC_GRAPHICS!
1371 
1372 #include <iostream>
1373 
1374 int main(int /*argc*/, char** /*argv*/) {
1375  std::cout << "Build with boinc api (scons extras=boinc,static)!" << std::endl;
1376  return -1;
1377 }
1378 
1379 #endif
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
static T min(T x, T y)
Definition: Svm.cc:16
int main(int, char **)
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
unsigned long int uintptr_t
Definition: types.hh:28
dictionary size
Definition: amino_acids.py:44
cmplx w(cmplx z, double relerr)
Definition: functions.cc:470
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.
Definition: FArray1.io.hh:35
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
def x
core::pose::Pose Pose
Definition: supercharge.cc:101
double log(double x, double base)
Computes log(x) in the given base.
Definition: util.hh:41
common derived classes for thrown exceptions
char MacAppIconData[]
tuple database
Program exit functions and macros.
utility::keys::lookup::key< KeyType > const key
Tracer IO system.
Input file stream wrapper for uncompressed and compressed files.
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
static char * line
Definition: Svm.cc:2683
DimensionExpressionPow pow(Dimension const &dim1, Dimension const &dim2)
pow( Dimension, Dimension )
std::string F(int const w, int const d, float const &t)
Fixed Point Format: float.
Definition: format.cc:387
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
std::string string_of(Fstring const &s)
string of an Fstring
Definition: Fstring.hh:2889
void init()
set global 'init_was_called' to true
Definition: init.cc:26
Program options global and initialization function.
static T max(T x, T y)
Definition: Svm.cc:19
platform::Size Size
Definition: random.fwd.hh:30
def y
numeric::xyzVector< core::Real > point
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378