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] ) ) );
306 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 )
309 map->set_header_i32 ( 1 ,
static_cast<int32_t
> ( xDimInds ) );
310 map->set_header_i32 ( 2 ,
static_cast<int32_t
> ( yDimInds ) );
311 map->set_header_i32 ( 3 ,
static_cast<int32_t
> ( zDimInds ) );
312 map->set_header_i32 ( 4 ,
static_cast<int32_t
> ( mode ) );
313 map->set_header_i32 ( 5 ,
static_cast<int32_t
> ( xFrom ) );
314 map->set_header_i32 ( 6 ,
static_cast<int32_t
> ( yFrom ) );
315 map->set_header_i32 ( 7 ,
static_cast<int32_t
> ( zFrom ) );
316 map->set_header_i32 ( 8 ,
static_cast<int32_t
> ( xGridInds ) );
317 map->set_header_i32 ( 9 ,
static_cast<int32_t
> ( yGridInds ) );
318 map->set_header_i32 ( 10,
static_cast<int32_t
> ( zGridInds ) );
319 map->set_header_float ( 11,
static_cast<float> ( xDim ) );
320 map->set_header_float ( 12,
static_cast<float> ( yDim ) );
321 map->set_header_float ( 13,
static_cast<float> ( zDim ) );
322 map->set_header_float ( 14,
static_cast<float> ( aAng ) );
323 map->set_header_float ( 15,
static_cast<float> ( bAng ) );
324 map->set_header_float ( 16,
static_cast<float> ( cAng ) );
325 map->set_header_i32 ( 17,
static_cast<int32_t
> ( xAxOrder ) );
326 map->set_header_i32 ( 18,
static_cast<int32_t
> ( yAxOrder ) );
327 map->set_header_i32 ( 19,
static_cast<int32_t
> ( zAxOrder ) );
328 if ( map->grid.spacegroup ) { map->set_header_i32 ( 23,
static_cast<int32_t
> ( map->grid.spacegroup->ccp4 ) ); }
329 else { map->set_header_i32 ( 23,
static_cast<int32_t
> ( 1 ) ); }
330 map->set_header_i32 ( 24,
static_cast<int32_t
> ( map->grid.spacegroup->operations().order() * 80 ) );
331 map->set_header_str ( 27,
"CCP4" );
332 map->set_header_i32 ( 28,
static_cast<int32_t
> ( 20140 ) );
333 map->set_header_i32 ( 50,
static_cast<int32_t
> ( xAxOrigin ) );
334 map->set_header_i32 ( 51,
static_cast<int32_t
> ( yAxOrigin ) );
335 map->set_header_i32 ( 52,
static_cast<int32_t
> ( zAxOrigin ) );
336 map->set_header_str ( 53,
"MAP" );
337 if ( gemmi::is_little_endian() ) { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x00004144 ) ); }
338 else { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x11110000 ) ); }
339 map->set_header_i32 ( 56,
static_cast<int32_t
> ( 1 ) );
340 std::memset (
reinterpret_cast<void*
> ( &(map->ccp4_header.at( 56 )) ),
' ',
static_cast< size_t > ( 800 + map->grid.spacegroup->operations().order() * 80 ) );
341 map->set_header_str ( 57, title );
398 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 )
401 std::ofstream jsonFile;
402 jsonFile.open ( fileName );
405 if ( !jsonFile.is_open( ) )
407 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." );
411 proshade_double* rotMat =
new proshade_double[9];
417 jsonFile <<
" \"translationToOrigin\" : [ " << trsX1 <<
", " << trsY1 <<
", " << trsZ1 <<
" ], \n";
419 jsonFile <<
" \"rotationMatrix:\" : [ " << rotMat[0] <<
", " << rotMat[1] <<
", " << rotMat[2] <<
", \n";
420 jsonFile <<
" " << rotMat[3] <<
", " << rotMat[4] <<
", " << rotMat[5] <<
", \n";
421 jsonFile <<
" " << rotMat[6] <<
", " << rotMat[7] <<
", " << rotMat[8] <<
"], \n";
423 jsonFile <<
" \"translationFromRotCenToOverlay\" : [ " << trsX2 <<
", " << trsY2 <<
", " << trsZ2 <<
" ] \n";