PGrid.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_GRID_H
00021 #define __P_GRID_H
00022 
00023 #include "PEnums.h"
00024 #include "PSpaceManager.h"
00025 // @package Grid
00033 typedef bool(*CollisionMetric)(const PAtom *, const PAtom *);
00034 
00035 class PGrid: public PSpaceManager {
00036  public:
00037   friend class PAtom;
00038   friend class PAtomShell;
00039   friend class PChain;
00040 
00044   static const int BOND_THRESHOLD = 3;
00045 
00049   Real getSideLength() const { return m_sideLength; }
00050 
00054   void setSideLength(int newVal);
00055 
00060   list<PAtom *> AtomsNearPoint(const Vector3& point, Real distance) const;
00061 
00062   pair<Vector3, Vector3> getCellBoundingBox(const Vector3 &pos) const;
00063   pair<Vector3, Vector3> getGlobalBoundingBox() const;
00064   OccupancyMap getOccupancy() const;
00065   static int getOccupancyNeighborNumber(const pair<Vector3, Vector3> &bound, OccupancyMap &occupancy, Vector3 pt);
00066 
00067  private:
00068   
00069   PGrid();
00070   
00071   /* Private side length helper methods. */
00072   static void updateSide(Real atomRadius);
00073   void updateDelta() { m_delta = int(ceil(double(m_defaultSideLength) / double(m_sideLength))); }
00074   
00075   /* Methods to add or remove atoms from the grid. */
00076   void addAtom(PAtom *atom);
00077   void removeAtom(PAtom *atom);
00078 
00079   /* Internal collision detection methods. */
00080   PAtom* getStaticCollidingAtom(const PAtom* atom) const;
00081   PAtom* getSelfCollidingAtom(const PAtom *atom) const;
00082   PAtom* getAnyCollidingAtom(const PAtom *atom) const;
00083 
00084   AtomSet* getAllCollidingStatic(const PAtom *atom) const;
00085   AtomSet* getAllCollidingSelf(const PAtom *atom) const;
00086   AtomSet* getAllCollidingEither(const PAtom *atom) const;
00087 
00088   AtomSet* findColliding(const PAtom *atom,
00089                          bool getOnlyOne,
00090                          CollisionType type,
00091                          CollisionMetric inCollision = vanDerWaalsCollision) const;
00092 
00093   bool InStaticCollision(const PAtom *atom) const;
00094   bool InSelfCollision(const PAtom *atom) const;
00095   bool InAnyCollision(const PAtom *atom) const;
00096 
00097   Vector3 scaleToGrid(const Vector3 &pos) const;
00098 
00099   /* Collision metrics. */
00100   static bool covalentCollision(const PAtom *a1, const PAtom *a2);
00101   static bool vanDerWaalsCollision(const PAtom *a1, const PAtom *a2);
00102   static bool atomsBonded(const PAtom *a1, const PAtom *a2);
00103 
00104   /* Private member variables. */
00105   static int m_defaultSideLength;   /* Default side length for new PGrids.    */
00106   int m_sideLength;                 /* Grid cell side length for THIS PGrid.  */
00107 
00108   int m_delta;                      /* How many cells in each x, y, z direction */
00109                                     /* to search for atom collisions; equal to  */
00110                                     /* ceil(m_defaultSideLength / m_sideLength. */
00111 
00112   CollisionMap m_collisionGrid;     /* The hash_map at the core of the PGrid. */
00113 
00114 };
00115 
00116 #endif  // __P_GRID_H

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