GLYLIB
0.3.0b
|
00001 // Function written by B. Lachele Foley, 2007 00002 //#include "../inc/mylib.h" 00003 //#include "../inc/molecules.h" 00004 00005 /****************** translate_molecule() *********************/ 00006 /* Translates the molecule so that the all coordinates are displaced 00007 * by the vector vec. The source coordinates should be in cs and 00008 * the target coordinates go in ct (in either case, -1 means the 00009 * main coordinate location). 00010 */ 00011 /* 00012 void translate_molecule(molecule *m,atype *ATYPE,int tw){ 00013 int ta=0,tuse=0,tsz=0,tbins=0; 00014 double tmm=0; 00015 00016 // calculate the molecular weight of residue 0 (the molecule, here) 00017 for(ta=0;ta<m[0].r[0].na;ta++){ 00018 tmm+=ATYPE[m[0].r[0].a[ta].t].m; 00019 } 00020 //printf("the molecular weight is %f\n",tmm); 00021 if(tmm==0){mywhine("molecular weight of molecule %s is zero.\n(Have types/masses been assigned?");} 00022 // glucose $molwt=174.078; 00023 00024 m[0].COM.i=0; 00025 m[0].COM.j=0; 00026 m[0].COM.k=0; 00027 //printf("center of mass is at: %f %f %f \n",m[0].COM.i,m[0].COM.j,m[0].COM.k); 00028 // calculate the center of mass 00029 for(ta=0;ta<m[0].r[0].na;ta++){ // COM = sum(m_i * r_i) / sum(m_i) 00030 m[0].COM.i+=m[0].r[0].a[ta].x.i*ATYPE[m[0].r[0].a[ta].t].m; 00031 m[0].COM.j+=m[0].r[0].a[ta].x.j*ATYPE[m[0].r[0].a[ta].t].m; 00032 m[0].COM.k+=m[0].r[0].a[ta].x.k*ATYPE[m[0].r[0].a[ta].t].m; 00033 } 00034 //printf("center of mass is at: %f %f %f \n",m[0].COM.i,m[0].COM.j,m[0].COM.k); 00035 m[0].COM.i/=tmm; 00036 m[0].COM.j/=tmm; 00037 m[0].COM.k/=tmm; 00038 //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); 00039 00040 // move center of mass to specified location 00041 if(tw==-1){ 00042 for(ta=0;ta<m[0].r[0].na;ta++){ // xyz(new) = xyz(old) - COM 00043 m[0].r[0].a[ta].x.i-=m[0].COM.i; 00044 m[0].r[0].a[ta].x.j-=m[0].COM.j; 00045 m[0].r[0].a[ta].x.k-=m[0].COM.k; 00046 } 00047 } 00048 else{ 00049 for(ta=0;ta<m[0].r[0].na;ta++){ // xyz(new) = xyz(old) - COM 00050 tuse=malloc_usable_size(m[0].r[0].a[ta].xa); 00051 tsz=sizeof(coord_3D); 00052 if(tsz==0){mywhine("memory issue: sizeof(coord_3D) given as zero in translate_to_COM.c");} 00053 tbins=tuse/tsz; 00054 //print_coord_3D(&m[0].r[0].a[ta].x); 00055 if(tbins<(tw+1)){mywhine("insufficient memory allocated before translate_to_COM");} 00056 m[0].r[0].a[ta].xa[tw].i=m[0].r[0].a[ta].x.i-m[0].COM.i; 00057 m[0].r[0].a[ta].xa[tw].j=m[0].r[0].a[ta].x.j-m[0].COM.j; 00058 m[0].r[0].a[ta].xa[tw].k=m[0].r[0].a[ta].x.k-m[0].COM.k; 00059 } 00060 } 00061 return; 00062 } 00063 */ 00064 00065 // Function written by B. Lachele Foley, 2007 00066 //#include "../inc/mylib.h" 00067 //#include "../inc/molecules.h" 00068 /****************** translate_zero_to_coord_M() *********************/ 00069 /* Translates the specifiec coords (location xs) so that the coordinate 00070 indicated by c is at the origin. Places the translated coords in xt. */ 00071 /* 00072 void translate_zero_to_coord_M(molecule *m,int xs,int xt,coord_3D c){ 00073 int ta=0,tb,tuse=0,tsz=0,tbins=0; 00074 00075 // move center of mass to specified location 00076 if((xs==-1)&&(xt==-1)){ 00077 for(ta=0;ta<m[0].nr;ta++){ 00078 for(tb=0;tb<m[0].r[ta].na;tb++){ 00079 m[0].r[ta].a[tb].x=subtract_coord(m[0].r[ta].a[tb].x,c); 00080 } 00081 } 00082 } 00083 if((xs!=-1)&&(xt==-1)){ 00084 for(ta=0;ta<m[0].nr;ta++){ 00085 for(tb=0;tb<m[0].r[ta].na;tb++){ 00086 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00087 tsz=sizeof(coord_3D); 00088 tbins=tuse/tsz; 00089 if(tbins<(xs+1)){mywhine("memory issue: source coords not allocated in translate_zero_to_coord");} 00090 m[0].r[ta].a[tb].x=subtract_coord(m[0].r[ta].a[tb].xa[xs],c); 00091 } 00092 } 00093 } 00094 if((xs==-1)&&(xt!=-1)){ 00095 for(ta=0;ta<m[0].nr;ta++){ 00096 for(tb=0;tb<m[0].r[ta].na;tb++){ 00097 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00098 tsz=sizeof(coord_3D); 00099 tbins=tuse/tsz; 00100 if(tbins<(xt+1)){mywhine("memory issue: translated coords not allocated in translate_zero_to_coord");} 00101 m[0].r[ta].a[tb].xa[xt]=subtract_coord(m[0].r[ta].a[tb].x,c); 00102 } 00103 } 00104 } 00105 if((xs!=-1)&&(xt!=-1)){ 00106 for(ta=0;ta<m[0].nr;ta++){ 00107 for(tb=0;tb<m[0].r[ta].na;tb++){ 00108 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00109 tsz=sizeof(coord_3D); 00110 tbins=tuse/tsz; 00111 if(tbins<(xs+1)){mywhine("memory issue: source coords not allocated in translate_zero_to_coord");} 00112 if(tbins<(xt+1)){mywhine("memory issue: translated coords not allocated in translate_zero_to_coord");} 00113 m[0].r[ta].a[tb].xa[xt]=subtract_coord(m[0].r[ta].a[tb].xa[xs],c); 00114 } 00115 } 00116 } 00117 return; 00118 } 00119 */