TorsionAngle.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_TORSIONANGLE_H__
00011 #define __RD_TORSIONANGLE_H__
00012 
00013 #include <ForceField/Contrib.h>
00014 
00015 // we need this so that we get the hybridizations:
00016 #include <GraphMol/Atom.h>
00017 //#include <Geometry/point.h>
00018 
00019 namespace RDGeom {
00020   class Point3D;
00021 }
00022 
00023 namespace ForceFields {
00024   namespace UFF {
00025     class AtomicParams;
00026 
00027     //! the torsion term for the Universal Force Field
00028     class TorsionAngleContrib : public ForceFieldContrib {
00029     public:
00030       TorsionAngleContrib() : d_at1Idx(-1), d_at2Idx(-1), d_at3Idx(-1), d_at4Idx(-1), d_order(0) {};
00031       //! Constructor
00032       /*!
00033         The torsion is between atom1 - atom2 - atom3 - atom4
00034         (i.e the angle between bond atom1-atom2 and bond atom3-atom4
00035         while looking down bond atom2-atom3)
00036         
00037         \param owner       pointer to the owning ForceField
00038         \param idx1        index of atom1 in the ForceField's positions
00039         \param idx2        index of atom2 in the ForceField's positions
00040         \param idx3        index of atom3 in the ForceField's positions
00041         \param idx4        index of atom4 in the ForceField's positions
00042         \param bondOrder23 order of the torsional bond between atoms 2 and 3 (as a double)
00043         \param atNum2      atomic number of atom2
00044         \param atNum3      atomic number of atom3
00045         \param hyb2        hybridization of atom2
00046         \param hyb3        hybridization of atom3
00047         \param at2Params   pointer to the parameters for atom 2
00048         \param at3Params   pointer to the parameters for atom 3
00049         \param endAtomIsSP2 (optional)
00050           This boolean is used to signal whether either atom1 or atom4 are
00051           RDKit::Atom::SP2 hybridized.
00052           This triggers a special case when either of these cases holds:
00053            - atom1 is RDKit::Atom::SP2, atom2 is RDKit::Atom::SP2
00054              and atom3 is RDKit::Atom::SP3
00055            - atom4 is RDKit::Atom::SP2, atom3 is RDKit::Atom::SP2
00056              and atom2 is RDKit::Atom::SP3
00057       */
00058       TorsionAngleContrib(ForceField *owner,
00059                           unsigned int idx1,unsigned int idx2,
00060                           unsigned int idx3,unsigned int idx4,
00061                           double bondOrder23,
00062                           int atNum2,int atNum3,
00063                           RDKit::Atom::HybridizationType hyb2,
00064                           RDKit::Atom::HybridizationType hyb3,
00065                           const AtomicParams *at2Params,
00066                           const AtomicParams *at3Params,
00067                           bool endAtomIsSP2=false);
00068       double getEnergy(double *pos) const;
00069       void getGrad(double *pos,double *grad) const;
00070       void scaleForceConstant(unsigned int count) { this->d_forceConstant /= static_cast<double>(count); };
00071     private:
00072       int d_at1Idx,d_at2Idx,d_at3Idx,d_at4Idx;
00073       unsigned int d_order;
00074       double d_forceConstant,d_cosTerm;
00075 
00076       //! returns dE/dTheta
00077       double getThetaDeriv(double cosTheta,double sinTheta) const;
00078 
00079       //! calculate default values of the torsion parameters.
00080       /*!
00081          see the constructor for an explanation of the arguments
00082       */
00083       void calcTorsionParams(double bondOrder23,
00084                              int atNum2,int atNum3,
00085                              RDKit::Atom::HybridizationType hyb2,
00086                              RDKit::Atom::HybridizationType hyb3,
00087                              const AtomicParams *at2Params,
00088                              const AtomicParams *at3Params,
00089                              bool endAtomIsSP2);
00090 
00091     };
00092 
00093     namespace Utils {
00094       //! calculates and returns the cosine of a torsion angle
00095       double calculateCosTorsion(const RDGeom::Point3D &p1,const RDGeom::Point3D &p2,
00096                                  const RDGeom::Point3D &p3,const RDGeom::Point3D &p4);
00097     }
00098   }
00099 }
00100 #endif