UltraScan III
us_mpi_parse.cpp
Go to the documentation of this file.
1 #include "us_mpi_analysis.h"
2 #include "us_math2.h"
3 #include "us_settings.h"
4 #include "mpi.h"
5 
6 // Parse XML routines
7 void US_MPI_Analysis::parse( const QString& xmlfile )
8 {
9  QFile file ( xmlfile );
10 
11  if ( ! file.open( QIODevice::ReadOnly | QIODevice::Text) )
12  {
13  // Fail quietly - can't use udp yet
14  if ( my_rank == 0 ) DbgLv(0) << "Cannot open file " << xmlfile;
15  printf( "Cannot open file %s\n", xmlfile.toAscii().data() );
16  printf( "Aborted" );
17  MPI_Finalize();
18  qApp->exit();
19  }
20 
21  QXmlStreamReader xml( &file );
22 
23  while ( ! xml.atEnd() )
24  {
25  xml.readNext();
26 
27  if ( xml.isStartElement() )
28  {
29  if ( xml.name() == "US_JobSubmit" )
30  {
31  QXmlStreamAttributes a = xml.attributes();
32  analysis_type = a.value( "method" ).toString();
33  }
34 
35  if ( xml.name() == "job" )
36  parse_job( xml );
37 
38  if ( xml.name() == "dataset" )
39  {
41  parse_dataset( xml, d );
42 
43  if ( parameters.contains( "CG_model" ) )
44  { // Flag Custom Grid model input
45  d->model_file = parameters[ "CG_model" ];
46  d->solute_type = 2;
47  attr_x = ATTR_S;
48  attr_y = ATTR_V;
49  attr_z = ATTR_K;
50  }
51 
52  else if ( parameters.contains( "DC_model" ) )
53  { // Flag DMGA_Constraints model input
54  d->model_file = parameters[ "DC_model" ];
55  }
56 
57  else if ( ! parameters[ "ztype" ].isEmpty() )
58  { // Flag generic x,y model with fixed "z"
59  QStringList s_attrs;
60  s_attrs << "s" << "ff0" << "MW" << "vbar" << "D" << "f";
61  attr_x = s_attrs.indexOf( parameters[ "xtype" ] );
62  attr_y = s_attrs.indexOf( parameters[ "ytype" ] );
63  attr_z = s_attrs.indexOf( parameters[ "ztype" ] );
64  attr_x = ( attr_x < 0 ) ? ATTR_S : attr_x;
65  attr_y = ( attr_y < 0 ) ? ATTR_K : attr_y;
66  attr_z = ( attr_z < 0 ) ? ATTR_V : attr_z;
67  // The solute type flag is a number which when viewed as
68  // octal is in the form "01xyz".
69  d->solute_type = ( attr_x << 6 ) + ( attr_y << 3 ) + attr_z;
70  }
71 
72  else if ( parameters[ "ytype" ] == "vbar" )
73  { // Flag s,vbar model with fixed f_f0
74  d->solute_type = 1;
75  attr_x = ATTR_S;
76  attr_y = ATTR_V;
77  attr_z = ATTR_K;
78  }
79 
80  else if ( ! parameters[ "solute_type" ].isEmpty() )
81  { // Flag explicit solute type
82  QString s_styp = parameters[ "solute_type" ];
84  attr_x = ( d->solute_type >> 6 ) & 7;
85  attr_y = ( d->solute_type >> 3 ) & 7;
86  attr_z = d->solute_type & 7;
87  }
88 
89  else
90  { // Flag standard s,k model with fixed vbar
91  d->solute_type = 0;
92  attr_x = ATTR_S;
93  attr_y = ATTR_K;
94  attr_z = ATTR_V;
95 //d->solute_type = (0 << 6) + (1 << 3) + 3;
96  }
97 
98 if (my_rank==0) DbgLv(0) << "PF: solute_type" << d->solute_type
99  << "attr_x _y _z" << attr_x << attr_y << attr_z;
100  data_sets << d;
101  }
102  }
103  }
104 
105  file.close();
106 }
107 
108 void US_MPI_Analysis::parse_job( QXmlStreamReader& xml )
109 {
110  QXmlStreamAttributes attr;
111  QString xname;
112  QString ytype;
113 
114  while ( ! xml.atEnd() )
115  {
116  xml.readNext();
117  xname = xml.name().toString();
118 
119  if ( xml.isEndElement() && xname == "job" ) break;
120 
121  if ( xml.isStartElement() )
122  {
123  attr = xml.attributes();
124 
125  if ( xname == "cluster" )
126  {
127  cluster = attr.value( "shortname" ).toString();
128  }
129 
130  else if ( xname == "name" )
131  {
132  db_name = attr.value( "value" ).toString();
133  }
134 
135  else if ( xname == "udp" )
136  {
137  server = QHostAddress( attr.value( "server" ).toString() );
138  port = (quint16)attr.value( "port" ).toString().toInt();
139  }
140 
141  else if ( xname == "global_fit" )
142  {
143  parameters[ xname ] = attr.value( "value" ).toString();
144  }
145 
146  else if ( xname == "request" )
147  {
148  QString ss;
149  requestID = ss.sprintf( "%06d",
150  attr.value( "id" ).toString().toInt() );
151  requestGUID = attr.value( "guid" ).toString();
152  }
153 
154  else if ( xname == "jobParameters" )
155  {
156  while ( ! xml.atEnd() )
157  {
158  xml.readNext();
159  QString name = xml.name().toString();
160 
161  if ( xml.isEndElement() && name == "jobParameters" ) break;
162 
163  if ( xml.isStartElement() )
164  {
165  attr = xml.attributes();
166 
167  if ( name == "bucket" )
168  { // Get bucket coords; try to forestall round-off problems
169  QString ytyp0 = QString( "ff0" );
170  Bucket b;
171  QString stxmn = attr.value( "x_min" ).toString();
172  QString stxmx = attr.value( "x_max" ).toString();
173  QString stymn = attr.value( "y_min" ).toString();
174  QString stymx = attr.value( "y_max" ).toString();
175  QString stfmn = attr.value( "ff0_min" ).toString();
176  QString stfmx = attr.value( "ff0_max" ).toString();
177  QString stvmn = attr.value( "vbar_min" ).toString();
178  QString stvmx = attr.value( "vbar_max" ).toString();
179  double xmin = stxmn.toDouble();
180  double xmax = stxmx.toDouble();
181  double ymin = stymn.toDouble();
182  double ymax = stymx.toDouble();
183 
184  if ( stxmx.isEmpty() )
185  {
186  xmin = attr.value( "s_min").toString().toDouble();
187  xmax = attr.value( "s_max").toString().toDouble();
188  if ( !stfmx.isEmpty() )
189  {
190  ymin = stfmn.toDouble();
191  ymax = stfmx.toDouble();
192  ytyp0 = QString( "ff0" );
193  }
194  else if ( !stvmx.isEmpty() )
195  {
196  ymin = stvmn.toDouble();
197  ymax = stvmx.toDouble();
198  ytyp0 = QString( "vbar" );
199  }
200  }
201 
202  if ( ytype.isEmpty() )
203  {
204  ytype = ytyp0;
205  parameters[ "ytype" ] = ytype;
206  }
207 
208  // Try to forestall round-off problems
209 if (my_rank==0) DbgLv(0) << "PF: xymnmx" << xmin << xmax << ymin << ymax;
210  int xpwr = (int)qFloor( log10( xmax ) ) - 6;
211  int ypwr = (int)qFloor( log10( ymax ) ) - 6;
212  double xinc = pow( 10.0, xpwr );
213  double yinc = pow( 10.0, ypwr );
214 if (my_rank==0) DbgLv(0) << "PF: xp yp xi yi" << xpwr << ypwr << xinc << yinc;
215  b.x_min = qRound64( xmin / xinc ) * xinc;
216  b.x_max = qRound64( xmax / xinc ) * xinc;
217  b.y_min = qRound64( ymin / yinc ) * yinc;
218  b.y_max = qRound64( ymax / yinc ) * yinc;
219 if (my_rank==0) DbgLv(0) << "PF: rnd xymnmx" << b.x_min << b.x_max << b.y_min << b.y_max;
220 
221  buckets << b;
222  }
223  else if ( name == "CG_model" || name == "DC_model" )
224  {
225  parameters[ name ] = attr.value( "filename").toString();
226 if (my_rank==0) DbgLv(0) << "PF: DC_model" << parameters[name] << name;
227  }
228  else if ( name == "bucket_fixed" )
229  {
230  parameters[ name ] = attr.value( "value" ).toString();
231  parameters[ "xtype" ] = attr.value( "xtype" ).toString();
232  parameters[ "ytype" ] = attr.value( "ytype" ).toString();
233  parameters[ "ztype" ] = attr.value("fixedtype").toString();
234  ytype = parameters[ "ytype" ];
235  }
236 
237  else if ( name.startsWith( "s_m" ) ||
238  name.startsWith( "ff0_m" ) )
239  {
240  QString svalu = attr.value( "value" ).toString();
241  parameters[ name ] = svalu;
242  name = name.replace( "s_m", "x_m" );
243  name = name.replace( "ff0_m", "y_m" );
244  parameters[ name ] = svalu;
245  }
246 
247  else
248  {
249  parameters[ name ] = attr.value( "value" ).toString();
250  }
251  }
252  }
253  }
254  }
255 
256  if ( ! parameters.contains( "z_value" ) )
257  parameters[ "z_value" ] = "0.0";
258 
259  if ( parameters.contains( "debug_level" ) )
260  dbg_level = parameters[ "debug_level" ].toInt();
261 
262  else
263  dbg_level = 0;
264 
265 // US_Settings::set_us_debug( dbg_level );
266  int dbglv = ( my_rank < 2 || my_rank == 15 ) ? dbg_level : 0;
267  US_Settings::set_us_debug( dbglv );
268  dbg_timing = ( parameters.contains( "debug_timings" )
269  && parameters[ "debug_timings" ].toInt() != 0 );
270  }
271 }
272 
273 void US_MPI_Analysis::parse_dataset( QXmlStreamReader& xml,
274  US_SolveSim::DataSet* dataset )
275 {
276  dataset->simparams.speed_step.clear();
277 
278  QXmlStreamAttributes a;
279 
280  while ( ! xml.atEnd() )
281  {
282  xml.readNext();
283  QString name = xml.name().toString();
284 
285  if ( xml.isEndElement() && xml.name() == "dataset" ) return;
286 
287  if ( ! xml.isStartElement() ) continue;
288 
289  if ( xml.name() == "files" )
290  parse_files( xml, dataset );
291 
292  if ( xml.name() == "solution" )
293  parse_solution( xml, dataset );
294 
295  a = xml.attributes();
296  if ( xml.name() == "simpoints" )
297  {
298  dataset->simparams.simpoints
299  = a.value( "value" ).toString().toInt();
300  }
301 
302  if ( xml.name() == "band_volume" )
303  {
304  dataset->simparams.band_volume
305  = a.value( "value" ).toString().toDouble();
306  }
307 
308  if ( xml.name() == "radial_grid" )
309  {
310  dataset->simparams.meshType = (US_SimulationParameters::MeshType)
311  a.value( "value" ).toString().toInt();
312  }
313 
314  if ( xml.name() == "time_grid" )
315  {
316  dataset->simparams.gridType = (US_SimulationParameters::GridType)
317  a.value( "value" ).toString().toInt();
318  }
319 
320  if ( xml.name() == "density" )
321  {
322  dataset->density = a.value( "value" ).toString().toDouble();
323  }
324 
325  if ( xml.name() == "viscosity" )
326  {
327  dataset->viscosity = a.value( "value" ).toString().toDouble();
328  }
329 
330  if ( xml.name() == "compress" )
331  {
332  dataset->compress = a.value( "value" ).toString().toDouble();
333  }
334 
335  if ( xml.name() == "rotor_stretch" )
336  {
337  QStringList stretch =
338  a.value( "value" ).toString().split( " ", QString::SkipEmptyParts );
339 
340  dataset->rotor_stretch[ 0 ] = stretch[ 0 ].toDouble();
341  dataset->rotor_stretch[ 1 ] = stretch[ 1 ].toDouble();
342  }
343 
344  if ( xml.name() == "centerpiece_bottom" )
345  {
346  dataset->centerpiece_bottom
347  = a.value( "value" ).toString().toDouble();
348  }
349 
350  if ( xml.name() == "centerpiece_shape" )
351  {
352  QString shape = a.value( "value" ).toString();
353  QStringList shapes;
354  shapes << "sector"
355  << "standard"
356  << "rectangular"
357  << "band-forming"
358  << "meniscus-matching"
359  << "circular"
360  << "synthetic";
361  dataset->simparams.cp_sector
362  = qMax( 0, shapes.indexOf( shape ) );
363  }
364 
365  if ( xml.name() == "centerpiece_angle" )
366  {
367  dataset->simparams.cp_angle
368  = a.value( "value" ).toString().toDouble();
369  }
370 
371  if ( xml.name() == "centerpiece_pathlength" )
372  {
373  dataset->simparams.cp_pathlen
374  = a.value( "value" ).toString().toDouble();
375  }
376 
377  if ( xml.name() == "centerpiece_width" )
378  {
379  dataset->simparams.cp_width
380  = a.value( "value" ).toString().toDouble();
381  }
382 
383  if ( xml.name() == "speedstep" )
384  {
386 
388 
389  dataset->simparams.speed_step << sp;
390  }
391  }
392 }
393 
394 void US_MPI_Analysis::parse_files( QXmlStreamReader& xml,
395  US_SolveSim::DataSet* dataset )
396 {
397  while ( ! xml.atEnd() )
398  {
399  xml.readNext();
400 
401  if ( xml.isEndElement() && xml.name() == "files" ) break;
402 
403  if ( xml.isStartElement() )
404  {
405  QXmlStreamAttributes a = xml.attributes();
406  QString type = xml.name().toString();
407  QString filename = a.value( "filename" ).toString();
408 
409  if ( type == "auc" ) dataset->auc_file = filename;
410  if ( type == "edit" ) dataset->edit_file = filename;
411  if ( type == "noise" ) dataset->noise_files << filename;
412  }
413  }
414 
415  QString clambda = dataset->edit_file.section( ".", -2, -2 );
416  if ( clambda.contains( "-" ) )
417  { // Modify edit file name for MWL case
418  clambda = clambda + "@" + dataset->auc_file.section( ".", -2, -2 );
419  QString fpart1 = dataset->edit_file.section( ".", 0, -3 );
420  QString fpart2 = dataset->edit_file.section( ".", -1, -1 );
421  dataset->edit_file = fpart1 + "." + clambda + "." + fpart2;
422 if (my_rank==0) DbgLv(0) << "PF: MWL edit_file" << dataset->edit_file;
423  }
424 }
425 
426 void US_MPI_Analysis::parse_solution( QXmlStreamReader& xml,
427  US_SolveSim::DataSet* dataset )
428 {
429  while ( ! xml.atEnd() )
430  {
431  xml.readNext();
432 
433  if ( xml.isEndElement() && xml.name() == "solution" ) break;
434 
435  if ( xml.isStartElement() && xml.name() == "buffer" )
436  {
437  QXmlStreamAttributes a = xml.attributes();
438  dataset->density = a.value( "density" ).toString().toDouble();
439  dataset->viscosity = a.value( "viscosity" ).toString().toDouble();
440  dataset->compress = a.value( "compress" ).toString().toDouble();
441  dataset->manual = a.value( "manual" ).toString().toInt();
442  }
443 
444  if ( xml.isStartElement() && xml.name() == "analyte" )
445  {
447  QXmlStreamAttributes a = xml.attributes();
448 
449  aninfo.analyte.mw = a.value( "mw" ).toString().toDouble();
450  aninfo.analyte.vbar20 = a.value( "vbar20" ).toString().toDouble();
451  aninfo.amount = a.value( "amount" ).toString().toDouble();
452  QString atype = a.value( "type" ).toString();
454  if ( atype == "DNA" )
455  aninfo.analyte.type = US_Analyte::DNA;
456  if ( atype == "RNA" )
457  aninfo.analyte.type = US_Analyte::RNA;
458  if ( atype == "Other" )
460 
461  dataset->solution_rec.analyteInfo << aninfo;
462  }
463  }
464 
465  dataset->vbar20 = US_Math2::calcCommonVbar( dataset->solution_rec, 20.0 );
466 }
467