| 1 | #include "fcvsfo.h" |
| 2 | #include "deprecation.h" |
| 3 | #include "itsme.h" |
| 4 | |
| 5 | FcVsFo::FcVsFo(QString filename,double a,double b, double c, double al, double be, double ga, double lambda){ |
| 6 | const double g2r=180.0/M_PI; |
| 7 | QString theIconPath; |
| 8 | if (!QString(PROGRAM_NAME).compare("shelXle")){ |
| 9 | theIconPath=QString(":/xle-icons/"); |
| 10 | }else{ |
| 11 | theIconPath=QString(":/bicons/"); |
| 12 | } |
| 13 | cell.wave=lambda; |
| 14 | cell.a=a; |
| 15 | cell.b=b; |
| 16 | cell.c=c; |
| 17 | cell.al=al; |
| 18 | cell.be=be; |
| 19 | cell.ga=ga; |
| 20 | cell.cosal = (cos(cell.be / g2r)*cos(cell.ga / g2r)-cos(cell.al / g2r))/(sin(cell.be / g2r)*sin(cell.ga / g2r)); |
| 21 | cell.cosbe = (cos(cell.al / g2r)*cos(cell.ga / g2r)-cos(cell.be / g2r))/(sin(cell.al / g2r)*sin(cell.ga / g2r)); |
| 22 | cell.cosga = (cos(cell.al / g2r)*cos(cell.be / g2r)-cos(cell.ga / g2r))/(sin(cell.be / g2r)*sin(cell.be / g2r)); |
| 23 | cell.singa = sin(cell.ga / g2r); |
| 24 | cell.tanga = tan(cell.ga / g2r); |
| 25 | cell.phi = sqrt(1-(cell.cosal * cell.cosal)- |
| 26 | (cell.cosbe * cell.cosbe)-(cell.cosga * cell.cosga) |
| 27 | +2*cell.cosal * cell.cosbe * cell.cosga); |
| 28 | cell.tau = cell.c *((cell.cosal- cell.cosbe * cell.cosga) / cell.singa); |
| 29 | cell.V = cell.a * cell.b * cell.c*cell.phi; |
| 30 | cell.as = cell.c * cell.b * sin(cell.al / g2r) / cell.V; |
| 31 | cell.bs = cell.c * cell.a * sin(cell.be / g2r) / cell.V; |
| 32 | cell.cs = cell.a * cell.b * cell.singa / cell.V; |
| 33 | if (filename.endsWith(".fcf", Qt::CaseInsensitive)){ |
| 34 | fileName=filename; |
| 35 | }else{ |
| 36 | fileName=filename; |
| 37 | fileName.chop(3); |
| 38 | fileName.append("fcf"); |
| 39 | } |
| 40 | foMax=foMin=fcMax=fcMin=0; |
| 41 | readFCF(); |
| 42 | timer = new QTimer(this); |
| 43 | timer->setSingleShot(true); |
| 44 | connect(timer, SIGNAL(timeout()), this, SLOT(selektiert())); |
| 45 | QHBoxLayout *lh = new QHBoxLayout(this); |
| 46 | QVBoxLayout *lt = new QVBoxLayout(); |
| 47 | QVBoxLayout *lr = new QVBoxLayout(); |
| 48 | brw = new QTextBrowser(this); |
| 49 | brw->setLineWrapMode(QTextEdit::NoWrap); |
| 50 | brw->setHtml("<h1>Selected Reflections</h1>"); |
| 51 | |
| 52 | scene= new GraphSceene(-30,-10,550,530); |
| 53 | scene->setBackgroundBrush(QBrush(QColor("#e9f7d6"))); |
| 54 | scene->clear (); |
| 55 | |
| 56 | // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ; |
| 57 | QGraphicsItem *itm; |
| 58 | for (int i=0; i<51;i++){ |
| 59 | itm=scene->addLine(i*10,0,i*10,500,QPen(QColor("#cbdbbb"),0)); |
| 60 | itm->setData(0,-1); |
| 61 | itm=scene->addLine(0,i*10,500,i*10,QPen(QColor("#cbdbbb"),0)); |
| 62 | itm->setData(0,-1); |
| 63 | } |
| 64 | // scene->addEllipse(50,450,2,2,QPen(Qt::NoPen),QBrush(QColor("#e90706"))); |
| 65 | //double maxx2=-1000,minn2=10000; |
| 66 | //minn2=qMin(foMin*foMin,fcMin*fcMin); |
| 67 | //maxx2=qMax(foMax*foMax,fcMax*fcMax); |
| 68 | double maxx=-1000,minn=10000; |
| 69 | minn=qMin(foMin,fcMin); |
| 70 | maxx=qMax(foMax,fcMax); |
| 71 | //qDebug()<<minn<<maxx<< minn2<<maxx2; |
| 72 | for (int i=0; i<Fo.size(); i++){ |
| 73 | // printf("%g %g\n",(Fo.at(i).F-foMin)/(foMax-foMin)*500,500-(Fc.at(i).F-fcMin)/(fcMax-fcMin)*500); |
| 74 | |
| 75 | //itm=scene->addEllipse(((Fo.at(i).F*Fo.at(i).F)-minn2)/(maxx2-minn2)*500,500-((Fc.at(i).F*Fc.at(i).F)-minn2)/(maxx2-minn2)*500,2,2,QPen(Qt::NoPen),QBrush(QColor("#e90706"))); |
| 76 | //itm->setData(0,i); |
| 77 | itm=scene->addEllipse((Fo.at(i).F-minn)/(maxx-minn)*500,500-(Fc.at(i).F-minn)/(maxx-minn)*500,1.5,1.5,QPen(Qt::NoPen),QBrush(QColor("#0907e6"))); |
| 78 | itm->setData(0,i); |
| 79 | } |
| 80 | diagonale=scene->addLine(0,500,500,0,QColor("#d99999")); |
| 81 | itm->setData(0,-2); |
| 82 | itm=scene->addLine(0,0,3,5,QColor("#000000")); |
| 83 | itm->setData(0,-1); |
| 84 | itm=scene->addLine(0,0,-3,5,QColor("#000000")); |
| 85 | itm->setData(0,-1); |
| 86 | itm=scene->addLine(0,0,0,500,QPen(QColor("#000000"),1.1)); |
| 87 | itm->setData(0,-1); |
| 88 | itm=scene->addLine(500,500,495,503,QColor("#000000")); |
| 89 | itm->setData(0,-1); |
| 90 | itm=scene->addLine(500,500,495,497,QColor("#000000")); |
| 91 | itm->setData(0,-1); |
| 92 | itm=scene->addLine(0,500,500,500,QPen(QColor("#000000"),1.0)); |
| 93 | itm->setData(0,-1); |
| 94 | txt = scene->addText("Fc"); |
| 95 | txt->moveBy(-20,10); |
| 96 | txt->setData(0,-1); |
| 97 | txt2 = scene->addText("Fo"); |
| 98 | txt2->moveBy(480,503); |
| 99 | txt2->setData(0,-1); |
| 100 | QToolBar *tb=new QToolBar(this); |
| 101 | tb-> addAction(QIcon(theIconPath+"zoom-in.svg"),"Zoom +",this,SLOT(zoomin())); |
| 102 | tb-> addAction(QIcon(theIconPath+"zoom-out.svg"),"Zoom -",this,SLOT(zoomout())); |
| 103 | tb-> addAction(QIcon(theIconPath+"zoom-fit.svg"),"Zoom selected",this,SLOT(zoomfit())); |
| 104 | tb-> addAction(QIcon(theIconPath+"zoom-off.svg"),"Zoom out",this,SLOT(zoomoff())); |
| 105 | QComboBox *cbx=new QComboBox(this); |
| 106 | cbx->addItem("Fo vs. Fc",1); |
| 107 | cbx->addItem("Delta( F^2)/sigma vs. sin(theta/lambda)"); |
| 108 | cbx->addItem("Fo / Fc vs. sin(theta/lambda)"); |
| 109 | connect(cbx,SIGNAL(currentIndexChanged(int)),this,SLOT(graphChange(int))); |
| 110 | tb->addWidget(cbx); |
| 111 | view = new QGraphicsView(scene,this); |
| 112 | state = new QLabel("", this); |
| 113 | connect(scene, |
| 114 | SIGNAL(meinstatus(int)), |
| 115 | this, |
| 116 | SLOT(st(int))); |
| 117 | connect(scene, |
| 118 | SIGNAL(listen()), |
| 119 | this, |
| 120 | SLOT(delayMe())); |
| 121 | QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Close); |
| 122 | connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
| 123 | setMouseTracking(true); |
| 124 | //view.show(); |
| 125 | scene->selEckt=scene->addRect(0,0,0,0,Qt::DashLine,QBrush(QColor("#d9e7e6"))); |
| 126 | scene->selEckt-> setOpacity(0.5); |
| 127 | lt->addWidget(view); |
| 128 | lt->addWidget(tb); |
| 129 | lt->addWidget(state); |
| 130 | lt->addWidget(buttonBox); |
| 131 | QPushButton *omit =new QPushButton("Omit reflections",this); |
| 132 | connect(omit, SIGNAL(clicked()), this, SLOT(omitref())); |
| 133 | lr->addWidget(brw); |
| 134 | lr->addWidget(omit); |
| 135 | lh->addLayout(lt); |
| 136 | lh->addLayout(lr); |
| 137 | //setLayout(lh); |
| 138 | // int da= scene->itemAt(50, 50)->data(0).toInt(); |
| 139 | // qDebug()<<Fo.at(da).h<<Fo.at(da).k<<Fo.at(da).l<<Fo.at(da).F<<Fc.at(da).F; |
| 140 | } |
| 141 | |
| 142 | FcVsFo::~FcVsFo(){ |
| 143 | // qDebug()<<"a"; |
| 144 | Fo.clear(); |
| 145 | // qDebug()<<"b"; |
| 146 | Fc.clear(); |
| 147 | // qDebug()<<"c"; |
| 148 | // qDebug()<<"d"; |
| 149 | scene->selected.clear(); |
| 150 | // qDebug()<<"e"; |
| 151 | scene->clear(); |
| 152 | // qDebug()<<"f"; |
| 153 | } |
| 154 | |
| 155 | void FcVsFo::delayMe(){ |
| 156 | if (!timer->isActive()) timer->start(80); |
| 157 | } |
| 158 | |
| 159 | void FcVsFo::zoomin(){ |
| 160 | view->scale(1.05,1.05); |
| 161 | } |
| 162 | |
| 163 | void FcVsFo::zoomout(){ |
| 164 | view->scale(0.95,0.95); |
| 165 | |
| 166 | } |
| 167 | |
| 168 | void FcVsFo::zoomfit(){ |
| 169 | view->fitInView(QRectF(scene->selStart,scene->selEnd),Qt::KeepAspectRatio);//Qt::KeepAspectRatio); |
| 170 | } |
| 171 | |
| 172 | void FcVsFo::zoomoff(){ |
| 173 | view->fitInView(QRectF(-30,-10,550,530),Qt::KeepAspectRatio); |
| 174 | } |
| 175 | |
| 176 | void FcVsFo::readFCF(){ |
| 177 | QFile f(fileName); |
| 178 | listType=0; |
| 179 | f.open(QIODevice::ReadOnly|QIODevice::Text); |
| 180 | // figure out what list type it is... |
| 181 | QString test=QString(f.readLine(120)); |
| 182 | QStringList lines; |
| 183 | if (test.contains("index")) listType=1; |
| 184 | //qDebug()<<test<<test.contains(QRegularExpression("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+")); |
| 185 | if (test.contains(QRegularExpression("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+"))) listType=2; |
| 186 | if (test.contains(QRegularExpression("\\s*\\d+\\s*\\d+\\s*\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+\\s*\\d+\\.\\d+"))) listType=5; |
| 187 | if ((test.startsWith("#"))||(test.startsWith("data"))){ |
| 188 | while (!test.isEmpty()){ |
| 189 | test=QString(f.readLine(120)); |
| 190 | if (test.startsWith("_shelx_refln_list_code")){ |
| 191 | test.remove(0,22); |
| 192 | test=test.trimmed(); |
| 193 | listType=test.toInt(); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | //printf("list type %d \n",listType); |
| 199 | QStringList tok; |
| 200 | Refls obs,cal; |
| 201 | double a,b; |
| 202 | cal.sigma=obs.sigma=0; |
| 203 | switch (listType){ |
| 204 | case 0: |
| 205 | ; |
| 206 | break; |
| 207 | case 1: |
| 208 | f.reset(); |
| 209 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 210 | for (int i=0; i<lines.size(); i++){ |
| 211 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 212 | if (!tok.isEmpty()){ |
| 213 | obs.h=cal.h=tok.at(1).toInt(); |
| 214 | obs.k=cal.k=tok.at(2).toInt(); |
| 215 | obs.l=cal.l=tok.at(3).toInt(); |
| 216 | obs.F=tok.at(5).toDouble(); |
| 217 | cal.F=tok.at(7).toDouble(); |
| 218 | obs.stl=cal.stl= |
| 219 | sqrt( |
| 220 | obs.h*obs.h*cell.as*cell.as+ |
| 221 | obs.k*obs.k*cell.bs*cell.bs+ |
| 222 | obs.l*obs.l*cell.cs*cell.cs+ |
| 223 | 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+ |
| 224 | 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+ |
| 225 | 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0; |
| 226 | |
| 227 | |
| 228 | |
| 229 | obs.phase=cal.phase=tok.at(8).toDouble(); |
| 230 | Fc.append(cal); |
| 231 | Fo.append(obs); |
| 232 | } |
| 233 | } |
| 234 | break; |
| 235 | case 3:{ |
| 236 | f.reset(); |
| 237 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 238 | |
| 239 | int i= 0; |
| 240 | for (int j=0; !j; i++){ |
| 241 | if (lines.at(i).contains("_refln_B_calc")) j++; |
| 242 | } |
| 243 | for (; i<lines.size(); i++){ |
| 244 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 245 | if (!tok.isEmpty()&&(tok.size()==7)){ |
| 246 | obs.h= cal.h=tok.at(0).toInt(); |
| 247 | obs.k= cal.k=tok.at(1).toInt(); |
| 248 | obs.l= cal.l=tok.at(2).toInt(); |
| 249 | obs.F= tok.at(3).toDouble(); |
| 250 | obs.sigma= tok.at(4).toDouble(); |
| 251 | a= tok.at(5).toDouble(); |
| 252 | b= tok.at(6).toDouble(); |
| 253 | cal.F= sqrt(a*a+b*b); |
| 254 | double FF= (b<0)?-1:1; |
| 255 | obs.phase= cal.phase= (cal.F!=0)?FF*acosf(a/cal.F):0; |
| 256 | obs.phase= cal.phase=fmod(4*M_PI+cal.phase,2*M_PI); |
| 257 | obs.stl=cal.stl= |
| 258 | sqrt( |
| 259 | obs.h*obs.h*cell.as*cell.as+ |
| 260 | obs.k*obs.k*cell.bs*cell.bs+ |
| 261 | obs.l*obs.l*cell.cs*cell.cs+ |
| 262 | 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+ |
| 263 | 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+ |
| 264 | 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0; |
| 265 | Fc.append(cal); |
| 266 | Fo.append(obs); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | break; |
| 271 | case 4:{ |
| 272 | f.reset(); |
| 273 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 274 | |
| 275 | int i= 0; |
| 276 | for (int j=0; !j; i++){ |
| 277 | if (lines.at(i).contains("_refln_observed_status")) j++; |
| 278 | } |
| 279 | for (; i<lines.size(); i++){ |
| 280 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 281 | if (!tok.isEmpty()&&(tok.size()==7)){ |
| 282 | obs.h= cal.h=tok.at(0).toInt(); |
| 283 | obs.k= cal.k=tok.at(1).toInt(); |
| 284 | obs.l= cal.l=tok.at(2).toInt(); |
| 285 | obs.F= sqrt(fabs(tok.at(4).toDouble())); |
| 286 | if (tok.at(4).toDouble()<0) obs.F*=-1; |
| 287 | cal.F= sqrt(fabs(tok.at(3).toDouble())); |
| 288 | if (tok.at(3).toDouble()<0) cal.F*=-1; |
| 289 | cal.sigma=obs.sigma=tok.at(5).toDouble(); |
| 290 | obs.stl=cal.stl= |
| 291 | sqrt( |
| 292 | obs.h*obs.h*cell.as*cell.as+ |
| 293 | obs.k*obs.k*cell.bs*cell.bs+ |
| 294 | obs.l*obs.l*cell.cs*cell.cs+ |
| 295 | 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+ |
| 296 | 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+ |
| 297 | 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0; |
| 298 | Fc.append(cal); |
| 299 | Fo.append(obs); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | } |
| 304 | // qDebug()<<"List4 OK"; |
| 305 | break; |
| 306 | case 5:f.reset(); |
| 307 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 308 | for (int i=0; i<lines.size(); i++){ |
| 309 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 310 | if (!tok.isEmpty()&&(tok.size()>5)){ |
| 311 | obs.h=cal.h=tok.at(0).toInt(); |
| 312 | obs.k=cal.k=tok.at(1).toInt(); |
| 313 | obs.l=cal.l=tok.at(2).toInt(); |
| 314 | obs.F=tok.at(3).toDouble(); |
| 315 | cal.F=tok.at(4).toDouble(); |
| 316 | obs.phase=cal.phase=tok.at(5).toDouble(); |
| 317 | obs.stl=cal.stl= |
| 318 | sqrt( |
| 319 | obs.h*obs.h*cell.as*cell.as+ |
| 320 | obs.k*obs.k*cell.bs*cell.bs+ |
| 321 | obs.l*obs.l*cell.cs*cell.cs+ |
| 322 | 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+ |
| 323 | 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+ |
| 324 | 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0; |
| 325 | Fc.append(cal); |
| 326 | Fo.append(obs); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | break; |
| 331 | case 6:{ |
| 332 | f.reset(); |
| 333 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 334 | |
| 335 | int i= 0; |
| 336 | for (int j=0; (!j)&&(i<lines.size()); i++){ |
| 337 | if (lines.at(i).contains("_refln_phase_calc")) j++; |
| 338 | } |
| 339 | // qDebug()<<i<<lines.at(i); |
| 340 | for (; i<lines.size(); i++){ |
| 341 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 342 | if (!tok.isEmpty()&&(tok.size()==7)){ |
| 343 | obs.h= cal.h=tok.at(0).toInt(); |
| 344 | obs.k= cal.k=tok.at(1).toInt(); |
| 345 | obs.l= cal.l=tok.at(2).toInt(); |
| 346 | obs.F= sqrt(fabs(tok.at(3).toDouble())); |
| 347 | cal.sigma=obs.sigma=tok.at(4).toDouble(); |
| 348 | cal.F= tok.at(5).toDouble(); |
| 349 | obs.phase=cal.phase=tok.at(6).toDouble(); |
| 350 | obs.stl=cal.stl= |
| 351 | sqrt( |
| 352 | obs.h*obs.h*cell.as*cell.as+ |
| 353 | obs.k*obs.k*cell.bs*cell.bs+ |
| 354 | obs.l*obs.l*cell.cs*cell.cs+ |
| 355 | 2*obs.h*obs.l*cell.as*cell.cs*cell.cosbe+ |
| 356 | 2*obs.k*obs.l*cell.bs*cell.cs*cell.cosal+ |
| 357 | 2*obs.h*obs.k*cell.as*cell.bs*cell.cosga)/2.0; |
| 358 | Fc.append(cal); |
| 359 | Fo.append(obs); |
| 360 | // printf("%d %d %d %f %f\n",obs.h,obs.k,obs.l,obs.F,cal.F); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | } |
| 365 | // qDebug()<<"List6 OK"; |
| 366 | |
| 367 | break; |
| 368 | case 7:{ |
| 369 | |
| 370 | } |
| 371 | break; |
| 372 | case 8:{ |
| 373 | |
| 374 | f.reset(); |
| 375 | lines=QString(f.readAll()).split(QRegularExpression("[\\r\\n]"),skipEmptyParts); |
| 376 | |
| 377 | int i= 0; |
| 378 | for (int j=0; (!j)&&(i<lines.size()); i++){ |
| 379 | if (lines.at(i).contains("_shelx_refinement_sigma")) j++; |
| 380 | } |
| 381 | // qDebug()<<i<<lines.at(i-1); |
| 382 | for (; i<lines.size(); i++){ |
| 383 | tok=lines.at(i).split(' ',skipEmptyParts); |
| 384 | if (!tok.isEmpty()&&(tok.size()==9)){ |
| 385 | obs.h= cal.h=tok.at(0).toInt(); |
| 386 | obs.k= cal.k=tok.at(1).toInt(); |
| 387 | obs.l= cal.l=tok.at(2).toInt(); |
| 388 | obs.F= sqrt(fabs(tok.at(3).toDouble())); |
| 389 | cal.sigma=obs.sigma=tok.at(4).toDouble(); |
| 390 | cal.F= sqrt(fabs(tok.at(5).toDouble())); |
| 391 | obs.phase=cal.phase=tok.at(6).toDouble(); |
| 392 | obs.stl=cal.stl=1.0/(2.0*tok.at(7).toDouble()); |
| 393 | obs.w=tok.at(8).toDouble(); |
| 394 | Fc.append(cal); |
| 395 | Fo.append(obs); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | break; |
| 400 | default: |
| 401 | break; |
| 402 | |
| 403 | } |
| 404 | // qDebug() << Fo.size() << Fc.size() << Fo.last().F<<Fc.last().F; |
| 405 | f.close(); |
| 406 | foMin=fcMin=1000000; |
| 407 | for (int i=0; i<Fo.size(); i++){ |
| 408 | foMax=qMax(foMax,Fo.at(i).F); |
| 409 | foMin=qMin(foMin,Fo.at(i).F); |
| 410 | fcMax=qMax(fcMax,Fc.at(i).F); |
| 411 | fcMin=qMin(fcMin,Fc.at(i).F); |
| 412 | } |
| 413 | // Fo.clear(); |
| 414 | // Fc.clear(); |
| 415 | // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ; |
| 416 | lines.clear(); |
| 417 | // qDebug()<<"Fo"<<foMin<< foMax<<"Fc "<<fcMin <<fcMax ; |
| 418 | } |
| 419 | |
| 420 | void FcVsFo::omitref(){ |
| 421 | QString omitstr; |
| 422 | for (int i=0; i<scene->selected.size(); i++){ |
| 423 | omitstr.append(QString("OMIT %1 %2 %3\n") |
| 424 | .arg(Fo.at(scene->selected.at(i)).h) |
| 425 | .arg(Fo.at(scene->selected.at(i)).k) |
| 426 | .arg(Fo.at(scene->selected.at(i)).l)); |
| 427 | } |
| 428 | emit weg(omitstr); |
| 429 | } |
| 430 | |
| 431 | void FcVsFo::selektiert(){ |
| 432 | |
| 433 | QString s="<h1>Selected Reflections</h1> <table>" |
| 434 | "<tr><th width=\"30\">h</th>" |
| 435 | "<th width=\"30\">k</th>" |
| 436 | "<th width=\"30\">l</th>" |
| 437 | "<th width=\"70\">Fo<sup>2</sup></th>" |
| 438 | "<th width=\"55\">Fc<sup>2</sup></th>" |
| 439 | "<th width=\"50\">Δ(F<sup>2</sup>)/sigma</th>" |
| 440 | "<th width=\"50\">sigma</th><th width=\"50\">sin(theta)/lambda</th></tr>\n"; |
| 441 | //double wghta=0,wghtb=0; |
| 442 | for (int i=0; i<scene->selected.size(); i++){ |
| 443 | int sel=scene->selected.at(i); |
| 444 | |
| 445 | // Weight = 1 / [ sigma^2(Fo^2) + ( 0.0693 * P )^2 + 0.00 * P ] where P = ( Max ( Fo^2, 0 ) + 2 * Fc^2 ) / 3 |
| 446 | // double P= (qMax(0.0,Fo.at(sel).F*Fo.at(sel).F) + 2.0 * Fc.at(sel).F * Fc.at(sel).F )/3.0; |
| 447 | // double wght=1.0/(Fo.at(sel).sigma + ( wghta * P)*( wghta * P) +wghtb*P); |
| 448 | s.append(QString( |
| 449 | "<tr>" |
| 450 | "<th style=\"text-align: right;\" >%1</th>" |
| 451 | "<th style=\"text-align: right;\" >%2</th>" |
| 452 | "<th style=\"text-align: right;\" >%3</th>" |
| 453 | "<th style=\"text-align: right;\" >%4</th>" |
| 454 | "<th style=\"text-align: right;\" >%5</th>" |
| 455 | "<th style=\"text-align: right;\" >%6</th>" |
| 456 | "<th style=\"text-align: right;\" >%7</th>" |
| 457 | "<th style=\"text-align: right;\" >%8</th></tr>\n") |
| 458 | .arg(Fo.at(sel).h) |
| 459 | .arg(Fo.at(sel).k) |
| 460 | .arg(Fo.at(sel).l) |
| 461 | .arg(Fo.at(sel).F* |
| 462 | Fo.at(sel).F) |
| 463 | .arg(Fc.at(sel).F* |
| 464 | Fc.at(sel).F) |
| 465 | .arg(fabs(Fo.at(sel).F*Fo.at(sel).F- |
| 466 | Fc.at(sel).F*Fc.at(sel).F)/ (Fc.at(sel).sigma)) |
| 467 | .arg(Fc.at(sel).sigma) |
| 468 | .arg(Fc.at(sel).stl)); |
| 469 | //Delta(F^2)/esd Fc/Fc(max) Resolution(A) |
| 470 | // |
| 471 | // qDebug()<<Fo.at(scene->selected.at(i)).h<<Fo.at(scene->selected.at(i)).k<<Fo.at(scene->selected.at(i)).l<<Fo.at(scene->selected.at(i)).F<<Fc.at(scene->selected.at(i)).F; |
| 472 | } |
| 473 | s.append("</table>\n"); |
| 474 | // qDebug()<<s; |
| 475 | brw->setHtml(s); |
| 476 | } |
| 477 | |
| 478 | void FcVsFo::graphChange(int type){ |
| 479 | QList<QGraphicsItem *> drin= scene->items (QRectF(-30,-10,550,530),Qt::ContainsItemShape); |
| 480 | view->hide(); |
| 481 | double maxx=-1000,minn=10000; |
| 482 | minn=qMin(foMin,fcMin); |
| 483 | maxx=qMax(foMax,fcMax); |
| 484 | double maxsintl=0; |
| 485 | switch (type){ |
| 486 | case 1: |
| 487 | { |
| 488 | if (txt2->toPlainText()!="sin(theta)/lambda"){ |
| 489 | txt2->setPlainText("sin(theta)/lambda"); |
| 490 | txt2->moveBy(-100,0); |
| 491 | } |
| 492 | txt->setPlainText("Delta( F^2)/sigma(F^2)"); |
| 493 | maxx=-1000; |
| 494 | minn=10000; |
| 495 | for (int i=0; i<Fo.size(); i++){ |
| 496 | double xx=fabs(Fo.at(i).F*Fo.at(i).F-Fc.at(i).F*Fc.at(i).F)/Fo.at(i).sigma; |
| 497 | minn=qMin(minn,xx); |
| 498 | maxx=qMax(maxx,xx); |
| 499 | // qDebug()<<Fo.at(i).stl<<maxsintl; |
| 500 | maxsintl=qMax(maxsintl,Fo.at(i).stl); |
| 501 | } |
| 502 | } |
| 503 | break; |
| 504 | case 0: |
| 505 | { |
| 506 | txt->setPlainText("Fc"); |
| 507 | txt2->setPlainText("Fo"); |
| 508 | txt2->moveBy(100,0); |
| 509 | } |
| 510 | break; |
| 511 | case 2: |
| 512 | { |
| 513 | if (txt2->toPlainText()!="sin(theta) / lambda"){ |
| 514 | txt2->setPlainText("sin(theta) / lambda"); |
| 515 | txt2->moveBy(-100,0); |
| 516 | } |
| 517 | txt->setPlainText("Fo / Fc"); |
| 518 | maxx=-1000; |
| 519 | minn=10000; |
| 520 | for (int i=0; i<Fo.size(); i++){ |
| 521 | double xx=Fo.at(i).F/Fc.at(i).F; |
| 522 | if ((std_isnormal(xx))&&(xx>0.001)){ |
| 523 | minn=qMin(minn,xx); |
| 524 | maxx=qMax(maxx,xx); |
| 525 | // qDebug()<<Fo.at(i).stl<<maxsintl<<xx; |
| 526 | maxsintl=qMax(maxsintl,Fo.at(i).stl); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | } |
| 531 | break; |
| 532 | } |
| 533 | QRectF ect; |
| 534 | if (type!=0) diagonale->hide(); |
| 535 | else diagonale->show(); |
| 536 | for (int i=0; i<drin.size();i++){ |
| 537 | bool ok=false; |
| 538 | int ix; |
| 539 | ix=drin.at(i)->data(0).toInt(&ok); |
| 540 | ect=drin.at(i)->sceneBoundingRect(); |
| 541 | if ((ix>-1)&&(ok)&&(ix<Fo.size())&&(ix<Fc.size())) { |
| 542 | drin[i]->moveBy(-ect.x(),-ect.y()); |
| 543 | switch (type){ |
| 544 | case 0: |
| 545 | drin[i]->moveBy((Fo.at(ix).F-minn)/(maxx-minn)*500,500-(Fc.at(ix).F-minn)/(maxx-minn)*500); |
| 546 | break; |
| 547 | case 1:{ |
| 548 | double xx=fabs(Fo.at(ix).F*Fo.at(ix).F-Fc.at(ix).F*Fc.at(ix).F)/Fo.at(ix).sigma; |
| 549 | if ((std_isnormal(Fc.at(ix).stl))&&(std_isnormal(xx))){ |
| 550 | // printf("%g %g\n",Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500); |
| 551 | drin[i]->moveBy(Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500); |
| 552 | } |
| 553 | else drin[i]->moveBy(0,500); |
| 554 | } |
| 555 | break; |
| 556 | case 2:{ |
| 557 | double xx=Fo.at(ix).F / Fc.at(ix).F; |
| 558 | if ((std_isnormal(Fc.at(ix).stl))&&(std_isnormal(xx))){ |
| 559 | drin[i]->moveBy(Fc.at(ix).stl/maxsintl*500,500-(xx-minn)/(maxx-minn)*500); |
| 560 | } |
| 561 | else drin[i]->moveBy(0,500); |
| 562 | } |
| 563 | break; |
| 564 | |
| 565 | } |
| 566 | |
| 567 | } |
| 568 | } |
| 569 | view->show(); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | GraphSceene::GraphSceene( qreal x, qreal y, qreal width, qreal height, QObject * parent ) :QGraphicsScene ( x, y, width, height, parent){ |
| 574 | //constructor |
| 575 | } |
| 576 | |
| 577 | void GraphSceene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ){ |
| 578 | qreal x= mouseEvent->scenePos().x(), |
| 579 | y= mouseEvent->scenePos().y(); |
| 580 | // qDebug()<<mouseEvent->buttons()<< mouseEvent->buttonDownScreenPos (Qt::LeftButton); |
| 581 | if (mouseEvent->buttons()&Qt::LeftButton){ |
| 582 | QPointF oli,ure;//oben links , unten rechts |
| 583 | oli.setX(qMin(selStart.x(),selEnd.x())); |
| 584 | oli.setY(qMin(selStart.y(),selEnd.y())); |
| 585 | ure.setX(qMax(selStart.x(),selEnd.x())); |
| 586 | ure.setY(qMax(selStart.y(),selEnd.y())); |
| 587 | QList<QGraphicsItem *> drin= items ( QRectF(oli,ure),Qt::ContainsItemShape); |
| 588 | // qDebug()<<drin.size(); |
| 589 | selected.clear(); |
| 590 | if (drin.size()){ |
| 591 | for (int i=0; i<drin.size();i++){ |
| 592 | bool ok=false; |
| 593 | int ix; |
| 594 | ix=drin.at(i)->data(0).toInt(&ok); |
| 595 | if ((ix>-1)&&(selected.size()<100)&&(ok)) selected.append(ix); |
| 596 | } |
| 597 | emit listen(); |
| 598 | } |
| 599 | selStart = mouseEvent->buttonDownScenePos (Qt::LeftButton); |
| 600 | selEnd = mouseEvent->scenePos(); |
| 601 | //if (selStart!=QPointF(0,0)) selEckt->setRect(QRectF(selStart,selEnd)); |
| 602 | if (selStart!=QPointF(0,0)) selEckt->setRect(QRectF(oli,ure)); |
| 603 | drin.clear(); |
| 604 | // qDebug()<<"End"<<selEnd; |
| 605 | }else{ |
| 606 | // qDebug()<<x<<y; |
| 607 | if (!itemAt(x,y,QTransform())) emit meinstatus(-1); |
| 608 | else{ |
| 609 | int da = itemAt(x,y,QTransform())->data(0).toInt(); |
| 610 | emit meinstatus(da); |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | void GraphSceene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ){ |
| 616 | if (mouseEvent->button()==Qt::LeftButton){ |
| 617 | selEckt->setRect(0,0,0,0); |
| 618 | selected.clear(); |
| 619 | emit listen(); |
| 620 | // qDebug()<<"start"<<selStart; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | |
| 625 | |
| 626 | void FcVsFo::st(int da){ |
| 627 | if (da<0) state->setText(""); |
| 628 | else{ |
| 629 | QString s; |
| 630 | s=QString("%1 %2 %3 Fo=%4 Fc%5 delta(F^2)/sigma(F^2)= %6") |
| 631 | .arg(Fo.at(da).h).arg(Fo.at(da).k).arg(Fo.at(da).l).arg(Fo.at(da).F).arg(Fc.at(da).F) |
| 632 | .arg(fabs(Fo.at(da).F*Fo.at(da).F-Fc.at(da).F*Fc.at(da).F)/Fo.at(da).sigma) |
| 633 | ; |
| 634 | state->setText(s); |
| 635 | } |
| 636 | } |