IMP  2.2.0
The Integrative Modeling Platform
DensityHeader.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/DensityHeader.h
3  * \brief Metadata for a density file.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_DENSITY_HEADER_H
10 #define IMPEM_DENSITY_HEADER_H
11 
12 #include <IMP/em/em_config.h>
13 #include "def.h"
14 #include <IMP/base/exception.h>
15 #include <iostream>
16 #include <fstream>
17 #include <cstring>
18 #include <limits>
20 #include <IMP/base/Object.h>
21 IMPEM_BEGIN_NAMESPACE
22 
23 /** \todo change so that the att will not be encoded but loaded from
24  a conf file (Keren) */
25 class IMPEMEXPORT DensityHeader {
26 
27  public:
28  DensityHeader();
29  // If a copy constructor is not defined in a class, the compiler itself
30  // defines one. This will ensure a shallow copy.
31  // If the class does not have pointer variables with dynamically allocated
32  // memory, then one need not worry about defining a
33  // copy constructor. It can be left to the compiler's discretion.
34  // But if the class has pointer variables and has some dynamic memory
35  // allocations, then it is a must to have a copy constructor.
36 
37  //! gets the upper bound of the grid
38  /** \param[in] ind The dimension index x:=0,y:=1,z:=2
39  \return the coordinate value in angstroms
40  */
41  emreal get_top(int ind) const {
42  IMP_USAGE_CHECK(top_calculated_,
43  " DensityHeader::get_top the top coordinates of the map "
44  << "have not been setup yet " << std::endl);
45  if (ind == 0) return xtop_;
46  if (ind == 1) return ytop_;
47  return ztop_;
48  }
49  //! Compute the farthest point of the grid.
50  /**
51  /param[in] force if true then the top point is calculated
52  even if it has already been calcualted.
53  */
54  void compute_xyz_top(bool force = false);
55 
56  //! Update the dimensions of the map to be (nnx,nny,nnz)
57  //!The origin of the map does not change
58  /**
59  /param[in] nnx the new number of voxels on the X axis
60  /param[in] nny the new number of voxels on the Y axis
61  /param[in] nnz the new number of voxels on the Z axis
62  */
63  void update_map_dimensions(int nnx, int nny, int nnz);
64 
65  //! Update the cell dimensions of the map multiplying the number of voxels
66  //! along each direction by the Objectpixelsize
67  void update_cell_dimensions();
68 
69  void show(std::ostream& out = std::cout) const;
70 
71  static const unsigned short MAP_FIELD_SIZE = 4;
72  static const unsigned short USER_FIELD_SIZE = 25;
73  static const unsigned short COMMENT_FIELD_NUM_OF = 10;
74  static const unsigned short COMMENT_FIELD_SINGLE_SIZE = 80;
75 
76  //! number of first columns in map (x-dimension)
77  int nxstart;
78  //! number of first columns in map (y-dimension)
79  int nystart;
80  //! number of first columns in map (z-dimension)
81  int nzstart;
82 
83  int mx, my, mz; // Number of intervals along each dimension
84  float xlen, ylen, zlen; // Cell dimensions (angstroms)
85  float alpha, beta, gamma; // Cell angles (degrees)
86  //! Axes corresponding to columns (mapc), rows (mapr) and sections (maps)
87  //! (1,2,3 for x,y,z)
88  int mapc, mapr, maps;
89  float dmin, dmax, dmean; // Minimum, maximum and mean density value
90  int ispg; // space group number 0 or 1
91  int nsymbt; // Number of bytes used for symmetry data
92  int user[USER_FIELD_SIZE]; // extra space used for anything
93  char map[MAP_FIELD_SIZE]; // character string 'MAP ' to identify file type
94  int machinestamp; // machine stamp (0x11110000 bigendian, 0x44440000 little)
95  float rms; // RMS deviation of map from mean density
96  int nlabl; // Number of labels being used
97  //! text comments \todo MRC: labels[10][80] - should it be a different field?
98  char comments[COMMENT_FIELD_NUM_OF][COMMENT_FIELD_SINGLE_SIZE];
99  //! magic byte for machine platform (~endian), OS-9=0, VAX=1, Convex=2,
100  //! SGI=3, Sun=4, Mac(Motorola)=5, PC,IntelMac=6
101  int magic;
102  float voltage; // Voltage of electron microscope
103  float Cs; // Cs of microscope
104  float Aperture; // Aperture used
105  float Magnification; // Magnification
106  float Postmagnification; // Postmagnification (of energy filter)
107  float Exposuretime; // Exposuretime
108  float Microscope; // Microscope
109  float Pixelsize; // Pixelsize - used for the microscope CCD camera
110  float CCDArea; // CCDArea
111  float Defocus; // Defocus
112  float Astigmatism; // Astigmatism
113  float AstigmatismAngle; // Astigmatism Angle
114  float FocusIncrement; // Focus-Increment
115  float CountsPerElectron; // Counts/Electron
116  float Intensity; // Intensity
117  float EnergySlitwidth; // Energy slitwidth of energy filter
118  float EnergyOffset; // Energy offset of Energy filter
119  float Tiltangle; // Tiltangle of stage
120  float Tiltaxis; // Tiltaxis
121  float MarkerX; // Marker_X coordinate
122  float MarkerY; // Marker_Y coordinate
123  int lswap;
124 
125  //! Returns the resolution of the map
126  inline float get_resolution() const {
127  IMP_INTERNAL_CHECK(is_resolution_set_, "The resolution was not set"
128  << std::endl);
129  return resolution_;
130  }
131  //! Return if the resolution has been set
132  inline bool get_has_resolution() const { return is_resolution_set_; }
133  //! Sets the resolution of the map
134  inline void set_resolution(float resolution) {
135  is_resolution_set_ = true;
136  resolution_ = resolution;
137  }
138  /** \note Use DensityMap::update_voxel_size() to set the spacing value.
139  */
140  inline float get_spacing() const { return Objectpixelsize_; }
141  //! Returns the origin on the map (x-coordinate)
142  inline float get_xorigin() const { return xorigin_; }
143  //! Returns the origin on the map (y-coordinate)
144  inline float get_yorigin() const { return yorigin_; }
145  //! Returns the origin on the map (z-coordinate)
146  inline float get_zorigin() const { return zorigin_; }
147  //! Returns the origin on the map
148  /**
149  \param[in] i the relevant coordinate (0:x, 1:y, 2:z)
150  \exception ValueException if the value of i is out of range.
151  */
152  inline float get_origin(int i) const {
153  IMP_USAGE_CHECK(i >= 0 && i <= 2,
154  "The origin coordinate should be between 0 and 2");
155  switch (i) {
156  case 0:
157  return get_xorigin();
158  case 1:
159  return get_yorigin();
160  default:
161  return get_zorigin();
162  }
163  }
164  //! Sets the origin on the map (x-coordinate).
165  /**
166  \note This is an absolute position in space.
167  */
168  inline void set_xorigin(float x) {
169  xorigin_ = x;
170  top_calculated_ = false;
171  }
172  //! Sets the origin on the map (y-coordinate)
173  /**
174  \note This is an absolute position in space.
175  */
176  inline void set_yorigin(float y) {
177  yorigin_ = y;
178  top_calculated_ = false;
179  }
180  //! Sets the origin on the map (z-coordinate)
181  /**
182  \note This is an absolute position in space.
183  */
184  inline void set_zorigin(float z) {
185  zorigin_ = z;
186  top_calculated_ = false;
187  }
188  //! True if the top coodinates (bounding-box) are calculated
189  inline bool is_top_calculated() const { return top_calculated_; }
190  float Objectpixelsize_; // this is the actual pixelsize
191 
192  // get/set functions
193  //! Get the number of voxels in the x dimension
194  inline int get_nx() const { return nx_; }
195  //! Get the number of voxels in the y dimension
196  inline int get_ny() const { return ny_; }
197  //! Get the number of voxels in the z dimension
198  inline int get_nz() const { return nz_; }
199  inline int get_number_of_voxels() const { return nx_ * ny_ * nz_; }
200  //! Get the number of bits that used to store the density of a single voxel
201  inline int get_data_type() const { return data_type_; }
202  inline void set_data_type(int data_type) { data_type_ = data_type; }
203 
204  protected:
205  float xtop_, ytop_, ztop_; // The upper bound for the x,y and z grid.
206  float xorigin_, yorigin_, zorigin_; // Origin used for transforms
207  bool top_calculated_;
208  float resolution_;
209  bool is_resolution_set_;
210  int nx_, ny_, nz_; // map size (voxels) in x,y,z dimensions
211  //! How many bits are used to store the density of a single voxel
212  //! (used in MRC format)
214 };
215 
216 //! Create a header from a bounding box 3D
217 /**
218  See DensityHeader
219 */
220 IMPEMEXPORT DensityHeader
221  create_density_header(const algebra::BoundingBoxD<3>& bb, float spacing);
222 
223 IMPEM_END_NAMESPACE
224 
225 #endif /* IMPEM_DENSITY_HEADER_H */
float get_resolution() const
Returns the resolution of the map.
int nxstart
number of first columns in map (x-dimension)
Definition: DensityHeader.h:77
bool is_top_calculated() const
True if the top coodinates (bounding-box) are calculated.
Definitions for EMBED.
float get_spacing() const
float get_yorigin() const
Returns the origin on the map (y-coordinate)
void set_zorigin(float z)
Sets the origin on the map (z-coordinate)
float get_zorigin() const
Returns the origin on the map (z-coordinate)
void set_resolution(float resolution)
Sets the resolution of the map.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
emreal get_top(int ind) const
gets the upper bound of the grid
Definition: DensityHeader.h:41
int nystart
number of first columns in map (y-dimension)
Definition: DensityHeader.h:79
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
DensityHeader create_density_header(const algebra::BoundingBoxD< 3 > &bb, float spacing)
Create a header from a bounding box 3D.
A bounding box in D dimensions.
bool get_has_resolution() const
Return if the resolution has been set.
int get_nx() const
Get the number of voxels in the x dimension.
void set_xorigin(float x)
Sets the origin on the map (x-coordinate).
Exception definitions and assertions.
int get_ny() const
Get the number of voxels in the y dimension.
float get_origin(int i) const
Returns the origin on the map.
void set_yorigin(float y)
Sets the origin on the map (y-coordinate)
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
int nzstart
number of first columns in map (z-dimension)
Definition: DensityHeader.h:81
float get_xorigin() const
Returns the origin on the map (x-coordinate)
int get_nz() const
Get the number of voxels in the z dimension.
A shared base class to help in debugging and things.
int get_data_type() const
Get the number of bits that used to store the density of a single voxel.