GLYLIB
0.3.0b
|
00001 /* File vector_movements.c begun on 20071231 by BLFoley. 00002 * Purpose: Provide functions that will move the atoms in a 00003 * structure according to vectors contained in the structure. 00004 */ 00005 #include <mylib.h> 00006 #include <molecules.h> 00007 //#include "../inc/mylib.h" 00008 //#include "../inc/molecules.h" 00009 /****************** shift_molecule_atoms_by_vector() *********************/ 00010 /* Moves each atom in a molecule acording to a vector saved within the 00011 * molecule. Moves the atoms according to the requested scale times the 00012 * vector. For coordinates, -1 means use main coordinate set. Usage: 00013 * shift_molecule_atoms_by_vector(molecule *m,int xs,int xt,int vr, double scale) 00014 * molecule *m = the molecule containing the data 00015 * int xs = the source coordinates (the coords to be shifted) 00016 * int xt = the target coordinated (where to put the shifted coords) 00017 * int vr = the vector by which to shift the atoms 00018 * double scale = vector scale factor to use for the shifting 00019 */ 00020 00021 void shift_molecule_atoms_by_vector_scale(molecule *m,int xs,int xt,int vr, double scale){ 00022 int ta=0,tb,tuse=0,tsz=0,tbins=0; 00023 coord_3D c; 00024 00025 // move atoms by scale * vector 00026 if((xs==-1)&&(xt==-1)){ 00027 for(ta=0;ta<m[0].nr;ta++){ 00028 for(tb=0;tb<m[0].r[ta].na;tb++){ 00029 c=scalarmult_coord(vec_to_coord(m[0].r[ta].a[tb].v[vr]),scale); 00030 m[0].r[ta].a[tb].x=add_coord(m[0].r[ta].a[tb].x,c); 00031 } 00032 } 00033 } 00034 if((xs!=-1)&&(xt==-1)){ 00035 for(ta=0;ta<m[0].nr;ta++){ 00036 for(tb=0;tb<m[0].r[ta].na;tb++){ 00037 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00038 tsz=sizeof(coord_3D); 00039 tbins=tuse/tsz; 00040 if(tbins<(xs+1)){mywhine("memory issue: source coords (1) not allocated in shift_molecule_atoms_by_vector_scale");} 00041 c=scalarmult_coord(vec_to_coord(m[0].r[ta].a[tb].v[vr]),scale); 00042 m[0].r[ta].a[tb].x=add_coord(m[0].r[ta].a[tb].xa[xs],c); 00043 } 00044 } 00045 } 00046 if((xs==-1)&&(xt!=-1)){ 00047 for(ta=0;ta<m[0].nr;ta++){ 00048 for(tb=0;tb<m[0].r[ta].na;tb++){ 00049 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00050 tsz=sizeof(coord_3D); 00051 tbins=tuse/tsz; 00052 if(tbins<(xt+1)){mywhine("memory issue: translated coords (1) not allocated in shift_molecule_atoms_by_vector_scale");} 00053 c=scalarmult_coord(vec_to_coord(m[0].r[ta].a[tb].v[vr]),scale); 00054 m[0].r[ta].a[tb].xa[xt]=add_coord(m[0].r[ta].a[tb].x,c); 00055 } 00056 } 00057 } 00058 if((xs!=-1)&&(xt!=-1)){ 00059 for(ta=0;ta<m[0].nr;ta++){ 00060 for(tb=0;tb<m[0].r[ta].na;tb++){ 00061 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00062 tsz=sizeof(coord_3D); 00063 tbins=tuse/tsz; 00064 if(tbins<(xs+1)){mywhine("memory issue: source coords (2) not allocated in shift_molecule_atoms_by_vector_scale");} 00065 if(tbins<(xt+1)){mywhine("memory issue: translated coords (2) not allocated in shift_molecule_atoms_by_vector_scale");} 00066 c=scalarmult_coord(vec_to_coord(m[0].r[ta].a[tb].v[vr]),scale); 00067 m[0].r[ta].a[tb].xa[xt]=add_coord(m[0].r[ta].a[tb].xa[xs],c); 00068 } 00069 } 00070 } 00071 return; 00072 }