PChain.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 #ifndef __P_CHAIN_H
00021 #define __P_CHAIN_H
00022 
00023 #include "PAtom.h"
00024 #include "PAtomNode.h"
00025 #include "PGrid.h"
00026 #include "PLightChain.h"
00027 #include "PResidue.h"
00028 #include "PStructs.h"
00029 
00030 #include <list>
00031 using std::list;
00032 
00033 //@package Main Infrastructure
00053 class PChain: public PLightChain {
00054  public:
00055   friend class PAtom; // so that it can access the grid
00056 
00060   PChain();
00061 
00066   PChain(const string &firstResidueName);
00067 
00072   PChain(const string &firstResidueName, PResidueSpec &firstResidueSpec);
00073 
00078   PChain(PChain *protein, int resStartIndex, int resEndIndex);
00079 
00084   ~PChain();
00085 
00090   void Obliterate();
00091 
00092 
00098   PResidue *AddResidue(const string &resName);
00099 
00105   PResidue *AddResidue(const string &resName, PResidueSpec &resSpec);
00106 
00111   bool IsSubChainOf(const PChain *other) const;
00112 
00117   PChain *getParent() const;
00118 
00123   PChain *getTopLevelChain();
00124 
00131   PBond *getBond(int res_index, const string &id1, const string &id2);
00132 
00140   PBond *getBond(int res_index1, const string &id1, int res_index2, const string &id2);
00141 
00145   int size() const;
00146 
00154   PResidue *getResidue(int localIndex);
00155 
00159   int getResidueIndex(const PAtom* atom);
00160 
00161 
00167   PAtom* getAtomAtRes(const string &atomID, int resNum);
00168 
00173   void setAtomColorAtRes(const string &atomID, int resNum, GLColor setColor) {
00174     getAtomAtRes(atomID,resNum)->setColor(setColor);
00175   }
00176 
00181   void revertAtomColorAtRes(const string &atomID, int resNum) {
00182     getAtomAtRes(atomID,resNum)->revertColor();
00183   }
00184 
00190   PAtom *getAtom(const string &blockType, int index);
00191   
00195   Vector3 getAtomPos(const string &blockType,int index);
00196 
00200   int NumAtoms(const string &blockType) const;
00201 
00206   bool InStaticCollision();
00207 
00213   bool InStaticCollision(int resIndex1, int resIndex2);
00214 
00219   bool InSelfCollision();
00220 
00226   bool InSelfCollision(int resIndex1, int resIndex2);
00227 
00232   bool InAnyCollision();
00233 
00239   bool InAnyCollision(int resIndex1, int resIndex2);
00240 
00246   pair<PAtom *, PAtom *> FindStaticCollision();
00247 
00253   pair<PAtom *, PAtom *> FindStaticCollision(int resIndex1, int resIndex2);
00254 
00260   pair<PAtom *, PAtom *> FindSelfCollision();
00261 
00267   pair<PAtom *, PAtom *> FindSelfCollision(int resIndex1, int resIndex2);
00268 
00274   pair<PAtom *, PAtom *> FindAnyCollision();
00275 
00281   pair<PAtom *, PAtom *> FindAnyCollision(int resIndex1, int resIndex2);
00282 
00287   AtomCollisions* getAllCollidingStatic();
00288 
00293   AtomCollisions* getAllCollidingStatic(int resIndex1, int resIndex2);
00294 
00299   AtomCollisions* getAllCollidingSelf();
00300 
00305   AtomCollisions* getAllCollidingSelf(int resIndex1, int resIndex2);
00306 
00311   AtomCollisions* getAllCollidingEither();
00312 
00317   AtomCollisions* getAllCollidingEither(int resIndex1, int resIndex2);
00318 
00324   vector<PBond *>& GetDOFs(const string &blockType);
00325   
00330   int NumDOF(const string &blockType) const;
00331   
00336   void RotateChain(const string &blockType,int DOFindex, BondDirection dir, float degrees);
00337 
00341   void RotateChain(const ChainMove &move);
00342 
00346   void MultiRotate(vector<ChainMove> &moves);
00347 
00351   void AntiMultiRotate(vector<ChainMove> &moves);
00352   
00356   vector<string> GetBlockTypes() const;
00357 
00361   void DetachBlocks(const string &blockType, const string &blockTypeToDetachFrom);
00362 
00367   void DetachBlocks(const string &blockType, const string &blockTypeToDetachFrom, int resStartIndex, int resEndIndex);
00368 
00372   void ReattachBlocks(const string &blockType);
00373 
00378   void ReattachBlocks(const string &blockType, int resStartIndex, int resEndIndex);
00379 
00383   void ReattachAllBlocks();  
00384 
00389   void ReattachAllBlocks(int resStartIndex, int resEndIndex);
00390 
00395   void RandomizeDOFs(BondDirection dir);
00396 
00402   void finalize();
00403 
00408   void AddRotateEventHandler(PRotateEventHandler *handler);
00409 
00414   void RemoveRotateEventHandler(PRotateEventHandler *handler);
00415 
00416 
00421   void traverseFromStart(AtomFunctor *atomFn) { traverseFromStart(atomFn, NULL); }
00422 
00427   void traverseFromStart(BondFunctor *bondFn) { traverseFromStart(NULL, bondFn); }
00428 
00434   void traverseFromStart(AtomFunctor *atomFn, BondFunctor *bondFn);
00435 
00443   pair<int, int> getTopLevelIndices() const;
00444   
00448   const PSpaceManager* getSpaceManager() { return m_grid; }
00449 
00457   PChain *Clone();
00458 
00463   int getResidueLocalIndex(PResidue *res);
00464 
00469   int getResidueGlobalIndex(PResidue *res);
00470 
00476   vector<const PAtom*> getShortestPath(const PAtom *a1, ConstAtomSet a2Set, int maxLength);
00477  
00483   vector<const PAtom*> getShortestPath(const PAtom *a1, const PAtom *a2, int maxLength);    
00484    
00490   vector<const PAtom*> getShortestPath(const PAtom *a1, ConstAtomSet a2Set, int maxLength, int extendNum);
00491 
00496   void inactivateResidue (int Rid1, int Rid2);
00497 
00502   void activateResidue (int Rid1, int Rid2);
00503 
00504  protected:
00505   void CloneResiduesIntoChain(PChain *other);
00506   virtual PResidue *CreateResidue(const string &name) { return new PResidue(this,name); }
00507   virtual PResidue *CreateResidue(const string &name, PResidueSpec &spec) { return new PResidue(this,name,spec); }
00508   virtual PResidue *CreateResidue(const string &name, PResidue *res) { return new PResidue(this,name,res); }
00509   virtual PResidue *CreateResidue(const string &name, PResidueSpec &spec, PResidue *res) { return new 
00510 PResidue(this,name,spec,res); }
00511 
00512  private:
00513   
00514   void UpdateIndexRangeOnAdd(int amtAdded);
00515   void InitChain();
00516   void CheckFinalized() const;
00517   vector<const PAtom*> extractPath(AtomNode* leaveNode); //post-process of getShortestPath
00518 
00519   bool m_isFinalized;
00520   vector<PResidue *> *m_residues;
00521   PGrid *m_grid;
00522 
00523   int m_startIndex;             /* Start index into the parent chain, if applicable. */
00524   int m_endIndex;               /* End index into the parent chain, if applicable. */
00525 
00526   PChain *m_parentChain;        /* Parent chain, or NULL if this is the whole chain. */
00527   list<PChain *> m_children;    /* List of children of this PChain. */
00528   list<PRotateEventHandler *> *m_rotationEvents;
00529 
00530   /* A bond's block type is the block type of the atom in the forward direction. */
00531 
00532   DOF_Cache m_dofs;             /* Map of block types to DOF's of that type. */
00533   Atom_Cache m_atomCache;
00534 
00535   /* Collision-detection helper methods. */
00536 
00537   bool InCollision(int resIndex1, int resIndex2, CollisionType type);
00538   pair<PAtom *, PAtom *> FindCollision(int resIndex1, int resIndex2, CollisionType type);
00539   AtomCollisions* getAllColliding(int resIndex1, int resIndex2, CollisionType type);
00540 
00541 };
00542 
00543 #endif  // __P_CHAIN_H

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