37 gemmi::Structure structure = gemmi::read_structure ( gemmi::MaybeGzipped ( fName ) );
39 catch ( std::runtime_error& e )
59 gemmi::Ccp4<float> map;
62 map.read_ccp4 ( gemmi::MaybeGzipped (fName.c_str() ) );
64 catch ( std::runtime_error& e )
103 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 )
106 *xDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 1 ) );
107 *yDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 2 ) );
108 *zDimInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 3 ) );
110 *xFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 5 ) );
111 *yFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 6 ) );
112 *zFrom =
static_cast<proshade_signed
> ( map->header_i32 ( 7 ) );
114 *xDim =
static_cast<proshade_single
> ( map->header_float ( 11 ) );
115 *yDim =
static_cast<proshade_single
> ( map->header_float ( 12 ) );
116 *zDim =
static_cast<proshade_single
> ( map->header_float ( 13 ) );
118 *aAng =
static_cast<proshade_single
> ( map->header_float ( 14 ) );
119 *bAng =
static_cast<proshade_single
> ( map->header_float ( 15 ) );
120 *cAng =
static_cast<proshade_single
> ( map->header_float ( 16 ) );
122 *xAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 50 ) ) + (*xFrom);
123 *yAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 51 ) ) + (*yFrom);
124 *zAxOrigin =
static_cast<proshade_signed
> ( map->header_i32 ( 52 ) ) + (*zFrom);
126 *xAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 17 ) );
127 *yAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 18 ) );
128 *zAxOrder =
static_cast<proshade_unsign
> ( map->header_i32 ( 19 ) );
130 *xGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 8 ) );
131 *yGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 9 ) );
132 *zGridInds =
static_cast<proshade_unsign
> ( map->header_i32 ( 10 ) );
135 if ( *xGridInds != *xDimInds )
137 *xDim = *xDim * (
static_cast<proshade_single
> ( *xDimInds ) /
static_cast<proshade_single
> ( *xGridInds ) );
138 *xGridInds = *xDimInds;
141 if ( *yGridInds != *yDimInds )
143 *yDim = *yDim * (
static_cast<proshade_single
> ( *yDimInds ) /
static_cast<proshade_single
> ( *yGridInds ) );
144 *yGridInds = *yDimInds;
147 if ( *zGridInds != *zDimInds )
149 *zDim = *zDim * (
static_cast<proshade_single
> ( *zDimInds ) /
static_cast<proshade_single
> ( *zGridInds ) );
150 *zGridInds = *zDimInds;
172 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 )
175 proshade_unsign *axOrdArr =
new proshade_unsign[3];
176 proshade_unsign *axDimArr =
new proshade_unsign[3];
177 proshade_unsign arrPos = 0;
182 axDimArr[0] = xDimInds;
183 axDimArr[1] = yDimInds;
184 axDimArr[2] = zDimInds;
187 map =
new proshade_double [xDimInds * yDimInds * zDimInds];
191 for ( axOrdArr[0] = 0; axOrdArr[0] < axDimArr[xAxOrder-1]; axOrdArr[0]++ )
193 for ( axOrdArr[1] = 0; axOrdArr[1] < axDimArr[yAxOrder-1]; axOrdArr[1]++ )
195 for ( axOrdArr[2] = 0; axOrdArr[2] < axDimArr[zAxOrder-1]; axOrdArr[2]++ )
197 arrPos = axOrdArr[2] + axDimArr[zAxOrder-1] * ( axOrdArr[1] + axDimArr[yAxOrder-1] * axOrdArr[0] );
198 map[arrPos] = gemmiMap->grid.get_value_q( axOrdArr[xAxOrder-1], axOrdArr[yAxOrder-1], axOrdArr[zAxOrder-1] );
242 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 )
245 map->set_header_i32 ( 1 ,
static_cast<int32_t
> ( xDimInds ) );
246 map->set_header_i32 ( 2 ,
static_cast<int32_t
> ( yDimInds ) );
247 map->set_header_i32 ( 3 ,
static_cast<int32_t
> ( zDimInds ) );
248 map->set_header_i32 ( 4 ,
static_cast<int32_t
> ( mode ) );
249 map->set_header_i32 ( 5 ,
static_cast<int32_t
> ( xFrom ) );
250 map->set_header_i32 ( 6 ,
static_cast<int32_t
> ( yFrom ) );
251 map->set_header_i32 ( 7 ,
static_cast<int32_t
> ( zFrom ) );
252 map->set_header_i32 ( 8 ,
static_cast<int32_t
> ( xGridInds ) );
253 map->set_header_i32 ( 9 ,
static_cast<int32_t
> ( yGridInds ) );
254 map->set_header_i32 ( 10,
static_cast<int32_t
> ( zGridInds ) );
255 map->set_header_float ( 11,
static_cast<float> ( xDim ) );
256 map->set_header_float ( 12,
static_cast<float> ( yDim ) );
257 map->set_header_float ( 13,
static_cast<float> ( zDim ) );
258 map->set_header_float ( 14,
static_cast<float> ( aAng ) );
259 map->set_header_float ( 15,
static_cast<float> ( bAng ) );
260 map->set_header_float ( 16,
static_cast<float> ( cAng ) );
261 map->set_header_i32 ( 17,
static_cast<int32_t
> ( xAxOrder ) );
262 map->set_header_i32 ( 18,
static_cast<int32_t
> ( yAxOrder ) );
263 map->set_header_i32 ( 19,
static_cast<int32_t
> ( zAxOrder ) );
264 if ( map->grid.spacegroup ) { map->set_header_i32 ( 23,
static_cast<int32_t
> ( map->grid.spacegroup->ccp4 ) ); }
265 else { map->set_header_i32 ( 23,
static_cast<int32_t
> ( 1 ) ); }
266 map->set_header_i32 ( 24,
static_cast<int32_t
> ( map->grid.spacegroup->operations().order() * 80 ) );
267 map->set_header_str ( 27,
"CCP4" );
268 map->set_header_i32 ( 28,
static_cast<int32_t
> ( 20140 ) );
269 map->set_header_i32 ( 50,
static_cast<int32_t
> ( xAxOrigin ) );
270 map->set_header_i32 ( 51,
static_cast<int32_t
> ( yAxOrigin ) );
271 map->set_header_i32 ( 52,
static_cast<int32_t
> ( zAxOrigin ) );
272 map->set_header_str ( 53,
"MAP" );
273 if ( gemmi::is_little_endian() ) { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x00004144 ) ); }
274 else { map->set_header_i32 ( 54,
static_cast<int32_t
> ( 0x11110000 ) ); }
275 map->set_header_i32 ( 56,
static_cast<int32_t
> ( 1 ) );
276 std::memset (
reinterpret_cast<void*
> ( &(map->ccp4_header.at( 56 )) ),
' ', 800 + map->grid.spacegroup->operations().order() * 80);
277 map->set_header_str ( 57, title );
334 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 )
337 std::ofstream jsonFile;
338 jsonFile.open ( fileName );
341 if ( !jsonFile.is_open( ) )
343 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." );
347 proshade_double* rotMat =
new proshade_double[9];
353 jsonFile <<
" \"translationToOrigin\" : [ " << trsX1 <<
", " << trsY1 <<
", " << trsZ1 <<
" ], \n";
355 jsonFile <<
" \"rotationMatrix:\" : [ " << rotMat[0] <<
", " << rotMat[1] <<
", " << rotMat[2] <<
", \n";
356 jsonFile <<
" " << rotMat[3] <<
", " << rotMat[4] <<
", " << rotMat[5] <<
", \n";
357 jsonFile <<
" " << rotMat[6] <<
", " << rotMat[7] <<
", " << rotMat[8] <<
"], \n";
359 jsonFile <<
" \"translationFromRotCenToOverlay\" : [ " << trsX2 <<
", " << trsY2 <<
", " << trsZ2 <<
" ] \n";