aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2009-11-23 15:04:27 +0100
committerThomas White <taw@physics.org>2009-11-23 18:43:22 +0100
commite2e6f1ae3039184d2012a02901f7d1138c4ac231 (patch)
tree0694ac0f8a0d39b9086a84a54f19b981338e4d4b /src
parentc4296981d5f16c58537a70ea66d9fadf49aed203 (diff)
Centre the molecule before calculating structure factors
Also fixes an incorrect comment
Diffstat (limited to 'src')
-rw-r--r--src/sfac.c60
-rw-r--r--src/sfac.h4
2 files changed, 63 insertions, 1 deletions
diff --git a/src/sfac.c b/src/sfac.c
index 3fafea92..00d6c69d 100644
--- a/src/sfac.c
+++ b/src/sfac.c
@@ -203,6 +203,62 @@ double complex get_sfac(const char *n, double s, double en)
}
+static void centre_molecule(struct molecule *mol)
+{
+ int i;
+ double tx = 0.0;
+ double ty = 0.0;
+ double tz = 0.0;
+ double total = 0.0;
+
+ /* Atoms are grouped by species for faster calculation */
+ for ( i=0; i<mol->n_species; i++ ) {
+
+ struct mol_species *spec;
+ int j;
+
+ spec = mol->species[i];
+
+ for ( j=0; j<spec->n_atoms; j++ ) {
+
+ double sfac = get_waas_kirf(spec->species, 0.0);
+
+ tx += spec->x[j] * sfac;
+ ty += spec->y[j] * sfac;
+ tz += spec->z[j] * sfac;
+ total += sfac;
+
+ }
+
+ }
+
+ mol->xc = tx / total;
+ mol->yc = ty / total;
+ mol->zc = tz / total;
+
+ for ( i=0; i<mol->n_species; i++ ) {
+
+ struct mol_species *spec;
+ int j;
+
+ spec = mol->species[i];
+
+ for ( j=0; j<spec->n_atoms; j++ ) {
+
+ spec->x[j] -= mol->xc;
+ spec->y[j] -= mol->yc;
+ spec->z[j] -= mol->zc;
+
+ }
+
+ }
+
+ printf("Molecule was shifted by %f,%f,%f nm\n",
+ mol->xc*1e9, mol->yc*1e9, mol->zc*1e9);
+
+}
+
+
/* Load PDB file into a memory format suitable for efficient(ish) structure
* factor calculation */
struct molecule *load_molecule()
@@ -268,7 +324,7 @@ struct molecule *load_molecule()
n = mol->species[j]->n_atoms;
- spec->x[n] = x*1.0e-10; /* Convert to nm */
+ spec->x[n] = x*1.0e-10; /* Convert to m */
spec->y[n] = y*1.0e-10;
spec->z[n] = z*1.0e-10;
spec->occ[n] = occ;
@@ -304,6 +360,8 @@ struct molecule *load_molecule()
fclose(fh);
+ centre_molecule(mol);
+
printf("There are %i species\n", mol->n_species);
for ( i=0; i<mol->n_species; i++ ) {
printf("%3s : %6i\n", mol->species[i]->species,
diff --git a/src/sfac.h b/src/sfac.h
index 725ebff9..f88729f4 100644
--- a/src/sfac.h
+++ b/src/sfac.h
@@ -36,6 +36,10 @@ struct molecule
{
int n_species;
struct mol_species *species[32];
+
+ double xc;
+ double yc;
+ double zc;
};