Debian Codegraph @

listfile.cpp

raw symbols SCIP
1 #include "listfile.h"
2 #include <QtCore>
3 #include <QTextStream>
4 #include "deprecation.h"
5
6 /*
7 * This file handles the ShelXl lst file during and after the refinement
8 *
9 *
10 L.S.:
11 wR2 = 0.165168 before cycle 1 for 29437 data and 2607 / 2607 parameters
12 GooF = S = 1.509; Restrained GooF = 1.434 for 3259 restraints
13 Mean shift/esd = 0.013 Maximum = 1.375 for U23 C54 at 09:31:33
14 Max. shift = 0.008 A for C54 Max. dU =-0.010 for C54
15 *
16 CGLS:
17 wR2 = 0.165155 before cycle 1 for 29437 data and 2607 / 2607 parameters
18 GooF = S = 1.509; Restrained GooF = 1.434 for 3257 restraints
19 Max. shift = 0.004 A for C54 Max. dU =-0.007 for C54
20 */
21
22 ListFileHandler::ListFileHandler(QString lfpath, QObject *parent) : QObject(parent)
23 {
24 REL_RESTR_CARDS << "SAME"<< "SADI"<< "SIMU"<< "RIGU"<< "ISOR"<< "NCSY"<< "FLAT" << "DELU";
25 my_lstpath = lfpath;
26 //QFileSystemWatcher fw; // The filesystem watcher doesn't work in my windows 8.1
27 //fw.addPath(*my_lstpath); // I am not shure why I added it? It works also without. DK
28 success = false; // turns to true if refinement was a sucess.
29 listfcontent = new QStringList;
30 listfcontent->append(this->loadLst());
31 }
32
33
34 QStringList ListFileHandler::loadLst(){
35 //! Reads the SHELXL lst file from disk
36 //! and returns it as a QStringlist
37 QFile file(my_lstpath);
38 QStringList lstList;
39 if (file.open(QFile::ReadOnly | QFile::Text)) {
40 QTextStream textStream(&file);
41 while (true) {
42 QString line = textStream.readLine();
43 if (line.isNull()) {
44 emit lstFinished();
45 break;
46 }
47 if (line.isEmpty()) {
48 continue;
49 } else {
50 lstList.append(line);
51 }
52 }
53 }
54 file.close();
55 return lstList;
56 }
57
58 QVector<QStringList> ListFileHandler::listfileparser() {
59 /*!
60 Gathers the residuals of the SHELXL lst file.
61 It searches for the final cycle summary and then for " Disagreeable restraints".
62 End is reached with ' Summary of restraints'.
63 Ported from: https://github.com/dkratzert/DSR-db
64
65 Disagreeable restraints before cycle 6
66
67 Observed Target Error Sigma Restraint
68
69 0.1487 0.0400 SAME/SADI O1_1b C2_1b O1_1b C4_1b
70
71 */
72 if (listfcontent->isEmpty()) {
73 QVector<QStringList> dummy;
74 return dummy;
75 }
76 bool disag = false;
77 bool final = false;
78 QVector<QStringList> disargeelist;
79 int num = 0;
80 foreach(QString line, *listfcontent) {
81 QStringList splitline;
82 splitline = line.split(" ", skipEmptyParts);
83 if (splitline.isEmpty()) {
84 continue;
85 }
86 if (splitline[0].startsWith("Observed")) {
87 continue;
88 }
89 if (line.startsWith(" Final Structure Factor")) {
90 final = true;
91 }
92 if (final && line.startsWith(" Disagreeable restraints")) {
93 disag = true;
94 continue;
95 }
96 if (line.startsWith(" Summary of restraints applied")) {
97 final = false;
98 disag = false;
99 }
100 if (line.contains("RIGU")) {
101 continue; // leave out RIGU, it produces too many lines...
102 }
103 if (splitline.size() < 2) continue;
104 if (disag) {
105 // in this case, the desired line is found:
106 disargeelist.append(lineformatter(splitline));
107 num = num+1;
108 if (num > 500) {
109 // Cutting restraints list. Too many bad restraints...
110 return disargeelist;
111 }
112 }
113 }
114 return disargeelist;
115 }
116
117
118 QStringList ListFileHandler::lineformatter(QStringList line) {
119 /*!
120 takes care of some extra things with different restraints. For example
121 RIGU xy should be in one column.
122 Ported from: https://github.com/dkratzert/DSR-db
123 */
124 int num = 0;
125 int pos = 0;
126 foreach(QString i, line) {
127 i = i.replace('/', ' ');
128 if (i[0].isLetter()){
129 pos = num;
130 break;
131 }
132 num += 1;
133 }
134 // remove the part symbol from e.g. F1_2a:
135 /*
136 num = 0;
137 foreach (QString i, line) {
138 line[num] = remove_partsymbol(i);
139 num += 1;
140 } */
141 // joining columns without numbers:
142 QStringList posline = line.mid(pos, -1);
143 QString joinline = posline.join(" ");
144 QStringList newline = line.mid(0, pos);
145 line = newline;
146 line.append(joinline);
147 QString tline = line.join(" ");
148 foreach (QString n, REL_RESTR_CARDS) {
149 if (tline.contains(n, Qt::CaseInsensitive)) {
150 // adding placeholders for empty fields:
151 QStringList nline;
152 nline.append("-");
153 nline.append("-");
154 nline.append(line);
155 return nline;
156 }
157 }
158 return line;
159 }
160
161
162 QString ListFileHandler::table_maker(QVector<QStringList> tabledata) {
163 /*!
164 Builds a html table out of a datalist from the final
165 cycle summary of a shelxl list file.
166 */
167 QStringList table;
168 QString header;
169 QString footer;
170 QString html;
171 table.clear();
172 foreach(QStringList line, tabledata) {
173 table.append(this->row(line));
174 }
175 header = QString(
176 "<body style=\"font-family:SansSerif; font-size:11pt;\">"
177 "<table>"
178 "<tr>"
179 "<td width=60% align=left>"
180 "<b>List of most disagreeable restraints:</b> &nbsp;"
181 "</td>"
182 "<td width=40% align=right>"
183 "</td>"
184 "</tr>"
185 "</table>");
186 footer = "</body>";
187 html = QString(
188 "%1"
189 "<table border=0 cellpadding=0 cellspacing=6 width=100% >"
190 "<tr>"
191 "<td align='center'> Observed </td>"
192 "<td align='center'> Target </td>"
193 "<td align='center'> Error </td>"
194 "<td align='center'> Sigma </td>"
195 "<td align='left'> Restraint </td>"
196 "</tr>"
197 "%2"
198 "</table>"
199 "%3").arg(header, table.join("\n"), footer);
200
201 if(table.isEmpty()) {
202 //return header+empty_data;
203 return QString(header+"All restraint deviations are within their standard deviation.");
204 //return QString("");
205 }
206 return html;
207 }
208
209 QString ListFileHandler::row(QStringList rowdata) {
210 /*!
211 creates a table row for the restraints list.
212 :type rowdata: list
213 */
214 QStringList td;
215 td.clear();
216 QString row = "";
217 QString bgcolor = "";
218 if (rowdata.size() >= 5) {
219 bool ok1 = false;
220 bool ok2 = false;
221 rowdata[2].toFloat(&ok1);
222 rowdata[3].toFloat(&ok2);
223 if (ok1 && ok2) {
224 if (qAbs(rowdata.at(2).toDouble()) > 2.5*rowdata[3].toDouble()) {
225 bgcolor = QString("bgcolor='#ffec99'"); // bgcolor='#FFD100' // yellow
226 }
227 if (qAbs(rowdata.at(2).toDouble()) > 3.5*rowdata[3].toDouble()) {
228 bgcolor = QString("bgcolor='#ff9fac'"); // bgcolor='#FF1030' // red
229 }
230 }
231 }
232 int num = 0;
233 foreach (QString item, rowdata) {
234 bool ok = false;
235 item.toDouble(&ok);
236 if (ok) {
237 // align right for numbers:
238 if (num < 2) {
239 // do not colorize the first two columns:
240 td.append(QString("<td align='right'> %1 </td>").arg(item));
241 } else {
242 td.append(QString("<td align='right' %1> %2 </td>").arg(bgcolor, item));
243 }
244 } else {
245 if (item.startsWith('-')) {
246 // only a minus sign
247 td.append(QString("<td align='center'> %1 </td>").arg(item));
248 } else {
249 if (num < 4) {
250 td.append(QString("<td align='right'> %1 </td>").arg(item));
251 continue;
252 }
253 // align left for words:
254 td.append(QString("<td align='left'> %1 </td>").arg(item));
255 }
256 }
257 num += 1;
258 }
259 if (td.isEmpty()) {
260 row = "<tr> No (disagreeable) restraints found in .lst file. </tr>";
261 } else {
262 row = QString("<tr> %1 </tr>").arg(td.join(""));
263 }
264 td.clear();
265 return row;
266 }
267
268 QString ListFileHandler::restraintsTable() {
269 QString txt;
270 txt.append(table_maker(listfileparser()));
271 return txt;
272 }
273
274 bool ListFileHandler::getSuccess() const {
275 return success;
276 }
277
278 void ListFileHandler::setSuccess(bool value) {
279 success = value;
280 }
281
282 QString ListFileHandler::thetaFromLst() {
283 //! Max. 2-theta = 55.30
284 //! -8 =< h =< 8, -21 =< k =< 21, -21 =< l =< 21, Max. 2-theta = 55.30
285 //! I might need this later
286 QString theta = "";
287 foreach(QString line, *listfcontent) {
288 if (line.contains("Max. 2-theta")) {
289 theta = line.section("theta", 1, 1).split(" ", skipEmptyParts).at(1);
290 }
291 }
292 return theta;
293 }
294
295
296 // ##########################################################################
297
298
299 XLOutputParser::XLOutputParser(QObject *parent) : QObject(parent) {
300 //! Handles the content of the SHELXL list file.
301 //! Methods with "current" in the name return values of the current state
302 //! in the continuously growing SHELXL list file.
303 //! Methods with "final" return the values after successful refinement.
304 //!
305 // The constructor:
306 ls_cycles = 0;
307 listf_data.cmdline = "";
308 listf_data.xlversion = "";
309 listf_data.threads = "";
310 listf_data.procs = "";
311 listf_data.rint = "";
312 listf_data.rsigma = "";
313 listf_data.wr2 = "";
314 listf_data.cycle = "";
315 listf_data.data = "0";
316 listf_data.current_parameters = "0";
317 listf_data.all_parameters = "0";
318 listf_data.curGoof = " ";
319 listf_data.curRGoof = " ";
320 listf_data.R1_4sig = "";
321 listf_data.finalwR2 = "";
322 listf_data.maxshift_esd = "";
323 listf_data.maxshiftfor = "";
324 listf_data.meanshift = "";
325 listf_data.maxshift = "";
326 listf_data.dU = "";
327 listf_data.dUfor = "";
328 listf_data.peak = "";
329 listf_data.hole = "";
330 listf_data.peakpos = "";
331 listf_data.holepos = "";
332 listf_data.peakdist = "";
333 listf_data.holedist = "";
334 listf_data.warning = "";
335 listf_data.warnings.clear();
336 listf_data.time = "";
337
338 rgr.Goof = 0.0;
339 rgr.cycle = 0.0;
340 rgr.dU = 0.0;
341 rgr.dUfor = "";
342 rgr.wR2 = 0.0;
343 rgr.final_wR2 = 0.0;
344 rgr.max_shift_esd_for = "";
345 rgr.maxshift = 0.0;
346 rgr.maxshift_esd = 0.0;
347 rgr.maxshiftfor = "";
348 rgr.meanshift = 0.0;
349 rgr.warnings.clear();
350 rgr.time = 0.0;
351 warnings.clear();
352 }
353
354
355 RGraph XLOutputParser::residualsGraphDisplay() {
356 //! Returns a data structure that collects the values of
357 //! wR2, R1, Goof, ... during refinement to display them as
358 //! a graph.
359 // collect data from each line and append it to RGraph
360 rgr.Goof = listf_data.curGoof.toDouble();
361 rgr.wR2 = listf_data.wr2.toDouble();
362 rgr.maxshift = listf_data.maxshift.toDouble();
363 rgr.meanshift = listf_data.meanshift.toDouble();
364 rgr.cycle = listf_data.cycle.toInt();
365 rgr.final_wR2 = listf_data.finalwR2.toDouble();
366 rgr.warnings = listf_data.warnings;
367 return rgr;
368 }
369
370
371 void XLOutputParser::fillListFileData(QString line) {
372 //! Fills listf_data with data but it is only filled
373 //! if the respective strings contain data
374 QStringList tproc = xl_threads(line);
375 QString cmdline = xl_cmdline(line);
376 QString version = xl_version(line);
377 QStringList rintsig = xl_rint_rsigma(line);
378 QStringList wr2data = xl_current_wr2_data_param(line);
379 QString R1_4sig = xl_final_R1_4sig(line);
380 QString R1_all = xl_final_R1all(line);
381 QString finalwR2 = xl_final_wR2(line);
382 QStringList goofs = xl_current_goof(line);
383 QStringList peakvalues = xl_peak(line);
384 QStringList holevalues = xl_hole(line);
385 //QStringList fgoofs = xl_final_goofs(line);
386 QStringList maxshifts = xl_current_max_shift(line);
387 QStringList meanshifts = xl_current_meanshift_esd(line);
388 xl_collect_warnings(line);
389 QStringList flackvals = xl_flacksvals(line);
390 QString timeval = xl_timeval(line);
391
392 // Only fill listf_data with values if there are any:
393 if (!cmdline.isEmpty()) {
394 listf_data.cmdline = cmdline;
395 }
396 if (!version.isEmpty()) {
397 listf_data.xlversion = version;
398 }
399 if ((!tproc[0].isEmpty()) && (!tproc[1].isEmpty())) {
400 listf_data.threads = tproc[0];
401 listf_data.procs = tproc[1];
402 }
403 if ((!rintsig[0].isEmpty()) && (!rintsig[1].isEmpty())) {
404 listf_data.rint = rintsig[0];
405 listf_data.rsigma = rintsig[1];
406 }
407 if (!wr2data.at(0).isEmpty()) {
408 listf_data.wr2 = wr2data.at(0);
409 }
410 if (!wr2data.at(1).isEmpty()) {
411 emit newLScycle();
412 listf_data.cycle = wr2data.at(1);
413 }
414 if (!wr2data.at(2).isEmpty()) {
415 listf_data.data = wr2data.at(2);
416 }
417 if (!wr2data.at(3).isEmpty()) {
418 listf_data.current_parameters = wr2data.at(3);
419 }
420 if (!wr2data.at(4).isEmpty()) {
421 listf_data.all_parameters = wr2data.at(4);
422 }
423 if (!goofs[0].isEmpty() && !goofs[1].isEmpty()) {
424 listf_data.curGoof = goofs[0];
425 listf_data.curRGoof = goofs[1];
426 }
427 if (!goofs[2].isEmpty()) {
428 listf_data.nrestraints = goofs[2];
429 }
430 if (!R1_4sig.isEmpty()) {
431 listf_data.R1_4sig = R1_4sig;
432 }
433 if (!R1_all.isEmpty()) {
434 listf_data.R1_all = R1_all;
435 }
436 if (!finalwR2.isEmpty()) {
437 listf_data.finalwR2 = finalwR2;
438 }
439 if (!maxshifts[0].isEmpty() && !maxshifts[1].isEmpty()) {
440 //shifts.append(maxshift);
441 //shifts.append(maxshiftfor);
442 //shifts.append(dU);
443 //shifts.append(dUfor);
444 listf_data.maxshift = maxshifts[0];
445 listf_data.maxshiftfor = maxshifts[1];
446 listf_data.dU = maxshifts[2];
447 listf_data.dUfor = maxshifts[3];
448 }
449 if (!meanshifts[0].isEmpty() && !meanshifts[2].isEmpty()) {
450 //shifts.append(meanshift);
451 //shifts.append(maxshift_esd);
452 //shifts.append(max_esd_shiftfor);
453 listf_data.meanshift = meanshifts[0];
454 listf_data.maxshift_esd = meanshifts[1];
455 listf_data.max_shift_esd_for = meanshifts[2];
456 }
457 if (!holevalues[0].isEmpty() && !holevalues[1].isEmpty() && !holevalues[2].isEmpty()
458 && !holevalues[3].isEmpty()) {
459 listf_data.hole = holevalues[0];
460 listf_data.holepos = holevalues[1];
461 listf_data.holedist = holevalues[2];
462 listf_data.holefrom = holevalues[3];
463 }
464 if (!peakvalues[0].isEmpty() && !peakvalues[1].isEmpty() && !peakvalues[2].isEmpty()
465 && !peakvalues[3].isEmpty()) {
466 listf_data.peak = peakvalues[0];
467 listf_data.peakpos = peakvalues[1];
468 listf_data.peakdist = peakvalues[2];
469 listf_data.peakfrom = peakvalues[3];
470 }
471 if (!flackvals[0].isEmpty()) {
472 listf_data.flack = flackvals.at(0);
473 }
474 if (!flackvals[1].isEmpty()) {
475 listf_data.parson = flackvals.at(1);
476 }
477 if (!timeval.isEmpty()) {
478 listf_data.time = timeval;
479 }
480 }
481
482 QString XLOutputParser::residualsTextDisplay(QString &line, int ls_cycles) {
483 //! returns a html string to display the refinement results in a QLabel
484 this->ls_cycles = ls_cycles;
485 fillListFileData(line);
486 QString html_output = "";
487 QString html_final = "";
488 QString wr2line = "";
489 QString shiftyellow = "";
490 QString shift_esd_yellow = "";
491 QString dUyellow = "";
492 QString cycleText = "";
493 QString progressbar = "";
494 float restr_ratio = 0.0;
495 float data_to_param_ratio = 0.0;
496 if (!listf_data.data.isEmpty() && !listf_data.nrestraints.isEmpty() && !listf_data.all_parameters.isEmpty()){
497 restr_ratio = (listf_data.data.toDouble()+listf_data.nrestraints.toInt())/listf_data.all_parameters.toDouble();
498 data_to_param_ratio = listf_data.data.toFloat()/listf_data.all_parameters.toFloat();
499 }
500 if (!listf_data.R1_4sig.isEmpty() && !listf_data.finalwR2.isEmpty()) { // final values:
501 html_final = QString("<tr><td align=right><b><i>wR</i><sub>2</sub> = </b></td> <td><b> %2% </b>(all data) </td>"
502 " <td align=right><b><i>R</i><sub>1</sub></b> [<i>I</i> > 4&sigma;<i>I</i>] = </td> <td><b>%1%</b> (%9% all data)</td></tr>"
503 "<tr><td align=right>Highest peak = </td> <td> %3 e&Aring;<sup>-3</sup> at %4 &Aring; from %7 &nbsp;&nbsp;&nbsp;&nbsp;</td>"
504 " <td align=right>Deepest hole = </td> <td> %5 e&Aring;<sup>-3</sup> at %6 &Aring; from %8 </td></tr>"
505 )
506 .arg(listf_data.R1_4sig.toDouble()*100, 4, 'f', 2, '0') // 1
507 .arg(listf_data.finalwR2.toDouble()*100, 4, 'f', 2, '0') // 2
508 .arg(listf_data.peak) // 3
509 .arg(listf_data.peakdist) // 4
510 .arg(listf_data.hole) // 5
511 .arg(listf_data.holedist) // 6
512 .arg(listf_data.peakfrom) // 7
513 .arg(listf_data.holefrom) // 8
514 .arg(listf_data.R1_all.toDouble()*100, 4, 'f', 2, '0') // 9
515 ;
516 // One of flack or parson exists:
517 if (!listf_data.flack.isEmpty() || !listf_data.parson.isEmpty()) {
518 // both exist:
519 if (!listf_data.flack.isEmpty() && !listf_data.parson.isEmpty()) {
520 wr2line = QString("<tr><td align=right> <b>Flack X </b>= </td> <td> %1 (Parsons' method)</td> <td> </td> </tr> "
521 "<tr><td align=right> </td> <td> %2 (classical fit)</td> <td> </td> </tr>").arg(listf_data.parson).arg(listf_data.flack);
522 }
523 // Only classical exists:
524 if (!listf_data.flack.isEmpty() && listf_data.parson.isEmpty()) {
525 wr2line = QString("<tr><td align=right> <b>Flack X </b>= </td> <td> %1 (classical fit)</td> "
526 "<td> </td> </tr>").arg(listf_data.flack);
527 }
528 // Only Parsons exists:
529 if (!listf_data.parson.isEmpty() && listf_data.flack.isEmpty()){
530 wr2line = QString("<tr><td align=right> <b>Flack X </b>= </td> <td> %1 (Parsons' method)</td> "
531 "<td> </td> </tr>").arg(listf_data.parson);
532 }
533 } else { // no flack parameter:
534 wr2line = ""; // No Table row to prevent empty line
535 }
536 } else { // shelxl is currently runnig:
537 html_final = "";
538 wr2line = QString("<tr><td align=right> <i>wR</i><sub>2</sub> = </td> <td> %7% </td></tr>")
539 .arg(listf_data.wr2.toDouble()*100, 4, 'f', 2);
540 }
541 if (qAbs(listf_data.maxshift.toDouble()) > 0.005) {
542 shiftyellow = QString("bgcolor=#ffec99");
543 }
544 if (qAbs(listf_data.maxshift_esd.toDouble()) > 0.01) {
545 shift_esd_yellow = QString("bgcolor=#ffec99");
546 }
547 if (qAbs(listf_data.dU.toDouble()) > 0.005) {
548 dUyellow = QString("bgcolor=#ffec99");
549 }
550 int repeat = 12;
551 if (listf_data.cycle.toInt() < ls_cycles) {
552 int progress;
553 progress = int((listf_data.cycle.toFloat() / ls_cycles)*10);
554 progressbar = QString("<td bgcolor=#69CB3F >%1</td>").arg(QString("&nbsp;").repeated(repeat)).repeated(progress)
555 +QString("<td bgcolor=#D0D0D0 >%1</td>").arg(QString("&nbsp;").repeated(repeat)).repeated(10-progress);
556 cycleText = QString("<tr><td> <b>Cycle %1 of %2</b> </td></tr>")
557 .arg(listf_data.cycle) // 1
558 .arg(ls_cycles) // 2
559 ;
560 } else {
561 cycleText = QString("<tr><td> <b>Final Cycle of %1</b></td></tr>")
562 .arg(ls_cycles); // 1
563 progressbar = QString("<td bgcolor=#69CB3F>%1</td>").arg(QString("&nbsp;").repeated(repeat)).repeated(10);
564 }
565 html_output = QString(
566 "<body style=\"font-family:SansSerif; font-size:11pt;\">"
567 "<H2>Running SHELXL %1</H2> "
568 "<table cellpadding=3% align=left>"
569 "<tr><td colspan=2 align=left> <table><tr> %2 </tr></table> </td></tr>"
570 "<tr><td> %3 threads on %4 processors </td></tr>"
571 "<tr><td> Using %5 data and %6 of %7 parameters (ratio %8; %11 with restraints) </td></tr>"
572 "<tr><td><i>R</i><sub>int</sub> = %9%, <i>R</i><sub>&sigma;</sub> = %10% </td></tr>"
573 "</table>")
574 .arg(listf_data.xlversion) // 1
575 .arg(progressbar) // 2
576 .arg(listf_data.threads) // 3
577 .arg(listf_data.procs) // 4
578 .arg(listf_data.data) // 5
579 .arg(listf_data.current_parameters) // 6
580 .arg(listf_data.all_parameters) // 7
581 .arg(data_to_param_ratio, 10, 'f', 1) // 8 data/restr. ratio
582 .arg(listf_data.rint.toFloat()*100, 10, 'f', 2) // 9
583 .arg(listf_data.rsigma.toFloat()*100, 10, 'f', 2) // 10
584 .arg(restr_ratio, 10, 'f', 1) // 11 (data+restraints)/parameter
585 ;
586
587 QString maxshift_row = "";
588
589 if (!listf_data.maxshift_esd.isEmpty()) {
590 maxshift_row = QString("<tr><td align=right> Max. shift = </td> <td %1> %2 @ %3 </td> </tr>")
591 .arg(shift_esd_yellow) // 1 color of max shifting param.
592 .arg(listf_data.maxshift_esd) // 2
593 .arg(listf_data.max_shift_esd_for) // 3
594 ;
595 }
596
597 QString xyz_shift_row = "";
598
599 if (!listf_data.maxshift.isEmpty()) {
600 xyz_shift_row = QString("<tr><td align=right> Max. xyz shift = </td> <td %1> %2 &Aring; @ %3 </td>"
601 " <td align=right> Max. &Delta;U = </td> <td %4> %5 @ %6 </td></tr>")
602 .arg(shiftyellow) // 1
603 .arg(listf_data.maxshift) // 2
604 .arg(listf_data.maxshiftfor) // 3
605 .arg(dUyellow) // 4
606 .arg(listf_data.dU) // 5
607 .arg(listf_data.dUfor) // 6
608 ;
609 }
610
611 QString html_output2 = QString("<table cellpadding=2%>"
612 "%1"
613 "%2"
614 "%3"
615 "<tr><td align=right> <i>GooF</i> = </td> <td> %4 </td>"
616 " <td align=right width=18%> Restr. <i>GooF</i> = </td> <td> %5 </td></tr>"
617 "%6"
618 "%7"
619 "</table>"
620 "<table><tr><td bgcolor=#ffec99><b> %8 </b></td></tr></table>"
621 "</body>")
622 .arg(cycleText) // 1
623 .arg(html_final) // 2
624 .arg(wr2line) // 3 //wr2
625 .arg(listf_data.curGoof) // 4
626 .arg(listf_data.curRGoof) // 5
627 .arg(xyz_shift_row) // 6
628 .arg(maxshift_row) // 7
629 .arg(listf_data.warnings.join("<br>")) // 8
630
631 ;
632 if (!listf_data.wr2.isEmpty()) {
633 html_output += html_output2;
634 } else {
635 // In this case, no refinement happened:
636 if (!listf_data.warnings.isEmpty()) {
637 // even if no refinenemt happened, I want to display the warnings:
638 html_output += QString("<table><tr><td bgcolor=#ffec99> %2 </td></tr></table>")
639 .arg(listf_data.warnings.join("<br>"));
640 } else {
641 // no warning, but still waiting for output from SHLEXL:
642 html_output += QString("<b>Waiting for output from SHELXL...</b>");
643 }
644 }
645 if (!listf_data.time.isEmpty() && listf_data.wr2.isEmpty()) {
646 // SHELXL finished regularly (time elapsed output), but no refinement happened (wr2 is empty)
647 html_output += QString("<br><b>SHELXL failed to run! Please inspect the instructions.</b>");
648 }
649 return html_output;
650 }
651
652
653 QString XLOutputParser::xl_version(QString line) {
654 //! Returns the running shelxl version
655 //! " + Copyright(C) George M. Sheldrick 1993-2014 Version 2014/7 +"
656 QRegularExpression versionregex = QRegularExpression("Version\\s+\\d+\\/\\d+");
657 QString version;
658 QStringList linesplit;
659 if (line.contains(versionregex)) {
660 linesplit = line.split(" ", skipEmptyParts);
661 int index = linesplit.indexOf("Version");
662 version = linesplit.at(index+1);
663 }
664 return version;
665 }
666
667 QStringList XLOutputParser::xl_threads(QString line) {
668 //! Returns on how many threads and processors shelxl is running
669 //! "Running 6 threads on 8 processors"
670 QStringList threadproc;
671 QString threads = "";
672 QString processors = "";
673 QStringList linesplit;
674 QRegularExpression tprocregex = QRegularExpression("Running\\s+\\d\\s+threads\\s+on\\s+\\d\\s+processors");
675 if (line.contains(tprocregex)) {
676 linesplit = line.split(" ", skipEmptyParts);
677 threads = linesplit.at(1);
678 processors = linesplit.at(4);
679 }
680 threadproc.append(threads);
681 threadproc.append(processors);
682 return threadproc;
683 }
684
685 QString XLOutputParser::xl_cmdline(QString line) {
686 //! Returns the command line options shelxl was started with
687 //! " Command line parameters: p21c -a50000 -b3000 -c624 -t6"
688 QString cmdline;
689 if (line.contains("Command line parameters:")) {
690 cmdline = line;
691 }
692 return cmdline;
693 }
694
695 QStringList XLOutputParser::xl_current_wr2_data_param(QString line) {
696 //! Returns the number of data (reflections) shelxl is refining against.
697 //! This is without sigma cutoff:
698 //! " wR2 = 0.4016 before cycle 1 for 10786 data and 737 / 737 parameters"
699 //! returns list of [wR2, cycles, data, current_parameters, all_parameters]
700 QStringList linesplit;
701 QString wr2 = "";
702 QString cycle = "";
703 QString data = "";
704 QString current_parameters = "";
705 QString all_parameters = "";
706 QStringList alldata;
707 if (line.contains("wR2") && line.contains("cycle") && line.contains("data")
708 && (line.split(" ", skipEmptyParts).size() >= 12) ) {
709 linesplit = line.split(" ", skipEmptyParts);
710 wr2 = linesplit.at(2);
711 cycle = linesplit.at(5);
712 data = linesplit.at(7);
713 current_parameters = linesplit.at(10);
714 all_parameters = linesplit.at(12);
715 }
716 alldata.append(wr2);
717 alldata.append(cycle);
718 alldata.append(data);
719 alldata.append(current_parameters);
720 alldata.append(all_parameters);
721 return alldata;
722 }
723
724 QStringList XLOutputParser::xl_rint_rsigma(QString line) {
725 //! Returns Rint and Rsigma of the dataset.
726 //! " R(int) = 0.0504 R(sigma) = 0.0585 Friedel opposites merged"
727 //chuebsch: this crashed:
728 //Data: 19 unique, 0 suppressed R(int) = 0.0000 R(sigma) =13.2352
729 //
730 QString rint = "";
731 QString rsigma = "";
732 QStringList linesplit, rvals;
733 QString l=line.remove('=');
734 if (line.contains("R(sigma)")) {
735 linesplit = l.split(" ", skipEmptyParts);
736 int RintInd = linesplit.indexOf(QRegularExpression("R\\(int\\)"));
737 if ((RintInd != -1) && linesplit.length() > RintInd+1) {//>= leads to segmentation fault
738 rint = linesplit.at(RintInd+1);
739 }
740 int RsigInd = linesplit.indexOf(QRegularExpression("R\\(sigma\\)"));
741 if ((RsigInd != -1) && linesplit.length() > RsigInd+1) {//>= leads to segmentation fault
742 rsigma = linesplit.at(RsigInd+1);
743 }//else qDebug()<<linesplit<<RsigInd;
744
745 }
746 rvals.append(rint);
747 rvals.append(rsigma);
748 return rvals;
749 }
750
751 QStringList XLOutputParser::xl_current_goof(QString line) {
752 //! Returns the current Goof of the refinement. This value is
753 //! the last value in the continuesly growing lst file.
754 //! "GooF = S = 4.130; Restrained GooF = 5.432 for 1662 restraints"
755 QString goof;
756 QString rgoof;
757 QString restraints;
758 QStringList linesplit;
759 QStringList goofs;
760 if (line.contains("Restrained GooF") && line.contains("restraints")
761 && (line.split(" ", skipEmptyParts).size() >= 8)) {
762 linesplit = line.split(" ", skipEmptyParts);
763 goof = linesplit.at(4);
764 goof.remove(QChar(';'));
765 rgoof = linesplit.at(8);
766 restraints = linesplit.at(10);
767 }
768 goofs.append(goof);
769 goofs.append(rgoof);
770 goofs.append(restraints);
771 return goofs;
772 }
773
774 QStringList XLOutputParser::xl_final_goofs(QString line) {
775 //! Returns the final Goof after refinement finished.
776 //! "wR2 = 0.2277, GooF = S = 2.275, Restrained GooF = 2.122 for all data"
777 QString goof;
778 QString rgoof;
779 QStringList linesplit;
780 QStringList goofs;
781 if (line.contains("for all data") && (line.split(" ", skipEmptyParts).size() >= 11) ) {
782 linesplit = line.split(" ", skipEmptyParts);
783 goof = linesplit.at(7);
784 goof.remove(QChar(','));
785 rgoof = linesplit.at(11);
786 }
787 goofs.append(goof);
788 goofs.append(rgoof);
789 return goofs;
790 }
791
792
793 QStringList XLOutputParser::xl_current_meanshift_esd(QString line) {
794 //! Returns the current shift per esd.
795 //! "Mean shift/esd = 0.016 Maximum = -8.976 for U11 C6 at 09:36:30
796 QStringList shifts;
797 QString meanshift = "";
798 QString maxshift_esd = "";
799 QString max_esd_shiftfor = "";
800 QStringList linesplit;
801 if (line.contains("shift/esd") && line.contains("Maximum")
802 && (line.split(" ", skipEmptyParts).size() >= 6) ) {
803 linesplit = line.split(" ", skipEmptyParts);
804 meanshift = linesplit.at(3);
805 maxshift_esd = linesplit.at(6);
806 max_esd_shiftfor = line.split("for", skipEmptyParts).at(1).trimmed()
807 .split("at", skipEmptyParts).at(0).trimmed();
808 }
809 shifts.append(meanshift);
810 shifts.append(maxshift_esd);
811 shifts.append(max_esd_shiftfor);
812 return shifts;
813 }
814
815
816 QStringList XLOutputParser::xl_current_max_shift(QString line) {
817 //! Returns the maximum shift during the refinement.
818 //! "Max. shift = 0.000 A for H26C Max. dU =-0.007 for C6"
819 //! "=-0.007 for C6"
820 QString maxshift;
821 QString maxshiftfor;
822 QString dU;
823 QString dUfor;
824 QStringList linesplit;
825 QStringList shifts;
826 if (line.contains("Max. shift") && line.contains("dU") && line.contains("for")
827 && (line.split(" ", skipEmptyParts).size() >= 6) ) {
828 linesplit = line.split(" ", skipEmptyParts);
829 maxshift = linesplit.at(3);
830 maxshiftfor = linesplit.at(6);
831 dU = line.split("dU").at(1).trimmed().remove("=").split(" ", skipEmptyParts).at(0);
832 dUfor = line.split("for").at(2).trimmed();
833 }
834 shifts.append(maxshift);
835 shifts.append(maxshiftfor);
836 shifts.append(dU);
837 shifts.append(dUfor);
838 return shifts;
839 }
840
841
842 QString XLOutputParser::xl_current_warning(QString line) {
843 //! Returns a Warning if there is any in the current line.
844 QRegularExpression warnregexp = QRegularExpression("\\*\\*"); //.*\\*\\*");
845 QString warn = "";
846 if ( line.contains(warnregexp) ) {
847 warn = line.simplified();
848 }
849 return warn;
850 }
851
852 void XLOutputParser::xl_collect_warnings(QString line) {
853 //! Returns all warning that occoured during refinement.
854 QRegularExpression warnregexp = QRegularExpression("\\*\\*"); //.*\\*\\*");
855 if ( line.contains(warnregexp) ) {
856 warnings.append(line.simplified());
857 }
858 if (line.contains("CANNOT OPEN FILE")) {
859 warnings.append(line.simplified());
860 }
861 listf_data.warnings = warnings;
862 rgr.warnings = warnings;
863 }
864
865 QString XLOutputParser::xl_final_R1_4sig(QString line) {
866 // R1 = 0.0401 for 7085 Fo > 4sig(Fo) and 0.0796 for all 10786 data
867 QString r1_4sigma = "";
868 QStringList linesplit;
869 if (line.contains("R1") && line.contains("4sig") && line.contains("for all")) {
870 linesplit = line.split(" ", skipEmptyParts);
871 r1_4sigma = linesplit.at(2);
872 r1_4sigma.remove(QChar(','));
873 }
874 return r1_4sigma;
875 }
876
877 QString XLOutputParser::xl_final_R1all(QString line) {
878 // R1 = 0.0766 for 10786 unique reflections after merging for Fourier
879 QString r1all = "";
880 QStringList linesplit;
881 if (line.contains("R1") && line.contains("merging for Fourier") && line.contains("for")) {
882 linesplit = line.split(" ", skipEmptyParts);
883 r1all = linesplit.at(2);
884 r1all.remove(QChar(','));
885 }
886 return r1all;
887 }
888
889
890 QString XLOutputParser::xl_final_wR2(QString line) {
891 QString finalwr2;
892 QStringList linesplit;
893 if (line.contains("wR2") && line.contains("for all data")) {
894 linesplit = line.split(" ", skipEmptyParts);
895 finalwr2 = linesplit.at(2);
896 finalwr2.remove(QChar(','));
897 }
898 return finalwr2;
899 }
900
901 QStringList XLOutputParser::xl_peak(QString line) {
902 //! Returns a list of the highest peak and the position
903 // Highest peak 8.15 at 0.3160 0.7496 0.4960 [ 1.30 A from F12 ]
904 QStringList values;
905 QString peak = "";
906 QString coord = "";
907 QString dist = "";
908 QString from = "";
909 QStringList linesplit;
910 if (line.contains("Highest peak") && line.contains("from")
911 && (line.split(" ", skipEmptyParts).size() >= 6) ) {
912 linesplit = line.split(" ", skipEmptyParts);
913 peak = linesplit.at(2);
914 coord = linesplit.at(4)+" "+linesplit.at(5)+" "+linesplit.at(6);
915 dist = line.split("[").at(1).split("]").at(0).trimmed().split(" ").at(0);
916 from = line.split("[").at(1).split("]").at(0).trimmed().split(" ").at(3);
917 }
918 values.append(peak);
919 values.append(coord);
920 values.append(dist);
921 values.append(from);
922 return values;
923 }
924
925 QStringList XLOutputParser::xl_hole(QString line) {
926 //! Returns a list of the deepest hole and the position
927 // Deepest hole -0.74 at 0.4337 0.4402 0.7821 [ 0.84 A from GA1 ]
928 QStringList values;
929 QString hole = "";
930 QString coord = "";
931 QString dist = "";
932 QString from = "";
933 QStringList linesplit;
934 if (line.contains("Deepest hole") && line.contains("from")
935 && (line.split(" ", skipEmptyParts).size() >= 12) ) {
936 linesplit = line.split(" ", skipEmptyParts);
937 hole = linesplit.at(2);
938 coord = linesplit.at(4)+" "+linesplit.at(5)+" "+linesplit.at(6);
939 dist = line.split("[").at(1).split("]").at(0).trimmed().split(" ").at(0);
940 from = line.split("[").at(1).split("]").at(0).trimmed().split(" ").at(3);
941 }
942 values.append(hole);
943 values.append(coord);
944 values.append(dist);
945 values.append(from);
946 return values;
947 }
948
949 QStringList XLOutputParser::xl_flacksvals(QString line) {
950 //! Flack x = -0.449(792) by classical fit to all intensities
951 //! Flack x = -0.315(296) from 3107 selected quotients (Parsons' method)
952 QStringList values;
953 QString flack = "";
954 QString parson = "";
955 QStringList linesplit;
956 if (line.contains("Flack x") && line.contains("classical fit")
957 && (!line.contains("No quotients"))
958 && (line.split(" ", skipEmptyParts).size() >= 3) ) {
959 linesplit = line.split(" ", skipEmptyParts);
960 flack = linesplit.at(3);
961 }
962 if (line.contains("Flack x") && line.contains("Parsons' method")
963 && (line.split(" ", skipEmptyParts).size() >= 3) ) {
964 linesplit = line.split(" ", skipEmptyParts);
965 parson = linesplit.at(3);
966
967 }
968 values.append(flack);
969 values.append(parson);
970 return values;
971 }
972
973 QString XLOutputParser::xl_timeval(QString line) {
974 //! + pn_a finished at 12:33:29 Total elapsed time: 0.00 secs +
975 //! returns the elapsed time of a SHELXL run
976 QStringList linesplit;
977 QString time = "";
978 if (line.contains("finished") && line.contains("time")) {
979 linesplit = line.split(" ", skipEmptyParts);
980 time = linesplit.at(linesplit.indexOf("time:")+1);
981 }
982 return time;
983 }