diff options
author | Thomas White <taw@physics.org> | 2009-11-17 17:04:00 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2009-11-17 17:04:00 +0100 |
commit | 79d63b556b771d4fb4dc4073c10891f26739d565 (patch) | |
tree | 90dd74656fed448feb11b51319bb6d21a03f9d6f | |
parent | 9c95cc556f924cbbba4e453c5582f24d3ac31955 (diff) |
Move load_molecule to sfac
-rw-r--r-- | src/diffraction.c | 108 | ||||
-rw-r--r-- | src/image.h | 20 | ||||
-rw-r--r-- | src/sfac.c | 108 | ||||
-rw-r--r-- | src/sfac.h | 22 |
4 files changed, 130 insertions, 128 deletions
diff --git a/src/diffraction.c b/src/diffraction.c index de43690d..32601046 100644 --- a/src/diffraction.c +++ b/src/diffraction.c @@ -101,114 +101,6 @@ static double complex molecule_factor(struct molecule *mol, struct threevec q, } -/* Load PDB file into a memory format suitable for efficient(ish) structure - * factor calculation */ -static struct molecule *load_molecule() -{ - struct molecule *mol; - FILE *fh; - char line[1024]; - char *rval; - int i; - - mol = malloc(sizeof(struct molecule)); - if ( mol == NULL ) return NULL; - mol->n_species = 0; - - fh = fopen("molecule.pdb", "r"); - if ( fh == NULL ) { - fprintf(stderr, "Couldn't open file\n"); - return NULL; - } - - do { - - char el[4]; - int j, r; - int done = 0; - float x, y, z, occ, B; - char *coords; - - rval = fgets(line, 1023, fh); - - /* Only interested in atoms */ - if ( strncmp(line, "HETATM", 6) != 0 ) continue; - - /* The following crimes against programming style - * were brought to you by Wizbit Enterprises, Inc. */ - if ( line[76] == ' ' ) { - el[0] = line[77]; - el[1] = '\0'; - } else { - el[0] = line[76]; - el[1] = line[77]; - el[2] = '\0'; - } - - coords = line + 29; - r = sscanf(coords, "%f %f %f %f %f", &x, &y, &z, &occ, &B); - if ( r != 5 ) { - fprintf(stderr, "WTF?\n"); - abort(); - } - - for ( j=0; j<mol->n_species; j++ ) { - - struct mol_species *spec; - int n; - - spec = mol->species[j]; - - if ( strcmp(spec->species, el) != 0 ) continue; - - n = mol->species[j]->n_atoms; - - spec->x[n] = x; - spec->y[n] = y; - spec->z[n] = z; - spec->occ[n] = occ; - spec->B[n] = B; - mol->species[j]->n_atoms++; - - done = 1; - - } - - if ( !done ) { - - /* Need to create record for this species */ - struct mol_species *spec; - - spec = malloc(sizeof(struct mol_species)); - - memcpy(spec->species, el, 4); - spec->x[0] = x; - spec->y[0] = y; - spec->z[0] = z; - spec->occ[0] = occ; - spec->B[0] = B; - spec->n_atoms = 1; - - mol->species[mol->n_species] = spec; - mol->n_species++; - - } - - - } while ( rval != NULL ); - - fclose(fh); - - printf("There are %i species\n", mol->n_species); - for ( i=0; i<mol->n_species; i++ ) { - printf("'%s': %i\n", mol->species[i]->species, - mol->species[i]->n_atoms); - } - - return mol; -} - - void get_diffraction(struct image *image, UnitCell *cell) { int x, y; diff --git a/src/image.h b/src/image.h index ec5a20d5..40e3e35e 100644 --- a/src/image.h +++ b/src/image.h @@ -57,26 +57,6 @@ struct threevec }; -struct mol_species -{ - char species[4]; /* Species name */ - int n_atoms; /* Number of atoms of this species */ - - float x[32*1024]; - float y[32*1024]; - float z[32*1024]; - float occ[32*1024]; - float B[32*1024]; -}; - - -struct molecule -{ - int n_species; - struct mol_species *species[32]; -}; - - /* Structure describing an image */ struct image { @@ -162,3 +162,111 @@ double complex get_sfac(const char *n, double s, double en) return fq - fq0 + f1f2; } + + +/* Load PDB file into a memory format suitable for efficient(ish) structure + * factor calculation */ +struct molecule *load_molecule() +{ + struct molecule *mol; + FILE *fh; + char line[1024]; + char *rval; + int i; + + mol = malloc(sizeof(struct molecule)); + if ( mol == NULL ) return NULL; + mol->n_species = 0; + + fh = fopen("molecule.pdb", "r"); + if ( fh == NULL ) { + fprintf(stderr, "Couldn't open file\n"); + return NULL; + } + + do { + + char el[4]; + int j, r; + int done = 0; + float x, y, z, occ, B; + char *coords; + + rval = fgets(line, 1023, fh); + + /* Only interested in atoms */ + if ( strncmp(line, "HETATM", 6) != 0 ) continue; + + /* The following crimes against programming style + * were brought to you by Wizbit Enterprises, Inc. */ + if ( line[76] == ' ' ) { + el[0] = line[77]; + el[1] = '\0'; + } else { + el[0] = line[76]; + el[1] = line[77]; + el[2] = '\0'; + } + + coords = line + 29; + r = sscanf(coords, "%f %f %f %f %f", &x, &y, &z, &occ, &B); + if ( r != 5 ) { + fprintf(stderr, "WTF?\n"); + abort(); + } + + for ( j=0; j<mol->n_species; j++ ) { + + struct mol_species *spec; + int n; + + spec = mol->species[j]; + + if ( strcmp(spec->species, el) != 0 ) continue; + + n = mol->species[j]->n_atoms; + + spec->x[n] = x; + spec->y[n] = y; + spec->z[n] = z; + spec->occ[n] = occ; + spec->B[n] = B; + mol->species[j]->n_atoms++; + + done = 1; + + } + + if ( !done ) { + + /* Need to create record for this species */ + struct mol_species *spec; + + spec = malloc(sizeof(struct mol_species)); + + memcpy(spec->species, el, 4); + spec->x[0] = x; + spec->y[0] = y; + spec->z[0] = z; + spec->occ[0] = occ; + spec->B[0] = B; + spec->n_atoms = 1; + + mol->species[mol->n_species] = spec; + mol->n_species++; + + } + + + } while ( rval != NULL ); + + fclose(fh); + + printf("There are %i species\n", mol->n_species); + for ( i=0; i<mol->n_species; i++ ) { + printf("'%s': %i\n", mol->species[i]->species, + mol->species[i]->n_atoms); + } + + return mol; +} @@ -18,6 +18,28 @@ #include <complex.h> + +struct mol_species +{ + char species[4]; /* Species name */ + int n_atoms; /* Number of atoms of this species */ + + float x[32*1024]; + float y[32*1024]; + float z[32*1024]; + float occ[32*1024]; + float B[32*1024]; +}; + + +struct molecule +{ + int n_species; + struct mol_species *species[32]; +}; + + extern double complex get_sfac(const char *n, double s, double en); +extern struct molecule *load_molecule(void); #endif /* SFAC_H */ |