| 1 | #include "ideal_defden.h" |
| 2 | |
| 3 | double IdealDefdenGenerator::defden(V3 pos,CEnvironment &belo, QList<Matrix> &mi){ |
| 4 | double rho=0.0; |
| 5 | double argu; |
| 6 | for (int i=0; i<belo.size(); i++){ |
| 7 | //V3 frac = V3(fmod(9999.+belo.at(i).frac.x,1.0), fmod(9999.+belo.at(i).frac.y,1.0), fmod(9999.+belo.at(i).frac.z,1.0)); |
| 8 | V3 pos0 = pos - belo.at(i).frac; |
| 9 | argu = pos0 * (mi.at(i) * pos0); |
| 10 | if (argu>-37.0)// this speeds it up! |
| 11 | rho += belo.at(i).sof_org * exp(argu); |
| 12 | } |
| 13 | return rho; |
| 14 | } |
| 15 | |
| 16 | void IdealDefdenGenerator::beloWriteCube(){ |
| 17 | if (!chgl->hideBeLo->isVisible()) {qDebug()<<"BeLo: 'rrrrrrr!'"; return; } |
| 18 | CEnvironment belo,bu; |
| 19 | double stepWitdth=0.11; |
| 20 | int stepx = chgl->mol->cell.a / stepWitdth; |
| 21 | int stepy = chgl->mol->cell.b / stepWitdth; |
| 22 | int stepz = chgl->mol->cell.c / stepWitdth; |
| 23 | size_t ntot = stepx * stepy * stepz; |
| 24 | float *dat = NULL; |
| 25 | do { |
| 26 | dat = (float*) malloc(ntot * sizeof (float)); |
| 27 | if (dat == NULL){ // |
| 28 | if (stepWitdth > 0.3) return; // stop if this gets to coarse |
| 29 | stepWitdth *= 1.1;//try a larger stepWitdth |
| 30 | stepx = chgl->mol->cell.a / stepWitdth; |
| 31 | stepy = chgl->mol->cell.b / stepWitdth; |
| 32 | stepz = chgl->mol->cell.c / stepWitdth; |
| 33 | ntot = stepx * stepy * stepz; |
| 34 | dat = (float*) malloc(ntot * sizeof (float)); |
| 35 | } |
| 36 | } while (dat == NULL); |
| 37 | V3 _dx = V3(1.0 / stepx, 0, 0), _dy = V3(0, 1.0 / stepy, 0), _dz = V3(0, 0, 1.0 / stepz); |
| 38 | V3 org = 0.5 * _dx + 0.5 * _dy + 0.5 * _dz; |
| 39 | for (int bl = 0; bl < chgl->mol->asymm.size(); bl++){ |
| 40 | if (chgl->mol->asymm.at(bl).an==-42){ //bede lone objects |
| 41 | bu.append(chgl->mol->asymm[bl]); |
| 42 | } |
| 43 | } |
| 44 | belo = chgl->mol->packInLimits(bu,-0.1,1.1,-0.1,1.1,-0.1,1.1); |
| 45 | emit message(QString("Computing on %1 BEDE LONE objects.").arg(belo.size())); |
| 46 | bu.clear(); |
| 47 | double midd=9.9e37,madd=-9.9e37,rho,summ=0.0,sum1=0.0, sum2=0.0; |
| 48 | QList<Matrix> mi; |
| 49 | //const double pisqrt = sqrt(M_PI); |
| 50 | const double pi2=M_PI*M_PI; |
| 51 | //const double pisqrt3=M_PI*pisqrt; |
| 52 | Matrix M,Mi; |
| 53 | double d; |
| 54 | for (int i=0; i<belo.size(); i++){ |
| 55 | M = (chgl->mol->cell.Gi* (belo.at(i).peakHeight*4)) + belo.at(i).uf; |
| 56 | //M = (chgl->mol->cell.Gi* (belo.at(i).uf*belo.at(i).peakHeight*.25)); |
| 57 | //M = (chgl->mol->cell.Gi* ((belo.at(i).uf)*(belo.at(i).peakHeight*0.25)));//uf is Bij here |
| 58 | //M = (chgl->mol->cell.Gi* (belo.at(i).peakHeight*0.25)) * belo.at(i).uf;//uf is Bij here |
| 59 | Mi = inverse(M); |
| 60 | //sof==a peakHeight=b |
| 61 | d = determinant(Mi); |
| 62 | belo[i].sof_org = sqrt(d) * belo.at(i).sof / chgl->mol->cell.V;// * pisqrt3; |
| 63 | Mi = Mi *(-pi2); |
| 64 | mi.append(Mi); |
| 65 | } |
| 66 | size_t pro=0,aproc,bproc=10; |
| 67 | for (int iz=0; iz<stepz; iz++){ |
| 68 | for (int iy=0; iy<stepy; iy++){ |
| 69 | for (int ix=0; ix<stepx; ix++){ |
| 70 | rho=defden((ix*_dx)+(iy*_dy)+(iz*_dz)+org,belo,mi);//+minp |
| 71 | midd=qMin(rho,midd); |
| 72 | madd=qMax(rho,madd); |
| 73 | if (rho>0.0) sum1+=rho; |
| 74 | else sum2+=rho; |
| 75 | summ+=rho; |
| 76 | if (fabs(rho)<=1.0e-98) rho=0.0; |
| 77 | dat[ix + iy*stepx + iz*stepx*stepy]=(float)rho; |
| 78 | pro++; |
| 79 | } |
| 80 | } |
| 81 | aproc = (pro * 100) / ntot; |
| 82 | if (aproc!=bproc){ |
| 83 | emit message(QString("Calculating deformation density %1% (steps:%2)").arg(aproc).arg(ntot)); |
| 84 | bproc = aproc; |
| 85 | } |
| 86 | } |
| 87 | mi.clear(); |
| 88 | belo.clear(); |
| 89 | printf("%f %f %f \n",midd,madd,summ); |
| 90 | bool gut = fxle->loadMap(stepx, stepy, stepz, dat);//dat lives as datfo_fc its life in fxle |
| 91 | if (!gut) { |
| 92 | emit message("Oh no! Something went wrong while creating BODD maps. Perhaps we are out of memory. Sorry!"); |
| 93 | free(dat); |
| 94 | dat=NULL; |
| 95 | return; |
| 96 | } |
| 97 | printf("%f %f %f %d\n",midd, madd, summ, gut); |
| 98 | chgl->dimc=QColor("darkorange"); |
| 99 | chgl->dipc=QColor("teal"); |
| 100 | emit message(QString("finished! minRho %1 e/A^3 maxRho %2 e/A^3 sum %3 e/A^3 OK %4 %5 %6 ").arg(midd).arg(madd).arg(summ).arg(gut).arg(sum1).arg(sum2)); |
| 101 | } |