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 ) );
260 const FloatingPoint< proshade_double > lhs ( map[arrPos] );
261 if ( !lhs.AlmostEquals ( lhs ) ) { map[arrPos] = 0.0;
continue; }
263 if ( map[arrPos] > 0.0 )
265 totDensity += map[arrPos];
266 *xCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( xIt ) * xSampRate ) * map[arrPos];
267 *yCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( yIt ) * ySampRate ) * map[arrPos];
268 *zCom +=
static_cast<proshade_double
> (
static_cast< proshade_single
> ( zIt ) * zSampRate ) * map[arrPos];
299 proshade_double yCom, proshade_double zCom,
bool firstModel )
302 proshade_double *rotMat =
new proshade_double[9];
307 proshade_double xTmp, yTmp, zTmp;
310 if ( pdbFile->models.size() > 0 )
313 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
316 gemmi::Model *model = &pdbFile->models.at(sIt);
319 if ( firstModel && ( sIt != 0 ) ) {
break; }
322 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
325 gemmi::Chain *chain = &model->chains.at(mIt);
328 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
331 gemmi::Residue *residue = &chain->residues.at(rIt);
334 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
337 gemmi::Atom *atom = &residue->atoms.at(aIt);
340 xTmp =
static_cast< proshade_double
> ( atom->pos.x - xCom );
341 yTmp =
static_cast< proshade_double
> ( atom->pos.y - yCom );
342 zTmp =
static_cast< proshade_double
> ( atom->pos.z - zCom );
345 atom->pos.x = ( xTmp * rotMat[0] ) + ( yTmp * rotMat[1] ) + ( zTmp * rotMat[2] );
346 atom->pos.y = ( xTmp * rotMat[3] ) + ( yTmp * rotMat[4] ) + ( zTmp * rotMat[5] );
347 atom->pos.z = ( xTmp * rotMat[6] ) + ( yTmp * rotMat[7] ) + ( zTmp * rotMat[8] );
350 atom->pos.x = atom->pos.x + xCom;
351 atom->pos.y = atom->pos.y + yCom;
352 atom->pos.z = atom->pos.z + zCom;
360 std::stringstream hlpSS;
361 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
362 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
386 if ( pdbFile->models.size() > 0 )
389 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
392 if ( firstModel && ( sIt != 0 ) ) {
break; }
395 gemmi::Model *model = &pdbFile->models.at(sIt);
398 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
401 gemmi::Chain *chain = &model->chains.at(mIt);
404 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
407 gemmi::Residue *residue = &chain->residues.at(rIt);
410 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
413 gemmi::Atom *atom = &residue->atoms.at(aIt);
416 atom->pos.x += transX;
417 atom->pos.y += transY;
418 atom->pos.z += transZ;
426 std::stringstream hlpSS;
427 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
428 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
449 if ( pdbFile->models.size() > 0 )
452 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
455 if ( firstModel && ( sIt != 0 ) ) {
break; }
458 gemmi::Model *model = &pdbFile->models.at(sIt);
461 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
464 gemmi::Chain *chain = &model->chains.at(mIt);
467 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
470 gemmi::Residue *residue = &chain->residues.at(rIt);
473 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
476 gemmi::Atom *atom = &residue->atoms.at(aIt);
479 atom->b_iso =
static_cast< float > ( newBFactorValue );
487 std::stringstream hlpSS;
488 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
489 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
509 if ( pdbFile->models.size() > 0 )
512 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
515 if ( firstModel && ( sIt != 0 ) ) {
break; }
518 gemmi::Model *model = &pdbFile->models.at(sIt);
521 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
524 gemmi::Chain *chain = &model->chains.at(mIt);
527 std::vector< proshade_unsign > delVec;
530 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
533 gemmi::Residue *residue = &chain->residues.at(rIt);
536 if ( residue->is_water() )
543 std::sort ( delVec.begin(), delVec.end(), std::greater<int>() );
544 for ( proshade_unsign vecIt = 0; vecIt < static_cast<proshade_unsign> ( delVec.size() ); vecIt++ )
546 chain->residues.erase ( chain->residues.begin() +
static_cast< long int > ( delVec.at(vecIt) ) );
553 std::stringstream hlpSS;
554 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
555 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
578 if ( pdbFile->models.size() > 0 )
581 for ( proshade_unsign sIt = 0; sIt < static_cast<proshade_unsign> ( pdbFile->models.size() ); sIt++ )
584 if ( firstModel && ( sIt != 0 ) ) {
break; }
587 gemmi::Model *model = &pdbFile->models.at(sIt);
590 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( model->chains.size() ); mIt++ )
593 gemmi::Chain *chain = &model->chains.at(mIt);
596 for ( proshade_unsign rIt = 0; rIt < static_cast<proshade_unsign> ( chain->residues.size() ); rIt++ )
599 gemmi::Residue *residue = &chain->residues.at(rIt);
602 for ( proshade_unsign aIt = 0; aIt < static_cast<proshade_unsign> ( residue->atoms.size() ); aIt++ )
605 gemmi::Atom *atom = &residue->atoms.at(aIt);
608 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 ) );
617 std::stringstream hlpSS;
618 hlpSS <<
"Found 0 models in input file " << pdbFile->name <<
".\n : This suggests that the input co-ordinate file is\n : corrupted or mis-formatted.";
619 throw ProSHADE_exception (
"Found no model in co-ordinate file.",
"EP00050", __FILE__, __LINE__, __func__, hlpSS.str() );
646 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 )
649 if ( forceP1 ) { pdbFile.cell = gemmi::UnitCell(); }
650 pdbFile.cell.a =
static_cast< proshade_double
> ( xCell );
651 pdbFile.cell.b =
static_cast< proshade_double
> ( yCell );
652 pdbFile.cell.c =
static_cast< proshade_double
> ( zCell );
653 pdbFile.cell.calculate_properties ( );
656 std::string totElString;
657 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); mIt++ )
660 if ( firstModel && ( mIt != 0 ) )
662 std::stringstream hlpSS;
663 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.";
668 std::string hlpStr = pdbFile.models[mIt].present_elements ( ).to_string<char,std::char_traits<char>,std::allocator<char> >();
669 totElString = totElString + hlpStr;
671 std::bitset< static_cast< size_t > ( gemmi::El::END )> present_elems ( totElString );
674 if ( present_elems[
static_cast<int> ( gemmi::El::X )] )
676 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." );
679 for ( proshade_unsign elIt = 0; elIt < static_cast<proshade_unsign> ( present_elems.size() ); elIt++ )
681 if ( present_elems[elIt] && !gemmi::IT92<double>::has (
static_cast<gemmi::El
> ( elIt ) ) )
683 std::stringstream hlpSS;
684 hlpSS <<
"Missing form factor for element " << element_name (
static_cast<gemmi::El
> ( elIt ) );
685 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." );
690 double wavelength = 10.0;
691 double energy = gemmi::hc() / wavelength;
694 gemmi::DensityCalculator<gemmi::IT92<double>,
float> dencalc;
696 dencalc.d_min =
static_cast< double > ( requestedResolution );
697 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_liberman (
static_cast< int > ( elIt ), energy,
nullptr ) ) ); } }
698 dencalc.set_grid_cell_and_spacegroup ( pdbFile );
701 if ( forceP1 ) { dencalc.grid.spacegroup = &gemmi::get_spacegroup_p1(); }
704 dencalc.grid.data.clear ( );
705 dencalc.grid.set_size_from_spacing ( dencalc.d_min / ( 2.0 * dencalc.rate),
true );
706 for ( proshade_unsign mIt = 0; mIt < static_cast<proshade_unsign> ( pdbFile.models.size() ); mIt++ )
708 if ( firstModel && ( mIt != 0 ) ) {
break; }
709 dencalc.add_model_density_to_grid ( pdbFile.models[mIt] );
710 dencalc.grid.symmetrize ( [](
float a,
float b) {
return a + b; } );
714 const gemmi::Grid<float>& grid = dencalc.grid;
722 map =
new proshade_double [(*xTo) * (*yTo) * (*zTo)];
725 proshade_signed arrPos = 0;
726 for ( proshade_signed uIt = 0; uIt < (*xTo); uIt++ )
728 for ( proshade_signed vIt = 0; vIt < (*yTo); vIt++ )
730 for ( proshade_signed wIt = 0; wIt < (*zTo); wIt++ )
732 arrPos = wIt + (*zTo) * ( vIt + (*yTo) * uIt );
733 map[arrPos] =
static_cast< proshade_double
> ( grid.get_value_q(
static_cast< int > ( uIt ),
static_cast< int > ( vIt ),
static_cast< int > ( wIt ) ) );
765 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 )
768 proshade_single xIndMove = std::floor ( -(*xMov) / ( xAngs / (
static_cast< proshade_single
> ( *xTo ) -
static_cast< proshade_single
> ( *xFrom ) + 1.0f ) ) );
769 proshade_single yIndMove = std::floor ( -(*yMov) / ( yAngs / (
static_cast< proshade_single
> ( *yTo ) -
static_cast< proshade_single
> ( *yFrom ) + 1.0f ) ) );
770 proshade_single zIndMove = std::floor ( -(*zMov) / ( zAngs / (
static_cast< proshade_single
> ( *zTo ) -
static_cast< proshade_single
> ( *zFrom ) + 1.0f ) ) );
773 *xMov = -( *xMov ) - ( xIndMove * ( xAngs / (
static_cast< proshade_single
> ( *xTo ) -
static_cast< proshade_single
> ( *xFrom ) + 1.0f ) ) );
774 *yMov = -( *yMov ) - ( yIndMove * ( yAngs / (
static_cast< proshade_single
> ( *yTo ) -
static_cast< proshade_single
> ( *yFrom ) + 1.0f ) ) );
775 *zMov = -( *zMov ) - ( zIndMove * ( zAngs / (
static_cast< proshade_single
> ( *zTo ) -
static_cast< proshade_single
> ( *zFrom ) + 1.0f ) ) );
778 *xFrom +=
static_cast< proshade_signed
> ( xIndMove );
779 *xTo +=
static_cast< proshade_signed
> ( xIndMove );
780 *yFrom +=
static_cast< proshade_signed
> ( yIndMove );
781 *yTo +=
static_cast< proshade_signed
> ( yIndMove );
782 *zFrom +=
static_cast< proshade_signed
> ( zIndMove );
783 *zTo +=
static_cast< proshade_signed
> ( zIndMove );
813 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 )
816 proshade_unsign arrayPos = 0;
819 fftw_complex *fCoeffs =
new fftw_complex [xDim * yDim * zDim];
820 fftw_complex *translatedMap =
new fftw_complex [xDim * yDim * zDim];
827 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 );
828 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 );
831 for ( proshade_unsign uIt = 0; uIt < static_cast< proshade_unsign > ( xDim ); uIt++ )
833 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( yDim ); vIt++ )
835 for ( proshade_unsign wIt = 0; wIt < static_cast< proshade_unsign > ( zDim ); wIt++ )
837 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
839 const FloatingPoint< proshade_double > lhs ( map[arrayPos] ), rhs ( map[arrayPos] );
840 if ( lhs.AlmostEquals ( rhs ) ) { translatedMap[arrayPos][0] = map[arrayPos]; }
841 else { translatedMap[arrayPos][0] = 0.0; }
842 translatedMap[arrayPos][1] = 0.0;
848 fftw_execute ( planForwardFourier );
851 proshade_double *weight =
nullptr;
852 moveMapByFourierInReci ( fCoeffs, weight, xMov, yMov, zMov, xAngs, yAngs, zAngs, xDim, yDim, zDim );
855 fftw_execute ( planBackwardFourier );
858 for ( proshade_unsign uIt = 0; uIt < static_cast< proshade_unsign > ( xDim ); uIt++ )
860 for ( proshade_unsign vIt = 0; vIt < static_cast< proshade_unsign > ( yDim ); vIt++ )
862 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 map[arrayPos] = translatedMap[arrayPos][0];
871 fftw_destroy_plan ( planForwardFourier );
872 fftw_destroy_plan ( planBackwardFourier );
874 delete[] translatedMap;
898 void ProSHADE_internal_mapManip::moveMapByFourierInReci ( proshade_complex*& coeffs, proshade_double*& weights, 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 )
901 proshade_unsign arrayPos = 0;
902 proshade_signed h, k, l;
903 proshade_double real = 0.0;
904 proshade_double imag = 0.0;
905 proshade_double trCoeffReal, trCoeffImag;
906 proshade_double normFactor =
static_cast< proshade_double
> ( xDim * yDim * zDim );
907 proshade_double exponent = 0.0;
908 proshade_double hlpArrReal;
909 proshade_double hlpArrImag;
912 proshade_double* wght =
new proshade_double[xDim * yDim * zDim];
914 if ( weights ==
nullptr ) {
for (
size_t iter = 0; iter < static_cast< size_t > ( xDim * yDim * zDim ); iter++ ) { wght[iter] = 1.0; } }
915 else {
for (
size_t iter = 0; iter < static_cast< size_t > ( xDim * yDim * zDim ); iter++ ) { wght[iter] = weights[iter]; } }
918 for ( proshade_unsign uIt = 0; uIt < static_cast<proshade_unsign> ( xDim ); uIt++ )
920 for ( proshade_unsign vIt = 0; vIt < static_cast<proshade_unsign> ( yDim ); vIt++ )
922 for ( proshade_unsign wIt = 0; wIt < static_cast<proshade_unsign> ( zDim ); wIt++ )
925 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
926 real = coeffs[arrayPos][0];
927 imag = coeffs[arrayPos][1];
930 if ( uIt >
static_cast< proshade_unsign
> ( (xDim+1) / 2) ) { h =
static_cast < proshade_signed
> ( uIt ) - xDim; }
else { h =
static_cast < proshade_signed
> ( uIt ); }
931 if ( vIt >
static_cast< proshade_unsign
> ( (yDim+1) / 2) ) { k =
static_cast < proshade_signed
> ( vIt ) - yDim; }
else { k =
static_cast < proshade_signed
> ( vIt ); }
932 if ( wIt >
static_cast< proshade_unsign
> ( (zDim+1) / 2) ) { l =
static_cast < proshade_signed
> ( wIt ) - zDim; }
else { l =
static_cast < proshade_signed
> ( wIt ); }
935 exponent = ( ( (
static_cast <proshade_double
> ( h ) /
static_cast <proshade_double
> ( xAngs ) ) *
static_cast< proshade_double
> ( -xMov ) ) +
936 ( (
static_cast <proshade_double
> ( k ) /
static_cast <proshade_double
> ( yAngs ) ) *
static_cast< proshade_double
> ( -yMov ) ) +
937 ( (
static_cast <proshade_double
> ( l ) /
static_cast <proshade_double
> ( zAngs ) ) *
static_cast< proshade_double
> ( -zMov ) ) ) * 2.0 * M_PI;
939 trCoeffReal = cos ( exponent );
940 trCoeffImag = sin ( exponent );
944 coeffs[arrayPos][0] = ( hlpArrReal / normFactor ) * wght[arrayPos];
945 coeffs[arrayPos][1] = ( hlpArrImag / normFactor ) * wght[arrayPos];
974 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 )
977 proshade_signed xDim =
static_cast< proshade_signed
> ( xDimS );
978 proshade_signed yDim =
static_cast< proshade_signed
> ( yDimS );
979 proshade_signed zDim =
static_cast< proshade_signed
> ( zDimS );
980 proshade_double real, imag, S, mag, phase;
981 proshade_signed h, k, l;
982 proshade_unsign arrayPos = 0;
983 proshade_double normFactor =
static_cast<proshade_double
> ( xDim * yDim * zDim );
986 fftw_complex* mapCoeffs =
new fftw_complex[xDim * yDim * zDim];
987 fftw_complex* mapMask =
new fftw_complex[xDim * yDim * zDim];
994 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> (xDim * yDim * zDim); iter++ )
996 mapMask[iter][0] = map[iter];
997 mapMask[iter][1] = 0.0;
1001 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 );
1002 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 );
1005 fftw_execute ( forward );
1008 for ( proshade_unsign uIt = 0; uIt < static_cast<proshade_unsign> ( xDim ); uIt++ )
1010 for ( proshade_unsign vIt = 0; vIt < static_cast<proshade_unsign> ( yDim ); vIt++ )
1012 for ( proshade_unsign wIt = 0; wIt < static_cast<proshade_unsign> ( zDim ); wIt++ )
1015 arrayPos = wIt +
static_cast< proshade_unsign
> ( zDim ) * ( vIt +
static_cast< proshade_unsign
> ( yDim ) * uIt );
1016 real = mapCoeffs[arrayPos][0];
1017 imag = mapCoeffs[arrayPos][1];
1020 if ( uIt >
static_cast< proshade_unsign
> ( (xDim+1) / 2) ) { h =
static_cast < proshade_signed
> ( uIt ) - xDim; }
else { h =
static_cast < proshade_signed
> ( uIt ); }
1021 if ( vIt >
static_cast< proshade_unsign
> ( (yDim+1) / 2) ) { k =
static_cast < proshade_signed
> ( vIt ) - yDim; }
else { k =
static_cast < proshade_signed
> ( vIt ); }
1022 if ( wIt >
static_cast< proshade_unsign
> ( (zDim+1) / 2) ) { l =
static_cast < proshade_signed
> ( wIt ) - zDim; }
else { l =
static_cast < proshade_signed
> ( wIt ); }
1025 S = ( pow(
static_cast< proshade_double
> ( h ) /
static_cast< proshade_double
> ( xAngs ), 2.0 ) +
1026 pow(
static_cast< proshade_double
> ( k ) /
static_cast< proshade_double
> ( yAngs ), 2.0 ) +
1027 pow(
static_cast< proshade_double
> ( l ) /
static_cast< proshade_double
> ( zAngs ), 2.0 ) );
1028 mag = std::sqrt ( (real*real) + (imag*imag) ) * std::exp ( - ( (
static_cast< proshade_double
> ( blurringFactor ) * S ) / 4.0 ) );
1029 phase = std::atan2 ( imag, real );
1032 mapCoeffs[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
1033 mapCoeffs[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
1039 fftw_execute ( inverse );
1042 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> (xDim * yDim * zDim); iter++ )
1044 blurredMap[iter] = mapMask[iter][0];
1052 fftw_destroy_plan ( forward );
1053 fftw_destroy_plan ( inverse );
1077 std::vector<proshade_double> mapVals ( xDim * yDim * zDim, 0.0 );
1080 for ( proshade_unsign iter = 0; iter < ( xDim * yDim * zDim ); iter++ )
1082 mapVals.at(iter) = blurMap[iter];
1086 proshade_double* medAndIQR =
new proshade_double[2];
1090 proshade_double maskThreshold = medAndIQR[0] + ( medAndIQR[1] *
static_cast<proshade_double
> ( noIQRs ) );
1093 for ( proshade_unsign iter = 0; iter < ( xDim * yDim * zDim ); iter++ )
1095 if ( blurMap[iter] < maskThreshold )
1098 blurMap[iter] = 0.0;
1127 proshade_signed arrayPos = 0;
1138 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1140 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1142 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1145 arrayPos = zIt + zDim * ( yIt + yDim * xIt );
1148 if ( map[arrayPos] > 0.001 )
1150 if ( xIt < ret[0] ) { ret[0] = xIt; }
1151 if ( xIt > ret[1] ) { ret[1] = xIt; }
1152 if ( yIt < ret[2] ) { ret[2] = yIt; }
1153 if ( yIt > ret[3] ) { ret[3] = yIt; }
1154 if ( zIt < ret[4] ) { ret[4] = zIt; }
1155 if ( zIt > ret[5] ) { ret[5] = zIt; }
1189 bounds[0] = bounds[0] - xExtraInds;
1190 bounds[1] = bounds[1] + xExtraInds;
1191 bounds[2] = bounds[2] - yExtraInds;
1192 bounds[3] = bounds[3] + yExtraInds;
1193 bounds[4] = bounds[4] - zExtraInds;
1194 bounds[5] = bounds[5] + zExtraInds;
1220 if ( resolution <= 0.0f )
1222 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." );
1226 proshade_signed xDim =
static_cast<proshade_signed
> ( xDimS );
1227 proshade_signed yDim =
static_cast<proshade_signed
> ( yDimS );
1228 proshade_signed zDim =
static_cast<proshade_signed
> ( zDimS );
1229 proshade_single oldXSample = ( xAngs /
static_cast<proshade_single
> ( xDim ) );
1230 proshade_single oldYSample = ( yAngs /
static_cast<proshade_single
> ( yDim ) );
1231 proshade_single oldZSample = ( zAngs /
static_cast<proshade_single
> ( zDim ) );
1232 proshade_single newXSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1233 proshade_single newYSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1234 proshade_single newZSample =
static_cast< proshade_single
> ( resolution / 2.0f );
1237 proshade_signed newXDim =
static_cast<proshade_signed
> ( std::ceil ( xAngs / newXSample ) );
1238 proshade_signed newYDim =
static_cast<proshade_signed
> ( std::ceil ( yAngs / newYSample ) );
1239 proshade_signed newZDim =
static_cast<proshade_signed
> ( std::ceil ( zAngs / newZSample ) );
1242 proshade_double* newMap =
new proshade_double [newXDim * newYDim * newZDim];
1245 proshade_signed xBottom = 0, xTop, yBottom = 0, yTop, zBottom = 0, zTop, oldMapIndex, newMapIndex;
1246 std::vector<proshade_double> c000 = std::vector<proshade_double> ( 4, 0.0 );
1247 std::vector<proshade_double> c001 = std::vector<proshade_double> ( 4, 0.0 );
1248 std::vector<proshade_double> c010 = std::vector<proshade_double> ( 4, 0.0 );
1249 std::vector<proshade_double> c011 = std::vector<proshade_double> ( 4, 0.0 );
1250 std::vector<proshade_double> c100 = std::vector<proshade_double> ( 4, 0.0 );
1251 std::vector<proshade_double> c101 = std::vector<proshade_double> ( 4, 0.0 );
1252 std::vector<proshade_double> c110 = std::vector<proshade_double> ( 4, 0.0 );
1253 std::vector<proshade_double> c111 = std::vector<proshade_double> ( 4, 0.0 );
1254 std::vector<proshade_double> c00 = std::vector<proshade_double> ( 4, 0.0 );
1255 std::vector<proshade_double> c01 = std::vector<proshade_double> ( 4, 0.0 );
1256 std::vector<proshade_double> c10 = std::vector<proshade_double> ( 4, 0.0 );
1257 std::vector<proshade_double> c11 = std::vector<proshade_double> ( 4, 0.0 );
1258 std::vector<proshade_double> c0 = std::vector<proshade_double> ( 4, 0.0 );
1259 std::vector<proshade_double> c1 = std::vector<proshade_double> ( 4, 0.0 );
1260 proshade_double xRelative, yRelative, zRelative;
1262 for ( proshade_signed xIt = 0; xIt < newXDim; xIt++ )
1264 for ( proshade_signed yIt = 0; yIt < newYDim; yIt++ )
1266 for ( proshade_signed zIt = 0; zIt < newZDim; zIt++ )
1269 newMapIndex = zIt + newZDim * ( yIt + newYDim * xIt );
1272 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; } }
1273 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; } }
1274 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; } }
1280 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1281 c000.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1282 c000.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1283 c000.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1284 c000.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1286 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1287 c001.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1288 c001.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1289 c001.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1290 c001.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1292 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1293 c010.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1294 c010.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1295 c010.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1296 c010.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1298 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xBottom );
1299 c011.at(0) =
static_cast<proshade_double
> ( xBottom ) *
static_cast<proshade_double
> ( oldXSample );
1300 c011.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1301 c011.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1302 c011.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1304 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1305 c100.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1306 c100.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1307 c100.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1308 c100.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1310 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yBottom +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1311 c101.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1312 c101.at(1) =
static_cast<proshade_double
> ( yBottom ) *
static_cast<proshade_double
> ( oldYSample );
1313 c101.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1314 c101.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1316 oldMapIndex = zBottom +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1317 c110.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1318 c110.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1319 c110.at(2) =
static_cast<proshade_double
> ( zBottom ) *
static_cast<proshade_double
> ( oldZSample );
1320 c110.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1322 oldMapIndex = zTop +
static_cast< proshade_signed
> ( zDimS ) * ( yTop +
static_cast< proshade_signed
> ( yDimS ) * xTop );
1323 c111.at(0) =
static_cast<proshade_double
> ( xTop ) *
static_cast<proshade_double
> ( oldXSample );
1324 c111.at(1) =
static_cast<proshade_double
> ( yTop ) *
static_cast<proshade_double
> ( oldYSample );
1325 c111.at(2) =
static_cast<proshade_double
> ( zTop ) *
static_cast<proshade_double
> ( oldZSample );
1326 c111.at(3) =
static_cast<proshade_double
> ( map[oldMapIndex] );
1329 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 ) ) );
1332 c00.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c000.at(0);
1333 c00.at(1) = c000.at(1);
1334 c00.at(2) = c000.at(2);
1335 c00.at(3) = ( c000.at(3) * ( 1.0 - xRelative ) ) + ( c100.at(3) * xRelative );
1338 c01.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c001.at(0);
1339 c01.at(1) = c001.at(1);
1340 c01.at(2) = c001.at(2);
1341 c01.at(3) = ( c001.at(3) * ( 1.0 - xRelative ) ) + ( c101.at(3) * xRelative );
1344 c10.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c010.at(0);
1345 c10.at(1) = c010.at(1);
1346 c10.at(2) = c010.at(2);
1347 c10.at(3) = ( c010.at(3) * ( 1.0 - xRelative ) ) + ( c110.at(3) * xRelative );
1350 c11.at(0) = (
static_cast< proshade_double
> ( newXSample ) * xRelative ) + c011.at(0);
1351 c11.at(1) = c011.at(1);
1352 c11.at(2) = c011.at(2);
1353 c11.at(3) = ( c011.at(3) * ( 1.0 - xRelative ) ) + ( c111.at(3) * xRelative );
1356 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 ) ) );
1359 c0.at(0) = c00.at(0);
1360 c0.at(1) = (
static_cast< proshade_double
> ( newYSample ) * yRelative ) + c00.at(1);
1361 c0.at(2) = c00.at(2);
1362 c0.at(3) = ( c00.at(3) * ( 1.0 - yRelative ) ) + ( c10.at(3) * yRelative );
1365 c1.at(0) = c01.at(0);
1366 c1.at(1) = (
static_cast< proshade_double
> ( newYSample ) * yRelative ) + c01.at(1);
1367 c1.at(2) = c01.at(2);
1368 c1.at(3) = ( c01.at(3) * ( 1.0 - yRelative ) ) + ( c11.at(3) * yRelative );
1371 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 ) ) );
1372 newMap[newMapIndex] = ( c0.at(3) * ( 1.0 - zRelative ) ) + ( c1.at(3) * zRelative );
1379 map =
new proshade_double [newXDim * newYDim * newZDim];
1382 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ )
1384 map[iter] = newMap[iter];
1391 corrs[0] =
static_cast< proshade_single
> ( newXDim - xDim );
1392 corrs[1] =
static_cast< proshade_single
> ( newYDim - yDim );
1393 corrs[2] =
static_cast< proshade_single
> ( newZDim - zDim );
1394 corrs[3] =
static_cast< proshade_single
> ( newXDim ) *
static_cast< proshade_single
> ( newXSample );
1395 corrs[4] =
static_cast< proshade_single
> ( newYDim ) *
static_cast< proshade_single
> ( newYSample );
1396 corrs[5] =
static_cast< proshade_single
> ( newZDim ) *
static_cast< proshade_single
> ( newZSample );
1430 if ( resolution <= 0.0f )
1432 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." );
1440 if ( newXDim % 2 != 0 ) { newXDim += 1; }
1441 if ( newYDim % 2 != 0 ) { newYDim += 1; }
1442 if ( newZDim % 2 != 0 ) { newZDim += 1; }
1444 proshade_signed preXChange, preYChange, preZChange;
1445 if ( ( xDimS % 2 ) == 0 ) { preXChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( xDimS ) -
static_cast<proshade_signed
> ( newXDim ) ) / 2 ) ); }
1446 else { preXChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( xDimS ) -
static_cast<proshade_signed
> ( newXDim ) ) / 2 ) ); }
1447 if ( ( yDimS % 2 ) == 0 ) { preYChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( yDimS ) -
static_cast<proshade_signed
> ( newYDim ) ) / 2 ) ); }
1448 else { preYChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( yDimS ) -
static_cast<proshade_signed
> ( newYDim ) ) / 2 ) ); }
1449 if ( ( zDimS % 2 ) == 0 ) { preZChange =
static_cast< proshade_signed
> ( std::ceil ( (
static_cast<proshade_signed
> ( zDimS ) -
static_cast<proshade_signed
> ( newZDim ) ) / 2 ) ); }
1450 else { preZChange =
static_cast< proshade_signed
> ( std::floor ( (
static_cast<proshade_signed
> ( zDimS ) -
static_cast<proshade_signed
> ( newZDim ) ) / 2 ) ); }
1452 proshade_signed postXChange =
static_cast<proshade_signed
> ( xDimS ) - ( preXChange +
static_cast<proshade_signed
> ( newXDim ) );
1453 proshade_signed postYChange =
static_cast<proshade_signed
> ( yDimS ) - ( preYChange +
static_cast<proshade_signed
> ( newYDim ) );
1454 proshade_signed postZChange =
static_cast<proshade_signed
> ( zDimS ) - ( preZChange +
static_cast<proshade_signed
> ( newZDim ) );
1456 proshade_unsign origSizeArr = 0, newSizeArr = 0;
1457 proshade_double normFactor =
static_cast<proshade_double
> ( xDimS * yDimS * zDimS );
1460 fftw_complex *origMap, *fCoeffs, *newFCoeffs, *newMap;
1461 fftw_plan planForwardFourier, planBackwardRescaledFourier;
1463 xDimS, yDimS, zDimS, newXDim, newYDim, newZDim );
1466 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDimS * yDimS * zDimS ); iter++ ) { origMap[iter][0] = map[iter]; origMap[iter][1] = 0.0; }
1467 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ ) { newFCoeffs[iter][0] = 0.0; newFCoeffs[iter][1] = 0.0; }
1470 fftw_execute ( planForwardFourier );
1473 changeFourierOrder ( fCoeffs,
static_cast< proshade_signed
> ( xDimS ),
static_cast< proshade_signed
> ( yDimS ),
static_cast< proshade_signed
> ( zDimS ),
true );
1476 for ( proshade_unsign xIt = 0; xIt < newXDim; xIt++ )
1478 for ( proshade_unsign yIt = 0; yIt < newYDim; yIt++ )
1480 for ( proshade_unsign zIt = 0; zIt < newZDim; zIt++ )
1483 origSizeArr = ( ( zIt +
static_cast< proshade_unsign
> ( preZChange ) ) + zDimS *
1484 ( ( yIt +
static_cast< proshade_unsign
> ( preYChange ) ) + yDimS *
1485 ( xIt +
static_cast< proshade_unsign
> ( preXChange ) ) ) );
1486 newSizeArr = zIt + newZDim * ( yIt + newYDim * xIt );
1489 if ( ( ( -1 <
static_cast< proshade_signed
> ( xIt ) + preXChange ) && ( -1 <
static_cast<proshade_signed
> ( yIt ) + preYChange ) && ( -1 <
static_cast<proshade_signed
> ( zIt ) + preZChange ) ) &&
1490 ( ( xIt < newXDim + static_cast<proshade_unsign> ( postXChange ) ) && ( yIt < newYDim +
static_cast<proshade_unsign
> ( postYChange ) ) && ( zIt < newZDim +
static_cast<proshade_unsign
> ( postZChange ) ) ) )
1493 newFCoeffs[newSizeArr][0] = fCoeffs[origSizeArr][0] / normFactor;
1494 newFCoeffs[newSizeArr][1] = fCoeffs[origSizeArr][1] / normFactor;
1501 changeFourierOrder ( newFCoeffs,
static_cast< proshade_signed
> ( newXDim ),
static_cast< proshade_signed
> ( newYDim ),
static_cast< proshade_signed
> ( newZDim ),
false );
1504 fftw_execute ( planBackwardRescaledFourier );
1508 map =
new proshade_double [newXDim * newYDim * newZDim];
1510 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( newXDim * newYDim * newZDim ); iter++ ) { map[iter] = newMap[iter][0]; }
1516 corrs[0] =
static_cast< proshade_single
> ( newXDim ) -
static_cast< proshade_single
> ( xDimS );
1517 corrs[1] =
static_cast< proshade_single
> ( newYDim ) -
static_cast< proshade_single
> ( yDimS );
1518 corrs[2] =
static_cast< proshade_single
> ( newZDim ) -
static_cast< proshade_single
> ( zDimS );
1519 corrs[3] =
static_cast< proshade_single
> ( newXDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1520 corrs[4] =
static_cast< proshade_single
> ( newYDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1521 corrs[5] =
static_cast< proshade_single
> ( newZDim ) *
static_cast< proshade_single
> ( resolution / 2.0f );
1546 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 )
1549 origMap =
new fftw_complex [xDimOld * yDimOld * zDimOld];
1550 fCoeffs =
new fftw_complex [xDimOld * yDimOld * zDimOld];
1551 newFCoeffs =
new fftw_complex [xDimNew * yDimNew * zDimNew];
1552 newMap =
new fftw_complex [xDimNew * yDimNew * zDimNew];
1561 planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimOld ),
static_cast< int > ( yDimOld ),
static_cast< int > ( zDimOld ), origMap, fCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
1562 planBackwardRescaledFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimNew ),
static_cast< int > ( yDimNew ),
static_cast< int > ( zDimNew ), newFCoeffs, newMap, FFTW_BACKWARD, FFTW_ESTIMATE );
1583 fftw_destroy_plan ( planForwardFourier );
1584 fftw_destroy_plan ( planBackwardRescaledFourier );
1589 delete[] newFCoeffs;
1612 proshade_signed h = 0, k = 0, l = 0, origSizeArr = 0, newSizeArr = 0;
1613 proshade_signed xSeq1FreqStart, ySeq1FreqStart, zSeq1FreqStart, xSeq2FreqStart, ySeq2FreqStart, zSeq2FreqStart;
1616 if ( negativeFirst )
1618 if ( ( xDim % 2 ) == 0 ) { xSeq1FreqStart = xDim / 2; xSeq2FreqStart = xDim / 2; }
else { xSeq1FreqStart = (xDim / 2) + 1; xSeq2FreqStart = xDim / 2; }
1619 if ( ( yDim % 2 ) == 0 ) { ySeq1FreqStart = yDim / 2; ySeq2FreqStart = yDim / 2; }
else { ySeq1FreqStart = (yDim / 2) + 1; ySeq2FreqStart = yDim / 2; }
1620 if ( ( zDim % 2 ) == 0 ) { zSeq1FreqStart = zDim / 2; zSeq2FreqStart = zDim / 2; }
else { zSeq1FreqStart = (zDim / 2) + 1; zSeq2FreqStart = zDim / 2; }
1624 if ( ( xDim % 2 ) == 0 ) { xSeq1FreqStart = xDim / 2; xSeq2FreqStart = xDim / 2; }
else { xSeq1FreqStart = (xDim / 2); xSeq2FreqStart = xDim / 2 + 1; }
1625 if ( ( yDim % 2 ) == 0 ) { ySeq1FreqStart = yDim / 2; ySeq2FreqStart = yDim / 2; }
else { ySeq1FreqStart = (yDim / 2); ySeq2FreqStart = yDim / 2 + 1; }
1626 if ( ( zDim % 2 ) == 0 ) { zSeq1FreqStart = zDim / 2; zSeq2FreqStart = zDim / 2; }
else { zSeq1FreqStart = (zDim / 2); zSeq2FreqStart = zDim / 2 + 1; }
1630 fftw_complex *hlpFCoeffs =
new fftw_complex [xDim * yDim * zDim];
1634 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1637 if ( xIt < xSeq1FreqStart ) { h = xIt + xSeq2FreqStart; }
else { h = xIt - xSeq1FreqStart; }
1638 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1641 if ( yIt < ySeq1FreqStart ) { k = yIt + ySeq2FreqStart; }
else { k = yIt - ySeq1FreqStart; }
1643 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1646 if ( zIt < zSeq1FreqStart ) { l = zIt + zSeq2FreqStart; }
else { l = zIt - zSeq1FreqStart; }
1649 newSizeArr = l + zDim * ( k + yDim * h );
1650 origSizeArr = zIt + zDim * ( yIt + yDim * xIt );
1653 hlpFCoeffs[newSizeArr][0] = fCoeffs[origSizeArr][0];
1654 hlpFCoeffs[newSizeArr][1] = fCoeffs[origSizeArr][1];
1660 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]; }
1663 delete[] hlpFCoeffs;
1684 proshade_double real, imag, mag, phase;
1685 proshade_unsign arrayPos = 0;
1686 proshade_double normFactor =
static_cast<proshade_double
> ( xDim * yDim * zDim );
1689 for ( proshade_unsign uIt = 0; uIt < xDim; uIt++ )
1691 for ( proshade_unsign vIt = 0; vIt < yDim; vIt++ )
1693 for ( proshade_unsign wIt = 0; wIt < zDim; wIt++ )
1696 arrayPos = wIt + zDim * ( vIt + yDim * uIt );
1697 real = mapCoeffs[arrayPos][0];
1698 imag = mapCoeffs[arrayPos][1];
1701 mag = std::sqrt ( (real*real) + (imag*imag) );;
1705 mapCoeffs[arrayPos][0] = ( mag * cos(phase) ) / normFactor;
1706 mapCoeffs[arrayPos][1] = ( mag * sin(phase) ) / normFactor;
1733 proshade_signed xDim =
static_cast< proshade_signed
> ( xDimS );
1734 proshade_signed yDim =
static_cast< proshade_signed
> ( yDimS );
1735 proshade_signed zDim =
static_cast< proshade_signed
> ( zDimS );
1736 proshade_signed currentPos, neighArrPos, neighXPos, neighYPos, neighZPos;
1737 proshade_double neighSum;
1738 proshade_double neighCount = pow ( ( ( fakeMapKernel * 2 ) + 1 ), 3.0 ) - 1.0;
1741 for ( proshade_signed uIt = 0; uIt < xDim; uIt++ )
1743 for ( proshade_signed vIt = 0; vIt < yDim; vIt++ )
1745 for ( proshade_signed wIt = 0; wIt < zDim; wIt++ )
1748 currentPos = wIt + zDim * ( vIt + yDim * uIt );
1752 for ( proshade_signed xCh = -fakeMapKernel; xCh <= +fakeMapKernel; xCh++ )
1754 for ( proshade_signed yCh = -fakeMapKernel; yCh <= +fakeMapKernel; yCh++ )
1756 for ( proshade_signed zCh = -fakeMapKernel; zCh <= +fakeMapKernel; zCh++ )
1758 if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) {
continue; }
1761 neighXPos = uIt + xCh;
if ( neighXPos >= xDim ) { neighXPos -= xDim; };
if ( neighXPos < 0 ) { neighXPos += xDim; }
1762 neighYPos = vIt + yCh;
if ( neighYPos >= yDim ) { neighYPos -= yDim; };
if ( neighYPos < 0 ) { neighYPos += yDim; }
1763 neighZPos = wIt + zCh;
if ( neighZPos >= zDim ) { neighZPos -= zDim; };
if ( neighZPos < 0 ) { neighZPos += zDim; }
1764 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1767 neighSum += map[neighArrPos];
1773 fakeHalfMap[currentPos] = neighSum / neighCount;
1798 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;
1799 proshade_unsign noCorrVals =
static_cast<proshade_unsign
> ( pow ( ( ( corrMaskKernel * 2 ) + 1 ), 3 ) );
1802 proshade_double *origMap =
new proshade_double [noCorrVals];
1803 proshade_double *fakeHM =
new proshade_double [noCorrVals];
1810 for ( proshade_signed uIt = 0; uIt < xDim; uIt++ )
1812 for ( proshade_signed vIt = 0; vIt < yDim; vIt++ )
1814 for ( proshade_signed wIt = 0; wIt < zDim; wIt++ )
1817 currentPos = wIt + zDim * ( vIt + yDim * uIt );
1821 for ( proshade_signed xCh = -corrMaskKernel; xCh <= +corrMaskKernel; xCh++ )
1823 for ( proshade_signed yCh = -corrMaskKernel; yCh <= +corrMaskKernel; yCh++ )
1825 for ( proshade_signed zCh = -corrMaskKernel; zCh <= +corrMaskKernel; zCh++ )
1828 neighXPos = uIt + xCh;
if ( neighXPos >= xDim ) { neighXPos -= xDim; };
if ( neighXPos < 0 ) { neighXPos += xDim; }
1829 neighYPos = vIt + yCh;
if ( neighYPos >= yDim ) { neighYPos -= yDim; };
if ( neighYPos < 0 ) { neighYPos += yDim; }
1830 neighZPos = wIt + zCh;
if ( neighZPos >= zDim ) { neighZPos -= zDim; };
if ( neighZPos < 0 ) { neighZPos += zDim; }
1831 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1834 origMap[corrIter] = map[neighArrPos];
1835 fakeHM[corrIter] = fakeHalfMap[neighArrPos];
1870 std::max ( dist / ( yAngs /
static_cast<proshade_single
> ( yDim ) ),
1871 dist / ( zAngs /
static_cast<proshade_single
> ( zDim ) ) ) ) ) );
1889 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 )
1892 proshade_double* hlpMap =
new proshade_double[xDim * yDim * zDim];
1893 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 ) ) ) ) ) );
1894 proshade_signed currPos, neighXPos, neighYPos, neighZPos, neighArrPos;
1900 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDim * yDim * zDim ); iter++ ) { hlpMap[iter] = mask[iter]; }
1903 for ( proshade_signed it = 0; it < addSurroundingPoints; it++ )
1906 for ( proshade_signed xIt = 0; xIt < xDim; xIt++ )
1908 for ( proshade_signed yIt = 0; yIt < yDim; yIt++ )
1910 for ( proshade_signed zIt = 0; zIt < zDim; zIt++ )
1913 currPos = zIt + zDim * ( yIt + yDim * xIt );
1916 if ( hlpMap[currPos] <
static_cast< proshade_double
> ( maskThres ) ) {
continue; }
1919 for ( proshade_signed xCh = -1; xCh <= +1; xCh++ )
1921 for ( proshade_signed yCh = -1; yCh <= +1; yCh++ )
1923 for ( proshade_signed zCh = -1; zCh <= +1; zCh++ )
1925 if ( ( xCh == 0 ) && ( yCh == 0 ) && ( zCh == 0 ) ) {
continue; }
1928 neighXPos = xIt + xCh;
if ( neighXPos < 0 ) {
continue; }
if ( neighXPos >= xDim ) {
continue; }
1929 neighYPos = yIt + yCh;
if ( neighYPos < 0 ) {
continue; }
if ( neighYPos >= yDim ) {
continue; }
1930 neighZPos = zIt + zCh;
if ( neighZPos < 0 ) {
continue; }
if ( neighZPos >= zDim ) {
continue; }
1931 neighArrPos = neighZPos + zDim * ( neighYPos + yDim * neighXPos );
1934 if ( hlpMap[neighArrPos] <
static_cast< proshade_double
> ( maskThres ) ) { mask[neighArrPos] =
static_cast< proshade_double
> ( maskThres ); }
1943 for ( proshade_unsign iter = 0; iter < static_cast<proshade_unsign> ( xDim * yDim * zDim ); iter++ ) { hlpMap[iter] = mask[iter]; }
1969 while ( bounds[1] >=
static_cast<proshade_signed
> ( xDim ) ) { xDim += 10; }
1970 while ( bounds[3] >=
static_cast<proshade_signed
> ( yDim ) ) { yDim += 10; }
1971 while ( bounds[5] >=
static_cast<proshade_signed
> ( zDim ) ) { zDim += 10; }
1974 proshade_signed addToX =
betterClosePrimeFactors ( bounds[1] - bounds[0] + 1,
static_cast< proshade_signed
> ( xDim ) );
1975 proshade_signed addToY =
betterClosePrimeFactors ( bounds[3] - bounds[2] + 1,
static_cast< proshade_signed
> ( yDim ) );
1976 proshade_signed addToZ =
betterClosePrimeFactors ( bounds[5] - bounds[4] + 1,
static_cast< proshade_signed
> ( zDim ) );
1979 proshade_signed XtoY = std::abs ( addToX - addToY );
1980 proshade_signed XtoZ = std::abs ( addToX - addToZ );
1981 proshade_signed YtoZ = std::abs ( addToY - addToZ );
1983 if ( ( ( XtoY < boundsDiffThres ) && ( XtoZ < boundsDiffThres ) ) ||
1984 ( ( XtoY < boundsDiffThres ) && ( YtoZ < boundsDiffThres ) ) ||
1985 ( ( XtoZ < boundsDiffThres ) && ( YtoZ < boundsDiffThres ) ) )
1988 proshade_signed maxSize = std::max ( addToX, std::max ( addToY, addToZ ) );
1996 if ( XtoY <= boundsDiffThres )
1998 proshade_signed maxSize = std::max ( addToX, addToY );
2002 if ( XtoZ <= boundsDiffThres )
2004 proshade_signed maxSize = std::max ( addToX, addToZ );
2008 if ( YtoZ <= boundsDiffThres )
2010 proshade_signed maxSize = std::max ( addToY, addToZ );
2039 proshade_signed ret = fromRange;
2040 std::vector < proshade_signed > posibles, hlp;
2041 proshade_signed sum;
2044 for ( proshade_signed iter = fromRange; iter < toRange; iter++ )
2048 for ( proshade_unsign i = 0; i < static_cast<proshade_unsign> ( hlp.size() ); i++ ) { sum += hlp.at(i); }
2054 for ( proshade_signed iter = fromRange; iter < toRange; iter++ )
2057 if ( iter %2 != 0 ) {
continue; }
2060 if ( posibles.at(
static_cast< size_t > ( iter - fromRange ) ) < ( posibles.at(
static_cast< size_t > ( ret - fromRange ) ) - ( iter - ret ) ) ) { ret = iter; }
2064 if ( ( ret % 2 != 0 ) && ( ret < ( toRange - 1 ) ) ) { ret += 1; }
2085 if ( newBoundRange > oldBoundRange )
2088 proshade_signed distributeThis = newBoundRange - oldBoundRange;
2090 while ( distributeThis != 0 )
2093 distributeThis -= 1;
2095 if ( distributeThis != 0 )
2098 distributeThis -= 1;
2132 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 )
2135 proshade_signed newMapIndex, oldMapIndex, oldX, oldY, oldZ, newX, newY, newZ;
2138 for ( proshade_signed xIt = xFrom; xIt <= xTo; xIt++ )
2141 newX = ( xIt - xFrom );
2142 oldX = ( newX + ( xFrom - origXFrom ) );
2144 for ( proshade_signed yIt = yFrom; yIt <= yTo; yIt++ )
2147 newY = ( yIt - yFrom );
2148 oldY = ( newY + ( yFrom - origYFrom ) );
2150 for ( proshade_signed zIt = zFrom; zIt <= zTo; zIt++ )
2153 newZ = ( zIt - zFrom );
2154 oldZ = ( newZ + ( zFrom - origZFrom ) );
2157 newMapIndex = newZ +
static_cast< proshade_signed
> ( zDimIndices ) * ( newY +
static_cast< proshade_signed
> ( yDimIndices ) * newX );
2158 oldMapIndex = oldZ +
static_cast< proshade_signed
> ( origZDimIndices ) * ( oldY +
static_cast< proshade_signed
> ( origYDimIndices ) * oldX );
2161 if ( ( ( oldX < 0 ) || ( oldX >=
static_cast< proshade_signed
> ( origXDimIndices ) ) ) ||
2162 ( ( oldY < 0 ) || ( oldY >=
static_cast< proshade_signed
> ( origYDimIndices ) ) ) ||
2163 ( ( oldZ < 0 ) || ( oldZ >=
static_cast< proshade_signed
> ( origZDimIndices ) ) ) )
2166 newMap[newMapIndex] = 0.0;
2171 newMap[newMapIndex] = origMap[oldMapIndex];