| 1 | #include "rename_selected.h" |
| 2 | |
| 3 | void rename_selected::work(){ |
| 4 | possible=0; |
| 5 | //todo: afix |
| 6 | |
| 7 | //int qda=0; |
| 8 | //CEnvironment qbackup; |
| 9 | for (int i=0; i<_w->chgl->mol->asymm.size(); i++) if (_w->chgl->mol->asymm.at(i).an>=0) possible++; |
| 10 | /*else { |
| 11 | qda++; |
| 12 | qbackup.append(_w->chgl->mol->asymm[i]); |
| 13 | }*/ |
| 14 | //printf("\n\n\nQ %d %d\n\n\n",qda,_w->chgl->mol->asymm.size()); |
| 15 | QFile res(_w->dirName); |
| 16 | res.open(QIODevice::ReadOnly|QIODevice::Text); |
| 17 | all = QString(res.readAll()); |
| 18 | res.close(); |
| 19 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 20 | QStringList newlabels; |
| 21 | QStringList oldlabels; |
| 22 | for (int i=0; i<_w->chgl->mol->asymm.size(); i++){ |
| 23 | if (!chain.contains(i)) oldlabels.append(QString("%1_%2").arg(_w->chgl->mol->asymm.at(i).Label.section(QString::fromUtf8("ยป"),0,0)) |
| 24 | .arg(_w->chgl->mol->asymm.at(i).resiNr)); |
| 25 | } |
| 26 | int partmin=0; |
| 27 | int partmax=0; |
| 28 | for (int i=0; i<chain.size(); i++){ |
| 29 | int das = chain.at(i); |
| 30 | partmin = qMin(partmin, _w->chgl->mol->asymm.at(das).part); |
| 31 | partmax = qMax(partmax, _w->chgl->mol->asymm.at(das).part); |
| 32 | //QString old = _w->chgl->mol->asymm.at(das).Label; |
| 33 | int j=1; |
| 34 | int rn=qMax(_w->chgl->mol->asymm.at(das).resiNr,0); |
| 35 | QString nl=QString("%1%2_%3").arg(_w->chgl->mol->pse(newan)).arg(j).arg(rn); |
| 36 | while ((newlabels.contains(nl))||(oldlabels.contains(nl))) nl=QString("%1%2_%3").arg(_w->chgl->mol->pse(newan)).arg(++j).arg(rn); |
| 37 | newlabels.append(nl); |
| 38 | _w->chgl->mol->asymm[das].Label = nl.section('_',0,0); |
| 39 | //if (das>=possible)qbackup[das-possible].Label = nl.section('_',0,0); |
| 40 | } |
| 41 | qDebug()<<_w->chgl->mol->asymm.size()<<oldlabels.size()<<newlabels.size(); |
| 42 | qDebug()<<newlabels; |
| 43 | qDebug()<<oldlabels; |
| 44 | newlabels.clear(); |
| 45 | oldlabels.clear(); |
| 46 | /*for (int i=0; i<_w->chgl->mol->asymm.size(); i++){ |
| 47 | printf("||%-4s %4d %8.5f %8.5f %8.5f %d\n",_w->chgl->mol->asymm.at(i).Label.toStdString().c_str(),_w->chgl->mol->asymm.at(i).an, |
| 48 | _w->chgl->mol->asymm.at(i).frac.x, |
| 49 | _w->chgl->mol->asymm.at(i).frac.y, |
| 50 | _w->chgl->mol->asymm.at(i).frac.z, |
| 51 | (chain.contains(i))); |
| 52 | }*/ |
| 53 | //return; |
| 54 | emit message("New labels created."); |
| 55 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 56 | int firstatom = all.indexOf(_w->chgl->mol->asymm.at(0).orginalLine); |
| 57 | int firstpart = all.indexOf("\nPART",0,Qt::CaseInsensitive); |
| 58 | int firstresi = all.indexOf("\nRESI",0,Qt::CaseInsensitive); |
| 59 | int vonhier = firstatom; |
| 60 | if (firstpart>-1) vonhier = qMin(vonhier,firstpart); |
| 61 | if (firstresi>-1) vonhier = qMin(vonhier,firstresi); |
| 62 | |
| 63 | int bisda =all.lastIndexOf("\nHKLF"); |
| 64 | if (firstresi>-1) vonhier = qMin(vonhier,bisda); |
| 65 | //printf("%d ---- >%d\n", vonhier, bisda); |
| 66 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 67 | //_w->editor->sortAtoms(_w->chgl->mol->asymm); |
| 68 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 69 | //printf("na = %d\n",_w->chgl->mol->asymm.size()); |
| 70 | //_w->chgl->mol->asymm.append(qbackup); |
| 71 | QString insert = "\n"; |
| 72 | int pr=0;//previous resi number |
| 73 | int pp=0;//previous part number |
| 74 | int pa=0;//previous afix |
| 75 | |
| 76 | for (int i=0; i<chain.size(); i++){printf("chain %d(%d) /%d\n", chain.at(i), chain.size(), _w->chgl->mol->asymm.size());} |
| 77 | for (int i=0; i<_w->chgl->mol->asymm.size(); i++){ |
| 78 | if (chain.contains(i)){ |
| 79 | int das = i; |
| 80 | int _sfacnr = 1 + _w->editor->sfac.indexOf(newan); |
| 81 | if ((_w->chgl->mol->asymm.at(das).resiNr>=0)&&(pr!=_w->chgl->mol->asymm.at(das).resiNr)) { |
| 82 | insert+=QString("RESI %1 %2\n").arg(_w->chgl->mol->asymm.at(das).resiNr).arg(_w->chgl->mol->asymm.at(das).ResiClass); |
| 83 | pr=_w->chgl->mol->asymm.at(das).resiNr; |
| 84 | } |
| 85 | if ((pa!=_w->chgl->mol->asymm.at(das).afix)) { |
| 86 | insert+=QString("AFIX %1\n").arg(_w->chgl->mol->asymm.at(das).afix); |
| 87 | pa=_w->chgl->mol->asymm.at(das).afix; |
| 88 | } |
| 89 | if (((partmin<0)||(partmax>0))&&(pp!=_w->chgl->mol->asymm.at(das).part)) { |
| 90 | insert+=QString("PART %1\n").arg(_w->chgl->mol->asymm.at(das).part); |
| 91 | pp=_w->chgl->mol->asymm.at(das).part; |
| 92 | } |
| 93 | if (_w->chgl->mol->asymm.at(das).isIso) |
| 94 | insert+=QString("%1 %2 %3 %4 %5 %6 %7\n") |
| 95 | .arg(_w->chgl->mol->asymm.at(das).Label,-4) |
| 96 | .arg(_sfacnr) |
| 97 | .arg(_w->chgl->mol->asymm.at(das).frac.x,10,'f',5) |
| 98 | .arg(_w->chgl->mol->asymm.at(das).frac.y,10,'f',5) |
| 99 | .arg(_w->chgl->mol->asymm.at(das).frac.z,10,'f',5) |
| 100 | .arg(_w->chgl->mol->asymm.at(das).sof_org,10,'f',5) |
| 101 | .arg(_w->chgl->mol->asymm.at(das).ufiso_org) |
| 102 | ; |
| 103 | else |
| 104 | // 0.01902 0.00464 0.01485 -0.00203 |
| 105 | insert+=QString("\n%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12\n") |
| 106 | .arg(_w->chgl->mol->asymm.at(das).Label,-4) |
| 107 | .arg(_sfacnr) |
| 108 | .arg(_w->chgl->mol->asymm.at(das).frac.x,10,'f',5) |
| 109 | .arg(_w->chgl->mol->asymm.at(das).frac.y,10,'f',5) |
| 110 | .arg(_w->chgl->mol->asymm.at(das).frac.z,10,'f',5) |
| 111 | .arg(_w->chgl->mol->asymm.at(das).sof_org,10,'f',5) |
| 112 | .arg(_w->chgl->mol->asymm.at(das).uf.m11,10,'f',5) |
| 113 | .arg(_w->chgl->mol->asymm.at(das).uf.m22,10,'f',5) |
| 114 | .arg(_w->chgl->mol->asymm.at(das).uf.m33,10,'f',5) |
| 115 | .arg(_w->chgl->mol->asymm.at(das).uf.m32,10,'f',5) |
| 116 | .arg(_w->chgl->mol->asymm.at(das).uf.m31,10,'f',5) |
| 117 | .arg(_w->chgl->mol->asymm.at(das).uf.m21,10,'f',5) |
| 118 | ; |
| 119 | }else { |
| 120 | if (_w->chgl->mol->asymm.at(i).an<0) continue; |
| 121 | if ((pr!=_w->chgl->mol->asymm.at(i).resiNr)) { |
| 122 | insert+=QString("RESI %1 %2\n").arg(_w->chgl->mol->asymm.at(i).resiNr).arg(_w->chgl->mol->asymm.at(i).ResiClass); |
| 123 | pr=_w->chgl->mol->asymm.at(i).resiNr; |
| 124 | } |
| 125 | if ((pa!=_w->chgl->mol->asymm.at(i).afix)) { |
| 126 | insert+=QString("AFIX %1\n").arg(_w->chgl->mol->asymm.at(i).afix); |
| 127 | pa=_w->chgl->mol->asymm.at(i).afix; |
| 128 | } |
| 129 | if (((partmin<0)||(partmax>0))&&(pp!=_w->chgl->mol->asymm.at(i).part)) { |
| 130 | insert+=QString("PART %1\n").arg(_w->chgl->mol->asymm.at(i).part); |
| 131 | pp=_w->chgl->mol->asymm.at(i).part; |
| 132 | } |
| 133 | insert+= _w->chgl->mol->asymm.at(i).orginalLine; |
| 134 | insert+="\n"; |
| 135 | } |
| 136 | |
| 137 | } |
| 138 | //printf("%d %d %d \n%s\n",vonhier,bisda-vonhier,bisda,insert.toStdString().c_str()); |
| 139 | all.replace(vonhier,bisda-vonhier,insert); |
| 140 | emit message("...old labeld atoms replaced with new ones..."); |
| 141 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 142 | //printf("%d %d %d\n",vonhier,bisda-vonhier,bisda); |
| 143 | //printf("%s\n==================\n%s\n",insert.toStdString().c_str(),all.toStdString().c_str()); |
| 144 | |
| 145 | } |
| 146 | |
| 147 | void rename_selected::finalize(){ |
| 148 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 149 | _w->editor->setPlainText(all); |
| 150 | all.clear(); |
| 151 | _w->fileSave(); |
| 152 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 153 | //_w->editor->textCursor().beginEditBlock(); |
| 154 | |
| 155 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 156 | |
| 157 | //_w->sdm(); |
| 158 | _w->chgl->update(); |
| 159 | //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart(); |
| 160 | _w->fileSave(); |
| 161 | |
| 162 | //printf("AuLa took %d ms.\n", rzeit.elapsed()); // rzeit.restart(); |
| 163 | QWhatsThis::hideText(); |
| 164 | QMessageBox mb2(QMessageBox::Information, |
| 165 | "Automatic Labeling",QString("<h4>Labeled %1 atoms out of %2 atoms in the asymmetic unit in %3 seconds </h4>") |
| 166 | .arg(chain.size()).arg(possible).arg((rzeit.elapsed()/1000.0),0,'f',1)); |
| 167 | mb2.exec(); |
| 168 | } |