Coordinate Systems Coordinate systems  We have to deal with many coordinate systems in crystallographic software. The book-keeping is not exciting, but it is vital. Simplifications (e.g. Coordinate systems, operators, and assuming orthogonal grids) must usually be paid for transformations. later.

 Examples: Kevin Cowtan  [email protected] Orthogonal Ångstrom coordinates.  Fractional coordinates.  Reciprocal .  Reflection (Miller) indices, i.e. HKLs.  Grid coordinates.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems Coordinate Systems

 In addition, we need to handle:  Conventions for this lecture:  Transformations between these coordinate systems.  scalars are italic, lower case, e.g. s, r  Transformations within a  vectors are italic, lower case and underlined, e.g. v, x, h (i.e. rotation and translation operators).  matrices are italic, uppercase and bold, e.g. O, F, M  Rotation representations.  In addition to matrix notation, most equations are  Derivatives of functions with respect to different also given as explicit sums of terms. coordinate systems.  The elements of a vector or matrix are given by the same  This lecture will give a basic overview of the issues. symbol in italic lower case with an appropriate number of Implementations of all these data types and subscripts. e.g. xi , Oi,j . transformations are a part of both the CCTBX and  All vectors and matrices are of rank 3. Clipper crystallographic libraries.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems Coordinate Systems: Real space Coordinate systems: Orthogonal Ångstrom Coordinates:

 Coordinate are used to describe the positions of  3 orthogonal distances in Ångstroms along elements within the crystal system. e.g. the position directions x, y, z. (Formally: vectors) of a particular atom within a unit cell, or a particular grid point within a grid. y z  3 dimensions -> rank 3. y  Coordinates represented by a vector of 3 numbers.

x x Note: there is no reference to the unit cell at this point. z

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Real space Coordinate Systems: Real space Fractional coordinates: Relating orthogonal and fractional coordinates:

 Position in the unit cell described as a fractional  We can orient and position one coordinate system position along each cell edge: however we want with respect to the other, but...

 It is convenient to adopt some convenient b 1 convention.  The most common convention in the PDB (also the w CCP4 default) is: v Note: since the cell repeats,  Align the a axis along x 0 1 u,v,w repeat on the range 0...1.  Align the b axis in the x-y plane u a We often standardize on the  Or equivalently align z axis perpendicular to a and b 1 range 0...1 (or -1/2...1/2), but this may split a molecule. c

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Real space Coordinate Systems: Real space Relating orthogonal and fractional coordinates: Relating orthogonal and fractional coordinates:

 An orthogonal coordinate may be determined from b a fractional coordinate by: y x = O u i.e. x = O u z w Σ xi = j Oij uj

y v Where O is the orthogonalization matrix. For the common convention, x u x a

c z

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Real space Coordinate Systems: Real space Relating orthogonal and fractional coordinates: Measuring distances:

 A fractional coordinate may be determined from an  We do this all the time, e.g. inter-atomic distances. orthogonal coordinate by:  In orthogonal coordinates, the squared distance u = F x between two points is given by r2 = Δx2+Δy2+Δz2 i.e. u = F x i.e: Δx =x -x Σ 2 1 ui = j Fij xj r2 = ΔxTΔx 2 T Where F is the fractionalization matrix. r = x x or: -1 Clearly F = O 2 Σ Δ 2 r = i xi  Note:  a,b,c,α,β,γ are the cell constants.  a*,b*,c*,α*,β*,γ* are the reciprocal cell constants.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Real space Coordinate Systems: Real space Measuring distances: Measuring distances:

 For the distance between two fractional  Simplified form using the metric : coordinates, convert to orthogonal first: 2 Δ 2 Δ 2 Δ 2 r =M11 u1 +M22 u2 +M33 u3 2 Δ T T Δ r = u O O u 2 T T +2M Δu Δu +2M Δu Δu +2M Δu Δu r = u O O u 12 1 2 13 1 3 23 2 3 or: (since the matrix is symmetric, we just use the r2 = Σ Σ Σ O O Δu Δu i j k ij ik j k upper triangle and double the off-diagonal terms).

 Simplify by pre-calculating the central :  (This is often a performance critical task). M = OTO Σ Mjk = i Oij Oik

 M is a symmetric matrix, called the “real-space ”.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Real space Coordinate Systems: Real space Other coordinate types: Other coordinate types:

 Grid coordinates: Electron density maps are usually  Grid coordinates: g

