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 this->_shellSpacing = *shellDistance;
95 this->_maxExtraCellularSpace = *extraSpace;
96 this->_firstLineCOM = hpFirstLineCom;
99 clipper::mmdb::CMMDBManager *mfile =
new clipper::mmdb::CMMDBManager ( );
100 if ( mfile->ReadCoorFile ( this->_inputFileName.c_str() ) )
102 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read file: " << this->_inputFileName.c_str() << std::endl;
106 std::stringstream hlpSS;
107 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file: " << this->_inputFileName.c_str() <<
"</font>";
108 rvapi_set_text ( hlpSS.str().c_str(),
128 bool firstAtom =
true;
130 double xVal, yVal, zVal;
137 clipper::mmdb::PPCChain chain;
138 clipper::mmdb::PPCResidue residue;
139 clipper::mmdb::PPCAtom atom;
141 double pdbXCom = 0.0;
142 double pdbYCom = 0.0;
143 double pdbZCom = 0.0;
144 double bFacTot = 0.0;
147 mfile->GetChainTable ( 1, chain, noChains );
149 for (
unsigned int nCh = 0; nCh < static_cast<unsigned int> ( noChains ); nCh++ )
154 chain[nCh]->GetResidueTable ( residue, noResidues );
156 for (
unsigned int nRes = 0; nRes < static_cast<unsigned int> ( noResidues ); nRes++ )
161 residue[nRes]->GetAtomTable ( atom, noAtoms );
163 for (
unsigned int aNo = 0; aNo < static_cast<unsigned int> ( noAtoms ); aNo++ )
168 if ( atom[aNo]->Ter ) {
continue; }
180 pdbXCom += atom[aNo]->x;
181 pdbYCom += atom[aNo]->y;
182 pdbZCom += atom[aNo]->z;
183 if ( Bfactor != 0.0 )
189 bFacTot += atom[aNo]->tempFactor;
200 if ( xVal > maxX ) { maxX = xVal; }
if ( xVal < minX ) { minX = xVal; }
201 if ( yVal > maxY ) { maxY = yVal; }
if ( yVal < minY ) { minY = yVal; }
202 if ( zVal > maxZ ) { maxZ = zVal; }
if ( zVal < minZ ) { minZ = zVal; }
204 if ( Bfactor != 0.0 )
207 pdbXCom += atom[aNo]->x;
208 pdbYCom += atom[aNo]->y;
209 pdbZCom += atom[aNo]->z;
213 bFacTot += atom[aNo]->tempFactor;
214 pdbXCom += atom[aNo]->x * atom[aNo]->tempFactor;
215 pdbYCom += atom[aNo]->y * atom[aNo]->tempFactor;
216 pdbZCom += atom[aNo]->z * atom[aNo]->tempFactor;
232 this->_xRange = (maxX - minX);
233 this->_yRange = (maxY - minY);
234 this->_zRange = (maxZ - minZ);
235 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
238 this->_maxExtraCellularSpace = *extraSpace;
239 double ecsHlp = std::floor ( std::max ( 20.0, ( this->_maxMapRange / 4.0 ) ) );
242 this->_xRange = (maxX - minX) + ecsHlp;
243 this->_yRange = (maxY - minY) + ecsHlp;
244 this->_zRange = (maxZ - minZ) + ecsHlp;
245 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
248 double xMov = (ecsHlp/2.0) - minX;
249 double yMov = (ecsHlp/2.0) - minY;
250 double zMov = (ecsHlp/2.0) - minZ;
253 mfile->GetChainTable ( 1, chain, noChains );
255 for (
unsigned int nCh = 0; nCh < static_cast<unsigned int> ( noChains ); nCh++ )
260 chain[nCh]->GetResidueTable ( residue, noResidues );
262 for (
unsigned int nRes = 0; nRes < static_cast<unsigned int> ( noResidues ); nRes++ )
267 residue[nRes]->GetAtomTable ( atom, noAtoms );
269 for (
unsigned int aNo = 0; aNo < static_cast<unsigned int> ( noAtoms ); aNo++ )
274 if ( atom[aNo]->Ter ) {
continue; }
276 if ( Bfactor != 0.0 )
278 atom[aNo]->SetCoordinates ( atom[aNo]->x + xMov,
281 atom[aNo]->occupancy,
286 atom[aNo]->SetCoordinates ( atom[aNo]->x + xMov,
289 atom[aNo]->occupancy,
290 atom[aNo]->tempFactor );
296 this->_xCorrErr = atom[aNo]->x;
297 this->_yCorrErr = atom[aNo]->y;
298 this->_zCorrErr = atom[aNo]->z;
308 clipper::Spacegroup spgr ( clipper::Spacegroup::P1 );
309 clipper::Cell cell ( clipper::Cell_descr ( this->_xRange, this->_yRange, this->_zRange ) );
310 clipper::Resolution reso;
314 reso = clipper::Resolution ( std::min ( std::max ( this->_mapResolution / 3.0, 2.0 ), this->_mapResolution ) );
318 reso = clipper::Resolution ( this->_mapResolution );
322 const clipper::Grid_sampling grid ( spgr, cell, reso );
323 clipper::Xmap<float> *densityMap =
new clipper::Xmap<float> ( spgr, cell, grid );
326 int hndl = mfile->NewSelection ( );
327 mfile->SelectAtoms ( hndl, 0, 0, ::mmdb::SKEY_NEW );
328 mfile->GetSelIndex ( hndl, atom, noAtoms );
329 clipper::MMDBAtom_list *aList =
new clipper::MMDBAtom_list ( atom, noAtoms );
330 clipper::EDcalc_aniso<clipper::ftype32> edCalc;
331 edCalc ( *densityMap, *aList );
337 clipper::Xmap_base::Map_reference_index LastPos = (*densityMap).first();
338 clipper::Xmap_base::Map_reference_index PrevPos = (*densityMap).first();
339 for ( LastPos = (*densityMap).first(); !LastPos.last(); LastPos.next() ) { PrevPos = LastPos; }
340 this->_maxMapU = PrevPos.coord().u();
341 this->_maxMapV = PrevPos.coord().v();
342 this->_maxMapW = PrevPos.coord().w();
344 this->_preCBSU = this->_maxMapU;
345 this->_preCBSV = this->_maxMapV;
346 this->_preCBSW = this->_maxMapW;
350 this->_densityMapMap = (
float*) malloc ( ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ) *
sizeof ( float ) );
351 if ( this->_densityMapMap ==
nullptr )
353 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
357 std::stringstream hlpSS;
358 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
359 rvapi_set_text ( hlpSS.str().c_str(),
374 for (
unsigned int uIt = 0; uIt < (this->_maxMapU+1); uIt++ )
376 for (
unsigned int vIt = 0; vIt < (this->_maxMapV+1); vIt++ )
378 for (
unsigned int wIt = 0; wIt < (this->_maxMapW+1); wIt++ )
380 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
382 clipper::Vec3<int> pos ( uIt, vIt, wIt );
383 clipper::Coord_grid cg ( pos );
385 this->_densityMapMap[arrPos] = densityMap->get_data ( cg );
391 if ( densityMap !=
nullptr )
394 densityMap =
nullptr;
402 this->_xTo = this->_maxMapU;
403 this->_yTo = this->_maxMapV;
404 this->_zTo = this->_maxMapW;
412 minX = this->_maxMapU;
413 minY = this->_maxMapV;
414 minZ = this->_maxMapW;
415 for (
unsigned int uIt = 0; uIt < (this->_maxMapU+1); uIt++ )
417 for (
unsigned int vIt = 0; vIt < (this->_maxMapV+1); vIt++ )
419 for (
unsigned int wIt = 0; wIt < (this->_maxMapW+1); wIt++ )
421 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
422 if ( this->_densityMapMap[arrPos] > 0.005 )
424 if ( maxX < uIt ) { maxX = uIt; }
if ( minX > uIt ) { minX = uIt; }
425 if ( maxY < vIt ) { maxY = vIt; }
if ( minY > vIt ) { minY = vIt; }
426 if ( maxZ < wIt ) { maxZ = wIt; }
if ( minZ > wIt ) { minZ = wIt; }
432 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
433 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
434 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
436 this->_xRange = this->_xRange - ( this->_maxMapU - ( maxX - minX ) ) * this->_xSamplingRate;
437 this->_yRange = this->_yRange - ( this->_maxMapV - ( maxY - minY ) ) * this->_ySamplingRate;
438 this->_zRange = this->_zRange - ( this->_maxMapW - ( maxZ - minZ ) ) * this->_zSamplingRate;
439 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
442 float *hlpMap =
nullptr;
443 hlpMap = (
float*) malloc ( static_cast<int>( (maxX - minX + 1) * (maxY - minY + 1) * (maxZ - minZ + 1) ) *
sizeof ( float ) );
444 if ( hlpMap ==
nullptr )
446 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
450 std::stringstream hlpSS;
451 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
452 rvapi_set_text ( hlpSS.str().c_str(),
465 unsigned int newU, newV, newW, hlpPos;
466 for (
int uIt = 0; uIt < static_cast<int> (maxX - minX + 1); uIt++ )
468 for (
int vIt = 0; vIt < static_cast<int> (maxY - minY + 1); vIt++ )
470 for (
int wIt = 0; wIt < static_cast<int> (maxZ - minZ + 1); wIt++ )
476 hlpPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
477 arrPos = wIt + (maxZ - minZ + 1) * ( vIt + (maxY - minY + 1) * uIt );
479 hlpMap[arrPos] = this->_densityMapMap[hlpPos];
484 this->_maxMapU = maxX - minX;
485 this->_maxMapV = maxY - minY;
486 this->_maxMapW = maxZ - minZ;
488 this->_xTo = maxX - minX;
489 this->_yTo = maxY - minY;
490 this->_zTo = maxZ - minZ;
493 if ( this->_densityMapMap !=
nullptr )
495 free ( this->_densityMapMap );
496 this->_densityMapMap =
nullptr;
499 this->_densityMapMap = (
float*) malloc ( ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ) *
sizeof ( float ) );
500 if ( this->_densityMapMap ==
nullptr )
502 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
506 std::stringstream hlpSS;
507 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
508 rvapi_set_text ( hlpSS.str().c_str(),
521 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
523 this->_densityMapMap[iter] = hlpMap[iter];
526 if ( hlpMap !=
nullptr )
532 if ( this->_maxExtraCellularSpace == -777.7 )
534 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 ) ) ) );
535 *extraSpace = this->_maxExtraCellularSpace;
538 if ( this->_maxExtraCellularSpace != 0.0 )
541 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
542 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
543 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
545 this->_xRange += xDiff * this->_xSamplingRate;
546 this->_yRange += yDiff * this->_ySamplingRate;
547 this->_zRange += zDiff * this->_zSamplingRate;
549 if ( xDiff % 2 != 0 )
551 this->_xRange += this->_xSamplingRate;
552 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
554 if ( yDiff % 2 != 0 )
556 this->_yRange += this->_ySamplingRate;
557 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
559 if ( zDiff % 2 != 0 )
561 this->_zRange += this->_zSamplingRate;
562 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
564 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
570 this->_exCeSpDiffX = xDiff;
571 this->_exCeSpDiffY = yDiff;
572 this->_exCeSpDiffZ = zDiff;
574 this->_xFrom -= xDiff;
575 this->_yFrom -= yDiff;
576 this->_zFrom -= zDiff;
582 this->_maxMapU = this->_xTo - this->_xFrom;
583 this->_maxMapV = this->_yTo - this->_yFrom;
584 this->_maxMapW = this->_zTo - this->_zFrom;
586 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
587 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
588 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
592 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
593 if ( hlpMap ==
nullptr )
595 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
599 std::stringstream hlpSS;
600 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for moving the map data. Did you run out of memory?" <<
"</font>";
601 rvapi_set_text ( hlpSS.str().c_str(),
613 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
618 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
620 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
622 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
624 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
625 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
626 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
628 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
629 hlpMap[hlpPos] = 0.0;
633 newU = (uIt - xDiff);
634 newV = (vIt - yDiff);
635 newW = (wIt - zDiff);
637 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
638 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
640 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
647 if ( this->_densityMapMap !=
nullptr )
649 free ( this->_densityMapMap );
650 this->_densityMapMap =
nullptr;
654 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
655 if ( this->_densityMapMap ==
nullptr )
657 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
661 std::stringstream hlpSS;
662 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
663 rvapi_set_text ( hlpSS.str().c_str(),
675 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
677 this->_densityMapMap[iter] = hlpMap[iter];
681 if ( hlpMap !=
nullptr )
689 this->_exCeSpDiffX = 0;
690 this->_exCeSpDiffY = 0;
691 this->_exCeSpDiffZ = 0;
695 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
696 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
697 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
700 double mapXCom = 0.0;
701 double mapYCom = 0.0;
702 double mapZCom = 0.0;
703 double densTot = 0.0;
704 for (
unsigned int uIt = 0; uIt < static_cast<unsigned int> ( (this->_maxMapU+1) ); uIt++ )
706 for (
unsigned int vIt = 0; vIt < static_cast<unsigned int> ( (this->_maxMapV+1) ); vIt++ )
708 for (
unsigned int wIt = 0; wIt < static_cast<unsigned int> ( (this->_maxMapW+1) ); wIt++ )
710 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
712 mapXCom += uIt * this->_densityMapMap[arrPos];
713 mapYCom += vIt * this->_densityMapMap[arrPos];
714 mapZCom += wIt * this->_densityMapMap[arrPos];
715 densTot += this->_densityMapMap[arrPos];
724 mapXCom = ( mapXCom + this->_xFrom ) * this->_xSamplingRate;
725 mapYCom = ( mapYCom + this->_yFrom ) * this->_ySamplingRate;
726 mapZCom = ( mapZCom + this->_zFrom ) * this->_zSamplingRate;
728 double mapXMove = ( pdbXCom - mapXCom ) / this->_xSamplingRate;
729 double mapYMove = ( pdbYCom - mapYCom ) / this->_ySamplingRate;
730 double mapZMove = ( pdbZCom - mapZCom ) / this->_zSamplingRate;
732 this->_xFrom += std::round ( mapXMove );
733 this->_xTo += std::round ( mapXMove );
734 this->_yFrom += std::round ( mapYMove );
735 this->_yTo += std::round ( mapYMove );
736 this->_zFrom += std::round ( mapZMove );
737 this->_zTo += std::round ( mapZMove );
740 bool xFSignChange =
false;
741 if ( ( ( ( this->_xFrom - std::round ( mapXMove ) ) < 0 ) && ( this->_xFrom > 0 ) ) ||
742 ( ( ( this->_xFrom - std::round ( mapXMove ) ) > 0 ) && ( this->_xFrom < 0 ) ) ) { xFSignChange =
true; }
743 bool xTSignChange =
false;
744 if ( ( ( ( this->_xTo - std::round ( mapXMove ) ) < 0 ) && ( this->_xTo > 0 ) ) ||
745 ( ( ( this->_xTo - std::round ( mapXMove ) ) > 0 ) && ( this->_xTo < 0 ) ) ) { xTSignChange =
true; }
747 bool yFSignChange =
false;
748 if ( ( ( ( this->_yFrom - std::round ( mapYMove ) ) < 0 ) && ( this->_yFrom > 0 ) ) ||
749 ( ( ( this->_yFrom - std::round ( mapYMove ) ) > 0 ) && ( this->_yFrom < 0 ) ) ) { yFSignChange =
true; }
750 bool yTSignChange =
false;
751 if ( ( ( ( this->_yTo - std::round ( mapYMove ) ) < 0 ) && ( this->_yTo > 0 ) ) ||
752 ( ( ( this->_yTo - std::round ( mapYMove ) ) > 0 ) && ( this->_yTo < 0 ) ) ) { yTSignChange =
true; }
754 bool zFSignChange =
false;
755 if ( ( ( ( this->_zFrom - std::round ( mapZMove ) ) < 0 ) && ( this->_zFrom > 0 ) ) ||
756 ( ( ( this->_zFrom - std::round ( mapZMove ) ) > 0 ) && ( this->_zFrom < 0 ) ) ) { zFSignChange =
true; }
757 bool zTSignChange =
false;
758 if ( ( ( ( this->_zTo - std::round ( mapZMove ) ) < 0 ) && ( this->_zTo > 0 ) ) ||
759 ( ( ( this->_zTo - std::round ( mapZMove ) ) > 0 ) && ( this->_zTo < 0 ) ) ) { zTSignChange =
true; }
761 if ( ( xFSignChange && !xTSignChange ) || ( !xFSignChange && xTSignChange ) )
765 if ( ( yFSignChange && !yTSignChange ) || ( !yFSignChange && yTSignChange ) )
769 if ( ( zFSignChange && !zTSignChange ) || ( !zFSignChange && zTSignChange ) )
775 if ( *bandwidth == 0 )
777 *bandwidth = std::ceil ( this->_maxMapRange / 4.0 );
782 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
783 this->_wasBandwithGiven =
true;
787 if ( *shellDistance == 0 )
789 settings->
shellSpacing =
static_cast<double> ( this->_maxMapRange / 2.0 ) / std::floor ( static_cast<double> ( this->_maxMapRange / 2.0 ) /
static_cast<double> ( this->_mapResolution / 2.0 ) );
791 *shellDistance = this->_shellSpacing;
793 while ( std::floor ( this->_maxMapRange / this->_shellSpacing ) < 20 )
795 this->_shellSpacing /= 2.0;
797 *shellDistance /= 2.0;
803 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
805 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
807 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
811 if ( *theta == 0 ) { *theta = 2 * (*bandwidth); }
812 if ( *phi == 0 ) { *phi = 2 * (*bandwidth); }
815 if ( *glIntegOrder == 0 )
817 double distPerPointFraction =
static_cast<double> ( this->_shellSpacing ) / ( this->_maxMapRange / 2.0 );
819 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
821 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
823 *glIntegOrder = iter;
829 this->_densityMapComputed =
true;
830 this->_fromPDB =
true;
854 double *shellDistance,
856 unsigned int *bandwidth,
859 unsigned int *glIntegOrder,
864 bool overlayDefaults )
867 this->_inputFileName = fileName;
868 this->_shellSpacing = *shellDistance;
869 this->_mapResolution = resolution;
870 this->_maxExtraCellularSpace = *extraSpace;
871 this->_firstLineCOM =
false;
873 if ( *extraSpace == -777.7 )
875 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 ) ) ) );
876 *extraSpace = this->_maxExtraCellularSpace;
880 CMap_io::CMMFile *mapFile =
nullptr;
881 float *cell =
nullptr;
884 int *order =
nullptr;
887 double cornerAvg = 0.0;
888 double centralAvg = 0.0;
889 double cornerCount = 0.0;
890 double centralCount = 0.0;
893 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
894 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
895 grid = (
int* ) malloc ( 3 *
sizeof (
int ) );
896 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
897 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
899 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) || ( grid ==
nullptr ) )
901 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
905 std::stringstream hlpSS;
906 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
907 rvapi_set_text ( hlpSS.str().c_str(),
921 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
922 if ( mapFile ==
nullptr )
924 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and corruption of the file. Terminating..." << std::endl;
928 std::stringstream hlpSS;
929 hlpSS <<
"<font color=\"red\">" <<
"Cannot open the file " << fileName <<
" . Could it be corrupted?" <<
"</font>";
930 rvapi_set_text ( hlpSS.str().c_str(),
943 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
944 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
945 CMap_io::ccp4_cmap_get_grid ( mapFile, grid );
946 CMap_io::ccp4_cmap_get_order ( mapFile, order );
947 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
950 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
951 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
952 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
955 this->_xRange = cell[0];
956 this->_yRange = cell[1];
957 this->_zRange = cell[2];
960 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
963 this->_maxExtraCellularSpace = *extraSpace;
966 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
967 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
968 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
970 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
971 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
972 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
974 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
975 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
976 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
979 this->_preCBSU = this->_maxMapU;
980 this->_preCBSV = this->_maxMapV;
981 this->_preCBSW = this->_maxMapW;
984 this->_xTo = this->_xFrom + this->_maxMapU;
985 this->_yTo = this->_yFrom + this->_maxMapV;
986 this->_zTo = this->_zFrom + this->_maxMapW;
989 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
990 if ( this->_densityMapMap ==
nullptr )
992 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
996 std::stringstream hlpSS;
997 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
998 rvapi_set_text ( hlpSS.str().c_str(),
1012 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
1013 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
1015 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
1019 std::stringstream hlpSS;
1020 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>";
1021 rvapi_set_text ( hlpSS.str().c_str(),
1038 int newU, newV, newW;
1041 for (
int iter = 0; iter < 3; iter++ )
1043 maxLim[iter] = orig[iter] + dim[iter] - 1;
1044 XYZOrder[order[iter]-1] = iter;
1048 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
1049 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
1050 std::vector<float> section( midDimSize );
1055 for ( iters[2] = orig[2]; iters[2] <= maxLim[2]; iters[2]++ )
1058 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
1062 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
1064 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
1068 for ( iters[1] = orig[1]; iters[1] <= maxLim[1]; iters[1]++ )
1070 for ( iters[0] = orig[0]; iters[0] <= maxLim[0]; iters[0]++ )
1072 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
1073 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
1074 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
1075 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
1076 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
1082 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1083 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
1085 vals.at(iter) = this->_densityMapMap[iter];
1087 std::sort ( vals.begin(), vals.end() );
1090 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
1091 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 );
1094 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
1095 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
1096 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
1098 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1100 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1102 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1105 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1108 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
1109 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
1110 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
1112 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
1113 centralCount += 1.0;
1115 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
1116 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1117 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
1118 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1119 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
1120 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
1121 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
1122 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
1124 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
1131 cornerAvg /= cornerCount;
1132 centralAvg /= centralCount;
1135 if ( cornerAvg > centralAvg )
1138 float* hlpMap =
nullptr;
1139 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
1140 if ( hlpMap ==
nullptr )
1142 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
1146 std::stringstream hlpSS;
1147 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1148 rvapi_set_text ( hlpSS.str().c_str(),
1160 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
1162 hlpMap[iter] = this->_densityMapMap[iter];
1166 unsigned int hlpPos;
1167 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1169 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1171 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1174 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
1175 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
1176 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
1178 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
1179 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1182 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
1193 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
1197 std::stringstream hlpSS;
1198 hlpSS <<
"<font color=\"red\">" <<
"Non-orthogonal map detected. Only P1 maps are currently supported." <<
"</font>";
1199 rvapi_set_text ( hlpSS.str().c_str(),
1213 if ( cell !=
nullptr )
1218 if ( dim !=
nullptr )
1223 if ( order !=
nullptr )
1228 if ( orig !=
nullptr )
1235 CMap_io::ccp4_cmap_close ( mapFile );
1238 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
1239 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
1240 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
1241 double maxSamplingRate = std::max ( this->_xSamplingRate, std::max( this->_ySamplingRate, this->_zSamplingRate ) );
1244 this->_maxExtraCellularSpace = *extraSpace;
1245 if ( *extraSpace != 0.0 )
1248 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
1249 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
1250 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
1252 this->_xRange += xDiff * this->_xSamplingRate;
1253 this->_yRange += yDiff * this->_ySamplingRate;
1254 this->_zRange += zDiff * this->_zSamplingRate;
1256 if ( xDiff % 2 != 0 )
1258 this->_xRange += this->_xSamplingRate;
1259 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
1261 if ( yDiff % 2 != 0 )
1263 this->_yRange += this->_ySamplingRate;
1264 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
1266 if ( zDiff % 2 != 0 )
1268 this->_zRange += this->_zSamplingRate;
1269 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
1276 this->_exCeSpDiffX = xDiff;
1277 this->_exCeSpDiffY = yDiff;
1278 this->_exCeSpDiffZ = zDiff;
1280 this->_xFrom -= xDiff;
1281 this->_yFrom -= yDiff;
1282 this->_zFrom -= zDiff;
1284 this->_xTo += xDiff;
1285 this->_yTo += yDiff;
1286 this->_zTo += zDiff;
1288 this->_maxMapU = this->_xTo - this->_xFrom;
1289 this->_maxMapV = this->_yTo - this->_yFrom;
1290 this->_maxMapW = this->_zTo - this->_zFrom;
1292 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
1293 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
1294 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
1297 float *hlpMap =
nullptr;
1298 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
1299 if ( hlpMap ==
nullptr )
1301 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
1305 std::stringstream hlpSS;
1306 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1307 rvapi_set_text ( hlpSS.str().c_str(),
1319 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1324 unsigned int newU, newV, newW, hlpPos, arrPos;
1325 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
1327 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
1329 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
1331 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
1332 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
1333 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
1335 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1336 hlpMap[hlpPos] = 0.0;
1340 newU = (uIt - xDiff);
1341 newV = (vIt - yDiff);
1342 newW = (wIt - zDiff);
1344 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1345 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
1347 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
1354 if ( this->_densityMapMap !=
nullptr )
1356 free ( this->_densityMapMap );
1357 this->_densityMapMap =
nullptr;
1361 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
1362 if ( this->_densityMapMap ==
nullptr )
1364 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
1368 std::stringstream hlpSS;
1369 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Did you run out of memory?" <<
"</font>";
1370 rvapi_set_text ( hlpSS.str().c_str(),
1382 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1384 this->_densityMapMap[iter] = hlpMap[iter];
1388 if ( hlpMap !=
nullptr )
1396 this->_exCeSpDiffX = 0;
1397 this->_exCeSpDiffY = 0;
1398 this->_exCeSpDiffZ = 0;
1402 if ( ( this->_mapResolution / 2.0 ) > maxSamplingRate )
1404 maxSamplingRate = ( this->_mapResolution / 2.0 );
1408 std::cerr <<
"!!! ProSHADE WARNING !!! The map sampling does not support the required resolution. This means that your map will be over-sampled and the computation will take longer than needed. Use higher resolution value to resolve." << std::endl;
1412 if ( *bandwidth == 0 )
1414 *bandwidth = std::ceil ( this->_maxMapRange / 4.0 );
1419 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
1420 this->_wasBandwithGiven =
true;
1424 if ( *shellDistance == 0 )
1426 settings->
shellSpacing =
static_cast<double> ( this->_maxMapRange / 2.0 ) / std::floor ( static_cast<double> ( this->_maxMapRange / 2.0 ) /
static_cast<double> ( this->_mapResolution / 2.0 ) );
1428 *shellDistance = this->_shellSpacing;
1430 while ( std::floor ( this->_maxMapRange / this->_shellSpacing ) < 20 )
1432 this->_shellSpacing /= 2.0;
1434 *shellDistance /= 2.0;
1439 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
1441 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
1443 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
1447 if ( *theta == 0 ) { *theta = 2 * (*bandwidth); }
1448 if ( *phi == 0 ) { *phi = 2 * (*bandwidth); }
1451 if ( *glIntegOrder == 0 )
1453 double distPerPointFraction =
static_cast<double> ( this->_shellSpacing ) / ( this->_maxMapRange / 2.0 );
1455 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
1457 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
1459 *glIntegOrder = iter;
1465 this->_densityMapComputed =
true;
1466 this->_fromPDB =
false;
1479 if ( this->_densityMapMap ==
nullptr )
1481 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;
1485 std::stringstream hlpSS;
1486 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>";
1487 rvapi_set_text ( hlpSS.str().c_str(),
1501 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1502 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1504 vals.at(iter) = this->_densityMapMap[iter];
1506 std::sort ( vals.begin(), vals.end() );
1509 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
1510 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 );
1513 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
1515 this->_densityMapMap[iter] = this->_densityMapMap[iter] / this->_mapSdev;
1531 if ( this->_densityMapMap ==
nullptr )
1533 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;
1537 std::stringstream hlpSS;
1538 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>";
1539 rvapi_set_text ( hlpSS.str().c_str(),
1553 unsigned int arrPos = 0;
1554 double totDens = 0.0;
1555 std::array<double,4> meanVals;
1560 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
1562 for (
unsigned int uIt = 0; uIt < static_cast<unsigned int> ( (this->_maxMapU+1) ); uIt++ )
1564 for (
unsigned int vIt = 0; vIt < static_cast<unsigned int> ( (this->_maxMapV+1) ); vIt++ )
1566 for (
unsigned int wIt = 0; wIt < static_cast<unsigned int> ( (this->_maxMapW+1) ); wIt++ )
1568 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
1570 if ( this->_densityMapMap[arrPos] > 0.0 )
1572 meanVals[0] += this->_densityMapMap[arrPos] * uIt;
1573 meanVals[1] += this->_densityMapMap[arrPos] * vIt;
1574 meanVals[2] += this->_densityMapMap[arrPos] * wIt;
1576 totDens += this->_densityMapMap[arrPos];
1582 meanVals[0] /= totDens;
1583 meanVals[1] /= totDens;
1584 meanVals[2] /= totDens;
1591 if ( meanVals[0] <= static_cast<double> ((this->_maxMapU+1)/2) )
1593 distX = meanVals[0] * this->_xSamplingRate;
1597 distX = (
static_cast<double> ( this->_maxMapU+1 ) - meanVals[0] ) * this->_xSamplingRate;
1600 if ( meanVals[1] <= static_cast<double> ((this->_maxMapV+1)/2) )
1602 distY = meanVals[1] * this->_ySamplingRate;
1606 distY = (
static_cast<double> ( this->_maxMapV+1 ) - meanVals[1] ) * this->_ySamplingRate;
1609 if ( meanVals[2] <= static_cast<double> ((this->_maxMapW+1)/2) )
1611 distZ = meanVals[2] * this->_zSamplingRate;
1615 distZ = (
static_cast<double> ( this->_maxMapW+1 ) - meanVals[2] ) * this->_zSamplingRate;
1619 meanVals[3] = sqrt ( pow( distX, 2.0 ) + pow ( distY, 2.0 ) + pow ( distZ, 2.0 ) );
1622 return ( meanVals );
1643 double extraMaskSpace )
1646 fftw_complex* tmpIn;
1647 fftw_complex* tmpOut;
1648 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
1649 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
1650 fftw_complex* maskData =
new fftw_complex [ hlpU * hlpV * hlpW ];
1651 fftw_complex* maskDataInv =
new fftw_complex [ hlpU * hlpV * hlpW ];
1656 double mag, phase, S;
1657 double normFactor = (hlpU * hlpV * hlpW);
1658 double bFacChange = blurBy;
1661 unsigned int hlpIt = 0;
1666 for ( uIt = 0; uIt < hlpU; uIt++ )
1668 for ( vIt = 0; vIt < hlpV; vIt++ )
1670 for ( wIt = 0; wIt < hlpW; wIt++ )
1673 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1675 if ( this->_densityMapCor[arrayPos] == this->_densityMapCor[arrayPos] )
1677 tmpIn[arrayPos][0] = ( this->_densityMapCor[arrayPos] - this->_mapMean ) / this->_mapSdev;
1678 tmpIn[arrayPos][1] = 0.0;
1682 tmpIn[arrayPos][0] = 0.0;
1683 tmpIn[arrayPos][1] = 0.0;
1690 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
1694 fftw_plan pMaskInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInv, maskData, FFTW_BACKWARD, FFTW_ESTIMATE );
1696 for ( uIt = 0; uIt < hlpU; uIt++ )
1698 for ( vIt = 0; vIt < hlpV; vIt++ )
1700 for ( wIt = 0; wIt < hlpW; wIt++ )
1703 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1704 real = tmpOut[arrayPos][0];
1705 imag = tmpOut[arrayPos][1];
1708 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
1709 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
1710 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
1713 S = ( pow( static_cast<double> ( h ) / this->_xRange, 2.0 ) +
1714 pow( static_cast<double> ( k ) / this->_yRange, 2.0 ) +
1715 pow( static_cast<double> ( l ) / this->_zRange, 2.0 ) );
1716 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
1717 phase = atan2 ( imag, real );
1720 maskDataInv[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
1721 maskDataInv[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
1727 fftw_execute ( pMaskInv );
1730 std::vector<double> maskVals ( hlpU * hlpV * hlpW );
1732 for ( uIt = 0; uIt < hlpU; uIt++ )
1734 for ( vIt = 0; vIt < hlpV; vIt++ )
1736 for ( wIt = 0; wIt < hlpW; wIt++ )
1739 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1740 maskVals.at(hlpIt) = maskData[arrayPos][0];
1747 double medianPos =
static_cast<unsigned int> ( maskVals.size() / 2 );
1748 std::sort ( maskVals.begin(), maskVals.end() );
1750 double interQuartileRange = maskVals.at(medianPos+(medianPos/2)) - maskVals.at(medianPos-(medianPos/2));
1751 double mapThresholdPlus = maskVals.at(medianPos+(medianPos/2)) + ( interQuartileRange * maxMapIQR );
1755 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) ) ) ) ) );
1756 int arrPosSearch = 0;
1757 int newU, newV, newW;
1758 bool breakOut =
false;
1760 for ( uIt = 0; uIt < hlpU; uIt++ )
1762 for ( vIt = 0; vIt < hlpV; vIt++ )
1764 for ( wIt = 0; wIt < hlpW; wIt++ )
1767 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1770 if ( maskData[arrayPos][0] > mapThresholdPlus )
1772 tmpIn[arrayPos][0] = 1.0;
1777 tmpIn[arrayPos][0] = 0.0;
1779 for (
int uCh = -addPoints; uCh <= addPoints; uCh++ )
1781 if ( breakOut ) {
break; }
1782 for (
int vCh = -addPoints; vCh <= addPoints; vCh++ )
1784 if ( breakOut ) {
break; }
1785 for (
int wCh = -addPoints; wCh <= addPoints; wCh++ )
1787 if ( breakOut ) {
break; }
1788 if ( ( uCh == 0 ) && ( vCh == 0 ) && wCh == 0 ) {
continue; }
1794 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= hlpU ) { newU -= hlpU; }
1795 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= hlpV ) { newV -= hlpV; }
1796 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= hlpW ) { newW -= hlpW; }
1798 arrPosSearch = newW + hlpW * ( newV + hlpV * newU );
1800 if ( maskData[arrPosSearch][0] > mapThresholdPlus )
1802 tmpIn[arrayPos][0] = 1.0;
1813 for ( uIt = 0; uIt < hlpU; uIt++ )
1815 for ( vIt = 0; vIt < hlpV; vIt++ )
1817 for ( wIt = 0; wIt < hlpW; wIt++ )
1820 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
1823 if ( tmpIn[arrayPos][0] == 0.0 )
1825 this->_densityMapCor[arrayPos] = 0.0;
1834 delete[] maskDataInv;
1835 maskDataInv =
nullptr;
1842 fftw_destroy_plan ( p );
1843 fftw_destroy_plan ( pMaskInv );
1871 std::vector< std::vector<int> > clusters = this->
findMapIslands ( hlpU, hlpV, hlpW, this->_densityMapCor );
1872 if ( clusters.size() == 0 )
1879 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1881 maxVolume = std::max ( maxVolume, static_cast<int> ( clusters.at(iter).size() ) );
1889 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1891 totVol += clusters.at(iter).size();
1892 if ( static_cast<double> ( clusters.at(iter).size() ) > ( 0.8 * maxVolume ) )
1894 volTop80 += clusters.at(iter).size();
1896 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.1 * maxVolume ) )
1900 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.2 * maxVolume ) )
1902 volLow20 += clusters.at(iter).size();
1907 if ( ( fracLess10 != 0 ) || ( clusters.size() > 5 ) )
1909 if ( ( ( static_cast<double> ( fracLess10 ) / static_cast<double> ( clusters.size() ) ) > 0.5 ) ||
1910 ( ( static_cast<double> ( volTop80 ) /
static_cast<double> ( totVol ) ) < 0.9 ) ||
1911 ( ( static_cast<double> ( volLow20 ) /
static_cast<double> ( totVol ) ) > 0.1 ) )
1923 std::cout <<
">>>>>>>> Cluster check started." << std::endl;
1927 double *tmpIn =
new double[hlpU * hlpV * hlpW];
1928 std::vector<int> removedClusters;
1930 for (
unsigned int i = 0; i < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); i++ )
1932 tmpIn[i] = this->_densityMapCor[i];
1933 this->_densityMapCor[i] = 0.0;
1936 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clusters.size() ); iter++ )
1938 if ( static_cast<double> ( clusters.at(iter).size() ) < ( 0.3 * static_cast<double> ( maxVolume ) ) )
1944 removedClusters.emplace_back ( iter );
1945 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clusters.at(iter).size() ); it++ )
1947 this->_densityMapCor[clusters.at(iter).at(it)] = tmpIn[clusters.at(iter).at(it)];
1953 int noPoints = std::ceil ( 3.0 / std::max ( this->_xRange / hlpU, std::max ( this->_yRange / hlpV, this->_zRange / hlpW ) ) );
1956 bool addPoint =
false;
1958 int hlpUIt, hlpVIt, hlpWIt;
1960 for (
unsigned int rIt = 0; rIt < static_cast<unsigned int> ( removedClusters.size() ); rIt++ )
1962 for (
int rPt = 0; rPt < static_cast<int> ( clusters.at(removedClusters.at(rIt)).size() ); rPt++ )
1965 uIt = ( clusters.at(removedClusters.at(rIt)).at(rPt) / ( hlpW * hlpV ) ) % hlpW;
1966 vIt =
static_cast<int> ( std::floor ( clusters.at(removedClusters.at(rIt)).at(rPt) / hlpW ) ) % hlpV;
1967 wIt = clusters.at(removedClusters.at(rIt)).at(rPt) - ( uIt * hlpW * hlpV ) - ( vIt * hlpW );
1970 for (
int newX = uIt-noPoints; newX <= uIt+noPoints; newX++ )
1972 if ( addPoint ) {
break; }
1973 for (
int newY = vIt-noPoints; newY <= vIt+noPoints; newY++ )
1975 if ( addPoint ) {
break; }
1976 for (
int newZ = wIt-noPoints; newZ <= wIt+noPoints; newZ++ )
1978 if ( ( newX == uIt ) && ( newY == vIt ) && ( newZ == wIt ) ) {
continue; }
1984 if ( hlpUIt < 0 ) { hlpUIt += hlpU; }
if ( hlpUIt >= hlpU ) { hlpUIt -= hlpU; }
1985 if ( hlpVIt < 0 ) { hlpVIt += hlpV; }
if ( hlpVIt >= hlpV ) { hlpVIt -= hlpV; }
1986 if ( hlpWIt < 0 ) { hlpWIt += hlpW; }
if ( hlpWIt >= hlpW ) { hlpWIt -= hlpW; }
1988 arrPos2 = hlpWIt + hlpW * ( hlpVIt + hlpV * hlpUIt );
1989 if ( this->_densityMapCor[arrPos2] > 0.0 ) { addPoint =
true;
break; }
1996 arrPos = wIt + hlpW * ( vIt + hlpV * uIt );
1997 this->_densityMapCor[arrPos] = -999.999;
2002 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
2004 if ( this->_densityMapCor[iter] == -999.999 )
2006 this->_densityMapCor[iter] = tmpIn[iter];
2034 this->_xFrom += xShift;
2035 this->_xTo += xShift;
2036 this->_yFrom += yShift;
2037 this->_yTo += yShift;
2038 this->_zFrom += zShift;
2039 this->_zTo += zShift;
2061 int hlpU = this->_maxMapU + 1;
2062 int hlpV = this->_maxMapV + 1;
2063 int hlpW = this->_maxMapW + 1;
2069 double exponent = 0.0;
2070 double trCoeffReal = 0.0;
2071 double trCoeffImag = 0.0;
2072 double normFactor =
static_cast<double> ( hlpU * hlpV * hlpW );
2073 fftw_complex *translatedMap =
new fftw_complex [hlpU * hlpV * hlpW];
2074 fftw_complex *fCoeffs =
new fftw_complex [hlpU * hlpV * hlpW];
2075 std::array<double,2> hlpArr;
2076 fftw_plan planForwardFourier;
2077 fftw_plan planBackwardFourier;
2081 planForwardFourier = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, translatedMap, fCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
2082 planBackwardFourier = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, fCoeffs, translatedMap, FFTW_BACKWARD, FFTW_ESTIMATE );
2085 if ( this->_densityMapCor ==
nullptr )
2087 for (
int uIt = 0; uIt < hlpU; uIt++ )
2089 for (
int vIt = 0; vIt < hlpV; vIt++ )
2091 for (
int wIt = 0; wIt < hlpW; wIt++ )
2093 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2095 translatedMap[arrayPos][0] = this->_densityMapMap[arrayPos];
2096 translatedMap[arrayPos][1] = 0.0;
2103 for (
int uIt = 0; uIt < hlpU; uIt++ )
2105 for (
int vIt = 0; vIt < hlpV; vIt++ )
2107 for (
int wIt = 0; wIt < hlpW; wIt++ )
2109 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2111 translatedMap[arrayPos][0] = this->_densityMapCor[arrayPos];
2112 translatedMap[arrayPos][1] = 0.0;
2119 fftw_execute ( planForwardFourier );
2121 for (
int uIt = 0; uIt < hlpU; uIt++ )
2123 for (
int vIt = 0; vIt < hlpV; vIt++ )
2125 for (
int wIt = 0; wIt < hlpW; wIt++ )
2128 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2129 real = fCoeffs[arrayPos][0];
2130 imag = fCoeffs[arrayPos][1];
2133 if ( uIt > ((hlpU+1) / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
2134 if ( vIt > ((hlpV+1) / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
2135 if ( wIt > ((hlpW+1) / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
2138 exponent = ( ( ( static_cast <
double> ( h ) / this->_xRange ) * xShift ) +
2139 ( ( static_cast <double> ( k ) / this->_yRange ) * yShift ) +
2140 ( ( static_cast <
double> ( l ) / this->_zRange ) * zShift ) ) * 2.0 * M_PI;
2142 trCoeffReal = cos ( exponent );
2143 trCoeffImag = sin ( exponent );
2145 hlpArr = ProSHADE_internal_misc::complexMultiplication ( &real, &imag, &trCoeffReal, &trCoeffImag );
2148 fCoeffs[arrayPos][0] = hlpArr[0] / normFactor;
2149 fCoeffs[arrayPos][1] = hlpArr[1] / normFactor;
2155 fftw_execute ( planBackwardFourier );
2158 if ( this->_densityMapCor ==
nullptr )
2160 for (
int uIt = 0; uIt < hlpU; uIt++ )
2162 for (
int vIt = 0; vIt < hlpV; vIt++ )
2164 for (
int wIt = 0; wIt < hlpW; wIt++ )
2166 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2167 this->_densityMapMap[arrayPos] =
static_cast<float> ( translatedMap[arrayPos][0] );
2174 for (
int uIt = 0; uIt < hlpU; uIt++ )
2176 for (
int vIt = 0; vIt < hlpV; vIt++ )
2178 for (
int wIt = 0; wIt < hlpW; wIt++ )
2180 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
2181 this->_densityMapCor[arrayPos] = translatedMap[arrayPos][0];
2188 fftw_destroy_plan ( planForwardFourier );
2189 fftw_destroy_plan ( planBackwardFourier );
2190 delete[] translatedMap;
2216 double maskBlurFactor,
2217 bool maskBlurFactorGiven,
2221 this->_inputFileName = fileName;
2222 this->_maxExtraCellularSpace = extraCS;
2225 CMap_io::CMMFile *mapFile =
nullptr;
2226 float *cell =
nullptr;
2228 int *order =
nullptr;
2229 int *orig =
nullptr;
2231 double cornerAvg = 0.0;
2232 double centralAvg = 0.0;
2233 double cornerCount = 0.0;
2234 double centralCount = 0.0;
2237 std::array<double,6> ret;
2240 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
2241 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
2242 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
2243 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
2245 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) )
2247 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
2251 std::stringstream hlpSS;
2252 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2253 rvapi_set_text ( hlpSS.str().c_str(),
2267 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
2268 if ( mapFile ==
nullptr )
2270 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and curruption of the file. Terminating..." << std::endl;
2274 std::stringstream hlpSS;
2275 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file " << fileName <<
".</font>";
2276 rvapi_set_text ( hlpSS.str().c_str(),
2289 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
2290 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
2291 CMap_io::ccp4_cmap_get_order ( mapFile, order );
2292 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
2297 std::cout <<
">> Map loaded." << std::endl;
2301 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
2302 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
2303 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
2306 this->_xRange = cell[0];
2307 this->_yRange = cell[1];
2308 this->_zRange = cell[2];
2311 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
2314 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
2315 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
2316 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
2318 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
2319 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
2320 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
2322 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
2323 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
2324 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
2327 this->_xTo = this->_xFrom + this->_maxMapU;
2328 this->_yTo = this->_yFrom + this->_maxMapV;
2329 this->_zTo = this->_zFrom + this->_maxMapW;
2332 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
2333 if ( this->_densityMapMap ==
nullptr )
2335 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
2339 std::stringstream hlpSS;
2340 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2341 rvapi_set_text ( hlpSS.str().c_str(),
2355 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
2356 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
2358 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
2362 std::stringstream hlpSS;
2363 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>";
2364 rvapi_set_text ( hlpSS.str().c_str(),
2379 int newU, newV, newW;
2382 for (
int iter = 0; iter < 3; iter++ )
2384 maxLim[iter] = orig[iter] + dim[iter] - 1;
2385 XYZOrder[order[iter]-1] = iter;
2389 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
2390 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
2391 std::vector<float> section( midDimSize );
2396 for ( iters[2] = orig[XYZOrder[2]]; iters[2] <= maxLim[XYZOrder[2]]; iters[2]++ )
2399 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
2403 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
2405 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
2409 for ( iters[1] = orig[XYZOrder[1]]; iters[1] <= maxLim[XYZOrder[1]]; iters[1]++ )
2411 for ( iters[0] = orig[XYZOrder[0]]; iters[0] <= maxLim[XYZOrder[0]]; iters[0]++ )
2413 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
2414 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
2415 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
2416 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
2417 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
2423 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
2424 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
2426 vals.at(iter) = this->_densityMapMap[iter];
2428 std::sort ( vals.begin(), vals.end() );
2431 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
2432 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 );
2436 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
2437 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
2438 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
2440 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
2442 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
2444 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
2447 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
2450 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
2451 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
2452 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
2454 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
2455 centralCount += 1.0;
2457 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
2458 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2459 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
2460 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2461 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
2462 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
2463 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
2464 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
2466 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
2473 cornerAvg /= cornerCount;
2474 centralAvg /= centralCount;
2477 if ( cornerAvg > centralAvg )
2480 float* hlpMap =
nullptr;
2481 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
2482 if ( hlpMap ==
nullptr )
2484 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
2488 std::stringstream hlpSS;
2489 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
2490 rvapi_set_text ( hlpSS.str().c_str(),
2502 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
2504 hlpMap[iter] = this->_densityMapMap[iter];
2508 unsigned int hlpPos;
2509 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
2511 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
2513 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
2516 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
2517 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
2518 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
2520 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
2521 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
2524 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
2535 std::cout <<
">>>>> Density moved from corners to center, if applicable." << std::endl;
2540 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
2544 std::stringstream hlpSS;
2545 hlpSS <<
"<font color=\"red\">" <<
"Detected non-orthogonal map. Currently, only the P1 maps are supported." <<
"</font>";
2546 rvapi_set_text ( hlpSS.str().c_str(),
2561 std::stringstream hlpSS;
2562 hlpSS <<
"<font color=\"green\">" <<
"Structure " << settings->
structFiles.at(0) <<
" read in." <<
"</font>";
2563 rvapi_set_text ( hlpSS.str().c_str(),
2575 rvapi_add_section (
"OrigHeaderSection",
2576 "Original structure header",
2586 std::stringstream hlpSS;
2587 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
2588 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2594 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length(),
2595 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length(),
2596 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ) );
2597 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length(),
2598 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length(),
2599 ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ) );
2600 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length(),
2601 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length(),
2602 ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ) );
2603 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length(),
2604 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length(),
2605 ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ) );
2606 int CAMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( cell[3], prec ).length(),
2607 std::max ( ProSHADE_internal_misc::to_string_with_precision ( cell[4], prec ).length(),
2608 ProSHADE_internal_misc::to_string_with_precision ( cell[5], prec ).length() ) );
2609 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, std::max ( CDMAX, CAMAX ) ) ) );
2610 if ( spacer < 5 ) { spacer = 5; }
2612 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( this->_maxMapU+1 );
2613 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++ )
2619 hlpSS << std::showpos << static_cast<int> ( this->_maxMapV+1 );
2620 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++ )
2626 hlpSS << std::showpos << static_cast<int> ( this->_maxMapW+1 );
2627 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++ )
2633 rvapi_set_text ( hlpSS.str().c_str(),
2634 "OrigHeaderSection",
2641 hlpSS.str ( std::string ( ) );
2642 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
2643 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2648 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xFrom;
2649 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length() ); iter++ )
2655 hlpSS << std::showpos << this->_xTo;
2656 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length() ); iter++ )
2662 hlpSS << std::showpos << this->_yFrom;
2663 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length() ); iter++ )
2669 hlpSS << std::showpos << this->_yTo;
2670 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length() ); iter++ )
2676 hlpSS << std::showpos <<
" " << this->_zFrom;
2677 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ); iter++ )
2683 hlpSS << std::showpos << this->_zTo;
2684 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ); iter++ )
2690 rvapi_set_text ( hlpSS.str().c_str(),
2691 "OrigHeaderSection",
2698 hlpSS.str ( std::string ( ) );
2699 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
2700 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2705 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xRange;
2706 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length() ); iter++ )
2712 hlpSS << std::showpos << this->_yRange;
2713 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length() ); iter++ )
2719 hlpSS << std::showpos << this->_zRange;
2720 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ); iter++ )
2726 rvapi_set_text ( hlpSS.str().c_str(),
2727 "OrigHeaderSection",
2734 hlpSS.str ( std::string ( ) );
2735 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
2736 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2741 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << cell[3];
2742 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[3], prec ).length() ); iter++ )
2748 hlpSS << std::showpos << cell[4];
2749 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[4], prec ).length() ); iter++ )
2755 hlpSS << std::showpos << cell[5];
2756 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( cell[5], prec ).length() ); iter++ )
2762 rvapi_set_text ( hlpSS.str().c_str(),
2763 "OrigHeaderSection",
2770 hlpSS.str ( std::string ( ) );
2771 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
2772 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
2777 if ( XYZOrder[0] == 0 ) { hlpSS <<
" X"; }
2778 else if ( XYZOrder[0] == 1 ) { hlpSS <<
" Y"; }
2779 else { hlpSS <<
" Z"; }
2780 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
2786 if ( XYZOrder[1] == 0 ) { hlpSS <<
"X"; }
2787 else if ( XYZOrder[1] == 1 ) { hlpSS <<
"Y"; }
2788 else { hlpSS <<
"Z"; }
2789 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
2795 if ( XYZOrder[2] == 0 ) { hlpSS <<
"X"; }
2796 else if ( XYZOrder[2] == 1 ) { hlpSS <<
"Y"; }
2797 else { hlpSS <<
"Z"; }
2798 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
2804 rvapi_set_text ( hlpSS.str().c_str(),
2805 "OrigHeaderSection",
2815 ret[0] = this->_maxMapU + 1;
2816 ret[1] = this->_maxMapV + 1;
2817 ret[2] = this->_maxMapW + 1;
2820 if ( cell !=
nullptr )
2825 if ( dim !=
nullptr )
2830 if ( order !=
nullptr )
2835 if ( orig !=
nullptr )
2842 CMap_io::ccp4_cmap_close ( mapFile );
2845 int hlpU = ( this->_maxMapU + 1 );
2846 int hlpV = ( this->_maxMapV + 1 );
2847 int hlpW = ( this->_maxMapW + 1 );
2850 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
2853 std::vector<double> vals ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) );
2855 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
2857 if ( this->_densityMapMap[iter] == this->_densityMapMap[iter] )
2860 this->_densityMapCor[iter] = this->_densityMapMap[iter];
2865 this->_densityMapCor[iter] = 0.0;
2870 std::cout <<
">>>>> Map normalised." << std::endl;
2874 double *tmpMp =
new double[hlpU * hlpV * hlpW];
2875 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
2877 tmpMp[iter] = this->_densityMapCor[iter];
2880 bool notTooManyIslads =
true;
2881 double blFr = 150.0;
2883 while ( notTooManyIslads )
2887 if ( maskBlurFactorGiven )
2889 blFr = maskBlurFactor;
2890 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
2895 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
2900 std::cout <<
">>>>>>>> Island detection started." << std::endl;
2903 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
2907 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
2909 if ( notTooManyIslads )
2913 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
2916 if ( blFr <= 500.0 )
2918 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
2920 this->_densityMapCor[iter] = tmpMp[iter];
2928 std::cout << std::endl;
2935 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;
2939 std::stringstream hlpSS;
2940 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>";
2941 rvapi_set_text ( hlpSS.str().c_str(),
2956 if ( !maskBlurFactorGiven )
2958 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
2960 this->_densityMapCor[iter] = tmpMp[iter];
2963 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
2968 std::cout <<
">> Map masked." << std::endl;
2973 std::stringstream hlpSS;
2974 hlpSS <<
"<font color=\"green\">" <<
"Map masked." <<
"</font>";
2975 rvapi_set_text ( hlpSS.str().c_str(),
2993 int maxXTot = hlpU/2;
2994 int minXTot = hlpU/2;
2995 int maxYTot = hlpV/2;
2996 int minYTot = hlpV/2;
2997 int maxZTot = hlpW/2;
2998 int minZTot = hlpW/2;
3000 for (
int uIt = 0; uIt < hlpU; uIt++ )
3002 for (
int vIt = 0; vIt < hlpV; vIt++ )
3004 for (
int wIt = 0; wIt < hlpW; wIt++ )
3006 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
3008 if ( this->_densityMapCor[coordPos] > 0.0 )
3010 maxX = std::max ( maxX, uIt );
3011 minX = std::min ( minX, uIt );
3012 maxY = std::max ( maxY, vIt );
3013 minY = std::min ( minY, vIt );
3014 maxZ = std::max ( maxZ, wIt );
3015 minZ = std::min ( minZ, wIt );
3017 maxXTot = std::max ( maxXTot, uIt );
3018 minXTot = std::min ( minXTot, uIt );
3019 maxYTot = std::max ( maxYTot, vIt );
3020 minYTot = std::min ( minYTot, vIt );
3021 maxZTot = std::max ( maxZTot, wIt );
3022 minZTot = std::min ( minZTot, wIt );
3028 int newUStart =
static_cast<int> ( this->_xFrom + ( minXTot + minX ) );
3029 int newUEnd =
static_cast<int> ( this->_xTo - ( maxXTot - maxX ) );
3030 int newVStart =
static_cast<int> ( this->_yFrom + ( minYTot + minY ) );
3031 int newVEnd =
static_cast<int> ( this->_yTo - ( maxYTot - maxY ) );
3032 int newWStart =
static_cast<int> ( this->_zFrom + ( minZTot + minZ ) );
3033 int newWEnd =
static_cast<int> ( this->_zTo - ( maxZTot - maxZ ) );
3036 if ( this->_maxExtraCellularSpace > 0.0 )
3038 int extraPTs =
static_cast<int> ( std::ceil ( this->_maxExtraCellularSpace / ( static_cast<double> ( this->_maxMapRange ) / static_cast<double> ( std::max ( hlpU, std::max ( hlpV, hlpW ) ) ) ) ) );
3040 if ( (newUStart - extraPTs) >
static_cast<int> ( this->_xFrom ) ) { newUStart -=
static_cast<int> ( extraPTs ); }
3041 if ( (newVStart - extraPTs) >
static_cast<int> ( this->_yFrom ) ) { newVStart -=
static_cast<int> ( extraPTs ); }
3042 if ( (newWStart - extraPTs) >
static_cast<int> ( this->_zFrom ) ) { newWStart -=
static_cast<int> ( extraPTs ); }
3043 if ( (newUEnd + extraPTs) <
static_cast<int> ( this->_xTo ) ) { newUEnd +=
static_cast<int> ( extraPTs ); }
3044 if ( (newVEnd + extraPTs) <
static_cast<int> ( this->_yTo ) ) { newVEnd +=
static_cast<int> ( extraPTs ); }
3045 if ( (newWEnd + extraPTs) <
static_cast<int> ( this->_zTo ) ) { newWEnd +=
static_cast<int> ( extraPTs ); }
3049 if ( this->_densityMapCor !=
nullptr )
3051 delete[] this->_densityMapCor;
3052 this->_densityMapCor =
nullptr;
3056 int newXDim = newUEnd - newUStart + 1;
3057 int newYDim = newVEnd - newVStart + 1;
3058 int newZDim = newWEnd - newWStart + 1;
3060 if ( ( this->_xFrom < 0 ) && ( ( this->_xFrom + newUStart ) >= 0 ) ) { newXDim += 1; }
3061 if ( ( this->_yFrom < 0 ) && ( ( this->_yFrom + newVStart ) >= 0 ) ) { newYDim += 1; }
3062 if ( ( this->_zFrom < 0 ) && ( ( this->_zFrom + newWStart ) >= 0 ) ) { newZDim += 1; }
3064 this->_densityMapCor =
new double [newXDim * newYDim * newZDim];
3067 int newU, newV, newW;
3068 for (
int uIt = newUStart; uIt <= newUEnd; uIt++ )
3070 for (
int vIt = newVStart; vIt <= newVEnd; vIt++ )
3072 for (
int wIt = newWStart; wIt <= newWEnd; wIt++ )
3074 newU = uIt - newUStart;
3075 newV = vIt - newVStart;
3076 newW = wIt - newWStart;
3077 hlpPos = newW + newZDim * ( newV + newYDim * newU );
3079 newU = uIt - this->_xFrom;
3080 newV = vIt - this->_yFrom;
3081 newW = wIt - this->_zFrom;
3082 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
3084 this->_densityMapCor[hlpPos] = tmpMp[arrPos];
3091 std::cout <<
"Map re-boxed." << std::endl;
3096 std::stringstream hlpSS;
3097 hlpSS <<
"<font color=\"green\">" <<
"Map re-boxed." <<
"</font>";
3098 rvapi_set_text ( hlpSS.str().c_str(),
3112 this->_xFrom = newUStart;
3113 this->_yFrom = newVStart;
3114 this->_zFrom = newWStart;
3116 this->_xTo = newUEnd;
3117 this->_yTo = newVEnd;
3118 this->_zTo = newWEnd;
3120 this->_xSamplingRate =
static_cast<double> ( this->_xRange ) / static_cast<double> ( hlpU );
3121 this->_ySamplingRate =
static_cast<double> ( this->_yRange ) / static_cast<double> ( hlpV );
3122 this->_zSamplingRate =
static_cast<double> ( this->_zRange ) / static_cast<double> ( hlpW );
3124 this->_xRange = this->_xSamplingRate * ( newXDim );
3125 this->_yRange = this->_ySamplingRate * ( newYDim );
3126 this->_zRange = this->_zSamplingRate * ( newZDim );
3128 this->_maxMapU = newXDim - 1;
3129 this->_maxMapV = newYDim - 1;
3130 this->_maxMapW = newZDim - 1;
3132 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
3133 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
3134 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
3137 if ( this->_densityMapMap !=
nullptr )
3139 delete this->_densityMapMap;
3140 this->_densityMapMap =
nullptr;
3146 rvapi_add_section (
"NewHeaderSection",
3147 "Re-boxed structure header",
3157 std::stringstream hlpSS;
3158 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
3159 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3165 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapU+1 ), prec ).length(),
3166 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapV+1 ), prec ).length(),
3167 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( this->_maxMapW+1 ), prec ).length() ) );
3168 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length(),
3169 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length(),
3170 ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ) );
3171 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length(),
3172 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length(),
3173 ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ) );
3174 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length(),
3175 std::max ( ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length(),
3176 ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ) );
3177 int CAMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length(),
3178 std::max ( ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length(),
3179 ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ) );
3180 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, std::max ( CDMAX, CAMAX ) ) ) );
3181 if ( spacer < 5 ) { spacer = 5; }
3183 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( this->_maxMapU+1 );
3184 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++ )
3190 hlpSS << std::showpos << static_cast<int> ( this->_maxMapV+1 );
3191 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++ )
3197 hlpSS << std::showpos << static_cast<int> ( this->_maxMapW+1 );
3198 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++ )
3204 rvapi_set_text ( hlpSS.str().c_str(),
3212 hlpSS.str ( std::string ( ) );
3213 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
3214 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3219 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xFrom;
3220 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xFrom, prec ).length() ); iter++ )
3226 hlpSS << std::showpos << this->_xTo;
3227 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xTo, prec ).length() ); iter++ )
3233 hlpSS << std::showpos << this->_yFrom;
3234 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yFrom, prec ).length() ); iter++ )
3240 hlpSS << std::showpos << this->_yTo;
3241 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yTo, prec ).length() ); iter++ )
3247 hlpSS << std::showpos <<
" " << this->_zFrom;
3248 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zFrom, prec ).length() ); iter++ )
3254 hlpSS << std::showpos << this->_zTo;
3255 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zTo, prec ).length() ); iter++ )
3261 rvapi_set_text ( hlpSS.str().c_str(),
3269 hlpSS.str ( std::string ( ) );
3270 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
3271 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3276 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << this->_xRange;
3277 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_xRange, prec ).length() ); iter++ )
3283 hlpSS << std::showpos << this->_yRange;
3284 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_yRange, prec ).length() ); iter++ )
3290 hlpSS << std::showpos << this->_zRange;
3291 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( this->_zRange, prec ).length() ); iter++ )
3297 rvapi_set_text ( hlpSS.str().c_str(),
3305 hlpSS.str ( std::string ( ) );
3306 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
3307 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3312 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.000;
3313 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3319 hlpSS << std::showpos << 90.000;
3320 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3326 hlpSS << std::showpos << 90.000;
3327 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.000, prec ).length() ); iter++ )
3333 rvapi_set_text ( hlpSS.str().c_str(),
3341 hlpSS.str ( std::string ( ) );
3342 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
3343 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
3348 if ( XYZOrder[0] == 0 ) { hlpSS <<
" X"; }
3349 else if ( XYZOrder[0] == 1 ) { hlpSS <<
" Y"; }
3350 else { hlpSS <<
" Z"; }
3351 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3357 if ( XYZOrder[1] == 0 ) { hlpSS <<
"X"; }
3358 else if ( XYZOrder[1] == 1 ) { hlpSS <<
"Y"; }
3359 else { hlpSS <<
"Z"; }
3360 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3366 if ( XYZOrder[2] == 0 ) { hlpSS <<
"X"; }
3367 else if ( XYZOrder[2] == 1 ) { hlpSS <<
"Y"; }
3368 else { hlpSS <<
"Z"; }
3369 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
3375 rvapi_set_text ( hlpSS.str().c_str(),
3386 ret[3] = this->_maxMapU + 1;
3387 ret[4] = this->_maxMapV + 1;
3388 ret[5] = this->_maxMapW + 1;
3429 double *minDensPreNorm,
3430 double *maxDensPreNorm,
3431 double *minDensPostNorm,
3432 double *maxDensPostNorm,
3433 double *postNormMean,
3434 double *postNormSdev,
3436 double* totalVolume,
3441 double *maskDensityRMS,
3442 double *allDensityRMS,
3443 std::array<double,3> *origRanges,
3444 std::array<double,3> *origDims,
3449 double maskBlurFactor,
3450 bool maskBlurFactorGiven,
3455 this->_inputFileName = fileName;
3458 CMap_io::CMMFile *mapFile =
nullptr;
3459 float *cell =
nullptr;
3461 int *order =
nullptr;
3462 int *orig =
nullptr;
3464 double cornerAvg = 0.0;
3465 double centralAvg = 0.0;
3466 double cornerCount = 0.0;
3467 double centralCount = 0.0;
3470 cell = (
float*) malloc ( 6 *
sizeof (
float ) );
3471 dim = (
int* ) malloc ( 3 *
sizeof (
int ) );
3472 order = (
int* ) malloc ( 3 *
sizeof (
int ) );
3473 orig = (
int* ) malloc ( 3 *
sizeof (
int ) );
3475 if ( ( cell ==
nullptr ) || ( dim == nullptr ) || ( order ==
nullptr ) || ( orig == nullptr ) )
3477 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory. Terminating... " << std::endl;
3481 std::stringstream hlpSS;
3482 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3483 rvapi_set_text ( hlpSS.str().c_str(),
3497 mapFile =
reinterpret_cast<CMap_io::CMMFile*
> ( CMap_io::ccp4_cmap_open ( fileName.c_str() , myMapMode ) );
3498 if ( mapFile ==
nullptr )
3500 std::cerr <<
"!!! ProSHADE ERROR !!! Failed to open the file " << fileName <<
". Check for typos and curruption of the file. Terminating..." << std::endl;
3504 std::stringstream hlpSS;
3505 hlpSS <<
"<font color=\"red\">" <<
"Cannot open file " << fileName <<
".</font>";
3506 rvapi_set_text ( hlpSS.str().c_str(),
3519 CMap_io::ccp4_cmap_get_cell ( mapFile, cell );
3520 CMap_io::ccp4_cmap_get_dim ( mapFile, dim );
3521 CMap_io::ccp4_cmap_get_order ( mapFile, order );
3522 CMap_io::ccp4_cmap_get_origin ( mapFile, orig );
3527 std::cout <<
">> Map loaded." << std::endl;
3531 if ( ( ( cell[3] < (90.0 + 0.1) ) && ( cell[3] > (90.0 - 0.1) ) ) &&
3532 ( ( cell[4] < (90.0 + 0.1) ) && ( cell[4] > (90.0 - 0.1) ) ) &&
3533 ( ( cell[5] < (90.0 + 0.1) ) && ( cell[5] > (90.0 - 0.1) ) ) )
3536 this->_xRange = cell[0];
3537 this->_yRange = cell[1];
3538 this->_zRange = cell[2];
3541 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
3544 if ( order[0] == 1 ) { this->_maxMapU = dim[0] - 1; this->_xFrom = orig[0]; }
3545 if ( order[0] == 2 ) { this->_maxMapU = dim[1] - 1; this->_yFrom = orig[0]; }
3546 if ( order[0] == 3 ) { this->_maxMapU = dim[2] - 1; this->_zFrom = orig[0]; }
3548 if ( order[1] == 1 ) { this->_maxMapV = dim[0] - 1; this->_xFrom = orig[1]; }
3549 if ( order[1] == 2 ) { this->_maxMapV = dim[1] - 1; this->_yFrom = orig[1]; }
3550 if ( order[1] == 3 ) { this->_maxMapV = dim[2] - 1; this->_zFrom = orig[1]; }
3552 if ( order[2] == 1 ) { this->_maxMapW = dim[0] - 1; this->_xFrom = orig[2]; }
3553 if ( order[2] == 2 ) { this->_maxMapW = dim[1] - 1; this->_yFrom = orig[2]; }
3554 if ( order[2] == 3 ) { this->_maxMapW = dim[2] - 1; this->_zFrom = orig[2]; }
3557 this->_xTo = this->_xFrom + this->_maxMapU;
3558 this->_yTo = this->_yFrom + this->_maxMapV;
3559 this->_zTo = this->_zFrom + this->_maxMapW;
3562 this->_densityMapMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
3563 if ( this->_densityMapMap ==
nullptr )
3565 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
3569 std::stringstream hlpSS;
3570 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3571 rvapi_set_text ( hlpSS.str().c_str(),
3585 int mapMode = CMap_io::ccp4_cmap_get_datamode ( mapFile );
3586 if ( ( mapMode != 0 ) && ( mapMode != 2 ) )
3588 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read from the map file. The map file mode is not supported. Terminating..." << std::endl;
3592 std::stringstream hlpSS;
3593 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>";
3594 rvapi_set_text ( hlpSS.str().c_str(),
3611 int newU, newV, newW;
3614 for (
int iter = 0; iter < 3; iter++ )
3616 maxLim[iter] = orig[iter] + dim[iter] - 1;
3617 XYZOrder[order[iter]-1] = iter;
3621 int fastDimSize = ( maxLim[0] - orig[0] + 1 );
3622 int midDimSize = ( maxLim[1] - orig[1] + 1 ) * fastDimSize;
3623 std::vector<float> section( midDimSize );
3628 for ( iters[2] = orig[2]; iters[2] <= maxLim[2]; iters[2]++ )
3631 CMap_io::ccp4_cmap_read_section( mapFile, §ion[0] );
3635 for (
int iter = ( midDimSize - 1 ); iter >= 0; iter-- )
3637 section[iter] =
static_cast<float> ( (
reinterpret_cast<unsigned char*
> (§ion[0]) )[iter] );
3641 for ( iters[1] = orig[1]; iters[1] <= maxLim[1]; iters[1]++ )
3643 for ( iters[0] = orig[0]; iters[0] <= maxLim[0]; iters[0]++ )
3645 newU = iters[XYZOrder[0]] - orig[XYZOrder[0]];
3646 newV = iters[XYZOrder[1]] - orig[XYZOrder[1]];
3647 newW = iters[XYZOrder[2]] - orig[XYZOrder[2]];
3648 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
3649 this->_densityMapMap[arrPos] =
static_cast<float> ( section[ index++ ] );
3655 std::vector<double> vals;
3656 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
3658 if ( this->_densityMapMap[iter] != 0.0 )
3660 vals.emplace_back ( this->_densityMapMap[iter] );
3663 std::sort ( vals.begin(), vals.end() );
3665 *minDensPreNorm = vals.at(0);
3666 *maxDensPreNorm = vals.at(vals.size()-1);
3672 rvapi_add_section (
"ResultsSection",
3682 std::stringstream hlpSS;
3683 hlpSS <<
"<pre>" <<
"Min / Max density pre normalisation: ";
3684 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
3685 for (
int iter = 0; iter < hlpIt; iter++ )
3690 std::stringstream hlpSS2;
3691 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *minDensPreNorm * 1000.0 ) / 1000.0;
3692 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
3693 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
3694 hlpSS <<
" " << hlpSS2.str() <<
" / ";
3696 hlpSS2.str( std::string ( ) );
3697 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maxDensPreNorm * 1000.0 ) / 1000.0;
3698 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
3699 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
3700 hlpSS << hlpSS2.str() <<
"</pre>";
3702 rvapi_set_text ( hlpSS.str().c_str(),
3713 this->_mapMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
3714 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 );
3718 int noPToCheckU =
static_cast<unsigned int> ( this->_maxMapU / 8.0 );
3719 int noPToCheckV =
static_cast<unsigned int> ( this->_maxMapV / 8.0 );
3720 int noPToCheckW =
static_cast<unsigned int> ( this->_maxMapW / 8.0 );
3722 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
3724 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
3726 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
3729 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
3732 if ( ( ( uIt <= static_cast<int> ( this->_maxMapU/2 + noPToCheckU ) ) && ( uIt >= static_cast<int> ( this->_maxMapU/2 - noPToCheckU ) ) ) &&
3733 ( ( vIt <= static_cast<int> ( this->_maxMapV/2 + noPToCheckV ) ) && ( vIt >=
static_cast<int> ( this->_maxMapV/2 - noPToCheckV ) ) ) &&
3734 ( ( wIt <= static_cast<int> ( this->_maxMapW/2 + noPToCheckW ) ) && ( wIt >= static_cast<int> ( this->_maxMapW/2 - noPToCheckW ) ) ) )
3736 centralAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
3737 centralCount += 1.0;
3739 if ( ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
3740 ( ( uIt < noPToCheckU ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
3741 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
3742 ( ( uIt < noPToCheckU ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
3743 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt < noPToCheckW ) ) ||
3744 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt < noPToCheckV ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) ||
3745 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt < noPToCheckW ) ) ||
3746 ( ( uIt > static_cast<int> (this->_maxMapU-noPToCheckU) ) && ( vIt > static_cast<int> (this->_maxMapV-noPToCheckV) ) && ( wIt > static_cast<int> (this->_maxMapW-noPToCheckW) ) ) )
3748 cornerAvg += std::max ( this->_densityMapMap[arrPos], static_cast<float>(0.0) );
3755 cornerAvg /= cornerCount;
3756 centralAvg /= centralCount;
3759 if ( cornerAvg > centralAvg )
3762 float* hlpMap =
nullptr;
3763 hlpMap = (
float*) malloc ( (dim[0]*dim[1]*dim[2]) *
sizeof ( float ) );
3764 if ( hlpMap ==
nullptr )
3766 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
3770 std::stringstream hlpSS;
3771 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3772 rvapi_set_text ( hlpSS.str().c_str(),
3784 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( dim[0] * dim[1] * dim[2] ); iter++ )
3786 hlpMap[iter] = this->_densityMapMap[iter];
3790 unsigned int hlpPos;
3791 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
3793 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
3795 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
3798 if ( uIt < static_cast<int> (this->_maxMapU+1)/2 ) { newU = uIt + (this->_maxMapU+1)/2; }
else { newU = uIt - (this->_maxMapU+1)/2; }
3799 if ( vIt < static_cast<int> (this->_maxMapV+1)/2 ) { newV = vIt + (this->_maxMapV+1)/2; }
else { newV = vIt - (this->_maxMapV+1)/2; }
3800 if ( wIt < static_cast<int> (this->_maxMapW+1)/2 ) { newW = wIt + (this->_maxMapW+1)/2; }
else { newW = wIt - (this->_maxMapW+1)/2; }
3802 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
3803 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
3806 this->_densityMapMap[arrPos] = hlpMap[hlpPos];
3817 std::cout <<
">>>>> Density moved from corners to center, if applicable." << std::endl;
3822 std::cerr <<
"!!! ProSHADE ERROR !!! Non-orthogonal maps are not yet supported." << std::endl;
3826 std::stringstream hlpSS;
3827 hlpSS <<
"<font color=\"red\">" <<
"Detected non-orthogonal map. Currently, only the P1 maps are supported." <<
"</font>";
3828 rvapi_set_text ( hlpSS.str().c_str(),
3843 std::stringstream hlpSS;
3844 hlpSS <<
"<font color=\"green\">" <<
"Structure " << fileName <<
" read." <<
"</font>";
3845 rvapi_set_text ( hlpSS.str().c_str(),
3856 if ( cell !=
nullptr )
3861 if ( dim !=
nullptr )
3866 if ( order !=
nullptr )
3871 if ( orig !=
nullptr )
3878 CMap_io::ccp4_cmap_close ( mapFile );
3881 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
3882 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
3883 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
3885 bool addXOne =
false;
3886 bool addYOne =
false;
3887 bool addZOne =
false;
3890 (*origRanges)[0] = this->_xRange;
3891 (*origRanges)[1] = this->_yRange;
3892 (*origRanges)[2] = this->_zRange;
3894 (*origDims)[0] = this->_maxMapU;
3895 (*origDims)[1] = this->_maxMapV;
3896 (*origDims)[2] = this->_maxMapW;
3899 this->_maxExtraCellularSpace = extraCS;
3900 if ( this->_maxExtraCellularSpace != 0.0 )
3903 int xDiff =
static_cast<int> ( std::ceil ( ( this->_xRange + this->_maxExtraCellularSpace ) / this->_xSamplingRate ) - this->_maxMapU );
3904 int yDiff =
static_cast<int> ( std::ceil ( ( this->_yRange + this->_maxExtraCellularSpace ) / this->_ySamplingRate ) - this->_maxMapV );
3905 int zDiff =
static_cast<int> ( std::ceil ( ( this->_zRange + this->_maxExtraCellularSpace ) / this->_zSamplingRate ) - this->_maxMapW );
3907 if ( ( this->_xFrom >= 0 ) && ( ( this->_xFrom - xDiff ) < 0 ) ) { addXOne =
true; }
3908 if ( ( this->_yFrom >= 0 ) && ( ( this->_yFrom - yDiff ) < 0 ) ) { addYOne =
true; }
3909 if ( ( this->_zFrom >= 0 ) && ( ( this->_zFrom - zDiff ) < 0 ) ) { addZOne =
true; }
3911 this->_xRange += xDiff * this->_xSamplingRate;
3912 this->_yRange += yDiff * this->_ySamplingRate;
3913 this->_zRange += zDiff * this->_zSamplingRate;
3915 if ( xDiff % 2 != 0 )
3917 this->_xRange += this->_xSamplingRate;
3918 xDiff =
static_cast<int> ( std::ceil ( this->_xRange / this->_xSamplingRate ) - ( this->_maxMapU + 1 ) );
3920 if ( yDiff % 2 != 0 )
3922 this->_yRange += this->_ySamplingRate;
3923 yDiff =
static_cast<int> ( std::ceil ( this->_yRange / this->_ySamplingRate ) - ( this->_maxMapV + 1 ) );
3925 if ( zDiff % 2 != 0 )
3927 this->_zRange += this->_zSamplingRate;
3928 zDiff =
static_cast<int> ( std::ceil ( this->_zRange / this->_zSamplingRate ) - ( this->_maxMapW + 1 ) );
3935 this->_xFrom -= xDiff;
3936 this->_yFrom -= yDiff;
3937 this->_zFrom -= zDiff;
3939 this->_xTo += xDiff;
3940 this->_yTo += yDiff;
3941 this->_zTo += zDiff;
3943 this->_maxMapU = this->_xTo - this->_xFrom;
3944 this->_maxMapV = this->_yTo - this->_yFrom;
3945 this->_maxMapW = this->_zTo - this->_zFrom;
3947 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
3948 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
3949 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
3952 float *hlpMap =
nullptr;
3953 hlpMap = (
float*) malloc ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) *
sizeof ( float ) );
3954 if ( hlpMap ==
nullptr )
3956 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
3960 std::stringstream hlpSS;
3961 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
3962 rvapi_set_text ( hlpSS.str().c_str(),
3974 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
3979 unsigned int newU, newV, newW, hlpPos, arrPos;
3980 for (
int uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
3982 for (
int vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
3984 for (
int wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
3986 if ( ( uIt < xDiff ) || ( uIt >
static_cast<int> ( this->_maxMapU - xDiff ) ) ||
3987 ( vIt < yDiff ) || ( vIt >
static_cast<int> ( this->_maxMapV - yDiff ) ) ||
3988 ( wIt < zDiff ) || ( wIt >
static_cast<int> ( this->_maxMapW - zDiff ) ) )
3990 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
3991 hlpMap[hlpPos] = 0.0;
3995 newU = (uIt - xDiff);
3996 newV = (vIt - yDiff);
3997 newW = (wIt - zDiff);
3999 hlpPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4000 arrPos = newW + (this->_maxMapW + 1 - zDiff * 2) * ( newV + (this->_maxMapV + 1 - yDiff * 2) * newU );
4002 hlpMap[hlpPos] = this->_densityMapMap[arrPos];
4009 if ( this->_densityMapMap !=
nullptr )
4011 free ( this->_densityMapMap );
4012 this->_densityMapMap =
nullptr;
4016 this->_densityMapMap = (
float*) malloc ( ((this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1)) *
sizeof ( float ) );
4017 if ( this->_densityMapMap ==
nullptr )
4019 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
4023 std::stringstream hlpSS;
4024 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
4025 rvapi_set_text ( hlpSS.str().c_str(),
4037 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
4039 this->_densityMapMap[iter] = hlpMap[iter];
4043 if ( hlpMap !=
nullptr )
4051 std::stringstream hlpSS;
4052 hlpSS <<
"<font color=\"green\">" <<
"Extra cell space added as required." <<
"</font>";
4053 rvapi_set_text ( hlpSS.str().c_str(),
4065 int hlpU = ( this->_maxMapU + 1 );
4066 int hlpV = ( this->_maxMapV + 1 );
4067 int hlpW = ( this->_maxMapW + 1 );
4071 unsigned int arrayPos = 0;
4073 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
4076 std::vector<double> vals;
4077 std::vector<double> valsWZ;
4079 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (this->_maxMapU+1) * (this->_maxMapV+1) * (this->_maxMapW+1) ); iter++ )
4081 if ( this->_densityMapMap[iter] == this->_densityMapMap[iter] )
4084 if ( this->_densityMapMap[iter] != 0.0 )
4086 vals.emplace_back ( ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev );
4088 valsWZ.emplace_back ( ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev );
4090 this->_densityMapCor[iter] = ( this->_densityMapMap[iter] - this->_mapMean ) / this->_mapSdev;
4095 this->_densityMapCor[iter] = 0.0;
4100 std::cout <<
">>>>> Map normalised." << std::endl;
4105 std::stringstream hlpSS;
4106 hlpSS <<
"<font color=\"green\">" <<
"Map normalisation complete." <<
"</font>";
4107 rvapi_set_text ( hlpSS.str().c_str(),
4125 std::sort ( vals.begin(), vals.end() );
4127 *minDensPostNorm = vals.at(0);
4128 *maxDensPostNorm = vals.at(vals.size()-1);
4130 *postNormMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
4131 *postNormSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - *postNormMean * *postNormMean );
4133 *allDensityRMS = 0.0;
4134 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( valsWZ.size() ); iter++ )
4136 *allDensityRMS += pow ( valsWZ.at(iter), 2.0 );
4138 *allDensityRMS /=
static_cast<double> ( valsWZ.size() - 1 );
4139 *allDensityRMS = sqrt ( *allDensityRMS );
4147 std::stringstream hlpSS;
4148 hlpSS <<
"<pre>" <<
"Mean (std. dev.) pre normalisation: ";
4149 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4150 for (
int iter = 0; iter < hlpIt; iter++ )
4155 std::stringstream hlpSS2;
4156 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( this->_mapMean * 1000.0 ) / 1000.0;
4157 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4158 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4159 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4161 hlpSS2.str( std::string ( ) );
4162 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( this->_mapSdev * 1000.0 ) / 1000.0;
4163 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4164 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4165 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4167 rvapi_set_text ( hlpSS.str().c_str(),
4174 hlpSS.str( std::string (
"<pre>" ) );
4175 for (
int iter = 0; iter < 70; iter++ )
4180 rvapi_set_text ( hlpSS.str().c_str(),
4187 hlpSS.str( std::string ( ) );
4188 hlpSS <<
"<pre>" <<
"Min / Max density post normalisation: ";
4189 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4190 for (
int iter = 0; iter < hlpIt; iter++ )
4195 hlpSS2.str( std::string ( ) );
4196 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *minDensPostNorm * 1000.0 ) / 1000.0;
4197 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4198 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4199 hlpSS <<
" " << hlpSS2.str() <<
" / ";
4201 hlpSS2.str( std::string ( ) );
4202 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maxDensPostNorm * 1000.0 ) / 1000.0;
4203 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4204 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4205 hlpSS << hlpSS2.str() <<
"</pre>";
4207 rvapi_set_text ( hlpSS.str().c_str(),
4214 hlpSS.str( std::string ( ) );
4215 hlpSS <<
"<pre>" <<
"Mean (std. dev.) post normalisation: ";
4216 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4217 for (
int iter = 0; iter < hlpIt; iter++ )
4222 hlpSS2.str( std::string ( ) );
4223 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *postNormMean * 1000.0 ) / 1000.0;
4224 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4225 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4226 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4228 hlpSS2.str( std::string ( ) );
4229 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *postNormSdev * 1000.0 ) / 1000.0;
4230 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4231 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4232 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4234 rvapi_set_text ( hlpSS.str().c_str(),
4241 hlpSS.str( std::string (
"<pre>" ) );
4242 for (
int iter = 0; iter < 70; iter++ )
4247 rvapi_set_text ( hlpSS.str().c_str(),
4258 this->_fromPDB =
false;
4259 if ( !this->_fromPDB )
4262 double *tmpMp =
new double[hlpU * hlpV * hlpW];
4263 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
4265 tmpMp[iter] = this->_densityMapCor[iter];
4268 bool notTooManyIslads =
true;
4269 double blFr = 150.0;
4271 while ( notTooManyIslads )
4275 if ( maskBlurFactorGiven )
4277 blFr = maskBlurFactor;
4278 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
4284 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
4289 std::cout <<
">>>>>>>> Island detection started." << std::endl;
4292 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
4294 if ( maskBlurFactorGiven )
4301 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
4303 if ( notTooManyIslads )
4307 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
4310 if ( blFr <= 500.0 )
4312 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
4314 this->_densityMapCor[iter] = tmpMp[iter];
4322 std::cout << std::endl;
4329 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;
4333 std::stringstream hlpSS;
4334 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>";
4335 rvapi_set_text ( hlpSS.str().c_str(),
4353 std::cout <<
">> Map masked." << std::endl;
4358 std::stringstream hlpSS;
4359 hlpSS <<
"<font color=\"green\">" <<
"Map masking complete." <<
"</font>";
4360 rvapi_set_text ( hlpSS.str().c_str(),
4371 if ( this->_densityMapMap !=
nullptr )
4373 delete this->_densityMapMap;
4374 this->_densityMapMap =
nullptr;
4380 for ( uIt = 0; uIt < hlpU; uIt++ )
4382 for ( vIt = 0; vIt < hlpV; vIt++ )
4384 for ( wIt = 0; wIt < hlpW; wIt++ )
4386 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4387 if ( this->_densityMapCor[arrayPos] != 0.0 ) { vals.emplace_back ( this->_densityMapCor[arrayPos] ); }
4392 *maskVolume =
static_cast<double> ( vals.size() );
4393 *totalVolume = hlpU * hlpV * hlpW;
4395 std::sort ( vals.begin(), vals.end() );
4397 *maskMin = vals.at(0);
4398 *maskMax = vals.at(vals.size()-1);
4401 *maskMean = std::accumulate ( vals.begin(), vals.end(), 0.0 ) / static_cast<double> ( vals.size() );
4402 *maskSdev = std::sqrt ( static_cast<double> ( std::inner_product ( vals.begin(), vals.end(), vals.begin(), 0.0 ) ) /
static_cast<double> ( vals.size() ) - *maskMean * *maskMean );
4404 *maskDensityRMS = 0.0;
4405 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( vals.size() ); iter++ )
4407 *maskDensityRMS += pow ( vals.at(iter), 2.0 );
4409 *maskDensityRMS /=
static_cast<double> ( vals.size() - 1 );
4410 *maskDensityRMS = sqrt ( *maskDensityRMS );
4417 std::stringstream hlpSS;
4418 hlpSS <<
"<pre>" <<
"Min / Max density after masking: ";
4419 int hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4420 for (
int iter = 0; iter < hlpIt; iter++ )
4425 std::stringstream hlpSS2;
4426 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMin * 1000.0 ) / 1000.0;
4427 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4428 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4429 hlpSS <<
" " << hlpSS2.str() <<
" / ";
4431 hlpSS2.str( std::string ( ) );
4432 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMax * 1000.0 ) / 1000.0;
4433 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4434 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4435 hlpSS << hlpSS2.str() <<
"</pre>";
4437 rvapi_set_text ( hlpSS.str().c_str(),
4444 hlpSS.str( std::string ( ) );
4445 hlpSS <<
"<pre>" <<
"Mean (std. dev.) within mask: ";
4446 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4447 for (
int iter = 0; iter < hlpIt; iter++ )
4452 hlpSS2.str( std::string ( ) );
4453 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskMean * 1000.0 ) / 1000.0;
4454 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4455 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4456 hlpSS <<
" " << hlpSS2.str() <<
" ( ";
4458 hlpSS2.str( std::string ( ) );
4459 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskSdev * 1000.0 ) / 1000.0;
4460 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4461 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4462 hlpSS << hlpSS2.str() <<
" ) " <<
"</pre>";
4464 rvapi_set_text ( hlpSS.str().c_str(),
4471 hlpSS.str( std::string (
"<pre>" ) );
4472 for (
int iter = 0; iter < 70; iter++ )
4477 rvapi_set_text ( hlpSS.str().c_str(),
4484 hlpSS.str( std::string ( ) );
4485 hlpSS <<
"<pre>" <<
"Total structure volume: ";
4486 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4487 for (
int iter = 0; iter < hlpIt; iter++ )
4492 hlpSS2.str( std::string ( ) );
4493 hlpSS2 << std::showpos << std::setprecision ( 10 ) << *totalVolume * 1000.0 / 1000.0;
4494 if ( hlpSS2.str().length() != 15 ) {
int hlp = 15 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4495 if ( hlpSS2.str().length() > 15 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4496 hlpSS <<
" " << hlpSS2.str() <<
" A^3 " <<
"</pre>";
4498 rvapi_set_text ( hlpSS.str().c_str(),
4505 hlpSS.str( std::string ( ) );
4506 hlpSS <<
"<pre>" <<
"Total mask volume: ";
4507 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4508 for (
int iter = 0; iter < hlpIt; iter++ )
4513 hlpSS2.str( std::string ( ) );
4514 hlpSS2 << std::showpos << std::setprecision ( 10 ) << *maskVolume * 1000.0 / 1000.0;
4515 if ( hlpSS2.str().length() != 15 ) {
int hlp = 15 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4516 if ( hlpSS2.str().length() > 15 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4517 hlpSS <<
" " << hlpSS2.str() <<
" A^3 " <<
"</pre>";
4519 rvapi_set_text ( hlpSS.str().c_str(),
4526 hlpSS.str( std::string (
"<pre>" ) );
4527 for (
int iter = 0; iter < 70; iter++ )
4532 rvapi_set_text ( hlpSS.str().c_str(),
4539 hlpSS.str( std::string ( ) );
4540 hlpSS <<
"<pre>" <<
"RMS of complete map: ";
4541 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4542 for (
int iter = 0; iter < hlpIt; iter++ )
4547 hlpSS2.str( std::string ( ) );
4548 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *allDensityRMS * 1000.0 ) / 1000.0;
4549 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4550 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4551 hlpSS <<
" " << hlpSS2.str() <<
" " <<
"</pre>";
4553 rvapi_set_text ( hlpSS.str().c_str(),
4560 hlpSS.str( std::string ( ) );
4561 hlpSS <<
"<pre>" <<
"RMS of masked map: ";
4562 hlpIt =
static_cast<int> ( 70 - hlpSS.str().length() );
4563 for (
int iter = 0; iter < hlpIt; iter++ )
4568 hlpSS2.str( std::string ( ) );
4569 hlpSS2 << std::showpos << ProSHADE_internal_misc::roundDouble ( *maskDensityRMS * 1000.0 ) / 1000.0;
4570 if ( hlpSS2.str().length() != 6 ) {
int hlp = 6 - hlpSS2.str().length();
for (
int i = 0; i < hlp; i++ ) { hlpSS2 <<
" "; } }
4571 if ( hlpSS2.str().length() > 6 ) { hlpSS2.str( hlpSS2.str().substr( 0, 6 ) ); }
4572 hlpSS <<
" " << hlpSS2.str() <<
" " <<
"</pre>";
4574 rvapi_set_text ( hlpSS.str().c_str(),
4585 double xReal = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
4586 double yReal = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
4587 double zReal = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
4590 std::array<double,3> meanVals;
4595 double totDens = 0.0;
4597 for ( uIt = 0; uIt < hlpU; uIt++ )
4599 for ( vIt = 0; vIt < hlpV; vIt++ )
4601 for ( wIt = 0; wIt < hlpW; wIt++ )
4603 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4605 meanVals[0] += this->_densityMapCor[arrayPos] * uIt;
4606 meanVals[1] += this->_densityMapCor[arrayPos] * vIt;
4607 meanVals[2] += this->_densityMapCor[arrayPos] * wIt;
4609 totDens += this->_densityMapCor[arrayPos];
4614 meanVals[0] /= totDens;
4615 meanVals[1] /= totDens;
4616 meanVals[2] /= totDens;
4619 this->_xCorrErr = meanVals[0] -
static_cast<double> ( this->_maxMapU + 1 )/2.0;
4620 this->_yCorrErr = meanVals[1] -
static_cast<double> ( this->_maxMapV + 1 )/2.0;
4621 this->_zCorrErr = meanVals[2] -
static_cast<double> ( this->_maxMapW + 1 )/2.0;
4623 this->_xCorrection = std::ceil ( this->_xCorrErr );
4624 this->_yCorrection = std::ceil ( this->_yCorrErr );
4625 this->_zCorrection = std::ceil ( this->_zCorrErr );
4628 this->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
4629 int newU, newV, newW, coordPos;
4632 for ( uIt = 0; uIt < hlpU; uIt++ )
4634 for ( vIt = 0; vIt < hlpV; vIt++ )
4636 for ( wIt = 0; wIt < hlpW; wIt++ )
4638 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
4639 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
4640 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
4642 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
4643 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
4644 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
4646 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4647 coordPos = newW + hlpW * ( newV + hlpV * newU );
4649 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) / 2.0 ) * xReal;
4650 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) / 2.0 ) * yReal;
4651 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) / 2.0 ) * zReal;
4657 std::cout <<
">> Map centered." << std::endl;
4662 std::stringstream hlpSS;
4663 hlpSS <<
"<font color=\"green\">" <<
"Map centered." <<
"</font>";
4664 rvapi_set_text ( hlpSS.str().c_str(),
4681 double maxXTot = 0.0;
4682 double minXTot = 0.0;
4683 double maxYTot = 0.0;
4684 double minYTot = 0.0;
4685 double maxZTot = 0.0;
4686 double minZTot = 0.0;
4689 for ( uIt = 0; uIt < hlpU; uIt++ )
4691 for ( vIt = 0; vIt < hlpV; vIt++ )
4693 for ( wIt = 0; wIt < hlpW; wIt++ )
4695 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
4697 if ( this->_densityMapCor[coordPos] > 0.0 )
4699 maxX = std::max ( maxX, this->_densityMapCorCoords[coordPos][0] );
4700 minX = std::min ( minX, this->_densityMapCorCoords[coordPos][0] );
4701 maxY = std::max ( maxY, this->_densityMapCorCoords[coordPos][1] );
4702 minY = std::min ( minY, this->_densityMapCorCoords[coordPos][1] );
4703 maxZ = std::max ( maxZ, this->_densityMapCorCoords[coordPos][2] );
4704 minZ = std::min ( minZ, this->_densityMapCorCoords[coordPos][2] );
4706 maxXTot = std::max ( maxXTot, this->_densityMapCorCoords[coordPos][0] );
4707 minXTot = std::min ( minXTot, this->_densityMapCorCoords[coordPos][0] );
4708 maxYTot = std::max ( maxYTot, this->_densityMapCorCoords[coordPos][1] );
4709 minYTot = std::min ( minYTot, this->_densityMapCorCoords[coordPos][1] );
4710 maxZTot = std::max ( maxZTot, this->_densityMapCorCoords[coordPos][2] );
4711 minZTot = std::min ( minZTot, this->_densityMapCorCoords[coordPos][2] );
4717 int newUStart = std::floor ( ( ( minX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
4718 int newUEnd = std::ceil ( ( ( maxX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
4719 int newVStart = std::floor ( ( ( minY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
4720 int newVEnd = std::ceil ( ( ( maxY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
4721 int newWStart = std::floor ( ( ( minZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
4722 int newWEnd = std::ceil ( ( ( maxZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
4727 newUStart = std::min( newUStart, std::min( newVStart, newWStart ) );
4728 newVStart = std::min( newUStart, std::min( newVStart, newWStart ) );
4729 newWStart = std::min( newUStart, std::min( newVStart, newWStart ) );
4730 newUEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
4731 newVEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
4732 newWEnd = std::max( newUEnd , std::max( newVEnd , newWEnd ) );
4736 int newXDim = newUEnd - newUStart + 1;
4737 int newYDim = newVEnd - newVStart + 1;
4738 int newZDim = newWEnd - newWStart + 1;
4740 if ( ( this->_xFrom < 0 ) && ( ( this->_xFrom + newUStart ) >= 0 ) ) { newXDim += 1; }
4741 if ( ( this->_yFrom < 0 ) && ( ( this->_yFrom + newVStart ) >= 0 ) ) { newYDim += 1; }
4742 if ( ( this->_zFrom < 0 ) && ( ( this->_zFrom + newWStart ) >= 0 ) ) { newZDim += 1; }
4744 double *hlpMap =
nullptr;
4745 hlpMap = (
double*) malloc ( newXDim * newYDim * newZDim *
sizeof (
double ) );
4746 if ( hlpMap ==
nullptr )
4748 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map moving data. Terminating... " << std::endl;
4752 std::stringstream hlpSS;
4753 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory for map data. Could you have run out of memory?" <<
"</font>";
4754 rvapi_set_text ( hlpSS.str().c_str(),
4768 for ( uIt = this->_xFrom; uIt <= this->_xTo; uIt++ )
4770 for ( vIt = this->_yFrom; vIt <= this->_yTo; vIt++ )
4772 for ( wIt = this->_zFrom; wIt <= this->_zTo; wIt++ )
4774 if ( ( uIt < (this->_xFrom+newUStart) ) || ( uIt > (this->_xFrom+newUEnd) ) ||
4775 ( vIt < (this->_yFrom+newVStart) ) || ( vIt > (this->_yFrom+newVEnd) ) ||
4776 ( wIt < (this->_zFrom+newWStart) ) || ( wIt > (this->_zFrom+newWEnd) ) )
4781 newU = uIt - this->_xFrom;
4782 newV = vIt - this->_yFrom;
4783 newW = wIt - this->_zFrom;
4784 arrPos = newW + (this->_maxMapW + 1) * ( newV + (this->_maxMapV + 1) * newU );
4786 newU = newU - newUStart;
4787 newV = newV - newVStart;
4788 newW = newW - newWStart;
4789 hlpPos = newW + newZDim * ( newV + newYDim * newU );
4791 hlpMap[hlpPos] = this->_densityMapCor[arrPos];
4797 if ( addXOne ) { this->_xFrom -= 1; }
4798 if ( addYOne ) { this->_yFrom -= 1; }
4799 if ( addZOne ) { this->_zFrom -= 1; }
4801 this->_xFrom += newUStart;
4802 this->_yFrom += newVStart;
4803 this->_zFrom += newWStart;
4805 this->_xTo -= this->_maxMapU - newUEnd;
4806 this->_yTo -= this->_maxMapV - newVEnd;
4807 this->_zTo -= this->_maxMapW - newWEnd;
4809 this->_maxMapU = newXDim - 1;
4810 this->_maxMapV = newYDim - 1;
4811 this->_maxMapW = newZDim - 1;
4813 if ( ( this->_xFrom > 0 ) && ( this->_xTo > 0 ) ) { this->_xTo += 1; }
4814 if ( ( this->_yFrom > 0 ) && ( this->_yTo > 0 ) ) { this->_yTo += 1; }
4815 if ( ( this->_zFrom > 0 ) && ( this->_zTo > 0 ) ) { this->_zTo += 1; }
4817 this->_xRange = this->_xSamplingRate * ( this->_maxMapU + 1 );
4818 this->_yRange = this->_ySamplingRate * ( this->_maxMapV + 1 );
4819 this->_zRange = this->_zSamplingRate * ( this->_maxMapW + 1 );
4822 delete[] this->_densityMapCor;
4823 this->_densityMapCor =
nullptr;
4824 this->_densityMapCor =
new double [newXDim * newYDim * newZDim];
4826 for (
int iter = 0; iter < (newXDim * newYDim * newZDim); iter++ )
4828 this->_densityMapCor[iter] = hlpMap[iter];
4831 if ( hlpMap !=
nullptr )
4839 std::cout <<
">> Map resized." << std::endl;
4844 std::stringstream hlpSS;
4845 hlpSS <<
"<font color=\"green\">" <<
"Map resized." <<
"</font>";
4846 rvapi_set_text ( hlpSS.str().c_str(),
4876 if ( !this->_densityMapComputed )
4878 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;
4882 std::stringstream hlpSS;
4883 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>";
4884 rvapi_set_text ( hlpSS.str().c_str(),
4898 this->_fourierCoeffPower = alpha;
4899 this->_bFactorChange = bFac;
4902 fftw_complex *tmpOut;
4903 fftw_complex *tmpIn;
4908 int hlpU = ( this->_maxMapU + 1 );
4909 int hlpV = ( this->_maxMapV + 1 );
4910 int hlpW = ( this->_maxMapW + 1 );
4912 this->_densityMapCor =
new double [(this->_maxMapU+2) * (this->_maxMapV+2) * (this->_maxMapW+2)];
4913 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
4914 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
4917 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
4918 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
4921 unsigned int noMapPoints = 0;
4923 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
4925 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
4927 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
4930 noMapPoints = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
4932 if ( this->_densityMapMap[noMapPoints] == this->_densityMapMap[noMapPoints] )
4934 tmpIn[noMapPoints][0] = this->_densityMapMap[noMapPoints];
4935 tmpIn[noMapPoints][1] = 0.0;
4939 tmpIn[noMapPoints][0] = 0.0;
4940 tmpIn[noMapPoints][1] = 0.0;
4950 unsigned int arrayPos = 0;
4953 double normFactor = (hlpU * hlpV * hlpW);
4954 for ( uIt = 0; uIt < hlpU; uIt++ )
4956 for ( vIt = 0; vIt < hlpV; vIt++ )
4958 for ( wIt = 0; wIt < hlpW; wIt++ )
4961 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
4962 real = tmpOut[arrayPos][0];
4963 imag = tmpOut[arrayPos][1];
4966 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
4967 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
4968 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
4970 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 );
4971 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
4974 mag *= sqrt ( (real*real) + (imag*imag) );
4977 mag = pow ( mag, this->_fourierCoeffPower );
4980 tmpOut[arrayPos][0] = mag;
4981 tmpOut[arrayPos][1] = 0.0;
4984 tmpOut[arrayPos][0] /= normFactor;
4990 fftw_execute ( pInv );
4993 fftw_destroy_plan ( p );
4994 fftw_destroy_plan ( pInv );
4997 this->_densityMapCorCoords =
new std::array<double,3> [(this->_maxMapU+2) * (this->_maxMapV+2) * (this->_maxMapW+2)];
5006 int nonTranslatedIter = 0;
5009 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU + 2); uIt++ )
5011 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV + 2); vIt++ )
5013 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW + 2); wIt++ )
5015 if ( ( uIt == hlpU ) || ( vIt == hlpV ) || ( wIt == hlpW ) )
5017 newU = uIt;
if ( uIt == hlpU ) { newU = 0; }
5018 newV = vIt;
if ( vIt == hlpV ) { newV = 0; }
5019 newW = wIt;
if ( wIt == hlpW ) { newW = 0; }
5021 cenPosU = newU + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5022 cenPosV = newV + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5023 cenPosW = newW + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5025 arrayPos = cenPosW + hlpW * ( cenPosV + hlpV * cenPosU );
5027 this->_densityMapCor[nonTranslatedIter] = tmpIn[arrayPos][0];
5028 this->_densityMapCorCoords[nonTranslatedIter][0] = uIt - hlpU / 2;
5029 this->_densityMapCorCoords[nonTranslatedIter][1] = vIt - hlpV / 2;
5030 this->_densityMapCorCoords[nonTranslatedIter][2] = wIt - hlpW / 2;
5034 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5036 cenPosU = uIt + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5037 cenPosV = vIt + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5038 cenPosW = wIt + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5039 coordPos = cenPosW + (this->_maxMapW + 2) * ( cenPosV + (this->_maxMapV + 2) * cenPosU );
5041 this->_densityMapCor[coordPos] = tmpIn[arrayPos][0];
5042 this->_densityMapCorCoords[coordPos][0] = cenPosU - hlpU / 2;
5043 this->_densityMapCorCoords[coordPos][1] = cenPosV - hlpV / 2;
5044 this->_densityMapCorCoords[coordPos][2] = cenPosW - hlpW / 2;
5046 nonTranslatedIter += 1;
5056 if ( this->_densityMapMap !=
nullptr )
5058 delete this->_densityMapMap;
5059 this->_densityMapMap =
nullptr;
5063 this->_phaseRemoved =
true;
5064 this->_keepOrRemove =
false;
5065 this->_usePhase =
false;
5085 if ( !this->_densityMapComputed )
5087 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;
5091 std::stringstream hlpSS;
5092 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>";
5093 rvapi_set_text ( hlpSS.str().c_str(),
5107 this->_fourierCoeffPower = alpha;
5108 this->_bFactorChange = bFac;
5111 fftw_complex *tmpOut;
5112 fftw_complex *tmpIn;
5117 int hlpU = ( this->_maxMapU + 1 );
5118 int hlpV = ( this->_maxMapV + 1 );
5119 int hlpW = ( this->_maxMapW + 1 );
5121 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
5122 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
5123 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
5126 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
5127 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
5130 unsigned int arrayPos = 0;
5132 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
5134 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
5136 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
5139 arrayPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
5141 if ( this->_densityMapMap[arrayPos] == this->_densityMapMap[arrayPos] )
5143 tmpIn[arrayPos][0] = this->_densityMapMap[arrayPos];
5144 tmpIn[arrayPos][1] = 0.0;
5148 tmpIn[arrayPos][0] = 0.0;
5149 tmpIn[arrayPos][1] = 0.0;
5162 double normFactor = (hlpU * hlpV * hlpW);
5163 for ( uIt = 0; uIt < hlpU; uIt++ )
5165 for ( vIt = 0; vIt < hlpV; vIt++ )
5167 for ( wIt = 0; wIt < hlpW; wIt++ )
5170 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5171 real = tmpOut[arrayPos][0];
5172 imag = tmpOut[arrayPos][1];
5175 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
5176 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
5177 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
5179 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 );
5180 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
5183 mag *= sqrt ( (real*real) + (imag*imag) );
5186 mag = pow ( mag, this->_fourierCoeffPower );
5189 tmpOut[arrayPos][0] = mag;
5190 tmpOut[arrayPos][1] = 0.0;
5193 tmpOut[arrayPos][0] /= normFactor;
5199 fftw_execute ( pInv );
5202 fftw_destroy_plan ( p );
5203 fftw_destroy_plan ( pInv );
5211 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU + 1); uIt++ )
5213 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV + 1); vIt++ )
5215 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW + 1); wIt++ )
5217 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5219 cenPosU = uIt + (hlpU / 2);
if ( cenPosU >= hlpU ) { cenPosU -= hlpU; }
5220 cenPosV = vIt + (hlpV / 2);
if ( cenPosV >= hlpV ) { cenPosV -= hlpV; }
5221 cenPosW = wIt + (hlpW / 2);
if ( cenPosW >= hlpW ) { cenPosW -= hlpW; }
5222 coordPos = cenPosW + (this->_maxMapW + 1) * ( cenPosV + (this->_maxMapV + 1) * cenPosU );
5224 this->_densityMapCor[arrayPos]= tmpIn[coordPos][0];
5234 if ( this->_densityMapMap !=
nullptr )
5236 delete this->_densityMapMap;
5237 this->_densityMapMap =
nullptr;
5241 this->_phaseRemoved =
true;
5242 this->_usePhase =
false;
5243 this->_keepOrRemove =
false;
5272 unsigned int *bandwidth,
5273 unsigned int *theta,
5275 unsigned int *glIntegOrder,
5282 bool overlapDefaults,
5284 bool maskBlurFactorGiven )
5287 if ( !this->_densityMapComputed )
5289 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;
5293 std::stringstream hlpSS;
5294 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>";
5295 rvapi_set_text ( hlpSS.str().c_str(),
5309 this->_fourierCoeffPower = alpha;
5310 this->_bFactorChange = bFac;
5313 int hlpU = ( this->_maxMapU + 1 );
5314 int hlpV = ( this->_maxMapV + 1 );
5315 int hlpW = ( this->_maxMapW + 1 );
5318 fftw_complex *tmpOut;
5319 fftw_complex *tmpIn;
5324 unsigned int arrayPos = 0;
5327 this->_densityMapCor =
new double [hlpU * hlpV * hlpW];
5328 tmpIn =
new fftw_complex[hlpU * hlpV * hlpW];
5329 tmpOut =
new fftw_complex[hlpU * hlpV * hlpW];
5332 p = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpIn, tmpOut, FFTW_FORWARD, FFTW_ESTIMATE );
5333 pInv = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpOut, tmpIn, FFTW_BACKWARD, FFTW_ESTIMATE );
5336 for ( uIt = 0; uIt < static_cast<int> (this->_maxMapU+1); uIt++ )
5338 for ( vIt = 0; vIt < static_cast<int> (this->_maxMapV+1); vIt++ )
5340 for ( wIt = 0; wIt < static_cast<int> (this->_maxMapW+1); wIt++ )
5343 arrPos = wIt + (this->_maxMapW + 1) * ( vIt + (this->_maxMapV + 1) * uIt );
5345 if ( this->_densityMapMap[arrPos] == this->_densityMapMap[arrPos] )
5347 tmpIn[arrPos][0] = this->_densityMapMap[arrPos];
5348 tmpIn[arrPos][1] = 0.0;
5352 tmpIn[arrPos][0] = 0.0;
5353 tmpIn[arrPos][1] = 0.0;
5360 if ( ( this->_fourierCoeffPower != 1.0 ) || ( this->_bFactorChange != 0.0 ) )
5367 double mag, phase, S;
5368 double normFactor = (hlpU * hlpV * hlpW);
5369 for ( uIt = 0; uIt < hlpU; uIt++ )
5371 for ( vIt = 0; vIt < hlpV; vIt++ )
5373 for ( wIt = 0; wIt < hlpW; wIt++ )
5376 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5377 real = tmpOut[arrayPos][0];
5378 imag = tmpOut[arrayPos][1];
5381 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
5382 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
5383 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
5385 S = pow ( static_cast<double> ( h ) / this->_xRange, 2.0 ) +
5386 pow ( static_cast<double> ( k ) / this->_yRange, 2.0 ) +
5387 pow ( static_cast<double> ( l ) / this->_zRange, 2.0 );
5388 mag = std::exp ( - ( ( this->_bFactorChange * S ) / 4.0 ) );
5391 mag *= sqrt ( (real*real) + (imag*imag) );
5392 phase = atan2 ( imag, real );
5395 mag = pow ( mag, this->_fourierCoeffPower );
5398 tmpOut[arrayPos][0] = mag * cos(phase);
5399 tmpOut[arrayPos][1] = mag * sin(phase);
5402 tmpOut[arrayPos][0] /= normFactor;
5403 tmpOut[arrayPos][1] /= normFactor;
5409 fftw_execute ( pInv );
5413 fftw_destroy_plan ( p );
5414 fftw_destroy_plan ( pInv );
5417 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5419 this->_densityMapCor[iter] = this->_densityMapMap[iter];
5423 if ( this->_densityMapMap !=
nullptr )
5425 free ( this->_densityMapMap );
5426 this->_densityMapMap =
nullptr;
5430 if ( !this->_fromPDB )
5435 double *tmpMp =
new double[hlpU * hlpV * hlpW];
5436 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5438 tmpMp[iter] = this->_densityMapCor[iter];
5441 bool notTooManyIslads =
true;
5442 double blFr = 150.0;
5444 while ( notTooManyIslads )
5448 if ( maskBlurFactorGiven )
5451 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
5457 this->
maskMap ( hlpU, hlpV, hlpW, blFr, maxMapIQR, 3.0 );
5462 std::cout <<
">>>>>>>> Island detection started." << std::endl;
5465 notTooManyIslads = this->
removeIslands ( hlpU, hlpV, hlpW, verbose,
false );
5467 if ( maskBlurFactorGiven )
5474 std::cout <<
">>>>> Map masked with factor of " << blFr <<
" and small islands were then removed.";
5476 if ( notTooManyIslads )
5480 std::cout <<
" However, too many islands remained. Trying higher blurring factor." << std::endl;
5483 if ( blFr <= 500.0 )
5485 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
5487 this->_densityMapCor[iter] = tmpMp[iter];
5495 std::cout << std::endl;
5501 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;
5505 std::stringstream hlpSS;
5506 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>";
5507 rvapi_set_text ( hlpSS.str().c_str(),
5525 double xReal = this->_xRange /
static_cast<double> ( this->_maxMapU + 1 );
5526 double yReal = this->_yRange /
static_cast<double> ( this->_maxMapV + 1 );
5527 double zReal = this->_zRange /
static_cast<double> ( this->_maxMapW + 1 );
5530 std::array<double,3> meanVals;
5535 if ( !this->_firstLineCOM )
5539 double totDens = 0.0;
5541 for ( uIt = 0; uIt < hlpU; uIt++ )
5543 for ( vIt = 0; vIt < hlpV; vIt++ )
5545 for ( wIt = 0; wIt < hlpW; wIt++ )
5547 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5549 if ( !this->_fromPDB )
5551 if ( this->_densityMapCor[arrayPos] > 0.0 )
5553 meanVals[0] += this->_densityMapCor[arrayPos] * uIt;
5554 meanVals[1] += this->_densityMapCor[arrayPos] * vIt;
5555 meanVals[2] += this->_densityMapCor[arrayPos] * wIt;
5557 totDens += this->_densityMapCor[arrayPos];
5562 if ( tmpIn[arrayPos][0] > 0.0 )
5564 meanVals[0] += tmpIn[arrayPos][0] * uIt;
5565 meanVals[1] += tmpIn[arrayPos][0] * vIt;
5566 meanVals[2] += tmpIn[arrayPos][0] * wIt;
5568 totDens += tmpIn[arrayPos][0];
5575 meanVals[0] /= totDens;
5576 meanVals[1] /= totDens;
5577 meanVals[2] /= totDens;
5581 meanVals[0] =
static_cast<double> ( this->_maxMapU + 1 )/2.0;
5582 meanVals[1] =
static_cast<double> ( this->_maxMapV + 1 )/2.0;
5583 meanVals[2] =
static_cast<double> ( this->_maxMapW + 1 )/2.0;
5588 meanVals[0] = this->_xCorrErr / xReal;
5589 meanVals[1] = this->_yCorrErr / yReal;
5590 meanVals[2] = this->_zCorrErr / zReal;
5594 this->_xCorrErr = meanVals[0] -
static_cast<double> ( this->_maxMapU + 1 )/2.0;
5595 this->_yCorrErr = meanVals[1] -
static_cast<double> ( this->_maxMapV + 1 )/2.0;
5596 this->_zCorrErr = meanVals[2] -
static_cast<double> ( this->_maxMapW + 1 )/2.0;
5598 this->_xCorrection = std::ceil ( this->_xCorrErr );
5599 this->_yCorrection = std::ceil ( this->_yCorrErr );
5600 this->_zCorrection = std::ceil ( this->_zCorrErr );
5603 this->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
5604 int newU, newV, newW, coordPos;
5606 if ( this->_fromPDB )
5610 for ( uIt = 0; uIt < hlpU; uIt++ )
5612 for ( vIt = 0; vIt < hlpV; vIt++ )
5614 for ( wIt = 0; wIt < hlpW; wIt++ )
5616 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
5617 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
5618 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
5620 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
5621 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
5622 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
5624 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5625 coordPos = newW + hlpW * ( newV + hlpV * newU );
5627 this->_densityMapCor[coordPos] = tmpIn[arrayPos][0];
5630 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) / 2.0 ) * xReal;
5631 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) / 2.0 ) * yReal;
5632 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) / 2.0 ) * zReal;
5639 for ( uIt = 0; uIt < hlpU; uIt++ )
5641 for ( vIt = 0; vIt < hlpV; vIt++ )
5643 for ( wIt = 0; wIt < hlpW; wIt++ )
5645 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5647 this->_densityMapCor[arrayPos] = tmpIn[arrayPos][0];
5648 this->_densityMapCorCoords[arrayPos][0] = (
static_cast<double> ( uIt ) - ( static_cast<double> ( hlpU ) / 2.0 ) ) * xReal;
5649 this->_densityMapCorCoords[arrayPos][1] = (
static_cast<double> ( vIt ) - ( static_cast<double> ( hlpV ) / 2.0 ) ) * yReal;
5650 this->_densityMapCorCoords[arrayPos][2] = (
static_cast<double> ( wIt ) - ( static_cast<double> ( hlpW ) / 2.0 ) ) * zReal;
5659 if ( !clearMapData )
5661 this->_xCorrection = 0.0;
5662 this->_yCorrection = 0.0;
5663 this->_zCorrection = 0.0;
5667 for ( uIt = 0; uIt < hlpU; uIt++ )
5669 for ( vIt = 0; vIt < hlpV; vIt++ )
5671 for ( wIt = 0; wIt < hlpW; wIt++ )
5673 newU =
static_cast<int> ( uIt ) - static_cast<int> ( this->_xCorrection );
5674 newV =
static_cast<int> ( vIt ) - static_cast<int> ( this->_yCorrection );
5675 newW =
static_cast<int> ( wIt ) - static_cast<int> ( this->_zCorrection );
5677 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
5678 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
5679 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
5681 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
5682 coordPos = newW + hlpW * ( newV + hlpV * newU );
5684 this->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) / 2.0 ) * xReal;
5685 this->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) / 2.0 ) * yReal;
5686 this->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) / 2.0 ) * zReal;
5698 double maxXTot = 0.0;
5699 double minXTot = 0.0;
5700 double maxYTot = 0.0;
5701 double minYTot = 0.0;
5702 double maxZTot = 0.0;
5703 double minZTot = 0.0;
5705 for ( uIt = 0; uIt < hlpU; uIt++ )
5707 for ( vIt = 0; vIt < hlpV; vIt++ )
5709 for ( wIt = 0; wIt < hlpW; wIt++ )
5711 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
5713 if ( this->_densityMapCor[coordPos] > 0.0 )
5715 maxX = std::max ( maxX, this->_densityMapCorCoords[coordPos][0] );
5716 minX = std::min ( minX, this->_densityMapCorCoords[coordPos][0] );
5717 maxY = std::max ( maxY, this->_densityMapCorCoords[coordPos][1] );
5718 minY = std::min ( minY, this->_densityMapCorCoords[coordPos][1] );
5719 maxZ = std::max ( maxZ, this->_densityMapCorCoords[coordPos][2] );
5720 minZ = std::min ( minZ, this->_densityMapCorCoords[coordPos][2] );
5722 maxXTot = std::max ( maxXTot, this->_densityMapCorCoords[coordPos][0] );
5723 minXTot = std::min ( minXTot, this->_densityMapCorCoords[coordPos][0] );
5724 maxYTot = std::max ( maxYTot, this->_densityMapCorCoords[coordPos][1] );
5725 minYTot = std::min ( minYTot, this->_densityMapCorCoords[coordPos][1] );
5726 maxZTot = std::max ( maxZTot, this->_densityMapCorCoords[coordPos][2] );
5727 minZTot = std::min ( minZTot, this->_densityMapCorCoords[coordPos][2] );
5733 if ( ( ( maxX == maxXTot ) && ( minX == minXTot ) ) &&
5734 ( ( maxY == maxYTot ) && ( minY == minYTot ) ) &&
5735 ( ( maxZ == maxZTot ) && ( minZ == minZTot ) ) )
5738 this->_phaseRemoved =
true;
5739 this->_keepOrRemove =
true;
5740 this->_usePhase =
true;
5746 if ( rotDefaults || overlapDefaults )
5749 this->_phaseRemoved =
true;
5750 this->_keepOrRemove =
true;
5751 this->_usePhase =
true;
5757 int newUStart = std::floor ( ( ( minX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
5758 int newUEnd = std::ceil ( ( ( maxX - minXTot ) / ( maxXTot - minXTot ) ) * ( this->_maxMapU + 1 ) );
5759 int newVStart = std::floor ( ( ( minY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
5760 int newVEnd = std::ceil ( ( ( maxY - minYTot ) / ( maxYTot - minYTot ) ) * ( this->_maxMapV + 1 ) );
5761 int newWStart = std::floor ( ( ( minZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
5762 int newWEnd = std::ceil ( ( ( maxZ - minZTot ) / ( maxZTot - minZTot ) ) * ( this->_maxMapW + 1 ) );
5764 int newURange = std::max ( std::abs ( newUStart - static_cast<int>( this->_maxMapU + 1 )/2 ), std::abs ( newUEnd - static_cast<int>( this->_maxMapU + 1 )/2 ) );
5765 int newVRange = std::max ( std::abs ( newVStart - static_cast<int>( this->_maxMapV + 1 )/2 ), std::abs ( newVEnd - static_cast<int>( this->_maxMapV + 1 )/2 ) );
5766 int newWRange = std::max ( std::abs ( newWStart - static_cast<int>( this->_maxMapW + 1 )/2 ), std::abs ( newWEnd - static_cast<int>( this->_maxMapW + 1 )/2 ) );
5768 newUStart = ( this->_maxMapU + 1 )/2 - newURange;
5769 newUEnd = ( this->_maxMapU + 1 )/2 + newURange;
5770 newVStart = ( this->_maxMapV + 1 )/2 - newVRange;
5771 newVEnd = ( this->_maxMapV + 1 )/2 + newVRange;
5772 newWStart = ( this->_maxMapW + 1 )/2 - newWRange;
5773 newWEnd = ( this->_maxMapW + 1 )/2 + newWRange;
5775 newURange = newURange * 2 + 1;
5776 newVRange = newVRange * 2 + 1;
5777 newWRange = newWRange * 2 + 1;
5780 double* newMapHlp =
new double [newURange * newVRange * newWRange];
5781 std::array<double,3>* newMapCoords =
new std::array<double,3> [newURange * newVRange * newWRange];
5784 unsigned int newUIt, newVIt, newWIt;
5787 for ( uIt = 0; uIt < hlpU; uIt++ )
5789 if ( ( uIt < newUStart ) || ( uIt > newUEnd ) ) {
continue; }
5792 for ( vIt = 0; vIt < hlpV; vIt++ )
5794 if ( ( vIt < newVStart ) || ( vIt > newVEnd ) ) {
continue; }
5797 for ( wIt = 0; wIt < hlpW; wIt++ )
5799 if ( ( wIt < newWStart ) || ( wIt > newWEnd ) ) {
continue; }
5801 coordPos = wIt + hlpW * ( vIt + hlpV * uIt );
5802 arrayPos = newWIt + newWRange * ( newVIt + newVRange * newUIt );
5804 newMapHlp[arrayPos] = this->_densityMapCor[coordPos];
5805 newMapCoords[arrayPos][0] = this->_densityMapCorCoords[coordPos][0];
5806 newMapCoords[arrayPos][1] = this->_densityMapCorCoords[coordPos][1];
5807 newMapCoords[arrayPos][2] = this->_densityMapCorCoords[coordPos][2];
5819 delete this->_densityMapCor;
5820 delete this->_densityMapCorCoords;
5821 this->_densityMapCor =
nullptr;
5822 this->_densityMapCorCoords =
nullptr;
5825 this->_densityMapCor = newMapHlp;
5826 newMapHlp =
nullptr;
5827 this->_densityMapCorCoords = newMapCoords;
5828 newMapCoords =
nullptr;
5831 this->_xRange = (
static_cast<double> (newURange - 1) / static_cast<double> ( this->_maxMapU ) ) * this->_xRange;
5832 this->_yRange = (
static_cast<double> (newVRange - 1) / static_cast<double> ( this->_maxMapV ) ) * this->_yRange;
5833 this->_zRange = (
static_cast<double> (newWRange - 1) / static_cast<double> ( this->_maxMapW ) ) * this->_zRange;
5834 this->_maxMapRange = std::max ( this->_xRange, std::max( this->_yRange, this->_zRange ) );
5836 this->_maxMapU = newURange - 1;
5837 this->_maxMapV = newVRange - 1;
5838 this->_maxMapW = newWRange - 1;
5841 this->_shellPlacement = std::vector<double> ( std::floor ( this->_maxMapRange / this->_shellSpacing ) );
5843 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( this->_shellPlacement.size() ); shellIter++ )
5845 this->_shellPlacement.at(shellIter) = (shellIter+1) * this->_shellSpacing;
5849 this->_xSamplingRate = this->_xRange /
static_cast<double> ( this->_maxMapU );
5850 this->_ySamplingRate = this->_yRange /
static_cast<double> ( this->_maxMapV );
5851 this->_zSamplingRate = this->_zRange /
static_cast<double> ( this->_maxMapW );
5852 double maxSamplingRate = std::max ( this->_xSamplingRate, std::max( this->_ySamplingRate, this->_zSamplingRate ) );
5855 if ( ( this->_mapResolution / 2.0 ) > maxSamplingRate )
5857 maxSamplingRate = ( this->_mapResolution / 2.0 );
5861 if ( !this->_wasBandwithGiven )
5863 *bandwidth = std::ceil ( std::ceil ( ( ( std::ceil ( this->_maxMapRange / this->_shellSpacing ) * this->_shellSpacing ) / maxSamplingRate ) * 2.0 ) / 2.0 );
5867 *bandwidth =
static_cast<unsigned int> ( 180 / settings->
maxRotError );
5868 this->_wasBandwithGiven =
true;
5872 if ( !this->_wasThetaGiven ) { *theta = 2 * (*bandwidth); this->_thetaAngle = *theta; }
5873 if ( !this->_wasPhiGiven ) { *phi = 2 * (*bandwidth); this->_phiAngle = *phi; }
5876 double distPerPointFraction;
5877 if ( !this->_wasGlInterGiven )
5879 distPerPointFraction =
static_cast<double> ( this->_shellSpacing ) / ( this->_maxMapRange / 2.0 );
5881 for (
unsigned int iter = 2; iter < static_cast<unsigned int> ( ProSHADE_internal_misc::glIntMaxDists.size() ); iter++ )
5883 if ( ProSHADE_internal_misc::glIntMaxDists.at(iter) >= distPerPointFraction )
5885 *glIntegOrder = iter;
5892 this->_bandwidthLimit = *bandwidth;
5893 this->_thetaAngle =
static_cast<double> ( *theta );
5894 this->_phiAngle =
static_cast<double> ( *phi );
5901 this->_phaseRemoved =
true;
5902 this->_usePhase =
true;
5903 this->_keepOrRemove =
true;
5920 std::cout <<
"-----------------------------------------------------------" << std::endl;
5921 std::cout <<
"| RESULTS |" << std::endl;
5922 std::cout <<
"-----------------------------------------------------------" << std::endl << std::endl;
5927 printf (
"File name: %s\n", this->one->_inputFileName.c_str() );
5929 printf (
"Cell dimmensions (A): %+.1f x %+.1f x %+.1f\n", this->origRanges[0], this->origRanges[1], this->origRanges[2] );
5930 printf (
"Cell U, V and W: %+.1f x %+.1f x %+.1f\n", this->origDims[0]+1, this->origDims[1]+1, this->origDims[2]+1 );
5932 printf (
"Min/Max density: %+.3f / %+.3f\n", this->minDensPreNorm, this->maxDensPreNorm );
5933 printf (
"Density mean: %+.3f\n", this->one->_mapMean );
5934 printf (
"Density std. dev: %+.3f\n", this->one->_mapSdev );
5936 printf (
"Min/Max norm density: %+.3f / %+.3f\n", this->minDensPostNorm, this->maxDensPostNorm );
5937 printf (
"Norm. density mean: %+.3f\n", this->postNormMean );
5938 printf (
"Norm. density std. dev: %+.3f\n", this->postNormSdev );
5940 printf (
"Total volume (A^3): %+.1f\n", this->totalVolume );
5941 printf (
"Mask volume (A^3): %+.1f\n", this->maskVolume );
5943 printf (
"Min/Max mask density: %+.3f / %+.3f\n", this->maskMin, this->maskMax );
5944 printf (
"Mask density mean: %+.3f\n", this->maskMean );
5945 printf (
"Mask density std. dev: %+.3f\n", this->maskSdev );
5947 printf (
"All density RMS: %+.3f\n", this->allDensityRMS );
5948 printf (
"Mask density RMS: %+.3f\n", this->maskDensityRMS );
5977 int newU, newV, newW, coordPos, arrayPos;
5981 std::vector< std::array<int,5> > clMap ( hlpU * hlpV * hlpW );
5982 std::array<int,5> hlpArr;
5983 for ( uIt = 0; uIt < hlpU; uIt++ )
5985 for ( vIt = 0; vIt < hlpV; vIt++ )
5987 for ( wIt = 0; wIt < hlpW; wIt++ )
5992 hlpArr[3] = wIt + hlpW * ( vIt + hlpV * uIt );
5994 if ( map[hlpArr[3]] <= threshold )
6002 clMap.at(hlpArr[3]) = hlpArr;
6008 std::vector< std::vector<int> > clusters;
6009 std::vector<int> unclNeigh;
6010 std::vector<int> clNeigh;
6011 std::vector<int> hlpVec;
6012 std::vector<int> XXXVec;
6014 bool allSame =
false;
6018 for ( uIt = 0; uIt < hlpU; uIt++ )
6020 for ( vIt = 0; vIt < hlpV; vIt++ )
6022 for ( wIt = 0; wIt < hlpW; wIt++ )
6025 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
6028 if ( clMap.at(arrayPos)[4] == -999 ) {
continue; }
6031 unclNeigh.clear ( );
6033 for (
int uCh = -1; uCh < 2; uCh++ )
6035 for (
int vCh = -1; vCh < 2; vCh++ )
6037 for (
int wCh = -1; wCh < 2; wCh++ )
6039 if ( ( uCh == 0 ) && ( vCh == 0 ) && ( wCh == 0 ) ) {
continue; }
6041 newU =
static_cast<int> ( uIt ) + uCh;
6042 newV =
static_cast<int> ( vIt ) + vCh;
6043 newW =
static_cast<int> ( wIt ) + wCh;
6045 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
6046 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
6047 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
6049 coordPos = newW + hlpW * ( newV + hlpV * newU );
6052 if ( clMap.at(coordPos)[4] == -999 ) {
continue; }
6055 if ( clMap.at(coordPos)[4] == -1 )
6057 unclNeigh.emplace_back ( coordPos );
6061 clNeigh.emplace_back ( coordPos );
6067 if ( ( unclNeigh.size() == 0 ) && ( clNeigh.size() == 0 ) )
6070 clMap.at(arrayPos)[4] = clusterNo;
6072 unclNeigh.emplace_back ( arrayPos );
6073 clusters.emplace_back ( unclNeigh );
6074 unclNeigh.clear ( );
6081 if ( ( unclNeigh.size() > 0 ) && ( clNeigh.size() == 0 ) )
6084 clMap.at(arrayPos)[4] = clusterNo;
6086 clNeigh.emplace_back ( arrayPos );
6087 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6089 clNeigh.emplace_back ( clMap.at(unclNeigh.at(iter))[3] );
6090 clMap.at(unclNeigh.at(iter))[4] = clusterNo;
6093 clusters.emplace_back ( clNeigh );
6101 if ( clNeigh.size() > 0 )
6104 hlpVal = clMap.at(clNeigh.at(0))[4];
6105 for (
unsigned int iter = 1; iter < static_cast<unsigned int> ( clNeigh.size() ); iter++ )
6107 if ( clMap.at(clNeigh.at(iter))[4] != hlpVal )
6116 if ( clMap.at(arrayPos)[4] == -1 )
6118 clMap.at(arrayPos)[4] = clMap.at(clNeigh.at(0))[4];
6119 clusters.at(clMap.at(clNeigh.at(0))[4]).emplace_back ( arrayPos );
6123 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6125 clusters.at(clMap.at(clNeigh.at(0))[4]).emplace_back ( clMap.at(unclNeigh.at(iter))[3] );
6126 clMap.at(unclNeigh.at(iter))[4] = clMap.at(clNeigh.at(0))[4];
6134 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clNeigh.size() ); iter++ )
6136 hlpVec.emplace_back ( clMap.at(clNeigh.at(iter))[4] );
6139 std::sort ( hlpVec.begin(), hlpVec.end() );
6140 hlpVec.erase ( std::unique( hlpVec.begin(), hlpVec.end() ), hlpVec.end() );
6142 minCl = hlpVec.at(0);
6145 if ( clMap.at(arrayPos)[4] == -1 )
6147 clMap.at(arrayPos)[4] = minCl;
6148 clusters.at(minCl).emplace_back ( arrayPos );
6152 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( unclNeigh.size() ); iter++ )
6154 clMap.at(unclNeigh.at(iter))[4] = minCl;
6155 clusters.at(minCl).emplace_back ( unclNeigh.at(iter) );
6159 for (
unsigned int iter = 1; iter < static_cast<unsigned int> ( hlpVec.size() ); iter++ )
6161 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clusters.at(hlpVec.at(iter)).size() ); it++ )
6163 clMap.at(clusters.at(hlpVec.at(iter)).at(it))[4] = minCl;
6164 clusters.at(minCl).emplace_back ( clusters.at(hlpVec.at(iter)).at(it) );
6166 clusters.at(hlpVec.at(iter)).clear();
6175 std::vector< std::array<double,3> > clVec;
6176 std::array<double,3> hArr;
6177 for (
unsigned int clIt = 0; clIt < static_cast<unsigned int> ( clusters.size() ); clIt++ )
6179 if ( clusters.at(clIt).size() > 1 )
6181 unsigned int minU = clMap.at(clusters.at(clIt).at(0))[0];
6182 unsigned int maxU = clMap.at(clusters.at(clIt).at(0))[0];
6183 unsigned int minV = clMap.at(clusters.at(clIt).at(0))[1];
6184 unsigned int maxV = clMap.at(clusters.at(clIt).at(0))[1];
6185 unsigned int minW = clMap.at(clusters.at(clIt).at(0))[2];
6186 unsigned int maxW = clMap.at(clusters.at(clIt).at(0))[2];
6187 for (
unsigned int el = 0; el < static_cast<unsigned int> ( clusters.at(clIt).size() ); el++ )
6189 minU = std::min ( minU, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[0] ) );
6190 maxU = std::max ( maxU, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[0] ) );
6191 minV = std::min ( minV, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[1] ) );
6192 maxV = std::max ( maxV, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[1] ) );
6193 minW = std::min ( minW, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[2] ) );
6194 maxW = std::max ( maxW, static_cast<unsigned int> ( clMap.at(clusters.at(clIt).at(el))[2] ) );
6196 double encVol = ( maxU - minU + 1 ) * ( maxV - minV + 1 ) * ( maxW - minW + 1 );
6197 hArr[0] = encVol /
static_cast<double> ( clusters.at(clIt).size() );
6198 hArr[1] =
static_cast<double> ( clusters.at(clIt).size() );
6200 clVec.emplace_back ( hArr );
6203 std::sort ( clVec.begin(), clVec.end(), [](
const std::array<double,3>& a,
const std::array<double,3>& b) {
return a[1] > b[1]; });
6205 std::vector<double> hlpVals;
6206 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( clVec.size() ); iter++ )
6208 hlpVals.emplace_back ( clVec.at(iter)[1] );
6211 double mean = std::accumulate ( hlpVals.begin(), hlpVals.end(), 0.0 ) / static_cast<double> ( hlpVals.size() );
6212 double sd = sqrt ( std::inner_product( hlpVals.begin(), hlpVals.end(), hlpVals.begin(), 0.0 ) / static_cast<double> ( hlpVals.size() ) - mean * mean );
6215 std::vector< std::array<double,3> > hVec;
6216 for (
double iter = 5.0; iter >= 0.0; iter = iter - 0.5 )
6218 thres = mean + ( iter * sd );
6221 for (
unsigned int it = 0; it < static_cast<unsigned int> ( clVec.size() ); it++ )
6223 if ( clVec.at(it)[1] >= thres )
6225 hArr[0] = clVec.at(it)[0];
6226 hArr[1] = clVec.at(it)[2];
6227 hVec.emplace_back ( hArr );
6231 if ( ( hVec.size() > std::max ( std::floor ( clVec.size() * 0.05 ), 10.0 ) ) && ( hVec.size() < clVec.size() ) )
6237 std::sort ( hVec.begin(), hVec.end(), [](
const std::array<double,3>& a,
const std::array<double,3>& b) {
return a[0] < b[0]; });
6238 std::vector< std::vector<int> > clusts;
6241 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6243 hlpVals.emplace_back ( hVec.at(iter)[0] );
6246 if ( hVec.size() == 0 )
6250 if ( hVec.size() < 5 )
6252 mean = hVec.at(hVec.size()-1)[0] + 0.0001;
6257 mean = std::accumulate ( hlpVals.begin(), hlpVals.end(), 0.0 ) / static_cast<double> ( hlpVals.size() );
6258 sd = sqrt ( std::inner_product( hlpVals.begin(), hlpVals.end(), hlpVals.begin(), 0.0 ) / static_cast<double> ( hlpVals.size() ) - mean * mean );
6261 for (
double it = 3.0; it >= 0.0; it = it - 0.25 )
6263 thres = mean - ( it * sd );
6268 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6270 thres = std::max ( hVec.at(iter)[0], thres );
6274 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hVec.size() ); iter++ )
6276 if ( hVec.at(iter)[0] <= thres )
6278 clusts.emplace_back ( clusters.at(hVec.at(iter)[1]) );
6282 if ( ( clusts.size() > 0 ) && ( clusts.size() < 5 ) )
6284 if ( ( clusts.size() ) < hVec.size() )
6286 if ( ( hVec.at(clusts.size()-1)[0] > 3.0 ) && ( ( 2.0 * hVec.at(clusts.size()-1)[0] ) < hVec.at(clusts.size())[0] ) )
6293 if ( ( clusts.size() > std::max ( std::floor ( hVec.size() * 0.1 ), 5.0 ) ) && ( clusts.size() < hVec.size() ) ) {
break; }
6317 if ( this->fragBoxSize <= 0.0 )
6319 std::cerr <<
"!!! ProSHADE ERROR !!! Tried to fragment the map to boxes of size " << this->fragBoxSize <<
" . Terminating..." << std::endl;
6323 std::stringstream hlpSS;
6324 hlpSS <<
"<font color=\"red\">" <<
"The box size to which the map should be fragmented in not in the allowed range ( " << this->fragBoxSize <<
" )" <<
"</font>";
6325 rvapi_set_text ( hlpSS.str().c_str(),
6340 std::cout <<
"-----------------------------------------------------------" << std::endl;
6341 std::cout <<
"| MAP FRAGMENTATION |" << std::endl;
6342 std::cout <<
"-----------------------------------------------------------" << std::endl << std::endl;
6346 std::vector< std::array<unsigned int,2> > XDim;
6347 std::vector< std::array<unsigned int,2> > YDim;
6348 std::vector< std::array<unsigned int,2> > ZDim;
6349 std::array<unsigned int,2> hlpArrX;
6350 std::array<unsigned int,2> hlpArrY;
6351 std::array<unsigned int,2> hlpArrZ;
6352 double maxMapAngPerIndex = std::max ( this->one->_xRange / static_cast<double> ( this->one->_maxMapU ),
6353 std::max ( this->one->_yRange / static_cast<double> ( this->one->_maxMapV ),
6354 this->one->_zRange / static_cast<double> ( this->one->_maxMapW ) ) );
6355 unsigned int boxDimInIndices =
static_cast<unsigned int> ( std::round ( this->fragBoxSize / maxMapAngPerIndex ) );
6356 if ( ( boxDimInIndices % 2 ) == 1 )
6359 boxDimInIndices += 1;
6363 if ( boxDimInIndices < 2 )
6365 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;
6369 std::stringstream hlpSS;
6370 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>";
6371 rvapi_set_text ( hlpSS.str().c_str(),
6383 if ( ( boxDimInIndices >= this->one->_maxMapU ) || ( boxDimInIndices >= this->one->_maxMapV ) || ( boxDimInIndices >= this->one->_maxMapW ) )
6385 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;
6389 std::stringstream hlpSS;
6390 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>";
6391 rvapi_set_text ( hlpSS.str().c_str(),
6405 for (
unsigned int xStart = 0; xStart <= ( this->one->_maxMapU - boxDimInIndices ); xStart += ( boxDimInIndices / 2 ) )
6407 hlpArrX[0] = xStart;
6408 hlpArrX[1] = xStart + boxDimInIndices;
6411 if ( ( xStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapU - boxDimInIndices ) )
6414 hlpArrX[1] = this->one->_maxMapU;
6417 for (
unsigned int yStart = 0; yStart <= ( this->one->_maxMapV - boxDimInIndices ); yStart += ( boxDimInIndices / 2 ) )
6419 hlpArrY[0] = yStart;
6420 hlpArrY[1] = yStart + boxDimInIndices;
6423 if ( ( yStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapV - boxDimInIndices ) )
6426 hlpArrY[1] = this->one->_maxMapV;
6429 for (
unsigned int zStart = 0; zStart <= ( this->one->_maxMapW - boxDimInIndices ); zStart += ( boxDimInIndices / 2 ) )
6431 hlpArrZ[0] = zStart;
6432 hlpArrZ[1] = zStart + boxDimInIndices;
6435 if ( ( zStart + ( boxDimInIndices / 2 ) ) > ( this->one->_maxMapW - boxDimInIndices ) )
6438 hlpArrZ[1] = this->one->_maxMapW;
6441 XDim.emplace_back ( hlpArrX );
6442 YDim.emplace_back ( hlpArrY );
6443 ZDim.emplace_back ( hlpArrZ );
6450 std::cout <<
">> Box borders generated." << std::endl;
6454 unsigned int noDensityPoints = 0;
6455 unsigned int arrayPos = 0;
6456 unsigned int hlpPos = 0;
6458 double boxVolume = 0.0;
6459 int newU, newV, newW;
6460 std::string fileName;
6462 for (
unsigned int boxIt = 0; boxIt < static_cast<unsigned int> ( XDim.size() ); boxIt++ )
6465 noDensityPoints = 0;
6466 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
6468 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
6470 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
6472 arrayPos = z + (this->one->_maxMapW+1) * ( y + (this->one->_maxMapV+1) * x );
6474 if ( this->one->_densityMapCor[arrayPos] > 0.0 )
6476 noDensityPoints += 1;
6483 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 );
6485 if ( ( static_cast<double> ( noDensityPoints ) / boxVolume ) > this->mapFragBoxFraction )
6488 fileName = this->mapFragName + std::to_string ( fileIter ) +
".map";
6489 this->fragFiles.emplace_back ( fileName );
6493 std::cout <<
">>>>> Writing out box " << fileIter-1 << std::endl;
6497 float *boxMap =
nullptr;
6498 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 ) );
6499 if ( boxMap ==
nullptr )
6501 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot allocate memory for map data. Terminating... " << std::endl;
6505 std::stringstream hlpSS;
6506 hlpSS <<
"<font color=\"red\">" <<
"Cannot allocate memory. Could you have run out of memory?" <<
"</font>";
6507 rvapi_set_text ( hlpSS.str().c_str(),
6520 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
6522 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
6524 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
6526 arrayPos = z + (this->one->_maxMapW+1) * ( y + (this->one->_maxMapV+1) * x );
6528 newU = x - XDim.at(boxIt)[0];
6529 newV = y - YDim.at(boxIt)[0];
6530 newW = z - ZDim.at(boxIt)[0];
6531 hlpPos = newW + (ZDim.at(boxIt)[1]-ZDim.at(boxIt)[0]) * ( newV + (YDim.at(boxIt)[1]-YDim.at(boxIt)[0]) * newU );
6533 boxMap[hlpPos] = this->one->_densityMapCor[arrayPos];
6538 float xFrom = XDim.at(boxIt)[0] + this->one->_xFrom;
6539 float xTo = XDim.at(boxIt)[1] + this->one->_xFrom - 1;
6540 float yFrom = YDim.at(boxIt)[0] + this->one->_yFrom;
6541 float yTo = YDim.at(boxIt)[1] + this->one->_yFrom - 1;
6542 float zFrom = ZDim.at(boxIt)[0] + this->one->_zFrom;
6543 float zTo = ZDim.at(boxIt)[1] + this->one->_zFrom - 1;
6545 this->one->writeMap ( fileName.c_str(),
6554 ( this->one->_xSamplingRate * ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) ),
6555 ( this->one->_ySamplingRate * ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) ),
6556 ( this->one->_zSamplingRate * ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) ) );
6567 std::cout <<
">> " << fileIter <<
" boxes written in " << this->mapFragName <<
"xx ." << std::endl << std::endl;
6571 std::cout <<
">> No boxes conform to your criteria. NO BOXES WRITTEN." << std::endl << std::endl;
6574 if ( fileIter == 0 )
6576 std::cout <<
"!!! ProSHADE WARNING !!! No map fragments produced - no box passed the required criteria." << std::endl << std::endl;
6580 std::stringstream hlpSS;
6581 hlpSS <<
"<font color=\"orange\">" <<
"No map fragments produced - no box passed the required criteria.." <<
"</font>";
6582 rvapi_set_text ( hlpSS.str().c_str(),
6594 this->fragFilesExist =
true;
6617 double *zTranslate )
6625 unsigned int bandwidth1 = settings->
bandwidth;
6626 unsigned int bandwidth2 = settings->
bandwidth;
6627 unsigned int theta1 = settings->
theta;
6628 unsigned int theta2 = settings->
theta;
6629 unsigned int phi1 = settings->
phi;
6630 unsigned int phi2 = settings->
phi;
6650 std::cout <<
"Read in the first half map." << std::endl;
6655 std::stringstream hlpSS;
6656 hlpSS <<
"<font color=\"green\">" <<
"Read in the first half map." <<
"</font>";
6657 rvapi_set_text ( hlpSS.str().c_str(),
6683 std::cout <<
"Read in the second half map." << std::endl;
6688 std::stringstream hlpSS;
6689 hlpSS <<
"<font color=\"green\">" <<
"Read in the second half map." <<
"</font>";
6690 rvapi_set_text ( hlpSS.str().c_str(),
6701 bool sizeAndSampleIdentical =
true;
6702 if ( ( halfMap1->_xRange != halfMap2->_xRange ) || ( halfMap1->_yRange != halfMap2->_yRange ) || ( halfMap1->_zRange != halfMap2->_zRange ) )
6704 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;
6708 std::stringstream hlpSS;
6709 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>";
6710 rvapi_set_text ( hlpSS.str().c_str(),
6720 sizeAndSampleIdentical =
false;
6723 if ( ( halfMap1->_maxMapU != halfMap2->_maxMapU ) || ( halfMap1->_maxMapV != halfMap2->_maxMapV ) || ( halfMap1->_maxMapW != halfMap2->_maxMapW ) )
6725 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;
6729 std::stringstream hlpSS;
6730 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>";
6731 rvapi_set_text ( hlpSS.str().c_str(),
6741 sizeAndSampleIdentical =
false;
6744 if ( !sizeAndSampleIdentical )
6748 std::cout <<
"Starting the re-sampling and re-sizing procedure. This may take some time." << std::endl;
6753 std::stringstream hlpSS;
6754 hlpSS <<
"<font color=\"green\">" <<
"Starting the re-sampling and re-sizing procedure. This may take some time." <<
"</font>";
6755 rvapi_set_text ( hlpSS.str().c_str(),
6766 halfMap1->_densityMapCor =
new double[(halfMap1->_maxMapU+1)*(halfMap1->_maxMapV+1)*(halfMap1->_maxMapW+1)];
6767 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (halfMap1->_maxMapU+1)*(halfMap1->_maxMapV+1)*(halfMap1->_maxMapW+1) ); iter++ )
6769 halfMap1->_densityMapCor[iter] = halfMap1->_densityMapMap[iter];
6771 delete[] halfMap1->_densityMapMap;
6772 halfMap1->_densityMapMap =
nullptr;
6774 halfMap2->_densityMapCor =
new double[(halfMap2->_maxMapU+1)*(halfMap2->_maxMapV+1)*(halfMap2->_maxMapW+1)];
6775 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( (halfMap2->_maxMapU+1)*(halfMap2->_maxMapV+1)*(halfMap2->_maxMapW+1) ); iter++ )
6777 halfMap2->_densityMapCor[iter] = halfMap2->_densityMapMap[iter];
6779 delete[] halfMap2->_densityMapMap;
6780 halfMap2->_densityMapMap =
nullptr;
6787 std::max ( glInteg1, glInteg2 ),
6789 std::array<double,4> translationVec;
6790 double xMapMov, yMapMov, zMapMov;
6800 if ( sizeAndSampleIdentical )
6802 rvapi_add_section (
"h1Header",
6803 "Half Map 1 Header",
6813 rvapi_add_section (
"h1Header",
6814 "Half Map 1 Header (after re-sampling)",
6825 std::stringstream hlpSS;
6826 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
6827 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
6833 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length(),
6834 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length(),
6835 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ) );
6836 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length(),
6837 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length(),
6838 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ) );
6839 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length(),
6840 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length(),
6841 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ) );
6842 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length(),
6843 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length(),
6844 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ) );
6845 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
6846 if ( spacer < 5 ) { spacer = 5; }
6848 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap1->_maxMapU+1 );
6849 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++ )
6855 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapV+1 );
6856 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++ )
6862 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapW+1 );
6863 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++ )
6869 rvapi_set_text ( hlpSS.str().c_str(),
6877 hlpSS.str ( std::string ( ) );
6878 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
6879 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
6884 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xFrom;
6885 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length() ); iter++ )
6891 hlpSS << std::showpos << halfMap1->_xTo;
6892 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length() ); iter++ )
6898 hlpSS << std::showpos << halfMap1->_yFrom;
6899 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length() ); iter++ )
6905 hlpSS << std::showpos << halfMap1->_yTo;
6906 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length() ); iter++ )
6912 hlpSS << std::showpos <<
" " << halfMap1->_zFrom;
6913 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ); iter++ )
6919 hlpSS << std::showpos << halfMap1->_zTo;
6920 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ); iter++ )
6926 rvapi_set_text ( hlpSS.str().c_str(),
6934 hlpSS.str ( std::string ( ) );
6935 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
6936 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
6941 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xRange;
6942 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length() ); iter++ )
6948 hlpSS << std::showpos << halfMap1->_yRange;
6949 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length() ); iter++ )
6955 hlpSS << std::showpos << halfMap1->_zRange;
6956 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ); iter++ )
6962 rvapi_set_text ( hlpSS.str().c_str(),
6970 hlpSS.str ( std::string ( ) );
6971 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
6972 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
6977 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
6978 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
6984 hlpSS << std::showpos << 90.0;
6985 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
6991 hlpSS << std::showpos << 90.0;
6992 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
6998 rvapi_set_text ( hlpSS.str().c_str(),
7006 hlpSS.str ( std::string ( ) );
7007 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
7008 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7013 std::string hlpAO = settings->
axisOrder;
7014 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
7015 hlpSS <<
" " << hlpAO;
7016 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
7022 rvapi_set_text ( hlpSS.str().c_str(),
7034 if ( sizeAndSampleIdentical )
7036 rvapi_add_section (
"h2Header",
7037 "Half Map 2 Header",
7047 rvapi_add_section (
"h2Header",
7048 "Half Map 2 Header (after re-sampling)",
7059 std::stringstream hlpSS;
7060 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7061 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7067 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length(),
7068 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length(),
7069 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ) );
7070 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length(),
7071 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length(),
7072 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ) );
7073 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length(),
7074 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length(),
7075 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ) );
7076 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length(),
7077 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length(),
7078 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ) );
7079 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
7080 if ( spacer < 5 ) { spacer = 5; }
7082 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap2->_maxMapU+1 );
7083 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++ )
7089 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapV+1 );
7090 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++ )
7096 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapW+1 );
7097 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++ )
7103 rvapi_set_text ( hlpSS.str().c_str(),
7111 hlpSS.str ( std::string ( ) );
7112 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
7113 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7118 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xFrom;
7119 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length() ); iter++ )
7125 hlpSS << std::showpos << halfMap2->_xTo;
7126 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length() ); iter++ )
7132 hlpSS << std::showpos << halfMap2->_yFrom;
7133 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length() ); iter++ )
7139 hlpSS << std::showpos << halfMap2->_yTo;
7140 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length() ); iter++ )
7146 hlpSS << std::showpos <<
" " << halfMap2->_zFrom;
7147 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ); iter++ )
7153 hlpSS << std::showpos << halfMap2->_zTo;
7154 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ); iter++ )
7160 rvapi_set_text ( hlpSS.str().c_str(),
7168 hlpSS.str ( std::string ( ) );
7169 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
7170 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7175 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xRange;
7176 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length() ); iter++ )
7182 hlpSS << std::showpos << halfMap2->_yRange;
7183 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length() ); iter++ )
7189 hlpSS << std::showpos << halfMap2->_zRange;
7190 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ); iter++ )
7196 rvapi_set_text ( hlpSS.str().c_str(),
7204 hlpSS.str ( std::string ( ) );
7205 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
7206 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7211 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
7212 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7218 hlpSS << std::showpos << 90.0;
7219 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7225 hlpSS << std::showpos << 90.0;
7226 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7232 rvapi_set_text ( hlpSS.str().c_str(),
7240 hlpSS.str ( std::string ( ) );
7241 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
7242 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7247 std::string hlpAO = settings->
axisOrder;
7248 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
7249 hlpSS <<
" " << hlpAO;
7250 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
7256 rvapi_set_text ( hlpSS.str().c_str(),
7267 fftw_complex *tmpOutA;
7268 fftw_complex *tmpInA;
7269 fftw_complex *tmpOutB;
7270 fftw_complex *tmpInB;
7274 int hlpU = halfMap1->_maxMapU + 1;
7275 int hlpV = halfMap1->_maxMapV + 1;
7276 int hlpW = halfMap1->_maxMapW + 1;
7279 tmpInA =
new fftw_complex[hlpU * hlpV * hlpW];
7280 tmpOutA =
new fftw_complex[hlpU * hlpV * hlpW];
7281 tmpInB =
new fftw_complex[hlpU * hlpV * hlpW];
7282 tmpOutB =
new fftw_complex[hlpU * hlpV * hlpW];
7285 pA = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpInA, tmpOutA, FFTW_FORWARD, FFTW_ESTIMATE );
7286 pB = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, tmpInB, tmpOutB, FFTW_FORWARD, FFTW_ESTIMATE );
7289 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
7291 if ( halfMap1->_densityMapCor[iter] == halfMap1->_densityMapCor[iter] )
7294 tmpInA[iter][0] = halfMap1->_densityMapCor[iter];
7295 tmpInA[iter][1] = 0.0;
7300 tmpInA[iter][0] = 0.0;
7301 tmpInA[iter][1] = 0.0;
7304 if ( halfMap2->_densityMapCor[iter] == halfMap2->_densityMapCor[iter] )
7307 tmpInB[iter][0] = halfMap2->_densityMapCor[iter];
7308 tmpInB[iter][1] = 0.0;
7313 tmpInB[iter][0] = 0.0;
7314 tmpInB[iter][1] = 0.0;
7319 fftw_execute ( pA );
7320 fftw_execute ( pB );
7321 fftw_destroy_plan ( pA );
7322 fftw_destroy_plan ( pB );
7325 fftw_complex* maskDataA =
new fftw_complex [ hlpU * hlpV * hlpW ];
7326 fftw_complex* maskDataInvA =
new fftw_complex [ hlpU * hlpV * hlpW ];
7327 fftw_complex* maskDataB =
new fftw_complex [ hlpU * hlpV * hlpW ];
7328 fftw_complex* maskDataInvB =
new fftw_complex [ hlpU * hlpV * hlpW ];
7333 unsigned int arrayPos = 0;
7334 double normFactor = (hlpU * hlpV * hlpW);
7337 double mag, phase, S;
7340 fftw_plan pMaskInvA = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInvA, maskDataA, FFTW_BACKWARD, FFTW_ESTIMATE );
7341 fftw_plan pMaskInvB = fftw_plan_dft_3d ( hlpU, hlpV, hlpW, maskDataInvB, maskDataB, FFTW_BACKWARD, FFTW_ESTIMATE );
7343 for ( uIt = 0; uIt < hlpU; uIt++ )
7345 for ( vIt = 0; vIt < hlpV; vIt++ )
7347 for ( wIt = 0; wIt < hlpW; wIt++ )
7351 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7352 real = tmpOutA[arrayPos][0];
7353 imag = tmpOutA[arrayPos][1];
7356 if ( uIt > (hlpU / 2) ) { h = uIt - hlpU; }
else { h = uIt; }
7357 if ( vIt > (hlpV / 2) ) { k = vIt - hlpV; }
else { k = vIt; }
7358 if ( wIt > (hlpW / 2) ) { l = wIt - hlpW; }
else { l = wIt; }
7361 S = ( pow( static_cast<double> ( h ) / halfMap1->_xRange, 2.0 ) +
7362 pow( static_cast<double> ( k ) / halfMap1->_yRange, 2.0 ) +
7363 pow( static_cast<double> ( l ) / halfMap1->_zRange, 2.0 ) );
7364 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
7365 phase = atan2 ( imag, real );
7368 maskDataInvA[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
7369 maskDataInvA[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
7373 real = tmpOutB[arrayPos][0];
7374 imag = tmpOutB[arrayPos][1];
7377 S = ( pow( static_cast<double> ( h ) / halfMap2->_xRange, 2.0 ) +
7378 pow( static_cast<double> ( k ) / halfMap2->_yRange, 2.0 ) +
7379 pow( static_cast<double> ( l ) / halfMap2->_zRange, 2.0 ) );
7380 mag = sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( ( bFacChange * S ) / 4.0 ) );
7381 phase = atan2 ( imag, real );
7384 maskDataInvB[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
7385 maskDataInvB[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
7391 fftw_execute ( pMaskInvA );
7392 fftw_execute ( pMaskInvB );
7393 fftw_destroy_plan ( pMaskInvA );
7394 fftw_destroy_plan ( pMaskInvB );
7395 delete[] maskDataInvA;
7396 delete[] maskDataInvB;
7402 std::cout <<
">>>>> Map blurring complete." << std::endl;
7407 std::stringstream hlpSS;
7408 hlpSS <<
"<font color=\"green\">" <<
"Map blurring complete." <<
"</font>";
7409 rvapi_set_text ( hlpSS.str().c_str(),
7420 double mapThresholdPlusA = 0.0;
7421 double mapThresholdPlusB = 0.0;
7422 unsigned int hlpIt = 0;
7423 std::vector<double> maskValsA ( hlpU * hlpV * hlpW );
7424 std::vector<double> maskValsB ( hlpU * hlpV * hlpW );
7426 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; } } }
7428 unsigned int medianPos =
static_cast<unsigned int> ( maskValsA.size() / 2 );
7429 std::sort ( maskValsA.begin(), maskValsA.end() );
7430 std::sort ( maskValsB.begin(), maskValsB.end() );
7432 double interQuartileRangeA = maskValsA.at(medianPos+(medianPos/2)) - maskValsA.at(medianPos-(medianPos/2));
7433 mapThresholdPlusA = maskValsA.at(medianPos+(medianPos/2)) + ( interQuartileRangeA * settings->
noIQRsFromMap );
7435 double interQuartileRangeB = maskValsB.at(medianPos+(medianPos/2)) - maskValsB.at(medianPos-(medianPos/2));
7436 mapThresholdPlusB = maskValsB.at(medianPos+(medianPos/2)) + ( interQuartileRangeB * settings->
noIQRsFromMap );
7438 maskValsA.clear ( );
7439 maskValsB.clear ( );
7442 for ( uIt = 0; uIt < hlpU; uIt++ )
7444 for ( vIt = 0; vIt < hlpV; vIt++ )
7446 for ( wIt = 0; wIt < hlpW; wIt++ )
7449 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7452 if ( mapThresholdPlusA >= maskDataA[arrayPos][0] )
7454 tmpInA[arrayPos][0] = 0.0;
7456 if ( mapThresholdPlusB >= maskDataB[arrayPos][0] )
7458 tmpInB[arrayPos][0] = 0.0;
7470 std::stringstream hlpSS;
7471 hlpSS <<
"<font color=\"green\">" <<
"Map masking complete." <<
"</font>";
7472 rvapi_set_text ( hlpSS.str().c_str(),
7484 bool atLeastSingleValueA =
false;
7485 bool atLeastSingleValueB =
false;
7486 for ( uIt = 0; uIt < hlpU; uIt++ )
7488 for ( vIt = 0; vIt < hlpV; vIt++ )
7490 for ( wIt = 0; wIt < hlpW; wIt++ )
7493 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
7495 if ( !atLeastSingleValueA ) {
if ( tmpInA[arrayPos][0] > 0.0 ) { atLeastSingleValueA =
true; } }
7496 if ( !atLeastSingleValueB ) {
if ( tmpInB[arrayPos][0] > 0.0 ) { atLeastSingleValueB =
true; } }
7501 if ( !atLeastSingleValueA || !atLeastSingleValueB )
7503 printf (
"!!! ProSHADE ERROR !!! The masking procedure failed to detect any significant density in the map!\n" );
7507 std::stringstream hlpSS;
7508 hlpSS <<
"<font color=\"red\">" <<
"The masking procedure failed to detect any significant density in the map. Please consider changing the blurring coefficient value." <<
"</font>";
7509 rvapi_set_text ( hlpSS.str().c_str(),
7531 for ( uIt = 0; uIt < hlpU; uIt++ )
7533 for ( vIt = 0; vIt < hlpV; vIt++ )
7535 for ( wIt = 0; wIt < hlpW; wIt++ )
7537 arrPos = wIt + hlpW * ( vIt + hlpV * uIt );
7539 if ( tmpInA[arrPos][0] > 0.0 )
7541 maxX = std::max ( maxX, uIt );
7542 minX = std::min ( minX, uIt );
7543 maxY = std::max ( maxY, vIt );
7544 minY = std::min ( minY, vIt );
7545 maxZ = std::max ( maxZ, wIt );
7546 minZ = std::min ( minZ, wIt );
7548 if ( tmpInB[arrPos][0] > 0.0 )
7550 maxX = std::max ( maxX, uIt );
7551 minX = std::min ( minX, uIt );
7552 maxY = std::max ( maxY, vIt );
7553 minY = std::min ( minY, vIt );
7554 maxZ = std::max ( maxZ, wIt );
7555 minZ = std::min ( minZ, wIt );
7565 maxX += std::ceil ( 7.5 / halfMap1->_xSamplingRate );
7566 maxY += std::ceil ( 7.5 / halfMap1->_ySamplingRate );
7567 maxZ += std::ceil ( 7.5 / halfMap1->_zSamplingRate );
7568 minX -= std::ceil ( 7.5 / halfMap1->_xSamplingRate );
7569 minY -= std::ceil ( 7.5 / halfMap1->_ySamplingRate );
7570 minZ -= std::ceil ( 7.5 / halfMap1->_zSamplingRate );
7572 if ( maxX > static_cast<int> ( halfMap1->_maxMapU ) ) { maxX = halfMap1->_maxMapU; }
7573 if ( maxY > static_cast<int> ( halfMap1->_maxMapV ) ) { maxY = halfMap1->_maxMapV; }
7574 if ( maxZ > static_cast<int> ( halfMap1->_maxMapW ) ) { maxZ = halfMap1->_maxMapW; }
7575 if ( minX < 0 ) { minX = 0; }
7576 if ( minY < 0 ) { minY = 0; }
7577 if ( minZ < 0 ) { minZ = 0; }
7582 minX = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7583 minY = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7584 minZ = std::max ( 0, std::min ( minX, std::min ( minY, minZ ) ) );
7585 maxX = std::min ( hlpU, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7586 maxY = std::min ( hlpV, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7587 maxZ = std::min ( hlpW, std::max ( maxX , std::max ( maxY , maxZ ) ) );
7589 if ( ( maxX != maxY ) || ( maxX != maxZ ) || ( maxY != maxZ ) )
7591 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;
7595 std::stringstream hlpSS;
7596 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>";
7597 rvapi_set_text ( hlpSS.str().c_str(),
7610 int xDim = 1 + maxX - minX;
7611 int yDim = 1 + maxY - minY;
7612 int zDim = 1 + maxZ - minZ;
7615 double* newHalf1Map =
new double[xDim * yDim * zDim];
7616 double* newHalf2Map =
new double[xDim * yDim * zDim];
7618 for (
int xIt = 0; xIt < hlpU; xIt++ )
7620 for (
int yIt = 0; yIt < hlpV; yIt++ )
7622 for (
int zIt = 0; zIt < hlpW; zIt++ )
7624 if ( ( xIt < minX ) || ( xIt > maxX ) ) {
continue; }
7625 if ( ( yIt < minY ) || ( yIt > maxY ) ) {
continue; }
7626 if ( ( zIt < minZ ) || ( zIt > maxZ ) ) {
continue; }
7628 arrPos = zIt + hlpW * ( yIt + hlpV * xIt );
7629 hlpPos = (zIt - minZ) + zDim * ( (yIt - minY) + yDim * (xIt - minX) );
7631 newHalf1Map[hlpPos] = halfMap1->_densityMapCor[arrPos];
7632 newHalf2Map[hlpPos] = halfMap2->_densityMapCor[arrPos];
7638 delete[] halfMap1->_densityMapCor;
7639 delete[] halfMap2->_densityMapCor;
7640 halfMap1->_densityMapCor =
new double[xDim * yDim * zDim];
7641 halfMap2->_densityMapCor =
new double[xDim * yDim * zDim];
7642 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( xDim * yDim * zDim ); iter++ )
7644 halfMap1->_densityMapCor[iter] = newHalf1Map[iter];
7645 halfMap2->_densityMapCor[iter] = newHalf2Map[iter];
7647 delete[] newHalf1Map;
7648 delete[] newHalf2Map;
7652 std::stringstream hlpSS;
7653 hlpSS <<
"<font color=\"green\">" <<
"Half maps re-boxed." <<
"</font>";
7654 rvapi_set_text ( hlpSS.str().c_str(),
7665 int oDimX1 = halfMap1->_maxMapU;
7666 int oDimY1 = halfMap1->_maxMapV;
7667 int oDimZ1 = halfMap1->_maxMapW;
7669 int oDimX2 = halfMap2->_maxMapU;
7670 int oDimY2 = halfMap2->_maxMapV;
7671 int oDimZ2 = halfMap2->_maxMapW;
7673 halfMap1->_maxMapU = xDim;
7674 halfMap1->_maxMapV = yDim;
7675 halfMap1->_maxMapW = zDim;
7677 halfMap1->_xTo = maxX + halfMap1->_xFrom;
7678 halfMap1->_yTo = maxY + halfMap1->_yFrom;
7679 halfMap1->_zTo = maxZ + halfMap1->_zFrom;
7681 halfMap1->_xFrom = minX + halfMap1->_xFrom;
7682 halfMap1->_yFrom = minY + halfMap1->_yFrom;
7683 halfMap1->_zFrom = minZ + halfMap1->_zFrom;
7685 halfMap1->_xRange = xDim * halfMap1->_xSamplingRate;
7686 halfMap1->_yRange = yDim * halfMap1->_ySamplingRate;
7687 halfMap1->_zRange = zDim * halfMap1->_zSamplingRate;
7689 halfMap2->_maxMapU = xDim;
7690 halfMap2->_maxMapV = yDim;
7691 halfMap2->_maxMapW = zDim;
7693 halfMap2->_xTo = maxX + halfMap2->_xFrom;
7694 halfMap2->_yTo = maxY + halfMap2->_yFrom;
7695 halfMap2->_zTo = maxZ + halfMap2->_zFrom;
7697 halfMap2->_xFrom = minX + halfMap2->_xFrom;
7698 halfMap2->_yFrom = minY + halfMap2->_yFrom;
7699 halfMap2->_zFrom = minZ + halfMap2->_zFrom;
7701 halfMap2->_xRange = xDim * halfMap2->_xSamplingRate;
7702 halfMap2->_yRange = yDim * halfMap2->_ySamplingRate;
7703 halfMap2->_zRange = zDim * halfMap2->_zSamplingRate;
7708 rvapi_add_section (
"h1OutHeader",
7709 "Half Map 1 Re-boxed Header",
7719 std::stringstream hlpSS;
7720 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7721 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7727 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapU+1 ), prec ).length(),
7728 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapV+1 ), prec ).length(),
7729 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap1->_maxMapW+1 ), prec ).length() ) );
7730 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length(),
7731 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length(),
7732 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ) );
7733 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length(),
7734 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length(),
7735 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ) );
7736 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length(),
7737 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length(),
7738 ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ) );
7739 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
7740 if ( spacer < 5 ) { spacer = 5; }
7742 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap1->_maxMapU+1 );
7743 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++ )
7749 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapV+1 );
7750 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++ )
7756 hlpSS << std::showpos << static_cast<int> ( halfMap1->_maxMapW+1 );
7757 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++ )
7763 rvapi_set_text ( hlpSS.str().c_str(),
7771 hlpSS.str ( std::string ( ) );
7772 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
7773 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7778 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xFrom;
7779 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xFrom, prec ).length() ); iter++ )
7785 hlpSS << std::showpos << halfMap1->_xTo;
7786 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xTo, prec ).length() ); iter++ )
7792 hlpSS << std::showpos << halfMap1->_yFrom;
7793 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yFrom, prec ).length() ); iter++ )
7799 hlpSS << std::showpos << halfMap1->_yTo;
7800 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yTo, prec ).length() ); iter++ )
7806 hlpSS << std::showpos <<
" " << halfMap1->_zFrom;
7807 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zFrom, prec ).length() ); iter++ )
7813 hlpSS << std::showpos << halfMap1->_zTo;
7814 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zTo, prec ).length() ); iter++ )
7820 rvapi_set_text ( hlpSS.str().c_str(),
7828 hlpSS.str ( std::string ( ) );
7829 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
7830 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7835 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap1->_xRange;
7836 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_xRange, prec ).length() ); iter++ )
7842 hlpSS << std::showpos << halfMap1->_yRange;
7843 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_yRange, prec ).length() ); iter++ )
7849 hlpSS << std::showpos << halfMap1->_zRange;
7850 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap1->_zRange, prec ).length() ); iter++ )
7856 rvapi_set_text ( hlpSS.str().c_str(),
7864 hlpSS.str ( std::string ( ) );
7865 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
7866 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7871 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
7872 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7878 hlpSS << std::showpos << 90.0;
7879 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7885 hlpSS << std::showpos << 90.0;
7886 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
7892 rvapi_set_text ( hlpSS.str().c_str(),
7900 hlpSS.str ( std::string ( ) );
7901 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
7902 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7907 std::string hlpAO = settings->
axisOrder;
7908 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
7909 hlpSS <<
" " << hlpAO;
7910 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
7916 rvapi_set_text ( hlpSS.str().c_str(),
7928 rvapi_add_section (
"h2OutHeader",
7929 "Half Map 2 Re-boxed Header",
7939 std::stringstream hlpSS;
7940 hlpSS <<
"<pre><b>" <<
"Rows, Columns and Sections sizes: " <<
"</b>";
7941 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7947 int UVWMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapU+1 ), prec ).length(),
7948 std::max ( ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapV+1 ), prec ).length(),
7949 ProSHADE_internal_misc::to_string_with_precision ( static_cast<int> ( halfMap2->_maxMapW+1 ), prec ).length() ) );
7950 int FMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length(),
7951 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length(),
7952 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ) );
7953 int TMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length(),
7954 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length(),
7955 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ) );
7956 int CDMAX = std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length(),
7957 std::max ( ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length(),
7958 ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ) );
7959 int spacer = std::max ( UVWMAX, std::max ( FMAX, std::max ( TMAX, CDMAX ) ) );
7960 if ( spacer < 5 ) { spacer = 5; }
7962 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " <<
static_cast<int> ( halfMap2->_maxMapU+1 );
7963 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++ )
7969 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapV+1 );
7970 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++ )
7976 hlpSS << std::showpos << static_cast<int> ( halfMap2->_maxMapW+1 );
7977 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++ )
7983 rvapi_set_text ( hlpSS.str().c_str(),
7991 hlpSS.str ( std::string ( ) );
7992 hlpSS <<
"<pre><b>" <<
"Start and stop points on columns, rows, sections: " <<
"</b>";
7993 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
7998 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xFrom;
7999 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xFrom, prec ).length() ); iter++ )
8005 hlpSS << std::showpos << halfMap2->_xTo;
8006 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xTo, prec ).length() ); iter++ )
8012 hlpSS << std::showpos << halfMap2->_yFrom;
8013 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yFrom, prec ).length() ); iter++ )
8019 hlpSS << std::showpos << halfMap2->_yTo;
8020 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yTo, prec ).length() ); iter++ )
8026 hlpSS << std::showpos <<
" " << halfMap2->_zFrom;
8027 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zFrom, prec ).length() ); iter++ )
8033 hlpSS << std::showpos << halfMap2->_zTo;
8034 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zTo, prec ).length() ); iter++ )
8040 rvapi_set_text ( hlpSS.str().c_str(),
8048 hlpSS.str ( std::string ( ) );
8049 hlpSS <<
"<pre><b>" <<
"Cell dimensions (Angstrom): " <<
"</b>";
8050 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8055 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << halfMap2->_xRange;
8056 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_xRange, prec ).length() ); iter++ )
8062 hlpSS << std::showpos << halfMap2->_yRange;
8063 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_yRange, prec ).length() ); iter++ )
8069 hlpSS << std::showpos << halfMap2->_zRange;
8070 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( halfMap2->_zRange, prec ).length() ); iter++ )
8076 rvapi_set_text ( hlpSS.str().c_str(),
8084 hlpSS.str ( std::string ( ) );
8085 hlpSS <<
"<pre><b>" <<
"Cell angles (Degrees): " <<
"</b>";
8086 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8091 hlpSS << std::showpos << std::setprecision ( prec ) <<
" " << 90.0;
8092 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8098 hlpSS << std::showpos << 90.0;
8099 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8105 hlpSS << std::showpos << 90.0;
8106 for (
int iter = 0; iter < static_cast<int> ( spacer - ProSHADE_internal_misc::to_string_with_precision ( 90.0, prec ).length() ); iter++ )
8112 rvapi_set_text ( hlpSS.str().c_str(),
8120 hlpSS.str ( std::string ( ) );
8121 hlpSS <<
"<pre><b>" <<
"Fast, medium, slow axes: " <<
"</b>";
8122 for (
int iter = static_cast<int> ( hlpSS.str().length() ); iter < 70; iter++ )
8127 std::string hlpAO = settings->
axisOrder;
8128 std::transform ( hlpAO.begin(), hlpAO.end(), hlpAO.begin(), ::toupper);
8129 hlpSS <<
" " << hlpAO;
8130 for (
int iter = 0; iter < static_cast<int> ( spacer - 1 ); iter++ )
8136 rvapi_set_text ( hlpSS.str().c_str(),
8147 std::stringstream ss;
8149 halfMap1->writeMap ( ss.str(), halfMap1->_densityMapCor );
8151 ss.str( std::string ( ) );
8153 halfMap2->writeMap ( ss.str(), halfMap2->_densityMapCor );
8157 std::stringstream hlpSS;
8158 hlpSS <<
"<font color=\"green\">" <<
"Half maps saved." <<
"</font>";
8159 rvapi_set_text ( hlpSS.str().c_str(),
8171 rvapi_add_section (
"ResultsSection",
8181 std::stringstream hlpSS;
8182 hlpSS <<
"<pre><b>" <<
"The re-boxed structures are available at: </b>" << settings->
clearMapFile <<
"_half1.map" <<
"</pre>";
8183 rvapi_set_text ( hlpSS.str().c_str(),
8190 hlpSS.str ( std::string ( ) );
8191 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << settings->
clearMapFile <<
"_half2.map" <<
"</pre>";
8192 rvapi_set_text ( hlpSS.str().c_str(),
8199 hlpSS.str ( std::string ( ) );
8200 hlpSS <<
"<pre><b>" <<
"Original structure dims: </b>" << oDimX1+1 <<
" x " << oDimY1+1 <<
" x " << oDimZ1+1 <<
"</pre>";
8201 rvapi_set_text ( hlpSS.str().c_str(),
8208 hlpSS.str ( std::string ( ) );
8209 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << oDimX2+1 <<
" x " << oDimY2+1 <<
" x " << oDimZ2+1 <<
"</pre>";
8210 rvapi_set_text ( hlpSS.str().c_str(),
8217 hlpSS.str ( std::string ( ) );
8218 hlpSS <<
"<pre><b>" <<
"Re-boxed structure dims: </b>" << halfMap1->_maxMapU <<
" x " << halfMap1->_maxMapV <<
" x " << halfMap1->_maxMapW <<
"</pre>";
8219 rvapi_set_text ( hlpSS.str().c_str(),
8226 hlpSS.str ( std::string ( ) );
8227 hlpSS <<
"<pre><b>" <<
" ... and : </b>" << halfMap2->_maxMapU <<
" x " << halfMap2->_maxMapV <<
" x " << halfMap2->_maxMapW <<
"</pre>";
8228 rvapi_set_text ( hlpSS.str().c_str(),
8235 hlpSS.str ( std::string ( ) );
8236 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>";
8237 rvapi_set_text ( hlpSS.str().c_str(),
8244 hlpSS.str ( std::string ( ) );
8245 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>";
8246 rvapi_set_text ( hlpSS.str().c_str(),
8283 if ( !this->_densityMapComputed )
8285 std::cerr <<
"!!! ProSHADE ERROR !!! Tried to fragment map without first computing it. Terminating..." << std::endl;
8289 std::stringstream hlpSS;
8290 hlpSS <<
"<font color=\"red\">" <<
"Tried to fragment map without first computing it. This looks like an internal bug - please report this case." <<
"</font>";
8291 rvapi_set_text ( hlpSS.str().c_str(),
8306 std::cout <<
">> Fragmenting map." << std::endl;
8310 std::vector<ProSHADE_data*> ret;
8311 std::vector< std::array<unsigned int,2> > XDim;
8312 std::vector< std::array<unsigned int,2> > YDim;
8313 std::vector< std::array<unsigned int,2> > ZDim;
8314 std::array<unsigned int,2> hlpArrX;
8315 std::array<unsigned int,2> hlpArrY;
8316 std::array<unsigned int,2> hlpArrZ;
8317 double maxMapAngPerIndex = std::max ( this->_xRange / static_cast<double> ( this->_maxMapU ),
8318 std::max ( this->_yRange / static_cast<double> ( this->_maxMapV ),
8319 this->_zRange / static_cast<double> ( this->_maxMapW ) ) );
8321 unsigned int boxDimInIndices =
static_cast<unsigned int> ( std::round ( settings->
mapFragBoxSize / maxMapAngPerIndex ) );
8322 if ( ( boxDimInIndices % 2 ) == 1 )
8325 boxDimInIndices += 1;
8329 if ( boxDimInIndices < 2 )
8331 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;
8335 std::stringstream hlpSS;
8336 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>";
8337 rvapi_set_text ( hlpSS.str().c_str(),
8349 if ( ( boxDimInIndices >= this->_maxMapU ) || ( boxDimInIndices >= this->_maxMapV ) || ( boxDimInIndices >= this->_maxMapW ) )
8351 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;
8355 std::stringstream hlpSS;
8356 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>";
8357 rvapi_set_text ( hlpSS.str().c_str(),
8371 std::cout <<
">>>>>>>> Sanity checks passed." << std::endl;
8375 for (
unsigned int xStart = 0; xStart <= ( this->_maxMapU - boxDimInIndices ); xStart += ( boxDimInIndices / 2 ) )
8377 hlpArrX[0] = xStart;
8378 hlpArrX[1] = xStart + boxDimInIndices;
8381 if ( ( xStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapU - boxDimInIndices ) )
8384 hlpArrX[1] = this->_maxMapU;
8387 for (
unsigned int yStart = 0; yStart <= ( this->_maxMapV - boxDimInIndices ); yStart += ( boxDimInIndices / 2 ) )
8389 hlpArrY[0] = yStart;
8390 hlpArrY[1] = yStart + boxDimInIndices;
8393 if ( ( yStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapV - boxDimInIndices ) )
8396 hlpArrY[1] = this->_maxMapV;
8399 for (
unsigned int zStart = 0; zStart <= ( this->_maxMapW - boxDimInIndices ); zStart += ( boxDimInIndices / 2 ) )
8401 hlpArrZ[0] = zStart;
8402 hlpArrZ[1] = zStart + boxDimInIndices;
8405 if ( ( zStart + ( boxDimInIndices / 2 ) ) > ( this->_maxMapW - boxDimInIndices ) )
8408 hlpArrZ[1] = this->_maxMapW;
8411 XDim.emplace_back ( hlpArrX );
8412 YDim.emplace_back ( hlpArrY );
8413 ZDim.emplace_back ( hlpArrZ );
8419 std::cout <<
">>>>> Box sizes computed." << std::endl;
8423 unsigned int noDensityPoints = 0;
8424 unsigned int strCounter = 0;
8425 unsigned int arrayPos = 0;
8427 double boxVolume = 0.0;
8431 double densTot = 0.0;
8432 int newU, newV, newW;
8433 int hlpU, hlpV, hlpW;
8434 std::vector<double> mapVals;
8435 std::string fileName;
8437 for (
unsigned int boxIt = 0; boxIt < static_cast<unsigned int> ( XDim.size() ); boxIt++ )
8441 std::cout <<
">>>>> Trying box " << boxIt <<
" ." << std::endl;
8445 noDensityPoints = 0;
8446 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
8448 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
8450 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
8452 arrayPos = z + (this->_maxMapW+1) * ( y + (this->_maxMapV+1) * x );
8454 if ( this->_densityMapCor[arrayPos] > 0.0 )
8456 noDensityPoints += 1;
8463 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 );
8464 if ( ( static_cast<double> ( noDensityPoints ) / boxVolume ) > settings->
mapFragBoxFraction )
8470 ret.at(strCounter)->_fromPDB =
false;
8471 ret.at(strCounter)->_shellSpacing = settings->
shellSpacing;
8472 ret.at(strCounter)->_maxExtraCellularSpace = settings->
extraSpace;
8473 ret.at(strCounter)->_xRange = ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] ) * ( this->_xRange / static_cast<double> ( this->_maxMapU ) );
8474 ret.at(strCounter)->_yRange = ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] ) * ( this->_yRange / static_cast<double> ( this->_maxMapV ) );
8475 ret.at(strCounter)->_zRange = ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] ) * ( this->_zRange / static_cast<double> ( this->_maxMapW ) );
8478 ret.at(strCounter)->_xFrom = XDim.at(boxIt)[0] + this->_xFrom;
8479 ret.at(strCounter)->_yFrom = YDim.at(boxIt)[0] + this->_yFrom;;
8480 ret.at(strCounter)->_zFrom = ZDim.at(boxIt)[0] + this->_zFrom;;
8482 ret.at(strCounter)->_xTo = XDim.at(boxIt)[1] + this->_xFrom;;
8483 ret.at(strCounter)->_yTo = YDim.at(boxIt)[1] + this->_yFrom;;
8484 ret.at(strCounter)->_zTo = ZDim.at(boxIt)[1] + this->_zFrom;;
8487 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 ) );
8489 for (
unsigned int shellIter = 0; shellIter < static_cast<unsigned int> ( ret.at(strCounter)->_shellPlacement.size() ); shellIter++ )
8491 ret.at(strCounter)->_shellPlacement.at(shellIter) = (shellIter+1) * ret.at(strCounter)->_shellSpacing;
8495 ret.at(strCounter)->_mapResolution= settings->
mapResolution;
8496 ret.at(strCounter)->_maxMapU = ( XDim.at(boxIt)[1] - XDim.at(boxIt)[0] );
8497 ret.at(strCounter)->_maxMapV = ( YDim.at(boxIt)[1] - YDim.at(boxIt)[0] );
8498 ret.at(strCounter)->_maxMapW = ( ZDim.at(boxIt)[1] - ZDim.at(boxIt)[0] );
8499 ret.at(strCounter)->_densityMapComputed =
true;
8501 hlpU = ( ret.at(strCounter)->_maxMapU + 1 );
8502 hlpV = ( ret.at(strCounter)->_maxMapV + 1 );
8503 hlpW = ( ret.at(strCounter)->_maxMapW + 1 );
8507 ret.at(strCounter)->_densityMapCor=
new double [(ret.at(strCounter)->_maxMapU+1) * (ret.at(strCounter)->_maxMapV+1) * (ret.at(strCounter)->_maxMapW + 1)];
8512 for (
unsigned int x = XDim.at(boxIt)[0]; x <= XDim.at(boxIt)[1]; x++ )
8514 for (
unsigned int y = YDim.at(boxIt)[0]; y <= YDim.at(boxIt)[1]; y++ )
8516 for (
unsigned int z = ZDim.at(boxIt)[0]; z <= ZDim.at(boxIt)[1]; z++ )
8518 arrayPos = z + (this->_maxMapW+1) * ( y + (this->_maxMapV+1) * x );
8519 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]) );
8521 ret.at(strCounter)->_densityMapCor[coordPos] = this->_densityMapCor[arrayPos];
8523 if ( this->_densityMapCor[arrayPos] > 0.0 )
8525 mapVals.emplace_back ( this->_densityMapCor[arrayPos] );
8526 xCOM += ( x - XDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8527 yCOM += ( y - YDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8528 zCOM += ( z - ZDim.at(boxIt)[0] ) * this->_densityMapCor[arrayPos];
8529 densTot += this->_densityMapCor[arrayPos];
8536 ret.at(strCounter)->_mapMean = std::accumulate ( mapVals.begin(), mapVals.end(), 0.0 ) / static_cast<double> ( mapVals.size() );
8537 ret.at(strCounter)->_mapSdev = std::sqrt ( static_cast<double> ( std::inner_product ( mapVals.begin(), mapVals.end(), mapVals.begin(), 0.0 ) ) /
8538 static_cast<double> ( mapVals.size() ) - ret.at(strCounter)->_mapMean * ret.at(strCounter)->_mapMean );
8542 std::array<double,3> meanVals;
8545 meanVals[0] = xCOM / densTot;
8546 meanVals[1] = yCOM / densTot;
8547 meanVals[2] = zCOM / densTot;
8551 meanVals[0] =
static_cast<double> ( hlpU ) / 2.0;
8552 meanVals[1] =
static_cast<double> ( hlpV ) / 2.0;
8553 meanVals[2] =
static_cast<double> ( hlpW ) / 2.0;
8557 ret.at(strCounter)->_xCorrErr = meanVals[0] -
static_cast<double> ( hlpU ) / 2.0;
8558 ret.at(strCounter)->_yCorrErr = meanVals[1] -
static_cast<double> ( hlpV ) / 2.0;
8559 ret.at(strCounter)->_zCorrErr = meanVals[2] -
static_cast<double> ( hlpW ) / 2.0;
8561 ret.at(strCounter)->_xCorrection = std::ceil ( ret.at(strCounter)->_xCorrErr );
8562 ret.at(strCounter)->_yCorrection = std::ceil ( ret.at(strCounter)->_yCorrErr );
8563 ret.at(strCounter)->_zCorrection = std::ceil ( ret.at(strCounter)->_zCorrErr );
8565 ret.at(strCounter)->_densityMapCorCoords =
new std::array<double,3> [hlpU * hlpV * hlpW];
8566 double *tmpIn =
new double [hlpU * hlpV * hlpW];
8567 for (
unsigned int iter = 0; iter < static_cast<unsigned int> ( hlpU * hlpV * hlpW ); iter++ )
8569 tmpIn[iter] = ret.at(strCounter)->_densityMapCor[iter];
8572 for (
int uIt = 0; uIt < hlpU; uIt++ )
8574 for (
int vIt = 0; vIt < hlpV; vIt++ )
8576 for (
int wIt = 0; wIt < hlpW; wIt++ )
8578 newU =
static_cast<int> ( uIt ) - static_cast<int> ( ret.at(strCounter)->_xCorrection );
8579 newV =
static_cast<int> ( vIt ) - static_cast<int> ( ret.at(strCounter)->_yCorrection );
8580 newW =
static_cast<int> ( wIt ) - static_cast<int> ( ret.at(strCounter)->_zCorrection );
8582 if ( newU < 0 ) { newU += hlpU; }
if ( newU >= static_cast<int> ( hlpU ) ) { newU -= hlpU; }
8583 if ( newV < 0 ) { newV += hlpV; }
if ( newV >= static_cast<int> ( hlpV ) ) { newV -= hlpV; }
8584 if ( newW < 0 ) { newW += hlpW; }
if ( newW >= static_cast<int> ( hlpW ) ) { newW -= hlpW; }
8586 arrayPos = wIt + hlpW * ( vIt + hlpV * uIt );
8587 coordPos = newW + hlpW * ( newV + hlpV * newU );
8589 ret.at(strCounter)->_densityMapCor[coordPos] = tmpIn[arrayPos];
8592 ret.at(strCounter)->_densityMapCorCoords[coordPos][0] = (
static_cast<double> ( newU ) - static_cast<double> ( hlpU ) /2.0 ) * ( ret.at(strCounter)->_xRange /
static_cast<double> ( hlpU ) );
8593 ret.at(strCounter)->_densityMapCorCoords[coordPos][1] = (
static_cast<double> ( newV ) - static_cast<double> ( hlpV ) /2.0 ) * ( ret.at(strCounter)->_yRange /
static_cast<double> ( hlpV ) );;
8594 ret.at(strCounter)->_densityMapCorCoords[coordPos][2] = (
static_cast<double> ( newW ) - static_cast<double> ( hlpW ) /2.0 ) * ( ret.at(strCounter)->_zRange /
static_cast<double> ( hlpW ) );;
8601 ret.at(strCounter)->_fourierCoeffPower = this->_fourierCoeffPower;
8602 ret.at(strCounter)->_bFactorChange= this->_bFactorChange;
8603 ret.at(strCounter)->_maxMapRange = std::max ( ret.at(strCounter)->_xRange, std::max ( ret.at(strCounter)->_yRange, ret.at(strCounter)->_zRange ) );
8604 ret.at(strCounter)->_phaseRemoved = this->_phaseRemoved;
8605 ret.at(strCounter)->_keepOrRemove = this->_keepOrRemove;
8606 ret.at(strCounter)->_thetaAngle = this->_thetaAngle;
8607 ret.at(strCounter)->_phiAngle = this->_phiAngle;
8608 ret.at(strCounter)->_noShellsWithData = 0;
8609 ret.at(strCounter)->_sphereMapped =
false;
8610 ret.at(strCounter)->_firstLineCOM =
false;
8611 ret.at(strCounter)->_bandwidthLimit = this->_bandwidthLimit;
8612 ret.at(strCounter)->_oneDimmension= ret.at(strCounter)->_bandwidthLimit * 2;
8613 ret.at(strCounter)->_sphericalCoefficientsComputed =
false;
8614 ret.at(strCounter)->_rrpMatricesPrecomputed =
false;
8615 ret.at(strCounter)->_shellMappedData =
nullptr;
8616 ret.at(strCounter)->_realSHCoeffs =
nullptr;
8617 ret.at(strCounter)->_imagSHCoeffs =
nullptr;
8618 ret.at(strCounter)->_sphericalHarmonicsWeights=
nullptr;
8619 ret.at(strCounter)->_semiNaiveTable =
nullptr;
8620 ret.at(strCounter)->_semiNaiveTableSpace =
nullptr;
8621 ret.at(strCounter)->_shWorkspace =
nullptr;
8622 ret.at(strCounter)->_invRealData =
nullptr;
8623 ret.at(strCounter)->_invImagData =
nullptr;
8624 ret.at(strCounter)->_rrpMatrices =
nullptr;
8633 std::cout <<
">>>>>>>> Density check NOT passed." << std::endl;
8639 std::cout <<
">>>>>>>> Box " << boxIt <<
" processed." << std::endl;
8660 clipper::mmdb::CMMDBManager *mfile =
new clipper::mmdb::CMMDBManager ( );
8661 if ( mfile->ReadCoorFile ( modelPath.c_str() ) )
8663 std::cerr <<
"!!! ProSHADE ERROR !!! Cannot read model file: " << modelPath.c_str() << std::endl;
8671 std::vector<std::array<double,3>> coords;
8672 std::array<double,3> hlpArr;
8674 clipper::mmdb::PPCChain chain;
8675 clipper::mmdb::PPCResidue residue;
8676 clipper::mmdb::PPCAtom atom;
8679 mfile->GetChainTable ( 1, chain, noChains );
8680 for (
unsigned int nCh = 0; nCh < static_cast<unsigned int> ( noChains ); nCh++ )
8685 chain[nCh]->GetResidueTable ( residue, noResidues );
8687 for (
unsigned int nRes = 0; nRes < static_cast<unsigned int> ( noResidues ); nRes++ )
8689 if ( residue[nRes] )
8692 residue[nRes]->GetAtomTable ( atom, noAtoms );
8694 for (
unsigned int aNo = 0; aNo < static_cast<unsigned int> ( noAtoms ); aNo++ )
8699 if ( atom[aNo]->Ter ) {
continue; }
8702 hlpArr[0] = atom[aNo]->x;
8703 hlpArr[1] = atom[aNo]->y;
8704 hlpArr[2] = atom[aNo]->z;
8707 coords.emplace_back ( hlpArr );
8738 double fullDist = 0.0;
8739 double firstApprox = 0.0;
8740 double hlpDist = 0.0;
8744 unsigned int furthestAtom = 0;
8745 for (
unsigned int at1 = 0; at1 < static_cast<unsigned int> ( coords.size() ); at1++ )
8747 xMean += coords.at(at1)[0];
8748 yMean += coords.at(at1)[1];
8749 zMean += coords.at(at1)[2];
8751 xMean /=
static_cast<double> ( coords.size() );
8752 yMean /=
static_cast<double> ( coords.size() );
8753 zMean /=
static_cast<double> ( coords.size() );
8755 std::vector<double> dists ( coords.size(), 0.0 );
8756 for (
unsigned int at1 = 0; at1 < static_cast<unsigned int> ( coords.size() ); at1++ )
8758 hlpDist = sqrt ( pow ( std::abs ( xMean - coords.at(at1)[0] ), 2.0 ) +
8759 pow ( std::abs ( yMean - coords.at(at1)[1] ), 2.0 ) +
8760 pow ( std::abs ( zMean - coords.at(at1)[2] ), 2.0 ) );
8761 dists.at(at1) = hlpDist;
8763 if ( firstApprox < hlpDist )
8765 firstApprox = hlpDist;
8770 for (
unsigned int at1 = 0; at1 < static_cast<unsigned int> ( dists.size() ); at1++ )
8772 if ( at1 == furthestAtom ) {
continue; }
8774 hlpDist = sqrt ( pow ( std::abs ( coords.at(furthestAtom)[0] - coords.at(at1)[0] ), 2.0 ) +
8775 pow ( std::abs ( coords.at(furthestAtom)[1] - coords.at(at1)[1] ), 2.0 ) +
8776 pow ( std::abs ( coords.at(furthestAtom)[2] - coords.at(at1)[2] ), 2.0 ) );
8778 if ( fullDist < hlpDist )
8785 return ( fullDist );
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 ...
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...
double modelRadiusCalc(std::string modelPath)
This function takes model and finds the maximum distance between any two atoms.
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! ...
Task taskToPerform
This custom type variable determines which task to perfom (i.e. symmetry detection, distances computation or map features extraction).
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.