From ac04881c50c140dbf7207363ed7e7400e186334b Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 5 Mar 2010 10:55:57 +0100 Subject: Read cell from PDB --- src/sfac.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'src/sfac.c') diff --git a/src/sfac.c b/src/sfac.c index d758fa08..0e8b9382 100644 --- a/src/sfac.c +++ b/src/sfac.c @@ -324,14 +324,6 @@ struct molecule *load_molecule() mol->n_species = 0; mol->reflections = NULL; - /* FIXME: Read cell from file */ - mol->cell = cell_new_from_parameters(28.10e-9, - 28.10e-9, - 16.52e-9, - deg2rad(90.0), - deg2rad(90.0), - deg2rad(120.0)); - fh = fopen("molecule.pdb", "r"); if ( fh == NULL ) { ERROR("Couldn't open PDB file\n"); @@ -349,6 +341,21 @@ struct molecule *load_molecule() rval = fgets(line, 1023, fh); + if ( strncmp(line, "CRYST1", 6) == 0 ) { + + float a, b, c, al, be, ga; + + r = sscanf(line+7, "%f %f %f %f %f %f", + &a, &b, &c, &al, &be, &ga); + + mol->cell = cell_new_from_parameters(a*1e-10, + b*1e-10, c*1e-10, + deg2rad(al), + deg2rad(be), + deg2rad(ga)); + + } + /* Only interested in atoms */ if ( strncmp(line, "HETATM", 6) != 0 ) continue; @@ -427,6 +434,11 @@ struct molecule *load_molecule() // mol->species[i]->n_atoms); } + if ( mol->cell == NULL ) { + ERROR("No unit cell found in PDB file\n"); + return NULL; + } + return mol; } -- cgit v1.2.3