Utils.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2004-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 #ifndef __RD_DIST_UTILS_H__
00011 #define __RD_DIST_UTILS_H__
00012 
00013 #include <math.h>
00014 #include "point.h"
00015 #include "Transform3D.h"
00016 #include "Transform.h"
00017 
00018 namespace RDGeom {
00019 
00020   /*! \brief Compute the 13 distance between points give the 12 distances
00021    *  and the angle between the axes.
00022    */
00023   inline double compute13Dist(double d1, double d2, double angle) {
00024     double res = d1*d1 + d2*d2 - 2*d1*d2*cos(angle);
00025     return sqrt(res);
00026   }
00027 
00028   /*! \brief Compute the 14 distances give the 12 distance and the angles
00029    *
00030    *   This is computed by aligning the d2 axis with the x-axis (with atom 2 at 
00031    *   the origin. Atom 1 is made to lie int he xy-plane with a +ve y-coordinate
00032    *   and finally the coordinates for atom 4 are computed. 
00033    *
00034    * ARGUMENTS:
00035    *   d1 - distance between atoms 1 and 2
00036    *   d2 - distance between atoms 2 and 3
00037    *   d3 - distance between atoms 3 and 4
00038    *   ang12 - angle between the axes d1 and d2
00039    *   ang23 - angle between the axes d2 and d3
00040    *   torAng - torsional agnle of the axis d2
00041    *
00042    * NOTE:
00043    *   we are specifically calling this function compute14Dist3D because
00044    *   we assume the torsional angle can take any value including 0 and 180 deg.
00045    *   However, if using either 0 or 180 as the torsional angle (which is often 
00046    *   the case) the user is recommended to use the specialized functions below
00047    *   instead of this function; they will be speedier.
00048    */
00049   inline double compute14Dist3D(double d1, double d2, double d3, 
00050                                 double ang12, double ang23, double torAng) {
00051     // location of atom1
00052     Point3D p1(d1*cos(ang12), d1*sin(ang12), 0.0);
00053 
00054     // location of atom 4 if the rosion angle was 0
00055     Point3D p4(d2-d3*cos(ang23), d3*sin(ang23), 0.0);
00056     
00057     // now we will rotate p4 about the x-axis by the desired torsion angle
00058     Transform3D trans;
00059     trans.SetRotation(torAng, X_Axis);
00060     trans.TransformPoint(p4);
00061 
00062     // find the distance
00063     p4 -= p1;
00064     return p4.length();
00065   }
00066 
00067   /*! \brief Compute the 14 distances give the 12 distance and bond angle
00068    *  for cis configuration
00069    *
00070    *  This is simply a special case of the above function compute14Dist3D;
00071    *  with torsion angle set to 0. However, this function should be speedier
00072    */
00073   inline double compute14DistCis(double d1, double d2, double d3, 
00074                                 double ang12, double ang23) {
00075     double dx = d2 - d3*cos(ang23) - d1*cos(ang12);
00076     double dy = d3*sin(ang23) - d1*sin(ang12);
00077     double res = dx*dx + dy*dy;
00078     return sqrt(res);
00079   }
00080 
00081   
00082    /*! \brief Compute the 14 distances give the 12 distance and bond angle
00083    *  for trans configuration
00084    *
00085    *  This is simply a special case of the above function compute14Dist3D;
00086    *  with torsion angle set to 180. However, this function should be speedier
00087    */
00088   inline double compute14DistTrans(double d1, double d2, double d3, 
00089                                 double ang12, double ang23) {
00090     double dx = d2 - d3*cos(ang23) - d1*cos(ang12);
00091     double dy = d3*sin(ang23) + d1*sin(ang12);
00092     double res = dx*dx + dy*dy;
00093     return sqrt(res);
00094   } 
00095 }
00096 
00097 #endif