00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __P_GRID_H
00021 #define __P_GRID_H
00022
00023 #include "PEnums.h"
00024 #include "PSpaceManager.h"
00025
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
00072 static void updateSide(Real atomRadius);
00073 void updateDelta() { m_delta = int(ceil(double(m_defaultSideLength) / double(m_sideLength))); }
00074
00075
00076 void addAtom(PAtom *atom);
00077 void removeAtom(PAtom *atom);
00078
00079
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
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
00105 static int m_defaultSideLength;
00106 int m_sideLength;
00107
00108 int m_delta;
00109
00110
00111
00112 CollisionMap m_collisionGrid;
00113
00114 };
00115
00116 #endif // __P_GRID_H