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);
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();
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();
00150     static void setupBlockConnections();
00151     static void setupResidueShells();
00152 
00153     static void setupAtomShells();
00154     static void setupChiIndices();
00155     static void setupEpsilonVals();
00156     static void setupIDMaps();
00157     static void setupRotamers();
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 
00193     static PProtein* readFromFile(const string &fileName);
00194 
00201     static void writeToFile(PChain *chain, const string &fileName, const string &prefix = "");
00202 
00209     static bool isCyclicPDB(const string &fileName);
00210 
00218     static vector<string> getAllAtomLines(const vector<string> &pdbLines);
00219 
00225     static pdbAtomLine parseAtomLine(const string &line);
00226 
00227   private:
00228 
00229     /* Helper functions for readFromFile(). */
00230 
00231     static PProtein* readFromLines(const vector<string> &pdbLines);
00232     static PProtein* readFromMap(const hash_map<int, vector<pdbAtomLine> > &atomMap, 
00233                                  const set<int> &allResNums);
00234     static void updateProtein(PProtein* &protein, const string &resName,
00235                                 PResidueSpec &spec, int resNum);
00236 
00237     static void trimHeadAndTail(vector<int> &resIndices, const hash_map<int,
00238                                 vector<pdbAtomLine> > &atomMap);
00239     static PResidueSpec getSpec(const vector<pdbAtomLine> &atomLines);
00240     static bool definesBackbone(PResidueSpec &spec);
00241 
00242     /* Helper functions for writeToFile() that do some error checking. */
00243 
00244     static void addAtomNum(string &pdbOutLine, int atomNum, string::size_type prefixLen);
00245     static void addAtomName(string &pdbOutLine, const string &atomName, string::size_type prefixLen);
00246     static void addResName(string &pdbOutLine, const string &resName, string::size_type prefixLen);
00247     static void addChainID(string &pdbOutLine, char chainID, string::size_type prefixLen);
00248     static void addResNum(string &pdbOutLine, int resNum, string::size_type prefixLen);
00249     static void addInsertionCode(string &pdbOutLine, const string &insCode, string::size_type prefixLen);
00250     static void addAtomPos(string &pdbOutLine, const Vector3 &atomPos, string::size_type prefixLen);
00251     static void addAuxData(string &pdbOutLine, Real occupancy, Real tempFactor,
00252                                 const string &segmentID, string::size_type prefixLen);
00253     static void addElemName(string &pdbOutLine, const string &elemName, string::size_type prefixLen);
00254 
00255 };
00256 
00257 //@package Math
00266 class PMath {
00267   public:
00268 
00274    static Real AngleBetweenPlanes(const Vector3 &p1, const Vector3 &p2,
00275                                   const Vector3 &p3, const Vector3 &p4);
00276 
00282     static Real getAngle(const Vector3 &v1, const Vector3 &v2);
00283 
00290     static Vector3 ComputePos(const Vector3 &prev, const Vector3 &cur, Real angle, Real bondLength);
00291 
00298     static bool sphereIntersectsCube(const Vector3 &sphereCenter, Real sphereRadius,
00299                                      const Vector3 &cubeVertex1, const Vector3 &cubeVertex2);
00300 
00306     static Vector3 ArbitraryNonParallel(const Vector3 &v);
00307 
00312     static void normalize(vector<double> &v);
00313 
00314     //finds transform that moves s1 to e1 and s2 to e2
00315     static Matrix4 Find2PtTransform(Vector3 s1, Vector3 s2, Vector3 e1, Vector3 e2);
00316 
00323     static Matrix3 FindRotationMatrix(const Vector3 &axis, Real angle);
00324 
00330     static Vector3 LocalToGlobalCoord(const vector<Vector3> definedRelativeCoordinates, const vector<Vector3> definedGlobalCoordinates);
00334     static void ConvertToQuaternion(double** input, Vector4* output, vector<int> sign);
00338     static void InterpolateQuaternion(Vector4 qi, Vector4 qf, Vector4* qu, double u);
00342     static void DeltaQuaterToDeltaVel(Vector4 qi, Vector4 qf, Vector3* delatV);
00343    
00345      static int signum(double a);
00346   
00348     static double TorsionAngle(Vector3 u,Vector3 v,Vector3 w);
00349 };
00350 
00359 class Angle {
00360 
00361   public:
00362 
00369     Angle(AngleType type, Real value);
00370 
00375     Real getDegrees();
00376 
00381     Real getRadians();
00382 
00383   private:
00384 
00385     AngleType m_type;   /* The angle type (radians or degrees). */
00386     Real m_value;       /* The angle value in m_type units.     */
00387 
00388 };
00389 //@package Input-Output
00399 class CS2IO {
00400 
00401   public:
00402 
00413     static PProtein* readConformation(const string &cs2File, int confNum);
00414 
00423     static PLightChain *readConformationLoopOnly(const string &cs2File, int confNum);
00424     
00434     static PConformationSpace *readConformationSpace(const string &cs2File);
00435 
00444     static pair<PLightChain *, PLightChain *> getNonLoopChains(const string &cs2File);
00445 
00454     static void appendConformation(const string &cs2File, PProtein *loop);
00455 
00464     static void writeToFile(const string &cs2File, PProtein *loop);
00465 
00470     static int getNumConformations(const string &cs2File);
00471 
00477     static void createPDBDirectory(const string &cs2File,const string &directoryName);
00478 
00479 
00480   private:
00481 
00482     /* Versions of the public functions that read from constituent components
00483      * of CS2 file. */
00484     static PLightChain *readConformationLoopOnly(const vector<string> &atomLines,
00485                                                  const vector<string> &loopLines,
00486                                                  const vector<string> &confLines,
00487                                                  const string &fileName);
00488     static pair<PLightChain *, PLightChain *> getNonLoopChains(const vector<string> &atomLines,
00489                                                                const vector<string> &loopLines,
00490                                                                 const string &fileName);
00491 
00492     /* Grabs the PDB atom lines, "loop" line and (optionally) conformation lines in cs2File. */
00493     static void parseFile(const string &cs2File, vector<string> &atomLines, vector<string> &loopLines);
00494     static void parseFile(const string &cs2File, vector<string> &atomLines, vector<string> &loopLines,
00495           vector<vector<string> > &allConfLines);
00496     static void parseFile(const string &cs2File, int confNum, vector<string> &atomLines, vector<string> &loopLines,
00497           vector<string> &confLines);
00498 
00499     /* Helpers for parseFile. */
00500     static vector<string> extractAtomLines(const vector<string> &cs2Lines, const string &fileName);
00501     static vector<string> extractLoopLines(const vector<string> &cs2Lines, const string &fileName);
00502     static vector<vector<string> > extractConfLines(const vector<string> &cs2Lines, const string &fileName);
00503 
00504     /* Parses a "cn" line, using sanityCheck to make sure residue indices are valid. */
00505     static csConfLine parseConfLine(const string &cs2File, const string &cs2Line,
00506         const pair<int, int> &sanityCheck);
00507 
00508     /* Counts the number of conformations in the specified CS2 file. */
00509     static int countConformations(const string &cs2File);
00510 
00511     /* Writes loop to the specified file as the confNum'th conformation,
00512      * using the specified start and end residue indices into the top level. */
00513     static void outputHelper(const string &cs2File, PProtein *loop, int confNum,
00514            int startIndex, int endIndex);
00515 
00516     /* Parses a "loop" line from the specified file into its constituent pair of ints. */
00517     static pair<int, int> parseLoopLine(const string &cs2File, const string &loopLine);
00518 
00519     /* Applies the specified conformation to loop, subtracting offset from start index. */
00520     static void applyConfLine(PProtein* &loop, const csConfLine &conf, int offset = 0);
00521 };
00522 
00523 typedef Real(*EnergyCalcFn)(const PAtom *, const PAtom *);
00524 
00525 //@package Math
00533 class PEnergy {
00534 
00535   public:
00536 
00542         static const Real DEFAULT_THRESHOLD = 10;
00543 
00549         static Real vanDerWaalsEnergy(const PAtom *a1, const PAtom *a2);
00550 
00561         static Real energyOfChain(PChain *chain, EnergyCalcFn energyFn = vanDerWaalsEnergy, Real threshold = DEFAULT_THRESHOLD);
00562 
00572         static Real collisionEnergy(const PAtom *a1, const PAtom *a2);
00573 
00574 
00575   private:
00576 
00577 };
00578  //@package Optimization
00585 class PMoveAtom {
00586 
00587   public:
00596         static vector<IKSolutions> MoveAtom(vector<PProtein*> loops, vector<vector<CDof> > Dofs, vector<int> AtomToMove, vector<Vector3> MovementDirn);
00603         static IKSolutions MoveAtom(PProtein *loop, int AtomToMove, Vector3 MovementDirn);
00604 
00605   private:
00606 
00607 };
00608 
00609 #endif

Generated on Wed May 16 20:22:07 2007 for LoopTK: Protein Loop Kinematic Toolkit by  doxygen 1.5.1