| 1 | // -*- Mode: C++; tab-width: 2; -*- |
| 2 | // vi: set ts=2: |
| 3 | // |
| 4 | // $Id: atomVector.h,v 1.24.20.1 2007/05/18 12:02:43 oliver Exp $ |
| 5 | // |
| 6 | |
| 7 | #ifndef BALL_MOLMEC_COMMON_ATOMVECTOR_H |
| 8 | #define BALL_MOLMEC_COMMON_ATOMVECTOR_H |
| 9 | |
| 10 | #ifndef BALL_COMMON_H |
| 11 | # include <BALL/common.h> |
| 12 | #endif |
| 13 | |
| 14 | #ifndef BALL_MATHS_VECTOR3_H |
| 15 | # include <BALL/MATHS/vector3.h> |
| 16 | #endif |
| 17 | |
| 18 | namespace BALL |
| 19 | { |
| 20 | class Gradient; |
| 21 | class Atom; |
| 22 | class Composite; |
| 23 | |
| 24 | /** Atom vector class. |
| 25 | This class is used to store atom pointers. \par |
| 26 | |
| 27 | \ingroup MolmecCommon |
| 28 | */ |
| 29 | class BALL_EXPORT AtomVector |
| 30 | : private std::vector<Atom*> |
| 31 | { |
| 32 | public: |
| 33 | |
| 34 | BALL_CREATE_DEEP(AtomVector) |
| 35 | |
| 36 | /** @name Type definitions |
| 37 | */ |
| 38 | //@{ |
| 39 | |
| 40 | /** Iterator type |
| 41 | */ |
| 42 | typedef std::vector<Atom*>::iterator Iterator; |
| 43 | |
| 44 | /** Const iterator type. |
| 45 | */ |
| 46 | typedef std::vector<Atom*>::const_iterator ConstIterator; |
| 47 | |
| 48 | //@} |
| 49 | /** @name Constructors and Destructors |
| 50 | */ |
| 51 | //@{ |
| 52 | |
| 53 | /** Default constructor. |
| 54 | */ |
| 55 | AtomVector(); |
| 56 | |
| 57 | /** Construct from a Composite. |
| 58 | This method constructs an AtomVector from a given composite |
| 59 | using selection or not. |
| 60 | @param composite the composite containing the atoms |
| 61 | @param selected_only store the selected atoms only (if <b>true</b>) |
| 62 | */ |
| 63 | AtomVector(const Composite& composite, bool selected_only = false); |
| 64 | |
| 65 | /** Copy constructor |
| 66 | */ |
| 67 | AtomVector(const AtomVector& atoms, bool deep = true); |
| 68 | |
| 69 | /** Destructor. |
| 70 | */ |
| 71 | virtual ~AtomVector(); |
| 72 | |
| 73 | /** Clear the vector. |
| 74 | Removes all atoms from the vector |
| 75 | */ |
| 76 | using std::vector<Atom*>::clear; |
| 77 | //@} |
| 78 | |
| 79 | /** @name Assignments |
| 80 | */ |
| 81 | //@{ |
| 82 | |
| 83 | /** Assignment operator |
| 84 | */ |
| 85 | const AtomVector& operator = (const AtomVector& rhs); |
| 86 | |
| 87 | /** Assign from another atom vector |
| 88 | */ |
| 89 | void set(const AtomVector& atoms); |
| 90 | |
| 91 | /** Assignment operator for Composites. |
| 92 | Calls set() and extracts all atoms, if none of the atoms in |
| 93 | <tt>composite</tt> are selected or the selected atoms only |
| 94 | (if any atom is selected in <tt>composite</tt>. |
| 95 | @see Selectable |
| 96 | */ |
| 97 | const AtomVector& operator = (const Composite& rhs); |
| 98 | |
| 99 | /** Assign from a composite. |
| 100 | This method iterates over the composite tree and extracts all atoms. |
| 101 | @param selected_only extract only selected atoms if set to <b>true</b> |
| 102 | */ |
| 103 | void set(const Composite& composite, bool selected_only = false); |
| 104 | |
| 105 | //@} |
| 106 | /** @name Accessors |
| 107 | */ |
| 108 | //@{ |
| 109 | |
| 110 | /** Return the vector size; |
| 111 | */ |
| 112 | using std::vector<Atom*>::size; |
| 113 | |
| 114 | /// Random access operator |
| 115 | Atom* & operator [] (int i) { return std::vector<Atom*>::operator [] (i); } |
| 116 | Atom* const & operator [] (int i) const { return std::vector<Atom*>::operator [] (i); } |
| 117 | |
| 118 | /** Store the current atom positions. |
| 119 | AtomVector also contains an array with positions for each atom. |
| 120 | moveTo() considers these coordinates as start coordinates. |
| 121 | */ |
| 122 | void savePositions(); |
| 123 | |
| 124 | /** Resets the atom positions to the saved positions. |
| 125 | If coordinates weres stored using savePositions() , the atoms |
| 126 | coordinates are reset to the saved positions. |
| 127 | If no savedPositions exist the coordinates remain unchanged. |
| 128 | */ |
| 129 | void resetPositions(); |
| 130 | |
| 131 | /** Move all atoms along a direction vector. |
| 132 | The method translates all atoms a long a given direction. |
| 133 | The direction vector is multiplied with a step length <tt>step</tt>. |
| 134 | If a saved position exists ( savePositions() ), it is used as a start |
| 135 | position (i.e. the final positions are $\vec{\mathrm{start}} + \mathrm{step} \vec{\mathrm{direction}}$). |
| 136 | Otherwise, the current atom positions are used. |
| 137 | If the gradient's size differs from the number of atoms, nothing is done. |
| 138 | */ |
| 139 | void moveTo(const Gradient& direction, double step = 1.0); |
| 140 | |
| 141 | /** Move the first k atoms along a direction vector. |
| 142 | The method translates all atoms a long a given direction. |
| 143 | The direction vector is multiplied with a step length <tt>step</tt>. |
| 144 | If a saved position exists ( savePositions() ), it is used as a start |
| 145 | position (i.e. the final positions are $\vec{\mathrm{start}} + \mathrm{step} \vec{\mathrm{direction}}$). |
| 146 | Otherwise, the current atom positions are used. |
| 147 | If the gradient's size differs from the number of atoms, nothing is done. |
| 148 | */ |
| 149 | void moveTo(const Gradient& direction, double step, Size k); |
| 150 | |
| 151 | /** Insert an atom pointer. |
| 152 | */ |
| 153 | using std::vector<Atom*>::push_back; |
| 154 | |
| 155 | /** Resize the vector. |
| 156 | * If the vector is resized to to more elements, than are contained, |
| 157 | * it is filled with NullPointers. |
| 158 | */ |
| 159 | void resize(Size new_size); |
| 160 | |
| 161 | //@} |
| 162 | /** @name Iteration |
| 163 | */ |
| 164 | //@{ |
| 165 | |
| 166 | /** Return an iterator, pointing to the first atom pointer. |
| 167 | */ |
| 168 | //?????: GCC3 using std::vector<Atom*>::begin; |
| 169 | iterator begin() { return std::vector<Atom*>::begin(); } |
| 170 | const_iterator begin() const { return std::vector<Atom*>::begin(); } |
| 171 | |
| 172 | /** Return an iterator, pointing behind the last atom pointer. |
| 173 | */ |
| 174 | //?????: GCC3 using std::vector<Atom*>::end; |
| 175 | iterator end() { return std::vector<Atom*>::end(); } |
| 176 | const_iterator end() const { return std::vector<Atom*>::end(); } |
| 177 | |
| 178 | //@} |
| 179 | |
| 180 | protected: |
| 181 | |
| 182 | /*_ The saved positions. |
| 183 | */ |
| 184 | std::vector<Vector3> saved_position_; |
| 185 | }; |
| 186 | } // end of namespace BALL |
| 187 | |
| 188 | #endif // BALL_MOLMEC_MINIMIZATION_GRADIENT_H |