37 gemmi::Structure structure = gemmi::read_structure ( gemmi::MaybeGzipped ( fName ) );
39 catch ( std::runtime_error& e )
62 gemmi::Ccp4<float> map;
65 map.read_ccp4 ( gemmi::MaybeGzipped (fName.c_str() ) );
67 catch ( std::runtime_error& e )
109 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 )
112 *xDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 1 ) );
113 *yDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 2 ) );
114 *zDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 3 ) );
116 *xFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 5 ) );
117 *yFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 6 ) );
118 *zFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 7 ) );
120 *xDim =
static_cast<proshade_single
> ( map->header_float ( 11 ) );
121 *yDim =
static_cast<proshade_single
> ( map->header_float ( 12 ) );
122 *zDim =
static_cast<proshade_single
> ( map->header_float ( 13 ) );
124 *aAng =
static_cast<proshade_single
> ( map->header_float ( 14 ) );
125 *bAng =
static_cast<proshade_single
> ( map->header_float ( 15 ) );
126 *cAng =
static_cast<proshade_single
> ( map->header_float ( 16 ) );
128 *xAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 50 ) ) + (*xFrom);
129 *yAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 51 ) ) + (*yFrom);
130 *zAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 52 ) ) + (*zFrom);
132 *xAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 17 ) );
133 *yAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 18 ) );
134 *zAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 19 ) );
136 *xGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 8 ) );
137 *yGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 9 ) );
138 *zGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 10 ) );
141 if ( *xGridInds != *xDimInds )
143 *xDim = *xDim * (
static_cast<proshade_single
> ( *xDimInds ) /
static_cast<proshade_single
> ( *xGridInds ) );
144 *xGridInds = *xDimInds;
147 if ( *yGridInds != *yDimInds )
149 *yDim = *yDim * (
static_cast<proshade_single
> ( *yDimInds ) /
static_cast<proshade_single
> ( *yGridInds ) );
150 *yGridInds = *yDimInds;
153 if ( *zGridInds != *zDimInds )
155 *zDim = *zDim * (
static_cast<proshade_single
> ( *zDimInds ) /
static_cast<proshade_single
> ( *zGridInds ) );
156 *zGridInds = *zDimInds;
178 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 )
181 proshade_unsign *axOrdArr =
new proshade_unsign[3];
182 proshade_unsign *axDimArr =
new proshade_unsign[3];
183 proshade_unsign arrPos = 0;
188 axDimArr[0] = xDimInds;
189 axDimArr[1] = yDimInds;
190 axDimArr[2] = zDimInds;
193 map =
new proshade_double [xDimInds * yDimInds * zDimInds];
197 for ( axOrdArr[0] = 0; axOrdArr[0] < axDimArr[xAxOrder-1]; axOrdArr[0]++ )
199 for ( axOrdArr[1] = 0; axOrdArr[1] < axDimArr[yAxOrder-1]; axOrdArr[1]++ )
201 for ( axOrdArr[2] = 0; axOrdArr[2] < axDimArr[zAxOrder-1]; axOrdArr[2]++ )
203 arrPos = axOrdArr[2] + axDimArr[zAxOrder-1] * ( axOrdArr[1] + axDimArr[yAxOrder-1] * axOrdArr[0] );
204 map[arrPos] =
static_cast< proshade_double
> ( gemmiMap->grid.get_value_q(
static_cast< int > ( axOrdArr[xAxOrder-1] ),
205 static_cast< int > ( axOrdArr[yAxOrder-1] ),
206 static_cast< int > ( axOrdArr[zAxOrder-1] ) ) );
234 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 )
237 proshade_unsign *axOrdArr =
new proshade_unsign[3];
238 proshade_unsign *axDimArr =
new proshade_unsign[3];
239 proshade_unsign arrPos = 0;
244 axDimArr[0] = xDimInds;
245 axDimArr[1] = yDimInds;
246 axDimArr[2] = zDimInds;
249 map =
new proshade_double [xDimInds * yDimInds * zDimInds];
253 for ( axOrdArr[0] = 0; axOrdArr[0] < axDimArr[xAxOrder-1]; axOrdArr[0]++ )
255 for ( axOrdArr[1] = 0; axOrdArr[1] < axDimArr[yAxOrder-1]; axOrdArr[1]++ )
257 for ( axOrdArr[2] = 0; axOrdArr[2] < axDimArr[zAxOrder-1]; axOrdArr[2]++ )
259 arrPos = axOrdArr[2] + axDimArr[zAxOrder-1] * ( axOrdArr[1] + axDimArr[yAxOrder-1] * axOrdArr[0] );
260 map[arrPos] =
static_cast< proshade_double
> ( gemmiMap->grid.get_value_q(
static_cast< int > ( axOrdArr[xAxOrder-1] ),
261 static_cast< int > ( axOrdArr[yAxOrder-1] ),
262 static_cast< int > ( axOrdArr[zAxOrder-1] ) ) );
295 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, proshade_double* maskArray, proshade_unsign maXInds, proshade_unsign maYInds, proshade_unsign maZInds )
298 std::stringstream hlpSS;
299 hlpSS <<
"Reading mask " << maskFile;
303 if ( ( maskArray !=
nullptr ) && ( maXInds != 0 ) && ( maYInds != 0 ) && ( maZInds != 0 ) )
314 gemmi::Ccp4<float> mask;
315 mask.read_ccp4 ( gemmi::MaybeGzipped ( maskFile.c_str() ) );
318 mask.setup ( gemmi::GridSetup::ReorderOnly, 0 );
321 proshade_unsign xDI, yDI, zDI, xAOR, yAOR, zAOR, xGI, yGI, zGI;
322 proshade_single xDS, yDS, zDS, aA, bA, cA;
323 proshade_signed xF, yF, zF, xAO, yAO, zAO;
334 proshade_double* internalMask =
nullptr;
341 delete[] internalMask;
367 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, proshade_signed verbose, proshade_signed messageShift )
370 size_t origVolume = xDimInds * yDimInds * zDimInds;
371 size_t newVolume = xDimIndsMsk * yDimIndsMsk * zDimIndsMsk;
372 proshade_double* maskFinal;
375 if ( ( xDimIndsMsk != xDimInds ) || ( yDimIndsMsk != yDimInds ) || ( zDimIndsMsk != zDimInds ) )
378 fftw_complex* origCoeffs =
new fftw_complex [newVolume ];
379 fftw_complex* origCoeffsHKL =
new fftw_complex [newVolume ];
380 fftw_complex* modifCoeffs =
new fftw_complex [origVolume];
381 fftw_complex* modifCoeffsHKL =
new fftw_complex [origVolume];
382 fftw_complex* inMap =
new fftw_complex [newVolume ];
383 fftw_complex* outMap =
new fftw_complex [origVolume];
394 for (
size_t iter = 0; iter < origVolume; iter++ ) { modifCoeffsHKL[iter][0] = 0.0; modifCoeffsHKL[iter][1] = 0.0; }
397 for (
size_t iter = 0; iter < newVolume; iter++ ) { inMap[iter][0] = mask[iter]; inMap[iter][1] = 0.0; }
400 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 );
401 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 );
404 proshade_signed xPre, yPre, zPre;
405 xPre = std::abs ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsMsk ) ) / 2 );
406 yPre = std::abs ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsMsk ) ) / 2 );
407 zPre = std::abs ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsMsk ) ) / 2 );
409 if ( ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsMsk ) ) % 2 ) == 1 ) { xPre -= 1; }
410 if ( ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsMsk ) ) % 2 ) == 1 ) { yPre -= 1; }
411 if ( ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsMsk ) ) % 2 ) == 1 ) { zPre -= 1; }
414 fftw_execute ( planForwardFourier );
417 proshade_signed maskMapIndex = 0;
418 proshade_signed densMapIndex = 0;
419 proshade_signed xMaskPos, yMaskPos, zMaskPos, xDensPos, yDensPos, zDensPos;
420 proshade_signed maskH, maskK, maskL;
423 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimIndsMsk ); xIt++ )
425 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimIndsMsk ); yIt++ )
427 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimIndsMsk ); zIt++ )
430 maskH = xIt +
static_cast< proshade_signed
> ( (xDimIndsMsk+1) / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimIndsMsk ) ) { maskH -= xDimIndsMsk; }
431 maskK = yIt +
static_cast< proshade_signed
> ( (yDimIndsMsk+1) / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimIndsMsk ) ) { maskK -= yDimIndsMsk; }
432 maskL = zIt +
static_cast< proshade_signed
> ( (zDimIndsMsk+1) / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimIndsMsk ) ) { maskL -= zDimIndsMsk; }
435 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( yIt +
static_cast< proshade_signed
> ( yDimIndsMsk ) * xIt );
436 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( maskK +
static_cast< proshade_signed
> ( yDimIndsMsk ) * maskH );
439 origCoeffsHKL[densMapIndex][0] = origCoeffs[maskMapIndex][0];
440 origCoeffsHKL[densMapIndex][1] = origCoeffs[maskMapIndex][1];
446 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
448 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
450 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
453 if ( xDimIndsMsk >= xDimInds ) { xMaskPos = xIt + xPre; }
454 else { xMaskPos = xIt - xPre; }
458 if ( yDimIndsMsk >= yDimInds ) { yMaskPos = yIt + yPre; }
459 else { yMaskPos = yIt - yPre; }
463 if ( zDimIndsMsk >= zDimInds ) { zMaskPos = zIt + zPre; }
464 else { zMaskPos = zIt - zPre; }
468 if ( ( xMaskPos < 0 ) || ( xMaskPos >=
static_cast< proshade_signed
> ( xDimIndsMsk ) ) ) {
continue; }
469 if ( ( yMaskPos < 0 ) || ( yMaskPos >=
static_cast< proshade_signed
> ( yDimIndsMsk ) ) ) {
continue; }
470 if ( ( zMaskPos < 0 ) || ( zMaskPos >=
static_cast< proshade_signed
> ( zDimIndsMsk ) ) ) {
continue; }
473 maskMapIndex = zMaskPos +
static_cast< proshade_signed
> ( zDimIndsMsk ) * ( yMaskPos +
static_cast< proshade_signed
> ( yDimIndsMsk ) * xMaskPos );
474 densMapIndex = zDensPos +
static_cast< proshade_signed
> ( zDimInds ) * ( yDensPos +
static_cast< proshade_signed
> ( yDimInds ) * xDensPos );
477 modifCoeffsHKL[densMapIndex][0] = origCoeffsHKL[maskMapIndex][0];
478 modifCoeffsHKL[densMapIndex][1] = origCoeffsHKL[maskMapIndex][1];
484 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
486 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
488 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
491 maskH = xIt +
static_cast< proshade_signed
> ( xDimInds / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimInds ) ) { maskH -= xDimInds; }
492 maskK = yIt +
static_cast< proshade_signed
> ( yDimInds / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimInds ) ) { maskK -= yDimInds; }
493 maskL = zIt +
static_cast< proshade_signed
> ( zDimInds / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimInds ) ) { maskL -= zDimInds; }
496 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimInds ) * ( yIt +
static_cast< proshade_signed
> ( yDimInds ) * xIt );
497 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimInds ) * ( maskK +
static_cast< proshade_signed
> ( yDimInds ) * maskH );
500 modifCoeffs[densMapIndex][0] = modifCoeffsHKL[maskMapIndex][0];
501 modifCoeffs[densMapIndex][1] = modifCoeffsHKL[maskMapIndex][1];
507 fftw_execute ( inverseFoourier );
510 maskFinal =
new proshade_double [origVolume];
514 for (
size_t iter = 0; iter < origVolume; iter++ ) { maskFinal[iter] = outMap[iter][0]; }
517 fftw_destroy_plan ( planForwardFourier );
518 fftw_destroy_plan ( inverseFoourier );
520 delete[] modifCoeffs;
521 delete[] origCoeffsHKL;
522 delete[] modifCoeffsHKL;
528 maskFinal =
new proshade_double [origVolume];
530 for (
size_t iter = 0; iter < origVolume; iter++ ) { maskFinal[iter] = mask[iter]; }
534 for (
size_t iter = 0; iter < static_cast< size_t > ( xDimInds * yDimInds * zDimInds ); iter++ ) { map[iter] *= maskFinal[iter]; }
566 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 )
569 std::stringstream hlpSS;
570 hlpSS <<
"Reading weights " << weightsFile;
574 if ( ( weightsArray !=
nullptr ) && ( waXInds != 0 ) && ( waYInds != 0 ) && ( waZInds != 0 ) )
585 gemmi::Ccp4<float> weights;
586 weights.read_ccp4 ( gemmi::MaybeGzipped ( weightsFile.c_str() ) );
589 weights.setup ( gemmi::GridSetup::ReorderOnly, 0 );
592 proshade_unsign xDI, yDI, zDI, xAOR, yAOR, zAOR, xGI, yGI, zGI;
593 proshade_single xDS, yDS, zDS, aA, bA, cA;
594 proshade_signed xF, yF, zF, xAO, yAO, zAO;
605 proshade_double* internalWeights =
nullptr;
612 delete[] internalWeights;
638 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 )
641 proshade_double* weightsFinal;
642 size_t origVolume = xDimInds * yDimInds * zDimInds;
643 size_t newVolume = xDimIndsWgh * yDimIndsWgh * zDimIndsWgh;
646 if ( ( xDimIndsWgh != xDimInds ) || ( yDimIndsWgh != yDimInds ) || ( zDimIndsWgh != zDimInds ) )
649 fftw_complex* origCoeffs =
new fftw_complex [newVolume ];
650 fftw_complex* origCoeffsHKL =
new fftw_complex [newVolume ];
651 fftw_complex* modifCoeffs =
new fftw_complex [origVolume];
652 fftw_complex* modifCoeffsHKL =
new fftw_complex [origVolume];
653 fftw_complex* inMap =
new fftw_complex [newVolume ];
654 fftw_complex* outMap =
new fftw_complex [origVolume];
665 for (
size_t iter = 0; iter < origVolume; iter++ ) { modifCoeffsHKL[iter][0] = 0.0; modifCoeffsHKL[iter][1] = 0.0; }
668 for (
size_t iter = 0; iter < newVolume; iter++ ) { inMap[iter][0] = weights[iter]; inMap[iter][1] = 0.0; }
671 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 );
672 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 );
675 proshade_signed xPre, yPre, zPre;
676 xPre = std::abs ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsWgh ) ) / 2 );
677 yPre = std::abs ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsWgh ) ) / 2 );
678 zPre = std::abs ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsWgh ) ) / 2 );
680 if ( ( (
static_cast< proshade_signed
> ( xDimInds ) -
static_cast< proshade_signed
> ( xDimIndsWgh ) ) % 2 ) == 1 ) { xPre -= 1; }
681 if ( ( (
static_cast< proshade_signed
> ( yDimInds ) -
static_cast< proshade_signed
> ( yDimIndsWgh ) ) % 2 ) == 1 ) { yPre -= 1; }
682 if ( ( (
static_cast< proshade_signed
> ( zDimInds ) -
static_cast< proshade_signed
> ( zDimIndsWgh ) ) % 2 ) == 1 ) { zPre -= 1; }
685 fftw_execute ( planForwardFourier );
688 proshade_signed maskMapIndex = 0;
689 proshade_signed densMapIndex = 0;
690 proshade_signed xMaskPos, yMaskPos, zMaskPos, xDensPos, yDensPos, zDensPos;
691 proshade_signed maskH, maskK, maskL;
694 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimIndsWgh ); xIt++ )
696 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimIndsWgh ); yIt++ )
698 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimIndsWgh ); zIt++ )
701 maskH = xIt +
static_cast< proshade_signed
> ( (xDimIndsWgh+1) / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimIndsWgh ) ) { maskH -= xDimIndsWgh; }
702 maskK = yIt +
static_cast< proshade_signed
> ( (yDimIndsWgh+1) / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimIndsWgh ) ) { maskK -= yDimIndsWgh; }
703 maskL = zIt +
static_cast< proshade_signed
> ( (zDimIndsWgh+1) / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimIndsWgh ) ) { maskL -= zDimIndsWgh; }
706 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( yIt +
static_cast< proshade_signed
> ( yDimIndsWgh ) * xIt );
707 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( maskK +
static_cast< proshade_signed
> ( yDimIndsWgh ) * maskH );
710 origCoeffsHKL[densMapIndex][0] = origCoeffs[maskMapIndex][0];
711 origCoeffsHKL[densMapIndex][1] = origCoeffs[maskMapIndex][1];
717 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
719 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
721 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
724 if ( xDimIndsWgh >= xDimInds ) { xMaskPos = xIt + xPre; }
725 else { xMaskPos = xIt - xPre; }
729 if ( yDimIndsWgh >= yDimInds ) { yMaskPos = yIt + yPre; }
730 else { yMaskPos = yIt - yPre; }
734 if ( zDimIndsWgh >= zDimInds ) { zMaskPos = zIt + zPre; }
735 else { zMaskPos = zIt - zPre; }
739 if ( ( xMaskPos < 0 ) || ( xMaskPos >=
static_cast< proshade_signed
> ( xDimIndsWgh ) ) ) {
continue; }
740 if ( ( yMaskPos < 0 ) || ( yMaskPos >=
static_cast< proshade_signed
> ( yDimIndsWgh ) ) ) {
continue; }
741 if ( ( zMaskPos < 0 ) || ( zMaskPos >=
static_cast< proshade_signed
> ( zDimIndsWgh ) ) ) {
continue; }
744 maskMapIndex = zMaskPos +
static_cast< proshade_signed
> ( zDimIndsWgh ) * ( yMaskPos +
static_cast< proshade_signed
> ( yDimIndsWgh ) * xMaskPos );
745 densMapIndex = zDensPos +
static_cast< proshade_signed
> ( zDimInds ) * ( yDensPos +
static_cast< proshade_signed
> ( yDimInds ) * xDensPos );
748 modifCoeffsHKL[densMapIndex][0] = origCoeffsHKL[maskMapIndex][0];
749 modifCoeffsHKL[densMapIndex][1] = origCoeffsHKL[maskMapIndex][1];
755 for ( proshade_signed xIt = 0; xIt < static_cast< proshade_signed > ( xDimInds ); xIt++ )
757 for ( proshade_signed yIt = 0; yIt < static_cast< proshade_signed > ( yDimInds ); yIt++ )
759 for ( proshade_signed zIt = 0; zIt < static_cast< proshade_signed > ( zDimInds ); zIt++ )
762 maskH = xIt +
static_cast< proshade_signed
> ( xDimInds / 2 );
if ( maskH >=
static_cast< proshade_signed
> ( xDimInds ) ) { maskH -= xDimInds; }
763 maskK = yIt +
static_cast< proshade_signed
> ( yDimInds / 2 );
if ( maskK >=
static_cast< proshade_signed
> ( yDimInds ) ) { maskK -= yDimInds; }
764 maskL = zIt +
static_cast< proshade_signed
> ( zDimInds / 2 );
if ( maskL >=
static_cast< proshade_signed
> ( zDimInds ) ) { maskL -= zDimInds; }
767 maskMapIndex = zIt +
static_cast< proshade_signed
> ( zDimInds ) * ( yIt +
static_cast< proshade_signed
> ( yDimInds ) * xIt );
768 densMapIndex = maskL +
static_cast< proshade_signed
> ( zDimInds ) * ( maskK +
static_cast< proshade_signed
> ( yDimInds ) * maskH );
771 modifCoeffs[densMapIndex][0] = modifCoeffsHKL[maskMapIndex][0];
772 modifCoeffs[densMapIndex][1] = modifCoeffsHKL[maskMapIndex][1];
778 fftw_execute ( inverseFoourier );
781 weightsFinal =
new proshade_double [origVolume];
785 for (
size_t iter = 0; iter < origVolume; iter++ ) { weightsFinal[iter] = outMap[iter][0]; }
788 fftw_destroy_plan ( planForwardFourier );
789 fftw_destroy_plan ( inverseFoourier );
791 delete[] modifCoeffs;
792 delete[] origCoeffsHKL;
793 delete[] modifCoeffsHKL;
799 weightsFinal =
new proshade_double [origVolume];
801 for (
size_t iter = 0; iter < origVolume; iter++ ) { weightsFinal[iter] = weights[iter]; }
805 fftw_complex* inMap =
new fftw_complex [origVolume];
806 fftw_complex* outMap =
new fftw_complex [origVolume];
809 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 );
810 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 );
813 for (
size_t iter = 0; iter < static_cast< size_t > ( origVolume ); iter++ ) { inMap[iter][0] = map[iter]; inMap[iter][1] = 0.0; }
816 fftw_execute ( planForwardFourier );
819 proshade_double normFactor =
static_cast<proshade_double
> ( origVolume );
820 for (
size_t iter = 0; iter < static_cast< size_t > ( origVolume ); iter++ ) { outMap[iter][0] *= weightsFinal[iter] / normFactor; outMap[iter][1] *= weightsFinal[iter] / normFactor; }
823 fftw_execute ( inverseFoourier );
826 for (
size_t iter = 0; iter < static_cast< size_t > ( xDimInds * yDimInds * zDimInds ); iter++ ) { map[iter] = inMap[iter][0]; }
829 delete[] weightsFinal;
832 fftw_destroy_plan ( planForwardFourier );
833 fftw_destroy_plan ( inverseFoourier );
873 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 )
876 map->set_header_i32 ( 1 ,
static_cast<int32_t
> ( xDimInds ) );
877 map->set_header_i32 ( 2 ,
static_cast<int32_t
> ( yDimInds ) );
878 map->set_header_i32 ( 3 ,
static_cast<int32_t
> ( zDimInds ) );
879 map->set_header_i32 ( 4 ,
static_cast<int32_t
> ( mode ) );
880 map->set_header_i32 ( 5 ,
static_cast<int32_t
> ( xFrom ) );
881 map->set_header_i32 ( 6 ,
static_cast<int32_t
> ( yFrom ) );
882 map->set_header_i32 ( 7 ,
static_cast<int32_t
> ( zFrom ) );
883 map->set_header_i32 ( 8 ,
static_cast<int32_t
> ( xGridInds ) );
884 map->set_header_i32 ( 9 ,
static_cast<int32_t
> ( yGridInds ) );
885 map->set_header_i32 ( 10,
static_cast<int32_t
> ( zGridInds ) );
886 map->set_header_float ( 11,
static_cast<float> ( xDim ) );
887 map->set_header_float ( 12,
static_cast<float> ( yDim ) );
888 map->set_header_float ( 13,
static_cast<float> ( zDim ) );
889 map->set_header_float ( 14,
static_cast<float> ( aAng ) );
890 map->set_header_float ( 15,
static_cast<float> ( bAng ) );
891 map->set_header_float ( 16,
static_cast<float> ( cAng ) );
892 map->set_header_i32 ( 17,
static_cast<int32_t
> ( xAxOrder ) );
893 map->set_header_i32 ( 18,
static_cast<int32_t
> ( yAxOrder ) );
894 map->set_header_i32 ( 19,
static_cast<int32_t
> ( zAxOrder ) );
895 if ( map->grid.spacegroup ) { map->set_header_i32 ( 23,
static_cast<int32_t
> ( map->grid.spacegroup->ccp4 ) ); }
896 else { map->set_header_i32 ( 23,
static_cast<int32_t
> ( 1 ) ); }
897 map->set_header_i32 ( 24,
static_cast<int32_t
> ( map->grid.spacegroup->operations().order() * 80 ) );
898 map->set_header_str ( 27,
"CCP4" );
899 map->set_header_i32 ( 28,
static_cast<int32_t
> ( 20140 ) );
900 map->set_header_i32 ( 50,
static_cast<int32_t
> ( xAxOrigin ) );
901 map->set_header_i32 ( 51,
static_cast<int32_t
> ( yAxOrigin ) );
902 map->set_header_i32 ( 52,
static_cast<int32_t
> ( zAxOrigin ) );
903 map->set_header_str ( 53,
"MAP" );
904 if ( gemmi::is_little_endian() ) { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x00004144 ) ); }
905 else { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x11110000 ) ); }
906 map->set_header_i32 ( 56,
static_cast<int32_t
> ( 1 ) );
907 std::memset (
reinterpret_cast<void*
> ( &(map->ccp4_header.at( 56 )) ),
' ',
static_cast< size_t > ( 800 + map->grid.spacegroup->operations().order() * 80 ) );
908 map->set_header_str ( 57, title );
965 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 )
968 std::ofstream jsonFile;
969 jsonFile.open ( fileName );
972 if ( !jsonFile.is_open( ) )
974 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." );
978 proshade_double* rotMat =
new proshade_double[9];
984 jsonFile <<
" \"translationToOrigin\" : [ " << trsX1 <<
", " << trsY1 <<
", " << trsZ1 <<
" ], \n";
986 jsonFile <<
" \"rotationMatrix:\" : [ " << rotMat[0] <<
", " << rotMat[1] <<
", " << rotMat[2] <<
", \n";
987 jsonFile <<
" " << rotMat[3] <<
", " << rotMat[4] <<
", " << rotMat[5] <<
", \n";
988 jsonFile <<
" " << rotMat[6] <<
", " << rotMat[7] <<
", " << rotMat[8] <<
"], \n";
990 jsonFile <<
" \"translationFromRotCenToOverlay\" : [ " << trsX2 <<
", " << trsY2 <<
", " << trsZ2 <<
" ] \n";