calculated on a grid which samples the unit cell.  Each grid point is indexed using 3 integer indices, gi, b usually starting from 0. 4  The sampling usually involves a grid in which each cell edge is divided into a set number of equal divisions, with 7 the number of divisions roughly proportional to the cell edge. 6  Symmetry and FFT requirements may constrain these a values(e.g.multipleof2,3,4,nolargeprimefactors).

c

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Real space Coordinate Systems: Real space Other coordinate types: Other coordinate types:

 Grid coordinates:  Grid coordinates: Additional complications:  Convert to grid coordinates by scaling the fractional  M. Rowicka, A. Kudlicki and Z. Otwinowski, [Acta Cryst. coordinates by the samplings, and taking nearest integer: (2002). A58, 574-579] use grids which do not intersect theorigintoimprovesymmetryhandlingintheFFT  Hexagonal close packed grids give a more efficient sampling of real space. How are they best indexed?  For orthogonal coordinates , convert to/from fractional first. As an optimization, the two steps can be combined.

 Grid coordinates repeat every ni along the i'th axis.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Real space Coordinate Systems: Real space Other coordinate types: Implementation issues:

 Map coordinates: (Cowtan)  It is very easy when programming to make  Non-integer grid coordinates. mistakes over coordinate types.  For crystallographic maps, fractional coordinates do the job just  When using strongly typed languages (e.g. C++), fine implement each coordinate type as a different class  For non-crystallographic maps, fractional coordinates are to prevent such errors. undefined.  Used for interpolation in non-crystallographic maps.  (Use inheritance for common behaviors)  Coordinate types or cell and sampling classes may then implement all the required conversions. See CCTBX or Clipper.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Reciprocal space Coordinate Systems: Reciprocal space In reciprocal space we mainly deal with reflections, In reciprocal space we mainly deal with reflections, indexed by integer h,k,l: indexed by integer h,k,l:

 h,k,l are coordinates on a non-orthogonal grid, like grid coordinates.

 h,k,l do not repeat. They are centered (+/-) about the origin h=k=l=0.

 May be referred to as Miller indices (by correspondence with the indexing of crystal cell faces).

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Reciprocal space Coordinate Systems: Reciprocal space We frequently need to determine the (reciprocal) Relating reciprocal orthogonal and fractional distance from a reflection to the origin (resolution). coordinates:

We may also need to  An reciprocal orthogonal coordinate may be determine a reciprocal determined from an HKL by: orthogonal coordinate s = O* h e.g. to make this picture.

 As in real space, O* is determined by the orthogonalization convention. A convenient choice is to use the transpose of the real space fractionalizing matrix: O* = FT  i.e. z parallel to c*, y in the b*-c* plane

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Reciprocal space Coordinate Systems: Reciprocal space Relating reciprocal orthogonal and fractional Measuring distances in reciprocal space: coordinates:  As before, to calculate squared distances (in  For display purposes, the “Cambridge Convention” inverse squared Ångstroms), we first need is more common: reciprocal orthogonal coordinates, or a reciprocal  x parallel to a* metric tensor: s2 =hTO*TO*h 2 T T  y in the a*-b* plane s = h O* O* h or:  In this case O* is calculated using the equivalent 2 Σ Σ Σ s = i j k O*ij O*ik hj hk formula to O.  Simplify by pre-calculating the central product:  Don't mix conventions between real and M* = O*TO* reciprocal space – it will only end in tears. Σ M*jk = i O*ij O*ik

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Reciprocal space Interlude Measuring distances: The Structure Factor Equation:

 Simplified form using the metric tensor:  From Scattering Theory: s2 =M* h 2 +M* k 2 +M* l 2 Σ π T 11 22 33 F(s)= j fj(s)exp(2 i s x ) +2M* hk+2M* hl+2M* kl 12 13 23  Structure Factor Equation:  Resolution in Ångstroms is 1/s,i.e.1/s2 Σ π T F(h)= j fj(s)exp(2 i h u )  2 2θ/λ2 s =4sin  Because: T T T  Some developers use the symbol s instead of s2. s x =(F h ) (O u ) = hT FOu  Clipper and CCP4 refer to s2 as inverse resolution = hT u squared: “invresolsq”.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Operators Coordinate Systems: Operators Operators transform coordinates in such a way that a Translation operators: rigid body will moved to a new position within the  Add the translation vector to the existing coordinate coordinate system. We consider three types: to get the new coordinate (in the same system).  Translation operators: x2 =x1 +Tx  Move an object without rotating it. u2 =u1 +Tu

 Rotation operators:  Translation vectors transform like coordinates,  Rotate an object about the origin of the coordinate i.e. if x1 = O u1 and x2 = O u2 then: system. Tx = O Tu  Rotation-translation (RT) operators: Tu = F Tx  Rotate and translate an object, or equivalently, rotate an  The inverse of T is -T . object about a point other than the origin.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Operators Coordinate Systems: Operators Rotation operators: Rotation operators:

 A rotation is described by a matrix R which is  We can represent the rotation in fractional coords: -1 T orthonormal (i.e. R = R ) x2 = Rx x1 x = R x 2 x 1 u2 = Ru u1

