crystallography module¶
Crystallographic operations.
Module author: Michael S. Chapman <chapmami@ohsu.edu>
Authors: | Michael S. Chapman <chapmami@ohsu.edu>, Oregon Health & Science University |
---|---|
Version: | 0.5, March 23, 2016 |
Changed in version 12/09: (EMScale)
Changed in version 0.1: 07/27/10
Changed in version 0.5.0: (3/19/15) ReStructured Text documentation
-
class
crystallography.
MapOrthogonal
(**kwds)¶ Inter-conversion of map grid/pixel and orthogonal Angstrom coordinates.
Assumes that the map is stored in a row-major (C-like) 3D array starting at [0,0,0].
Variables: - orthog (3x3 numpy.matrix) – matrix to scale/rotate grid to orthonormal Angstrom coord.
- origin (numpy.matrix(shape=3)) – translation of map origin to orthonormal Angstrom coord.
- orthoxyz (bool) – true if map grid orthonormal in (‘X’,’Y’,’Z’) orientation.
- volume (float) – pixel volume (Angstrom^2).
- spacing – perpendicular distances between faces [A, B, C] of the pixel.
- orthonormal (bool) – True if pixel has orthonormal shape
Note
If
orthoxyz
: positions may be calculated by scalar multiplication by grid step instead of matrix multiplication.Note
to enclose a sphere, radius r, centered on a grid point, need 2n+1 grid points, where n = r / spacing.
Initialize operators to interconvert map indices & orthogonal coords.
The forward operator consists of a scaling/rotation matrix and a vector which defines the position of the first map element ([0,0,0]). It will be constructed one of two ways, depending on which named arguments are provided:
- Calculated from crystallographic parmeters if named argument
orthogonalize_unit_cell
is provided - see methodfrom_unit_cell()
. - Direct input of
matrix
&ortho_origin
(default) see methodnew()
.
Note: Most crystallographic maps are calculated on grids parallel to the unit cell axes, for which option 1 will be appropriate. However, this is not required here. If the density has been (re-)mapped to a different grid, or used an arbitrary grid placed over a non-periodic structure (electron microscopy), then option 2 would be appropriate. Indeed, some calculations may be more efficient following interpolation of crystallographic maps onto orthogonal grids (prior to this call).
-
deorthogonalize
(orthonormal_coordinates)¶ Deorthogonalize, converting from orthonormal Angstrom to map grid index.
Parameters: orthonormal_coordinates (numpy.matrix(float, shape=(3,1)) – position in Cartesian space Returns: m as column vector, where m = [O]^(-1) (x - o) and m is a map array index vector, x a position in orthonormal Angstrom coordinates and o is the map origin (Angstrom coordinates of 1st element). Return type: NumPy.matrix(float,shape=(3,1)) Note
For fast application to many points, may want to copy properties
orthog
&origin
; or rundeorthogonalize_vec()
-
deorthogonalize_vec
(orthonormal_coordinates)¶ Vectorized version of deorthogonalize.
Parameters: orthonormal_coordinates (numpy.matrix(float, shape=(3,N))) – N positions in Cartesian space Returns: m as N column vectors, where m = [O]^(-1) (x - o) and m is a map array index vector, x a position in orthonormal Angstrom coordinates and o is the map origin (Angstrom coordinates of 1st element). Return type: NumPy.matrix(float,shape=(3,N)) Warning
no dimension/type checking in this version.
-
from_unit_cell
(orthogonalize_unit_cell=None, map_permutation=('Z', 'Y', 'X'), grid_spacing=None, frac_origin=matrix([[ 0., 0., 0.]]))¶ Calculate operator between map & orthonormal coords from crystal param.
Parameters: - orthogonalize_unit_cell (ndarray-like(type=float, shape=(3,3)) – the orthogonalization matrix, converting crystallographic fractional coordinates to orthonormal Angstrom: [[a_X, b_X, c_X][0, b_Y, c_Y][0, 0, c_Z]], where [0,X,Y,Z] is the orthonormal Angstrom system and (a,b,c) are the unit cell vectors. See
OrthogonalizationMatrix
for calculation of the matrix. - map_permutation (string tuple (3)) – symbolic identification of the crystallographic axes along the slow, medium and fast map directions, each specified by an optional “-” and a single character X, Y, or Z, eg. (‘X’, ‘Y’, ‘Z’) or (‘Y’, ‘-X’, ‘Z’). Note that this refers to the internal map permutation, which is assumed to be in the “row-major” order of C (rightmost array index changes fastest and moves across row 1, then row 2...). Thus, the permutation may be in the reversed order from that used in a “column-major” Fortran program where the leftmost index changes fastest. CCTBX and X-plor files appear to have X slowest, Z fastest, i.e. (“X”, “Y”, “Z”) in the notation used here.
- grid_spacing (ndarray-like(type=float, size=3)) – spacing (Angstrom) in the directions of the a, b and c crystallographic axes respectively.
- frac_origin (ndarray-like(type=float, shape=3)) – position of the first map grid point in fractional crystallographic coordinates.
Returns: ([O], o) in x = [O]m + o, where m is a map array index vector and x a position in orthonormal Angstrom coordinates.
Return type: NumPy.matrix(3,3), NumPy.matrix(3,1)
- orthogonalize_unit_cell (ndarray-like(type=float, shape=(3,3)) – the orthogonalization matrix, converting crystallographic fractional coordinates to orthonormal Angstrom: [[a_X, b_X, c_X][0, b_Y, c_Y][0, 0, c_Z]], where [0,X,Y,Z] is the orthonormal Angstrom system and (a,b,c) are the unit cell vectors. See
-
getIsOrthogonal
()¶ True if the map is orthonormal (any orientation).
-
getOrigin
()¶
-
getOrthog
()¶
-
getOrthoxyz
()¶ True if the map is orthonormal and oriented xyz.
-
getSpacing
()¶
-
getVolume
()¶
-
isorthogonal
¶ True if the map is orthonormal, any orientation.
-
new
(matrix=None, ortho_origin=matrix([[ 0., 0., 0.]]))¶ Set a new map orthonormalization matrix.
Parameters: - matrix (ndarray-like(type=float, shape=(3,3))) – [[s_X, m_X, f_X][s_Y, m_Y, f_Y][s_Z, m_Z, f_Z] where [0,X,Y,Z] is the orthonormal Angstrom system for atom coordinates and (s, m, f) are pixel-edge (grid) vectors along the slow (sections), medium and fast directions of the map array. Orthonormal grids, should have only three non-zero elements, equal to the grid-spacings in the three directions (Angstrom).
- ortho_origin (ndarray-like(type=float, shape=3)) – position of the first map grid point in orthonormal Angstrom coordinates.
-
origin
¶ orthonormal Angstrom coordinates for 1st map element
-
orthog
¶ map orthogonalization matrix, grid-index to Angstrom
-
orthogonalize
(map_coordinates)¶ Orthogonalize, converting from map grid indices to orthonormal Angstrom.
Parameters: map_coordinates (numpy.matrix(int, shape=(3,1)) – index of a map element Returns: x as column vector, where x = [O]m + o where m is a map array index vector, o is the map origin (Angstrom coordinates of 1st element), and x a position in orthonormal Angstrom coordinates. Return type: NumPy.matrix(float,shape=(3,1))
-
orthogonalize_vec
(map_coordinates)¶ Vectorized orthogonalize: map grid indices to orthonormal Angstrom.
Parameters: map_coordinates (numpy.matrix(int, shape=(3,N)) – indices of a map N map elements Returns: x as column vector, where x = [O]m + o, where m is a map array index vector, o is the map origin (Angstrom coordinates of 1st element), and x a position in orthonormal Angstrom coordinates. Return type: NumPy.matrix(float,shape=(3,N))
-
orthoxyz
¶ True if the map is orthonormal and oriented xyz.
-
spacing
¶ perpendicular Angstrom spacing in each map dimension
-
volume
¶ map pixel volume (A^3)
-
class
crystallography.
OrthogonalizationMatrix
(matrix=None, unit_cell=None)¶ Fractional crystallographic to orthogonal Angstrom coordinates.
Standard PDB convention (Rupp, B., Biomolecular Crystallography A3):
- Cartesian X colinear with crystallographic a.
- Y colinear with (a^b)^X
- Z colinear with (a^b)
Variables: Initialization with matrix or unit cell parameters.
Parameters: - matrix (ndarray-like(type=float, shape=(3,3))) – [[a_X, b_X, c_X][0, b_Y, c_Y][0, 0, c_Z]] where [0,X,Y,Z] is the orthonormal Angstrom system and (a,b,c) are the unit cell vectors.
- unit_cell (tuple or list of size 6) – a, b, c, alpha, beta, gamma (Angstrom, degrees)
-
getOrthog
()¶
-
getVolume
()¶
-
orthog
¶ orthogonalization matrix, fractional to Angstrom
-
volume
¶ unit cell volume (A^3)
-
crystallography.
resolutions
(d_start, d_end, nstep, spacing_type=1, return_type=1, mid_points=False)¶ Iterator over resolution in various forms.
Parameters: - d_start (float) – low resolution limit (real-space, Angstrom, high number).
- d_end (float) – high resolution limit (real-space, Angstrom, low number).
- nstep (int) – number of steps.
- spacing_type (int) – shells will be even in resolution^spacing_type (see below).
- return_type (int) – yielded will be resolution^(return_type/spacing_type).
- mid_points (bool) – return the mid-point of each of nstep shells within range.
spacing_type & return_type each can have the following values:
- +1 - in real-space d (Angstrom)
- -1 - in reciprocal space 1/d (1/Angstrom)
- -2 - in sqared reciprocal space 1/d^2 (1/Angstrom^2)
- -3 - in cubed reciprocal space 1/d^3 with equal volumes / ~reflections
Iterator can be used directly in loops, eg: for
dstar in resolutions(...)
. To save a list, example:[dstar for dstar in resolutions(98.3,12.0,npt,-3,-1,mid_points=True)]