/* * basis.c * * Handle basis structures * * (c) 2007 Thomas White * * dtr - Diffraction Tomography Reconstruction * */ #ifdef HAVE_CONFIG_H #include #endif #include #include "reflections.h" #include "basis.h" static double basis_efom(ReflectionList *reflectionlist, Basis *basis) { int n_indexed, n_counted; Reflection *cur; cur = reflectionlist->reflections; n_indexed = 0; n_counted = 0; while ( cur ) { if ( cur->type == REFLECTION_NORMAL ) { /* Can this basis "approximately" account for this reflection? */ double det; double a11, a12, a13, a21, a22, a23, a31, a32, a33; double h, k, l; /* Set up the coordinate transform from hkl to xyz */ a11 = basis->a.x; a12 = basis->a.y; a13 = basis->a.z; a21 = basis->b.x; a22 = basis->b.y; a23 = basis->b.z; a31 = basis->c.x; a32 = basis->c.y; a33 = basis->c.z; /* Invert the matrix to get hkl from xyz */ det = a11*(a22*a33 - a23*a32) - a12*(a21*a33 - a23*a31) + a13*(a21*a32 - a22*a31); h = ((a22*a33-a23*a32)*cur->x + (a23*a31-a21*a33)*cur->y + (a21*a32-a22*a31)*cur->z) / det; k = ((a13*a32-a12*a33)*cur->x + (a11*a33-a13*a31)*cur->y + (a12*a31-a11*a32)*cur->z) / det; l = ((a12*a23-a13*a22)*cur->x + (a13*a21-a11*a23)*cur->y + (a11*a22-a12*a21)*cur->z) / det; /* Calculate the deviations in terms of |a|, |b| and |c| */ h = fabs(h); k = fabs(k); l = fabs(l); h -= floor(h); k -= floor(k); l -= floor(l); if ( h == 1.0 ) h = 0.0; if ( k == 1.0 ) k = 0.0; if ( l == 1.0 ) l = 0.0; /* Define "approximately" here. Circle in basis space becomes an ellipsoid in reciprocal space */ if ( h*h + k*k + l*l <= 0.1*0.1*0.1 ) n_indexed++; n_counted++; } cur = cur->next; } return (double)n_indexed / n_counted; }