20 #include <clipper/clipper.h> 21 #include <clipper/clipper-contrib.h> 22 #include <clipper/clipper-ccp4.h> 23 #include <clipper/clipper-mmdb.h> 24 #include <clipper/clipper-minimol.h> 31 #include <wrap_fftw.h> 32 #include <makeweights.h> 33 #include <s2_primitive.h> 34 #include <s2_cospmls.h> 35 #include <s2_legendreTransforms.h> 36 #include <s2_semi_fly.h> 37 #include <rotate_so3_utils.h> 38 #include <utils_so3.h> 39 #include <soft_fftw.h> 40 #include <rotate_so3_fftw.h> 49 #include <rvapi_interface.h> 78 double *shellDistance,
80 unsigned int *bandwidth,
83 unsigned int *glIntegOrder,
89 bool overlayDefaults )
92 this->_inputFileName = fileName;
93 this->_mapResolution = resolution;
94 if ( mapResDefault && overlayDefaults && resolution == 2.0 ) { this->_mapResolution = 2.0; }
95 this->_shellSpacing = *shellDistance;
96 this->_maxExtraCellularSpace = *extraSpace;
97 this->_firstLineCOM = hpFirstLineCom;
100 clipper::mmdb::CMMDBManager *mfile =
new clipper::mmdb::CMMDBManager ( );
101 if ( mfile->ReadCoorFile ( this->_inputFileName.c_str() ) )
103 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read file: " << this->_inputFileName.c_str() << std::endl;
107 std::stringstream hlpSS;
108 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file: " << this->_inputFileName.c_str() <<
"</font>";
109 rvapi_set_text ( hlpSS.str().c_str(),
129 bool firstAtom =
true;
131 double xVal, yVal, zVal;
138 clipper::mmdb::PPCChain chain;
139 clipper::mmdb::PPCResidue residue;
140 clipper::mmdb::PPCAtom atom;
142 double pdbXCom = 0.0;
143 double pdbYCom = 0.0;
144 double pdbZCom = 0.0;
145 double bFacTot = 0.0;
148 mfile->GetChainTable ( 1, chain, noChains );
150 for (
unsigned int nCh = 0; nCh < static_cast<unsigned int> ( noChains ); nCh++ )
155 chain[nCh]->GetResidueTable ( residue, noResidues );
157 for (
unsigned int nRes = 0; nRes < static_cast<unsigned int> ( noResidues ); nRes++ )
162 residue[nRes]->GetAtomTable ( atom, noAtoms );
164 for (
unsigned int aNo = 0; aNo < static_cast<unsigned int> ( noAtoms ); aNo++ )
169 if ( atom[aNo]->Ter ) {
continue; }
181 pdbXCom += atom[aNo]->x;
182 pdbYCom += atom[aNo]->y;
183 pdbZCom += atom[aNo]->z;
184 if ( Bfactor != 0.0 )
190 bFacTot += atom[aNo]->tempFactor;
201 if ( xVal > maxX ) { maxX = xVal; }
if ( xVal < minX ) { minX = xVal; }
202 if ( yVal > maxY ) { maxY = yVal; }
if ( yVal < minY ) { minY = yVal; }
203 if ( zVal > maxZ ) { maxZ = zVal; }
if ( zVal < minZ ) { minZ = zVal; }
205 if ( Bfactor != 0.0 )
208 pdbXCom += atom[aNo]->x;
209 pdbYCom += atom[aNo]->y;
210 pdbZCom += atom[aNo]->z;
214 bFacTot += atom[aNo]->tempFactor;
215 pdbXCom += atom[aNo]->x * atom[aNo]->tempFactor;
216 pdbYCom += atom[aNo]->y * atom[aNo]->tempFactor;
217 pdbZCom += atom[aNo]->z * atom[aNo]->tempFactor;
233 this->_xRange = (maxX - minX);
234 this->_yRange = (maxY - minY);
235 this->_zRange = (maxZ - minZ);
236 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
239 this->_maxExtraCellularSpace = *extraSpace;
240 double ecsHlp = std::floor ( std::max ( 20.0, ( this->_maxMapRange / 4.0 ) ) );
243 this->_xRange = (maxX - minX) + ecsHlp;
244 this->_yRange = (maxY - minY) + ecsHlp;
245 this->_zRange = (maxZ - minZ) + ecsHlp;
246 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
249 double xMov = (ecsHlp/2.0) - minX;
250 double yMov = (ecsHlp/2.0) - minY;
251 double zMov = (ecsHlp/2.0) - minZ;
254 mfile->GetChainTable ( 1, chain, noChains );
256 for (
unsigned int nCh = 0; nCh < static_cast<unsigned int> ( noChains ); nCh++ )
261 chain[nCh]->GetResidueTable ( residue, noResidues );
263 for (
unsigned int nRes = 0; nRes < static_cast<unsigned int> ( noResidues ); nRes++ )
268 residue[nRes]->GetAtomTable ( atom, noAtoms );
270 for (
unsigned int aNo = 0; aNo < static_cast<unsigned int> ( noAtoms ); aNo++ )
275 if ( atom[aNo]->Ter ) {
continue; }
277 if ( Bfactor != 0.0 )
279 atom[aNo]->SetCoordinates ( atom[aNo]->x + xMov,
282 atom[aNo]->occupancy,
287 atom[aNo]->SetCoordinates ( atom[aNo]->x + xMov,
290 atom[aNo]->occupancy,
291 atom[aNo]->tempFactor );
297 this->_xCorrErr = atom[aNo]->x;
298 this->_yCorrErr = atom[aNo]->y;
299 this->_zCorrErr = atom[aNo]->z;
309 clipper::Spacegroup spgr ( clipper::Spacegroup::P1 );
310 clipper::Cell cell ( clipper::Cell_descr ( this->_xRange, this->_yRange, this->_zRange ) );
311 clipper::Resolution reso = clipper::Resolution ( this->_mapResolution );
312 const clipper::Grid_sampling grid ( spgr, cell, reso );
313 clipper::Xmap<float> *densityMap =
new clipper::Xmap<float> ( spgr, cell, grid );
316 int hndl = mfile->NewSelection ( );
317 mfile->SelectAtoms ( hndl, 0, 0, ::mmdb::SKEY_NEW );
318 mfile->GetSelIndex ( hndl, atom, noAtoms );
319 clipper::MMDBAtom_list *aList =
new clipper::MMDBAtom_list ( atom, noAtoms );
320 clipper::EDcalc_aniso<clipper::ftype32> edCalc;
321 edCalc ( *densityMap, *aList );
327 clipper::Xmap_base::Map_reference_index LastPos = (*densityMap).first();
328 clipper::Xmap_base::Map_reference_index PrevPos = (*densityMap).first();
329 for ( LastPos = (*densityMap).first(); !LastPos.last(); LastPos.next() ) { PrevPos = LastPos; }
330 this->_maxMapU = PrevPos.coord().u();
331 this->_maxMapV = PrevPos.coord().v();
332 this->_maxMapW = PrevPos.coord().w();
336 this->_densityMapMap = (
float*) malloc ( ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ) *
sizeof ( float ) );
337 if ( this->_densityMapMap ==
nullptr )
339 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
343 std::stringstream hlpSS;
344 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
345 rvapi_set_text ( hlpSS.str().c_str(),
360 for (
unsigned int uIt = 0; uIt < (this->_maxMapU+1); uIt++ )
362 for (
unsigned int vIt = 0; vIt < (this->_maxMapV+1); vIt++ )
364 for (
unsigned int wIt = 0; wIt < (this->_maxMapW+1); wIt++ )
366 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
368 clipper::Vec3<int> pos ( uIt, vIt, wIt );
369 clipper::Coord_grid cg ( pos );
371 this->_densityMapMap[arrPos] = densityMap->get_data ( cg );
377 if ( densityMap !=
nullptr )
380 densityMap =
nullptr;
388 this->_xTo = this->_maxMapU;
389 this->_yTo = this->_maxMapV;
390 this->_zTo = this->_maxMapW;
398 minX = this->_maxMapU;
399 minY = this->_maxMapV;
400 minZ = this->_maxMapW;
401 for (
unsigned int uIt = 0; uIt < (this->_maxMapU+1); uIt++ )
403 for (
unsigned int vIt = 0; vIt < (this->_maxMapV+1); vIt++ )
405 for (
unsigned int wIt = 0; wIt < (this->_maxMapW+1); wIt++ )
407 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
408 if ( this->_densityMapMap[arrPos] > 0.005 )
410 if ( maxX < uIt ) { maxX = uIt; }
if ( minX > uIt ) { minX = uIt; }
411 if ( maxY < vIt ) { maxY = vIt; }
if ( minY > vIt ) { minY = vIt; }
412 if ( maxZ < wIt ) { maxZ = wIt; }
if ( minZ > wIt ) { minZ = wIt; }
418 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
419 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
420 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
422 this->_xRange = this->_xRange - ( this->_maxMapU - ( maxX - minX ) ) * this->_xSamplingRate;
423 this->_yRange = this->_yRange - ( this->_maxMapV - ( maxY - minY ) ) * this->_ySamplingRate;
424 this->_zRange = this->_zRange - ( this->_maxMapW - ( maxZ - minZ ) ) * this->_zSamplingRate;
425 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
428 float *hlpMap =
nullptr;
429 hlpMap = (
float*) malloc ( static_cast<int>( (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1) ) *
sizeof ( float ) );
430 if ( hlpMap ==
nullptr )
432 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
436 std::stringstream hlpSS;
437 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
438 rvapi_set_text ( hlpSS.str().c_str(),
451 unsigned int newU, newV, newW, hlpPos;
452 for (
int uIt = 0; uIt < static_cast<int> (maxX - minX + 1); uIt++ )
454 for (
int vIt = 0; vIt < static_cast<int> (maxY - minY + 1); vIt++ )
456 for (
int wIt = 0; wIt < static_cast<int> (maxZ - minZ + 1); wIt++ )
462 hlpPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
463 arrPos = wIt + (maxZ - minZ + 1) * ( vIt + (maxY - minY + 1) * uIt );
465 hlpMap[arrPos] = this->_densityMapMap[hlpPos];
470 this->_maxMapU = maxX - minX;
471 this->_maxMapV = maxY - minY;
472 this->_maxMapW = maxZ - minZ;
474 this->_xTo = maxX - minX;
475 this->_yTo = maxY - minY;
476 this->_zTo = maxZ - minZ;
479 if ( this->_densityMapMap !=
nullptr )
481 free ( this->_densityMapMap );
482 this->_densityMapMap =
nullptr;
485 this->_densityMapMap = (
float*) malloc ( ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ) *
sizeof ( float ) );
486 if ( this->_densityMapMap ==
nullptr )
488 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
492 std::stringstream hlpSS;
493 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
494 rvapi_set_text ( hlpSS.str().c_str(),
507 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
509 this->_densityMapMap[iter] = hlpMap[iter];
512 if ( hlpMap !=
nullptr )
518 if ( this->_maxExtraCellularSpace == -777.7 )
520 this->_maxExtraCellularSpace = std::max ( 20.0, ( std::max( this->_xRange, std::max ( this->_yRange, this->_zRange ) ) - std::min( this->_xRange, std::min ( this->_yRange, this->_zRange ) ) ) );
521 *extraSpace = this->_maxExtraCellularSpace;
524 if ( this->_maxExtraCellularSpace != 0.0 )
527 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
528 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
529 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
531 this->_xRange += xDiff * this->_xSamplingRate;
532 this->_yRange += yDiff * this->_ySamplingRate;
533 this->_zRange += zDiff * this->_zSamplingRate;
535 if ( xDiff % 2 != 0 )
537 this->_xRange += this->_xSamplingRate;
538 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
540 if ( yDiff % 2 != 0 )
542 this->_yRange += this->_ySamplingRate;
543 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
545 if ( zDiff % 2 != 0 )
547 this->_zRange += this->_zSamplingRate;
548 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
550 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
556 this->_xFrom -= xDiff;
557 this->_yFrom -= yDiff;
558 this->_zFrom -= zDiff;
564 this->_maxMapU = this->_xTo - this->_xFrom;
565 this->_maxMapV = this->_yTo - this->_yFrom;
566 this->_maxMapW = this->_zTo - this->_zFrom;
568 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
569 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
570 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
574 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
575 if ( hlpMap ==
nullptr )
577 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
581 std::stringstream hlpSS;
582 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for moving the map data. Did you run out of memory?" <<
"</font>";
583 rvapi_set_text ( hlpSS.str().c_str(),
595 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
600 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
602 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
604 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
606 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
607 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
608 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
610 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
611 hlpMap[hlpPos] = 0.0;
615 newU = (uIt - xDiff);
616 newV = (vIt - yDiff);
617 newW = (wIt - zDiff);
619 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
620 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
622 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
629 if ( this->_densityMapMap !=
nullptr )
631 free ( this->_densityMapMap );
632 this->_densityMapMap =
nullptr;
636 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
637 if ( this->_densityMapMap ==
nullptr )
639 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
643 std::stringstream hlpSS;
644 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
645 rvapi_set_text ( hlpSS.str().c_str(),
657 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
659 this->_densityMapMap[iter] = hlpMap[iter];
663 if ( hlpMap !=
nullptr )
671 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
672 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
673 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
674 double maxSamplingRate = std::max ( this->_xSamplingRate, std::max( this->_ySamplingRate, this->_zSamplingRate ) );
677 double mapXCom = 0.0;
678 double mapYCom = 0.0;
679 double mapZCom = 0.0;
680 double densTot = 0.0;
681 for (
unsigned int uIt = 0; uIt < static_cast<unsigned int> ( (this->_maxMapU+1) ); uIt++ )
683 for (
unsigned int vIt = 0; vIt < static_cast<unsigned int> ( (this->_maxMapV+1) ); vIt++ )
685 for (
unsigned int wIt = 0; wIt < static_cast<unsigned int> ( (this->_maxMapW+1) ); wIt++ )
687 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
689 mapXCom += uIt * this->_densityMapMap[arrPos];
690 mapYCom += vIt * this->_densityMapMap[arrPos];
691 mapZCom += wIt * this->_densityMapMap[arrPos];
692 densTot += this->_densityMapMap[arrPos];
701 mapXCom = ( mapXCom + this->_xFrom ) * this->_xSamplingRate;
702 mapYCom = ( mapYCom + this->_yFrom ) * this->_ySamplingRate;
703 mapZCom = ( mapZCom + this->_zFrom ) * this->_zSamplingRate;
705 double mapXMove = ( pdbXCom - mapXCom ) / this->_xSamplingRate;
706 double mapYMove = ( pdbYCom - mapYCom ) / this->_ySamplingRate;
707 double mapZMove = ( pdbZCom - mapZCom ) / this->_zSamplingRate;
709 this->_xFrom += std::round ( mapXMove );
710 this->_xTo += std::round ( mapXMove );
711 this->_yFrom += std::round ( mapYMove );
712 this->_yTo += std::round ( mapYMove );
713 this->_zFrom += std::round ( mapZMove );
714 this->_zTo += std::round ( mapZMove );
716 bool xFSignChange =
false;
717 if ( ( ( ( this->_xFrom - std::round ( mapXMove ) ) < 0 ) && ( this->_xFrom > 0 ) ) ||
718 ( ( ( this->_xFrom - std::round ( mapXMove ) ) > 0 ) && ( this->_xFrom < 0 ) ) ) { xFSignChange =
true; }
719 bool xTSignChange =
false;
720 if ( ( ( ( this->_xTo - std::round ( mapXMove ) ) < 0 ) && ( this->_xTo > 0 ) ) ||
721 ( ( ( this->_xTo - std::round ( mapXMove ) ) > 0 ) && ( this->_xTo < 0 ) ) ) { xTSignChange =
true; }
723 bool yFSignChange =
false;
724 if ( ( ( ( this->_yFrom - std::round ( mapYMove ) ) < 0 ) && ( this->_yFrom > 0 ) ) ||
725 ( ( ( this->_yFrom - std::round ( mapYMove ) ) > 0 ) && ( this->_yFrom < 0 ) ) ) { yFSignChange =
true; }
726 bool yTSignChange =
false;
727 if ( ( ( ( this->_yTo - std::round ( mapYMove ) ) < 0 ) && ( this->_yTo > 0 ) ) ||
728 ( ( ( this->_yTo - std::round ( mapYMove ) ) > 0 ) && ( this->_yTo < 0 ) ) ) { yTSignChange =
true; }
730 bool zFSignChange =
false;
731 if ( ( ( ( this->_zFrom - std::round ( mapZMove ) ) < 0 ) && ( this->_zFrom > 0 ) ) ||
732 ( ( ( this->_zFrom - std::round ( mapZMove ) ) > 0 ) && ( this->_zFrom < 0 ) ) ) { zFSignChange =
true; }
733 bool zTSignChange =
false;
734 if ( ( ( ( this->_zTo - std::round ( mapZMove ) ) < 0 ) && ( this->_zTo > 0 ) ) ||
735 ( ( ( this->_zTo - std::round ( mapZMove ) ) > 0 ) && ( this->_zTo < 0 ) ) ) { zTSignChange =
true; }
737 if ( ( xFSignChange && !xTSignChange ) || ( !xFSignChange && xTSignChange ) )
741 if ( ( yFSignChange && !yTSignChange ) || ( !yFSignChange && yTSignChange ) )
745 if ( ( zFSignChange && !zTSignChange ) || ( !zFSignChange && zTSignChange ) )
751 if ( *shellDistance == 0 )
754 this->_shellSpacing = maxSamplingRate / 2.0;
755 *shellDistance = this->_shellSpacing;
757 if ( overlayDefaults )
760 this->_shellSpacing *= 2.0;
761 *shellDistance *= 2.0;
764 while ( std::floor ( this->_maxMapRange / this->_shellSpacing ) < 20 )
766 this->_shellSpacing /= 2.0;
768 *shellDistance /= 2.0;
773 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
775 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
777 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
781 if ( *bandwidth == 0 )
783 *bandwidth = std::ceil ( std::ceil ( ( ( std::ceil ( this->_maxMapRange / this->_shellSpacing ) *
784 this->_shellSpacing ) / maxSamplingRate ) * 2.0 ) / 2.0 );
788 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
789 this->_wasBandwithGiven =
true;
793 if ( *theta == 0 ) { *theta = 2 * (*bandwidth); }
794 if ( *phi == 0 ) { *phi = 2 * (*bandwidth); }
797 if ( *glIntegOrder == 0 )
799 double distPerPointFraction = ( ( this->_maxMapRange / 2.0 ) / static_cast<double> ( *bandwidth / 2 ) ) / ( this->_maxMapRange / 2.0 );
801 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
803 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
805 *glIntegOrder = iter;
811 this->_densityMapComputed =
true;
812 this->_fromPDB =
true;
836 double *shellDistance,
838 unsigned int *bandwidth,
841 unsigned int *glIntegOrder,
846 bool overlayDefaults )
849 this->_inputFileName = fileName;
850 this->_shellSpacing = *shellDistance;
851 this->_mapResolution = resolution;
852 if ( mapResDefault && overlayDefaults ) { this->_mapResolution = 3.0; }
853 if ( *extraSpace == -777.7 ) { *extraSpace= 0.0; std::cout <<
"!!! ProSHADE WARNING !!! Using the overlay mode with no extra space around the map. This can lead to incorrect rotation and translation as well as artefacts, unless your map has enough empty space around it density. If not, please use the \"--cellBorderSpace\" command line option to add some empty space." << std::endl; }
854 this->_maxExtraCellularSpace = *extraSpace;
855 this->_firstLineCOM =
false;
858 CMap_io::CMMFile *mapFile =
nullptr;
859 float *cell =
nullptr;
862 int *order =
nullptr;
865 double cornerAvg = 0.0;
866 double centralAvg = 0.0;
867 double cornerCount = 0.0;
868 double centralCount = 0.0;
871 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
872 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
873 grid = (
int* ) malloc ( 3 *
sizeof (
int ) );
874 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
875 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
877 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) || ( grid ==
nullptr ) )
879 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
883 std::stringstream hlpSS;
884 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
885 rvapi_set_text ( hlpSS.str().c_str(),
899 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
900 if ( mapFile ==
nullptr )
902 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and corruption of the file. Terminating..." << std::endl;
906 std::stringstream hlpSS;
907 hlpSS <<
"<font color=\"red\">" <<
"Cannot open the file " << fileName <<
" . Could it be corrupted?" <<
"</font>";
908 rvapi_set_text ( hlpSS.str().c_str(),
921 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
922 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
923 CMap_io::ccp4_cmap_get_grid ( mapFile, grid );
924 CMap_io::ccp4_cmap_get_order ( mapFile, order );
925 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
928 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
929 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
930 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
933 this->_xRange = cell[0];
934 this->_yRange = cell[1];
935 this->_zRange = cell[2];
938 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
941 this->_maxExtraCellularSpace = *extraSpace;
944 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
945 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
946 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
948 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
949 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
950 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
952 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
953 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
954 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
957 this->_xTo = this->_xFrom + this->_maxMapU;
958 this->_yTo = this->_yFrom + this->_maxMapV;
959 this->_zTo = this->_zFrom + this->_maxMapW;
962 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
963 if ( this->_densityMapMap ==
nullptr )
965 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
969 std::stringstream hlpSS;
970 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
971 rvapi_set_text ( hlpSS.str().c_str(),
985 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
986 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
988 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
992 std::stringstream hlpSS;
993 hlpSS <<
"<font color=\"red\">" <<
"Cannot read from the map file. The map mode is neither 0, nor 2; other modes are not supperted at the moment." <<
"</font>";
994 rvapi_set_text ( hlpSS.str().c_str(),
1011 int newU, newV, newW;
1014 for (
int iter = 0; iter < 3; iter++ )
1016 maxLim[iter] = orig[iter] + dim[iter] - 1;
1017 XYZOrder[order[iter]-1] = iter;
1021 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
1022 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
1023 std::vector<float> section( midDimSize );
1028 for ( iters[2] = orig[2]; iters[2] <= maxLim[2]; iters[2]++ )
1031 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
1035 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
1037 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
1041 for ( iters[1] = orig[1]; iters[1] <= maxLim[1]; iters[1]++ )
1043 for ( iters[0] = orig[0]; iters[0] <= maxLim[0]; iters[0]++ )
1045 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
1046 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
1047 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
1048 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
1049 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
1055 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1056 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
1058 vals.at(iter) = this->_densityMapMap[iter];
1060 std::sort ( vals.begin(), vals.end() );
1063 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
1064 this->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - this->_mapMean * this->_mapMean );
1067 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
1068 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
1069 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
1071 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1073 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1075 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1078 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1081 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
1082 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
1083 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
1085 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
1086 centralCount += 1.0;
1088 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
1089 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1090 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
1091 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1092 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
1093 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1094 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
1095 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
1097 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
1104 cornerAvg /= cornerCount;
1105 centralAvg /= centralCount;
1108 if ( cornerAvg > centralAvg )
1111 float* hlpMap =
nullptr;
1112 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
1113 if ( hlpMap ==
nullptr )
1115 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
1119 std::stringstream hlpSS;
1120 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1121 rvapi_set_text ( hlpSS.str().c_str(),
1133 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
1135 hlpMap[iter] = this->_densityMapMap[iter];
1139 unsigned int hlpPos;
1140 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1142 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1144 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1147 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
1148 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
1149 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
1151 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
1152 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1155 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
1166 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
1170 std::stringstream hlpSS;
1171 hlpSS <<
"<font color=\"red\">" <<
"Non-orthogonal map detected. Only P1 maps are currently supported." <<
"</font>";
1172 rvapi_set_text ( hlpSS.str().c_str(),
1186 if ( cell !=
nullptr )
1191 if ( dim !=
nullptr )
1196 if ( order !=
nullptr )
1201 if ( orig !=
nullptr )
1208 CMap_io::ccp4_cmap_close ( mapFile );
1211 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
1212 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
1213 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
1214 double maxSamplingRate = std::max ( this->_xSamplingRate, std::max( this->_ySamplingRate, this->_zSamplingRate ) );
1217 this->_maxExtraCellularSpace = *extraSpace;
1218 if ( *extraSpace != 0.0 )
1221 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
1222 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
1223 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
1225 this->_xRange += xDiff * this->_xSamplingRate;
1226 this->_yRange += yDiff * this->_ySamplingRate;
1227 this->_zRange += zDiff * this->_zSamplingRate;
1229 if ( xDiff % 2 != 0 )
1231 this->_xRange += this->_xSamplingRate;
1232 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
1234 if ( yDiff % 2 != 0 )
1236 this->_yRange += this->_ySamplingRate;
1237 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
1239 if ( zDiff % 2 != 0 )
1241 this->_zRange += this->_zSamplingRate;
1242 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
1249 this->_xFrom -= xDiff;
1250 this->_yFrom -= yDiff;
1251 this->_zFrom -= zDiff;
1253 this->_xTo += xDiff;
1254 this->_yTo += yDiff;
1255 this->_zTo += zDiff;
1257 this->_maxMapU = this->_xTo - this->_xFrom;
1258 this->_maxMapV = this->_yTo - this->_yFrom;
1259 this->_maxMapW = this->_zTo - this->_zFrom;
1261 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
1262 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
1263 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
1266 float *hlpMap =
nullptr;
1267 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
1268 if ( hlpMap ==
nullptr )
1270 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
1274 std::stringstream hlpSS;
1275 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1276 rvapi_set_text ( hlpSS.str().c_str(),
1288 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1293 unsigned int newU, newV, newW, hlpPos, arrPos;
1294 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1296 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1298 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1300 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
1301 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
1302 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
1304 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1305 hlpMap[hlpPos] = 0.0;
1309 newU = (uIt - xDiff);
1310 newV = (vIt - yDiff);
1311 newW = (wIt - zDiff);
1313 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1314 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
1316 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
1323 if ( this->_densityMapMap !=
nullptr )
1325 free ( this->_densityMapMap );
1326 this->_densityMapMap =
nullptr;
1330 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
1331 if ( this->_densityMapMap ==
nullptr )
1333 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
1337 std::stringstream hlpSS;
1338 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1339 rvapi_set_text ( hlpSS.str().c_str(),
1351 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1353 this->_densityMapMap[iter] = hlpMap[iter];
1357 if ( hlpMap !=
nullptr )
1365 if ( ( this->_mapResolution / 2.0 ) > maxSamplingRate )
1367 maxSamplingRate = ( this->_mapResolution / 2.0 );
1371 this->_mapResolution = maxSamplingRate * 2.0;
1375 if ( *shellDistance == 0 )
1378 this->_shellSpacing = maxSamplingRate;
1379 *shellDistance = maxSamplingRate;
1384 this->_shellSpacing = this->_shellSpacing / 2.0;
1385 *shellDistance = this->_shellSpacing;
1388 if ( overlayDefaults )
1391 this->_shellSpacing *= 2.0;
1392 *shellDistance *= 2.0;
1395 while ( std::floor ( this->_maxMapRange / this->_shellSpacing ) < 20 )
1397 this->_shellSpacing /= 2.0;
1399 *shellDistance /= 2.0;
1404 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
1406 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
1408 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
1412 if ( *bandwidth == 0 )
1414 *bandwidth = std::ceil ( std::ceil ( ( ( std::ceil ( this->_maxMapRange / this->_shellSpacing ) *
1415 this->_shellSpacing ) / maxSamplingRate ) * 2.0 ) / 2.0 );
1416 this->_wasBandwithGiven =
false;
1420 *bandwidth = *bandwidth * 1.5;
1425 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
1426 this->_wasBandwithGiven =
true;
1430 *theta = 2 * (*bandwidth);
1431 this->_wasThetaGiven =
false;
1432 *phi = 2 * (*bandwidth);
1433 this->_wasPhiGiven =
false;
1436 if ( *glIntegOrder == 0 )
1438 double distPerPointFraction = ( ( this->_maxMapRange / 2.0 ) / static_cast<double> ( *bandwidth / 2 ) ) / ( this->_maxMapRange / 2.0 );
1440 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
1442 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
1444 *glIntegOrder = iter;
1448 this->_wasGlInterGiven =
false;
1452 this->_densityMapComputed =
true;
1453 this->_fromPDB =
false;
1466 if ( this->_densityMapMap ==
nullptr )
1468 std::cerr <<
"!!! ProSHADE ERROR !!! Attempted to normalise the internal map representation, but the values have already been deleted - either called the normaliseMap function too early or too late. Terminating..." << std::endl;
1472 std::stringstream hlpSS;
1473 hlpSS <<
"<font color=\"red\">" <<
"Attempted to normalise the internal map representation, but the values have already been deleted - either called the normaliseMap function too early or too late. This seems like an internal bug, please report this case." <<
"</font>";
1474 rvapi_set_text ( hlpSS.str().c_str(),
1488 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1489 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1491 vals.at(iter) = this->_densityMapMap[iter];
1493 std::sort ( vals.begin(), vals.end() );
1496 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
1497 this->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - this->_mapMean * this->_mapMean );
1500 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1502 this->_densityMapMap[iter] = this->_densityMapMap[iter] / this->_mapSdev;
1518 if ( this->_densityMapMap ==
nullptr )
1520 std::cerr <<
"!!! ProSHADE ERROR !!! Attempted to get COM and distances for the internal map representation, but the values have already been deleted - either called the getCOMandDist function too early or too late. Terminating..." << std::endl;
1524 std::stringstream hlpSS;
1525 hlpSS <<
"<font color=\"red\">" <<
"Attempted to normalise the internal map representation, but the values have already been deleted - either called the normaliseMap function too early or too late. This seems like an internal bug, please report this case." <<
"</font>";
1526 rvapi_set_text ( hlpSS.str().c_str(),
1540 unsigned int arrPos = 0;
1541 double totDens = 0.0;
1542 std::array<double,4> meanVals;
1547 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1549 for (
unsigned int uIt = 0; uIt < static_cast<unsigned int> ( (this->_maxMapU+1) ); uIt++ )
1551 for (
unsigned int vIt = 0; vIt < static_cast<unsigned int> ( (this->_maxMapV+1) ); vIt++ )
1553 for (
unsigned int wIt = 0; wIt < static_cast<unsigned int> ( (this->_maxMapW+1) ); wIt++ )
1555 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1557 if ( this->_densityMapMap[arrPos] > 0.0 )
1559 meanVals[0] += this->_densityMapMap[arrPos] * uIt;
1560 meanVals[1] += this->_densityMapMap[arrPos] * vIt;
1561 meanVals[2] += this->_densityMapMap[arrPos] * wIt;
1563 totDens += this->_densityMapMap[arrPos];
1569 meanVals[0] /= totDens;
1570 meanVals[1] /= totDens;
1571 meanVals[2] /= totDens;
1578 if ( meanVals[0] <= static_cast<double> ((this->_maxMapU+1)/2) )
1580 distX = meanVals[0] * this->_xSamplingRate;
1584 distX = (
static_cast<double> ( this->_maxMapU+1 ) - meanVals[0] ) * this->_xSamplingRate;
1587 if ( meanVals[1] <= static_cast<double> ((this->_maxMapV+1)/2) )
1589 distY = meanVals[1] * this->_ySamplingRate;
1593 distY = (
static_cast<double> ( this->_maxMapV+1 ) - meanVals[1] ) * this->_ySamplingRate;
1596 if ( meanVals[2] <= static_cast<double> ((this->_maxMapW+1)/2) )
1598 distZ = meanVals[2] * this->_zSamplingRate;
1602 distZ = (
static_cast<double> ( this->_maxMapW+1 ) - meanVals[2] ) * this->_zSamplingRate;
1606 meanVals[3] = sqrt ( pow( distX, 2.0 ) + pow ( distY, 2.0 ) + pow ( distZ, 2.0 ) );
1609 return ( meanVals );
1630 double extraMaskSpace )
1633 fftw_complex* tmpIn;
1634 fftw_complex* tmpOut;
1635 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
1636 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
1637 fftw_complex* maskData =
new fftw_complex [ hlpU * hlpV * hlpW ];
1638 fftw_complex* maskDataInv =
new fftw_complex [ hlpU * hlpV * hlpW ];
1643 double mag, phase, S;
1644 double normFactor = (hlpU * hlpV * hlpW);
1645 double bFacChange = blurBy;
1648 unsigned int hlpIt = 0;
1653 for ( uIt = 0; uIt < hlpU; uIt++ )
1655 for ( vIt = 0; vIt < hlpV; vIt++ )
1657 for ( wIt = 0; wIt < hlpW; wIt++ )
1660 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1662 if ( this->_densityMapCor[arrayPos] == this->_densityMapCor[arrayPos] )
1664 tmpIn[arrayPos][0] = ( this->_densityMapCor[arrayPos] - this->_mapMean ) / this->_mapSdev;
1665 tmpIn[arrayPos][1] = 0.0;
1669 tmpIn[arrayPos][0] = 0.0;
1670 tmpIn[arrayPos][1] = 0.0;
1677 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
1681 fftw_plan pMaskInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInv, maskData, FFTW_BACKWARD, FFTW_ESTIMATE );
1683 for ( uIt = 0; uIt < hlpU; uIt++ )
1685 for ( vIt = 0; vIt < hlpV; vIt++ )
1687 for ( wIt = 0; wIt < hlpW; wIt++ )
1690 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1691 real = tmpOut[arrayPos][0];
1692 imag = tmpOut[arrayPos][1];
1695 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
1696 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
1697 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
1700 S = ( pow( static_cast<double> ( h ) / this->_xRange, 2.0 ) +
1701 pow( static_cast<double> ( k ) / this->_yRange, 2.0 ) +
1702 pow( static_cast<double> ( l ) / this->_zRange, 2.0 ) );
1703 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
1704 phase = atan2 ( imag, real );
1707 maskDataInv[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
1708 maskDataInv[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
1714 fftw_execute ( pMaskInv );
1717 std::vector<double> maskVals ( hlpU * hlpV * hlpW );
1719 for ( uIt = 0; uIt < hlpU; uIt++ )
1721 for ( vIt = 0; vIt < hlpV; vIt++ )
1723 for ( wIt = 0; wIt < hlpW; wIt++ )
1726 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1727 maskVals.at(hlpIt) = maskData[arrayPos][0];
1734 double medianPos =
static_cast<unsigned int> ( maskVals.size() / 2 );
1735 std::sort ( maskVals.begin(), maskVals.end() );
1737 double interQuartileRange = maskVals.at(medianPos+(medianPos/2)) - maskVals.at(medianPos-(medianPos/2));
1738 double mapThresholdPlus = maskVals.at(medianPos+(medianPos/2)) + ( interQuartileRange * maxMapIQR );
1742 int addPoints =
static_cast<int> ( std::max ( std::ceil ( extraMaskSpace / static_cast<double> ( this->_xRange / (hlpU-1) ) ), std::max ( std::ceil ( extraMaskSpace / static_cast<double> ( this->_yRange / (hlpV-1) ) ), std::ceil ( extraMaskSpace / static_cast<double> ( this->_zRange / (hlpW-1) ) ) ) ) );
1743 int arrPosSearch = 0;
1744 int newU, newV, newW;
1745 bool breakOut =
false;
1747 for ( uIt = 0; uIt < hlpU; uIt++ )
1749 for ( vIt = 0; vIt < hlpV; vIt++ )
1751 for ( wIt = 0; wIt < hlpW; wIt++ )
1754 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1757 if ( maskData[arrayPos][0] > mapThresholdPlus )
1759 tmpIn[arrayPos][0] = 1.0;
1764 tmpIn[arrayPos][0] = 0.0;
1766 for (
int uCh = -addPoints; uCh <= addPoints; uCh++ )
1768 if ( breakOut ) {
break; }
1769 for (
int vCh = -addPoints; vCh <= addPoints; vCh++ )
1771 if ( breakOut ) {
break; }
1772 for (
int wCh = -addPoints; wCh <= addPoints; wCh++ )
1774 if ( breakOut ) {
break; }
1775 if ( ( uCh == 0 ) && ( vCh == 0 ) && wCh == 0 ) {
continue; }
1781 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= hlpU ) { newU -= hlpU; }
1782 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= hlpV ) { newV -= hlpV; }
1783 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= hlpW ) { newW -= hlpW; }
1785 arrPosSearch = newW + hlpW * ( newV + hlpV * newU );
1787 if ( maskData[arrPosSearch][0] > mapThresholdPlus )
1789 tmpIn[arrayPos][0] = 1.0;
1800 for ( uIt = 0; uIt < hlpU; uIt++ )
1802 for ( vIt = 0; vIt < hlpV; vIt++ )
1804 for ( wIt = 0; wIt < hlpW; wIt++ )
1807 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1810 if ( tmpIn[arrayPos][0] == 0.0 )
1812 this->_densityMapCor[arrayPos] = 0.0;
1821 delete[] maskDataInv;
1822 maskDataInv =
nullptr;
1829 fftw_destroy_plan ( p );
1830 fftw_destroy_plan ( pMaskInv );
1858 std::vector< std::vector<int> > clusters = this->
findMapIslands ( hlpU, hlpV, hlpW, this->_densityMapCor );
1862 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1864 maxVolume = std::max ( maxVolume, static_cast<int> ( clusters.at(iter).size() ) );
1872 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1874 totVol += clusters.at(iter).size();
1875 if ( static_cast<double> ( clusters.at(iter).size() ) > ( 0.8 * maxVolume ) )
1877 volTop80 += clusters.at(iter).size();
1879 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.1 * maxVolume ) )
1883 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.2 * maxVolume ) )
1885 volLow20 += clusters.at(iter).size();
1890 if ( ( fracLess10 != 0 ) || ( clusters.size() > 5 ) )
1892 if ( ( ( static_cast<double> ( fracLess10 ) / static_cast<double> ( clusters.size() ) ) > 0.5 ) ||
1893 ( ( static_cast<double> ( volTop80 ) /
static_cast<double> ( totVol ) ) < 0.9 ) ||
1894 ( ( static_cast<double> ( volLow20 ) /
static_cast<double> ( totVol ) ) > 0.1 ) )
1906 std::cout <<
">>>>>>>> Cluster check started." << std::endl;
1910 double *tmpIn =
new double[hlpU * hlpV * hlpW];
1911 std::vector<int> removedClusters;
1913 for (
unsigned int i = 0; i < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); i++ )
1915 tmpIn[i] = this->_densityMapCor[i];
1916 this->_densityMapCor[i] = 0.0;
1919 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1921 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.3 * static_cast<double> ( maxVolume ) ) )
1927 removedClusters.emplace_back ( iter );
1928 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clusters.at(iter).size() ); it++ )
1930 this->_densityMapCor[clusters.at(iter).at(it)] = tmpIn[clusters.at(iter).at(it)];
1936 int noPoints = std::ceil ( 3.0 / std::max ( this->_xRange / hlpU, std::max ( this->_yRange / hlpV, this->_zRange / hlpW ) ) );
1939 bool addPoint =
false;
1941 int hlpUIt, hlpVIt, hlpWIt;
1943 for (
unsigned int rIt = 0; rIt < static_cast<unsigned int> ( removedClusters.size() ); rIt++ )
1945 for (
int rPt = 0; rPt < static_cast<int> ( clusters.at(removedClusters.at(rIt)).size() ); rPt++ )
1948 uIt = ( clusters.at(removedClusters.at(rIt)).at(rPt) / ( hlpW * hlpV ) ) % hlpW;
1949 vIt =
static_cast<int> ( std::floor ( clusters.at(removedClusters.at(rIt)).at(rPt) / hlpW ) ) % hlpV;
1950 wIt = clusters.at(removedClusters.at(rIt)).at(rPt) - ( uIt * hlpW * hlpV ) - ( vIt * hlpW );
1953 for (
int newX = uIt-noPoints; newX <= uIt+noPoints; newX++ )
1955 if ( addPoint ) {
break; }
1956 for (
int newY = vIt-noPoints; newY <= vIt+noPoints; newY++ )
1958 if ( addPoint ) {
break; }
1959 for (
int newZ = wIt-noPoints; newZ <= wIt+noPoints; newZ++ )
1961 if ( ( newX == uIt ) && ( newY == vIt ) && ( newZ == wIt ) ) {
continue; }
1967 if ( hlpUIt < 0 ) { hlpUIt += hlpU; }
if ( hlpUIt >= hlpU ) { hlpUIt -= hlpU; }
1968 if ( hlpVIt < 0 ) { hlpVIt += hlpV; }
if ( hlpVIt >= hlpV ) { hlpVIt -= hlpV; }
1969 if ( hlpWIt < 0 ) { hlpWIt += hlpW; }
if ( hlpWIt >= hlpW ) { hlpWIt -= hlpW; }
1971 arrPos2 = hlpWIt + hlpW * ( hlpVIt + hlpV * hlpUIt );
1972 if ( this->_densityMapCor[arrPos2] > 0.0 ) { addPoint =
true;
break; }
1979 arrPos = wIt + hlpW * ( vIt + hlpV * uIt );
1980 this->_densityMapCor[arrPos] = -999.999;
1985 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
1987 if ( this->_densityMapCor[iter] == -999.999 )
1989 this->_densityMapCor[iter] = tmpIn[iter];
2017 this->_xFrom += xShift;
2018 this->_xTo += xShift;
2019 this->_yFrom += yShift;
2020 this->_yTo += yShift;
2021 this->_zFrom += zShift;
2022 this->_zTo += zShift;
2044 if ( ( this->_xSamplingRate == matchTo->_xSamplingRate ) && ( this->_ySamplingRate == matchTo->_ySamplingRate ) && ( this->_zSamplingRate == matchTo->_zSamplingRate ) )
2047 double *hlpMap =
new double [(matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1)];
2049 for (
int uIt = 0; uIt < static_cast<int> (matchTo->_maxMapU+1); uIt++ )
2051 for (
int vIt = 0; vIt < static_cast<int> (matchTo->_maxMapV+1); vIt++ )
2053 for (
int wIt = 0; wIt < static_cast<int> (matchTo->_maxMapW+1); wIt++ )
2055 arrPos = wIt + (matchTo->_maxMapW+1) * ( vIt + (matchTo->_maxMapV+1) * uIt );
2056 hlpPos = wIt + (this->_maxMapW+1) * ( vIt + (this->_maxMapV+1) * uIt );
2057 hlpMap[arrPos] = this->_densityMapCor[hlpPos];
2063 delete[] this->_densityMapCor;
2064 this->_densityMapCor =
new double [(matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1)];
2065 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1) ); iter++ )
2067 this->_densityMapCor[iter] = hlpMap[iter];
2072 this->_maxMapU = matchTo->_maxMapU;
2073 this->_maxMapV = matchTo->_maxMapV;
2074 this->_maxMapW = matchTo->_maxMapW;
2076 this->_xFrom = matchTo->_xFrom;
2077 this->_yFrom = matchTo->_yFrom;
2078 this->_zFrom = matchTo->_zFrom;
2080 this->_xTo = matchTo->_xTo;
2081 this->_yTo = matchTo->_yTo;
2082 this->_zTo = matchTo->_zTo;
2084 this->_xRange = matchTo->_xRange;
2085 this->_yRange = matchTo->_yRange;
2086 this->_zRange = matchTo->_zRange;
2094 double *hlpMap =
new double [(matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1)];
2104 bool xFound =
false;
2105 bool yFound =
false;
2106 bool zFound =
false;
2108 std::array<double,4> p000, p001, p010, p011, p100, p101, p110, p111;
2109 std::array<double,3> p00, p01, p10, p11;
2110 std::array<double,2> p0, p1;
2113 for (
int uIt = 0; uIt < static_cast<int> (matchTo->_maxMapU+1); uIt++ )
2115 for (
int vIt = 0; vIt < static_cast<int> (matchTo->_maxMapV+1); vIt++ )
2117 for (
int wIt = 0; wIt < static_cast<int> (matchTo->_maxMapW+1); wIt++ )
2120 arrPos = wIt + (matchTo->_maxMapW+1) * ( vIt + (matchTo->_maxMapV+1) * uIt );
2130 newX =
static_cast<double> ( uIt ) * matchTo->_xSamplingRate;
2131 newY = static_cast<double> ( vIt ) * matchTo->_ySamplingRate;
2132 newZ =
static_cast<double> ( wIt ) * matchTo->_zSamplingRate;
2136 for (
int iter = 0; iter < static_cast<int> (this->_maxMapU+1); iter++ )
2138 if ( ( iter * this->_xSamplingRate ) <= newX )
2144 if ( !xFound ) { hlpMap[arrPos] = 0.0;
continue; }
2147 for (
int iter = 0; iter < static_cast<int> (this->_maxMapV+1); iter++ )
2149 if ( ( iter * this->_ySamplingRate ) <= newY )
2155 if ( !yFound ) { hlpMap[arrPos] = 0.0;
continue; }
2158 for (
int iter = 0; iter < static_cast<int> (this->_maxMapW+1); iter++ )
2160 if ( ( iter * this->_zSamplingRate ) <= newZ )
2166 if ( !zFound ) { hlpMap[arrPos] = 0.0;
continue; }
2168 if ( ( oldX == static_cast<int> (this->_maxMapU) ) && ( ( (oldX+1) * this->_xSamplingRate ) > newX ) )
2175 for (
int iter = 0; iter < static_cast<int> (this->_maxMapU+1); iter++ )
2177 if ( ( iter * this->_xSamplingRate ) > newX )
2184 if ( !xFound ) { hlpMap[arrPos] = 0.0;
continue; }
2187 if ( ( oldY == static_cast<int> (this->_maxMapV) ) && ( ( (oldY+1) * this->_ySamplingRate ) > newY ) )
2194 for (
int iter = 0; iter < static_cast<int> (this->_maxMapV+1); iter++ )
2196 if ( ( iter * this->_ySamplingRate ) > newY )
2203 if ( !yFound ) { hlpMap[arrPos] = 0.0;
continue; }
2206 if ( ( oldZ == static_cast<int> (this->_maxMapW) ) && ( ( (oldZ+1) * this->_zSamplingRate ) > newZ ) )
2213 for (
int iter = 0; iter < static_cast<int> (this->_maxMapW+1); iter++ )
2215 if ( ( iter * this->_zSamplingRate ) > newZ )
2222 if ( !zFound ) { hlpMap[arrPos] = 0.0;
continue; }
2229 hlpPos = p000[2] + (this->_maxMapW+1) * ( p000[1] + (this->_maxMapV+1) * p000[0] );
2230 p000[3] = this->_densityMapCor[hlpPos];
2235 hlpPos = p001[2] + (this->_maxMapW+1) * ( p001[1] + (this->_maxMapV+1) * p001[0] );
2236 p001[3] = this->_densityMapCor[hlpPos];
2241 hlpPos = p010[2] + (this->_maxMapW+1) * ( p010[1] + (this->_maxMapV+1) * p010[0] );
2242 p010[3] = this->_densityMapCor[hlpPos];
2247 hlpPos = p011[2] + (this->_maxMapW+1) * ( p011[1] + (this->_maxMapV+1) * p011[0] );
2248 p011[3] = this->_densityMapCor[hlpPos];
2253 hlpPos = p100[2] + (this->_maxMapW+1) * ( p100[1] + (this->_maxMapV+1) * p100[0] );
2254 p100[3] = this->_densityMapCor[hlpPos];
2259 hlpPos = p101[2] + (this->_maxMapW+1) * ( p101[1] + (this->_maxMapV+1) * p101[0] );
2260 p101[3] = this->_densityMapCor[hlpPos];
2265 hlpPos = p110[2] + (this->_maxMapW+1) * ( p110[1] + (this->_maxMapV+1) * p110[0] );
2266 p110[3] = this->_densityMapCor[hlpPos];
2271 hlpPos = p111[2] + (this->_maxMapW+1) * ( p111[1] + (this->_maxMapV+1) * p111[0] );
2272 p111[3] = this->_densityMapCor[hlpPos];
2275 xd = 1.0 - ( ( newX - (
static_cast<double> ( oldX ) * this->_xSamplingRate ) ) / matchTo->_xSamplingRate );
2276 p00[0] = p000[1]; p00[1] = p000[2]; p00[2] = ( xd * p000[3] ) + ( (1.0 - xd) * p100[3] );
2277 p01[0] = p001[1]; p01[1] = p001[2]; p01[2] = ( xd * p001[3] ) + ( (1.0 - xd) * p101[3] );
2278 p10[0] = p010[1]; p10[1] = p010[2]; p10[2] = ( xd * p010[3] ) + ( (1.0 - xd) * p110[3] );
2279 p11[0] = p011[1]; p11[1] = p011[2]; p11[2] = ( xd * p011[3] ) + ( (1.0 - xd) * p111[3] );
2281 yd = 1.0 - ( ( newY - (
static_cast<double> ( oldY ) * this->_ySamplingRate ) ) / matchTo->_ySamplingRate );
2282 p0[0] = p00[1]; p0[1] = ( yd * p00[2] ) + ( (1.0 - yd) * p10[2] );
2283 p1[0] = p01[1]; p1[1] = ( yd * p01[2] ) + ( (1.0 - yd) * p11[2] );
2285 zd = 1.0 - ( ( newZ - (
static_cast<double> ( oldZ ) * this->_zSamplingRate ) ) / matchTo->_zSamplingRate );
2286 hlpMap[arrPos] = ( zd * p0[1] ) + ( (1.0 - zd) * p1[1] );
2292 delete[] this->_densityMapCor;
2293 this->_densityMapCor =
new double [(matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1)];
2294 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (matchTo->_maxMapU+1) * (matchTo->_maxMapV+1) * (matchTo->_maxMapW+1) ); iter++ )
2296 this->_densityMapCor[iter] = hlpMap[iter];
2301 this->_maxMapU = matchTo->_maxMapU;
2302 this->_maxMapV = matchTo->_maxMapV;
2303 this->_maxMapW = matchTo->_maxMapW;
2305 this->_xFrom = matchTo->_xFrom;
2306 this->_yFrom = matchTo->_yFrom;
2307 this->_zFrom = matchTo->_zFrom;
2309 this->_xTo = matchTo->_xTo;
2310 this->_yTo = matchTo->_yTo;
2311 this->_zTo = matchTo->_zTo;
2313 this->_xRange = matchTo->_xRange;
2314 this->_yRange = matchTo->_yRange;
2315 this->_zRange = matchTo->_zRange;
2338 int hlpU = this->_maxMapU + 1;
2339 int hlpV = this->_maxMapV + 1;
2340 int hlpW = this->_maxMapW + 1;
2346 double exponent = 0.0;
2347 double trCoeffReal = 0.0;
2348 double trCoeffImag = 0.0;
2349 double normFactor =
static_cast<double> ( hlpU * hlpV * hlpW );
2350 fftw_complex *translatedMap =
new fftw_complex [hlpU * hlpV * hlpW];
2351 fftw_complex *fCoeffs =
new fftw_complex [hlpU * hlpV * hlpW];
2352 std::array<double,2> hlpArr;
2353 fftw_plan planForwardFourier;
2354 fftw_plan planBackwardFourier;
2358 planForwardFourier = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, translatedMap, fCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
2359 planBackwardFourier = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, fCoeffs, translatedMap, FFTW_BACKWARD, FFTW_ESTIMATE );
2362 if ( this->_densityMapCor ==
nullptr )
2364 for (
int uIt = 0; uIt < hlpU; uIt++ )
2366 for (
int vIt = 0; vIt < hlpV; vIt++ )
2368 for (
int wIt = 0; wIt < hlpW; wIt++ )
2370 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2372 translatedMap[arrayPos][0] = this->_densityMapMap[arrayPos];
2373 translatedMap[arrayPos][1] = 0.0;
2380 for (
int uIt = 0; uIt < hlpU; uIt++ )
2382 for (
int vIt = 0; vIt < hlpV; vIt++ )
2384 for (
int wIt = 0; wIt < hlpW; wIt++ )
2386 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2388 translatedMap[arrayPos][0] = this->_densityMapCor[arrayPos];
2389 translatedMap[arrayPos][1] = 0.0;
2396 fftw_execute ( planForwardFourier );
2398 for (
int uIt = 0; uIt < hlpU; uIt++ )
2400 for (
int vIt = 0; vIt < hlpV; vIt++ )
2402 for (
int wIt = 0; wIt < hlpW; wIt++ )
2405 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2406 real = fCoeffs[arrayPos][0];
2407 imag = fCoeffs[arrayPos][1];
2410 if ( uIt > ((hlpU+1) / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
2411 if ( vIt > ((hlpV+1) / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
2412 if ( wIt > ((hlpW+1) / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
2415 exponent = ( ( ( static_cast <
double> ( h ) / this->_xRange ) * xShift ) +
2416 ( ( static_cast <double> ( k ) / this->_yRange ) * yShift ) +
2417 ( ( static_cast <
double> ( l ) / this->_zRange ) * zShift ) ) * 2.0 * M_PI;
2419 trCoeffReal = cos ( exponent );
2420 trCoeffImag = sin ( exponent );
2422 hlpArr = ProSHADE_internal_misc::complexMultiplication ( &real, &imag, &trCoeffReal, &trCoeffImag );
2425 fCoeffs[arrayPos][0] = hlpArr[0] / normFactor;
2426 fCoeffs[arrayPos][1] = hlpArr[1] / normFactor;
2432 fftw_execute ( planBackwardFourier );
2435 if ( this->_densityMapCor ==
nullptr )
2437 for (
int uIt = 0; uIt < hlpU; uIt++ )
2439 for (
int vIt = 0; vIt < hlpV; vIt++ )
2441 for (
int wIt = 0; wIt < hlpW; wIt++ )
2443 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2444 this->_densityMapMap[arrayPos] =
static_cast<float> ( translatedMap[arrayPos][0] );
2451 for (
int uIt = 0; uIt < hlpU; uIt++ )
2453 for (
int vIt = 0; vIt < hlpV; vIt++ )
2455 for (
int wIt = 0; wIt < hlpW; wIt++ )
2457 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2458 this->_densityMapCor[arrayPos] = translatedMap[arrayPos][0];
2465 fftw_destroy_plan ( planForwardFourier );
2466 fftw_destroy_plan ( planBackwardFourier );
2467 delete[] translatedMap;
2493 double maskBlurFactor,
2494 bool maskBlurFactorGiven,
2498 this->_inputFileName = fileName;
2499 this->_maxExtraCellularSpace = extraCS;
2502 CMap_io::CMMFile *mapFile =
nullptr;
2503 float *cell =
nullptr;
2505 int *order =
nullptr;
2506 int *orig =
nullptr;
2508 double cornerAvg = 0.0;
2509 double centralAvg = 0.0;
2510 double cornerCount = 0.0;
2511 double centralCount = 0.0;
2514 std::array<double,6> ret;
2517 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
2518 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
2519 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
2520 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
2522 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) )
2524 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
2528 std::stringstream hlpSS;
2529 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2530 rvapi_set_text ( hlpSS.str().c_str(),
2544 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
2545 if ( mapFile ==
nullptr )
2547 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and curruption of the file. Terminating..." << std::endl;
2551 std::stringstream hlpSS;
2552 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file " << fileName <<
".</font>";
2553 rvapi_set_text ( hlpSS.str().c_str(),
2566 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
2567 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
2568 CMap_io::ccp4_cmap_get_order ( mapFile, order );
2569 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
2574 std::cout <<
">> Map loaded." << std::endl;
2578 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
2579 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
2580 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
2583 this->_xRange = cell[0];
2584 this->_yRange = cell[1];
2585 this->_zRange = cell[2];
2588 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
2591 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
2592 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
2593 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
2595 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
2596 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
2597 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
2599 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
2600 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
2601 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
2604 this->_xTo = this->_xFrom + this->_maxMapU;
2605 this->_yTo = this->_yFrom + this->_maxMapV;
2606 this->_zTo = this->_zFrom + this->_maxMapW;
2609 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
2610 if ( this->_densityMapMap ==
nullptr )
2612 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
2616 std::stringstream hlpSS;
2617 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2618 rvapi_set_text ( hlpSS.str().c_str(),
2632 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
2633 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
2635 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
2639 std::stringstream hlpSS;
2640 hlpSS <<
"<font color=\"red\">" <<
"Cannot read from the map file. The map file mode is neither 0, nor 2. Other map modes are not supported at the moment." <<
"</font>";
2641 rvapi_set_text ( hlpSS.str().c_str(),
2656 int newU, newV, newW;
2659 for (
int iter = 0; iter < 3; iter++ )
2661 maxLim[iter] = orig[iter] + dim[iter] - 1;
2662 XYZOrder[order[iter]-1] = iter;
2666 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
2667 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
2668 std::vector<float> section( midDimSize );
2673 for ( iters[2] = orig[2]; iters[2] <= maxLim[2]; iters[2]++ )
2676 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
2680 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
2682 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
2686 for ( iters[1] = orig[1]; iters[1] <= maxLim[1]; iters[1]++ )
2688 for ( iters[0] = orig[0]; iters[0] <= maxLim[0]; iters[0]++ )
2690 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
2691 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
2692 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
2693 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
2694 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
2700 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
2701 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
2703 vals.at(iter) = this->_densityMapMap[iter];
2705 std::sort ( vals.begin(), vals.end() );
2708 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
2709 this->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - this->_mapMean * this->_mapMean );
2713 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
2714 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
2715 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
2717 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
2719 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
2721 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
2724 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
2727 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
2728 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
2729 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
2731 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
2732 centralCount += 1.0;
2734 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
2735 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2736 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
2737 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2738 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
2739 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2740 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
2741 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
2743 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
2750 cornerAvg /= cornerCount;
2751 centralAvg /= centralCount;
2754 if ( cornerAvg > centralAvg )
2757 float* hlpMap =
nullptr;
2758 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
2759 if ( hlpMap ==
nullptr )
2761 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
2765 std::stringstream hlpSS;
2766 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2767 rvapi_set_text ( hlpSS.str().c_str(),
2779 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
2781 hlpMap[iter] = this->_densityMapMap[iter];
2785 unsigned int hlpPos;
2786 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
2788 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
2790 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
2793 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
2794 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
2795 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
2797 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
2798 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
2801 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
2812 std::cout <<
">>>>> Density moved from corners to center, if applicable." << std::endl;
2817 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
2821 std::stringstream hlpSS;
2822 hlpSS <<
"<font color=\"red\">" <<
"Detected non-orthogonal map. Currently, only the P1 maps are supported." <<
"</font>";
2823 rvapi_set_text ( hlpSS.str().c_str(),
2838 std::stringstream hlpSS;
2839 hlpSS <<
"<font color=\"green\">" <<
"Structure " << settings->
structFiles.at(0) <<
" read in." <<
"</font>";
2840 rvapi_set_text ( hlpSS.str().c_str(),
2852 rvapi_add_section (
"OrigHeaderSection",
2853 "Original structure header",
2863 std::stringstream hlpSS;
2864 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
2865 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2871 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length(),
2872 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length(),
2873 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ) );
2874 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length(),
2875 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length(),
2876 ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ) );
2877 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length(),
2878 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length(),
2879 ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ) );
2880 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length(),
2881 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length(),
2882 ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ) );
2883 int CAMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( cell[3], prec ).length(),
2884 std::max ( ProSHADE_internal_misc::to_string_with_precision ( cell[4], prec ).length(),
2885 ProSHADE_internal_misc::to_string_with_precision ( cell[5], prec ).length() ) );
2886 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, std::max ( CDMAX, CAMAX ) ) ) );
2887 if ( spacer < 5 ) { spacer = 5; }
2889 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( this->_maxMapU+1 );
2890 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length() ); iter++ )
2896 hlpSS << std::showpos << static_cast<int> ( this->_maxMapV+1 );
2897 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length() ); iter++ )
2903 hlpSS << std::showpos << static_cast<int> ( this->_maxMapW+1 );
2904 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ); iter++ )
2910 rvapi_set_text ( hlpSS.str().c_str(),
2911 "OrigHeaderSection",
2918 hlpSS.str ( std::string ( ) );
2919 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
2920 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2925 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xFrom;
2926 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length() ); iter++ )
2932 hlpSS << std::showpos << this->_xTo;
2933 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length() ); iter++ )
2939 hlpSS << std::showpos << this->_yFrom;
2940 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length() ); iter++ )
2946 hlpSS << std::showpos << this->_yTo;
2947 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length() ); iter++ )
2953 hlpSS << std::showpos <<
" " << this->_zFrom;
2954 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ); iter++ )
2960 hlpSS << std::showpos << this->_zTo;
2961 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ); iter++ )
2967 rvapi_set_text ( hlpSS.str().c_str(),
2968 "OrigHeaderSection",
2975 hlpSS.str ( std::string ( ) );
2976 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
2977 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2982 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xRange;
2983 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length() ); iter++ )
2989 hlpSS << std::showpos << this->_yRange;
2990 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length() ); iter++ )
2996 hlpSS << std::showpos << this->_zRange;
2997 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ); iter++ )
3003 rvapi_set_text ( hlpSS.str().c_str(),
3004 "OrigHeaderSection",
3011 hlpSS.str ( std::string ( ) );
3012 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
3013 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3018 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << cell[3];
3019 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[3], prec ).length() ); iter++ )
3025 hlpSS << std::showpos << cell[4];
3026 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[4], prec ).length() ); iter++ )
3032 hlpSS << std::showpos << cell[5];
3033 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[5], prec ).length() ); iter++ )
3039 rvapi_set_text ( hlpSS.str().c_str(),
3040 "OrigHeaderSection",
3047 hlpSS.str ( std::string ( ) );
3048 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
3049 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3054 if ( XYZOrder[0] == 0 ) { hlpSS <<
" X"; }
3055 else if ( XYZOrder[0] == 1 ) { hlpSS <<
" Y"; }
3056 else { hlpSS <<
" Z"; }
3057 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3063 if ( XYZOrder[1] == 0 ) { hlpSS <<
"X"; }
3064 else if ( XYZOrder[1] == 1 ) { hlpSS <<
"Y"; }
3065 else { hlpSS <<
"Z"; }
3066 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3072 if ( XYZOrder[2] == 0 ) { hlpSS <<
"X"; }
3073 else if ( XYZOrder[2] == 1 ) { hlpSS <<
"Y"; }
3074 else { hlpSS <<
"Z"; }
3075 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3081 rvapi_set_text ( hlpSS.str().c_str(),
3082 "OrigHeaderSection",
3092 ret[0] = this->_maxMapU + 1;
3093 ret[1] = this->_maxMapV + 1;
3094 ret[2] = this->_maxMapW + 1;
3097 if ( cell !=
nullptr )
3102 if ( dim !=
nullptr )
3107 if ( order !=
nullptr )
3112 if ( orig !=
nullptr )
3119 CMap_io::ccp4_cmap_close ( mapFile );
3122 int hlpU = ( this->_maxMapU + 1 );
3123 int hlpV = ( this->_maxMapV + 1 );
3124 int hlpW = ( this->_maxMapW + 1 );
3127 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
3130 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
3132 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
3134 if ( this->_densityMapMap[iter] == this->_densityMapMap[iter] )
3137 this->_densityMapCor[iter] = this->_densityMapMap[iter];
3142 this->_densityMapCor[iter] = 0.0;
3147 std::cout <<
">>>>> Map normalised." << std::endl;
3151 double *tmpMp =
new double[hlpU * hlpV * hlpW];
3152 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
3154 tmpMp[iter] = this->_densityMapCor[iter];
3157 bool notTooManyIslads =
true;
3158 double blFr = 150.0;
3160 while ( notTooManyIslads )
3164 if ( maskBlurFactorGiven )
3166 blFr = maskBlurFactor;
3167 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
3172 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
3177 std::cout <<
">>>>>>>> Island detection started." << std::endl;
3180 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
3184 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
3186 if ( notTooManyIslads )
3190 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
3193 if ( blFr <= 500.0 )
3195 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
3197 this->_densityMapCor[iter] = tmpMp[iter];
3205 std::cout << std::endl;
3212 std::cout <<
"!!! ProSHADE WARNING !!! Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." << std::endl;
3216 std::stringstream hlpSS;
3217 hlpSS <<
"<font color=\"orange\">" <<
"Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." <<
"</font>";
3218 rvapi_set_text ( hlpSS.str().c_str(),
3233 if ( !maskBlurFactorGiven )
3235 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
3237 this->_densityMapCor[iter] = tmpMp[iter];
3240 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
3245 std::cout <<
">> Map masked." << std::endl;
3250 std::stringstream hlpSS;
3251 hlpSS <<
"<font color=\"green\">" <<
"Map masked." <<
"</font>";
3252 rvapi_set_text ( hlpSS.str().c_str(),
3270 int maxXTot = hlpU/2;
3271 int minXTot = hlpU/2;
3272 int maxYTot = hlpV/2;
3273 int minYTot = hlpV/2;
3274 int maxZTot = hlpW/2;
3275 int minZTot = hlpW/2;
3277 for (
int uIt = 0; uIt < hlpU; uIt++ )
3279 for (
int vIt = 0; vIt < hlpV; vIt++ )
3281 for (
int wIt = 0; wIt < hlpW; wIt++ )
3283 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
3285 if ( this->_densityMapCor[coordPos] > 0.0 )
3287 maxX = std::max ( maxX, uIt );
3288 minX = std::min ( minX, uIt );
3289 maxY = std::max ( maxY, vIt );
3290 minY = std::min ( minY, vIt );
3291 maxZ = std::max ( maxZ, wIt );
3292 minZ = std::min ( minZ, wIt );
3294 maxXTot = std::max ( maxXTot, uIt );
3295 minXTot = std::min ( minXTot, uIt );
3296 maxYTot = std::max ( maxYTot, vIt );
3297 minYTot = std::min ( minYTot, vIt );
3298 maxZTot = std::max ( maxZTot, wIt );
3299 minZTot = std::min ( minZTot, wIt );
3305 int newUStart =
static_cast<int> ( this->_xFrom + ( minXTot + minX ) );
3306 int newUEnd =
static_cast<int> ( this->_xTo - ( maxXTot - maxX ) );
3307 int newVStart =
static_cast<int> ( this->_yFrom + ( minYTot + minY ) );
3308 int newVEnd =
static_cast<int> ( this->_yTo - ( maxYTot - maxY ) );
3309 int newWStart =
static_cast<int> ( this->_zFrom + ( minZTot + minZ ) );
3310 int newWEnd =
static_cast<int> ( this->_zTo - ( maxZTot - maxZ ) );
3313 if ( this->_maxExtraCellularSpace > 0.0 )
3315 int extraPTs =
static_cast<int> ( std::ceil ( this->_maxExtraCellularSpace / ( static_cast<double> ( this->_maxMapRange ) / static_cast<double> ( std::max ( hlpU, std::max ( hlpV, hlpW ) ) ) ) ) );
3317 if ( (newUStart - extraPTs) >
static_cast<int> ( this->_xFrom ) ) { newUStart -=
static_cast<int> ( extraPTs ); }
3318 if ( (newVStart - extraPTs) >
static_cast<int> ( this->_yFrom ) ) { newVStart -=
static_cast<int> ( extraPTs ); }
3319 if ( (newWStart - extraPTs) >
static_cast<int> ( this->_zFrom ) ) { newWStart -=
static_cast<int> ( extraPTs ); }
3320 if ( (newUEnd + extraPTs) <
static_cast<int> ( this->_xTo ) ) { newUEnd +=
static_cast<int> ( extraPTs ); }
3321 if ( (newVEnd + extraPTs) <
static_cast<int> ( this->_yTo ) ) { newVEnd +=
static_cast<int> ( extraPTs ); }
3322 if ( (newWEnd + extraPTs) <
static_cast<int> ( this->_zTo ) ) { newWEnd +=
static_cast<int> ( extraPTs ); }
3326 if ( this->_densityMapCor !=
nullptr )
3328 delete[] this->_densityMapCor;
3329 this->_densityMapCor =
nullptr;
3333 int newXDim = newUEnd - newUStart + 1;
3334 int newYDim = newVEnd - newVStart + 1;
3335 int newZDim = newWEnd - newWStart + 1;
3337 if ( ( this->_xFrom < 0 ) && ( ( this->_xFrom + newUStart ) >= 0 ) ) { newXDim += 1; }
3338 if ( ( this->_yFrom < 0 ) && ( ( this->_yFrom + newVStart ) >= 0 ) ) { newYDim += 1; }
3339 if ( ( this->_zFrom < 0 ) && ( ( this->_zFrom + newWStart ) >= 0 ) ) { newZDim += 1; }
3341 this->_densityMapCor =
new double [newXDim * newYDim * newZDim];
3344 int newU, newV, newW;
3345 for (
int uIt = newUStart; uIt <= newUEnd; uIt++ )
3347 for (
int vIt = newVStart; vIt <= newVEnd; vIt++ )
3349 for (
int wIt = newWStart; wIt <= newWEnd; wIt++ )
3351 newU = uIt - newUStart;
3352 newV = vIt - newVStart;
3353 newW = wIt - newWStart;
3354 hlpPos = newW + newZDim * ( newV + newYDim * newU );
3356 newU = uIt - this->_xFrom;
3357 newV = vIt - this->_yFrom;
3358 newW = wIt - this->_zFrom;
3359 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
3361 this->_densityMapCor[hlpPos] = tmpMp[arrPos];
3368 std::cout <<
"Map re-boxed." << std::endl;
3373 std::stringstream hlpSS;
3374 hlpSS <<
"<font color=\"green\">" <<
"Map re-boxed." <<
"</font>";
3375 rvapi_set_text ( hlpSS.str().c_str(),
3389 this->_xFrom = newUStart;
3390 this->_yFrom = newVStart;
3391 this->_zFrom = newWStart;
3393 this->_xTo = newUEnd;
3394 this->_yTo = newVEnd;
3395 this->_zTo = newWEnd;
3397 this->_xSamplingRate =
static_cast<double> ( this->_xRange ) / static_cast<double> ( hlpU );
3398 this->_ySamplingRate =
static_cast<double> ( this->_yRange ) / static_cast<double> ( hlpV );
3399 this->_zSamplingRate =
static_cast<double> ( this->_zRange ) / static_cast<double> ( hlpW );
3401 this->_xRange = this->_xSamplingRate * ( newXDim );
3402 this->_yRange = this->_ySamplingRate * ( newYDim );
3403 this->_zRange = this->_zSamplingRate * ( newZDim );
3405 this->_maxMapU = newXDim - 1;
3406 this->_maxMapV = newYDim - 1;
3407 this->_maxMapW = newZDim - 1;
3409 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
3410 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
3411 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
3414 if ( this->_densityMapMap !=
nullptr )
3416 delete this->_densityMapMap;
3417 this->_densityMapMap =
nullptr;
3423 rvapi_add_section (
"NewHeaderSection",
3424 "Re-boxed structure header",
3434 std::stringstream hlpSS;
3435 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
3436 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3442 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length(),
3443 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length(),
3444 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ) );
3445 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length(),
3446 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length(),
3447 ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ) );
3448 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length(),
3449 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length(),
3450 ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ) );
3451 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length(),
3452 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length(),
3453 ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ) );
3454 int CAMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length(),
3455 std::max ( ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length(),
3456 ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ) );
3457 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, std::max ( CDMAX, CAMAX ) ) ) );
3458 if ( spacer < 5 ) { spacer = 5; }
3460 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( this->_maxMapU+1 );
3461 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length() ); iter++ )
3467 hlpSS << std::showpos << static_cast<int> ( this->_maxMapV+1 );
3468 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length() ); iter++ )
3474 hlpSS << std::showpos << static_cast<int> ( this->_maxMapW+1 );
3475 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ); iter++ )
3481 rvapi_set_text ( hlpSS.str().c_str(),
3489 hlpSS.str ( std::string ( ) );
3490 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
3491 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3496 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xFrom;
3497 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length() ); iter++ )
3503 hlpSS << std::showpos << this->_xTo;
3504 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length() ); iter++ )
3510 hlpSS << std::showpos << this->_yFrom;
3511 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length() ); iter++ )
3517 hlpSS << std::showpos << this->_yTo;
3518 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length() ); iter++ )
3524 hlpSS << std::showpos <<
" " << this->_zFrom;
3525 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ); iter++ )
3531 hlpSS << std::showpos << this->_zTo;
3532 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ); iter++ )
3538 rvapi_set_text ( hlpSS.str().c_str(),
3546 hlpSS.str ( std::string ( ) );
3547 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
3548 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3553 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xRange;
3554 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length() ); iter++ )
3560 hlpSS << std::showpos << this->_yRange;
3561 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length() ); iter++ )
3567 hlpSS << std::showpos << this->_zRange;
3568 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ); iter++ )
3574 rvapi_set_text ( hlpSS.str().c_str(),
3582 hlpSS.str ( std::string ( ) );
3583 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
3584 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3589 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.000;
3590 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3596 hlpSS << std::showpos << 90.000;
3597 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3603 hlpSS << std::showpos << 90.000;
3604 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3610 rvapi_set_text ( hlpSS.str().c_str(),
3618 hlpSS.str ( std::string ( ) );
3619 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
3620 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3625 if ( XYZOrder[0] == 0 ) { hlpSS <<
" X"; }
3626 else if ( XYZOrder[0] == 1 ) { hlpSS <<
" Y"; }
3627 else { hlpSS <<
" Z"; }
3628 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3634 if ( XYZOrder[1] == 0 ) { hlpSS <<
"X"; }
3635 else if ( XYZOrder[1] == 1 ) { hlpSS <<
"Y"; }
3636 else { hlpSS <<
"Z"; }
3637 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3643 if ( XYZOrder[2] == 0 ) { hlpSS <<
"X"; }
3644 else if ( XYZOrder[2] == 1 ) { hlpSS <<
"Y"; }
3645 else { hlpSS <<
"Z"; }
3646 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3652 rvapi_set_text ( hlpSS.str().c_str(),
3663 ret[3] = this->_maxMapU + 1;
3664 ret[4] = this->_maxMapV + 1;
3665 ret[5] = this->_maxMapW + 1;
3706 double *minDensPreNorm,
3707 double *maxDensPreNorm,
3708 double *minDensPostNorm,
3709 double *maxDensPostNorm,
3710 double *postNormMean,
3711 double *postNormSdev,
3713 double* totalVolume,
3718 double *maskDensityRMS,
3719 double *allDensityRMS,
3720 std::array<double,3> *origRanges,
3721 std::array<double,3> *origDims,
3726 double maskBlurFactor,
3727 bool maskBlurFactorGiven,
3732 this->_inputFileName = fileName;
3735 CMap_io::CMMFile *mapFile =
nullptr;
3736 float *cell =
nullptr;
3738 int *order =
nullptr;
3739 int *orig =
nullptr;
3741 double cornerAvg = 0.0;
3742 double centralAvg = 0.0;
3743 double cornerCount = 0.0;
3744 double centralCount = 0.0;
3747 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
3748 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
3749 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
3750 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
3752 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) )
3754 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
3758 std::stringstream hlpSS;
3759 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3760 rvapi_set_text ( hlpSS.str().c_str(),
3774 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
3775 if ( mapFile ==
nullptr )
3777 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and curruption of the file. Terminating..." << std::endl;
3781 std::stringstream hlpSS;
3782 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file " << fileName <<
".</font>";
3783 rvapi_set_text ( hlpSS.str().c_str(),
3796 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
3797 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
3798 CMap_io::ccp4_cmap_get_order ( mapFile, order );
3799 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
3804 std::cout <<
">> Map loaded." << std::endl;
3808 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
3809 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
3810 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
3813 this->_xRange = cell[0];
3814 this->_yRange = cell[1];
3815 this->_zRange = cell[2];
3818 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
3821 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
3822 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
3823 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
3825 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
3826 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
3827 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
3829 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
3830 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
3831 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
3834 this->_xTo = this->_xFrom + this->_maxMapU;
3835 this->_yTo = this->_yFrom + this->_maxMapV;
3836 this->_zTo = this->_zFrom + this->_maxMapW;
3839 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
3840 if ( this->_densityMapMap ==
nullptr )
3842 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
3846 std::stringstream hlpSS;
3847 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3848 rvapi_set_text ( hlpSS.str().c_str(),
3862 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
3863 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
3865 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
3869 std::stringstream hlpSS;
3870 hlpSS <<
"<font color=\"red\">" <<
"Cannot read from the map file. The map mode is neither 0, nor 2. Other map modes are currently not supported." <<
"</font>";
3871 rvapi_set_text ( hlpSS.str().c_str(),
3888 int newU, newV, newW;
3891 for (
int iter = 0; iter < 3; iter++ )
3893 maxLim[iter] = orig[iter] + dim[iter] - 1;
3894 XYZOrder[order[iter]-1] = iter;
3898 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
3899 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
3900 std::vector<float> section( midDimSize );
3905 for ( iters[2] = orig[2]; iters[2] <= maxLim[2]; iters[2]++ )
3908 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
3912 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
3914 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
3918 for ( iters[1] = orig[1]; iters[1] <= maxLim[1]; iters[1]++ )
3920 for ( iters[0] = orig[0]; iters[0] <= maxLim[0]; iters[0]++ )
3922 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
3923 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
3924 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
3925 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
3926 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
3932 std::vector<double> vals;
3933 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
3935 if ( this->_densityMapMap[iter] != 0.0 )
3937 vals.emplace_back ( this->_densityMapMap[iter] );
3940 std::sort ( vals.begin(), vals.end() );
3942 *minDensPreNorm = vals.at(0);
3943 *maxDensPreNorm = vals.at(vals.size()-1);
3949 rvapi_add_section (
"ResultsSection",
3959 std::stringstream hlpSS;
3960 hlpSS <<
"<pre>" <<
"Min / Max density pre normalisation: ";
3961 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
3962 for (
int iter = 0; iter < hlpIt; iter++ )
3967 std::stringstream hlpSS2;
3968 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *minDensPreNorm * 1000.0 ) / 1000.0;
3969 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
3970 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
3971 hlpSS <<
" " << hlpSS2.str() <<
" / ";
3973 hlpSS2.str( std::string ( ) );
3974 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maxDensPreNorm * 1000.0 ) / 1000.0;
3975 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
3976 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
3977 hlpSS << hlpSS2.str() <<
"</pre>";
3979 rvapi_set_text ( hlpSS.str().c_str(),
3990 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
3991 this->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - this->_mapMean * this->_mapMean );
3995 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
3996 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
3997 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
3999 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
4001 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
4003 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
4006 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4009 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
4010 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
4011 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
4013 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
4014 centralCount += 1.0;
4016 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
4017 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
4018 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
4019 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
4020 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
4021 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
4022 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
4023 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
4025 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
4032 cornerAvg /= cornerCount;
4033 centralAvg /= centralCount;
4036 if ( cornerAvg > centralAvg )
4039 float* hlpMap =
nullptr;
4040 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
4041 if ( hlpMap ==
nullptr )
4043 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
4047 std::stringstream hlpSS;
4048 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
4049 rvapi_set_text ( hlpSS.str().c_str(),
4061 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
4063 hlpMap[iter] = this->_densityMapMap[iter];
4067 unsigned int hlpPos;
4068 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
4070 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
4072 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
4075 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
4076 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
4077 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
4079 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
4080 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4083 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
4094 std::cout <<
">>>>> Density moved from corners to center, if applicable." << std::endl;
4099 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
4103 std::stringstream hlpSS;
4104 hlpSS <<
"<font color=\"red\">" <<
"Detected non-orthogonal map. Currently, only the P1 maps are supported." <<
"</font>";
4105 rvapi_set_text ( hlpSS.str().c_str(),
4120 std::stringstream hlpSS;
4121 hlpSS <<
"<font color=\"green\">" <<
"Structure " << fileName <<
" read." <<
"</font>";
4122 rvapi_set_text ( hlpSS.str().c_str(),
4133 if ( cell !=
nullptr )
4138 if ( dim !=
nullptr )
4143 if ( order !=
nullptr )
4148 if ( orig !=
nullptr )
4155 CMap_io::ccp4_cmap_close ( mapFile );
4158 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
4159 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
4160 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
4162 bool addXOne =
false;
4163 bool addYOne =
false;
4164 bool addZOne =
false;
4167 (*origRanges)[0] = this->_xRange;
4168 (*origRanges)[1] = this->_yRange;
4169 (*origRanges)[2] = this->_zRange;
4171 (*origDims)[0] = this->_maxMapU;
4172 (*origDims)[1] = this->_maxMapV;
4173 (*origDims)[2] = this->_maxMapW;
4176 this->_maxExtraCellularSpace = extraCS;
4177 if ( this->_maxExtraCellularSpace != 0.0 )
4180 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
4181 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
4182 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
4184 if ( ( this->_xFrom >= 0 ) && ( ( this->_xFrom - xDiff ) < 0 ) ) { addXOne =
true; }
4185 if ( ( this->_yFrom >= 0 ) && ( ( this->_yFrom - yDiff ) < 0 ) ) { addYOne =
true; }
4186 if ( ( this->_zFrom >= 0 ) && ( ( this->_zFrom - zDiff ) < 0 ) ) { addZOne =
true; }
4188 this->_xRange += xDiff * this->_xSamplingRate;
4189 this->_yRange += yDiff * this->_ySamplingRate;
4190 this->_zRange += zDiff * this->_zSamplingRate;
4192 if ( xDiff % 2 != 0 )
4194 this->_xRange += this->_xSamplingRate;
4195 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
4197 if ( yDiff % 2 != 0 )
4199 this->_yRange += this->_ySamplingRate;
4200 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
4202 if ( zDiff % 2 != 0 )
4204 this->_zRange += this->_zSamplingRate;
4205 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
4212 this->_xFrom -= xDiff;
4213 this->_yFrom -= yDiff;
4214 this->_zFrom -= zDiff;
4216 this->_xTo += xDiff;
4217 this->_yTo += yDiff;
4218 this->_zTo += zDiff;
4220 this->_maxMapU = this->_xTo - this->_xFrom;
4221 this->_maxMapV = this->_yTo - this->_yFrom;
4222 this->_maxMapW = this->_zTo - this->_zFrom;
4224 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
4225 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
4226 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
4229 float *hlpMap =
nullptr;
4230 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
4231 if ( hlpMap ==
nullptr )
4233 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
4237 std::stringstream hlpSS;
4238 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
4239 rvapi_set_text ( hlpSS.str().c_str(),
4251 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
4256 unsigned int newU, newV, newW, hlpPos, arrPos;
4257 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
4259 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
4261 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
4263 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
4264 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
4265 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
4267 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4268 hlpMap[hlpPos] = 0.0;
4272 newU = (uIt - xDiff);
4273 newV = (vIt - yDiff);
4274 newW = (wIt - zDiff);
4276 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4277 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
4279 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
4286 if ( this->_densityMapMap !=
nullptr )
4288 free ( this->_densityMapMap );
4289 this->_densityMapMap =
nullptr;
4293 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
4294 if ( this->_densityMapMap ==
nullptr )
4296 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
4300 std::stringstream hlpSS;
4301 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
4302 rvapi_set_text ( hlpSS.str().c_str(),
4314 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
4316 this->_densityMapMap[iter] = hlpMap[iter];
4320 if ( hlpMap !=
nullptr )
4328 std::stringstream hlpSS;
4329 hlpSS <<
"<font color=\"green\">" <<
"Extra cell space added as required." <<
"</font>";
4330 rvapi_set_text ( hlpSS.str().c_str(),
4342 int hlpU = ( this->_maxMapU + 1 );
4343 int hlpV = ( this->_maxMapV + 1 );
4344 int hlpW = ( this->_maxMapW + 1 );
4348 unsigned int arrayPos = 0;
4350 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
4353 std::vector<double> vals;
4354 std::vector<double> valsWZ;
4356 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
4358 if ( this->_densityMapMap[iter] == this->_densityMapMap[iter] )
4361 if ( this->_densityMapMap[iter] != 0.0 )
4363 vals.emplace_back ( ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev );
4365 valsWZ.emplace_back ( ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev );
4367 this->_densityMapCor[iter] = ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev;
4372 this->_densityMapCor[iter] = 0.0;
4377 std::cout <<
">>>>> Map normalised." << std::endl;
4382 std::stringstream hlpSS;
4383 hlpSS <<
"<font color=\"green\">" <<
"Map normalisation complete." <<
"</font>";
4384 rvapi_set_text ( hlpSS.str().c_str(),
4402 std::sort ( vals.begin(), vals.end() );
4404 *minDensPostNorm = vals.at(0);
4405 *maxDensPostNorm = vals.at(vals.size()-1);
4407 *postNormMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
4408 *postNormSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - *postNormMean * *postNormMean );
4410 *allDensityRMS = 0.0;
4411 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( valsWZ.size() ); iter++ )
4413 *allDensityRMS += pow ( valsWZ.at(iter), 2.0 );
4415 *allDensityRMS /=
static_cast<double> ( valsWZ.size() - 1 );
4416 *allDensityRMS = sqrt ( *allDensityRMS );
4424 std::stringstream hlpSS;
4425 hlpSS <<
"<pre>" <<
"Mean (std. dev.) pre normalisation: ";
4426 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4427 for (
int iter = 0; iter < hlpIt; iter++ )
4432 std::stringstream hlpSS2;
4433 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( this->_mapMean * 1000.0 ) / 1000.0;
4434 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4435 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4436 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4438 hlpSS2.str( std::string ( ) );
4439 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( this->_mapSdev * 1000.0 ) / 1000.0;
4440 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4441 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4442 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4444 rvapi_set_text ( hlpSS.str().c_str(),
4451 hlpSS.str( std::string (
"<pre>" ) );
4452 for (
int iter = 0; iter < 70; iter++ )
4457 rvapi_set_text ( hlpSS.str().c_str(),
4464 hlpSS.str( std::string ( ) );
4465 hlpSS <<
"<pre>" <<
"Min / Max density post normalisation: ";
4466 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4467 for (
int iter = 0; iter < hlpIt; iter++ )
4472 hlpSS2.str( std::string ( ) );
4473 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *minDensPostNorm * 1000.0 ) / 1000.0;
4474 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4475 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4476 hlpSS <<
" " << hlpSS2.str() <<
" / ";
4478 hlpSS2.str( std::string ( ) );
4479 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maxDensPostNorm * 1000.0 ) / 1000.0;
4480 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4481 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4482 hlpSS << hlpSS2.str() <<
"</pre>";
4484 rvapi_set_text ( hlpSS.str().c_str(),
4491 hlpSS.str( std::string ( ) );
4492 hlpSS <<
"<pre>" <<
"Mean (std. dev.) post normalisation: ";
4493 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4494 for (
int iter = 0; iter < hlpIt; iter++ )
4499 hlpSS2.str( std::string ( ) );
4500 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *postNormMean * 1000.0 ) / 1000.0;
4501 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4502 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4503 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4505 hlpSS2.str( std::string ( ) );
4506 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *postNormSdev * 1000.0 ) / 1000.0;
4507 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4508 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4509 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4511 rvapi_set_text ( hlpSS.str().c_str(),
4518 hlpSS.str( std::string (
"<pre>" ) );
4519 for (
int iter = 0; iter < 70; iter++ )
4524 rvapi_set_text ( hlpSS.str().c_str(),
4535 this->_fromPDB =
false;
4536 if ( !this->_fromPDB )
4539 double *tmpMp =
new double[hlpU * hlpV * hlpW];
4540 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
4542 tmpMp[iter] = this->_densityMapCor[iter];
4545 bool notTooManyIslads =
true;
4546 double blFr = 150.0;
4548 while ( notTooManyIslads )
4552 if ( maskBlurFactorGiven )
4554 blFr = maskBlurFactor;
4555 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
4561 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
4566 std::cout <<
">>>>>>>> Island detection started." << std::endl;
4569 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
4571 if ( maskBlurFactorGiven )
4578 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
4580 if ( notTooManyIslads )
4584 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
4587 if ( blFr <= 500.0 )
4589 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
4591 this->_densityMapCor[iter] = tmpMp[iter];
4599 std::cout << std::endl;
4606 std::cout <<
"!!! ProSHADE WARNING !!! Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." << std::endl;
4610 std::stringstream hlpSS;
4611 hlpSS <<
"<font color=\"orange\">" <<
"Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." <<
"</font>";
4612 rvapi_set_text ( hlpSS.str().c_str(),
4630 std::cout <<
">> Map masked." << std::endl;
4635 std::stringstream hlpSS;
4636 hlpSS <<
"<font color=\"green\">" <<
"Map masking complete." <<
"</font>";
4637 rvapi_set_text ( hlpSS.str().c_str(),
4648 if ( this->_densityMapMap !=
nullptr )
4650 delete this->_densityMapMap;
4651 this->_densityMapMap =
nullptr;
4657 for ( uIt = 0; uIt < hlpU; uIt++ )
4659 for ( vIt = 0; vIt < hlpV; vIt++ )
4661 for ( wIt = 0; wIt < hlpW; wIt++ )
4663 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4664 if ( this->_densityMapCor[arrayPos] != 0.0 ) { vals.emplace_back ( this->_densityMapCor[arrayPos] ); }
4669 *maskVolume =
static_cast<double> ( vals.size() );
4670 *totalVolume = hlpU * hlpV * hlpW;
4672 std::sort ( vals.begin(), vals.end() );
4674 *maskMin = vals.at(0);
4675 *maskMax = vals.at(vals.size()-1);
4678 *maskMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
4679 *maskSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - *maskMean * *maskMean );
4681 *maskDensityRMS = 0.0;
4682 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( vals.size() ); iter++ )
4684 *maskDensityRMS += pow ( vals.at(iter), 2.0 );
4686 *maskDensityRMS /=
static_cast<double> ( vals.size() - 1 );
4687 *maskDensityRMS = sqrt ( *maskDensityRMS );
4694 std::stringstream hlpSS;
4695 hlpSS <<
"<pre>" <<
"Min / Max density after masking: ";
4696 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4697 for (
int iter = 0; iter < hlpIt; iter++ )
4702 std::stringstream hlpSS2;
4703 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMin * 1000.0 ) / 1000.0;
4704 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4705 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4706 hlpSS <<
" " << hlpSS2.str() <<
" / ";
4708 hlpSS2.str( std::string ( ) );
4709 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMax * 1000.0 ) / 1000.0;
4710 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4711 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4712 hlpSS << hlpSS2.str() <<
"</pre>";
4714 rvapi_set_text ( hlpSS.str().c_str(),
4721 hlpSS.str( std::string ( ) );
4722 hlpSS <<
"<pre>" <<
"Mean (std. dev.) within mask: ";
4723 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4724 for (
int iter = 0; iter < hlpIt; iter++ )
4729 hlpSS2.str( std::string ( ) );
4730 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMean * 1000.0 ) / 1000.0;
4731 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4732 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4733 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4735 hlpSS2.str( std::string ( ) );
4736 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskSdev * 1000.0 ) / 1000.0;
4737 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4738 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4739 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4741 rvapi_set_text ( hlpSS.str().c_str(),
4748 hlpSS.str( std::string (
"<pre>" ) );
4749 for (
int iter = 0; iter < 70; iter++ )
4754 rvapi_set_text ( hlpSS.str().c_str(),
4761 hlpSS.str( std::string ( ) );
4762 hlpSS <<
"<pre>" <<
"Total structure volume: ";
4763 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4764 for (
int iter = 0; iter < hlpIt; iter++ )
4769 hlpSS2.str( std::string ( ) );
4770 hlpSS2 << std::showpos << std::setprecision ( 10 ) << *totalVolume * 1000.0 / 1000.0;
4771 if ( hlpSS2.str().length() != 15 ) {
int hlp = 15 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4772 if ( hlpSS2.str().length() > 15 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4773 hlpSS <<
" " << hlpSS2.str() <<
" A^3 " <<
"</pre>";
4775 rvapi_set_text ( hlpSS.str().c_str(),
4782 hlpSS.str( std::string ( ) );
4783 hlpSS <<
"<pre>" <<
"Total mask volume: ";
4784 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4785 for (
int iter = 0; iter < hlpIt; iter++ )
4790 hlpSS2.str( std::string ( ) );
4791 hlpSS2 << std::showpos << std::setprecision ( 10 ) << *maskVolume * 1000.0 / 1000.0;
4792 if ( hlpSS2.str().length() != 15 ) {
int hlp = 15 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4793 if ( hlpSS2.str().length() > 15 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4794 hlpSS <<
" " << hlpSS2.str() <<
" A^3 " <<
"</pre>";
4796 rvapi_set_text ( hlpSS.str().c_str(),
4803 hlpSS.str( std::string (
"<pre>" ) );
4804 for (
int iter = 0; iter < 70; iter++ )
4809 rvapi_set_text ( hlpSS.str().c_str(),
4816 hlpSS.str( std::string ( ) );
4817 hlpSS <<
"<pre>" <<
"RMS of complete map: ";
4818 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4819 for (
int iter = 0; iter < hlpIt; iter++ )
4824 hlpSS2.str( std::string ( ) );
4825 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *allDensityRMS * 1000.0 ) / 1000.0;
4826 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4827 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4828 hlpSS <<
" " << hlpSS2.str() <<
" " <<
"</pre>";
4830 rvapi_set_text ( hlpSS.str().c_str(),
4837 hlpSS.str( std::string ( ) );
4838 hlpSS <<
"<pre>" <<
"RMS of masked map: ";
4839 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4840 for (
int iter = 0; iter < hlpIt; iter++ )
4845 hlpSS2.str( std::string ( ) );
4846 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskDensityRMS * 1000.0 ) / 1000.0;
4847 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4848 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4849 hlpSS <<
" " << hlpSS2.str() <<
" " <<
"</pre>";
4851 rvapi_set_text ( hlpSS.str().c_str(),
4862 double xReal = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
4863 double yReal = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
4864 double zReal = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
4867 std::array<double,3> meanVals;
4872 double totDens = 0.0;
4874 for ( uIt = 0; uIt < hlpU; uIt++ )
4876 for ( vIt = 0; vIt < hlpV; vIt++ )
4878 for ( wIt = 0; wIt < hlpW; wIt++ )
4880 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4882 meanVals[0] += this->_densityMapCor[arrayPos] * uIt;
4883 meanVals[1] += this->_densityMapCor[arrayPos] * vIt;
4884 meanVals[2] += this->_densityMapCor[arrayPos] * wIt;
4886 totDens += this->_densityMapCor[arrayPos];
4891 meanVals[0] /= totDens;
4892 meanVals[1] /= totDens;
4893 meanVals[2] /= totDens;
4896 this->_xCorrErr = meanVals[0] -
static_cast<double> ( this->_maxMapU + 1 )/2.0;
4897 this->_yCorrErr = meanVals[1] -
static_cast<double> ( this->_maxMapV + 1 )/2.0;
4898 this->_zCorrErr = meanVals[2] -
static_cast<double> ( this->_maxMapW + 1 )/2.0;
4900 this->_xCorrection = std::ceil ( this->_xCorrErr );
4901 this->_yCorrection = std::ceil ( this->_yCorrErr );
4902 this->_zCorrection = std::ceil ( this->_zCorrErr );
4905 this->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
4906 int newU, newV, newW, coordPos;
4909 for ( uIt = 0; uIt < hlpU; uIt++ )
4911 for ( vIt = 0; vIt < hlpV; vIt++ )
4913 for ( wIt = 0; wIt < hlpW; wIt++ )
4915 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
4916 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
4917 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
4919 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
4920 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
4921 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
4923 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4924 coordPos = newW + hlpW * ( newV + hlpV * newU );
4926 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) / 2.0 ) * xReal;
4927 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) / 2.0 ) * yReal;
4928 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) / 2.0 ) * zReal;
4934 std::cout <<
">> Map centered." << std::endl;
4939 std::stringstream hlpSS;
4940 hlpSS <<
"<font color=\"green\">" <<
"Map centered." <<
"</font>";
4941 rvapi_set_text ( hlpSS.str().c_str(),
4958 double maxXTot = 0.0;
4959 double minXTot = 0.0;
4960 double maxYTot = 0.0;
4961 double minYTot = 0.0;
4962 double maxZTot = 0.0;
4963 double minZTot = 0.0;
4966 for ( uIt = 0; uIt < hlpU; uIt++ )
4968 for ( vIt = 0; vIt < hlpV; vIt++ )
4970 for ( wIt = 0; wIt < hlpW; wIt++ )
4972 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
4974 if ( this->_densityMapCor[coordPos] > 0.0 )
4976 maxX = std::max ( maxX, this->_densityMapCorCoords[coordPos][0] );
4977 minX = std::min ( minX, this->_densityMapCorCoords[coordPos][0] );
4978 maxY = std::max ( maxY, this->_densityMapCorCoords[coordPos][1] );
4979 minY = std::min ( minY, this->_densityMapCorCoords[coordPos][1] );
4980 maxZ = std::max ( maxZ, this->_densityMapCorCoords[coordPos][2] );
4981 minZ = std::min ( minZ, this->_densityMapCorCoords[coordPos][2] );
4983 maxXTot = std::max ( maxXTot, this->_densityMapCorCoords[coordPos][0] );
4984 minXTot = std::min ( minXTot, this->_densityMapCorCoords[coordPos][0] );
4985 maxYTot = std::max ( maxYTot, this->_densityMapCorCoords[coordPos][1] );
4986 minYTot = std::min ( minYTot, this->_densityMapCorCoords[coordPos][1] );
4987 maxZTot = std::max ( maxZTot, this->_densityMapCorCoords[coordPos][2] );
4988 minZTot = std::min ( minZTot, this->_densityMapCorCoords[coordPos][2] );
4994 int newUStart = std::floor ( ( ( minX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
4995 int newUEnd = std::ceil ( ( ( maxX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
4996 int newVStart = std::floor ( ( ( minY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
4997 int newVEnd = std::ceil ( ( ( maxY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
4998 int newWStart = std::floor ( ( ( minZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
4999 int newWEnd = std::ceil ( ( ( maxZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
5004 newUStart = std::min( newUStart, std::min( newVStart, newWStart ) );
5005 newVStart = std::min( newUStart, std::min( newVStart, newWStart ) );
5006 newWStart = std::min( newUStart, std::min( newVStart, newWStart ) );
5007 newUEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
5008 newVEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
5009 newWEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
5013 int newXDim = newUEnd - newUStart + 1;
5014 int newYDim = newVEnd - newVStart + 1;
5015 int newZDim = newWEnd - newWStart + 1;
5017 if ( ( this->_xFrom < 0 ) && ( ( this->_xFrom + newUStart ) >= 0 ) ) { newXDim += 1; }
5018 if ( ( this->_yFrom < 0 ) && ( ( this->_yFrom + newVStart ) >= 0 ) ) { newYDim += 1; }
5019 if ( ( this->_zFrom < 0 ) && ( ( this->_zFrom + newWStart ) >= 0 ) ) { newZDim += 1; }
5021 double *hlpMap =
nullptr;
5022 hlpMap = (
double*) malloc ( newXDim * newYDim * newZDim *
sizeof (
double ) );
5023 if ( hlpMap ==
nullptr )
5025 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
5029 std::stringstream hlpSS;
5030 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
5031 rvapi_set_text ( hlpSS.str().c_str(),
5045 for ( uIt = this->_xFrom; uIt <= this->_xTo; uIt++ )
5047 for ( vIt = this->_yFrom; vIt <= this->_yTo; vIt++ )
5049 for ( wIt = this->_zFrom; wIt <= this->_zTo; wIt++ )
5051 if ( ( uIt < (this->_xFrom+newUStart) ) || ( uIt > (this->_xFrom+newUEnd) ) ||
5052 ( vIt < (this->_yFrom+newVStart) ) || ( vIt > (this->_yFrom+newVEnd) ) ||
5053 ( wIt < (this->_zFrom+newWStart) ) || ( wIt > (this->_zFrom+newWEnd) ) )
5058 newU = uIt - this->_xFrom;
5059 newV = vIt - this->_yFrom;
5060 newW = wIt - this->_zFrom;
5061 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
5063 newU = newU - newUStart;
5064 newV = newV - newVStart;
5065 newW = newW - newWStart;
5066 hlpPos = newW + newZDim * ( newV + newYDim * newU );
5068 hlpMap[hlpPos] = this->_densityMapCor[arrPos];
5074 if ( addXOne ) { this->_xFrom -= 1; }
5075 if ( addYOne ) { this->_yFrom -= 1; }
5076 if ( addZOne ) { this->_zFrom -= 1; }
5078 this->_xFrom += newUStart;
5079 this->_yFrom += newVStart;
5080 this->_zFrom += newWStart;
5082 this->_xTo -= this->_maxMapU - newUEnd;
5083 this->_yTo -= this->_maxMapV - newVEnd;
5084 this->_zTo -= this->_maxMapW - newWEnd;
5086 this->_maxMapU = newXDim - 1;
5087 this->_maxMapV = newYDim - 1;
5088 this->_maxMapW = newZDim - 1;
5090 if ( ( this->_xFrom > 0 ) && ( this->_xTo > 0 ) ) { this->_xTo += 1; }
5091 if ( ( this->_yFrom > 0 ) && ( this->_yTo > 0 ) ) { this->_yTo += 1; }
5092 if ( ( this->_zFrom > 0 ) && ( this->_zTo > 0 ) ) { this->_zTo += 1; }
5094 this->_xRange = this->_xSamplingRate * ( this->_maxMapU + 1 );
5095 this->_yRange = this->_ySamplingRate * ( this->_maxMapV + 1 );
5096 this->_zRange = this->_zSamplingRate * ( this->_maxMapW + 1 );
5099 delete[] this->_densityMapCor;
5100 this->_densityMapCor =
nullptr;
5101 this->_densityMapCor =
new double [newXDim * newYDim * newZDim];
5103 for (
int iter = 0; iter < (newXDim * newYDim * newZDim); iter++ )
5105 this->_densityMapCor[iter] = hlpMap[iter];
5108 if ( hlpMap !=
nullptr )
5116 std::cout <<
">> Map resized." << std::endl;
5121 std::stringstream hlpSS;
5122 hlpSS <<
"<font color=\"green\">" <<
"Map resized." <<
"</font>";
5123 rvapi_set_text ( hlpSS.str().c_str(),
5153 if ( !this->_densityMapComputed )
5155 std::cerr <<
"!!! ProSHADE ERROR !!! Error in file " << this->_inputFileName <<
" !!! Attempted to remove phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the removePhaseFromMap function." << std::endl;
5159 std::stringstream hlpSS;
5160 hlpSS <<
"<font color=\"red\">" <<
"Attempted to remove phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the removePhaseFromMap function. This looks like an internal bug - please report this case." <<
"</font>";
5161 rvapi_set_text ( hlpSS.str().c_str(),
5175 this->_fourierCoeffPower = alpha;
5176 this->_bFactorChange = bFac;
5179 fftw_complex *tmpOut;
5180 fftw_complex *tmpIn;
5185 int hlpU = ( this->_maxMapU + 1 );
5186 int hlpV = ( this->_maxMapV + 1 );
5187 int hlpW = ( this->_maxMapW + 1 );
5189 this->_densityMapCor =
new double [(this->_maxMapU+2) * (this->_maxMapV+2) * (this->_maxMapW+2)];
5190 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
5191 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
5194 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
5195 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
5198 unsigned int noMapPoints = 0;
5200 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
5202 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
5204 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
5207 noMapPoints = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
5209 if ( this->_densityMapMap[noMapPoints] == this->_densityMapMap[noMapPoints] )
5211 tmpIn[noMapPoints][0] = this->_densityMapMap[noMapPoints];
5212 tmpIn[noMapPoints][1] = 0.0;
5216 tmpIn[noMapPoints][0] = 0.0;
5217 tmpIn[noMapPoints][1] = 0.0;
5227 unsigned int arrayPos = 0;
5230 double normFactor = (hlpU * hlpV * hlpW);
5231 for ( uIt = 0; uIt < hlpU; uIt++ )
5233 for ( vIt = 0; vIt < hlpV; vIt++ )
5235 for ( wIt = 0; wIt < hlpW; wIt++ )
5238 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5239 real = tmpOut[arrayPos][0];
5240 imag = tmpOut[arrayPos][1];
5243 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
5244 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
5245 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
5247 S = pow( static_cast<double> ( h ) / this->_xRange, 2.0 ) + pow( static_cast<double> ( k ) / this->_yRange, 2.0 ) + pow( static_cast<double> ( l ) / this->_zRange, 2.0 );
5248 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
5251 mag *= sqrt ( (real*real) + (imag*imag) );
5254 mag = pow ( mag, this->_fourierCoeffPower );
5257 tmpOut[arrayPos][0] = mag;
5258 tmpOut[arrayPos][1] = 0.0;
5261 tmpOut[arrayPos][0] /= normFactor;
5267 fftw_execute ( pInv );
5270 fftw_destroy_plan ( p );
5271 fftw_destroy_plan ( pInv );
5274 this->_densityMapCorCoords =
new std::array<double,3> [(this->_maxMapU+2) * (this->_maxMapV+2) * (this->_maxMapW+2)];
5283 int nonTranslatedIter = 0;
5286 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU + 2); uIt++ )
5288 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV + 2); vIt++ )
5290 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW + 2); wIt++ )
5292 if ( ( uIt == hlpU ) || ( vIt == hlpV ) || ( wIt == hlpW ) )
5294 newU = uIt;
if ( uIt == hlpU ) { newU = 0; }
5295 newV = vIt;
if ( vIt == hlpV ) { newV = 0; }
5296 newW = wIt;
if ( wIt == hlpW ) { newW = 0; }
5298 cenPosU = newU + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5299 cenPosV = newV + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5300 cenPosW = newW + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5302 arrayPos = cenPosW + hlpW * ( cenPosV + hlpV * cenPosU );
5304 this->_densityMapCor[nonTranslatedIter] = tmpIn[arrayPos][0];
5305 this->_densityMapCorCoords[nonTranslatedIter][0] = uIt - hlpU / 2;
5306 this->_densityMapCorCoords[nonTranslatedIter][1] = vIt - hlpV / 2;
5307 this->_densityMapCorCoords[nonTranslatedIter][2] = wIt - hlpW / 2;
5311 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5313 cenPosU = uIt + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5314 cenPosV = vIt + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5315 cenPosW = wIt + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5316 coordPos = cenPosW + (this->_maxMapW + 2) * ( cenPosV + (this->_maxMapV + 2) * cenPosU );
5318 this->_densityMapCor[coordPos] = tmpIn[arrayPos][0];
5319 this->_densityMapCorCoords[coordPos][0] = cenPosU - hlpU / 2;
5320 this->_densityMapCorCoords[coordPos][1] = cenPosV - hlpV / 2;
5321 this->_densityMapCorCoords[coordPos][2] = cenPosW - hlpW / 2;
5323 nonTranslatedIter += 1;
5333 if ( this->_densityMapMap !=
nullptr )
5335 delete this->_densityMapMap;
5336 this->_densityMapMap =
nullptr;
5340 this->_phaseRemoved =
true;
5341 this->_keepOrRemove =
false;
5342 this->_usePhase =
false;
5362 if ( !this->_densityMapComputed )
5364 std::cerr <<
"!!! ProSHADE ERROR !!! Error in file " << this->_inputFileName <<
" !!! Attempted to remove phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the removePhaseFromMap function." << std::endl;
5368 std::stringstream hlpSS;
5369 hlpSS <<
"<font color=\"red\">" <<
"Attempted to remove phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the removePhaseFromMap function. This looks like an internal bug - please report this case." <<
"</font>";
5370 rvapi_set_text ( hlpSS.str().c_str(),
5384 this->_fourierCoeffPower = alpha;
5385 this->_bFactorChange = bFac;
5388 fftw_complex *tmpOut;
5389 fftw_complex *tmpIn;
5394 int hlpU = ( this->_maxMapU + 1 );
5395 int hlpV = ( this->_maxMapV + 1 );
5396 int hlpW = ( this->_maxMapW + 1 );
5398 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
5399 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
5400 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
5403 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
5404 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
5407 unsigned int arrayPos = 0;
5409 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
5411 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
5413 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
5416 arrayPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
5418 if ( this->_densityMapMap[arrayPos] == this->_densityMapMap[arrayPos] )
5420 tmpIn[arrayPos][0] = this->_densityMapMap[arrayPos];
5421 tmpIn[arrayPos][1] = 0.0;
5425 tmpIn[arrayPos][0] = 0.0;
5426 tmpIn[arrayPos][1] = 0.0;
5439 double normFactor = (hlpU * hlpV * hlpW);
5440 for ( uIt = 0; uIt < hlpU; uIt++ )
5442 for ( vIt = 0; vIt < hlpV; vIt++ )
5444 for ( wIt = 0; wIt < hlpW; wIt++ )
5447 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5448 real = tmpOut[arrayPos][0];
5449 imag = tmpOut[arrayPos][1];
5452 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
5453 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
5454 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
5456 S = pow( static_cast<double> ( h ) / this->_xRange, 2.0 ) + pow( static_cast<double> ( k ) / this->_yRange, 2.0 ) + pow( static_cast<double> ( l ) / this->_zRange, 2.0 );
5457 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
5460 mag *= sqrt ( (real*real) + (imag*imag) );
5463 mag = pow ( mag, this->_fourierCoeffPower );
5466 tmpOut[arrayPos][0] = mag;
5467 tmpOut[arrayPos][1] = 0.0;
5470 tmpOut[arrayPos][0] /= normFactor;
5476 fftw_execute ( pInv );
5479 fftw_destroy_plan ( p );
5480 fftw_destroy_plan ( pInv );
5488 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU + 1); uIt++ )
5490 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV + 1); vIt++ )
5492 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW + 1); wIt++ )
5494 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5496 cenPosU = uIt + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5497 cenPosV = vIt + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5498 cenPosW = wIt + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5499 coordPos = cenPosW + (this->_maxMapW + 1) * ( cenPosV + (this->_maxMapV + 1) * cenPosU );
5501 this->_densityMapCor[arrayPos]= tmpIn[coordPos][0];
5511 if ( this->_densityMapMap !=
nullptr )
5513 delete this->_densityMapMap;
5514 this->_densityMapMap =
nullptr;
5518 this->_phaseRemoved =
true;
5519 this->_usePhase =
false;
5520 this->_keepOrRemove =
false;
5549 unsigned int *bandwidth,
5550 unsigned int *theta,
5552 unsigned int *glIntegOrder,
5559 bool overlapDefaults,
5561 bool maskBlurFactorGiven )
5564 if ( !this->_densityMapComputed )
5566 std::cerr <<
"!!! ProSHADE ERROR !!! Error in file " << this->_inputFileName <<
" !!! Attempted to keep phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the keepPhaseInMap function." << std::endl;
5570 std::stringstream hlpSS;
5571 hlpSS <<
"<font color=\"red\">" <<
"Attempted to remove phase information from map before computing the map. Call the getDensityMapFromPDB function BEFORE the keepPhaseInMap function. This looks like an internal bug - please report this case." <<
"</font>";
5572 rvapi_set_text ( hlpSS.str().c_str(),
5586 this->_fourierCoeffPower = alpha;
5587 this->_bFactorChange = bFac;
5590 int hlpU = ( this->_maxMapU + 1 );
5591 int hlpV = ( this->_maxMapV + 1 );
5592 int hlpW = ( this->_maxMapW + 1 );
5595 fftw_complex *tmpOut;
5596 fftw_complex *tmpIn;
5601 unsigned int arrayPos = 0;
5604 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
5605 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
5606 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
5609 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
5610 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
5613 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
5615 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
5617 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
5620 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
5622 if ( this->_densityMapMap[arrPos] == this->_densityMapMap[arrPos] )
5624 tmpIn[arrPos][0] = this->_densityMapMap[arrPos];
5625 tmpIn[arrPos][1] = 0.0;
5629 tmpIn[arrPos][0] = 0.0;
5630 tmpIn[arrPos][1] = 0.0;
5637 if ( ( this->_fourierCoeffPower != 1.0 ) || ( this->_bFactorChange != 0.0 ) )
5644 double mag, phase, S;
5645 double normFactor = (hlpU * hlpV * hlpW);
5646 for ( uIt = 0; uIt < hlpU; uIt++ )
5648 for ( vIt = 0; vIt < hlpV; vIt++ )
5650 for ( wIt = 0; wIt < hlpW; wIt++ )
5653 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5654 real = tmpOut[arrayPos][0];
5655 imag = tmpOut[arrayPos][1];
5658 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
5659 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
5660 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
5662 S = pow ( static_cast<double> ( h ) / this->_xRange, 2.0 ) +
5663 pow ( static_cast<double> ( k ) / this->_yRange, 2.0 ) +
5664 pow ( static_cast<double> ( l ) / this->_zRange, 2.0 );
5665 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
5668 mag *= sqrt ( (real*real) + (imag*imag) );
5669 phase = atan2 ( imag, real );
5672 mag = pow ( mag, this->_fourierCoeffPower );
5675 tmpOut[arrayPos][0] = mag * cos(phase);
5676 tmpOut[arrayPos][1] = mag * sin(phase);
5679 tmpOut[arrayPos][0] /= normFactor;
5680 tmpOut[arrayPos][1] /= normFactor;
5686 fftw_execute ( pInv );
5690 fftw_destroy_plan ( p );
5691 fftw_destroy_plan ( pInv );
5694 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5696 this->_densityMapCor[iter] = this->_densityMapMap[iter];
5700 if ( this->_densityMapMap !=
nullptr )
5702 free ( this->_densityMapMap );
5703 this->_densityMapMap =
nullptr;
5707 if ( !this->_fromPDB )
5712 double *tmpMp =
new double[hlpU * hlpV * hlpW];
5713 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5715 tmpMp[iter] = this->_densityMapCor[iter];
5718 bool notTooManyIslads =
true;
5719 double blFr = 150.0;
5721 while ( notTooManyIslads )
5725 if ( maskBlurFactorGiven )
5728 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
5734 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
5739 std::cout <<
">>>>>>>> Island detection started." << std::endl;
5742 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
5744 if ( maskBlurFactorGiven )
5751 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
5753 if ( notTooManyIslads )
5757 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
5760 if ( blFr <= 500.0 )
5762 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5764 this->_densityMapCor[iter] = tmpMp[iter];
5772 std::cout << std::endl;
5778 std::cout <<
"!!! ProSHADE WARNING !!! Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." << std::endl;
5782 std::stringstream hlpSS;
5783 hlpSS <<
"<font color=\"orange\">" <<
"Even blurring factor of 500 did not remove islands. Will not proceed with what we have, but be warned that either the masking is bugged or yout map has high levels of noise. You can consider using the -y ( or --no_clear ) options to avoid this message and the extra time for testing different blurring factors for this map." <<
"</font>";
5784 rvapi_set_text ( hlpSS.str().c_str(),
5802 double xReal = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
5803 double yReal = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
5804 double zReal = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
5807 std::array<double,3> meanVals;
5812 if ( !this->_firstLineCOM )
5816 double totDens = 0.0;
5818 for ( uIt = 0; uIt < hlpU; uIt++ )
5820 for ( vIt = 0; vIt < hlpV; vIt++ )
5822 for ( wIt = 0; wIt < hlpW; wIt++ )
5824 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5826 if ( !this->_fromPDB )
5828 if ( this->_densityMapCor[arrayPos] > 0.0 )
5830 meanVals[0] += this->_densityMapCor[arrayPos] * uIt;
5831 meanVals[1] += this->_densityMapCor[arrayPos] * vIt;
5832 meanVals[2] += this->_densityMapCor[arrayPos] * wIt;
5834 totDens += this->_densityMapCor[arrayPos];
5839 if ( tmpIn[arrayPos][0] > 0.0 )
5841 meanVals[0] += tmpIn[arrayPos][0] * uIt;
5842 meanVals[1] += tmpIn[arrayPos][0] * vIt;
5843 meanVals[2] += tmpIn[arrayPos][0] * wIt;
5845 totDens += tmpIn[arrayPos][0];
5852 meanVals[0] /= totDens;
5853 meanVals[1] /= totDens;
5854 meanVals[2] /= totDens;
5858 meanVals[0] =
static_cast<double> ( this->_maxMapU + 1 )/2.0;
5859 meanVals[1] =
static_cast<double> ( this->_maxMapV + 1 )/2.0;
5860 meanVals[2] =
static_cast<double> ( this->_maxMapW + 1 )/2.0;
5865 meanVals[0] = this->_xCorrErr / xReal;
5866 meanVals[1] = this->_yCorrErr / yReal;
5867 meanVals[2] = this->_zCorrErr / zReal;
5871 this->_xCorrErr = meanVals[0] -
static_cast<double> ( this->_maxMapU + 1 )/2.0;
5872 this->_yCorrErr = meanVals[1] -
static_cast<double> ( this->_maxMapV + 1 )/2.0;
5873 this->_zCorrErr = meanVals[2] -
static_cast<double> ( this->_maxMapW + 1 )/2.0;
5875 this->_xCorrection = std::ceil ( this->_xCorrErr );
5876 this->_yCorrection = std::ceil ( this->_yCorrErr );
5877 this->_zCorrection = std::ceil ( this->_zCorrErr );
5880 this->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
5881 int newU, newV, newW, coordPos;
5883 if ( this->_fromPDB )
5888 for ( uIt = 0; uIt < hlpU; uIt++ )
5890 for ( vIt = 0; vIt < hlpV; vIt++ )
5892 for ( wIt = 0; wIt < hlpW; wIt++ )
5894 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
5895 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
5896 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
5898 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
5899 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
5900 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
5902 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5903 coordPos = newW + hlpW * ( newV + hlpV * newU );
5905 this->_densityMapCor[coordPos] = tmpIn[arrayPos][0];
5908 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) /2.0 ) * xReal;
5909 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) /2.0 ) * yReal;
5910 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) /2.0 ) * zReal;
5917 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5919 this->_densityMapCor[iter] = tmpIn[iter][0];
5926 if ( !clearMapData )
5928 this->_xCorrection = 0.0;
5929 this->_yCorrection = 0.0;
5930 this->_zCorrection = 0.0;
5934 for ( uIt = 0; uIt < hlpU; uIt++ )
5936 for ( vIt = 0; vIt < hlpV; vIt++ )
5938 for ( wIt = 0; wIt < hlpW; wIt++ )
5940 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
5941 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
5942 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
5944 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
5945 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
5946 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
5948 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5949 coordPos = newW + hlpW * ( newV + hlpV * newU );
5951 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) / 2.0 ) * xReal;
5952 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) / 2.0 ) * yReal;
5953 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) / 2.0 ) * zReal;
5965 double maxXTot = 0.0;
5966 double minXTot = 0.0;
5967 double maxYTot = 0.0;
5968 double minYTot = 0.0;
5969 double maxZTot = 0.0;
5970 double minZTot = 0.0;
5972 for ( uIt = 0; uIt < hlpU; uIt++ )
5974 for ( vIt = 0; vIt < hlpV; vIt++ )
5976 for ( wIt = 0; wIt < hlpW; wIt++ )
5978 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
5980 if ( this->_densityMapCor[coordPos] > 0.0 )
5982 maxX = std::max ( maxX, this->_densityMapCorCoords[coordPos][0] );
5983 minX = std::min ( minX, this->_densityMapCorCoords[coordPos][0] );
5984 maxY = std::max ( maxY, this->_densityMapCorCoords[coordPos][1] );
5985 minY = std::min ( minY, this->_densityMapCorCoords[coordPos][1] );
5986 maxZ = std::max ( maxZ, this->_densityMapCorCoords[coordPos][2] );
5987 minZ = std::min ( minZ, this->_densityMapCorCoords[coordPos][2] );
5989 maxXTot = std::max ( maxXTot, this->_densityMapCorCoords[coordPos][0] );
5990 minXTot = std::min ( minXTot, this->_densityMapCorCoords[coordPos][0] );
5991 maxYTot = std::max ( maxYTot, this->_densityMapCorCoords[coordPos][1] );
5992 minYTot = std::min ( minYTot, this->_densityMapCorCoords[coordPos][1] );
5993 maxZTot = std::max ( maxZTot, this->_densityMapCorCoords[coordPos][2] );
5994 minZTot = std::min ( minZTot, this->_densityMapCorCoords[coordPos][2] );
6000 if ( ( ( maxX == maxXTot ) && ( minX == minXTot ) ) &&
6001 ( ( maxY == maxYTot ) && ( minY == minYTot ) ) &&
6002 ( ( maxZ == maxZTot ) && ( minZ == minZTot ) ) )
6005 this->_phaseRemoved =
true;
6006 this->_keepOrRemove =
true;
6007 this->_usePhase =
true;
6013 if ( rotDefaults || overlapDefaults )
6016 this->_phaseRemoved =
true;
6017 this->_keepOrRemove =
true;
6018 this->_usePhase =
true;
6024 int newUStart = std::floor ( ( ( minX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
6025 int newUEnd = std::ceil ( ( ( maxX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
6026 int newVStart = std::floor ( ( ( minY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
6027 int newVEnd = std::ceil ( ( ( maxY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
6028 int newWStart = std::floor ( ( ( minZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
6029 int newWEnd = std::ceil ( ( ( maxZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
6031 int newURange = std::max ( std::abs ( newUStart - static_cast<int>( this->_maxMapU + 1 )/2 ), std::abs ( newUEnd - static_cast<int>( this->_maxMapU + 1 )/2 ) );
6032 int newVRange = std::max ( std::abs ( newVStart - static_cast<int>( this->_maxMapV + 1 )/2 ), std::abs ( newVEnd - static_cast<int>( this->_maxMapV + 1 )/2 ) );
6033 int newWRange = std::max ( std::abs ( newWStart - static_cast<int>( this->_maxMapW + 1 )/2 ), std::abs ( newWEnd - static_cast<int>( this->_maxMapW + 1 )/2 ) );
6035 newUStart = ( this->_maxMapU + 1 )/2 - newURange;
6036 newUEnd = ( this->_maxMapU + 1 )/2 + newURange;
6037 newVStart = ( this->_maxMapV + 1 )/2 - newVRange;
6038 newVEnd = ( this->_maxMapV + 1 )/2 + newVRange;
6039 newWStart = ( this->_maxMapW + 1 )/2 - newWRange;
6040 newWEnd = ( this->_maxMapW + 1 )/2 + newWRange;
6042 newURange = newURange * 2 + 1;
6043 newVRange = newVRange * 2 + 1;
6044 newWRange = newWRange * 2 + 1;
6047 double* newMapHlp =
new double [newURange * newVRange * newWRange];
6048 std::array<double,3>* newMapCoords =
new std::array<double,3> [newURange * newVRange * newWRange];
6051 unsigned int newUIt, newVIt, newWIt;
6054 for ( uIt = 0; uIt < hlpU; uIt++ )
6056 if ( ( uIt < newUStart ) || ( uIt > newUEnd ) ) {
continue; }
6059 for ( vIt = 0; vIt < hlpV; vIt++ )
6061 if ( ( vIt < newVStart ) || ( vIt > newVEnd ) ) {
continue; }
6064 for ( wIt = 0; wIt < hlpW; wIt++ )
6066 if ( ( wIt < newWStart ) || ( wIt > newWEnd ) ) {
continue; }
6068 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
6069 arrayPos = newWIt + newWRange * ( newVIt + newVRange * newUIt );
6071 newMapHlp[arrayPos] = this->_densityMapCor[coordPos];
6072 newMapCoords[arrayPos][0] = this->_densityMapCorCoords[coordPos][0];
6073 newMapCoords[arrayPos][1] = this->_densityMapCorCoords[coordPos][1];
6074 newMapCoords[arrayPos][2] = this->_densityMapCorCoords[coordPos][2];
6086 delete this->_densityMapCor;
6087 delete this->_densityMapCorCoords;
6088 this->_densityMapCor =
nullptr;
6089 this->_densityMapCorCoords =
nullptr;
6092 this->_densityMapCor = newMapHlp;
6093 newMapHlp =
nullptr;
6094 this->_densityMapCorCoords = newMapCoords;
6095 newMapCoords =
nullptr;
6098 this->_xRange = (
static_cast<double> (newURange - 1) / static_cast<double> ( this->_maxMapU ) ) * this->_xRange;
6099 this->_yRange = (
static_cast<double> (newVRange - 1) / static_cast<double> ( this->_maxMapV ) ) * this->_yRange;
6100 this->_zRange = (
static_cast<double> (newWRange - 1) / static_cast<double> ( this->_maxMapW ) ) * this->_zRange;
6101 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
6103 this->_maxMapU = newURange - 1;
6104 this->_maxMapV = newVRange - 1;
6105 this->_maxMapW = newWRange - 1;
6108 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
6110 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
6112 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
6116 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU );
6117 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV );
6118 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW );
6119 double maxSamplingRate = std::max ( this->_xSamplingRate, std::max( this->_ySamplingRate, this->_zSamplingRate ) );
6122 if ( ( this->_mapResolution / 2.0 ) > maxSamplingRate )
6124 maxSamplingRate = ( this->_mapResolution / 2.0 );
6128 if ( !this->_wasBandwithGiven )
6130 *bandwidth = std::ceil ( std::ceil ( ( ( std::ceil ( this->_maxMapRange / this->_shellSpacing ) * this->_shellSpacing ) / maxSamplingRate ) * 2.0 ) / 2.0 );
6134 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
6135 this->_wasBandwithGiven =
true;
6139 if ( !this->_wasThetaGiven ) { *theta = 2 * (*bandwidth); this->_thetaAngle = *theta; }
6140 if ( !this->_wasPhiGiven ) { *phi = 2 * (*bandwidth); this->_phiAngle = *phi; }
6143 double distPerPointFraction;
6144 if ( !this->_wasGlInterGiven )
6146 distPerPointFraction = ( ( this->_maxMapRange / 2.0 ) / static_cast<double> ( *bandwidth / 2 ) ) / ( this->_maxMapRange / 2.0 );
6148 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
6150 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
6152 *glIntegOrder = iter;
6159 this->_bandwidthLimit = *bandwidth;
6160 this->_thetaAngle =
static_cast<double> ( *theta );
6161 this->_phiAngle =
static_cast<double> ( *phi );
6168 this->_phaseRemoved =
true;
6169 this->_usePhase =
true;
6170 this->_keepOrRemove =
true;
6187 std::cout <<
"-----------------------------------------------------------" << std::endl;
6188 std::cout <<
"| RESULTS |" << std::endl;
6189 std::cout <<
"-----------------------------------------------------------" << std::endl << std::endl;
6194 printf (
"File name: %s\n", this->one->_inputFileName.c_str() );
6196 printf (
"Cell dimmensions (A): %+.1f x %+.1f x %+.1f\n", this->origRanges[0], this->origRanges[1], this->origRanges[2] );
6197 printf (
"Cell U, V and W: %+.1f x %+.1f x %+.1f\n", this->origDims[0]+1, this->origDims[1]+1, this->origDims[2]+1 );
6199 printf (
"Min/Max density: %+.3f / %+.3f\n", this->minDensPreNorm, this->maxDensPreNorm );
6200 printf (
"Density mean: %+.3f\n", this->one->_mapMean );
6201 printf (
"Density std. dev: %+.3f\n", this->one->_mapSdev );
6203 printf (
"Min/Max norm density: %+.3f / %+.3f\n", this->minDensPostNorm, this->maxDensPostNorm );
6204 printf (
"Norm. density mean: %+.3f\n", this->postNormMean );
6205 printf (
"Norm. density std. dev: %+.3f\n", this->postNormSdev );
6207 printf (
"Total volume (A^3): %+.1f\n", this->totalVolume );
6208 printf (
"Mask volume (A^3): %+.1f\n", this->maskVolume );
6210 printf (
"Min/Max mask density: %+.3f / %+.3f\n", this->maskMin, this->maskMax );
6211 printf (
"Mask density mean: %+.3f\n", this->maskMean );
6212 printf (
"Mask density std. dev: %+.3f\n", this->maskSdev );
6214 printf (
"All density RMS: %+.3f\n", this->allDensityRMS );
6215 printf (
"Mask density RMS: %+.3f\n", this->maskDensityRMS );
6244 int newU, newV, newW, coordPos, arrayPos;
6248 std::vector< std::array<int,5> > clMap ( hlpU * hlpV * hlpW );
6249 std::array<int,5> hlpArr;
6250 for ( uIt = 0; uIt < hlpU; uIt++ )
6252 for ( vIt = 0; vIt < hlpV; vIt++ )
6254 for ( wIt = 0; wIt < hlpW; wIt++ )
6259 hlpArr[3] = wIt + hlpW * ( vIt + hlpV * uIt );
6261 if ( map[hlpArr[3]] <= threshold )
6269 clMap.at(hlpArr[3]) = hlpArr;
6275 std::vector< std::vector<int> > clusters;
6276 std::vector<int> unclNeigh;
6277 std::vector<int> clNeigh;
6278 std::vector<int> hlpVec;
6279 std::vector<int> XXXVec;
6281 bool allSame =
false;
6285 for ( uIt = 0; uIt < hlpU; uIt++ )
6287 for ( vIt = 0; vIt < hlpV; vIt++ )
6289 for ( wIt = 0; wIt < hlpW; wIt++ )
6292 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
6295 if ( clMap.at(arrayPos)[4] == -999 ) {
continue; }
6298 unclNeigh.clear ( );
6300 for (
int uCh = -1; uCh < 2; uCh++ )
6302 for (
int vCh = -1; vCh < 2; vCh++ )
6304 for (
int wCh = -1; wCh < 2; wCh++ )
6306 if ( ( uCh == 0 ) && ( vCh == 0 ) && ( wCh == 0 ) ) {
continue; }
6308 newU =
static_cast<int> ( uIt ) + uCh;
6309 newV =
static_cast<int> ( vIt ) + vCh;
6310 newW =
static_cast<int> ( wIt ) + wCh;
6312 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
6313 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
6314 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
6316 coordPos = newW + hlpW * ( newV + hlpV * newU );
6319 if ( clMap.at(coordPos)[4] == -999 ) {
continue; }
6322 if ( clMap.at(coordPos)[4] == -1 )
6324 unclNeigh.emplace_back ( coordPos );
6328 clNeigh.emplace_back ( coordPos );
6334 if ( ( unclNeigh.size() == 0 ) && ( clNeigh.size() == 0 ) )
6337 clMap.at(arrayPos)[4] = clusterNo;
6339 unclNeigh.emplace_back ( arrayPos );
6340 clusters.emplace_back ( unclNeigh );
6341 unclNeigh.clear ( );
6348 if ( ( unclNeigh.size() > 0 ) && ( clNeigh.size() == 0 ) )
6351 clMap.at(arrayPos)[4] = clusterNo;
6353 clNeigh.emplace_back ( arrayPos );
6354 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6356 clNeigh.emplace_back ( clMap.at(unclNeigh.at(iter))[3] );
6357 clMap.at(unclNeigh.at(iter))[4] = clusterNo;
6360 clusters.emplace_back ( clNeigh );
6368 if ( clNeigh.size() > 0 )
6371 hlpVal = clMap.at(clNeigh.at(0))[4];
6372 for (
unsigned int iter = 1; iter < static_cast<unsigned int> ( clNeigh.size() ); iter++ )
6374 if ( clMap.at(clNeigh.at(iter))[4] != hlpVal )
6383 if ( clMap.at(arrayPos)[4] == -1 )
6385 clMap.at(arrayPos)[4] = clMap.at(clNeigh.at(0))[4];
6386 clusters.at(clMap.at(clNeigh.at(0))[4]).emplace_back ( arrayPos );
6390 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6392 clusters.at(clMap.at(clNeigh.at(0))[4]).emplace_back ( clMap.at(unclNeigh.at(iter))[3] );
6393 clMap.at(unclNeigh.at(iter))[4] = clMap.at(clNeigh.at(0))[4];
6401 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clNeigh.size() ); iter++ )
6403 hlpVec.emplace_back ( clMap.at(clNeigh.at(iter))[4] );
6406 std::sort ( hlpVec.begin(), hlpVec.end() );
6407 hlpVec.erase ( std::unique( hlpVec.begin(), hlpVec.end() ), hlpVec.end() );
6409 minCl = hlpVec.at(0);
6412 if ( clMap.at(arrayPos)[4] == -1 )
6414 clMap.at(arrayPos)[4] = minCl;
6415 clusters.at(minCl).emplace_back ( arrayPos );
6419 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6421 clMap.at(unclNeigh.at(iter))[4] = minCl;
6422 clusters.at(minCl).emplace_back ( unclNeigh.at(iter) );
6426 for (
unsigned int iter = 1; iter < static_cast<unsigned int> ( hlpVec.size() ); iter++ )
6428 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clusters.at(hlpVec.at(iter)).size() ); it++ )
6430 clMap.at(clusters.at(hlpVec.at(iter)).at(it))[4] = minCl;
6431 clusters.at(minCl).emplace_back ( clusters.at(hlpVec.at(iter)).at(it) );
6433 clusters.at(hlpVec.at(iter)).clear();
6442 std::vector< std::array<double,3> > clVec;
6443 std::array<double,3> hArr;
6444 for (
unsigned int clIt = 0; clIt < static_cast<unsigned int> ( clusters.size() ); clIt++ )
6446 if ( clusters.at(clIt).size() > 1 )
6448 unsigned int minU = clMap.at(clusters.at(clIt).at(0))[0];
6449 unsigned int maxU = clMap.at(clusters.at(clIt).at(0))[0];
6450 unsigned int minV = clMap.at(clusters.at(clIt).at(0))[1];
6451 unsigned int maxV = clMap.at(clusters.at(clIt).at(0))[1];
6452 unsigned int minW = clMap.at(clusters.at(clIt).at(0))[2];
6453 unsigned int maxW = clMap.at(clusters.at(clIt).at(0))[2];
6454 for (
unsigned int el = 0; el < static_cast<unsigned int> ( clusters.at(clIt).size() ); el++ )
6456 minU = std::min ( minU, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[0] ) );
6457 maxU = std::max ( maxU, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[0] ) );
6458 minV = std::min ( minV, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[1] ) );
6459 maxV = std::max ( maxV, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[1] ) );
6460 minW = std::min ( minW, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[2] ) );
6461 maxW = std::max ( maxW, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[2] ) );
6463 double encVol = ( maxU - minU + 1 ) * ( maxV - minV + 1 ) * ( maxW - minW + 1 );
6464 hArr[0] = encVol /
static_cast<double> ( clusters.at(clIt).size() );
6465 hArr[1] =
static_cast<double> ( clusters.at(clIt).size() );
6467 clVec.emplace_back ( hArr );
6470 std::sort ( clVec.begin(), clVec.end(), [](
const std::array<double,3>& a,
const std::array<double,3>& b) {
return a[1] > b[1]; });
6472 std::vector<double> hlpVals;
6473 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clVec.size() ); iter++ )
6475 hlpVals.emplace_back ( clVec.at(iter)[1] );
6478 double mean = std::accumulate ( hlpVals.begin(), hlpVals.end(), 0.0 ) / static_cast<double> ( hlpVals.size() );
6479 double sd = sqrt ( std::inner_product( hlpVals.begin(), hlpVals.end(), hlpVals.begin(), 0.0 ) / static_cast<double> ( hlpVals.size() ) - mean * mean );
6482 std::vector< std::array<double,3> > hVec;
6483 for (
double iter = 5.0; iter >= 0.0; iter = iter - 0.5 )
6485 thres = mean + ( iter * sd );
6488 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clVec.size() ); it++ )
6490 if ( clVec.at(it)[1] >= thres )
6492 hArr[0] = clVec.at(it)[0];
6493 hArr[1] = clVec.at(it)[2];
6494 hVec.emplace_back ( hArr );
6498 if ( ( hVec.size() > std::max ( std::floor ( clVec.size() * 0.05 ), 10.0 ) ) && ( hVec.size() < clVec.size() ) )
6504 std::sort ( hVec.begin(), hVec.end(), [](
const std::array<double,3>& a,
const std::array<double,3>& b) {
return a[0] < b[0]; });
6505 std::vector< std::vector<int> > clusts;
6508 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6510 hlpVals.emplace_back ( hVec.at(iter)[0] );
6513 if ( hVec.size() < 5 )
6515 mean = hVec.at(hVec.size()-1)[0] + 0.0001;
6520 mean = std::accumulate ( hlpVals.begin(), hlpVals.end(), 0.0 ) / static_cast<double> ( hlpVals.size() );
6521 sd = sqrt ( std::inner_product( hlpVals.begin(), hlpVals.end(), hlpVals.begin(), 0.0 ) / static_cast<double> ( hlpVals.size() ) - mean * mean );
6524 for (
double it = 3.0; it >= 0.0; it = it - 0.25 )
6526 thres = mean - ( it * sd );
6531 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6533 thres = std::max ( hVec.at(iter)[0], thres );
6537 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6539 if ( hVec.at(iter)[0] <= thres )
6541 clusts.emplace_back ( clusters.at(hVec.at(iter)[1]) );
6545 if ( ( clusts.size() > 0 ) && ( clusts.size() < 5 ) )
6547 if ( ( clusts.size() ) < hVec.size() )
6549 if ( ( hVec.at(clusts.size()-1)[0] > 3.0 ) && ( ( 2.0 * hVec.at(clusts.size()-1)[0] ) < hVec.at(clusts.size())[0] ) )
6556 if ( ( clusts.size() > std::max ( std::floor ( hVec.size() * 0.1 ), 5.0 ) ) && ( clusts.size() < hVec.size() ) ) {
break; }
6580 if ( this->fragBoxSize <= 0.0 )
6582 std::cerr <<
"!!! ProSHADE ERROR !!! Tried to fragment the map to boxes of size " << this->fragBoxSize <<
" . Terminating..." << std::endl;
6586 std::stringstream hlpSS;
6587 hlpSS <<
"<font color=\"red\">" <<
"The box size to which the map should be fragmented in not in the allowed range ( " << this->fragBoxSize <<
" )" <<
"</font>";
6588 rvapi_set_text ( hlpSS.str().c_str(),
6603 std::cout <<
"-----------------------------------------------------------" << std::endl;
6604 std::cout <<
"| MAP FRAGMENTATION |" << std::endl;
6605 std::cout <<
"-----------------------------------------------------------" << std::endl << std::endl;
6609 std::vector< std::array<unsigned int,2> > XDim;
6610 std::vector< std::array<unsigned int,2> > YDim;
6611 std::vector< std::array<unsigned int,2> > ZDim;
6612 std::array<unsigned int,2> hlpArrX;
6613 std::array<unsigned int,2> hlpArrY;
6614 std::array<unsigned int,2> hlpArrZ;
6615 double maxMapAngPerIndex = std::max ( this->one->_xRange / static_cast<double> ( this->one->_maxMapU ),
6616 std::max ( this->one->_yRange / static_cast<double> ( this->one->_maxMapV ),
6617 this->one->_zRange / static_cast<double> ( this->one->_maxMapW ) ) );
6618 unsigned int boxDimInIndices =
static_cast<unsigned int> ( std::round ( this->fragBoxSize / maxMapAngPerIndex ) );
6619 if ( ( boxDimInIndices % 2 ) == 1 )
6622 boxDimInIndices += 1;
6626 if ( boxDimInIndices < 2 )
6628 std::cerr <<
"!!! ProSHADE ERROR !!! The box size for fragmentation is too small, please increase the box size or submit more detailed map. (Increasing the number of points by interpolation could work without changing the map here...)" << std::endl;
6632 std::stringstream hlpSS;
6633 hlpSS <<
"<font color=\"red\">" <<
"The box size for fragmentation is too small, please increase the box size or submit more detailed map. (Increasing the number of points by interpolation could work without changing the map here...)." <<
"</font>";
6634 rvapi_set_text ( hlpSS.str().c_str(),
6646 if ( ( boxDimInIndices >= this->one->_maxMapU ) || ( boxDimInIndices >= this->one->_maxMapV ) || ( boxDimInIndices >= this->one->_maxMapW ) )
6648 std::cerr <<
"!!! ProSHADE ERROR !!! The box size for fragmentation is too large, please decrease the box size so that it is smaller than the map dimmensions." << std::endl;
6652 std::stringstream hlpSS;
6653 hlpSS <<
"<font color=\"red\">" <<
"The box size for fragmentation is too large, please decrease the box size so that it is smaller than the map dimmensions." <<
"</font>";
6654 rvapi_set_text ( hlpSS.str().c_str(),
6668 for (
unsigned int xStart = 0; xStart <= ( this->one->_maxMapU - boxDimInIndices ); xStart += ( boxDimInIndices / 2 ) )
6670 hlpArrX[0] = xStart;
6671 hlpArrX[1] = xStart + boxDimInIndices;
6674 if ( ( xStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapU - boxDimInIndices ) )
6677 hlpArrX[1] = this->one->_maxMapU;
6680 for (
unsigned int yStart = 0; yStart <= ( this->one->_maxMapV - boxDimInIndices ); yStart += ( boxDimInIndices / 2 ) )
6682 hlpArrY[0] = yStart;
6683 hlpArrY[1] = yStart + boxDimInIndices;
6686 if ( ( yStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapV - boxDimInIndices ) )
6689 hlpArrY[1] = this->one->_maxMapV;
6692 for (
unsigned int zStart = 0; zStart <= ( this->one->_maxMapW - boxDimInIndices ); zStart += ( boxDimInIndices / 2 ) )
6694 hlpArrZ[0] = zStart;
6695 hlpArrZ[1] = zStart + boxDimInIndices;
6698 if ( ( zStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapW - boxDimInIndices ) )
6701 hlpArrZ[1] = this->one->_maxMapW;
6704 XDim.emplace_back ( hlpArrX );
6705 YDim.emplace_back ( hlpArrY );
6706 ZDim.emplace_back ( hlpArrZ );
6713 std::cout <<
">> Box borders generated." << std::endl;
6717 unsigned int noDensityPoints = 0;
6718 unsigned int arrayPos = 0;
6719 unsigned int hlpPos = 0;
6721 double boxVolume = 0.0;
6722 int newU, newV, newW;
6723 std::string fileName;
6725 for (
unsigned int boxIt = 0; boxIt < static_cast<unsigned int> ( XDim.size() ); boxIt++ )
6728 noDensityPoints = 0;
6729 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
6731 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
6733 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
6735 arrayPos = z + (this->one->_maxMapW+1) * ( y + (this->one->_maxMapV+1) * x );
6737 if ( this->one->_densityMapCor[arrayPos] > 0.0 )
6739 noDensityPoints += 1;
6746 boxVolume = ( ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) + 1 ) * ( ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) + 1 ) * ( ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) + 1 );
6748 if ( ( static_cast<double> ( noDensityPoints ) / boxVolume ) > this->mapFragBoxFraction )
6751 fileName = this->mapFragName + std::to_string ( fileIter ) +
".map";
6752 this->fragFiles.emplace_back ( fileName );
6756 std::cout <<
">>>>> Writing out box " << fileIter-1 << std::endl;
6760 float *boxMap =
nullptr;
6761 boxMap = (
float*) malloc ( (XDim.at(boxIt)[1]-XDim.at(boxIt)[0]+1) * (YDim.at(boxIt)[1]-YDim.at(boxIt)[0]+1) * (ZDim.at(boxIt)[1]-ZDim.at(boxIt)[0]+1) *
sizeof (
float ) );
6762 if ( boxMap ==
nullptr )
6764 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
6768 std::stringstream hlpSS;
6769 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory. Could you have run out of memory?" <<
"</font>";
6770 rvapi_set_text ( hlpSS.str().c_str(),
6783 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
6785 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
6787 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
6789 arrayPos = z + (this->one->_maxMapW+1) * ( y + (this->one->_maxMapV+1) * x );
6791 newU = x - XDim.at(boxIt)[0];
6792 newV = y - YDim.at(boxIt)[0];
6793 newW = z - ZDim.at(boxIt)[0];
6794 hlpPos = newW + (ZDim.at(boxIt)[1]-ZDim.at(boxIt)[0]) * ( newV + (YDim.at(boxIt)[1]-YDim.at(boxIt)[0]) * newU );
6796 boxMap[hlpPos] = this->one->_densityMapCor[arrayPos];
6801 float xFrom = XDim.at(boxIt)[0] + this->one->_xFrom;
6802 float xTo = XDim.at(boxIt)[1] + this->one->_xFrom - 1;
6803 float yFrom = YDim.at(boxIt)[0] + this->one->_yFrom;
6804 float yTo = YDim.at(boxIt)[1] + this->one->_yFrom - 1;
6805 float zFrom = ZDim.at(boxIt)[0] + this->one->_zFrom;
6806 float zTo = ZDim.at(boxIt)[1] + this->one->_zFrom - 1;
6808 this->one->writeMap ( fileName.c_str(),
6817 ( this->one->_xSamplingRate * ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) ),
6818 ( this->one->_ySamplingRate * ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) ),
6819 ( this->one->_zSamplingRate * ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) ) );
6830 std::cout <<
">> " << fileIter <<
" boxes written in " << this->mapFragName <<
"xx ." << std::endl << std::endl;
6834 std::cout <<
">> No boxes conform to your criteria. NO BOXES WRITTEN." << std::endl << std::endl;
6837 if ( fileIter == 0 )
6839 std::cout <<
"!!! ProSHADE WARNING !!! No map fragments produced - no box passed the required criteria." << std::endl << std::endl;
6843 std::stringstream hlpSS;
6844 hlpSS <<
"<font color=\"orange\">" <<
"No map fragments produced - no box passed the required criteria.." <<
"</font>";
6845 rvapi_set_text ( hlpSS.str().c_str(),
6857 this->fragFilesExist =
true;
6880 double *zTranslate )
6888 unsigned int bandwidth1 = settings->
bandwidth;
6889 unsigned int bandwidth2 = settings->
bandwidth;
6890 unsigned int theta1 = settings->
theta;
6891 unsigned int theta2 = settings->
theta;
6892 unsigned int phi1 = settings->
phi;
6893 unsigned int phi2 = settings->
phi;
6913 std::cout <<
"Read in the first half map." << std::endl;
6918 std::stringstream hlpSS;
6919 hlpSS <<
"<font color=\"green\">" <<
"Read in the first half map." <<
"</font>";
6920 rvapi_set_text ( hlpSS.str().c_str(),
6946 std::cout <<
"Read in the second half map." << std::endl;
6951 std::stringstream hlpSS;
6952 hlpSS <<
"<font color=\"green\">" <<
"Read in the second half map." <<
"</font>";
6953 rvapi_set_text ( hlpSS.str().c_str(),
6964 bool sizeAndSampleIdentical =
true;
6965 if ( ( halfMap1->_xRange != halfMap2->_xRange ) || ( halfMap1->_yRange != halfMap2->_yRange ) || ( halfMap1->_zRange != halfMap2->_zRange ) )
6967 std::cout <<
"!!! ProSHADE WARNING !!! The cell ranges differ between the two half maps - this is not allowed for half maps. Will attempt to re-size and re-sample the maps, but beware this may not be what you wanted. Please check the output manually." << std::endl;
6971 std::stringstream hlpSS;
6972 hlpSS <<
"<font color=\"orange\">" <<
"The cell ranges differ between the two half maps - this is not allowed for half maps. Will attempt to re-size and re-sample the maps, but beware this may not be what you wanted. Please check the output manually." <<
"</font>";
6973 rvapi_set_text ( hlpSS.str().c_str(),
6983 sizeAndSampleIdentical =
false;
6986 if ( ( halfMap1->_maxMapU != halfMap2->_maxMapU ) || ( halfMap1->_maxMapV != halfMap2->_maxMapV ) || ( halfMap1->_maxMapW != halfMap2->_maxMapW ) )
6988 std::cout <<
"!!! ProSHADE WARNING !!! The cell dimensions differ between the two half maps - this is not allowed for half maps. Will attempt to re-size and re-sample the maps, but beware this may not be what you wanted. Please check the output manually." << std::endl;
6992 std::stringstream hlpSS;
6993 hlpSS <<
"<font color=\"orange\">" <<
"The cell dimensions differ between the two half maps - this is not allowed for half maps. Will attempt to re-size and re-sample the maps, but beware this may not be what you wanted. Please check the output manually." <<
"</font>";
6994 rvapi_set_text ( hlpSS.str().c_str(),
7004 sizeAndSampleIdentical =
false;
7007 if ( !sizeAndSampleIdentical )
7011 std::cout <<
"Starting the re-sampling and re-sizing procedure. This may take some time." << std::endl;
7016 std::stringstream hlpSS;
7017 hlpSS <<
"<font color=\"green\">" <<
"Starting the re-sampling and re-sizing procedure. This may take some time." <<
"</font>";
7018 rvapi_set_text ( hlpSS.str().c_str(),
7029 halfMap1->_densityMapCor =
new double[(halfMap1->_maxMapU+1)*(halfMap1->_maxMapV+1)*(halfMap1->_maxMapW+1)];
7030 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (halfMap1->_maxMapU+1)*(halfMap1->_maxMapV+1)*(halfMap1->_maxMapW+1) ); iter++ )
7032 halfMap1->_densityMapCor[iter] = halfMap1->_densityMapMap[iter];
7034 delete[] halfMap1->_densityMapMap;
7035 halfMap1->_densityMapMap =
nullptr;
7037 halfMap2->_densityMapCor =
new double[(halfMap2->_maxMapU+1)*(halfMap2->_maxMapV+1)*(halfMap2->_maxMapW+1)];
7038 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (halfMap2->_maxMapU+1)*(halfMap2->_maxMapV+1)*(halfMap2->_maxMapW+1) ); iter++ )
7040 halfMap2->_densityMapCor[iter] = halfMap2->_densityMapMap[iter];
7042 delete[] halfMap2->_densityMapMap;
7043 halfMap2->_densityMapMap =
nullptr;
7050 std::max ( glInteg1, glInteg2 ),
7052 std::array<double,4> translationVec;
7053 double xMapMov, yMapMov, zMapMov;
7064 if ( sizeAndSampleIdentical )
7066 rvapi_add_section (
"h1Header",
7067 "Half Map 1 Header",
7077 rvapi_add_section (
"h1Header",
7078 "Half Map 1 Header (after re-sampling)",
7089 std::stringstream hlpSS;
7090 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7091 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7097 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length(),
7098 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length(),
7099 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ) );
7100 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length(),
7101 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length(),
7102 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ) );
7103 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length(),
7104 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length(),
7105 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ) );
7106 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length(),
7107 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length(),
7108 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ) );
7109 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
7110 if ( spacer < 5 ) { spacer = 5; }
7112 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap1->_maxMapU+1 );
7113 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length() ); iter++ )
7119 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapV+1 );
7120 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length() ); iter++ )
7126 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapW+1 );
7127 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ); iter++ )
7133 rvapi_set_text ( hlpSS.str().c_str(),
7141 hlpSS.str ( std::string ( ) );
7142 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
7143 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7148 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xFrom;
7149 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length() ); iter++ )
7155 hlpSS << std::showpos << halfMap1->_xTo;
7156 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length() ); iter++ )
7162 hlpSS << std::showpos << halfMap1->_yFrom;
7163 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length() ); iter++ )
7169 hlpSS << std::showpos << halfMap1->_yTo;
7170 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length() ); iter++ )
7176 hlpSS << std::showpos <<
" " << halfMap1->_zFrom;
7177 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ); iter++ )
7183 hlpSS << std::showpos << halfMap1->_zTo;
7184 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ); iter++ )
7190 rvapi_set_text ( hlpSS.str().c_str(),
7198 hlpSS.str ( std::string ( ) );
7199 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
7200 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7205 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xRange;
7206 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length() ); iter++ )
7212 hlpSS << std::showpos << halfMap1->_yRange;
7213 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length() ); iter++ )
7219 hlpSS << std::showpos << halfMap1->_zRange;
7220 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ); iter++ )
7226 rvapi_set_text ( hlpSS.str().c_str(),
7234 hlpSS.str ( std::string ( ) );
7235 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
7236 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7241 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
7242 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7248 hlpSS << std::showpos << 90.0;
7249 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7255 hlpSS << std::showpos << 90.0;
7256 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7262 rvapi_set_text ( hlpSS.str().c_str(),
7270 hlpSS.str ( std::string ( ) );
7271 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
7272 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7277 std::string hlpAO = settings->
axisOrder;
7278 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
7279 hlpSS <<
" " << hlpAO;
7280 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
7286 rvapi_set_text ( hlpSS.str().c_str(),
7298 if ( sizeAndSampleIdentical )
7300 rvapi_add_section (
"h2Header",
7301 "Half Map 2 Header",
7311 rvapi_add_section (
"h2Header",
7312 "Half Map 2 Header (after re-sampling)",
7323 std::stringstream hlpSS;
7324 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7325 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7331 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length(),
7332 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length(),
7333 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ) );
7334 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length(),
7335 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length(),
7336 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ) );
7337 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length(),
7338 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length(),
7339 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ) );
7340 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length(),
7341 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length(),
7342 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ) );
7343 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
7344 if ( spacer < 5 ) { spacer = 5; }
7346 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap2->_maxMapU+1 );
7347 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length() ); iter++ )
7353 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapV+1 );
7354 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length() ); iter++ )
7360 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapW+1 );
7361 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ); iter++ )
7367 rvapi_set_text ( hlpSS.str().c_str(),
7375 hlpSS.str ( std::string ( ) );
7376 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
7377 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7382 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xFrom;
7383 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length() ); iter++ )
7389 hlpSS << std::showpos << halfMap2->_xTo;
7390 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length() ); iter++ )
7396 hlpSS << std::showpos << halfMap2->_yFrom;
7397 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length() ); iter++ )
7403 hlpSS << std::showpos << halfMap2->_yTo;
7404 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length() ); iter++ )
7410 hlpSS << std::showpos <<
" " << halfMap2->_zFrom;
7411 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ); iter++ )
7417 hlpSS << std::showpos << halfMap2->_zTo;
7418 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ); iter++ )
7424 rvapi_set_text ( hlpSS.str().c_str(),
7432 hlpSS.str ( std::string ( ) );
7433 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
7434 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7439 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xRange;
7440 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length() ); iter++ )
7446 hlpSS << std::showpos << halfMap2->_yRange;
7447 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length() ); iter++ )
7453 hlpSS << std::showpos << halfMap2->_zRange;
7454 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ); iter++ )
7460 rvapi_set_text ( hlpSS.str().c_str(),
7468 hlpSS.str ( std::string ( ) );
7469 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
7470 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7475 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
7476 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7482 hlpSS << std::showpos << 90.0;
7483 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7489 hlpSS << std::showpos << 90.0;
7490 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7496 rvapi_set_text ( hlpSS.str().c_str(),
7504 hlpSS.str ( std::string ( ) );
7505 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
7506 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7511 std::string hlpAO = settings->
axisOrder;
7512 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
7513 hlpSS <<
" " << hlpAO;
7514 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
7520 rvapi_set_text ( hlpSS.str().c_str(),
7531 fftw_complex *tmpOutA;
7532 fftw_complex *tmpInA;
7533 fftw_complex *tmpOutB;
7534 fftw_complex *tmpInB;
7538 int hlpU = halfMap1->_maxMapU + 1;
7539 int hlpV = halfMap1->_maxMapV + 1;
7540 int hlpW = halfMap1->_maxMapW + 1;
7543 tmpInA =
new fftw_complex[hlpU * hlpV * hlpW];
7544 tmpOutA =
new fftw_complex[hlpU * hlpV * hlpW];
7545 tmpInB =
new fftw_complex[hlpU * hlpV * hlpW];
7546 tmpOutB =
new fftw_complex[hlpU * hlpV * hlpW];
7549 pA = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpInA, tmpOutA, FFTW_FORWARD, FFTW_ESTIMATE );
7550 pB = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpInB, tmpOutB, FFTW_FORWARD, FFTW_ESTIMATE );
7553 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
7555 if ( halfMap1->_densityMapCor[iter] == halfMap1->_densityMapCor[iter] )
7558 tmpInA[iter][0] = halfMap1->_densityMapCor[iter];
7559 tmpInA[iter][1] = 0.0;
7564 tmpInA[iter][0] = 0.0;
7565 tmpInA[iter][1] = 0.0;
7568 if ( halfMap2->_densityMapCor[iter] == halfMap2->_densityMapCor[iter] )
7571 tmpInB[iter][0] = halfMap2->_densityMapCor[iter];
7572 tmpInB[iter][1] = 0.0;
7577 tmpInB[iter][0] = 0.0;
7578 tmpInB[iter][1] = 0.0;
7583 fftw_execute ( pA );
7584 fftw_execute ( pB );
7585 fftw_destroy_plan ( pA );
7586 fftw_destroy_plan ( pB );
7589 fftw_complex* maskDataA =
new fftw_complex [ hlpU * hlpV * hlpW ];
7590 fftw_complex* maskDataInvA =
new fftw_complex [ hlpU * hlpV * hlpW ];
7591 fftw_complex* maskDataB =
new fftw_complex [ hlpU * hlpV * hlpW ];
7592 fftw_complex* maskDataInvB =
new fftw_complex [ hlpU * hlpV * hlpW ];
7597 unsigned int arrayPos = 0;
7598 double normFactor = (hlpU * hlpV * hlpW);
7601 double mag, phase, S;
7604 fftw_plan pMaskInvA = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInvA, maskDataA, FFTW_BACKWARD, FFTW_ESTIMATE );
7605 fftw_plan pMaskInvB = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInvB, maskDataB, FFTW_BACKWARD, FFTW_ESTIMATE );
7607 for ( uIt = 0; uIt < hlpU; uIt++ )
7609 for ( vIt = 0; vIt < hlpV; vIt++ )
7611 for ( wIt = 0; wIt < hlpW; wIt++ )
7615 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7616 real = tmpOutA[arrayPos][0];
7617 imag = tmpOutA[arrayPos][1];
7620 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
7621 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
7622 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
7625 S = ( pow( static_cast<double> ( h ) / halfMap1->_xRange, 2.0 ) +
7626 pow( static_cast<double> ( k ) / halfMap1->_yRange, 2.0 ) +
7627 pow( static_cast<double> ( l ) / halfMap1->_zRange, 2.0 ) );
7628 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
7629 phase = atan2 ( imag, real );
7632 maskDataInvA[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
7633 maskDataInvA[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
7637 real = tmpOutB[arrayPos][0];
7638 imag = tmpOutB[arrayPos][1];
7641 S = ( pow( static_cast<double> ( h ) / halfMap2->_xRange, 2.0 ) +
7642 pow( static_cast<double> ( k ) / halfMap2->_yRange, 2.0 ) +
7643 pow( static_cast<double> ( l ) / halfMap2->_zRange, 2.0 ) );
7644 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
7645 phase = atan2 ( imag, real );
7648 maskDataInvB[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
7649 maskDataInvB[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
7655 fftw_execute ( pMaskInvA );
7656 fftw_execute ( pMaskInvB );
7657 fftw_destroy_plan ( pMaskInvA );
7658 fftw_destroy_plan ( pMaskInvB );
7659 delete[] maskDataInvA;
7660 delete[] maskDataInvB;
7666 std::cout <<
">>>>> Map blurring complete." << std::endl;
7671 std::stringstream hlpSS;
7672 hlpSS <<
"<font color=\"green\">" <<
"Map blurring complete." <<
"</font>";
7673 rvapi_set_text ( hlpSS.str().c_str(),
7684 double mapThresholdPlusA = 0.0;
7685 double mapThresholdPlusB = 0.0;
7686 unsigned int hlpIt = 0;
7687 std::vector<double> maskValsA ( hlpU * hlpV * hlpW );
7688 std::vector<double> maskValsB ( hlpU * hlpV * hlpW );
7690 for ( uIt = 0; uIt < hlpU; uIt++ ) {
for ( vIt = 0; vIt < hlpV; vIt++ ) {
for ( wIt = 0; wIt < hlpW; wIt++ ) { arrayPos = wIt + hlpW * ( vIt + hlpV * uIt ); maskValsA.at(hlpIt) = maskDataA[arrayPos][0]; maskValsB.at(hlpIt) = maskDataB[arrayPos][0]; hlpIt += 1; } } }
7692 unsigned int medianPos =
static_cast<unsigned int> ( maskValsA.size() / 2 );
7693 std::sort ( maskValsA.begin(), maskValsA.end() );
7694 std::sort ( maskValsB.begin(), maskValsB.end() );
7696 double interQuartileRangeA = maskValsA.at(medianPos+(medianPos/2)) - maskValsA.at(medianPos-(medianPos/2));
7697 mapThresholdPlusA = maskValsA.at(medianPos+(medianPos/2)) + ( interQuartileRangeA * settings->
noIQRsFromMap );
7699 double interQuartileRangeB = maskValsB.at(medianPos+(medianPos/2)) - maskValsB.at(medianPos-(medianPos/2));
7700 mapThresholdPlusB = maskValsB.at(medianPos+(medianPos/2)) + ( interQuartileRangeB * settings->
noIQRsFromMap );
7702 maskValsA.clear ( );
7703 maskValsB.clear ( );
7706 for ( uIt = 0; uIt < hlpU; uIt++ )
7708 for ( vIt = 0; vIt < hlpV; vIt++ )
7710 for ( wIt = 0; wIt < hlpW; wIt++ )
7713 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7716 if ( mapThresholdPlusA >= maskDataA[arrayPos][0] )
7718 tmpInA[arrayPos][0] = 0.0;
7720 if ( mapThresholdPlusB >= maskDataB[arrayPos][0] )
7722 tmpInB[arrayPos][0] = 0.0;
7734 std::stringstream hlpSS;
7735 hlpSS <<
"<font color=\"green\">" <<
"Map masking complete." <<
"</font>";
7736 rvapi_set_text ( hlpSS.str().c_str(),
7748 bool atLeastSingleValueA =
false;
7749 bool atLeastSingleValueB =
false;
7750 for ( uIt = 0; uIt < hlpU; uIt++ )
7752 for ( vIt = 0; vIt < hlpV; vIt++ )
7754 for ( wIt = 0; wIt < hlpW; wIt++ )
7757 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7759 if ( !atLeastSingleValueA ) {
if ( tmpInA[arrayPos][0] > 0.0 ) { atLeastSingleValueA =
true; } }
7760 if ( !atLeastSingleValueB ) {
if ( tmpInB[arrayPos][0] > 0.0 ) { atLeastSingleValueB =
true; } }
7765 if ( !atLeastSingleValueA || !atLeastSingleValueB )
7767 printf (
"!!! ProSHADE ERROR !!! The masking procedure failed to detect any significant density in the map!\n" );
7771 std::stringstream hlpSS;
7772 hlpSS <<
"<font color=\"red\">" <<
"The masking procedure failed to detect any significant density in the map. Please consider changing the blurring coefficient value." <<
"</font>";
7773 rvapi_set_text ( hlpSS.str().c_str(),
7795 for ( uIt = 0; uIt < hlpU; uIt++ )
7797 for ( vIt = 0; vIt < hlpV; vIt++ )
7799 for ( wIt = 0; wIt < hlpW; wIt++ )
7801 arrPos = wIt + hlpW * ( vIt + hlpV * uIt );
7803 if ( tmpInA[arrPos][0] > 0.0 )
7805 maxX = std::max ( maxX, uIt );
7806 minX = std::min ( minX, uIt );
7807 maxY = std::max ( maxY, vIt );
7808 minY = std::min ( minY, vIt );
7809 maxZ = std::max ( maxZ, wIt );
7810 minZ = std::min ( minZ, wIt );
7812 if ( tmpInB[arrPos][0] > 0.0 )
7814 maxX = std::max ( maxX, uIt );
7815 minX = std::min ( minX, uIt );
7816 maxY = std::max ( maxY, vIt );
7817 minY = std::min ( minY, vIt );
7818 maxZ = std::max ( maxZ, wIt );
7819 minZ = std::min ( minZ, wIt );
7829 maxX += std::ceil ( 7.5 / halfMap1->_xSamplingRate );
7830 maxY += std::ceil ( 7.5 / halfMap1->_ySamplingRate );
7831 maxZ += std::ceil ( 7.5 / halfMap1->_zSamplingRate );
7832 minX -= std::ceil ( 7.5 / halfMap1->_xSamplingRate );
7833 minY -= std::ceil ( 7.5 / halfMap1->_ySamplingRate );
7834 minZ -= std::ceil ( 7.5 / halfMap1->_zSamplingRate );
7836 if ( maxX > static_cast<int> ( halfMap1->_maxMapU ) ) { maxX = halfMap1->_maxMapU; }
7837 if ( maxY > static_cast<int> ( halfMap1->_maxMapV ) ) { maxY = halfMap1->_maxMapV; }
7838 if ( maxZ > static_cast<int> ( halfMap1->_maxMapW ) ) { maxZ = halfMap1->_maxMapW; }
7839 if ( minX < 0 ) { minX = 0; }
7840 if ( minY < 0 ) { minY = 0; }
7841 if ( minZ < 0 ) { minZ = 0; }
7846 minX = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7847 minY = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7848 minZ = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7849 maxX = std::min ( hlpU, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7850 maxY = std::min ( hlpV, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7851 maxZ = std::min ( hlpW, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7853 if ( ( maxX != maxY ) || ( maxX != maxZ ) || ( maxY != maxZ ) )
7855 std::cout <<
"!!! ProSHADE Warning !!! Although cubic map was requested, this cannot be done as the input is not cubic and cutting it to cubic would result in density being removed. Maps will not be cubic." << std::endl;
7859 std::stringstream hlpSS;
7860 hlpSS <<
"<font color=\"orange\">" <<
"Although cubic map was requested, this cannot be done as the input is not cubic and cutting it to cubic would result in density being removed. Maps will not be cubic." <<
"</font>";
7861 rvapi_set_text ( hlpSS.str().c_str(),
7874 int xDim = 1 + maxX - minX;
7875 int yDim = 1 + maxY - minY;
7876 int zDim = 1 + maxZ - minZ;
7879 double* newHalf1Map =
new double[xDim * yDim * zDim];
7880 double* newHalf2Map =
new double[xDim * yDim * zDim];
7882 for (
int xIt = 0; xIt < hlpU; xIt++ )
7884 for (
int yIt = 0; yIt < hlpV; yIt++ )
7886 for (
int zIt = 0; zIt < hlpW; zIt++ )
7888 if ( ( xIt < minX ) || ( xIt > maxX ) ) {
continue; }
7889 if ( ( yIt < minY ) || ( yIt > maxY ) ) {
continue; }
7890 if ( ( zIt < minZ ) || ( zIt > maxZ ) ) {
continue; }
7892 arrPos = zIt + hlpW * ( yIt + hlpV * xIt );
7893 hlpPos = (zIt - minZ) + zDim * ( (yIt - minY) + yDim * (xIt - minX) );
7895 newHalf1Map[hlpPos] = halfMap1->_densityMapCor[arrPos];
7896 newHalf2Map[hlpPos] = halfMap2->_densityMapCor[arrPos];
7902 delete[] halfMap1->_densityMapCor;
7903 delete[] halfMap2->_densityMapCor;
7904 halfMap1->_densityMapCor =
new double[xDim * yDim * zDim];
7905 halfMap2->_densityMapCor =
new double[xDim * yDim * zDim];
7906 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( xDim * yDim * zDim ); iter++ )
7908 halfMap1->_densityMapCor[iter] = newHalf1Map[iter];
7909 halfMap2->_densityMapCor[iter] = newHalf2Map[iter];
7911 delete[] newHalf1Map;
7912 delete[] newHalf2Map;
7916 std::stringstream hlpSS;
7917 hlpSS <<
"<font color=\"green\">" <<
"Half maps re-boxed." <<
"</font>";
7918 rvapi_set_text ( hlpSS.str().c_str(),
7929 int oDimX1 = halfMap1->_maxMapU;
7930 int oDimY1 = halfMap1->_maxMapV;
7931 int oDimZ1 = halfMap1->_maxMapW;
7933 int oDimX2 = halfMap2->_maxMapU;
7934 int oDimY2 = halfMap2->_maxMapV;
7935 int oDimZ2 = halfMap2->_maxMapW;
7937 halfMap1->_maxMapU = xDim;
7938 halfMap1->_maxMapV = yDim;
7939 halfMap1->_maxMapW = zDim;
7941 halfMap1->_xTo = maxX + halfMap1->_xFrom;
7942 halfMap1->_yTo = maxY + halfMap1->_yFrom;
7943 halfMap1->_zTo = maxZ + halfMap1->_zFrom;
7945 halfMap1->_xFrom = minX + halfMap1->_xFrom;
7946 halfMap1->_yFrom = minY + halfMap1->_yFrom;
7947 halfMap1->_zFrom = minZ + halfMap1->_zFrom;
7949 halfMap1->_xRange = xDim * halfMap1->_xSamplingRate;
7950 halfMap1->_yRange = yDim * halfMap1->_ySamplingRate;
7951 halfMap1->_zRange = zDim * halfMap1->_zSamplingRate;
7953 halfMap2->_maxMapU = xDim;
7954 halfMap2->_maxMapV = yDim;
7955 halfMap2->_maxMapW = zDim;
7957 halfMap2->_xTo = maxX + halfMap2->_xFrom;
7958 halfMap2->_yTo = maxY + halfMap2->_yFrom;
7959 halfMap2->_zTo = maxZ + halfMap2->_zFrom;
7961 halfMap2->_xFrom = minX + halfMap2->_xFrom;
7962 halfMap2->_yFrom = minY + halfMap2->_yFrom;
7963 halfMap2->_zFrom = minZ + halfMap2->_zFrom;
7965 halfMap2->_xRange = xDim * halfMap2->_xSamplingRate;
7966 halfMap2->_yRange = yDim * halfMap2->_ySamplingRate;
7967 halfMap2->_zRange = zDim * halfMap2->_zSamplingRate;
7972 rvapi_add_section (
"h1OutHeader",
7973 "Half Map 1 Re-boxed Header",
7983 std::stringstream hlpSS;
7984 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7985 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7991 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length(),
7992 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length(),
7993 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ) );
7994 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length(),
7995 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length(),
7996 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ) );
7997 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length(),
7998 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length(),
7999 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ) );
8000 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length(),
8001 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length(),
8002 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ) );
8003 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
8004 if ( spacer < 5 ) { spacer = 5; }
8006 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap1->_maxMapU+1 );
8007 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length() ); iter++ )
8013 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapV+1 );
8014 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length() ); iter++ )
8020 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapW+1 );
8021 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ); iter++ )
8027 rvapi_set_text ( hlpSS.str().c_str(),
8035 hlpSS.str ( std::string ( ) );
8036 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
8037 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8042 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xFrom;
8043 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length() ); iter++ )
8049 hlpSS << std::showpos << halfMap1->_xTo;
8050 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length() ); iter++ )
8056 hlpSS << std::showpos << halfMap1->_yFrom;
8057 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length() ); iter++ )
8063 hlpSS << std::showpos << halfMap1->_yTo;
8064 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length() ); iter++ )
8070 hlpSS << std::showpos <<
" " << halfMap1->_zFrom;
8071 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ); iter++ )
8077 hlpSS << std::showpos << halfMap1->_zTo;
8078 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ); iter++ )
8084 rvapi_set_text ( hlpSS.str().c_str(),
8092 hlpSS.str ( std::string ( ) );
8093 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
8094 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8099 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xRange;
8100 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length() ); iter++ )
8106 hlpSS << std::showpos << halfMap1->_yRange;
8107 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length() ); iter++ )
8113 hlpSS << std::showpos << halfMap1->_zRange;
8114 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ); iter++ )
8120 rvapi_set_text ( hlpSS.str().c_str(),
8128 hlpSS.str ( std::string ( ) );
8129 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
8130 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8135 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
8136 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8142 hlpSS << std::showpos << 90.0;
8143 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8149 hlpSS << std::showpos << 90.0;
8150 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8156 rvapi_set_text ( hlpSS.str().c_str(),
8164 hlpSS.str ( std::string ( ) );
8165 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
8166 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8171 std::string hlpAO = settings->
axisOrder;
8172 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
8173 hlpSS <<
" " << hlpAO;
8174 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
8180 rvapi_set_text ( hlpSS.str().c_str(),
8192 rvapi_add_section (
"h2OutHeader",
8193 "Half Map 2 Re-boxed Header",
8203 std::stringstream hlpSS;
8204 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
8205 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8211 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length(),
8212 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length(),
8213 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ) );
8214 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length(),
8215 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length(),
8216 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ) );
8217 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length(),
8218 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length(),
8219 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ) );
8220 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length(),
8221 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length(),
8222 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ) );
8223 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
8224 if ( spacer < 5 ) { spacer = 5; }
8226 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap2->_maxMapU+1 );
8227 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length() ); iter++ )
8233 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapV+1 );
8234 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length() ); iter++ )
8240 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapW+1 );
8241 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ); iter++ )
8247 rvapi_set_text ( hlpSS.str().c_str(),
8255 hlpSS.str ( std::string ( ) );
8256 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
8257 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8262 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xFrom;
8263 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length() ); iter++ )
8269 hlpSS << std::showpos << halfMap2->_xTo;
8270 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length() ); iter++ )
8276 hlpSS << std::showpos << halfMap2->_yFrom;
8277 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length() ); iter++ )
8283 hlpSS << std::showpos << halfMap2->_yTo;
8284 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length() ); iter++ )
8290 hlpSS << std::showpos <<
" " << halfMap2->_zFrom;
8291 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ); iter++ )
8297 hlpSS << std::showpos << halfMap2->_zTo;
8298 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ); iter++ )
8304 rvapi_set_text ( hlpSS.str().c_str(),
8312 hlpSS.str ( std::string ( ) );
8313 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
8314 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8319 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xRange;
8320 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length() ); iter++ )
8326 hlpSS << std::showpos << halfMap2->_yRange;
8327 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length() ); iter++ )
8333 hlpSS << std::showpos << halfMap2->_zRange;
8334 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ); iter++ )
8340 rvapi_set_text ( hlpSS.str().c_str(),
8348 hlpSS.str ( std::string ( ) );
8349 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
8350 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8355 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
8356 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8362 hlpSS << std::showpos << 90.0;
8363 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8369 hlpSS << std::showpos << 90.0;
8370 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8376 rvapi_set_text ( hlpSS.str().c_str(),
8384 hlpSS.str ( std::string ( ) );
8385 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
8386 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8391 std::string hlpAO = settings->
axisOrder;
8392 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
8393 hlpSS <<
" " << hlpAO;
8394 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
8400 rvapi_set_text ( hlpSS.str().c_str(),
8411 std::stringstream ss;
8413 halfMap1->writeMap ( ss.str(), halfMap1->_densityMapCor );
8415 ss.str( std::string ( ) );
8417 halfMap2->writeMap ( ss.str(), halfMap2->_densityMapCor );
8421 std::stringstream hlpSS;
8422 hlpSS <<
"<font color=\"green\">" <<
"Half maps saved." <<
"</font>";
8423 rvapi_set_text ( hlpSS.str().c_str(),
8435 rvapi_add_section (
"ResultsSection",
8445 std::stringstream hlpSS;
8446 hlpSS <<
"<pre><b>" <<
"The re-boxed structures are available at: </b>" << settings->
clearMapFile <<
"_half1.map" <<
"</pre>";
8447 rvapi_set_text ( hlpSS.str().c_str(),
8454 hlpSS.str ( std::string ( ) );
8455 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << settings->
clearMapFile <<
"_half2.map" <<
"</pre>";
8456 rvapi_set_text ( hlpSS.str().c_str(),
8463 hlpSS.str ( std::string ( ) );
8464 hlpSS <<
"<pre><b>" <<
"Original structure dims: </b>" << oDimX1+1 <<
" x " << oDimY1+1 <<
" x " << oDimZ1+1 <<
"</pre>";
8465 rvapi_set_text ( hlpSS.str().c_str(),
8472 hlpSS.str ( std::string ( ) );
8473 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << oDimX2+1 <<
" x " << oDimY2+1 <<
" x " << oDimZ2+1 <<
"</pre>";
8474 rvapi_set_text ( hlpSS.str().c_str(),
8481 hlpSS.str ( std::string ( ) );
8482 hlpSS <<
"<pre><b>" <<
"Re-boxed structure dims: </b>" << halfMap1->_maxMapU <<
" x " << halfMap1->_maxMapV <<
" x " << halfMap1->_maxMapW <<
"</pre>";
8483 rvapi_set_text ( hlpSS.str().c_str(),
8490 hlpSS.str ( std::string ( ) );
8491 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << halfMap2->_maxMapU <<
" x " << halfMap2->_maxMapV <<
" x " << halfMap2->_maxMapW <<
"</pre>";
8492 rvapi_set_text ( hlpSS.str().c_str(),
8499 hlpSS.str ( std::string ( ) );
8500 hlpSS <<
"<pre><b>" <<
"New volume as percentage of old volume: </b>" << ProSHADE_internal_misc::to_string_with_precision ( ( static_cast<double> ( (halfMap1->_maxMapU+1) * (halfMap1->_maxMapV+1) * (halfMap1->_maxMapW+1) ) / static_cast<double> ( (oDimX1+1) * (oDimY1+1) * (oDimZ1+1) ) ) * 100 ) <<
" %</pre>";
8501 rvapi_set_text ( hlpSS.str().c_str(),
8508 hlpSS.str ( std::string ( ) );
8509 hlpSS <<
"<pre><b>" <<
"Linear processing speed-up: </b>" << ProSHADE_internal_misc::to_string_with_precision ( ( ( (oDimX1+1) * (oDimY1+1) * (oDimZ1+1) ) / ( (halfMap1->_maxMapU+1) * (halfMap1->_maxMapV+1) * (halfMap1->_maxMapW+1) ) ) - 1.0 ) <<
" times</pre>";
8510 rvapi_set_text ( hlpSS.str().c_str(),
8547 if ( !this->_densityMapComputed )
8549 std::cerr <<
"!!! ProSHADE ERROR !!! Tried to fragment map without first computing it. Terminating..." << std::endl;
8553 std::stringstream hlpSS;
8554 hlpSS <<
"<font color=\"red\">" <<
"Tried to fragment map without first computing it. This looks like an internal bug - please report this case." <<
"</font>";
8555 rvapi_set_text ( hlpSS.str().c_str(),
8570 std::cout <<
">> Fragmenting map." << std::endl;
8574 std::vector<ProSHADE_data*> ret;
8575 std::vector< std::array<unsigned int,2> > XDim;
8576 std::vector< std::array<unsigned int,2> > YDim;
8577 std::vector< std::array<unsigned int,2> > ZDim;
8578 std::array<unsigned int,2> hlpArrX;
8579 std::array<unsigned int,2> hlpArrY;
8580 std::array<unsigned int,2> hlpArrZ;
8581 double maxMapAngPerIndex = std::max ( this->_xRange / static_cast<double> ( this->_maxMapU ),
8582 std::max ( this->_yRange / static_cast<double> ( this->_maxMapV ),
8583 this->_zRange / static_cast<double> ( this->_maxMapW ) ) );
8585 unsigned int boxDimInIndices =
static_cast<unsigned int> ( std::round ( settings->
mapFragBoxSize / maxMapAngPerIndex ) );
8586 if ( ( boxDimInIndices % 2 ) == 1 )
8589 boxDimInIndices += 1;
8593 if ( boxDimInIndices < 2 )
8595 std::cerr <<
"!!! ProSHADE ERROR !!! The box size for fragmentation is too small, please increase the box size or submit more detailed map. (Increasing the number of points by interpolation could work without changing the map here...)" << std::endl;
8599 std::stringstream hlpSS;
8600 hlpSS <<
"<font color=\"red\">" <<
"The box size for fragmentation is too small, please increase the box size or submit more detailed map. (Increasing the number of points by interpolation could work without changing the map here...)." <<
"</font>";
8601 rvapi_set_text ( hlpSS.str().c_str(),
8613 if ( ( boxDimInIndices >= this->_maxMapU ) || ( boxDimInIndices >= this->_maxMapV ) || ( boxDimInIndices >= this->_maxMapW ) )
8615 std::cerr <<
"!!! ProSHADE ERROR !!! The box size for fragmentation is too large, please decrease the box size so that it is smaller than the clearmap dimmensions." << std::endl;
8619 std::stringstream hlpSS;
8620 hlpSS <<
"<font color=\"red\">" <<
"The box size for fragmentation is too large, please decrease the box size so that it is smaller than the map dimmensions." <<
"</font>";
8621 rvapi_set_text ( hlpSS.str().c_str(),
8635 std::cout <<
">>>>>>>> Sanity checks passed." << std::endl;
8639 for (
unsigned int xStart = 0; xStart <= ( this->_maxMapU - boxDimInIndices ); xStart += ( boxDimInIndices / 2 ) )
8641 hlpArrX[0] = xStart;
8642 hlpArrX[1] = xStart + boxDimInIndices;
8645 if ( ( xStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapU - boxDimInIndices ) )
8648 hlpArrX[1] = this->_maxMapU;
8651 for (
unsigned int yStart = 0; yStart <= ( this->_maxMapV - boxDimInIndices ); yStart += ( boxDimInIndices / 2 ) )
8653 hlpArrY[0] = yStart;
8654 hlpArrY[1] = yStart + boxDimInIndices;
8657 if ( ( yStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapV - boxDimInIndices ) )
8660 hlpArrY[1] = this->_maxMapV;
8663 for (
unsigned int zStart = 0; zStart <= ( this->_maxMapW - boxDimInIndices ); zStart += ( boxDimInIndices / 2 ) )
8665 hlpArrZ[0] = zStart;
8666 hlpArrZ[1] = zStart + boxDimInIndices;
8669 if ( ( zStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapW - boxDimInIndices ) )
8672 hlpArrZ[1] = this->_maxMapW;
8675 XDim.emplace_back ( hlpArrX );
8676 YDim.emplace_back ( hlpArrY );
8677 ZDim.emplace_back ( hlpArrZ );
8683 std::cout <<
">>>>> Box sizes computed." << std::endl;
8687 unsigned int noDensityPoints = 0;
8688 unsigned int strCounter = 0;
8689 unsigned int arrayPos = 0;
8691 double boxVolume = 0.0;
8695 double densTot = 0.0;
8696 int newU, newV, newW;
8697 int hlpU, hlpV, hlpW;
8698 std::vector<double> mapVals;
8699 std::string fileName;
8701 for (
unsigned int boxIt = 0; boxIt < static_cast<unsigned int> ( XDim.size() ); boxIt++ )
8705 std::cout <<
">>>>> Trying box " << boxIt <<
" ." << std::endl;
8709 noDensityPoints = 0;
8710 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
8712 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
8714 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
8716 arrayPos = z + (this->_maxMapW+1) * ( y + (this->_maxMapV+1) * x );
8718 if ( this->_densityMapCor[arrayPos] > 0.0 )
8720 noDensityPoints += 1;
8727 boxVolume = ( ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) + 1 ) * ( ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) + 1 ) * ( ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) + 1 );
8728 if ( ( static_cast<double> ( noDensityPoints ) / boxVolume ) > settings->
mapFragBoxFraction )
8734 ret.at(strCounter)->_fromPDB =
false;
8735 ret.at(strCounter)->_shellSpacing = settings->
shellSpacing;
8736 ret.at(strCounter)->_maxExtraCellularSpace = settings->
extraSpace;
8737 ret.at(strCounter)->_xRange = ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) * ( this->_xRange / static_cast<double> ( this->_maxMapU ) );
8738 ret.at(strCounter)->_yRange = ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) * ( this->_yRange / static_cast<double> ( this->_maxMapV ) );
8739 ret.at(strCounter)->_zRange = ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) * ( this->_zRange / static_cast<double> ( this->_maxMapW ) );
8742 ret.at(strCounter)->_xFrom = XDim.at(boxIt)[0] + this->_xFrom;
8743 ret.at(strCounter)->_yFrom = YDim.at(boxIt)[0] + this->_yFrom;;
8744 ret.at(strCounter)->_zFrom = ZDim.at(boxIt)[0] + this->_zFrom;;
8746 ret.at(strCounter)->_xTo = XDim.at(boxIt)[1] + this->_xFrom;;
8747 ret.at(strCounter)->_yTo = YDim.at(boxIt)[1] + this->_yFrom;;
8748 ret.at(strCounter)->_zTo = ZDim.at(boxIt)[1] + this->_zFrom;;
8751 ret.at(strCounter)->_shellPlacement = std::vector<double> ( std::floor ( std::max ( ret.at(strCounter)->_xRange, std::max ( ret.at(strCounter)->_yRange, ret.at(strCounter)->_zRange ) ) / ret.at(strCounter)->_shellSpacing ) );
8753 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( ret.at(strCounter)->_shellPlacement.size() ); shellIter++ )
8755 ret.at(strCounter)->_shellPlacement.at(shellIter) = (shellIter+1) * ret.at(strCounter)->_shellSpacing;
8759 ret.at(strCounter)->_mapResolution= settings->
mapResolution;
8760 ret.at(strCounter)->_maxMapU = ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] );
8761 ret.at(strCounter)->_maxMapV = ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] );
8762 ret.at(strCounter)->_maxMapW = ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] );
8763 ret.at(strCounter)->_densityMapComputed =
true;
8765 hlpU = ( ret.at(strCounter)->_maxMapU + 1 );
8766 hlpV = ( ret.at(strCounter)->_maxMapV + 1 );
8767 hlpW = ( ret.at(strCounter)->_maxMapW + 1 );
8771 ret.at(strCounter)->_densityMapCor=
new double [(ret.at(strCounter)->_maxMapU+1) * (ret.at(strCounter)->_maxMapV+1) * (ret.at(strCounter)->_maxMapW + 1)];
8776 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
8778 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
8780 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
8782 arrayPos = z + (this->_maxMapW+1) * ( y + (this->_maxMapV+1) * x );
8783 coordPos = (z-ZDim.at(boxIt)[0]) + (ret.at(strCounter)->_maxMapW+1) * ( (y-YDim.at(boxIt)[0]) + (ret.at(strCounter)->_maxMapV+1) * (x-XDim.at(boxIt)[0]) );
8785 ret.at(strCounter)->_densityMapCor[coordPos] = this->_densityMapCor[arrayPos];
8787 if ( this->_densityMapCor[arrayPos] > 0.0 )
8789 mapVals.emplace_back ( this->_densityMapCor[arrayPos] );
8790 xCOM += ( x - XDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8791 yCOM += ( y - YDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8792 zCOM += ( z - ZDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8793 densTot += this->_densityMapCor[arrayPos];
8800 ret.at(strCounter)->_mapMean = std::accumulate ( mapVals.begin(), mapVals.end(), 0.0 ) / static_cast<double> ( mapVals.size() );
8801 ret.at(strCounter)->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( mapVals.begin(), mapVals.end(), mapVals.begin(), 0.0 ) ) /
8802 static_cast<double> ( mapVals.size() ) - ret.at(strCounter)->_mapMean * ret.at(strCounter)->_mapMean );
8806 std::array<double,3> meanVals;
8809 meanVals[0] = xCOM / densTot;
8810 meanVals[1] = yCOM / densTot;
8811 meanVals[2] = zCOM / densTot;
8815 meanVals[0] =
static_cast<double> ( hlpU ) / 2.0;
8816 meanVals[1] =
static_cast<double> ( hlpV ) / 2.0;
8817 meanVals[2] =
static_cast<double> ( hlpW ) / 2.0;
8821 ret.at(strCounter)->_xCorrErr = meanVals[0] -
static_cast<double> ( hlpU ) / 2.0;
8822 ret.at(strCounter)->_yCorrErr = meanVals[1] -
static_cast<double> ( hlpV ) / 2.0;
8823 ret.at(strCounter)->_zCorrErr = meanVals[2] -
static_cast<double> ( hlpW ) / 2.0;
8825 ret.at(strCounter)->_xCorrection = std::ceil ( ret.at(strCounter)->_xCorrErr );
8826 ret.at(strCounter)->_yCorrection = std::ceil ( ret.at(strCounter)->_yCorrErr );
8827 ret.at(strCounter)->_zCorrection = std::ceil ( ret.at(strCounter)->_zCorrErr );
8829 ret.at(strCounter)->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
8830 double *tmpIn =
new double [hlpU * hlpV * hlpW];
8831 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
8833 tmpIn[iter] = ret.at(strCounter)->_densityMapCor[iter];
8836 for (
int uIt = 0; uIt < hlpU; uIt++ )
8838 for (
int vIt = 0; vIt < hlpV; vIt++ )
8840 for (
int wIt = 0; wIt < hlpW; wIt++ )
8842 newU =
static_cast<int> ( uIt ) - static_cast<int> ( ret.at(strCounter)->_xCorrection );
8843 newV =
static_cast<int> ( vIt ) - static_cast<int> ( ret.at(strCounter)->_yCorrection );
8844 newW =
static_cast<int> ( wIt ) - static_cast<int> ( ret.at(strCounter)->_zCorrection );
8846 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
8847 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
8848 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
8850 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
8851 coordPos = newW + hlpW * ( newV + hlpV * newU );
8853 ret.at(strCounter)->_densityMapCor[coordPos] = tmpIn[arrayPos];
8856 ret.at(strCounter)->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) /2.0 ) * ( ret.at(strCounter)->_xRange /
static_cast<double> ( hlpU ) );
8857 ret.at(strCounter)->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) /2.0 ) * ( ret.at(strCounter)->_yRange /
static_cast<double> ( hlpV ) );;
8858 ret.at(strCounter)->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) /2.0 ) * ( ret.at(strCounter)->_zRange /
static_cast<double> ( hlpW ) );;
8865 ret.at(strCounter)->_fourierCoeffPower = this->_fourierCoeffPower;
8866 ret.at(strCounter)->_bFactorChange= this->_bFactorChange;
8867 ret.at(strCounter)->_maxMapRange = std::max ( ret.at(strCounter)->_xRange, std::max ( ret.at(strCounter)->_yRange, ret.at(strCounter)->_zRange ) );
8868 ret.at(strCounter)->_phaseRemoved = this->_phaseRemoved;
8869 ret.at(strCounter)->_keepOrRemove = this->_keepOrRemove;
8870 ret.at(strCounter)->_thetaAngle = this->_thetaAngle;
8871 ret.at(strCounter)->_phiAngle = this->_phiAngle;
8872 ret.at(strCounter)->_noShellsWithData = 0;
8873 ret.at(strCounter)->_sphereMapped =
false;
8874 ret.at(strCounter)->_firstLineCOM =
false;
8875 ret.at(strCounter)->_bandwidthLimit = this->_bandwidthLimit;
8876 ret.at(strCounter)->_oneDimmension= ret.at(strCounter)->_bandwidthLimit * 2;
8877 ret.at(strCounter)->_sphericalCoefficientsComputed =
false;
8878 ret.at(strCounter)->_rrpMatricesPrecomputed =
false;
8879 ret.at(strCounter)->_shellMappedData =
nullptr;
8880 ret.at(strCounter)->_realSHCoeffs =
nullptr;
8881 ret.at(strCounter)->_imagSHCoeffs =
nullptr;
8882 ret.at(strCounter)->_sphericalHarmonicsWeights=
nullptr;
8883 ret.at(strCounter)->_semiNaiveTable =
nullptr;
8884 ret.at(strCounter)->_semiNaiveTableSpace =
nullptr;
8885 ret.at(strCounter)->_shWorkspace =
nullptr;
8886 ret.at(strCounter)->_invRealData =
nullptr;
8887 ret.at(strCounter)->_invImagData =
nullptr;
8888 ret.at(strCounter)->_rrpMatrices =
nullptr;
8897 std::cout <<
">>>>>>>> Density check NOT passed." << std::endl;
8903 std::cout <<
">>>>>>>> Box " << boxIt <<
" processed." << std::endl;
This class deals with reading in the data and computing structure specific information including the ...
double mapResolution
This is the internal resolution at which the calculations are done, not necessarily the resolution of...
double noIQRsFromMap
This is the number of interquartile distances from mean that is used to threshold the map masking...
unsigned int theta
This parameter is the longitude of the spherical grid mapping. It should be 2 * bandwidth unless ther...
std::string clearMapFile
If map features are to be extracted, should the clear map be saved (then give file name here)...
void normaliseMap(ProSHADE::ProSHADE_settings *settings)
This function does normalises the map data.
void translateMap(double xShift, double yShift, double zShift)
This function translates the data along the three coordinate axis by the amount given by the three pa...
bool overlayDefaults
If true, the shell spacing and distances will be doube to their typical values. This is to speed up m...
double mapFragBoxFraction
Fraction of box that needs to have density in order to be passed on.
unsigned int bandwidth
This parameter determines the angular resolution of the spherical harmonics decomposition.
void keepPhaseInMap(double alpha, double bFac, unsigned int *bandwidth, unsigned int *theta, unsigned int *phi, unsigned int *glIntegOrder, ProSHADE::ProSHADE_settings *settings, bool useCom=true, double maxMapIQR=10.0, int verbose=0, bool clearMapData=true, bool rotDefaults=false, bool overlapDefaults=false, double blurFactor=500.0, bool maskBlurFactorGiven=false)
This function keeps the phase information from the density map and prepares the data for SH coefficie...
bool htmlReport
Should HTML report for the run be created?
int verbose
Should the software report on the progress, or just be quiet? Value between 0 (quiet) and 4 (loud) ...
The main header file containing all declarations the user of the library needs.
void getDensityMapFromMAPFeatures(std::string fileName, double *minDensPreNorm, double *maxDensPreNorm, double *minDensPostNorm, double *maxDensPostNorm, double *postNormMean, double *postNormSdev, double *maskVolume, double *totalVolume, double *maskMean, double *maskSdev, double *maskMin, double *maskMax, double *maskDensityRMS, double *allDensityRMS, std::array< double, 3 > *origRanges, std::array< double, 3 > *origDims, double maxMapIQR, double extraCS, int verbose, bool useCubicMaps, double maskBlurFactor, bool maskBlurFactorGiven, bool reboxAtAll, ProSHADE::ProSHADE_settings *settings)
This function reads in the CCP4' MAP formatted file and computes its features.
void fragmentMap(std::string axOrder, int verbose, ProSHADE::ProSHADE_settings *settings)
This function takes the clear map produced already and fragments it into overlapping boxes of given s...
std::vector< std::vector< int > > findMapIslands(int hlpU, int hlpV, int hlpW, double *map, double threshold=0.0)
This function takes a map and a threshold on it and proceeds to detect islands (continuous fragments ...
void matchMap(ProSHADE_data *matchTo)
This function is called on a map to re-size and re-sample it to match the second, parameter input map...
bool useCubicMaps
When saving clear maps, should the rectangular or cubic (older versions of refmac need this) maps be ...
std::vector< int > ignoreLs
This vector lists all the bandwidth values which should be ignored and not part of the computations...
void shiftMap(double xShift, double yShift, double zShift)
This function shifts (changing header) the data along the three coordinate axis by the amount given b...
void getDensityMapFromPDB(std::string fileName, double *shellDistance, double resolution, unsigned int *bandwidth, unsigned int *theta, unsigned int *phi, unsigned int *glIntegOrder, double *extraSpace, bool mapResDefault, ProSHADE::ProSHADE_settings *settings, double Bfactor=80.0, bool hpFirstLineCom=false, bool overlayDefaults=false)
Function to read in the PDB file and compute the theoretical density map.
double shellSpacing
This parameter determines how far the radial shells should be from each other.
std::array< double, 6 > getDensityMapFromMAPRebox(std::string fileName, double maxMapIQR, double extraCS, int verbose, bool useCubicMaps, double maskBlurFactor, bool maskBlurFactorGiven, ProSHADE::ProSHADE_settings *settings)
This function reads in the CCP4' MAP formatted file and re-boxes its contents using the masking proce...
bool mapResDefault
This variable states if default resolution should be used, or whether the user has supplied a differe...
This is the executive class responsible for comparing strictly two structures.
std::vector< ProSHADE_data * > fragmentMap(ProSHADE::ProSHADE_settings *settings, bool userCOM)
This function takes the map and fragments it into boxes of given size, returning vector of data objec...
void printInfo(int verbose)
This is the main information output for the ProSHADE_mapFeatures class.
bool rotChangeDefault
If map rotation is selected, the default automatic parameter decision is changed. This variable state...
void removePhaseFromMapOverlay(double alpha, double bFac, ProSHADE::ProSHADE_settings *settings)
This function removes the phase information from the density map for the overlay purposes.
unsigned int phi
This parameter is the latitudd of the spherical grid mapping. It should be 2 * bandwidth unless there...
unsigned int maxRotError
This is the maximum allowed error in degrees for the rotation computation. This can be used to speed ...
std::string axisOrder
A string specifying the order of the axis. Must have three characters and any permutation of 'x'...
The main header file containing all declarations for the innter workings of the library.
int htmlReportLine
Iterator for current HTML line.
int htmlReportLineProgress
Iterator for current HTML line in the progress bar.
void getDensityMapFromMAP(std::string fileName, double *shellDistance, double resolution, unsigned int *bandwidth, unsigned int *theta, unsigned int *phi, unsigned int *glIntegOrder, double *extraSpace, bool mapResDefault, bool rotDefaults, ProSHADE::ProSHADE_settings *settings, bool overlayDefaults=false)
Function to read in the MAP file and provide the basic processing.
void dealWithHalfMaps(ProSHADE::ProSHADE_settings *settings, double *xTranslate, double *yTranslate, double *zTranslate)
This function takes the clear map produced already and fragments it into overlapping boxes of given s...
double mapFragBoxSize
Should the clear map be fragmented into boxes? If so, put box size here, otherwise leave 0...
ProSHADE_data()
Contructor for the ProSHADE_data class.
std::array< double, 4 > getCOMandDist(ProSHADE::ProSHADE_settings *settings)
This function gets COM and its distance to closes border.
This class stores all the settings and is passed to the executive classes instead of multitude of par...
double mPower
This parameter determines the scaling for trace sigma descriptor.
bool removeIslands(int hlpU, int hlpV, int hlpW, int verbose=0, bool runAll=false)
This function does the island detection support and decides whether different masking should be appli...
void maskMap(int hlpU, int hlpV, int hlpW, double blurBy=250.0, double maxMapIQR=3.0, double extraMaskSpace=3.0)
This function does the map masking for cleaning and re-boxing maps.
double maskBlurFactor
The is the amount of blurring to be used to create masks for maps.
std::vector< std::string > structFiles
This vector should contain all the structures that are being dealt with, but this does not yet work! ...
void removePhaseFromMap(double alpha, double bFac, ProSHADE::ProSHADE_settings *settings)
This function removes the phase information from the density map.
std::array< double, 4 > getTranslationFunctionMap(ProSHADE_data *obj1, ProSHADE_data *obj2, double *ob2XMov=nullptr, double *ob2YMov=nullptr, double *ob2ZMov=nullptr)
Computes the translation function for the two objects and returns the position of the highest peak...
This file contains the ProSHADE_internal_misc namespace and its miscellaneous functions.
double extraSpace
What should be the distance added on both sides to the structure, so that the next cell density would...
unsigned int glIntegOrder
This parameter controls the Gauss-Legendre integration order and so the radial resolution.