GLYLIB
0.3.0b
|
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 /****************** translate_by_XYZ() *********************/ 00007 /* Adds the vector vec to all coordinates in the specified 00008 * structure. Uses xs (source) as the coordinates to move and 00009 * xd (destination) as the location for the new coordinates. 00010 * As usual xs or xd = -1 means main set. 00011 */ 00012 // 00013 //The following are useful for troubleshooting memory issues 00014 //tuse=malloc_usable_size(m[0].r[0].a[ta].xa); 00015 //tsz=sizeof(coord_3D); 00016 //if(tsz==0){mywhine("memory issue: sizeof(coord_3D) given as zero in translate_to_COM.c");} 00017 //tbins=tuse/tsz; 00018 //print_coord_3D(&m[0].r[0].a[ta].x); 00019 //if(tbins<(tw+1)){mywhine("insufficient memory allocated before translate_to_COM");} 00020 00021 void translate_residue_by_XYZ(residue *r,int xs,int xd,coord_3D vec){ 00022 int ta=0; 00023 if(r[0].na<=0){mywhine("Residue contains no atoms in translate_residue_by_XYZ.");} 00024 if((xs<-1)||(xd<-1)){mywhine("Invalid source or destination coordinates to translate_residue_by_XYZ.");} 00025 if((xs==-1)&&(xd==-1)){ 00026 for(ta=0;ta<r[0].na;ta++){ 00027 r[0].a[ta].x.i+=vec.i; 00028 r[0].a[ta].x.j+=vec.j; 00029 r[0].a[ta].x.k+=vec.k; 00030 } 00031 return; 00032 } 00033 if((xs>r[0].a[0].nalt-1)||(xd>=r[0].a[0].nalt-1)){ 00034 mywhine("Unallocated source or destination coordinates in translate_residue_by_XYZ.");} 00035 if(xs==-1){ 00036 for(ta=0;ta<r[0].na;ta++){ 00037 r[0].a[ta].xa[xd].i=r[0].a[ta].x.i+vec.i; 00038 r[0].a[ta].xa[xd].j=r[0].a[ta].x.j+vec.j; 00039 r[0].a[ta].xa[xd].k=r[0].a[ta].x.k+vec.k; 00040 } 00041 return; 00042 } 00043 if(xd==-1){ 00044 for(ta=0;ta<r[0].na;ta++){ 00045 r[0].a[ta].x.i=r[0].a[ta].xa[xs].i+vec.i; 00046 r[0].a[ta].x.j=r[0].a[ta].xa[xs].j+vec.j; 00047 r[0].a[ta].x.k=r[0].a[ta].xa[xs].k+vec.k; 00048 } 00049 return; 00050 } 00051 // still here? 00052 if((xs<0)||(xd<0)){mywhine("Something is very wrong in translate_residue_by_XYZ.");} 00053 for(ta=0;ta<r[0].na;ta++){ 00054 r[0].a[ta].xa[xd].i=r[0].a[ta].xa[xs].i+vec.i; 00055 r[0].a[ta].xa[xd].j=r[0].a[ta].xa[xs].j+vec.j; 00056 r[0].a[ta].xa[xd].k=r[0].a[ta].xa[xs].k+vec.k; 00057 } 00058 00059 return; 00060 } 00061 void translate_molecule_by_XYZ(molecule *m,int xs,int xd,coord_3D vec){ 00062 int ta=0,tr=0; 00063 if(m[0].nr<=0){mywhine("Molecule contains no residues in translate_molecule_by_XYZ.");} 00064 if(m[0].r[0].na<=0){mywhine("Molecule's residue zero contains no atoms in translate_molecule_by_XYZ.");} 00065 if((xs<-1)||(xd<-1)){mywhine("Invalid source or destination coordinates to translate_molecule_by_XYZ.");} 00066 if((xs==-1)&&(xd==-1)){ 00067 for(tr=0;tr<m[0].nr;tr++){ 00068 for(ta=0;ta<m[0].r[tr].na;ta++){ 00069 m[0].r[tr].a[ta].x.i+=vec.i; 00070 m[0].r[tr].a[ta].x.j+=vec.j; 00071 m[0].r[tr].a[ta].x.k+=vec.k; 00072 }} 00073 return; 00074 } 00075 if((xs>m[0].r[0].a[0].nalt-1)||(xd>=m[0].r[0].a[0].nalt-1)){ 00076 mywhine("Unallocated source or destination coordinates in translate_molecule_by_XYZ.");} 00077 if(xs==-1){ 00078 for(tr=0;tr<m[0].nr;tr++){ 00079 for(ta=0;ta<m[0].r[tr].na;ta++){ 00080 m[0].r[tr].a[ta].xa[xd].i=m[0].r[tr].a[ta].x.i+vec.i; 00081 m[0].r[tr].a[ta].xa[xd].j=m[0].r[tr].a[ta].x.j+vec.j; 00082 m[0].r[tr].a[ta].xa[xd].k=m[0].r[tr].a[ta].x.k+vec.k; 00083 }} 00084 return; 00085 } 00086 if(xd==-1){ 00087 for(tr=0;tr<m[0].nr;tr++){ 00088 for(ta=0;ta<m[0].r[tr].na;ta++){ 00089 m[0].r[tr].a[ta].x.i=m[0].r[tr].a[ta].xa[xs].i+vec.i; 00090 m[0].r[tr].a[ta].x.j=m[0].r[tr].a[ta].xa[xs].j+vec.j; 00091 m[0].r[tr].a[ta].x.k=m[0].r[tr].a[ta].xa[xs].k+vec.k; 00092 }} 00093 return; 00094 } 00095 // still here? 00096 if((xs<0)||(xd<0)){mywhine("Something is very wrong in translate_molecule_by_XYZ.");} 00097 for(tr=0;tr<m[0].nr;tr++){ 00098 for(ta=0;ta<m[0].r[tr].na;ta++){ 00099 m[0].r[tr].a[ta].xa[xd].i=m[0].r[tr].a[ta].xa[xs].i+vec.i; 00100 m[0].r[tr].a[ta].xa[xd].j=m[0].r[tr].a[ta].xa[xs].j+vec.j; 00101 m[0].r[tr].a[ta].xa[xd].k=m[0].r[tr].a[ta].xa[xs].k+vec.k; 00102 }} 00103 00104 return; 00105 } 00106 void translate_ensemble_by_XYZ(ensemble *e,int xs,int xd,coord_3D vec){ 00107 int ta=0,tr=0,tm=0; 00108 if(e[0].nm<=0){mywhine("Ensemble contains no molecules in translate_ensemble_by_XYZ.");} 00109 if(e[0].m[0].nr<=0){mywhine("Ensemble's molecule zero contains no residues in translate_ensemble_by_XYZ.");} 00110 if(e[0].m[0].r[0].na<=0){mywhine("Ensemble's molecule/residue zero contains no atoms in translate_ensemble_by_XYZ.");} 00111 if((xs<-1)||(xd<-1)){mywhine("Invalid source or destination coordinates to translate_ensemble_by_XYZ.");} 00112 if((xs==-1)&&(xd==-1)){ 00113 for(tm=0;tm<e[0].nm;tm++){ 00114 for(tr=0;tr<e[0].m[tm].nr;tr++){ 00115 for(ta=0;ta<e[0].m[tm].r[tr].na;ta++){ 00116 e[0].m[tm].r[tr].a[ta].x.i+=vec.i; 00117 e[0].m[tm].r[tr].a[ta].x.j+=vec.j; 00118 e[0].m[tm].r[tr].a[ta].x.k+=vec.k; 00119 }}} 00120 return; 00121 } 00122 if((xs>e[0].m[0].r[0].a[0].nalt-1)||(xd>=e[0].m[0].r[0].a[0].nalt-1)){ 00123 mywhine("Unallocated source or destination coordinates in translate_ensemble_by_XYZ.");} 00124 if(xs==-1){ 00125 for(tm=0;tm<e[0].nm;tm++){ 00126 for(tr=0;tr<e[0].m[tm].nr;tr++){ 00127 for(ta=0;ta<e[0].m[tm].r[tr].na;ta++){ 00128 e[0].m[tm].r[tr].a[ta].xa[xd].i=e[0].m[tm].r[tr].a[ta].x.i+vec.i; 00129 e[0].m[tm].r[tr].a[ta].xa[xd].j=e[0].m[tm].r[tr].a[ta].x.j+vec.j; 00130 e[0].m[tm].r[tr].a[ta].xa[xd].k=e[0].m[tm].r[tr].a[ta].x.k+vec.k; 00131 }}} 00132 return; 00133 } 00134 if(xd==-1){ 00135 for(tm=0;tm<e[0].nm;tm++){ 00136 for(tr=0;tr<e[0].m[tm].nr;tr++){ 00137 for(ta=0;ta<e[0].m[tm].r[tr].na;ta++){ 00138 e[0].m[tm].r[tr].a[ta].x.i=e[0].m[tm].r[tr].a[ta].xa[xs].i+vec.i; 00139 e[0].m[tm].r[tr].a[ta].x.j=e[0].m[tm].r[tr].a[ta].xa[xs].j+vec.j; 00140 e[0].m[tm].r[tr].a[ta].x.k=e[0].m[tm].r[tr].a[ta].xa[xs].k+vec.k; 00141 }}} 00142 return; 00143 } 00144 // still here? 00145 if((xs<0)||(xd<0)){mywhine("Something is very wrong in translate_ensemble_by_XYZ.");} 00146 for(tm=0;tm<e[0].nm;tm++){ 00147 for(tr=0;tr<e[0].m[tm].nr;tr++){ 00148 for(ta=0;ta<e[0].m[tm].r[tr].na;ta++){ 00149 e[0].m[tm].r[tr].a[ta].xa[xd].i=e[0].m[tm].r[tr].a[ta].xa[xs].i+vec.i; 00150 e[0].m[tm].r[tr].a[ta].xa[xd].j=e[0].m[tm].r[tr].a[ta].xa[xs].j+vec.j; 00151 e[0].m[tm].r[tr].a[ta].xa[xd].k=e[0].m[tm].r[tr].a[ta].xa[xs].k+vec.k; 00152 }}} 00153 00154 return; 00155 }