GLYLIB  0.3.0b
normalize_X_vectors.c
Go to the documentation of this file.
00001 // Function written by B. Lachele Foley, 2007
00002 #include <mylib.h>
00003 #include <molecules.h>
00004 //#include "../inc/mylib.h"
00005 //#include "../inc/molecules.h"
00006 /* This function normalizes all the vectors in a molecule's atom
00007 structures, in the location indicated by n1, and places the 
00008 normalized forms in n2. The vectors are all normalized to one,
00009 e.g., they are made into unit vectors. */
00010 /************** normalize_molecule_vectors **********************/
00011 void normalize_molecule_vectors(molecule *m,int n1, int n2){
00012 int na=0,nb=0,nalloc=0;
00013 int nuse=0,nsz=0,nbins=0;
00014 // figure how big the vector array needs to be
00015 if(n1>n2){nalloc=n1+1;}
00016 else{nalloc=n2+1;} 
00017 // normalize the vectors
00018 for(na=0;na<m[0].nr;na++){ // for each residue
00019         for(nb=0;nb<m[0].r[na].na;nb++){ // for each atom
00020                 //make sure there is space...
00021                 nuse=malloc_usable_size(m[0].r[na].a[nb].v);
00022                 nsz=sizeof(vectormag_3D);
00023                 if(nsz==0){mywhine("memory issue (sizeof(vectormag_3D) given as zero) in normalize_molecule_vectors.c");}
00024                 nbins=nuse/nsz;
00025                 if(nbins<nalloc){mywhine("insufficient memory in normalize_molecule_vectors");}
00026                 m[0].r[na].a[nb].v[n2]=normalize_vec(m[0].r[na].a[nb].v[n1]);
00027                 }  // for each atom
00028         } // for each residue 
00029 return;
00030 } 
00031 /************** normalize_ensemble_vectors **********************/
00032 void normalize_ensemble_vectors(ensemble *e,int n1, int n2){
00033 int nm=0;
00034 // call for each molecule
00035 for(nm=0;nm<e[0].nm;nm++){ normalize_molecule_vectors(&e[0].m[nm],n1,n2); } 
00036 return;
00037 } 
 All Classes Files Functions Variables Typedefs Defines