aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2010-12-09 13:44:34 -0700
committerThomas White <taw@physics.org>2012-02-22 15:27:09 +0100
commit5948c1cdb1166475f6be900b00ea663dca77d8c3 (patch)
treefbd68b3b5f06ebef20bcc373d98877cd1200d7b8 /src
parentec6823feaef08a4d74cf57ac7fa163068430be63 (diff)
Read fixed-width fields properly in load_cell_from_pdb()
Diffstat (limited to 'src')
-rw-r--r--src/cell.c24
-rw-r--r--src/sfac.c16
2 files changed, 20 insertions, 20 deletions
diff --git a/src/cell.c b/src/cell.c
index c1dce498..826b003e 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -867,14 +867,28 @@ UnitCell *load_cell_from_pdb(const char *filename)
if ( strncmp(line, "CRYST1", 6) == 0 ) {
float a, b, c, al, be, ga;
- int r;
+ char as[10], bs[10], cs[10];
+ char als[8], bes[8], gas[8];
char *sym;
+ int r;
+
+ memcpy(as, line+6, 9); as[9] = '\0';
+ memcpy(bs, line+15, 9); bs[9] = '\0';
+ memcpy(cs, line+24, 9); cs[9] = '\0';
+ memcpy(als, line+33, 7); als[7] = '\0';
+ memcpy(bes, line+40, 7); bes[7] = '\0';
+ memcpy(gas, line+47, 7); gas[7] = '\0';
+
+ r = sscanf(as, "%f", &a);
+ r += sscanf(bs, "%f", &b);
+ r += sscanf(cs, "%f", &c);
+ r += sscanf(als, "%f", &al);
+ r += sscanf(bes, "%f", &be);
+ r += sscanf(gas, "%f", &ga);
- r = sscanf(line+7, "%f %f %f %f %f %f\n",
- &a, &b, &c, &al, &be, &ga);
if ( r != 6 ) {
- ERROR("Couldn't understand CRYST1 line\n");
- return NULL;
+ STATUS("Couldn't understand CRYST1 line.\n");
+ continue;
}
cell = cell_new_from_parameters(a*1e-10,
diff --git a/src/sfac.c b/src/sfac.c
index c56097a4..436544c8 100644
--- a/src/sfac.c
+++ b/src/sfac.c
@@ -347,21 +347,6 @@ struct molecule *load_molecule(const char *filename)
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)
&& (strncmp(line, "ATOM ", 6) != 0) ) continue;
@@ -456,6 +441,7 @@ struct molecule *load_molecule(const char *filename)
mol->species[i]->n_atoms);
}
+ mol->cell = load_cell_from_pdb(filename);
if ( mol->cell == NULL ) {
ERROR("No unit cell found in PDB file\n");
return NULL;