GLYLIB  0.3.0b
set_COM.c
Go to the documentation of this file.
00001 /* \file set_COM.c 
00002  * \addtogroup GEOMETRY
00003  * \brief   Sets COM's and m's (masses) in the standard structures.
00004  *
00005  * Replaces assign_COM functions.
00006  * If ATYPE==NULL or ==0x0, masses will be taken from entries
00007  * in the atom strucutures.
00008  *
00009  * These functions behave differently from the get_COM functions in
00010  * that they rely, recursively, on nested structures.  In other words,
00011  * set_molecule_COM, will set each residue's COM, but then will calculate
00012  * its own COM based on the residues' COM's rather than directly on
00013  * information in the atoms.  The two approaches, in most circumstances,
00014  * will give the same result.
00015  *
00016  * Begun on 20100310 by BLFoley.
00017  */
00018 
00019 #include <mylib.h>
00020 #include <molecules.h>
00021 /****************** set_residue_COM() *********************/
00022 /* Finds the center of mass of the residue and places it in the
00023  * COM location.  COM calcualtion based on coords in xs.
00024  * This function is trivial, but the others aren't so much.
00025  */ 
00026 void set_residue_COM(residue *r,atype *ATYPE, int xs){
00027 r[0].COM=get_residue_COM(r,ATYPE,xs);
00028 return;
00029 }
00030 
00031 /****************** set_molecule_COM() *********************/
00032 /* Finds the center of mass of the molecule and places it in the
00033  * appropriate location.  Determines it recurively via the residues
00034  */
00035 void set_molecule_COM(molecule *m,atype *ATYPE, int xs){
00036 int tr=0;
00037 double tmm=0;
00038 m[0].COM.i=0;
00039 m[0].COM.j=0;
00040 m[0].COM.k=0; 
00041 // calculate the center of mass
00042 for(tr=0;tr<m[0].nr;tr++){ // COM = sum(m_i * r_i) / sum(m_i)
00043         set_residue_COM(&m[0].r[tr],ATYPE,xs);
00044         m[0].COM.i+=m[0].r[tr].COM.i*m[0].r[tr].m;
00045         m[0].COM.j+=m[0].r[tr].COM.j*m[0].r[tr].m;
00046         m[0].COM.k+=m[0].r[tr].COM.k*m[0].r[tr].m;
00047         tmm+=m[0].r[tr].m;
00048         }
00049 //printf("center of mass is at: %f %f %f \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00050 m[0].COM.i/=tmm;
00051 m[0].COM.j/=tmm;
00052 m[0].COM.k/=tmm; 
00053 m[0].m=tmm;
00054 //printf("center of mass is at: %20.12e %20.12e %20.12e \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00055 return;
00056 }
00057 
00058 /****************** set_assembly_molecule_COM() *********************/
00059 /* Finds the center of mass of the assembly and places it in the
00060  * appropriate location.  This function assumes that the assembly has
00061  * a traditional structure, with molecules, residues and atoms all in
00062  * nested structures.  If only the atom or residue pointers contain
00063  * data, this function won't work.
00064  */
00065 void set_assembly_molecule_COM(assembly *a,atype *ATYPE,int xs){
00066 int tm=0;
00067 double tmm=0; 
00068 
00069 a[0].COM.i=0;
00070 a[0].COM.j=0;
00071 a[0].COM.k=0; 
00072 // calculate the center of mass
00073 for(tm=0;tm<a[0].nm;tm++){ // COM = sum(m_i * r_i) / sum(m_i)
00074         set_molecule_COM(&a[0].m[tm][0],ATYPE,xs);
00075         a[0].COM.i+=a[0].m[tm][0].COM.i*a[0].m[tm][0].m;
00076         a[0].COM.j+=a[0].m[tm][0].COM.j*a[0].m[tm][0].m;
00077         a[0].COM.k+=a[0].m[tm][0].COM.k*a[0].m[tm][0].m;
00078         tmm+=a[0].m[tm][0].m;
00079         }
00080 //printf("center of mass is at: %f %f %f \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00081 a[0].COM.i/=tmm;
00082 a[0].COM.j/=tmm;
00083 a[0].COM.k/=tmm; 
00084 a[0].mass=tmm;
00085 //printf("center of mass is at: %20.12e %20.12e %20.12e \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00086 return;
00087 }
00088 
00089 /****************** set_ensemble_COM() *********************/
00090 /* Finds the center of mass of the ensemble and places it in the
00091  * appropriate location.  
00092  * NOTE!!  Assemblies within ensembles are assumed to be redundant.
00093  *      That is, the molecules in the ensemble are also represented
00094  *      within the assemblies (copying the molecule pointers keeps 
00095  *      the data from taking extra space).  So, when calculating the
00096  *      center of mass for the ensemble, this function ONLY considers
00097  *      molecules and not assemblies.
00098  */
00099 void set_ensemble_COM(ensemble *e,atype *ATYPE, int xs){
00100 int tm=0;
00101 double tmm=0; 
00102 e[0].COM.i=0;
00103 e[0].COM.j=0;
00104 e[0].COM.k=0; 
00105 // calculate the center of mass
00106 for(tm=0;tm<e[0].nm;tm++){ // COM = sum(m_i * r_i) / sum(m_i)
00107         set_molecule_COM(&e[0].m[tm],ATYPE,xs);
00108         e[0].COM.i+=e[0].m[tm].COM.i*e[0].m[tm].m;
00109         e[0].COM.j+=e[0].m[tm].COM.j*e[0].m[tm].m;
00110         e[0].COM.k+=e[0].m[tm].COM.k*e[0].m[tm].m;
00111         tmm+=e[0].m[tm].m;
00112         }
00113 //printf("center of mass is at: %f %f %f \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00114 e[0].COM.i/=tmm;
00115 e[0].COM.j/=tmm;
00116 e[0].COM.k/=tmm; 
00117 e[0].mass=tmm;
00118 //printf("center of mass is at: %20.12e %20.12e %20.12e \n",m[0].COM.i,m[0].COM.j,m[0].COM.k);
00119 return;
00120 } 
00121 
 All Classes Files Functions Variables Typedefs Defines