28 void getNonZeroBounds ( proshade_double* map, proshade_signed xDim, proshade_signed yDim, proshade_signed zDim, proshade_signed*& ret );
43 gemmi::Structure structure = gemmi::read_structure ( gemmi::MaybeGzipped ( fName ) );
45 catch ( std::runtime_error& e )
68 gemmi::Ccp4<float> map;
71 map.read_ccp4 ( gemmi::MaybeGzipped (fName.c_str() ) );
73 catch ( std::runtime_error& e )
115 void ProSHADE_internal_io::readInMapHeader ( gemmi::Ccp4<float> *map, proshade_unsign *xDimInds, proshade_unsign *yDimInds, proshade_unsign *zDimInds, proshade_single *xDim, proshade_single *yDim, proshade_single *zDim, proshade_single *aAng, proshade_single *bAng, proshade_single *cAng, proshade_signed *xFrom, proshade_signed *yFrom, proshade_signed *zFrom, proshade_signed *xAxOrigin, proshade_signed *yAxOrigin, proshade_signed *zAxOrigin, proshade_unsign *xAxOrder, proshade_unsign *yAxOrder, proshade_unsign *zAxOrder, proshade_unsign *xGridInds, proshade_unsign *yGridInds, proshade_unsign *zGridInds )
118 *xDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 1 ) );
119 *yDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 2 ) );
120 *zDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 3 ) );
122 *xFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 5 ) );
123 *yFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 6 ) );
124 *zFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 7 ) );
126 *xDim =
static_cast<proshade_single
> ( map->header_float ( 11 ) );
127 *yDim =
static_cast<proshade_single
> ( map->header_float ( 12 ) );
128 *zDim =
static_cast<proshade_single
> ( map->header_float ( 13 ) );
130 *aAng =
static_cast<proshade_single
> ( map->header_float ( 14 ) );
131 *bAng =
static_cast<proshade_single
> ( map->header_float ( 15 ) );
132 *cAng =
static_cast<proshade_single
> ( map->header_float ( 16 ) );
134 *xAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 50 ) ) + (*xFrom);
135 *yAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 51 ) ) + (*yFrom);
136 *zAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 52 ) ) + (*zFrom);
138 *xAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 17 ) );
139 *yAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 18 ) );
140 *zAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 19 ) );
142 *xGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 8 ) );
143 *yGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 9 ) );
144 *zGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 10 ) );
147 if ( *xGridInds != *xDimInds )
149 *xDim = *xDim * (
static_cast<proshade_single
> ( *xDimInds ) /
static_cast<proshade_single
> ( *xGridInds ) );
150 *xGridInds = *xDimInds;
153 if ( *yGridInds != *yDimInds )
155 *yDim = *yDim * (
static_cast<proshade_single
> ( *yDimInds ) /
static_cast<proshade_single
> ( *yGridInds ) );
156 *yGridInds = *yDimInds;
159 if ( *zGridInds != *zDimInds )
161 *zDim = *zDim * (
static_cast<proshade_single
> ( *zDimInds ) /
static_cast<proshade_single
> ( *zGridInds ) );
162 *zGridInds = *zDimInds;
184 void ProSHADE_internal_io::readInMapData ( gemmi::Ccp4<float> *gemmiMap, proshade_double*& map, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_unsign xAxOrder, proshade_unsign yAxOrder, proshade_unsign zAxOrder )
187 proshade_unsign *axOrdArr =
new proshade_unsign[3];
188 proshade_unsign *axDimArr =
new proshade_unsign[3];
189 proshade_unsign arrPos = 0;
194 axDimArr[0] = xDimInds;
195 axDimArr[1] = yDimInds;
196 axDimArr[2] = zDimInds;
199 map =
new proshade_double [xDimInds * yDimInds * zDimInds];
203 for ( axOrdArr[0] = 0; axOrdArr[0] < axDimArr[xAxOrder-1]; axOrdArr[0]++ )
205 for ( axOrdArr[1] = 0; axOrdArr[1] < axDimArr[yAxOrder-1]; axOrdArr[1]++ )
207 for ( axOrdArr[2] = 0; axOrdArr[2] < axDimArr[zAxOrder-1]; axOrdArr[2]++ )
209 arrPos = axOrdArr[2] + axDimArr[zAxOrder-1] * ( axOrdArr[1] + axDimArr[yAxOrder-1] * axOrdArr[0] );
210 map[arrPos] =
static_cast< proshade_double
> ( gemmiMap->grid.get_value_q(
static_cast< int > ( axOrdArr[xAxOrder-1] ),
211 static_cast< int > ( axOrdArr[yAxOrder-1] ),
212 static_cast< int > ( axOrdArr[zAxOrder-1] ) ) );
240 void ProSHADE_internal_io::readInMapData ( gemmi::Ccp4<int8_t> *gemmiMap, proshade_double*& map, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_unsign xAxOrder, proshade_unsign yAxOrder, proshade_unsign zAxOrder )
243 proshade_unsign *axOrdArr =
new proshade_unsign[3];
244 proshade_unsign *axDimArr =
new proshade_unsign[3];
245 proshade_unsign arrPos = 0;
250 axDimArr[0] = xDimInds;
251 axDimArr[1] = yDimInds;
252 axDimArr[2] = zDimInds;
255 map =
new proshade_double [xDimInds * yDimInds * zDimInds];
259 for ( axOrdArr[0] = 0; axOrdArr[0] < axDimArr[xAxOrder-1]; axOrdArr[0]++ )
261 for ( axOrdArr[1] = 0; axOrdArr[1] < axDimArr[yAxOrder-1]; axOrdArr[1]++ )
263 for ( axOrdArr[2] = 0; axOrdArr[2] < axDimArr[zAxOrder-1]; axOrdArr[2]++ )
265 arrPos = axOrdArr[2] + axDimArr[zAxOrder-1] * ( axOrdArr[1] + axDimArr[yAxOrder-1] * axOrdArr[0] );
266 map[arrPos] =
static_cast< proshade_double
> ( gemmiMap->grid.get_value_q(
static_cast< int > ( axOrdArr[xAxOrder-1] ),
267 static_cast< int > ( axOrdArr[yAxOrder-1] ),
268 static_cast< int > ( axOrdArr[zAxOrder-1] ) ) );
302 void ProSHADE_internal_io::applyMask ( proshade_double*& map, std::string maskFile, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_signed verbose, proshade_signed messageShift, std::vector< proshade_double >* calcBounds, proshade_double* maskArray, proshade_unsign maXInds, proshade_unsign maYInds, proshade_unsign maZInds )
305 std::stringstream hlpSS;
306 hlpSS <<
"Reading mask " << maskFile;
310 if ( ( maskArray !=
nullptr ) && ( maXInds != 0 ) && ( maYInds != 0 ) && ( maZInds != 0 ) )
313 ProSHADE_internal_io::applyMaskFromArray ( map, xDimInds, yDimInds, zDimInds, maskArray, maXInds, maYInds, maZInds, calcBounds, verbose, messageShift );
321 gemmi::Ccp4<float> mask;
322 mask.read_ccp4 ( gemmi::MaybeGzipped ( maskFile.c_str() ) );
325 mask.setup ( 0.0f, gemmi::MapSetup::ReorderOnly );
328 proshade_unsign xDI, yDI, zDI, xAOR, yAOR, zAOR, xGI, yGI, zGI;
329 proshade_single xDS, yDS, zDS, aA, bA, cA;
330 proshade_signed xF, yF, zF, xAO, yAO, zAO;
341 proshade_double* internalMask =
nullptr;
345 ProSHADE_internal_io::applyMaskFromArray ( map, xDimInds, yDimInds, zDimInds, internalMask, xDI, yDI, zDI, calcBounds, verbose, messageShift );
348 delete[] internalMask;
375 void ProSHADE_internal_io::applyMaskFromArray ( proshade_double*& map, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_double*& mask, proshade_unsign xDimIndsMsk, proshade_unsign yDimIndsMsk, proshade_unsign zDimIndsMsk, std::vector< proshade_double >* calcBounds, proshade_signed verbose, proshade_signed messageShift )
378 size_t origVolume = xDimInds * yDimInds * zDimInds;
379 size_t newVolume = xDimIndsMsk * yDimIndsMsk * zDimIndsMsk;
380 proshade_double* maskFinal;
383 if ( ( xDimIndsMsk != xDimInds ) || ( yDimIndsMsk != yDimInds ) || ( zDimIndsMsk != zDimInds ) )
386 fftw_complex* origCoeffs =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
387 fftw_complex* origCoeffsHKL =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
388 fftw_complex* modifCoeffs =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
389 fftw_complex* modifCoeffsHKL =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
390 fftw_complex* inMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
391 fftw_complex* outMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
402 for (
size_t iter = 0; iter < origVolume; iter++ ) { modifCoeffsHKL[iter][0] = 0.0; modifCoeffsHKL[iter][1] = 0.0; }
405 for (
size_t iter = 0; iter < newVolume; iter++ ) { inMap[iter][0] = mask[iter]; inMap[iter][1] = 0.0; }
408 fftw_plan planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimIndsMsk ),
static_cast< int > ( yDimIndsMsk ),
static_cast< int > ( zDimIndsMsk ), inMap, origCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
409 fftw_plan inverseFoourier = fftw_plan_dft_3d (
static_cast< int > ( xDimInds ),
static_cast< int > ( yDimInds ),
static_cast< int > ( zDimInds ), modifCoeffs, outMap, FFTW_BACKWARD, FFTW_ESTIMATE );
412 proshade_signed xPre, yPre, zPre;
413 xPre = std::abs ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsMsk ) ) / 2 );
414 yPre = std::abs ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsMsk ) ) / 2 );
415 zPre = std::abs ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsMsk ) ) / 2 );
417 if ( ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsMsk ) ) % 2 ) == 1 ) { xPre -= 1; }
418 if ( ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsMsk ) ) % 2 ) == 1 ) { yPre -= 1; }
419 if ( ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsMsk ) ) % 2 ) == 1 ) { zPre -= 1; }
422 fftw_execute ( planForwardFourier );
425 proshade_signed maskMapIndex = 0;
426 proshade_signed densMapIndex = 0;
427 proshade_signed xMaskPos, yMaskPos, zMaskPos, xDensPos, yDensPos, zDensPos;
428 proshade_signed maskH, maskK, maskL;
431 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimIndsMsk ); xIt++ )
433 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimIndsMsk ); yIt++ )
435 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimIndsMsk ); zIt++ )
438 maskH = xIt +
static_cast< proshade_signed
> ( (xDimIndsMsk+1) / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimIndsMsk ) ) { maskH -= xDimIndsMsk; }
439 maskK = yIt +
static_cast< proshade_signed
> ( (yDimIndsMsk+1) / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimIndsMsk ) ) { maskK -= yDimIndsMsk; }
440 maskL = zIt +
static_cast< proshade_signed
> ( (zDimIndsMsk+1) / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimIndsMsk ) ) { maskL -= zDimIndsMsk; }
443 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( yIt +
static_cast< proshade_signed
> ( yDimIndsMsk ) * xIt );
444 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( maskK +
static_cast< proshade_signed
> ( yDimIndsMsk ) * maskH );
447 origCoeffsHKL[densMapIndex][0] = origCoeffs[maskMapIndex][0];
448 origCoeffsHKL[densMapIndex][1] = origCoeffs[maskMapIndex][1];
454 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
456 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
458 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
461 if ( xDimIndsMsk >= xDimInds ) { xMaskPos = xIt + xPre; }
462 else { xMaskPos = xIt - xPre; }
466 if ( yDimIndsMsk >= yDimInds ) { yMaskPos = yIt + yPre; }
467 else { yMaskPos = yIt - yPre; }
471 if ( zDimIndsMsk >= zDimInds ) { zMaskPos = zIt + zPre; }
472 else { zMaskPos = zIt - zPre; }
476 if ( ( xMaskPos < 0 ) || ( xMaskPos >=
static_cast< proshade_signed
> ( xDimIndsMsk ) ) ) {
continue; }
477 if ( ( yMaskPos < 0 ) || ( yMaskPos >=
static_cast< proshade_signed
> ( yDimIndsMsk ) ) ) {
continue; }
478 if ( ( zMaskPos < 0 ) || ( zMaskPos >=
static_cast< proshade_signed
> ( zDimIndsMsk ) ) ) {
continue; }
481 maskMapIndex = zMaskPos +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( yMaskPos +
static_cast< proshade_signed
> ( yDimIndsMsk ) * xMaskPos );
482 densMapIndex = zDensPos +
static_cast< proshade_signed
> ( zDimInds ) * ( yDensPos +
static_cast< proshade_signed
> ( yDimInds ) * xDensPos );
485 modifCoeffsHKL[densMapIndex][0] = origCoeffsHKL[maskMapIndex][0];
486 modifCoeffsHKL[densMapIndex][1] = origCoeffsHKL[maskMapIndex][1];
492 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
494 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
496 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
499 maskH = xIt +
static_cast< proshade_signed
> ( xDimInds / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimInds ) ) { maskH -= xDimInds; }
500 maskK = yIt +
static_cast< proshade_signed
> ( yDimInds / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimInds ) ) { maskK -= yDimInds; }
501 maskL = zIt +
static_cast< proshade_signed
> ( zDimInds / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimInds ) ) { maskL -= zDimInds; }
504 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimInds ) * ( yIt +
static_cast< proshade_signed
> ( yDimInds ) * xIt );
505 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimInds ) * ( maskK +
static_cast< proshade_signed
> ( yDimInds ) * maskH );
508 modifCoeffs[densMapIndex][0] = modifCoeffsHKL[maskMapIndex][0];
509 modifCoeffs[densMapIndex][1] = modifCoeffsHKL[maskMapIndex][1];
515 fftw_execute ( inverseFoourier );
518 maskFinal =
new proshade_double [origVolume];
522 for (
size_t iter = 0; iter < origVolume; iter++ ) { maskFinal[iter] = outMap[iter][0]; }
525 fftw_destroy_plan ( planForwardFourier );
526 fftw_destroy_plan ( inverseFoourier );
527 fftw_free ( origCoeffs );
528 fftw_free ( modifCoeffs );
529 fftw_free ( origCoeffsHKL );
530 fftw_free ( modifCoeffsHKL );
532 fftw_free ( outMap );
536 maskFinal =
new proshade_double [origVolume];
538 for (
size_t iter = 0; iter < origVolume; iter++ ) { maskFinal[iter] = mask[iter]; }
542 for (
size_t iter = 0; iter < static_cast< size_t > ( xDimInds * yDimInds * zDimInds ); iter++ ) { map[iter] *= maskFinal[iter]; }
548 proshade_signed* bnds =
new proshade_signed[6];
553 calcBounds->at(0) =
static_cast< proshade_double
> ( bnds[1] - bnds[0] );
554 calcBounds->at(1) =
static_cast< proshade_double
> ( bnds[3] - bnds[2] );
555 calcBounds->at(2) =
static_cast< proshade_double
> ( bnds[5] - bnds[4] );
588 void ProSHADE_internal_io::applyWeights ( proshade_double*& map, std::string weightsFile, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_signed verbose, proshade_signed messageShift, proshade_double* weightsArray, proshade_unsign waXInds, proshade_unsign waYInds, proshade_unsign waZInds )
591 std::stringstream hlpSS;
592 hlpSS <<
"Reading weights " << weightsFile;
596 if ( ( weightsArray !=
nullptr ) && ( waXInds != 0 ) && ( waYInds != 0 ) && ( waZInds != 0 ) )
607 gemmi::Ccp4<float> weights;
608 weights.read_ccp4 ( gemmi::MaybeGzipped ( weightsFile.c_str() ) );
611 weights.setup ( 0.0f, gemmi::MapSetup::ReorderOnly );
614 proshade_unsign xDI, yDI, zDI, xAOR, yAOR, zAOR, xGI, yGI, zGI;
615 proshade_single xDS, yDS, zDS, aA, bA, cA;
616 proshade_signed xF, yF, zF, xAO, yAO, zAO;
627 proshade_double* internalWeights =
nullptr;
634 delete[] internalWeights;
660 void ProSHADE_internal_io::applyWeightsFromArray ( proshade_double*& map, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_double*& weights, proshade_unsign xDimIndsWgh, proshade_unsign yDimIndsWgh, proshade_unsign zDimIndsWgh, proshade_signed verbose, proshade_signed messageShift )
663 proshade_double* weightsFinal;
664 size_t origVolume = xDimInds * yDimInds * zDimInds;
665 size_t newVolume = xDimIndsWgh * yDimIndsWgh * zDimIndsWgh;
668 if ( ( xDimIndsWgh != xDimInds ) || ( yDimIndsWgh != yDimInds ) || ( zDimIndsWgh != zDimInds ) )
671 fftw_complex* origCoeffs =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
672 fftw_complex* origCoeffsHKL =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
673 fftw_complex* modifCoeffs =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
674 fftw_complex* modifCoeffsHKL =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
675 fftw_complex* inMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * newVolume ) );
676 fftw_complex* outMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
687 for (
size_t iter = 0; iter < origVolume; iter++ ) { modifCoeffsHKL[iter][0] = 0.0; modifCoeffsHKL[iter][1] = 0.0; }
690 for (
size_t iter = 0; iter < newVolume; iter++ ) { inMap[iter][0] = weights[iter]; inMap[iter][1] = 0.0; }
693 fftw_plan planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimIndsWgh ),
static_cast< int > ( yDimIndsWgh ),
static_cast< int > ( zDimIndsWgh ), inMap, origCoeffs, FFTW_FORWARD, FFTW_ESTIMATE );
694 fftw_plan inverseFoourier = fftw_plan_dft_3d (
static_cast< int > ( xDimInds ),
static_cast< int > ( yDimInds ),
static_cast< int > ( zDimInds ), modifCoeffs, outMap, FFTW_BACKWARD, FFTW_ESTIMATE );
697 proshade_signed xPre, yPre, zPre;
698 xPre = std::abs ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsWgh ) ) / 2 );
699 yPre = std::abs ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsWgh ) ) / 2 );
700 zPre = std::abs ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsWgh ) ) / 2 );
702 if ( ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsWgh ) ) % 2 ) == 1 ) { xPre -= 1; }
703 if ( ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsWgh ) ) % 2 ) == 1 ) { yPre -= 1; }
704 if ( ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsWgh ) ) % 2 ) == 1 ) { zPre -= 1; }
707 fftw_execute ( planForwardFourier );
710 proshade_signed maskMapIndex = 0;
711 proshade_signed densMapIndex = 0;
712 proshade_signed xMaskPos, yMaskPos, zMaskPos, xDensPos, yDensPos, zDensPos;
713 proshade_signed maskH, maskK, maskL;
716 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimIndsWgh ); xIt++ )
718 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimIndsWgh ); yIt++ )
720 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimIndsWgh ); zIt++ )
723 maskH = xIt +
static_cast< proshade_signed
> ( (xDimIndsWgh+1) / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimIndsWgh ) ) { maskH -= xDimIndsWgh; }
724 maskK = yIt +
static_cast< proshade_signed
> ( (yDimIndsWgh+1) / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimIndsWgh ) ) { maskK -= yDimIndsWgh; }
725 maskL = zIt +
static_cast< proshade_signed
> ( (zDimIndsWgh+1) / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimIndsWgh ) ) { maskL -= zDimIndsWgh; }
728 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( yIt +
static_cast< proshade_signed
> ( yDimIndsWgh ) * xIt );
729 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( maskK +
static_cast< proshade_signed
> ( yDimIndsWgh ) * maskH );
732 origCoeffsHKL[densMapIndex][0] = origCoeffs[maskMapIndex][0];
733 origCoeffsHKL[densMapIndex][1] = origCoeffs[maskMapIndex][1];
739 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
741 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
743 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
746 if ( xDimIndsWgh >= xDimInds ) { xMaskPos = xIt + xPre; }
747 else { xMaskPos = xIt - xPre; }
751 if ( yDimIndsWgh >= yDimInds ) { yMaskPos = yIt + yPre; }
752 else { yMaskPos = yIt - yPre; }
756 if ( zDimIndsWgh >= zDimInds ) { zMaskPos = zIt + zPre; }
757 else { zMaskPos = zIt - zPre; }
761 if ( ( xMaskPos < 0 ) || ( xMaskPos >=
static_cast< proshade_signed
> ( xDimIndsWgh ) ) ) {
continue; }
762 if ( ( yMaskPos < 0 ) || ( yMaskPos >=
static_cast< proshade_signed
> ( yDimIndsWgh ) ) ) {
continue; }
763 if ( ( zMaskPos < 0 ) || ( zMaskPos >=
static_cast< proshade_signed
> ( zDimIndsWgh ) ) ) {
continue; }
766 maskMapIndex = zMaskPos +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( yMaskPos +
static_cast< proshade_signed
> ( yDimIndsWgh ) * xMaskPos );
767 densMapIndex = zDensPos +
static_cast< proshade_signed
> ( zDimInds ) * ( yDensPos +
static_cast< proshade_signed
> ( yDimInds ) * xDensPos );
770 modifCoeffsHKL[densMapIndex][0] = origCoeffsHKL[maskMapIndex][0];
771 modifCoeffsHKL[densMapIndex][1] = origCoeffsHKL[maskMapIndex][1];
777 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
779 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
781 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
784 maskH = xIt +
static_cast< proshade_signed
> ( xDimInds / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimInds ) ) { maskH -= xDimInds; }
785 maskK = yIt +
static_cast< proshade_signed
> ( yDimInds / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimInds ) ) { maskK -= yDimInds; }
786 maskL = zIt +
static_cast< proshade_signed
> ( zDimInds / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimInds ) ) { maskL -= zDimInds; }
789 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimInds ) * ( yIt +
static_cast< proshade_signed
> ( yDimInds ) * xIt );
790 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimInds ) * ( maskK +
static_cast< proshade_signed
> ( yDimInds ) * maskH );
793 modifCoeffs[densMapIndex][0] = modifCoeffsHKL[maskMapIndex][0];
794 modifCoeffs[densMapIndex][1] = modifCoeffsHKL[maskMapIndex][1];
800 fftw_execute ( inverseFoourier );
803 weightsFinal =
new proshade_double [origVolume];
807 for (
size_t iter = 0; iter < origVolume; iter++ ) { weightsFinal[iter] = outMap[iter][0]; }
810 fftw_destroy_plan ( planForwardFourier );
811 fftw_destroy_plan ( inverseFoourier );
812 fftw_free ( origCoeffs );
813 fftw_free ( modifCoeffs );
814 fftw_free ( origCoeffsHKL );
815 fftw_free ( modifCoeffsHKL );
817 fftw_free ( outMap );
821 weightsFinal =
new proshade_double [origVolume];
823 for (
size_t iter = 0; iter < origVolume; iter++ ) { weightsFinal[iter] = weights[iter]; }
827 fftw_complex* inMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
828 fftw_complex* outMap =
reinterpret_cast< fftw_complex*
> ( fftw_malloc (
sizeof ( fftw_complex ) * origVolume ) );
831 fftw_plan planForwardFourier = fftw_plan_dft_3d (
static_cast< int > ( xDimInds ),
static_cast< int > ( yDimInds ),
static_cast< int > ( zDimInds ), inMap, outMap, FFTW_FORWARD, FFTW_ESTIMATE );
832 fftw_plan inverseFoourier = fftw_plan_dft_3d (
static_cast< int > ( xDimInds ),
static_cast< int > ( yDimInds ),
static_cast< int > ( zDimInds ), outMap, inMap, FFTW_BACKWARD, FFTW_ESTIMATE );
835 for (
size_t iter = 0; iter < static_cast< size_t > ( origVolume ); iter++ ) { inMap[iter][0] = map[iter]; inMap[iter][1] = 0.0; }
838 fftw_execute ( planForwardFourier );
841 proshade_double normFactor =
static_cast<proshade_double
> ( origVolume );
842 for (
size_t iter = 0; iter < static_cast< size_t > ( origVolume ); iter++ ) { outMap[iter][0] *= weightsFinal[iter] / normFactor; outMap[iter][1] *= weightsFinal[iter] / normFactor; }
845 fftw_execute ( inverseFoourier );
848 for (
size_t iter = 0; iter < static_cast< size_t > ( xDimInds * yDimInds * zDimInds ); iter++ ) { map[iter] = inMap[iter][0]; }
851 delete[] weightsFinal;
853 fftw_free ( outMap );
854 fftw_destroy_plan ( planForwardFourier );
855 fftw_destroy_plan ( inverseFoourier );
895 void ProSHADE_internal_io::writeOutMapHeader ( gemmi::Ccp4<float> *map, proshade_unsign xDimInds, proshade_unsign yDimInds, proshade_unsign zDimInds, proshade_single xDim, proshade_single yDim, proshade_single zDim, proshade_single aAng, proshade_single bAng, proshade_single cAng, proshade_signed xFrom, proshade_signed yFrom, proshade_signed zFrom, proshade_signed xAxOrigin, proshade_signed yAxOrigin, proshade_signed zAxOrigin, proshade_unsign xAxOrder, proshade_unsign yAxOrder, proshade_unsign zAxOrder, proshade_unsign xGridInds, proshade_unsign yGridInds, proshade_unsign zGridInds, std::string title,
int mode )
898 map->set_header_i32 ( 1 ,
static_cast<int32_t
> ( xDimInds ) );
899 map->set_header_i32 ( 2 ,
static_cast<int32_t
> ( yDimInds ) );
900 map->set_header_i32 ( 3 ,
static_cast<int32_t
> ( zDimInds ) );
901 map->set_header_i32 ( 4 ,
static_cast<int32_t
> ( mode ) );
902 map->set_header_i32 ( 5 ,
static_cast<int32_t
> ( xFrom ) );
903 map->set_header_i32 ( 6 ,
static_cast<int32_t
> ( yFrom ) );
904 map->set_header_i32 ( 7 ,
static_cast<int32_t
> ( zFrom ) );
905 map->set_header_i32 ( 8 ,
static_cast<int32_t
> ( xGridInds ) );
906 map->set_header_i32 ( 9 ,
static_cast<int32_t
> ( yGridInds ) );
907 map->set_header_i32 ( 10,
static_cast<int32_t
> ( zGridInds ) );
908 map->set_header_float ( 11,
static_cast<float> ( xDim ) );
909 map->set_header_float ( 12,
static_cast<float> ( yDim ) );
910 map->set_header_float ( 13,
static_cast<float> ( zDim ) );
911 map->set_header_float ( 14,
static_cast<float> ( aAng ) );
912 map->set_header_float ( 15,
static_cast<float> ( bAng ) );
913 map->set_header_float ( 16,
static_cast<float> ( cAng ) );
914 map->set_header_i32 ( 17,
static_cast<int32_t
> ( xAxOrder ) );
915 map->set_header_i32 ( 18,
static_cast<int32_t
> ( yAxOrder ) );
916 map->set_header_i32 ( 19,
static_cast<int32_t
> ( zAxOrder ) );
917 if ( map->grid.spacegroup ) { map->set_header_i32 ( 23,
static_cast<int32_t
> ( map->grid.spacegroup->ccp4 ) ); }
918 else { map->set_header_i32 ( 23,
static_cast<int32_t
> ( 1 ) ); }
919 map->set_header_i32 ( 24,
static_cast<int32_t
> ( map->grid.spacegroup->operations().order() * 80 ) );
920 map->set_header_str ( 27,
"CCP4" );
921 map->set_header_i32 ( 28,
static_cast<int32_t
> ( 20140 ) );
922 map->set_header_i32 ( 50,
static_cast<int32_t
> ( xAxOrigin ) );
923 map->set_header_i32 ( 51,
static_cast<int32_t
> ( yAxOrigin ) );
924 map->set_header_i32 ( 52,
static_cast<int32_t
> ( zAxOrigin ) );
925 map->set_header_str ( 53,
"MAP" );
926 if ( gemmi::is_little_endian() ) { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x00004144 ) ); }
927 else { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x11110000 ) ); }
928 map->set_header_i32 ( 56,
static_cast<int32_t
> ( 1 ) );
929 std::memset (
reinterpret_cast<void*
> ( &(map->ccp4_header.at( 56 )) ),
' ',
static_cast< size_t > ( 800 + map->grid.spacegroup->operations().order() * 80 ) );
930 map->set_header_str ( 57, title );
987 void ProSHADE_internal_io::writeRotationTranslationJSON ( proshade_double trsX1, proshade_double trsY1, proshade_double trsZ1, proshade_double eulA, proshade_double eulB, proshade_double eulG, proshade_double trsX2, proshade_double trsY2, proshade_double trsZ2, std::string fileName )
990 std::ofstream jsonFile;
991 jsonFile.open ( fileName );
994 if ( !jsonFile.is_open( ) )
996 throw ProSHADE_exception (
"Failed to open JSON output file.",
"E000056", __FILE__, __LINE__, __func__,
"Failed to open json file to which the rotation and\n : translation would be written into. Most likely cause is\n : lack of rights to write in the current folder." );
1000 proshade_double* rotMat =
new proshade_double[9];
1006 jsonFile <<
" \"translationToOrigin\" : [ " << trsX1 <<
", " << trsY1 <<
", " << trsZ1 <<
" ], \n";
1008 jsonFile <<
" \"rotationMatrix:\" : [ " << rotMat[0] <<
", " << rotMat[1] <<
", " << rotMat[2] <<
", \n";
1009 jsonFile <<
" " << rotMat[3] <<
", " << rotMat[4] <<
", " << rotMat[5] <<
", \n";
1010 jsonFile <<
" " << rotMat[6] <<
", " << rotMat[7] <<
", " << rotMat[8] <<
"], \n";
1012 jsonFile <<
" \"translationFromRotCenToOverlay\" : [ " << trsX2 <<
", " << trsY2 <<
", " << trsZ2 <<
" ] \n";