3 #include <QApplication>
23 int main(
int argc,
char* argv[] )
25 QApplication application( argc, argv );
32 return application.exec();
40 setWindowTitle(
"UltraScan3 Simulation Module" );
55 QGridLayout*
main =
new QGridLayout(
this );
56 main->setSpacing( 2 );
57 main->setContentsMargins ( 2, 2, 2, 2 );
58 main->setColumnStretch( 1, 1 );
60 QBoxLayout* buttonbox =
new QVBoxLayout;
63 connect( pb_new, SIGNAL( clicked() ), SLOT(
new_model() ) );
64 buttonbox->addWidget( pb_new );
75 buttonbox->addLayout( movie );
80 buttonbox->addLayout( lo_svmovie );
86 buttonbox->addLayout( timeCorr );
94 buttonbox->addWidget(
pb_stop );
101 connect( pb_help, SIGNAL( clicked() ), SLOT(
help()) );
102 buttonbox->addWidget( pb_help );
105 buttonbox->addWidget( pb_close );
106 connect( pb_close, SIGNAL( clicked() ), SLOT( close()) );
108 QPalette pa( pb_close->palette() );
110 te_status->setPalette( pa );
111 te_status->setTextBackgroundColor( pa.color( QPalette::Window ) );
112 te_status->setTextColor( pa.color( QPalette::WindowText ) );
113 QFontMetrics fm( te_status->font() );
114 te_status->setMaximumHeight( fm.lineSpacing() * 17 / 2 );
118 buttonbox->addWidget( te_status );
119 buttonbox->addStretch();
121 main->addLayout( buttonbox, 0, 0 );
124 QBoxLayout*
plot =
new QVBoxLayout;
128 tr(
"Radius (cm)" ), tr(
"Concentration" ) );
131 moviePlot->setAxisScale( QwtPlot::yLeft, 0.0, 2.0 );
132 moviePlot->setAxisScale( QwtPlot::xBottom, 5.8, 7.2 );
134 plot->addLayout(
plot1 );
136 QBoxLayout* timeSpeed =
new QHBoxLayout;
138 QLabel* lb_time =
us_label( tr(
"Time( in seconds):" ) );
139 lb_time->setAlignment ( Qt::AlignCenter );
140 timeSpeed->addWidget( lb_time );
145 QLabel* lb_speed =
us_label( tr(
"Current Speed:" ) );
146 lb_speed->setAlignment ( Qt::AlignCenter );
147 timeSpeed->addWidget( lb_speed );
152 plot->addLayout( timeSpeed );
156 tr(
"Radius (cm)" ), tr(
"Concentration" ) );
158 grid2->enableX(
true );
159 grid2->enableY(
true );
160 scanPlot->setMinimumSize( 600, 275);
161 scanPlot->setAxisScale( QwtPlot::yLeft, 0.0, 2.0 );
162 scanPlot->setAxisScale( QwtPlot::xBottom, 5.8, 7.2 );
163 plot->addLayout(
plot2 );
165 QBoxLayout* completion =
new QHBoxLayout;
181 plot->addLayout( completion );
183 main->addLayout( plot, 0, 1 );
189 QString rotor_calibr =
"0";
190 double rpm = 45000.0;
198 bottom = (double)( qRound( bottom * 1000.0 ) ) * 0.001;
199 qDebug() <<
"ASim:InSP: rotor_calibr" << rotor_calibr;
200 qDebug() <<
"ASim:InSP: rpm" << rpm;
236 connect( dialog, SIGNAL( valueChanged(
US_Model ) ),
264 connect( dialog, SIGNAL( valueChanged(
US_Buffer ) ),
268 qApp->processEvents();
284 mtyps <<
"ASTFEM" <<
"CLAVERIE" <<
"MOVING_HAT" <<
"USER" <<
"ASTFVM";
300 int khrs = dmns / 60;
301 dmns -= ( khrs * 60.0 );
307 "Buffer (density/viscosity/compress.):\n %2 / %3 / %4\n"
308 "SimParams (type/duration/scans):\n %5 / %6 h %7 m / %8" )
323 connect( dialog, SIGNAL( complete() ), SLOT(
set_parameters() ) );
358 scanPlot->setAxisAutoScale( QwtPlot::xBottom );
386 for (
int i = 0; i < points; i++ )
396 int terpsize = ( points + 7 ) / 8;
398 for (
int i = 0; i < total_scans; i++ )
409 scan->
rvalues .fill( 0.0, points );
414 double w2t_sum = 0.0;
417 double current_time = 0.0;
419 double increment = 0.0;
433 increment = ( duration - delay ) / (
double)( sp->
scans - 1 );
434 double w2t_inc = increment * w2t;
435 current_time += delay;
436 w2t_sum = ( ii == 0 ) ? ( current_time * w2t ) : w2t_sum;
437 DbgLv(2) <<
"SIM curtime dur incr" << current_time << duration << increment
438 <<
"w2t w2tsum" << w2t << w2t_sum;
440 for (
int jj = 0; jj < sp->
scans; jj++ )
443 scan->
seconds = (double)qRound( current_time );
446 current_time += increment;
449 DbgLv(2) <<
"SIM scan time omega2t" << scan_number << scan->
seconds
453 int j1 = scan_number - sp->
scans;
454 int j2 = scan_number - 1;
483 connect(
astfem_rsa, SIGNAL( new_scan( QVector< double >*,
double* ) ),
485 connect(
astfem_rsa, SIGNAL( current_component(
int ) ),
487 connect(
astfem_rsa, SIGNAL( new_time (
double ) ),
489 connect(
astfem_rsa, SIGNAL( current_speed(
int ) ),
491 connect(
astfem_rsa, SIGNAL( calc_progress(
int ) ),
493 connect(
astfem_rsa, SIGNAL( calc_done(
void ) ),
509 double cmax=-999999.9;
517 for (
int ii=0; ii<nscn; ii++ )
522 if ( ii==0 || (ii+1)==nscn || (ii*2)==nscn )
523 DbgLv(2) <<
" Scan" << ii <<
" Time" << t0 << t1;
524 for (
int jj=0; jj<ncvl; jj++ )
527 if ( cval < cmin ) { ilo=ii; jlo=jj; cmin=cval; }
528 if ( cval > cmax ) { ihi=ii; jhi=jj; cmax=cval; }
529 if ( ii==0 || (ii+1)==nscn || (ii*2)==nscn )
531 if ( jj<10 || (jj+11)>ncvl ||
532 ((jj*2)>(ncvl-10)&&(jj*2)<(ncvl+11)) )
533 DbgLv(2) <<
" C index value" << jj << cval;
537 DbgLv(1) <<
"SIM data min conc ilo jlo" << cmin << ilo << jlo;
538 DbgLv(1) <<
"SIM data max conc ihi jhi" << cmax << ihi << jhi;
552 connect(
astfvm, SIGNAL( calc_start(
int ) ),
555 connect(
astfvm, SIGNAL( calc_progress(
int ) ),
558 connect(
astfvm, SIGNAL( calc_done(
void ) ),
561 connect(
astfvm, SIGNAL( new_scan( QVector< double >*,
double* ) ),
563 connect(
astfvm, SIGNAL( new_time (
double ) ),
579 QMessageBox::information(
this,
580 tr(
"Non-Ideal Simulation Error" ),
581 tr(
"Unable to create simulation.\n"
582 "Multiple non-ideal conditions exist.\n"
583 "Edit the ambiguous model." ) );
595 double cmax=-999999.9;
602 for (
int ii=0; ii<nscn; ii++ )
607 if ( ii==0 || (ii+1)==nscn || (ii*2)==nscn )
608 DbgLv(2) <<
" Scan" << ii <<
" Time" << t0 << t1
610 for (
int jj=0; jj<npts; jj++ )
613 if ( cval < cmin ) { ilo=ii; jlo=jj; cmin=cval; }
614 if ( cval > cmax ) { ihi=ii; jhi=jj; cmax=cval; }
615 if ( ii==0 || (ii+1)==nscn || (ii*2)==nscn )
617 if ( jj<10 || (jj+11)>npts ||
618 ((jj*2)>(npts-10)&&(jj*2)<(npts+11)) )
619 DbgLv(2) <<
" C index value" << jj << cval;
623 DbgLv(1) <<
"SIM data min conc ilo jlo" << cmin << ilo << jlo;
624 DbgLv(1) <<
"SIM data max conc ihi jhi" << cmax << ihi << jhi;
713 QVector< double > tinoise;
714 tinoise.resize( points );
718 for (
int k = 0; k < points; k++ )
726 for (
int k = 0; k < points; k++ )
741 scanPlot->setAxisAutoScale( QwtPlot::xBottom );
742 scanPlot->setAxisAutoScale( QwtPlot::yLeft );
751 grid2->enableX(
true );
752 grid2->enableY(
true );
759 int* curve =
new int[ scan_count ];
764 x =
new double [ points ];
765 y =
new double* [ scan_count ];
767 for (
int j = 0; j < points; j++ )
770 for (
int j = 0; j < scan_count; j++ )
771 y[ j ] =
new double [ points ];
773 for (
int j = 0; j < scan_count; j++ )
775 for (
int k = 0; k < points; k++ )
779 for (
int j = 0; j < scan_count; j++ )
781 QString title =
"Concentration" + QString::number( j );
782 QwtPlotCurve* plotCurve =
new QwtPlotCurve( title );
784 plotCurve->setData( x, y[ j ], points );
785 plotCurve->setPen( QPen( Qt::yellow ) );
791 for (
int j = 0; j < scan_count; j++ )
delete [] y[ j ];
801 QString fn = QFileDialog::getExistingDirectory(
this,
802 tr(
"Select a directory for the simulated data:" ),
807 if ( ! fn.isEmpty() )
809 fn = fn.replace(
"\\",
"/" );
821 int points = (int)( ( brad - mrad ) / grid_res ) + 31;
827 for (
int ii = 0; ii < total_scans; ii++ )
829 for (
int kk = 0; kk < old_points; kk++ )
834 QVector< double > xtmpVec( total_scans );
835 QVector< double > ytmpVec( total_scans );
836 double *xtmp = xtmpVec.data();
837 double *ytmp = ytmpVec.data();
843 for (
int ii = 0; ii < total_scans; ii++ )
851 &correl, total_scans );
853 double timecorr = -intercept / slope;
854 double s20wcorr = -2.0;
857 * omega * omega * s20wcorr;
865 s1plat += ( conc * exp( oterm * sval ) );
868 double dthresh = maxc;
869 DbgLv(1) <<
"Sim:SV: maxc" << maxc <<
"s1plat" << s1plat
870 <<
"dthresh" << dthresh <<
"total_conc" <<
total_conc;
871 double maxrad = brad;
872 s1plat = qMin( s1plat, ( dthresh * 0.5 ) );
873 DbgLv(1) <<
"Sim:SV: reset s1plat" << s1plat;
885 if ( maxc > dthresh )
891 for (
int ii = 0; ii < total_scans; ii++ )
895 for (
int jj = 0; jj < old_points; jj++ )
910 DbgLv(1) <<
"Sim:SV: OD-Limit nchange nmodscn" << nchange << nmodscn
911 <<
"maxc dthresh" << maxc << dthresh;
914 QMessageBox::information(
this,
915 tr(
"OD Values Threshold Limited" ),
916 tr(
"%1 readings in %2 scans were reset\n"
917 "to a threshold value of %3 .\n"
918 "The pre-threshold-limit maximum OD\n"
920 .arg( nchange ).arg( nmodscn ).arg( dthresh ).arg( maxc ) );
924 points = (int)( ( maxrad - mrad ) / grid_res ) + 31;
926 progress->setMaximum( total_scans );
929 QVector< double > tconc_v( points );
930 double* temp_conc = tconc_v.data();
931 double rad = mrad - 30.0 * grid_res;
935 for (
int jj = 0; jj < points; jj++ )
941 for (
int ii = 0; ii < total_scans; ii++ )
945 for (
int jj = 30; jj < points; jj++ )
947 temp_conc[ jj ] = scan->
rvalues[ jj - 30 ];
950 for (
int jj = 0; jj < 30; jj++ )
952 temp_conc[ jj ] = 0.0;
955 temp_conc[ 30 ] = s1plat * 2.0;
957 scan->
rvalues.resize( points );
959 for (
int jj = 0; jj < points; jj++ )
961 scan->
rvalues[ jj ] = temp_conc[ jj ];
974 QString run_id = dirname.section(
"/", -1, -1 );
980 wvlen = ( wvlen < 99 ) ? 123 : wvlen;
981 QString ofname = QString(
"%1/%2.%3.%4.%5.%6.auc" )
982 .arg( dirname ).arg( run_id ).arg( stype ).arg( cell )
983 .arg( schann ).arg( wvlen );
996 if ( component == -1 )
1003 else if ( component < 0 )
1005 progress->setMaximum( -component );
1055 double total_c = 0.0;
1056 double yscale = 0.0;
1064 yscale = total_c * 3.0;
1074 yscale = total_c * 7.0;
1077 moviePlot->setAxisScale( QwtPlot::yLeft, 0, yscale );
1079 moviePlot->setAxisAutoScale( QwtPlot::xBottom );
1081 double* r =
new double [ x->size() ];
1083 for (
int i = 0; i < x->size(); i++ ) r[ i ] = (*x)[ i ];
1085 QwtPlotCurve* curve =
1086 new QwtPlotCurve(
"Scan Number " + QString::number(
curve_count++ ) );
1088 curve->setPen( QPen( Qt::yellow, 3 ) );
1089 curve->setData( r, c, x->size() );
1102 qApp->processEvents();
1114 DbgLv(1) <<
"SIM: update_save_movie" << ckd;
1119 imagedir = QFileDialog::getExistingDirectory(
this,
1120 tr(
"Select or create a movie frames directory" ),
1143 qDebug() <<
"component " << i + 1;
1149 qDebug() <<
"Association vector " << i + 1;
1158 qDebug() <<
"vbar20" << sc.
vbar20;
1159 qDebug() <<
"mw" << sc.
mw;
1160 qDebug() <<
"s" << sc.
s;
1161 qDebug() <<
"D" << sc.
D;
1162 qDebug() <<
"f" << sc.
f;
1163 qDebug() <<
"f_f0" << sc.
f_f0;
1166 qDebug() <<
"sigma" << sc.
sigma;
1167 qDebug() <<
"delta" << sc.
delta;
1168 qDebug() <<
"oligomer" << sc.
oligomer;
1169 qDebug() <<
"shape" << sc.
shape;
1170 qDebug() <<
"name" << sc.
name;
1172 qDebug() <<
"mfem_initial:";
1178 qDebug() <<
"radius list size " << mfem.
radius.size();
1180 qDebug() <<
"concentration list size " << mfem.
concentration.size();
1186 qDebug() <<
"k_d" << as.
k_d;
1187 qDebug() <<
"k_off" << as.
k_off;
1188 qDebug() <<
"rcomps list size " << as.
rcomps.size();
1189 qDebug() <<
"rcomps list " << as.
rcomps;
1190 qDebug() <<
"stoichs list size " << as.
stoichs.size();
1191 qDebug() <<
"stoichs list " << as.
stoichs;
1196 qDebug() <<
"simparams";
1214 qDebug() <<
"firstScanIsConcentration "
1220 qDebug() <<
"speed profile";
1225 qDebug() <<
"scans " << sp.
scans;