PExtension.h

Go to the documentation of this file.
00001 /*
00002     LoopTK: Protein Loop Kinematic Toolkit
00003     Copyright (C) 2007 Stanford University
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; if not, write to the Free Software Foundation, Inc.,
00017     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 */
00019 
00020 /*
00021  * PExtension defines a variety of auxiliary
00022  * classes that are not considered part of the
00023  * "core" LoopTK class hierarchy. These include
00024  * file I/O classes, initialization classes,
00025  * test classes, and so forth.
00026  */
00027 
00028 #ifndef PEXTENSION_H
00029 #define PEXTENSION_H
00030 
00031 #include "PBasic.h"
00032 #include "PIKAlgorithms.h"
00033 #include "PConstants.h"
00034 // @package Conformation Analysis
00035 
00036 #include <libxml/parser.h>
00037 #include <libxml/tree.h>
00038 
00039 typedef list<PLightChain *> PLightChainList;
00040 
00047 class PConformationSpace: public PLightChainList
00048 {
00049  public:
00050 
00060   PConformationSpace(pair<PLightChain *,PLightChain *> staticPortions);
00061   ~PConformationSpace();
00062   
00069   pair<PLightChain *, PLightChain *> getStaticPortions() { return m_staticPortions; }
00070 
00071  private:
00072   pair<PLightChain *,PLightChain *> m_staticPortions;
00073 
00074 };
00075 
00076 
00077 /*
00078  * A csConfLine (conformation line) defines a new position for one
00079  * particular atom in one particular loop residue.
00080  */
00081 
00082 #define         csConfLine              pair<pair<int, string>, Vector3>
00083 
00084 enum WarningIndicator {
00085   SUPPRESS_WARNINGS,
00086   ENABLE_WARNINGS
00087 };
00088 // @package Main Infrastructure
00096 class LoopTK {
00097  public:
00098 
00104   static void Initialize(WarningIndicator ind, const string &resourcePath = "resources");
00105 
00110   static void SuppressWarnings();
00111 
00116   static void EnableWarnings();
00117 
00123   static void DisplayWarning(const string &warning);
00124  private:
00125   static bool m_warningsEnabled;
00126 };
00127 
00128 //@package Resource Management
00136 class PInit {
00137   friend class LoopTK;
00138 
00139   public:
00140     static string GetName(xmlNodePtr node);
00141     static string GetAttribute(xmlNodePtr node, const string &attr);
00142 
00143   private:
00144     static void InitializeResources(const string &resourceDir);
00145 
00146     static HASH_MAP_STRPAIR_EX(vector<PBlockBondShell>) blockBonds;
00147     static HASH_MAP_STRPAIR_EX(HASH_MAP_STRPAIR_EX(Vector3)) relPos;
00148 
00149     static void setupBlockShells(const string &file);
00150     static void setupBlockConnections(const string &file);
00151     static void setupResidueShells(const string &file);
00152 
00153     static void setupAtomShells(const string &file);
00154     static void setupChiIndices(const string &file);
00155     static void setupEpsilonVals(const string &file);
00156     static void setupIDMaps(const string &file);
00157     static void setupRotamers(const string &file);
00158 };
00159 //@package Input-Output
00169 class PDBIO {
00170   friend class CS2IO;   /* To access readFromLines(). */
00171 
00172   public:
00173 
00179     struct pdbAtomLine {
00180       string atomName, resName, elem;
00181       char altLoc, insCode, chainID;
00182       int atomNum, resNum;
00183       string occupancy, tempFactor;
00184       Vector3 pos;
00185     };
00186 
00194     static PProtein* readFromFile(const string &fileName, const string &chainId="");
00195 
00202     static void writeToFile(PChain *chain, const string &fileName, const string &prefix = "");
00203 
00210     static bool isCyclicPDB(const string &fileName);
00211 
00219     static vector<string> getAllAtomLines(const vector<string> &pdbLines);
00220 
00226     static pdbAtomLine parseAtomLine(const string &line);
00227 
00228   private:
00229 
00230     /* Helper functions for readFromFile(). */
00231 
00232     static PProtein* readFromLines(const vector<string> &pdbLines);
00233     static PProtein* readFromMap(const hash_map<int, vector<pdbAtomLine> > &atomMap, 
00234                                  const set<int> &allResNums);
00235     static void updateProtein(PProtein* &protein, const string &resName,
00236                                 PResidueSpec &spec, int resNum);
00237 
00238     static void trimHeadAndTail(vector<int> &resIndices, const hash_map<int,
00239                                 vector<pdbAtomLine> > &atomMap);
00240     static PResidueSpec getSpec(const vector<pdbAtomLine> &atomLines);
00241     static bool definesBackbone(PResidueSpec &spec);
00242 
00243     /* Helper functions for writeToFile() that do some error checking. */
00244 
00245     static void addAtomNum(string &pdbOutLine, int atomNum, string::size_type prefixLen);
00246     static void addAtomName(string &pdbOutLine, const string &atomName, string::size_type prefixLen);
00247     static void addResName(string &pdbOutLine, const string &resName, string::size_type prefixLen);
00248     static void addChainID(string &pdbOutLine, char chainID, string::size_type prefixLen);
00249     static void addResNum(string &pdbOutLine, int resNum, string::size_type prefixLen);
00250     static void addInsertionCode(string &pdbOutLine, const string &insCode, string::size_type prefixLen);
00251     static void addAtomPos(string &pdbOutLine, const Vector3 &atomPos, string::size_type prefixLen);
00252     static void addAuxData(string &pdbOutLine, Real occupancy, Real tempFactor,
00253                                 const string &segmentID, string::size_type prefixLen);
00254     static void addElemName(string &pdbOutLine, const string &elemName, string::size_type prefixLen);
00255 
00256 };
00257 
00258 //@package Math
00267 class PMath {
00268   public:
00269 
00275    static Real AngleBetweenPlanes(const Vector3 &p1, const Vector3 &p2,
00276                                   const Vector3 &p3, const Vector3 &p4);
00277 
00283     static Real getAngle(const Vector3 &v1, const Vector3 &v2);
00284 
00291     static Vector3 ComputePos(const Vector3 &prev, const Vector3 &cur, Real angle, Real bondLength);
00292 
00299     static bool sphereIntersectsCube(const Vector3 &sphereCenter, Real sphereRadius,
00300                                      const Vector3 &cubeVertex1, const Vector3 &cubeVertex2);
00301 
00307     static Vector3 ArbitraryNonParallel(const Vector3 &v);
00308 
00313     static void normalize(vector<double> &v);
00314 
00315     //finds transform that moves s1 to e1 and s2 to e2
00316     static Matrix4 Find2PtTransform(Vector3 s1, Vector3 s2, Vector3 e1, Vector3 e2);
00317 
00324     static Matrix3 FindRotationMatrix(const Vector3 &axis, Real angle);
00325 
00331     static Vector3 LocalToGlobalCoord(const vector<Vector3> definedRelativeCoordinates, const vector<Vector3> definedGlobalCoordinates);
00335     static void ConvertToQuaternion(double** input, Vector4* output, vector<int> sign);
00339     static void InterpolateQuaternion(Vector4 qi, Vector4 qf, Vector4* qu, double u);
00343     static void DeltaQuaterToDeltaVel(Vector4 qi, Vector4 qf, Vector3* delatV);
00344    
00346      static int signum(double a);
00347   
00349     static double TorsionAngle(Vector3 u,Vector3 v,Vector3 w);
00350 
00351     static double abs(double d);
00352 };
00353 
00362 class Angle {
00363 
00364   public:
00365 
00372     Angle(AngleType type, Real value);
00373 
00378     Real getDegrees();
00379 
00384     Real getRadians();
00385 
00386   private:
00387 
00388     AngleType m_type;   /* The angle type (radians or degrees). */
00389     Real m_value;       /* The angle value in m_type units.     */
00390 
00391 };
00392 //@package Input-Output
00402 class CS2IO {
00403 
00404   public:
00405 
00416     static PProtein* readConformation(const string &cs2File, int confNum);
00417 
00426     static PLightChain *readConformationLoopOnly(const string &cs2File, int confNum);
00427     
00437     static PConformationSpace *readConformationSpace(const string &cs2File);
00438 
00447     static pair<PLightChain *, PLightChain *> getNonLoopChains(const string &cs2File);
00448 
00457     static void appendConformation(const string &cs2File, PProtein *loop);
00458 
00467     static void writeToFile(const string &cs2File, PProtein *loop);
00468 
00473     static int getNumConformations(const string &cs2File);
00474 
00480     static void createPDBDirectory(const string &cs2File,const string &directoryName);
00481 
00482 
00483   private:
00484 
00485     /* Versions of the public functions that read from constituent components
00486      * of CS2 file. */
00487     static PLightChain *readConformationLoopOnly(const vector<string> &atomLines,
00488                                                  const vector<string> &loopLines,
00489                                                  const vector<string> &confLines,
00490                                                  const string &fileName);
00491     static pair<PLightChain *, PLightChain *> getNonLoopChains(const vector<string> &atomLines,
00492                                                                const vector<string> &loopLines,
00493                                                                 const string &fileName);
00494 
00495     /* Grabs the PDB atom lines, "loop" line and (optionally) conformation lines in cs2File. */
00496     static void parseFile(const string &cs2File, vector<string> &atomLines, vector<string> &loopLines);
00497     static void parseFile(const string &cs2File, vector<string> &atomLines, vector<string> &loopLines,
00498           vector<vector<string> > &allConfLines);
00499     static void parseFile(const string &cs2File, int confNum, vector<string> &atomLines, vector<string> &loopLines,
00500           vector<string> &confLines);
00501 
00502     /* Helpers for parseFile. */
00503     static vector<string> extractAtomLines(const vector<string> &cs2Lines, const string &fileName);
00504     static vector<string> extractLoopLines(const vector<string> &cs2Lines, const string &fileName);
00505     static vector<vector<string> > extractConfLines(const vector<string> &cs2Lines, const string &fileName);
00506 
00507     /* Parses a "cn" line, using sanityCheck to make sure residue indices are valid. */
00508     static csConfLine parseConfLine(const string &cs2File, const string &cs2Line,
00509         const pair<int, int> &sanityCheck);
00510 
00511     /* Counts the number of conformations in the specified CS2 file. */
00512     static int countConformations(const string &cs2File);
00513 
00514     /* Writes loop to the specified file as the confNum'th conformation,
00515      * using the specified start and end residue indices into the top level. */
00516     static void outputHelper(const string &cs2File, PProtein *loop, int confNum,
00517            int startIndex, int endIndex);
00518 
00519     /* Parses a "loop" line from the specified file into its constituent pair of ints. */
00520     static pair<int, int> parseLoopLine(const string &cs2File, const string &loopLine);
00521 
00522     /* Applies the specified conformation to loop, subtracting offset from start index. */
00523     static void applyConfLine(PProtein* &loop, const csConfLine &conf, int offset = 0);
00524 };
00525 
00526 typedef Real(*EnergyCalcFn)(const PAtom *, const PAtom *);
00527 
00528 //@package Math
00536 class PEnergy {
00537 
00538   public:
00539 
00545         static const Real DEFAULT_THRESHOLD = 10;
00546 
00552         static Real vanDerWaalsEnergy(const PAtom *a1, const PAtom *a2);
00553 
00564         static Real energyOfChain(PChain *chain, EnergyCalcFn energyFn = vanDerWaalsEnergy, Real threshold = DEFAULT_THRESHOLD);
00565 
00575         static Real collisionEnergy(const PAtom *a1, const PAtom *a2);
00576 
00577 
00578   private:
00579 
00580 };
00581  //@package Optimization
00588 class PMoveAtom {
00589 
00590   public:
00599         static vector<IKSolutions> MoveAtom(vector<PProtein*> loops, vector<vector<CDof> > Dofs, vector<int> AtomToMove, vector<Vector3> MovementDirn);
00606         static IKSolutions MoveAtom(PProtein *loop, int AtomToMove, Vector3 MovementDirn);
00607 
00608   private:
00609 
00610 };
00611 
00612 #endif

Generated on Tue Aug 26 16:06:04 2008 for LoopTK: Protein Loop Kinematic Toolkit by  doxygen 1.5.1