GLYLIB  0.3.0b
geometry.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include "geometries.h"
00003 //#include "geometry.h"
00004 
00005 /* Magnitude
00006  */
00007 /*double
00008 norm(vector a)
00009 {
00010     return sqrt(a.i*a.i + a.j*a.j + a.k*a.k);
00011 }
00012 */
00013 
00014 /*
00015 vector
00016 scale(vector v, double c)
00017 {
00018     return (vector) {v.i*c,
00019                      v.j*c,
00020                      v.k*c};
00021 }
00022 */
00023 
00024 /* Cross product
00025  */
00026 /*
00027 vector
00028 cross(vector a, vector b)
00029 {
00030     return (vector) {a.j*b.k - a.k*b.j,
00031                      a.k*b.i - a.i*b.k,
00032                      a.i*b.j - a.j*b.i};
00033 }
00034 */
00035 
00036 /* Get the unit vector in given direction
00037  */
00038 /*
00039 vector
00040 normalize(vector v)
00041 {
00042     return scale(v, 1/norm(v));
00043 }
00044 */
00045 
00046 /* Dot product
00047  */
00048 /*
00049 double
00050 dot(vector a, vector b)
00051 {
00052     return a.i*b.i + a.j*b.j + a.k*b.k;
00053 }
00054 */
00055 
00056 /* Euclidean distance from x to y
00057  */
00058 /*
00059 double
00060 dist(coord x, coord y)
00061 {
00062     return sqrt(pow(y.i-x.i,2) + pow(y.j-x.j,2) + pow(y.k-x.k,2));
00063 }
00064 */
00065 
00066 /*
00067 vector
00068 subtract(vector a, vector b){
00069     return (vector) {a.i - b.i,
00070                      a.j - b.j,
00071                      a.k - b.k};
00072 }
00073 */
00074 
00075 /*
00076 vector
00077 add(vector a, vector b){
00078     return (vector) {a.i + b.i,
00079                      a.j + b.j,
00080                      a.k + b.k};
00081 }
00082 */
00083 
00084 
00085 double get_angle_two_vectors(vectormag_3D a, vectormag_3D b)
00086 {
00087         return acos(get_dotprod(normalize_vec(a),normalize_vec(b)));
00088 
00089 }
00090 double get_angle_ABC(coord_3D a, coord_3D b, coord_3D c)
00091 {
00092         vectormag_3D ab = coord_to_vec(subtract_coord(a,b));
00093         vectormag_3D cb = coord_to_vec(subtract_coord(c,b));
00094         return get_angle_between_vectors(ab,cb);
00095 }
00096 
00097 /*
00098 double
00099 get_angle(coord a, coord b, coord c)
00100 {
00101     vector b1 = get_vector(b, a);
00102     vector b2 = get_vector(b, c);
00103     return acos( dot(b1,b2) / norm(b1) / norm(b2) );
00104 }
00105 */
00106 
00107 
00108 /** This assumes that the bonding goes as: A-B-C-D.  When A and D are eclipsed, 
00109         the angle is zero.  */
00110 double get_dihedral_bonded_ABCD(coord_3D a, coord_3D b, coord_3D c, coord_3D d)
00111 {
00112         vectormag_3D b1 = coord_to_vec(subtract_coord(a, b));
00113         vectormag_3D b2 = coord_to_vec(subtract_coord(b, c));
00114         vectormag_3D b3 = coord_to_vec(subtract_coord(c, d));
00115 
00116         return atan2( get_dotprod(scalarmult_vec(b1, b2.d), get_crossprod(b2,b3)),
00117                 get_dotprod(get_crossprod(b1,b2), get_crossprod(b2,b3)) ) ;
00118 }
00119 
00120 
00121 /*
00122 double
00123 get_dihedral(coord a, coord b, coord c, coord d)
00124 {
00125     vector b1 = get_vector(a, b);
00126     vector b2 = get_vector(b, c);
00127     vector b3 = get_vector(c, d);
00128 
00129     return atan2( dot(scale(b1, norm(b2)), cross(b2,b3)),
00130                   dot(cross(b1,b2), cross(b2,b3)) ) ;
00131 }
00132 */
00133 
00134 
00135 void
00136 translate_coords_dp_list(coord **coords, int num_coords, coord shift)
00137 {
00138     int i;
00139 
00140     for(i=0; i!=num_coords; i++){
00141         coords[i]->i += shift.i;
00142         coords[i]->j += shift.j;
00143         coords[i]->k += shift.k;
00144     }
00145 }
00146 
00147 
00148 void
00149 orient_coords2_to_coords1_dp_list(coord **coords, int num_coords,
00150           const coord *bond_atom_a, coord *bond_atom_b, double distance,
00151           const coord *angle_atom_a, double theta,
00152           coord *angle_atom_b, double rho,
00153           const coord *dih_atom_a, coord *dih_atom_b, double tau,
00154           const coord *tor_atom_a, const coord *ref_angle_a, double phi,
00155           coord *tor_atom_b, coord *ref_atom_b, double omega)
00156 {
00157     coord d = find_attachment_point(*ref_angle_a, *tor_atom_a, *bond_atom_a,
00158                                     theta, PI - phi, distance);
00159 
00160     translate_coords(coords, num_coords, subtract(d,*bond_atom_b));
00161 
00162     double cur_dihedral = get_dihedral(*dih_atom_a, *bond_atom_a,
00163                                        *bond_atom_b, *dih_atom_b);
00164     double cur_bond_angle = get_angle(*bond_atom_a, *bond_atom_b, *angle_atom_b);
00165 
00166     rotate_coords(coords, num_coords, *bond_atom_b,
00167                   cross(
00168                     get_vector(*bond_atom_a, *bond_atom_b),
00169                     get_vector(*angle_atom_b, *bond_atom_b)
00170                   ),
00171                   rho-cur_bond_angle);
00172 
00173     rotate_coords(coords, num_coords, *bond_atom_a,
00174                   subtract(*bond_atom_a, *bond_atom_b), cur_dihedral-tau);
00175 
00176     double cur_omega = get_dihedral(*bond_atom_a, *bond_atom_b,
00177                                     *tor_atom_b, *ref_atom_b);
00178 
00179     rotate_coords(coords, num_coords, *bond_atom_b,
00180                   subtract(*bond_atom_b, *tor_atom_b),
00181                   cur_omega-omega);
00182 }
00183 
00184 /*
00185 coord **
00186 atoms_to_coord_list(atom **atoms, int num_atoms)
00187 {
00188     int i;
00189 
00190     coord **coords = (coord **)malloc(num_atoms * sizeof(coord *));
00191     for(i=0; i<num_atoms; i++)
00192         coords[i] = &atoms[i]->x;
00193 
00194     return coords;
00195 }
00196 */
 All Classes Files Functions Variables Typedefs Defines