Since x1 = O u1 and x2 = O u2 , O u2 = Rx O u1 y 1 therefore: y 2 -1 R -1 R x 2 Ru = O Rx O u = O x O and: -1 R = O R O -1 Rx = ORu O x u x1  -1 ≠ T Note: Ru is not a rotation matrix. ( Ru Ru )

z1 z 2

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Operators Coordinate Systems: Operators Rotation-translation (RT) operators: Rotation-translation (RT) operators:

 A rotation-translation operator is described by a  Implementation: rotation matrix R followed by a translation T.  Use a class to hold the rotation matrix and translation

x2 = Rx x1 +Tx vector, and provide methods to transform a vector, invert, and convert the operator to other coordinate systems.  We can represent this as a single vector operator:  Historical: Fortran 77 does not support classes, so x =R(x ) 2 x 1 developers often grouped the rotationandtranslationina 3x4 or 4x4 matrix. Mathematically, vectors must be  Its inverse is given by the rotation R -1 and the x augmented to length 4 by appending a '1'. -1 translation -Rx Tx : -1 -1 -1 x1 = Rx (x2 –Tx )=Rx x2 – Rx Tx

 To convert to fractional, convert R and T as before.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Rotations Coordinate Systems: Rotations Rotations have many representations: Quaternions:

 Matrix:  4 numbers: (x,y,z,w)  use directly to manipulate vectors  x,y,z are the direction cosines of the rotation axis, scaled  by sin(κ/2) uniquely defined, 9 numbers (mij).  w gives the angle of rotation, as cos(κ/2).  Quaternions:  No ambiguity in definition.  uniquely defined, 4 numbers (x,y,z,w).  Easy to convert to Matrix, Euler, Polar  Euler angles:  good as an interchange format. See Clipper,  multiple conventions, 3 numbers (α,β,γ). rotation.cpp  Polar angles:  multiple conventions, 3 numbers (φ,ψ,κ).

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems: Rotations Coordinate Systems: Rotations Euler angles: Polar angles:

 3 numbers: (α,β,γ).  3 numbers: (φ,ψ,κ)or(ω,φ,κ)

 α is rotation about z,  (φ,ψ) define the direction of the axis, κ is the angle  β is rotation about new y, of rotation about it.  γ is rotation about new z.  Easy to understand. ψ

 24 conventions (which axis to rotate about,  Inconsistent conventions. κ stationary or moving axes), but crystallographers all  Use for program output only. φ uses ZYZr, so well standardised.

 Convenient for rotation function search limits.

 Convenient for program input.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Derivatives Coordinate Systems: Derivatives

Many calculations require that we calculate  Refinement, MR both depend on calculation of derivatives of some function with respect to some density and curvatures – these are coordinate. e.g. calculated along grid/cell directions, i.e. fractional coordinates.  Refinement:   Refinement of individual atomic coordinates and B- Rigid body rotations, and refinement restraints (e.g. bond lengths/angles), are calculated using factors: (xi , Bi ) orthogonal coordinates.  Molecular replacement:  Need to convert derivatives between fractional and  Rigid body refinement of search model against density: orthogonal. (Rx , Tx ).

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems

Coordinate Systems: Derivatives Coordinate Systems: Derivatives

 e.g. for density gradients,  Gradients transform using the transpose of the f=ρ inverse matrix (because the coordinate is in the denominator): T gu = O gx T gx = F gu Σ Σ gu,j = i Oij gx,i gx,j = i Fij gu,i  Curvatures: T Cu = O Cx O T Cx = F Cu F Σ Σ Σ Σ Cu,kl = i j Oik Ojl Cx,ij Cx,kl = i j Fik Fjl Cu,ij

Kevin Cowtan, [email protected] Sienna/Coordinate Systems Kevin Cowtan, [email protected] Sienna/Coordinate Systems Coordinate Systems Summary:

 In crystallographic calculations, we need to use a range of coordinate systems:  real and reciprocal space  orthogonal, fractional, and grid.  We also use operators in each space.  rotations, translations, and RT.  Coordinates and operators are related by orthogonalising and fractionalising matrices and their transposes in various combinations.

Kevin Cowtan, [email protected] Sienna/Coordinate Systems