33 #if __cplusplus >= 201103L
34 return (
static_cast< proshade_signed
> ( std::round ( x ) ) );
36 return (
static_cast< proshade_signed
> ( round ( x ) ) );
48 #if __cplusplus >= 201103L
49 return (
static_cast< proshade_signed
> ( std::round ( x ) ) );
51 return (
static_cast< proshade_signed
> ( round ( x ) ) );
75 bool firstAtom =
true;
78 if ( pdbFile.models.size() > 0 )
81 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); sIt++ )
84 if ( firstModel && ( sIt != 0 ) ) {
break; }
87 gemmi::Model model = pdbFile.models.at(sIt);
90 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model.chains.size() ); mIt++ )
93 gemmi::Chain chain = model.chains.at(mIt);
96 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain.residues.size() ); rIt++ )
99 gemmi::Residue residue = chain.residues.at(rIt);
102 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue.atoms.size() ); aIt++ )
105 gemmi::Atom atom = residue.atoms.at(aIt);
108 if ( atom.is_hydrogen() ) {
continue; }
113 *xTo =
static_cast<proshade_single
> ( atom.pos.x );
114 *xFrom =
static_cast<proshade_single
> ( atom.pos.x );
115 *yTo =
static_cast<proshade_single
> ( atom.pos.y );
116 *yFrom =
static_cast<proshade_single
> ( atom.pos.y );
117 *zTo =
static_cast<proshade_single
> ( atom.pos.z );
118 *zFrom =
static_cast<proshade_single
> ( atom.pos.z );
123 if (
static_cast<proshade_single
> ( atom.pos.x ) > *xTo ) { *xTo =
static_cast<proshade_single
> ( atom.pos.x ); }
124 if (
static_cast<proshade_single
> ( atom.pos.x ) < *xFrom ) { *xFrom =
static_cast<proshade_single
> ( atom.pos.x ); }
125 if (
static_cast<proshade_single
> ( atom.pos.y ) > *yTo ) { *yTo =
static_cast<proshade_single
> ( atom.pos.y ); }
126 if (
static_cast<proshade_single
> ( atom.pos.y ) < *yFrom ) { *yFrom =
static_cast<proshade_single
> ( atom.pos.y ); }
127 if (
static_cast<proshade_single
> ( atom.pos.z ) > *zTo ) { *zTo =
static_cast<proshade_single
> ( atom.pos.z ); }
128 if (
static_cast<proshade_single
> ( atom.pos.z ) < *zFrom ) { *zFrom =
static_cast<proshade_single
> ( atom.pos.z ); }
137 std::stringstream hlpSS;
138 hlpSS <<
"Found 0 models in input file " << pdbFile.name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
139 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
160 proshade_double totAtoms = 0.0;
166 if ( pdbFile.models.size() > 0 )
169 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); sIt++ )
172 gemmi::Model model = pdbFile.models.at(sIt);
175 if ( firstModel && ( sIt != 0 ) ) {
break; }
178 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model.chains.size() ); mIt++ )
181 gemmi::Chain chain = model.chains.at(mIt);
184 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain.residues.size() ); rIt++ )
187 gemmi::Residue residue = chain.residues.at(rIt);
190 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue.atoms.size() ); aIt++ )
193 gemmi::Atom atom = residue.atoms.at(aIt);
196 *xCom += atom.pos.x * atom.element.weight();
197 *yCom += atom.pos.y * atom.element.weight();
198 *zCom += atom.pos.z * atom.element.weight();
199 totAtoms += atom.element.weight();
207 std::stringstream hlpSS;
208 hlpSS <<
"Found 0 models in input file " << pdbFile.name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
209 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
240 void ProSHADE_internal_mapManip::findMAPCOMValues ( proshade_double* map, proshade_double *xCom, proshade_double *yCom, proshade_double *zCom, proshade_single xAngs, proshade_single yAngs, proshade_single zAngs, proshade_signed xFrom, proshade_signed xTo, proshade_signed yFrom, proshade_signed yTo, proshade_signed zFrom, proshade_signed zTo )
243 proshade_double totDensity = 0.0;
247 proshade_signed arrPos = 0;
248 proshade_single xSampRate = xAngs /
static_cast< proshade_single
> ( xTo - xFrom );
249 proshade_single ySampRate = yAngs /
static_cast< proshade_single
> ( yTo - yFrom );
250 proshade_single zSampRate = zAngs /
static_cast< proshade_single
> ( zTo - zFrom );
253 for ( proshade_signed xIt = xFrom; xIt <= xTo; xIt++ )
255 for ( proshade_signed yIt = yFrom; yIt <= yTo; yIt++ )
257 for ( proshade_signed zIt = zFrom; zIt <= zTo; zIt++ )
259 arrPos = (zIt-zFrom) + ( zTo - zFrom + 1 ) * ( ( yIt - yFrom ) + ( yTo - yFrom + 1 ) * ( xIt - xFrom ) );
261 if ( map[arrPos] > 0.0 )
263 totDensity += map[arrPos];
264 *xCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( xIt ) * xSampRate ) * map[arrPos];
265 *yCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( yIt ) * ySampRate ) * map[arrPos];
266 *zCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( zIt ) * zSampRate ) * map[arrPos];
297 proshade_double yCom, proshade_double zCom,
bool firstModel )
300 proshade_double *rotMat =
new proshade_double[9];
305 proshade_double xTmp, yTmp, zTmp;
308 if ( pdbFile->models.size() > 0 )
311 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
314 gemmi::Model *model = &pdbFile->models.at(sIt);
317 if ( firstModel && ( sIt != 0 ) ) {
break; }
320 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
323 gemmi::Chain *chain = &model->chains.at(mIt);
326 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
329 gemmi::Residue *residue = &chain->residues.at(rIt);
332 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
335 gemmi::Atom *atom = &residue->atoms.at(aIt);
338 xTmp =
static_cast< proshade_double
> ( atom->pos.x - xCom );
339 yTmp =
static_cast< proshade_double
> ( atom->pos.y - yCom );
340 zTmp =
static_cast< proshade_double
> ( atom->pos.z - zCom );
343 atom->pos.x = ( xTmp * rotMat[0] ) + ( yTmp * rotMat[1] ) + ( zTmp * rotMat[2] );
344 atom->pos.y = ( xTmp * rotMat[3] ) + ( yTmp * rotMat[4] ) + ( zTmp * rotMat[5] );
345 atom->pos.z = ( xTmp * rotMat[6] ) + ( yTmp * rotMat[7] ) + ( zTmp * rotMat[8] );
348 atom->pos.x = atom->pos.x + xCom;
349 atom->pos.y = atom->pos.y + yCom;
350 atom->pos.z = atom->pos.z + zCom;
358 std::stringstream hlpSS;
359 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
360 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
384 if ( pdbFile->models.size() > 0 )
387 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
390 if ( firstModel && ( sIt != 0 ) ) {
break; }
393 gemmi::Model *model = &pdbFile->models.at(sIt);
396 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
399 gemmi::Chain *chain = &model->chains.at(mIt);
402 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
405 gemmi::Residue *residue = &chain->residues.at(rIt);
408 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
411 gemmi::Atom *atom = &residue->atoms.at(aIt);
414 atom->pos.x += transX;
415 atom->pos.y += transY;
416 atom->pos.z += transZ;
424 std::stringstream hlpSS;
425 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
426 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
447 if ( pdbFile->models.size() > 0 )
450 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
453 if ( firstModel && ( sIt != 0 ) ) {
break; }
456 gemmi::Model *model = &pdbFile->models.at(sIt);
459 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
462 gemmi::Chain *chain = &model->chains.at(mIt);
465 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
468 gemmi::Residue *residue = &chain->residues.at(rIt);
471 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
474 gemmi::Atom *atom = &residue->atoms.at(aIt);
477 atom->b_iso =
static_cast< float > ( newBFactorValue );
485 std::stringstream hlpSS;
486 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
487 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
507 if ( pdbFile->models.size() > 0 )
510 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
513 if ( firstModel && ( sIt != 0 ) ) {
break; }
516 gemmi::Model *model = &pdbFile->models.at(sIt);
519 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
522 gemmi::Chain *chain = &model->chains.at(mIt);
525 std::vector< proshade_unsign > delVec;
528 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
531 gemmi::Residue *residue = &chain->residues.at(rIt);
534 if ( residue->is_water() )
541 std::sort ( delVec.begin(), delVec.end(), std::greater<int>() );
542 for ( proshade_unsign vecIt = 0; vecIt < static_cast<proshade_unsign> ( delVec.size() ); vecIt++ )
544 chain->residues.erase ( chain->residues.begin() +
static_cast< long int > ( delVec.at(vecIt) ) );
551 std::stringstream hlpSS;
552 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
553 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
576 if ( pdbFile->models.size() > 0 )
579 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
582 if ( firstModel && ( sIt != 0 ) ) {
break; }
585 gemmi::Model *model = &pdbFile->models.at(sIt);
588 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
591 gemmi::Chain *chain = &model->chains.at(mIt);
594 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
597 gemmi::Residue *residue = &chain->residues.at(rIt);
600 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
603 gemmi::Atom *atom = &residue->atoms.at(aIt);
606 atom->pos = gemmi::Position ( atom->pos.x +
static_cast< proshade_double
> ( xMov ), atom->pos.y +
static_cast< proshade_double
> ( yMov ), atom->pos.z +
static_cast< proshade_double
> ( zMov ) );
615 std::stringstream hlpSS;
616 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
617 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
644 void ProSHADE_internal_mapManip::generateMapFromPDB ( gemmi::Structure pdbFile, proshade_double*& map, proshade_single requestedResolution, proshade_single xCell, proshade_single yCell, proshade_single zCell, proshade_signed* xTo, proshade_signed* yTo, proshade_signed* zTo,
bool forceP1,
bool firstModel )
647 if ( forceP1 ) { pdbFile.cell = gemmi::UnitCell(); }
648 pdbFile.cell.a =
static_cast< proshade_double
> ( xCell );
649 pdbFile.cell.b =
static_cast< proshade_double
> ( yCell );
650 pdbFile.cell.c =
static_cast< proshade_double
> ( zCell );
651 pdbFile.cell.calculate_properties ( );
654 std::string totElString;
655 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); mIt++ )
658 if ( firstModel && ( mIt != 0 ) )
660 std::stringstream hlpSS;
661 hlpSS <<
"!!! ProSHADE WARNING !!! Found multiple models (" << pdbFile.models.size() <<
") in input file " << pdbFile.name <<
", while the settings state that only the first PDB file model should be used. If all models should be used, please supply ProSHADE with the \"-x\" option.";
666 std::string hlpStr = pdbFile.models[mIt].present_elements ( ).to_string<char,std::char_traits<char>,std::allocator<char> >();
667 totElString = totElString + hlpStr;
669 std::bitset< static_cast< size_t > ( gemmi::El::END )> present_elems ( totElString );
672 if ( present_elems[
static_cast<int> ( gemmi::El::X )] )
674 throw ProSHADE_exception (
"Found unknown element in input file.",
"EP00051", __FILE__, __LINE__, __func__,
"Gemmi library does not recognise some of the elements in\n : the co-ordinate file. Please check the file for not being\n : corrupted and containing standard elements." );
677 for ( proshade_unsign elIt = 0; elIt < static_cast<proshade_unsign> ( present_elems.size() ); elIt++ )
679 if ( present_elems[elIt] && !gemmi::IT92<double>::has (
static_cast<gemmi::El
> ( elIt ) ) )
681 std::stringstream hlpSS;
682 hlpSS <<
"Missing form factor for element " << element_name (
static_cast<gemmi::El
> ( elIt ) );
683 throw ProSHADE_exception ( hlpSS.str().c_str(),
"EP00052", __FILE__, __LINE__, __func__,
"Gemmi library does not have a form factor value for this\n : reported element. Please report this to the author." );
688 double wavelength = 0.1;
689 double energy = gemmi::hc() / wavelength;
692 gemmi::DensityCalculator<gemmi::IT92<double>,
float> dencalc;
694 dencalc.d_min =
static_cast< double > ( requestedResolution );
695 for (
size_t elIt = 0; elIt < present_elems.size(); elIt++ ) {
if ( present_elems[elIt] ) { dencalc.addends.set (
static_cast< gemmi::El
> ( elIt ),
static_cast< float > ( gemmi::cromer_libermann (
static_cast< int > ( elIt ), energy,
nullptr ) ) ); } }
696 dencalc.set_grid_cell_and_spacegroup ( pdbFile );
699 if ( forceP1 ) { dencalc.grid.spacegroup = &gemmi::get_spacegroup_p1(); }
702 dencalc.grid.data.clear ( );
703 dencalc.grid.set_size_from_spacing ( dencalc.d_min / ( 2.0 * dencalc.rate),
true );
704 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); mIt++ )
706 if ( firstModel && ( mIt != 0 ) ) {
break; }
707 dencalc.add_model_density_to_grid ( pdbFile.models[mIt] );
708 dencalc.grid.symmetrize ( [](
float a,
float b) {
return a + b; } );
712 const gemmi::Grid<float>& grid = dencalc.grid;
720 map =
new proshade_double [(*xTo) * (*yTo) * (*zTo)];
723 proshade_signed arrPos = 0;
724 for ( proshade_signed uIt = 0; uIt < (*xTo); uIt++ )
726 for ( proshade_signed vIt = 0; vIt < (*yTo); vIt++ )
728 for ( proshade_signed wIt = 0; wIt < (*zTo); wIt++ )
730 arrPos = wIt + (*zTo) * ( vIt + (*yTo) * uIt );
731 map[arrPos] =
static_cast< proshade_double
> ( grid.get_value_q(
static_cast< int > ( uIt ),
static_cast< int > ( vIt ),
static_cast< int > ( wIt ) ) );
763 void ProSHADE_internal_mapManip::moveMapByIndices ( proshade_single* xMov, proshade_single* yMov, proshade_single* zMov, proshade_single xAngs, proshade_single yAngs, proshade_single zAngs, proshade_signed* xFrom, proshade_signed* xTo, proshade_signed* yFrom, proshade_signed* yTo, proshade_signed* zFrom, proshade_signed* zTo, proshade_signed* xOrigin, proshade_signed* yOrigin, proshade_signed* zOrigin )
766 proshade_single xIndMove = std::floor ( -(*xMov) / ( xAngs / (
static_cast< proshade_single
> ( *xTo ) -
static_cast< proshade_single
> ( *xFrom ) ) ) );
767 proshade_single yIndMove = std::floor ( -(*yMov) / ( yAngs / (
static_cast< proshade_single
> ( *yTo ) -
static_cast< proshade_single
> ( *yFrom ) ) ) );
768 proshade_single zIndMove = std::floor ( -(*zMov) / ( zAngs / (
static_cast< proshade_single
> ( *zTo ) -
static_cast< proshade_single
> ( *zFrom ) ) ) );
771 *xMov = -( *xMov ) - ( xIndMove * ( xAngs / (
static_cast< proshade_single
> ( *xTo ) -
static_cast< proshade_single
> ( *xFrom ) ) ) );
772 *yMov = -( *yMov ) - ( yIndMove * ( yAngs / (
static_cast< proshade_single
> ( *yTo ) -
static_cast< proshade_single
> ( *yFrom ) ) ) );
773 *zMov = -( *zMov ) - ( zIndMove * ( zAngs / (
static_cast< proshade_single
> ( *zTo ) -
static_cast< proshade_single
> ( *zFrom ) ) ) );
776 *xFrom +=
static_cast< proshade_signed
> ( xIndMove );
777 *xTo +=
static_cast< proshade_signed
> ( xIndMove );
778 *yFrom +=
static_cast< proshade_signed
> ( yIndMove );
779 *yTo +=
static_cast< proshade_signed
> ( yIndMove );
780 *zFrom +=
static_cast< proshade_signed
> ( zIndMove );
781 *zTo +=
static_cast< proshade_signed
> ( zIndMove );
811 void ProSHADE_internal_mapManip::moveMapByFourier ( proshade_double*& map, proshade_single xMov, proshade_single yMov, proshade_single zMov, proshade_single xAngs, proshade_single yAngs, proshade_single zAngs, proshade_signed xDim, proshade_signed yDim, proshade_signed zDim )
814 proshade_unsign arrayPos = 0;
815 proshade_signed h, k, l;
816 proshade_double real = 0.0;
817 proshade_double imag = 0.0;
818 proshade_double trCoeffReal, trCoeffImag;
819 proshade_double normFactor =
static_cast< proshade_double
> ( xDim * yDim * zDim );
820 proshade_double exponent = 0.0;
821 proshade_double hlpArrReal;
822 proshade_double hlpArrImag;
825 fftw_complex *fCoeffs =
new fftw_complex [xDim * yDim * zDim];
826 fftw_complex *translatedMap =
new fftw_complex [xDim * yDim * zDim];
833 fftw_plan planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDim ),
static_cast< int > ( yDim ),
static_cast< int > ( zDim ), translatedMap, fCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
834 fftw_plan planBackwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDim ),
static_cast< int > ( yDim ),
static_cast< int > ( zDim ), fCoeffs, translatedMap, FFTW_BACKWARD, FFTW_ESTIMATE );
837 for ( proshade_unsign uIt = 0; uIt < static_cast< proshade_unsign > ( xDim ); uIt++ )
839 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( yDim ); vIt++ )
841 for ( proshade_unsign wIt = 0; wIt < static_cast< proshade_unsign > ( zDim ); wIt++ )
843 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
845 const FloatingPoint< proshade_double > lhs ( map[arrayPos] ), rhs ( map[arrayPos] );
846 if ( lhs.AlmostEquals ( rhs ) ) { translatedMap[arrayPos][0] = map[arrayPos]; }
847 else { translatedMap[arrayPos][0] = 0.0; }
848 translatedMap[arrayPos][1] = 0.0;
854 fftw_execute ( planForwardFourier );
857 for ( proshade_unsign uIt = 0; uIt < static_cast<proshade_unsign> ( xDim ); uIt++ )
859 for ( proshade_unsign vIt = 0; vIt < static_cast<proshade_unsign> ( yDim ); vIt++ )
861 for ( proshade_unsign wIt = 0; wIt < static_cast<proshade_unsign> ( zDim ); wIt++ )
864 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
865 real = fCoeffs[arrayPos][0];
866 imag = fCoeffs[arrayPos][1];
869 if ( uIt >
static_cast< proshade_unsign
> ( (xDim+1) / 2) ) { h =
static_cast < proshade_signed
> ( uIt ) - xDim; }
else { h =
static_cast < proshade_signed
> ( uIt ); }
870 if ( vIt >
static_cast< proshade_unsign
> ( (yDim+1) / 2) ) { k =
static_cast < proshade_signed
> ( vIt ) - yDim; }
else { k =
static_cast < proshade_signed
> ( vIt ); }
871 if ( wIt >
static_cast< proshade_unsign
> ( (zDim+1) / 2) ) { l =
static_cast < proshade_signed
> ( wIt ) - zDim; }
else { l =
static_cast < proshade_signed
> ( wIt ); }
874 exponent = ( ( (
static_cast <proshade_double
> ( h ) /
static_cast <proshade_double
> ( xAngs ) ) *
static_cast< proshade_double
> ( -xMov ) ) +
875 ( (
static_cast <proshade_double
> ( k ) /
static_cast <proshade_double
> ( yAngs ) ) *
static_cast< proshade_double
> ( -yMov ) ) +
876 ( (
static_cast <proshade_double
> ( l ) /
static_cast <proshade_double
> ( zAngs ) ) *
static_cast< proshade_double
> ( -zMov ) ) ) * 2.0 * M_PI;
878 trCoeffReal = cos ( exponent );
879 trCoeffImag = sin ( exponent );
883 fCoeffs[arrayPos][0] = hlpArrReal / normFactor;
884 fCoeffs[arrayPos][1] = hlpArrImag / normFactor;
890 fftw_execute ( planBackwardFourier );
893 for ( proshade_unsign uIt = 0; uIt < static_cast< proshade_unsign > ( xDim ); uIt++ )
895 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( yDim ); vIt++ )
897 for ( proshade_unsign wIt = 0; wIt < static_cast< proshade_unsign > ( zDim ); wIt++ )
899 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
900 map[arrayPos] = translatedMap[arrayPos][0];
906 fftw_destroy_plan ( planForwardFourier );
907 fftw_destroy_plan ( planBackwardFourier );
909 delete[] translatedMap;
932 void ProSHADE_internal_mapManip::blurSharpenMap ( proshade_double*& map, proshade_double*& blurredMap, proshade_unsign xDimS, proshade_unsign yDimS, proshade_unsign zDimS, proshade_single xAngs, proshade_single yAngs, proshade_single zAngs, proshade_single blurringFactor )
935 proshade_signed xDim =
static_cast< proshade_signed
> ( xDimS );
936 proshade_signed yDim =
static_cast< proshade_signed
> ( yDimS );
937 proshade_signed zDim =
static_cast< proshade_signed
> ( zDimS );
938 proshade_double real, imag, S, mag, phase;
939 proshade_signed h, k, l;
940 proshade_unsign arrayPos = 0;
941 proshade_double normFactor =
static_cast<proshade_double
> ( xDim * yDim * zDim );
944 fftw_complex* mapCoeffs =
new fftw_complex[xDim * yDim * zDim];
945 fftw_complex* mapMask =
new fftw_complex[xDim * yDim * zDim];
952 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> (xDim * yDim * zDim); iter++ )
954 mapMask[iter][0] = map[iter];
955 mapMask[iter][1] = 0.0;
959 fftw_plan forward = fftw_plan_dft_3d (
static_cast< int > ( xDim ),
static_cast< int > ( yDim ),
static_cast< int > ( zDim ), mapMask, mapCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
960 fftw_plan inverse = fftw_plan_dft_3d (
static_cast< int > ( xDim ),
static_cast< int > ( yDim ),
static_cast< int > ( zDim ), mapCoeffs, mapMask, FFTW_BACKWARD, FFTW_ESTIMATE );
963 fftw_execute ( forward );
966 for ( proshade_unsign uIt = 0; uIt < static_cast<proshade_unsign> ( xDim ); uIt++ )
968 for ( proshade_unsign vIt = 0; vIt < static_cast<proshade_unsign> ( yDim ); vIt++ )
970 for ( proshade_unsign wIt = 0; wIt < static_cast<proshade_unsign> ( zDim ); wIt++ )
973 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
974 real = mapCoeffs[arrayPos][0];
975 imag = mapCoeffs[arrayPos][1];
978 if ( uIt >
static_cast< proshade_unsign
> ( (xDim+1) / 2) ) { h =
static_cast < proshade_signed
> ( uIt ) - xDim; }
else { h =
static_cast < proshade_signed
> ( uIt ); }
979 if ( vIt >
static_cast< proshade_unsign
> ( (yDim+1) / 2) ) { k =
static_cast < proshade_signed
> ( vIt ) - yDim; }
else { k =
static_cast < proshade_signed
> ( vIt ); }
980 if ( wIt >
static_cast< proshade_unsign
> ( (zDim+1) / 2) ) { l =
static_cast < proshade_signed
> ( wIt ) - zDim; }
else { l =
static_cast < proshade_signed
> ( wIt ); }
983 S = ( pow(
static_cast< proshade_double
> ( h ) /
static_cast< proshade_double
> ( xAngs ), 2.0 ) +
984 pow(
static_cast< proshade_double
> ( k ) /
static_cast< proshade_double
> ( yAngs ), 2.0 ) +
985 pow(
static_cast< proshade_double
> ( l ) /
static_cast< proshade_double
> ( zAngs ), 2.0 ) );
986 mag = std::sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( (
static_cast< proshade_double
> ( blurringFactor ) * S ) / 4.0 ) );
987 phase = std::atan2 ( imag, real );
990 mapCoeffs[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
991 mapCoeffs[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
997 fftw_execute ( inverse );
1000 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> (xDim * yDim * zDim); iter++ )
1002 blurredMap[iter] = mapMask[iter][0];
1010 fftw_destroy_plan ( forward );
1011 fftw_destroy_plan ( inverse );
1035 std::vector<proshade_double> mapVals ( xDim * yDim * zDim, 0.0 );
1038 for ( proshade_unsign iter = 0; iter < ( xDim * yDim * zDim ); iter++ )
1040 mapVals.at(iter) = blurMap[iter];
1044 proshade_double* medAndIQR =
new proshade_double[2];
1048 proshade_double maskThreshold = medAndIQR[0] + ( medAndIQR[1] *
static_cast<proshade_double
> ( noIQRs ) );
1051 for ( proshade_unsign iter = 0; iter < ( xDim * yDim * zDim ); iter++ )
1053 if ( blurMap[iter] < maskThreshold )
1056 blurMap[iter] = 0.0;
1085 proshade_signed arrayPos = 0;
1096 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1098 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1100 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1103 arrayPos = zIt + zDim * ( yIt + yDim * xIt );
1106 if ( map[arrayPos] > 0.001 )
1108 if ( xIt < ret[0] ) { ret[0] = xIt; }
1109 if ( xIt > ret[1] ) { ret[1] = xIt; }
1110 if ( yIt < ret[2] ) { ret[2] = yIt; }
1111 if ( yIt > ret[3] ) { ret[3] = yIt; }
1112 if ( zIt < ret[4] ) { ret[4] = zIt; }
1113 if ( zIt > ret[5] ) { ret[5] = zIt; }
1147 bounds[0] = bounds[0] - xExtraInds;
1148 bounds[1] = bounds[1] + xExtraInds;
1149 bounds[2] = bounds[2] - yExtraInds;
1150 bounds[3] = bounds[3] + yExtraInds;
1151 bounds[4] = bounds[4] - zExtraInds;
1152 bounds[5] = bounds[5] + zExtraInds;
1178 if ( resolution <= 0.0f )
1180 throw ProSHADE_exception (
"Requested resolution not set for map re-sampling.",
"EM00015", __FILE__, __LINE__, __func__,
"There is no resolution value set, but map re-sampling to\n : this unset resolution value is required. This error\n : occurs when a task with no resolution requirement is\n : requested on a map data and the map resolution change is\n : set to \'on\'. Either supply a resolution value, or do not\n : re-sample the map." );
1184 proshade_signed xDim =
static_cast<proshade_signed
> ( xDimS );
1185 proshade_signed yDim =
static_cast<proshade_signed
> ( yDimS );
1186 proshade_signed zDim =
static_cast<proshade_signed
> ( zDimS );
1187 proshade_single oldXSample = ( xAngs /
static_cast<proshade_single
> ( xDim ) );
1188 proshade_single oldYSample = ( yAngs /
static_cast<proshade_single
> ( yDim ) );
1189 proshade_single oldZSample = ( zAngs /
static_cast<proshade_single
> ( zDim ) );
1190 proshade_single newXSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1191 proshade_single newYSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1192 proshade_single newZSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1195 proshade_signed newXDim =
static_cast<proshade_signed
> ( std::ceil ( xAngs / newXSample ) );
1196 proshade_signed newYDim =
static_cast<proshade_signed
> ( std::ceil ( yAngs / newYSample ) );
1197 proshade_signed newZDim =
static_cast<proshade_signed
> ( std::ceil ( zAngs / newZSample ) );
1200 proshade_double* newMap =
new proshade_double [newXDim * newYDim * newZDim];
1203 proshade_signed xBottom = 0, xTop, yBottom = 0, yTop, zBottom = 0, zTop, oldMapIndex, newMapIndex;
1204 std::vector<proshade_double> c000 = std::vector<proshade_double> ( 4, 0.0 );
1205 std::vector<proshade_double> c001 = std::vector<proshade_double> ( 4, 0.0 );
1206 std::vector<proshade_double> c010 = std::vector<proshade_double> ( 4, 0.0 );
1207 std::vector<proshade_double> c011 = std::vector<proshade_double> ( 4, 0.0 );
1208 std::vector<proshade_double> c100 = std::vector<proshade_double> ( 4, 0.0 );
1209 std::vector<proshade_double> c101 = std::vector<proshade_double> ( 4, 0.0 );
1210 std::vector<proshade_double> c110 = std::vector<proshade_double> ( 4, 0.0 );
1211 std::vector<proshade_double> c111 = std::vector<proshade_double> ( 4, 0.0 );
1212 std::vector<proshade_double> c00 = std::vector<proshade_double> ( 4, 0.0 );
1213 std::vector<proshade_double> c01 = std::vector<proshade_double> ( 4, 0.0 );
1214 std::vector<proshade_double> c10 = std::vector<proshade_double> ( 4, 0.0 );
1215 std::vector<proshade_double> c11 = std::vector<proshade_double> ( 4, 0.0 );
1216 std::vector<proshade_double> c0 = std::vector<proshade_double> ( 4, 0.0 );
1217 std::vector<proshade_double> c1 = std::vector<proshade_double> ( 4, 0.0 );
1218 proshade_double xRelative, yRelative, zRelative;
1220 for ( proshade_signed xIt = 0; xIt < newXDim; xIt++ )
1222 for ( proshade_signed yIt = 0; yIt < newYDim; yIt++ )
1224 for ( proshade_signed zIt = 0; zIt < newZDim; zIt++ )
1227 newMapIndex = zIt + newZDim * ( yIt + newYDim * xIt );
1230 for ( proshade_signed ox = 0; ox < ( static_cast< proshade_signed > ( xDimS ) - 1 ); ox++ ) {
if ( ( (
static_cast< proshade_single
> ( xIt ) * newXSample ) >= (
static_cast< proshade_single
> ( ox ) * oldXSample ) ) && ( (
static_cast< proshade_single
> ( xIt ) * newXSample ) <= ( (
static_cast< proshade_single
> ( ox ) + 1 ) * oldXSample ) ) ) { xBottom = ox;
break; } }
1231 for ( proshade_signed oy = 0; oy < ( static_cast< proshade_signed > ( yDimS ) - 1 ); oy++ ) {
if ( ( (
static_cast< proshade_single
> ( yIt ) * newYSample ) >= (
static_cast< proshade_single
> ( oy ) * oldYSample ) ) && ( (
static_cast< proshade_single
> ( yIt ) * newYSample ) <= ( (
static_cast< proshade_single
> ( oy ) + 1 ) * oldYSample ) ) ) { yBottom = oy;
break; } }
1232 for ( proshade_signed oz = 0; oz < ( static_cast< proshade_signed > ( zDimS ) - 1 ); oz++ ) {
if ( ( (
static_cast< proshade_single
> ( zIt ) * newZSample ) >= (
static_cast< proshade_single
> ( oz ) * oldZSample ) ) && ( (
static_cast< proshade_single
> ( zIt ) * newZSample ) <= ( (
static_cast< proshade_single
> ( oz ) + 1 ) * oldZSample ) ) ) { zBottom = oz;
break; } }
1238 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1239 c000.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1240 c000.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1241 c000.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1242 c000.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1244 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1245 c001.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1246 c001.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1247 c001.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1248 c001.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1250 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1251 c010.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1252 c010.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1253 c010.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1254 c010.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1256 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1257 c011.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1258 c011.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1259 c011.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1260 c011.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1262 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1263 c100.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1264 c100.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1265 c100.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1266 c100.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1268 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1269 c101.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1270 c101.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1271 c101.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1272 c101.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1274 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1275 c110.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1276 c110.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1277 c110.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1278 c110.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1280 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1281 c111.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1282 c111.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1283 c111.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1284 c111.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1287 xRelative = ( (
static_cast<proshade_double
> ( xIt ) *
static_cast<proshade_double
> ( newXSample ) ) - (
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample ) ) ) / ( (
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample ) ) - (
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample ) ) );
1290 c00.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c000.at(0);
1291 c00.at(1) = c000.at(1);
1292 c00.at(2) = c000.at(2);
1293 c00.at(3) = ( c000.at(3) * ( 1.0 - xRelative ) ) + ( c100.at(3) * xRelative );
1296 c01.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c001.at(0);
1297 c01.at(1) = c001.at(1);
1298 c01.at(2) = c001.at(2);
1299 c01.at(3) = ( c001.at(3) * ( 1.0 - xRelative ) ) + ( c101.at(3) * xRelative );
1302 c10.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c010.at(0);
1303 c10.at(1) = c010.at(1);
1304 c10.at(2) = c010.at(2);
1305 c10.at(3) = ( c010.at(3) * ( 1.0 - xRelative ) ) + ( c110.at(3) * xRelative );
1308 c11.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c011.at(0);
1309 c11.at(1) = c011.at(1);
1310 c11.at(2) = c011.at(2);
1311 c11.at(3) = ( c011.at(3) * ( 1.0 - xRelative ) ) + ( c111.at(3) * xRelative );
1314 yRelative = ( (
static_cast<proshade_double
> ( yIt ) *
static_cast<proshade_double
> ( newYSample ) ) - (
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample ) ) ) / ( (
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample ) ) - (
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample ) ) );
1317 c0.at(0) = c00.at(0);
1318 c0.at(1) = (
static_cast< proshade_double
> ( newYSample ) * yRelative ) + c00.at(1);
1319 c0.at(2) = c00.at(2);
1320 c0.at(3) = ( c00.at(3) * ( 1.0 - yRelative ) ) + ( c10.at(3) * yRelative );
1323 c1.at(0) = c01.at(0);
1324 c1.at(1) = (
static_cast< proshade_double
> ( newYSample ) * yRelative ) + c01.at(1);
1325 c1.at(2) = c01.at(2);
1326 c1.at(3) = ( c01.at(3) * ( 1.0 - yRelative ) ) + ( c11.at(3) * yRelative );
1329 zRelative = ( (
static_cast<proshade_double
> ( zIt ) *
static_cast< proshade_double
> ( newZSample ) ) - (
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample ) ) ) /
static_cast< proshade_double
> ( (
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample ) ) - (
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample ) ) );
1330 newMap[newMapIndex] = ( c0.at(3) * ( 1.0 - zRelative ) ) + ( c1.at(3) * zRelative );
1337 map =
new proshade_double [newXDim * newYDim * newZDim];
1340 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ )
1342 map[iter] = newMap[iter];
1349 corrs[0] =
static_cast< proshade_single
> ( newXDim - xDim );
1350 corrs[1] =
static_cast< proshade_single
> ( newYDim - yDim );
1351 corrs[2] =
static_cast< proshade_single
> ( newZDim - zDim );
1352 corrs[3] =
static_cast< proshade_single
> ( newXDim ) *
static_cast< proshade_single
> ( newXSample );
1353 corrs[4] =
static_cast< proshade_single
> ( newYDim ) *
static_cast< proshade_single
> ( newYSample );
1354 corrs[5] =
static_cast< proshade_single
> ( newZDim ) *
static_cast< proshade_single
> ( newZSample );
1379 if ( resolution <= 0.0f )
1381 throw ProSHADE_exception (
"Requested resolution not set for map re-sampling.",
"EM00015", __FILE__, __LINE__, __func__,
"There is no resolution value set, but map re-sampling to\n : this unset resolution value is required. This error\n : occurs when a task with no resolution requirement is\n : requested on a map data and the map resolution change is\n : set to \'on\'. Either supply a resolution value, or do not\n : re-sample the map." );
1389 if ( newXDim % 2 != 0 ) { newXDim += 1; }
1390 if ( newYDim % 2 != 0 ) { newYDim += 1; }
1391 if ( newZDim % 2 != 0 ) { newZDim += 1; }
1393 proshade_signed preXChange, preYChange, preZChange;
1394 if ( ( xDimS % 2 ) == 0 ) { preXChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( xDimS ) -
static_cast<proshade_signed
> ( newXDim ) ) / 2 ) ); }
1395 else { preXChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( xDimS ) -
static_cast<proshade_signed
> ( newXDim ) ) / 2 ) ); }
1396 if ( ( yDimS % 2 ) == 0 ) { preYChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( yDimS ) -
static_cast<proshade_signed
> ( newYDim ) ) / 2 ) ); }
1397 else { preYChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( yDimS ) -
static_cast<proshade_signed
> ( newYDim ) ) / 2 ) ); }
1398 if ( ( zDimS % 2 ) == 0 ) { preZChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( zDimS ) -
static_cast<proshade_signed
> ( newZDim ) ) / 2 ) ); }
1399 else { preZChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( zDimS ) -
static_cast<proshade_signed
> ( newZDim ) ) / 2 ) ); }
1401 proshade_signed postXChange =
static_cast<proshade_signed
> ( xDimS ) - ( preXChange +
static_cast<proshade_signed
> ( newXDim ) );
1402 proshade_signed postYChange =
static_cast<proshade_signed
> ( yDimS ) - ( preYChange +
static_cast<proshade_signed
> ( newYDim ) );
1403 proshade_signed postZChange =
static_cast<proshade_signed
> ( zDimS ) - ( preZChange +
static_cast<proshade_signed
> ( newZDim ) );
1405 proshade_unsign origSizeArr = 0, newSizeArr = 0;
1406 proshade_double normFactor =
static_cast<proshade_double
> ( xDimS * yDimS * zDimS );
1409 fftw_complex *origMap, *fCoeffs, *newFCoeffs, *newMap;
1410 fftw_plan planForwardFourier, planBackwardRescaledFourier;
1412 xDimS, yDimS, zDimS, newXDim, newYDim, newZDim );
1415 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDimS * yDimS * zDimS ); iter++ ) { origMap[iter][0] = map[iter]; origMap[iter][1] = 0.0; }
1416 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ ) { newFCoeffs[iter][0] = 0.0; newFCoeffs[iter][1] = 0.0; }
1419 fftw_execute ( planForwardFourier );
1422 changeFourierOrder ( fCoeffs,
static_cast< proshade_signed
> ( xDimS ),
static_cast< proshade_signed
> ( yDimS ),
static_cast< proshade_signed
> ( zDimS ),
true );
1425 for ( proshade_unsign xIt = 0; xIt < newXDim; xIt++ )
1427 for ( proshade_unsign yIt = 0; yIt < newYDim; yIt++ )
1429 for ( proshade_unsign zIt = 0; zIt < newZDim; zIt++ )
1432 origSizeArr = ( ( zIt +
static_cast< proshade_unsign
> ( preZChange ) ) + zDimS *
1433 ( ( yIt +
static_cast< proshade_unsign
> ( preYChange ) ) + yDimS *
1434 ( xIt +
static_cast< proshade_unsign
> ( preXChange ) ) ) );
1435 newSizeArr = zIt + newZDim * ( yIt + newYDim * xIt );
1438 if ( ( ( -1 <
static_cast< proshade_signed
> ( xIt ) + preXChange ) && ( -1 <
static_cast<proshade_signed
> ( yIt ) + preYChange ) && ( -1 <
static_cast<proshade_signed
> ( zIt ) + preZChange ) ) &&
1439 ( ( xIt < newXDim + static_cast<proshade_unsign> ( postXChange ) ) && ( yIt < newYDim +
static_cast<proshade_unsign
> ( postYChange ) ) && ( zIt < newZDim +
static_cast<proshade_unsign
> ( postZChange ) ) ) )
1442 newFCoeffs[newSizeArr][0] = fCoeffs[origSizeArr][0] / normFactor;
1443 newFCoeffs[newSizeArr][1] = fCoeffs[origSizeArr][1] / normFactor;
1450 changeFourierOrder ( newFCoeffs,
static_cast< proshade_signed
> ( newXDim ),
static_cast< proshade_signed
> ( newYDim ),
static_cast< proshade_signed
> ( newZDim ),
false );
1453 fftw_execute ( planBackwardRescaledFourier );
1457 map =
new proshade_double [newXDim * newYDim * newZDim];
1459 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ ) { map[iter] = newMap[iter][0]; }
1465 corrs[0] =
static_cast< proshade_single
> ( newXDim ) -
static_cast< proshade_single
> ( xDimS );
1466 corrs[1] =
static_cast< proshade_single
> ( newYDim ) -
static_cast< proshade_single
> ( yDimS );
1467 corrs[2] =
static_cast< proshade_single
> ( newZDim ) -
static_cast< proshade_single
> ( zDimS );
1468 corrs[3] =
static_cast< proshade_single
> ( newXDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1469 corrs[4] =
static_cast< proshade_single
> ( newYDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1470 corrs[5] =
static_cast< proshade_single
> ( newZDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1496 void ProSHADE_internal_mapManip::allocateResolutionFourierMemory ( fftw_complex*& origMap, fftw_complex*& fCoeffs, fftw_complex*& newFCoeffs, fftw_complex*& newMap, fftw_plan& planForwardFourier, fftw_plan& planBackwardRescaledFourier, proshade_unsign xDimOld, proshade_unsign yDimOld, proshade_unsign zDimOld, proshade_unsign xDimNew, proshade_unsign yDimNew, proshade_unsign zDimNew )
1499 origMap =
new fftw_complex [xDimOld * yDimOld * zDimOld];
1500 fCoeffs =
new fftw_complex [xDimOld * yDimOld * zDimOld];
1501 newFCoeffs =
new fftw_complex [xDimNew * yDimNew * zDimNew];
1502 newMap =
new fftw_complex [xDimNew * yDimNew * zDimNew];
1511 planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimOld ),
static_cast< int > ( yDimOld ),
static_cast< int > ( zDimOld ), origMap, fCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
1512 planBackwardRescaledFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimNew ),
static_cast< int > ( yDimNew ),
static_cast< int > ( zDimNew ), newFCoeffs, newMap, FFTW_BACKWARD, FFTW_ESTIMATE );
1533 fftw_destroy_plan ( planForwardFourier );
1534 fftw_destroy_plan ( planBackwardRescaledFourier );
1539 delete[] newFCoeffs;
1562 proshade_signed h = 0, k = 0, l = 0, origSizeArr = 0, newSizeArr = 0;
1563 proshade_signed xSeq1FreqStart, ySeq1FreqStart, zSeq1FreqStart, xSeq2FreqStart, ySeq2FreqStart, zSeq2FreqStart;
1566 if ( negativeFirst )
1568 if ( ( xDim % 2 ) == 0 ) { xSeq1FreqStart = xDim / 2; xSeq2FreqStart = xDim / 2; }
else { xSeq1FreqStart = (xDim / 2) + 1; xSeq2FreqStart = xDim / 2; }
1569 if ( ( yDim % 2 ) == 0 ) { ySeq1FreqStart = yDim / 2; ySeq2FreqStart = yDim / 2; }
else { ySeq1FreqStart = (yDim / 2) + 1; ySeq2FreqStart = yDim / 2; }
1570 if ( ( zDim % 2 ) == 0 ) { zSeq1FreqStart = zDim / 2; zSeq2FreqStart = zDim / 2; }
else { zSeq1FreqStart = (zDim / 2) + 1; zSeq2FreqStart = zDim / 2; }
1574 if ( ( xDim % 2 ) == 0 ) { xSeq1FreqStart = xDim / 2; xSeq2FreqStart = xDim / 2; }
else { xSeq1FreqStart = (xDim / 2); xSeq2FreqStart = xDim / 2 + 1; }
1575 if ( ( yDim % 2 ) == 0 ) { ySeq1FreqStart = yDim / 2; ySeq2FreqStart = yDim / 2; }
else { ySeq1FreqStart = (yDim / 2); ySeq2FreqStart = yDim / 2 + 1; }
1576 if ( ( zDim % 2 ) == 0 ) { zSeq1FreqStart = zDim / 2; zSeq2FreqStart = zDim / 2; }
else { zSeq1FreqStart = (zDim / 2); zSeq2FreqStart = zDim / 2 + 1; }
1580 fftw_complex *hlpFCoeffs =
new fftw_complex [xDim * yDim * zDim];
1584 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1587 if ( xIt < xSeq1FreqStart ) { h = xIt + xSeq2FreqStart; }
else { h = xIt - xSeq1FreqStart; }
1588 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1591 if ( yIt < ySeq1FreqStart ) { k = yIt + ySeq2FreqStart; }
else { k = yIt - ySeq1FreqStart; }
1593 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1596 if ( zIt < zSeq1FreqStart ) { l = zIt + zSeq2FreqStart; }
else { l = zIt - zSeq1FreqStart; }
1599 newSizeArr = l + zDim * ( k + yDim * h );
1600 origSizeArr = zIt + zDim * ( yIt + yDim * xIt );
1603 hlpFCoeffs[newSizeArr][0] = fCoeffs[origSizeArr][0];
1604 hlpFCoeffs[newSizeArr][1] = fCoeffs[origSizeArr][1];
1610 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDim * yDim * zDim ); iter++ ) { fCoeffs[iter][0] = hlpFCoeffs[iter][0]; fCoeffs[iter][1] = hlpFCoeffs[iter][1]; }
1613 delete[] hlpFCoeffs;
1634 proshade_double real, imag, mag, phase;
1635 proshade_unsign arrayPos = 0;
1636 proshade_double normFactor =
static_cast<proshade_double
> ( xDim * yDim * zDim );
1639 for ( proshade_unsign uIt = 0; uIt < xDim; uIt++ )
1641 for ( proshade_unsign vIt = 0; vIt < yDim; vIt++ )
1643 for ( proshade_unsign wIt = 0; wIt < zDim; wIt++ )
1646 arrayPos = wIt + zDim * ( vIt + yDim * uIt );
1647 real = mapCoeffs[arrayPos][0];
1648 imag = mapCoeffs[arrayPos][1];
1651 mag = std::sqrt ( (real*real) + (imag*imag) );;
1655 mapCoeffs[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
1656 mapCoeffs[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
1683 proshade_signed xDim =
static_cast< proshade_signed
> ( xDimS );
1684 proshade_signed yDim =
static_cast< proshade_signed
> ( yDimS );
1685 proshade_signed zDim =
static_cast< proshade_signed
> ( zDimS );
1686 proshade_signed currentPos, neighArrPos, neighXPos, neighYPos, neighZPos;
1687 proshade_double neighSum;
1688 proshade_double neighCount = pow ( ( ( fakeMapKernel * 2 ) + 1 ), 3.0 ) - 1.0;
1691 for ( proshade_signed uIt = 0; uIt < xDim; uIt++ )
1693 for ( proshade_signed vIt = 0; vIt < yDim; vIt++ )
1695 for ( proshade_signed wIt = 0; wIt < zDim; wIt++ )
1698 currentPos = wIt + zDim * ( vIt + yDim * uIt );
1702 for ( proshade_signed xCh = -fakeMapKernel; xCh <= +fakeMapKernel; xCh++ )
1704 for ( proshade_signed yCh = -fakeMapKernel; yCh <= +fakeMapKernel; yCh++ )
1706 for ( proshade_signed zCh = -fakeMapKernel; zCh <= +fakeMapKernel; zCh++ )
1708 if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) {
continue; }
1711 neighXPos = uIt + xCh;
if ( neighXPos >= xDim ) { neighXPos -= xDim; };
if ( neighXPos < 0 ) { neighXPos += xDim; }
1712 neighYPos = vIt + yCh;
if ( neighYPos >= yDim ) { neighYPos -= yDim; };
if ( neighYPos < 0 ) { neighYPos += yDim; }
1713 neighZPos = wIt + zCh;
if ( neighZPos >= zDim ) { neighZPos -= zDim; };
if ( neighZPos < 0 ) { neighZPos += zDim; }
1714 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1717 neighSum += map[neighArrPos];
1723 fakeHalfMap[currentPos] = neighSum / neighCount;
1748 proshade_signed xDim =
static_cast< proshade_signed
> ( xDimS ), yDim =
static_cast< proshade_signed
> ( yDimS ), zDim =
static_cast< proshade_signed
> ( zDimS ), currentPos, neighArrPos, neighXPos, neighYPos, neighZPos, corrIter;
1749 proshade_unsign noCorrVals =
static_cast<proshade_unsign
> ( pow ( ( ( corrMaskKernel * 2 ) + 1 ), 3 ) );
1752 proshade_double *origMap =
new proshade_double [noCorrVals];
1753 proshade_double *fakeHM =
new proshade_double [noCorrVals];
1760 for ( proshade_signed uIt = 0; uIt < xDim; uIt++ )
1762 for ( proshade_signed vIt = 0; vIt < yDim; vIt++ )
1764 for ( proshade_signed wIt = 0; wIt < zDim; wIt++ )
1767 currentPos = wIt + zDim * ( vIt + yDim * uIt );
1771 for ( proshade_signed xCh = -corrMaskKernel; xCh <= +corrMaskKernel; xCh++ )
1773 for ( proshade_signed yCh = -corrMaskKernel; yCh <= +corrMaskKernel; yCh++ )
1775 for ( proshade_signed zCh = -corrMaskKernel; zCh <= +corrMaskKernel; zCh++ )
1778 neighXPos = uIt + xCh;
if ( neighXPos >= xDim ) { neighXPos -= xDim; };
if ( neighXPos < 0 ) { neighXPos += xDim; }
1779 neighYPos = vIt + yCh;
if ( neighYPos >= yDim ) { neighYPos -= yDim; };
if ( neighYPos < 0 ) { neighYPos += yDim; }
1780 neighZPos = wIt + zCh;
if ( neighZPos >= zDim ) { neighZPos -= zDim; };
if ( neighZPos < 0 ) { neighZPos += zDim; }
1781 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1784 origMap[corrIter] = map[neighArrPos];
1785 fakeHM[corrIter] = fakeHalfMap[neighArrPos];
1820 std::max ( dist / ( yAngs /
static_cast<proshade_single
> ( yDim ) ),
1821 dist / ( zAngs /
static_cast<proshade_single
> ( zDim ) ) ) ) ) );
1839 void ProSHADE_internal_mapManip::connectMaskBlobs ( proshade_double*& mask, proshade_signed xDim, proshade_signed yDim, proshade_signed zDim, proshade_single xAngs, proshade_single yAngs, proshade_single zAngs, proshade_single maskThres )
1842 proshade_double* hlpMap =
new proshade_double[xDim * yDim * zDim];
1843 proshade_signed addSurroundingPoints =
static_cast< proshade_signed
> ( std::max ( 3L,
static_cast<proshade_signed
> ( std::ceil (
getIndicesFromAngstroms(
static_cast< proshade_unsign
> ( xDim ),
static_cast< proshade_unsign
> ( yDim ),
static_cast< proshade_unsign
> ( zDim ), xAngs, yAngs, zAngs,
static_cast< proshade_single
> ( std::max( xAngs, std::max( yAngs, zAngs ) ) * 0.1f ) ) ) ) ) );
1844 proshade_signed currPos, neighXPos, neighYPos, neighZPos, neighArrPos;
1850 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDim * yDim * zDim ); iter++ ) { hlpMap[iter] = mask[iter]; }
1853 for ( proshade_signed it = 0; it < addSurroundingPoints; it++ )
1856 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1858 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1860 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1863 currPos = zIt + zDim * ( yIt + yDim * xIt );
1866 if ( hlpMap[currPos] <
static_cast< proshade_double
> ( maskThres ) ) {
continue; }
1869 for ( proshade_signed xCh = -1; xCh <= +1; xCh++ )
1871 for ( proshade_signed yCh = -1; yCh <= +1; yCh++ )
1873 for ( proshade_signed zCh = -1; zCh <= +1; zCh++ )
1875 if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) {
continue; }
1878 neighXPos = xIt + xCh;
if ( neighXPos < 0 ) {
continue; }
if ( neighXPos >= xDim ) {
continue; }
1879 neighYPos = yIt + yCh;
if ( neighYPos < 0 ) {
continue; }
if ( neighYPos >= yDim ) {
continue; }
1880 neighZPos = zIt + zCh;
if ( neighZPos < 0 ) {
continue; }
if ( neighZPos >= zDim ) {
continue; }
1881 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1884 if ( hlpMap[neighArrPos] <
static_cast< proshade_double
> ( maskThres ) ) { mask[neighArrPos] =
static_cast< proshade_double
> ( maskThres ); }
1893 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDim * yDim * zDim ); iter++ ) { hlpMap[iter] = mask[iter]; }
1919 while ( bounds[1] >=
static_cast<proshade_signed
> ( xDim ) ) { xDim += 10; }
1920 while ( bounds[3] >=
static_cast<proshade_signed
> ( yDim ) ) { yDim += 10; }
1921 while ( bounds[5] >=
static_cast<proshade_signed
> ( zDim ) ) { zDim += 10; }
1924 proshade_signed addToX =
betterClosePrimeFactors ( bounds[1] - bounds[0] + 1,
static_cast< proshade_signed
> ( xDim ) );
1925 proshade_signed addToY =
betterClosePrimeFactors ( bounds[3] - bounds[2] + 1,
static_cast< proshade_signed
> ( yDim ) );
1926 proshade_signed addToZ =
betterClosePrimeFactors ( bounds[5] - bounds[4] + 1,
static_cast< proshade_signed
> ( zDim ) );
1929 proshade_signed XtoY = std::abs ( addToX - addToY );
1930 proshade_signed XtoZ = std::abs ( addToX - addToZ );
1931 proshade_signed YtoZ = std::abs ( addToY - addToZ );
1933 if ( ( ( XtoY < boundsDiffThres ) && ( XtoZ < boundsDiffThres ) ) ||
1934 ( ( XtoY < boundsDiffThres ) && ( YtoZ < boundsDiffThres ) ) ||
1935 ( ( XtoZ < boundsDiffThres ) && ( YtoZ < boundsDiffThres ) ) )
1938 proshade_signed maxSize = std::max ( addToX, std::max ( addToY, addToZ ) );
1946 if ( XtoY <= boundsDiffThres )
1948 proshade_signed maxSize = std::max ( addToX, addToY );
1952 if ( XtoZ <= boundsDiffThres )
1954 proshade_signed maxSize = std::max ( addToX, addToZ );
1958 if ( YtoZ <= boundsDiffThres )
1960 proshade_signed maxSize = std::max ( addToY, addToZ );
1989 proshade_signed ret = fromRange;
1990 std::vector < proshade_signed > posibles, hlp;
1991 proshade_signed sum;
1994 for ( proshade_signed iter = fromRange; iter < toRange; iter++ )
1998 for ( proshade_unsign i = 0; i < static_cast<proshade_unsign> ( hlp.size() ); i++ ) { sum += hlp.at(i); }
2004 for ( proshade_signed iter = fromRange; iter < toRange; iter++ )
2007 if ( iter %2 != 0 ) {
continue; }
2010 if ( posibles.at(
static_cast< size_t > ( iter - fromRange ) ) < ( posibles.at(
static_cast< size_t > ( ret - fromRange ) ) - ( iter - ret ) ) ) { ret = iter; }
2014 if ( ( ret % 2 != 0 ) && ( ret < ( toRange - 1 ) ) ) { ret += 1; }
2035 if ( newBoundRange > oldBoundRange )
2038 proshade_signed distributeThis = newBoundRange - oldBoundRange;
2040 while ( distributeThis != 0 )
2043 distributeThis -= 1;
2045 if ( distributeThis != 0 )
2048 distributeThis -= 1;
2082 void ProSHADE_internal_mapManip::copyMapByBounds ( proshade_signed xFrom, proshade_signed xTo, proshade_signed yFrom, proshade_signed yTo, proshade_signed zFrom, proshade_signed zTo, proshade_signed origXFrom, proshade_signed origYFrom, proshade_signed origZFrom, proshade_unsign yDimIndices, proshade_unsign zDimIndices, proshade_unsign origXDimIndices, proshade_unsign origYDimIndices, proshade_unsign origZDimIndices, proshade_double*& newMap, proshade_double* origMap )
2085 proshade_signed newMapIndex, oldMapIndex, oldX, oldY, oldZ, newX, newY, newZ;
2088 for ( proshade_signed xIt = xFrom; xIt <= xTo; xIt++ )
2091 newX = ( xIt - xFrom );
2092 oldX = ( newX + ( xFrom - origXFrom ) );
2094 for ( proshade_signed yIt = yFrom; yIt <= yTo; yIt++ )
2097 newY = ( yIt - yFrom );
2098 oldY = ( newY + ( yFrom - origYFrom ) );
2100 for ( proshade_signed zIt = zFrom; zIt <= zTo; zIt++ )
2103 newZ = ( zIt - zFrom );
2104 oldZ = ( newZ + ( zFrom - origZFrom ) );
2107 newMapIndex = newZ +
static_cast< proshade_signed
> ( zDimIndices ) * ( newY +
static_cast< proshade_signed
> ( yDimIndices ) * newX );
2108 oldMapIndex = oldZ +
static_cast< proshade_signed
> ( origZDimIndices ) * ( oldY +
static_cast< proshade_signed
> ( origYDimIndices ) * oldX );
2111 if ( ( ( oldX < 0 ) || ( oldX >=
static_cast< proshade_signed
> ( origXDimIndices ) ) ) ||
2112 ( ( oldY < 0 ) || ( oldY >=
static_cast< proshade_signed
> ( origYDimIndices ) ) ) ||
2113 ( ( oldZ < 0 ) || ( oldZ >=
static_cast< proshade_signed
> ( origZDimIndices ) ) ) )
2116 newMap[newMapIndex] = 0.0;
2121 newMap[newMapIndex] = origMap[oldMapIndex];