GLYLIB
0.3.0b
|
00001 /* File get_dipole.c begun on 20071231 by BLFoley 00002 * Purpose: contains functions for calculating dipole moments on 00003 * various structures. Dipole moments should be calculated via 00004 * the center of mass of the unit (only matters if the unit is 00005 * charged, but might as well). Since alternate coordinate sets are 00006 * allowed, the COM will be calculated here (despite anything listed 00007 * within the structure). 00008 */ 00009 #include <mylib.h> 00010 #include <molecules.h> 00011 /****************** get_molecule_point_charge_dipole() *********************/ 00012 /* Determines the dipole for a molecule based on the point charges of the 00013 * atoms at the coordinates specified. The atom type array is needed to 00014 * supply atom masses (to get the COM for the specified coordinates). 00015 */ 00016 00017 vectormag_3D get_molecule_point_charge_dipole(molecule *m,int xs,int chgsrc,atype *AT){ 00018 int ta=0,tb,tuse=0,tsz=0,tbins=0; 00019 coord_3D com; 00020 vectormag_3D dip; 00021 00022 dip = zero_vec(); 00023 // determine the center of mass 00024 com=get_molecule_COM(m,AT,xs); 00025 // calculate the dipole relative to the center of mass 00026 if(xs==-1){ 00027 // sum over all charge*(x-COM) 00028 for(ta=0;ta<m[0].nr;ta++){ 00029 for(tb=0;tb<m[0].r[ta].na;tb++){ 00030 dip.i+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].x.i-com.i); 00031 dip.j+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].x.j-com.j); 00032 dip.k+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].x.k-com.k); 00033 } 00034 } 00035 } 00036 else{ 00037 for(ta=0;ta<m[0].nr;ta++){ 00038 for(tb=0;tb<m[0].r[ta].na;tb++){ 00039 tuse=malloc_usable_size(m[0].r[ta].a[tb].xa); 00040 tsz=sizeof(coord_3D); 00041 tbins=tuse/tsz; 00042 if(tbins<(xs+1)){mywhine("memory issue: source coords not allocated in get_molecule_point_charge_dipole");} 00043 dip.i+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].xa[xs].i-com.i); 00044 dip.j+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].xa[xs].j-com.j); 00045 dip.k+=m[0].r[ta].a[tb].ch[chgsrc]*(m[0].r[ta].a[tb].xa[xs].k-com.k); 00046 } 00047 } 00048 } 00049 dip.d=get_magnitude(dip); 00050 00051 return dip; 00052 }