UltraScan III
us_mlplot.cpp
Go to the documentation of this file.
1 
3 #include "us_mlplot.h"
4 #include "us_pcsa.h"
5 #include "us_settings.h"
6 #include "us_gui_settings.h"
7 #include "us_math2.h"
8 #include "us_zsolute.h"
9 #include "us_colorgradIO.h"
10 
11 #include <qwt_legend.h>
12 #include <qwt_double_interval.h>
13 #include <qwt_scale_widget.h>
14 #include <qwt_color_map.h>
15 #include <qwt_scale_draw.h>
16 
17 // constructor: model lines plot widget
18 US_MLinesPlot::US_MLinesPlot( double& ylo, double& yhi, double& xlo,
19  double& xhi, int& typ, int& nkp, int& nlp, int& bmx )
20  : US_WidgetsDialog( 0, 0 ), ymin( ylo ), ymax( yhi ), xmin( xlo ),
21  xmax( xhi ), ctype( typ ), nkpts( nkp ), nlpts( nlp ), bmndx( bmx )
22 {
23  // lay out the GUI
24  setObjectName( "US_MLinesPlot" );
25  setAttribute( Qt::WA_DeleteOnClose, true );
26  setWindowTitle( tr( "Parametrically Constrained Spectrum Analysis "
27  "Model Lines Viewer" ) );
28  setPalette( US_GuiSettings::frameColor() );
29 
30  QSize p1size( 560, 480 );
31 
33  model = 0;
34  rmsd_best = 0.0;
35  rmsd_worst = 0.0;
36  rmsd_elite = 0.0;
37  rmsd_visib = 0.0;
38 
39  mainLayout = new QHBoxLayout( this );
40  leftLayout = new QVBoxLayout();
41  rightLayout = new QVBoxLayout();
42  pltctrlsLayout = new QGridLayout();
43  buttonsLayout = new QHBoxLayout();
44 
45  mainLayout->setSpacing ( 2 );
46  mainLayout->setContentsMargins( 2, 2, 2, 2 );
47 
48  QLabel* lb_datctrls = us_banner( tr( "PCSA Model Parameters" ) );
49  QLabel* lb_mtype = us_label( tr( "Model Type:" ) );
50  QLabel* lb_nlines = us_label( tr( "Lines (Models):" ) );
51  QLabel* lb_npoints = us_label( tr( "Max Points per Line:" ) );
52  QLabel* lb_varcount = us_label( tr( "Variation Count:" ) );
53  lb_rmsdhd = us_label( tr( "RMSD Cuts" ) );
54  lb_ltypeh = us_label( tr( "Line Type" ) );
55  lb_counth = us_label( tr( "Counts" ) );
56  lb_neline = us_label( tr( "Elite:" ) );
57  lb_nsline = us_label( tr( "Solutes:" ) );
58  lb_nvline = us_label( tr( "Visible:" ) );
59  lb_rmsdb = us_label( tr( "Overall Best Fit:" ) );
60  lb_rmsdw = us_label( tr( "Overall Worst Fit:" ) );
61  pb_colmap = us_pushbutton( tr( "Color Map" ) );
62 
63  QPushButton* pb_help = us_pushbutton( tr( "Help" ) );
64  QPushButton* pb_close = us_pushbutton( tr( "Close" ) );
65 
66  nmodel = ( ctype != CTYPE_HL ) ? ( nkpts * nkpts ) : nkpts;
67  nmodel = ( ctype != CTYPE_ALL ) ? nmodel : nmodel * 3;
68  nmodel = ( ctype != CTYPE_2O ) ? nmodel : nmodel * nkpts;
69  neline = qMax( 2, nmodel / 10 );
70  nsline = qMax( 1, neline / 4 );
71  nvline = nmodel;
72 DbgLv(1) << "RP: nkpts nmodel" << nkpts << nmodel;
73  le_mtype = us_lineedit( tr( "Straight Line" ), -1, true );
74  le_nlines = us_lineedit( QString::number( nmodel ), -1, true );
75  le_npoints = us_lineedit( QString::number( nlpts ), -1, true );
76  le_varcount = us_lineedit( QString::number( nkpts ), -1, true );
77  le_rmsdb = us_lineedit( QString::number( rmsd_best ), -1, true );
78  le_rmsdw = us_lineedit( QString::number( rmsd_worst ), -1, true );
79  le_rmsde = us_lineedit( QString::number( rmsd_elite ), -1, true );
80  le_rmsds = us_lineedit( QString::number( rmsd_solut ), -1, true );
81  le_rmsdv = us_lineedit( QString::number( rmsd_visib ), -1, true );
82  ct_neline = us_counter( 2, 1, nmodel, neline );
83  ct_nsline = us_counter( 2, 1, nmodel, nsline );
84  ct_nvline = us_counter( 2, 1, nmodel, nvline );
85  ct_neline->setStep( 1 );
86  ct_nsline->setStep( 1 );
87  ct_nvline->setStep( 1 );
88  le_colmap = us_lineedit( cmapname, -1, true );
89 
90  // Set the default color map (rainbow)
92 
93  // Adjust the size of line counters and rmsd text
94  lb_nvline->adjustSize();
95  QFont font( US_GuiSettings::fontFamily(),
97  QFontMetrics fmet( font );
98  int fwidth = fmet.maxWidth();
99  int rheight = lb_nvline->height();
100  int cminw = fwidth * ( nmodel < 1000 ? 6 : 7 );
101  int csizw = cminw + fwidth;
102  int tminw = cminw;
103  int tsizw = csizw;
104  ct_neline->resize( csizw, rheight );
105  ct_nsline->resize( csizw, rheight );
106  ct_nvline->resize( csizw, rheight );
107  ct_neline->setMinimumWidth( cminw );
108  ct_nsline->setMinimumWidth( cminw );
109  ct_nvline->setMinimumWidth( cminw );
110  le_rmsde ->resize( tsizw, rheight );
111  le_rmsds ->resize( tsizw, rheight );
112  le_rmsdv ->resize( tsizw, rheight );
113  le_rmsde ->setMinimumWidth( tminw );
114  le_rmsds ->setMinimumWidth( tminw );
115  le_rmsdv ->setMinimumWidth( tminw );
116 DbgLv(1) << "RP: csizw cminw tsizw" << csizw << cminw << tsizw;
117 
118  // Add elements to the controls layout
119  int row = 0;
120  pltctrlsLayout->addWidget( lb_datctrls, row++, 0, 1, 6 );
121  pltctrlsLayout->addWidget( lb_mtype, row, 0, 1, 3 );
122  pltctrlsLayout->addWidget( le_mtype, row++, 3, 1, 3 );
123  pltctrlsLayout->addWidget( lb_nlines, row, 0, 1, 3 );
124  pltctrlsLayout->addWidget( le_nlines, row++, 3, 1, 3 );
125  pltctrlsLayout->addWidget( lb_npoints, row, 0, 1, 3 );
126  pltctrlsLayout->addWidget( le_npoints, row++, 3, 1, 3 );
127  pltctrlsLayout->addWidget( lb_varcount, row, 0, 1, 3 );
128  pltctrlsLayout->addWidget( le_varcount, row++, 3, 1, 3 );
129  pltctrlsLayout->addWidget( lb_ltypeh, row, 0, 1, 2 );
130  pltctrlsLayout->addWidget( lb_counth, row, 2, 1, 2 );
131  pltctrlsLayout->addWidget( lb_rmsdhd, row++, 4, 1, 2 );
132  pltctrlsLayout->addWidget( lb_neline, row, 0, 1, 2 );
133  pltctrlsLayout->addWidget( ct_neline, row, 2, 1, 2 );
134  pltctrlsLayout->addWidget( le_rmsde, row++, 4, 1, 2 );
135  pltctrlsLayout->addWidget( lb_nsline, row, 0, 1, 2 );
136  pltctrlsLayout->addWidget( ct_nsline, row, 2, 1, 2 );
137  pltctrlsLayout->addWidget( le_rmsds, row++, 4, 1, 2 );
138  pltctrlsLayout->addWidget( lb_nvline, row, 0, 1, 2 );
139  pltctrlsLayout->addWidget( ct_nvline, row, 2, 1, 2 );
140  pltctrlsLayout->addWidget( le_rmsdv, row++, 4, 1, 2 );
141  pltctrlsLayout->addWidget( lb_rmsdb, row, 0, 1, 4 );
142  pltctrlsLayout->addWidget( le_rmsdb, row++, 4, 1, 2 );
143  pltctrlsLayout->addWidget( lb_rmsdw, row, 0, 1, 4 );
144  pltctrlsLayout->addWidget( le_rmsdw, row++, 4, 1, 2 );
145  pltctrlsLayout->addWidget( pb_colmap, row, 0, 1, 2 );
146  pltctrlsLayout->addWidget( le_colmap, row++, 2, 1, 4 );
147 // row += 7;
148  QString s_type = tr( "Unknown" );
149  if ( ctype == CTYPE_SL ) s_type = tr( "Straight Line" );
150  else if ( ctype == CTYPE_IS ) s_type = tr( "Increasing Sigmoid" );
151  else if ( ctype == CTYPE_DS ) s_type = tr( "Decreasing Sigmoid" );
152  else if ( ctype == CTYPE_HL ) s_type = tr( "Horizontal Line [C(s)]" );
153  else if ( ctype == CTYPE_ALL ) s_type = tr( "All (SL + IS + DS)" );
154  else if ( ctype == CTYPE_2O ) s_type = tr( "Second-Order Power Law" );
155  le_mtype->setText( s_type );
156 
157  // Hide the color items for now
158  showColorItems( false );
159 
160  buttonsLayout ->addWidget( pb_help );
161  buttonsLayout ->addWidget( pb_close );
162 
163  // Complete layouts and set up signals/slots
165  tr( "Model Lines" ),
166  tr( "Sedimentation Coefficient (x 1e13)" ),
167  tr( "Frictional Ratio (f/f0)" ) );
168 
169  data_plot1->setCanvasBackground( Qt::black );
170  data_plot1->setMinimumSize( p1size );
171 
172  rightLayout->addLayout( plotLayout1 );
173 
174  leftLayout ->addLayout( pltctrlsLayout );
175  leftLayout ->addStretch();
176  leftLayout ->addLayout( buttonsLayout );
177 
178  mainLayout->addLayout( leftLayout );
179  mainLayout->addLayout( rightLayout );
180  mainLayout->setStretchFactor( leftLayout, 3 );
181  mainLayout->setStretchFactor( rightLayout, 5 );
182 
183  connect( ct_neline, SIGNAL( valueChanged ( double ) ),
184  this, SLOT ( updateElite ( double ) ) );
185  connect( ct_nsline, SIGNAL( valueChanged ( double ) ),
186  this, SLOT ( updateSolutes( double ) ) );
187  connect( ct_nvline, SIGNAL( valueChanged ( double ) ),
188  this, SLOT ( updateVisible( double ) ) );
189  connect( pb_colmap, SIGNAL( clicked() ),
190  this, SLOT ( selectColorMap() ) );
191  connect( pb_help, SIGNAL( clicked() ),
192  this, SLOT ( help() ) );
193  connect( pb_close, SIGNAL( clicked() ),
194  this, SLOT ( close_all() ) );
195 
196 DbgLv(1) << "RP: p1size" << p1size;
197  data_plot1->resize( p1size );
198  ct_neline ->resize( rheight, csizw );
199  ct_nsline ->resize( rheight, csizw );
200  ct_nvline ->resize( rheight, csizw );
201  setAttribute( Qt::WA_DeleteOnClose, true );
202  adjustSize();
203 DbgLv(1) << "RP: actual csizw" << ct_nvline->width();
204 }
205 
206 // Close button clicked
208 {
209  close();
210 }
211 
212 // Plot the data
214 {
215  data_plot1->detachItems();
216  data_plot1->clear();
217 
218  bool got_best = ( model != 0 && bmndx >= 0 ); // Got best model?
219 DbgLv(1) << "RP:PD got_best" << got_best << "bmndx" << bmndx;
220 
221  us_grid( data_plot1 );
222 DbgLv(1) << "RP:PD us_grid RTN";
223 
224  QString title;
225  QwtPlotCurve* curv;
226 DbgLv(1) << "RP:PD xmin xmax" << xmin << xmax << "ymin ymax" << ymin << ymax;
227 
228  QVector< double > xvec( nlpts, 0.0 );
229  QVector< double > yvec( nlpts, 0.0 );
230 
231  double* xx = xvec.data();
232  double* yy = yvec.data();
233  int nmodl = mrecs.size();
234  QPen pen_plot( US_GuiSettings::plotCurve(), 1 );
235  int stype = mrecs[ 0 ].stype;
236  int attr_x = ( stype >> 6 ) & 7;
237  int attr_y = ( stype >> 3 ) & 7;
238  int attr_z = stype & 7;
239  double xpscl = ( attr_x == US_ZSolute::ATTR_S ) ? 1.e+13 : 1.0;
240  double ypscl = ( attr_y == US_ZSolute::ATTR_S ) ? 1.e+13 : 1.0;
241 DbgLv(1) << "RP:PD stype" << stype << "attr_x attr_y attr_z"
242  << attr_x << attr_y << attr_z;
243  QString xtitl = tr( "Sedimentation Coefficient (x 1e13)" );
244  QString ytitl = tr( "Frictional Ratio (f/f0)" );
245  xtitl = ( attr_x == US_ZSolute::ATTR_S )
246  ? tr( "Sedimentation Coefficient (x 1e13)" ) : xtitl;
247  xtitl = ( attr_x == US_ZSolute::ATTR_K )
248  ? tr( "Frictional Ratio (f/f0)" ) : xtitl;
249  xtitl = ( attr_x == US_ZSolute::ATTR_W )
250  ? tr( "Molecular Weight (Dalton)" ) : xtitl;
251  xtitl = ( attr_x == US_ZSolute::ATTR_V )
252  ? tr( "Specific Density (vbar_20W)" ) : xtitl;
253  xtitl = ( attr_x == US_ZSolute::ATTR_D )
254  ? tr( "Diffusion Coefficient" ) : xtitl;
255  ytitl = ( attr_y == US_ZSolute::ATTR_S )
256  ? tr( "Sedimentation Coefficient (x 1e13)" ) : ytitl;
257  ytitl = ( attr_y == US_ZSolute::ATTR_K )
258  ? tr( "Frictional Ratio (f/f0)" ) : ytitl;
259  ytitl = ( attr_y == US_ZSolute::ATTR_W )
260  ? tr( "Molecular Weight (Dalton)" ) : ytitl;
261  ytitl = ( attr_y == US_ZSolute::ATTR_V )
262  ? tr( "Specific Density (vbar_20W)" ) : ytitl;
263  ytitl = ( attr_y == US_ZSolute::ATTR_D )
264  ? tr( "Diffusion Coefficient" ) : ytitl;
265 
266 
267  //if ( attr_x == US_ZSolute::ATTR_S )
268  if ( attr_x == US_ZSolute::ATTR_S ||
269  attr_x == US_ZSolute::ATTR_K )
270  {
271  //double xrng = xmax - xmin;
272  //double xinc = xrng < 15.0 ? 1.0 : ( xrng < 50.0 ? 2.0 : 5.0 );
273  //data_plot1->setAxisScale( QwtPlot::xBottom, xmin, xmax, xinc );
274  data_plot1->setAxisScale( QwtPlot::xBottom, xmin, xmax );
275  }
276  else
277  {
278  data_plot1->setAxisAutoScale( QwtPlot::xBottom );
279  }
280 
281  //if ( attr_y == US_ZSolute::ATTR_S )
282  if ( attr_y == US_ZSolute::ATTR_S ||
283  attr_y == US_ZSolute::ATTR_K )
284  {
285  //double yrng = ymax - ymin;
286  //double yinc = yrng < 15.0 ? 1.0 : ( yrng < 50.0 ? 2.0 : 5.0 );
287  //data_plot1->setAxisScale( QwtPlot::yLeft, ymin, ymax, yinc );
288  data_plot1->setAxisScale( QwtPlot::yLeft, ymin, ymax );
289  }
290  else
291  {
292  data_plot1->setAxisAutoScale( QwtPlot::yLeft );
293  }
294 
295  data_plot1->setAxisTitle( QwtPlot::xBottom, xtitl );
296  data_plot1->setAxisTitle( QwtPlot::yLeft, ytitl );
297 DbgLv(1) << "RP:PD got_best" << got_best;
298 DbgLv(1) << "RP:PD nmodel mrecs_size" << nmodel << nmodl;
299 
300  if ( got_best )
301  { // Plot lines after best and sorted model records have been produced
302 DbgLv(1) << "RP:PD mrecs size" << mrecs.size() << nmodl;
303  rmsd_best = mrecs[ 0 ].rmsd; // Get RMSDs
304  rmsd_worst = mrecs[ nmodel - 1 ].rmsd;
305  rmsd_elite = mrecs[ neline - 1 ].rmsd;
306  rmsd_solut = mrecs[ nsline - 1 ].rmsd;
307  rmsd_visib = mrecs[ nvline - 1 ].rmsd;
308  le_rmsdb->setText( QString::number( rmsd_best ) ); // Document RMSDs
309  le_rmsdw->setText( QString::number( rmsd_worst ) );
310  le_rmsde->setText( QString::number( rmsd_elite ) );
311  le_rmsds->setText( QString::number( rmsd_solut ) );
312  le_rmsdv->setText( QString::number( rmsd_visib ) );
313 
314  QFont afont = data_plot1->axisTitle( QwtPlot::yLeft ).font();
315  QwtDoubleInterval cdrange( rmsd_best, rmsd_elite );
316  QwtScaleWidget* rightAxis = data_plot1->axisWidget( QwtPlot::yRight );
317  QwtLinearColorMap revcmap = reverseColorMap();
318 
319  // Set up the right-side axis with the color map
320  rightAxis->setColorBarEnabled( true );
321  rightAxis->setColorMap ( cdrange, revcmap );
322  data_plot1->enableAxis ( QwtPlot::yRight, true );
323  data_plot1->axisTitle ( QwtPlot::yRight ).setFont( afont );
324  data_plot1->setAxisTitle( QwtPlot::yRight, tr( "RMSD" ) );
325  data_plot1->setAxisScale( QwtPlot::yRight, rmsd_best, rmsd_elite );
326 
327  QColor c_white ( Qt::white ); // Color white
328  QColor c_yellow( Qt::yellow ); // Color yellow
329  QColor c_cyan ( Qt::cyan ); // Color cyan
330  QPen pen_best( colormap->color2(), 3 ); // Pen for best line
331  QPen pen_gray( QColor( 64, 64, 64 ), 1 ); // Pen for gray lines
332  int eloffs = neline - 1; // Elite count offset
333  double elrange = (double)eloffs; // Elite line count range
334  int blnx = 0;
335  if ( mrecs[ 1 ].taskx == mrecs[ 0 ].taskx )
336  blnx = 1;
337  if ( mrecs[ 2 ].taskx == mrecs[ 0 ].taskx )
338  blnx = 2;
339 
340  // Determine maximum concentration in models with solutes to display
341  double max_conc = 0.0;
342  for ( int ii = 0; ii < nsline; ii++ )
343  {
344  for ( int kk = 0; kk < mrecs[ ii ].csolutes.size(); kk++ )
345  {
346  max_conc = qMax( max_conc, mrecs[ ii ].csolutes[ kk ].c );
347  }
348  }
349 DbgLv(1) << "RP:PD (4)xmin xmax" << xmin << xmax;
350 
351  // Draw the lines and solute points
352 
353  for ( int ii = ( nmodel - 1 ); ii >= 0; ii-- )
354  { // Loop over model records from worst (highest rmsd) to best
355 
356  // Skip line processing if beyond visible count
357  if ( ii >= nvline )
358  continue;
359 //DbgLv(1) << "RP:PD ii" << ii << "rmsd_rec" << mrecs[ii].rmsd;
360  bool do_curv = true;
361 
362  if ( ii == blnx )
363  { // Best: color with top color and use wider line
364  title = tr( "Best Curve " ) + QString::number( ii );
365  curv = us_curve( data_plot1, title );
366  curv->setPen ( pen_best ); // Red
367  }
368 
369  else if ( ii < neline && ii > blnx )
370  { // Elite: color according to position in elite range
371  title = tr( "Elite Curve " ) + QString::number( ii );
372  curv = us_curve( data_plot1, title );
373  double position = (double)( eloffs - ii ) / elrange;
374  curv->setPen( QPen( positionColor( position ), 2 ) );
375  }
376 
377  else if ( ii > blnx )
378  { // Non-elite: color gray
379  title = tr( "Curve " ) + QString::number( ii );
380  curv = us_curve( data_plot1, title );
381  curv->setPen( pen_gray );
382  }
383 
384  else
385  {
386  do_curv = false;
387  }
388 
389  int klpts = mrecs[ ii ].isolutes.size();
390 
391  if ( ctype == CTYPE_SL || ctype == CTYPE_HL )
392  { // For straight line, just draw from start to end
393  klpts = 2;
394  xx[ 0 ] = xmin;
395  xx[ 1 ] = xmax;
396  yy[ 0 ] = mrecs[ ii ].str_y;
397  yy[ 1 ] = mrecs[ ii ].end_y;
398  }
399 
400  else
401  { // Otherwise, set each point on the curve
402 //DbgLv(1) << "RP:PD nlpts" << nlpts;
403 //DbgLv(1) << "RP:PD isol size" << mrecs[ii].isolutes.size();
404  for ( int kk = 0; kk < klpts; kk++ )
405  {
406  xx[ kk ] = mrecs[ ii ].isolutes[ kk ].x * xpscl;
407  yy[ kk ] = mrecs[ ii ].isolutes[ kk ].y * ypscl;
408  }
409  }
410 
411 //DbgLv(1) << "RP:PD klpts" << klpts;
412  if ( do_curv )
413  curv->setData ( xx, yy, klpts );
414 
415  if ( ii < nsline )
416  { // If within solutes-lines count, plot the solute points
417  int ncomp = mrecs[ ii ].csolutes.size();
418  QColor c_symb = c_white; // Predominant solutes symbol color
419  int szdmin = 2; // and likely minimum size
420  if ( ii == 1 && mrecs[ 1 ].taskx == mrecs[ 0 ].taskx )
421  {
422  c_symb = c_yellow; // Differint symbol color for TR/MC
423  szdmin = 3; // and different minimum size
424  }
425  if ( ii == 2 && mrecs[ 2 ].taskx == mrecs[ 0 ].taskx )
426  {
427  c_symb = c_cyan; // Differint symbol color for TR/MC
428  szdmin = 3; // and different minimum size
429  }
430 
431  for ( int kk = 0; kk < ncomp; kk++ )
432  {
433  double xv = mrecs[ ii ].csolutes[ kk ].x * xpscl;
434  double yv = mrecs[ ii ].csolutes[ kk ].y * ypscl;
435  double cv = mrecs[ ii ].csolutes[ kk ].c;
436  double cfra = cv / max_conc;
437  int szd = qMax( szdmin, qRound( 9.0 * cfra ) );
438  title = tr( "Solute Curve " ) + QString::number( ii )
439  + " Point " + QString::number( kk );
440  curv = us_curve( data_plot1, title );
441  QwtSymbol symbol;
442  symbol.setPen ( c_symb );
443  symbol.setSize ( szd );
444  symbol.setStyle( QwtSymbol::Ellipse );
445  symbol.setBrush( c_symb );
446 
447  curv->setStyle ( QwtPlotCurve::NoCurve );
448  curv->setSymbol( symbol );
449  curv->setData ( &xv, &yv, 1 );
450  }
451 DbgLv(1) << "RP:PD ncomp" << ncomp << "x0 y0 xn yn"
452  << xx[0] << yy[0] << xx[ncomp-1] << yy[ncomp-1];
453  }
454  } // END: models loop
455 DbgLv(1) << "RP:PD (5)xmin xmax" << xmin << xmax;
456  }
457 
458  else
459  { // Plot lines before any best-fit computations
460  for ( int ii = 0; ii < nmodl; ii++ )
461  {
462  for ( int kk = 0; kk < nlpts; kk++ )
463  { // Accumulate the curve points
464  xx[ kk ] = mrecs[ ii ].isolutes[ kk ].x * xpscl;
465  yy[ kk ] = mrecs[ ii ].isolutes[ kk ].y * ypscl;
466  }
467 
468  title = tr( "Curve " ) + QString::number( ii );
469  curv = us_curve( data_plot1, title );
470  curv->setPen ( pen_plot ); // Default color (yellow)
471  curv->setData ( xx, yy, nlpts );
472  } // END: model lines loop
473  } // END: pre-fit lines
474 
475  data_plot1->replot();
476 }
477 
478 // Public slot to set a pointer to a model to use in the plot for highlights
480  QVector< US_ModelRecord >& mrs )
481 {
482  model = a_model;
483  mrecs = mrs;
484 DbgLv(1) << "RP:SM bmndx" << bmndx << "stype" << mrecs[0].stype;
485 
486  // Show or hide the color items based on presence of a model
487  showColorItems( ( model != 0 ) );
488 }
489 
490 // Handle change in elite line count
491 void US_MLinesPlot::updateElite( double value )
492 {
493  neline = (int)value;
494 
495  if ( model != 0 )
496  {
497  rmsd_elite = mrecs[ neline - 1 ].rmsd;
498  le_rmsde->setText( QString::number( rmsd_elite ) );
499  plot_data();
500  }
501 }
502 
503 // Handle change in solutes line count
504 void US_MLinesPlot::updateSolutes( double value )
505 {
506  nsline = (int)value;
507 
508  if ( model != 0 )
509  {
510  rmsd_solut = mrecs[ nsline - 1 ].rmsd;
511  le_rmsds->setText( QString::number( rmsd_solut ) );
512  plot_data();
513  }
514 }
515 
516 // Handle change in visible line count
517 void US_MLinesPlot::updateVisible( double value )
518 {
519  nvline = (int)value;
520 
521  if ( model != 0 )
522  {
523  rmsd_visib = mrecs[ nvline - 1 ].rmsd;
524  le_rmsdv->setText( QString::number( rmsd_visib ) );
525  plot_data();
526  }
527 }
528 
529 // Generate the default color map (rainbow)
531 {
532  cmapname = tr( "Default (rainbow)" );
533  le_colmap->setText( cmapname );
534 DbgLv(1) << "dCM: cmapname" << cmapname;
535  colormap = new QwtLinearColorMap( Qt::magenta, Qt::red );
536  colormap->addColorStop( 0.2000, Qt::blue );
537  colormap->addColorStop( 0.4000, Qt::cyan );
538  colormap->addColorStop( 0.6000, Qt::green );
539  colormap->addColorStop( 0.8000, Qt::yellow );
540 DbgLv(1) << "dCM: RTN cmCstopSize" << colormap->colorStops().size();
541 for ( double pos=0.0; pos<=1.0; pos+=0.1 ) {
542 DbgLv(1) << "Color at position" << pos << positionColor( pos ); }
543 }
544 
545 // Generate the colors given relative position
546 QColor US_MLinesPlot::positionColor( double pos )
547 {
548 //DbgLv(1) << "pC: position" << pos;
549  QwtDoubleInterval colorinterv( 0.0, 1.0 );
550  return QColor( colormap->rgb( colorinterv, pos ) );
551 }
552 
553 // Produce a copy of the color map in reverse order for right-side axis
555 {
556  QwtLinearColorMap rcolmap( colormap->color2(), colormap->color1() );
557 
558  QwtDoubleInterval cinterv( 0.0, 1.0 );
559  QVector< double > cstops = colormap->colorStops();
560  int kstops = cstops.size() - 1;
561 
562  for ( int ii = kstops; ii >= 0; ii-- )
563  {
564  double csvalue = cstops[ ii ];
565  QColor mcolor( colormap->rgb( cinterv, csvalue ) );
566 DbgLv(1) << "rCM: pos" << csvalue << "color" << mcolor;
567  rcolmap.addColorStop( 1.0 - csvalue, mcolor );
568  }
569 DbgLv(1) << "rCM: color1" << rcolmap.color1() << "color2" << rcolmap.color2();
570 
571 for ( double pos=0.0; pos<=1.0; pos+=0.2 ) {
572 DbgLv(1) << " CM position" << pos << "InColor" << positionColor( pos )
573  << "RevColor" << QColor(rcolmap.rgb(cinterv,pos)); }
574  return rcolmap;
575 }
576 
577 // Show or hide the color-related GUI items
578 void US_MLinesPlot::showColorItems( bool visible )
579 {
580  lb_ltypeh->setVisible( visible );
581  lb_counth->setVisible( visible );
582  lb_rmsdhd->setVisible( visible );
583  lb_neline->setVisible( visible );
584  lb_nsline->setVisible( visible );
585  lb_nvline->setVisible( visible );
586  lb_rmsdb ->setVisible( visible );
587  lb_rmsdw ->setVisible( visible );
588  le_rmsde ->setVisible( visible );
589  le_rmsds ->setVisible( visible );
590  le_rmsdv ->setVisible( visible );
591  le_rmsdb ->setVisible( visible );
592  le_rmsdw ->setVisible( visible );
593  ct_neline->setVisible( visible );
594  ct_nsline->setVisible( visible );
595  ct_nvline->setVisible( visible );
596  pb_colmap->setVisible( visible );
597  le_colmap->setVisible( visible );
598 }
599 
600 // Select a color map from a file
602 {
603  QString filter = tr( "Color Map files (*cm-*.xml);;"
604  "Any XML files (*.xml);;"
605  "Any files (*)" );
606 
607  // get an xml file name for the color map
608  QString fname = QFileDialog::getOpenFileName( this,
609  tr( "Load Color Map File" ),
610  US_Settings::etcDir(), filter, 0, 0 );
611 
612  if ( fname.isEmpty() )
613  return;
614 
615  // get the map from the file
616  QList< QColor > cmcolors;
617  QList< double > cmvalues;
618 
619  US_ColorGradIO::read_color_steps( fname, cmcolors, cmvalues );
620  colormap = new QwtLinearColorMap( cmcolors.first(), cmcolors.last() );
621 
622  for ( int jj = 1; jj < cmvalues.size() - 1; jj++ )
623  {
624  colormap->addColorStop( cmvalues.at( jj ), cmcolors.at( jj ) );
625  }
626 
627  cmapname = QFileInfo( fname ).baseName().replace( ".xml$", "" );
628  le_colmap->setText( cmapname );
629  plot_data();
630 for ( double pos=0.0; pos<=1.0; pos+=0.1 ) {
631 DbgLv(1) << "Color at position" << pos << positionColor( pos ); }
632 }
633