aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src/cell.c
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2014-09-19 16:07:24 +0200
committerThomas White <taw@physics.org>2014-09-19 16:23:39 +0200
commit6a6cb3b4d7f15c234a79ff8421a0ae5c1a1dcb2a (patch)
tree00f6e0da9a8d086af18b0b1f34433bc115c9f206 /libcrystfel/src/cell.c
parent2c959daa7a46b99a10dd5a1998b62ccb8def97de (diff)
Introduce CrystFEL unit cell files
Diffstat (limited to 'libcrystfel/src/cell.c')
-rw-r--r--libcrystfel/src/cell.c83
1 files changed, 72 insertions, 11 deletions
diff --git a/libcrystfel/src/cell.c b/libcrystfel/src/cell.c
index 44c767f0..490a80ac 100644
--- a/libcrystfel/src/cell.c
+++ b/libcrystfel/src/cell.c
@@ -3,15 +3,15 @@
*
* A class representing a unit cell
*
- * Copyright © 2012 Deutsches Elektronen-Synchrotron DESY,
- * a research centre of the Helmholtz Association.
+ * Copyright © 2012-2014 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
* Copyright © 2012 Richard Kirian
* Copyright © 2012 Lorenzo Galli
*
* Authors:
- * 2009-2012 Thomas White <taw@physics.org>
- * 2010 Richard Kirian
- * 2012 Lorenzo Galli
+ * 2009-2012,2014 Thomas White <taw@physics.org>
+ * 2010 Richard Kirian
+ * 2012 Lorenzo Galli
*
* This file is part of CrystFEL.
*
@@ -70,6 +70,11 @@ struct _unitcell {
CellRepresentation rep;
+ int have_parameters;
+ int have_a;
+ int have_b;
+ int have_c;
+
/* Crystallographic representation */
double a; /* m */
double b; /* m */
@@ -116,9 +121,9 @@ UnitCell *cell_new()
cell->a = 1.0;
cell->b = 1.0;
cell->c = 1.0;
- cell->alpha = M_PI_2;
- cell->beta = M_PI_2;
- cell->gamma = M_PI_2;
+ cell->alpha = 0.0;
+ cell->beta = 0.0;
+ cell->gamma = 0.0;
cell->rep = CELL_REP_CRYST;
@@ -126,6 +131,10 @@ UnitCell *cell_new()
cell->lattice_type = L_TRICLINIC;
cell->centering = 'P';
cell->unique_axis = '?';
+ cell->have_parameters = 0;
+ cell->have_a = 0;
+ cell->have_b = 0;
+ cell->have_c = 0;
return cell;
}
@@ -146,6 +155,20 @@ void cell_free(UnitCell *cell)
}
+/**
+ * cell_has_parameters:
+ * @cell: A %UnitCell
+ *
+ * Returns: True if @cell has its parameters specified.
+ *
+ */
+int cell_has_parameters(UnitCell *cell)
+{
+ if ( cell == NULL ) return 0;
+ return cell->have_parameters;
+}
+
+
void cell_set_parameters(UnitCell *cell, double a, double b, double c,
double alpha, double beta, double gamma)
{
@@ -159,6 +182,7 @@ void cell_set_parameters(UnitCell *cell, double a, double b, double c,
cell->gamma = gamma;
cell->rep = CELL_REP_CRYST;
+ cell->have_parameters = 1;
}
@@ -174,6 +198,7 @@ void cell_set_cartesian(UnitCell *cell,
cell->cx = cx; cell->cy = cy; cell->cz = cz;
cell->rep = CELL_REP_CART;
+ cell->have_parameters = 1;
}
@@ -182,6 +207,10 @@ void cell_set_cartesian_a(UnitCell *cell, double ax, double ay, double az)
if ( cell == NULL ) return;
cell->ax = ax; cell->ay = ay; cell->az = az;
cell->rep = CELL_REP_CART;
+ cell->have_a = 1;
+ if ( cell->have_a && cell->have_b && cell->have_c ) {
+ cell->have_parameters = 1;
+ }
}
@@ -190,6 +219,10 @@ void cell_set_cartesian_b(UnitCell *cell, double bx, double by, double bz)
if ( cell == NULL ) return;
cell->bx = bx; cell->by = by; cell->bz = bz;
cell->rep = CELL_REP_CART;
+ cell->have_b = 1;
+ if ( cell->have_a && cell->have_b && cell->have_c ) {
+ cell->have_parameters = 1;
+ }
}
@@ -198,6 +231,10 @@ void cell_set_cartesian_c(UnitCell *cell, double cx, double cy, double cz)
if ( cell == NULL ) return;
cell->cx = cx; cell->cy = cy; cell->cz = cz;
cell->rep = CELL_REP_CART;
+ cell->have_c = 1;
+ if ( cell->have_a && cell->have_b && cell->have_c ) {
+ cell->have_parameters = 1;
+ }
}
@@ -228,6 +265,7 @@ UnitCell *cell_new_from_reciprocal_axes(struct rvec as, struct rvec bs,
cell->cxs = cs.u; cell->cys = cs.v; cell->czs = cs.w;
cell->rep = CELL_REP_RECIP;
+ cell->have_parameters = 1;
return cell;
}
@@ -245,6 +283,7 @@ UnitCell *cell_new_from_direct_axes(struct rvec a, struct rvec b, struct rvec c)
cell->cx = c.u; cell->cy = c.v; cell->cz = c.w;
cell->rep = CELL_REP_CART;
+ cell->have_parameters = 1;
return cell;
}
@@ -280,6 +319,7 @@ void cell_set_reciprocal(UnitCell *cell,
cell->cxs = csx; cell->cys = csy; cell->czs = csz;
cell->rep = CELL_REP_RECIP;
+ cell->have_parameters = 1;
}
@@ -317,6 +357,11 @@ static int cell_crystallographic_to_cartesian(UnitCell *cell,
{
double tmp, V, cosalphastar, cstar;
+ if ( !cell->have_parameters ) {
+ ERROR("Unit cell has unspecified parameters.\n");
+ return 1;
+ }
+
/* Firstly: Get a in terms of x, y and z
* +a (cryst) is defined to lie along +x (cart) */
*ax = cell->a;
@@ -434,6 +479,11 @@ int cell_get_parameters(UnitCell *cell, double *a, double *b, double *c,
if ( cell == NULL ) return 1;
+ if ( !cell->have_parameters ) {
+ ERROR("Unit cell has unspecified parameters.\n");
+ return 1;
+ }
+
switch ( cell->rep ) {
case CELL_REP_CRYST:
@@ -490,6 +540,11 @@ int cell_get_cartesian(UnitCell *cell,
{
if ( cell == NULL ) return 1;
+ if ( !cell->have_parameters ) {
+ ERROR("Unit cell has unspecified parameters.\n");
+ return 1;
+ }
+
switch ( cell->rep ) {
case CELL_REP_CRYST:
@@ -526,8 +581,14 @@ int cell_get_reciprocal(UnitCell *cell,
{
int r;
double ax, ay, az, bx, by, bz, cx, cy, cz;
+
if ( cell == NULL ) return 1;
+ if ( !cell->have_parameters ) {
+ ERROR("Unit cell has unspecified parameters.\n");
+ return 1;
+ }
+
switch ( cell->rep ) {
case CELL_REP_CRYST:
@@ -697,9 +758,9 @@ UnitCell *cell_transform(UnitCell *cell, UnitCellTransformation *t)
out = cell_new_from_cell(cell);
if ( out == NULL ) return NULL;
- cell_get_cartesian(out, &ax, &ay, &az,
- &bx, &by, &bz,
- &cx, &cy, &cz);
+ if ( cell_get_cartesian(out, &ax, &ay, &az,
+ &bx, &by, &bz,
+ &cx, &cy, &cz) ) return NULL;
m = gsl_matrix_alloc(3,3);
a = gsl_matrix_calloc(3,3);