| 1 | /* | 
|---|
| 2 | * UndoRedoHelpers.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Apr 5, 2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef UNDOREDOHELPERS_HPP_ | 
|---|
| 9 | #define UNDOREDOHELPERS_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | // include config.h | 
|---|
| 13 | #ifdef HAVE_CONFIG_H | 
|---|
| 14 | #include <config.h> | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 | #include <vector> | 
|---|
| 18 |  | 
|---|
| 19 | #include "Atom/AtomicInfo.hpp" | 
|---|
| 20 | #include "Bond/BondInfo.hpp" | 
|---|
| 21 | #include "WorldTime.hpp" | 
|---|
| 22 |  | 
|---|
| 23 | namespace MoleCuilder { | 
|---|
| 24 |  | 
|---|
| 25 | /** Adds removed atoms back to the world whose state is stored as AtomicInfo. | 
|---|
| 26 | * | 
|---|
| 27 | * @param atoms vector of atomicInfo | 
|---|
| 28 | * @return restoral was successful, at least atom could not be restored. | 
|---|
| 29 | */ | 
|---|
| 30 | bool AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms); | 
|---|
| 31 |  | 
|---|
| 32 | /** Adds removed molecules with their atoms back to the world. | 
|---|
| 33 | * | 
|---|
| 34 | * @param mol_atoms map of molecules with ids and their atoms as AtomicInfo | 
|---|
| 35 | * \return true - restoral was successful, at least one atom or molecule could not be restored | 
|---|
| 36 | */ | 
|---|
| 37 | bool AddMoleculesFromAtomicInfo(std::map< moleculeId_t, std::vector<AtomicInfo> > &mol_atoms); | 
|---|
| 38 |  | 
|---|
| 39 | /** Removes atoms whose state information is stored as AtomicInfo. | 
|---|
| 40 | * | 
|---|
| 41 | * @param atoms vector of atomicInfo | 
|---|
| 42 | */ | 
|---|
| 43 | void RemoveAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms); | 
|---|
| 44 |  | 
|---|
| 45 | /** Stores the required bond information in for all \a atoms in \a bonds. | 
|---|
| 46 | * | 
|---|
| 47 | * @param atoms atoms whose bonds to store | 
|---|
| 48 | * @param bonds vector with bond information on return | 
|---|
| 49 | */ | 
|---|
| 50 | void StoreBondInformationFromAtoms( | 
|---|
| 51 | const std::vector<const atom*> &atoms, | 
|---|
| 52 | std::vector<BondInfo> &bonds); | 
|---|
| 53 |  | 
|---|
| 54 | /** Recreates bonds from information stored in \a bonds. | 
|---|
| 55 | * | 
|---|
| 56 | * @param bonds bond state information | 
|---|
| 57 | * @return true - all bonds restored, false - at least one bond could not be restored | 
|---|
| 58 | */ | 
|---|
| 59 | bool AddBondsFromBondInfo(const std::vector< BondInfo > &bonds); | 
|---|
| 60 |  | 
|---|
| 61 | /** Sets atoms to state information stored as AtomicInfo. | 
|---|
| 62 | * | 
|---|
| 63 | * @param movedatoms vector of atomicInfo | 
|---|
| 64 | * @param _step set state information for given world time | 
|---|
| 65 | */ | 
|---|
| 66 | void SetAtomsFromAtomicInfo( | 
|---|
| 67 | const std::vector<AtomicInfo> &_movedatoms, | 
|---|
| 68 | const unsigned int _step = WorldTime::getTime()); | 
|---|
| 69 |  | 
|---|
| 70 | /** Selects all atoms inside the given vector | 
|---|
| 71 | * | 
|---|
| 72 | * @param movedatoms vector of atomicInfo | 
|---|
| 73 | */ | 
|---|
| 74 | void SelectAtomsFromAtomicInfo(const std::vector<AtomicInfo> &_movedatoms); | 
|---|
| 75 |  | 
|---|
| 76 | /** Helper function to allow setting arbitrary atom vectorial information via some | 
|---|
| 77 | * \a setter function. | 
|---|
| 78 | * | 
|---|
| 79 | * @param movedatoms atoms whose info to change | 
|---|
| 80 | * @param MovedToVector vector with old vectorial information | 
|---|
| 81 | */ | 
|---|
| 82 | void ResetByFunction( | 
|---|
| 83 | const std::vector<AtomicInfo> &movedatoms, | 
|---|
| 84 | const std::vector<Vector> &MovedToVector, | 
|---|
| 85 | boost::function<void(atom *, const Vector&)> &setter); | 
|---|
| 86 |  | 
|---|
| 87 | /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms | 
|---|
| 88 | *  to position in \a MovedToVector. | 
|---|
| 89 | * | 
|---|
| 90 | * @param movedatoms atoms whose position to change | 
|---|
| 91 | * @param MovedToVector vector with old positions | 
|---|
| 92 | */ | 
|---|
| 93 | void ResetAtomPosition(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &MovedToVector); | 
|---|
| 94 |  | 
|---|
| 95 | /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms | 
|---|
| 96 | *  to position in \a MovedToVector. | 
|---|
| 97 | * | 
|---|
| 98 | * @param movedatoms atoms whose position to change | 
|---|
| 99 | * @param VelocityVector vector with old velocities | 
|---|
| 100 | */ | 
|---|
| 101 | void ResetAtomVelocity(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &VelocityVector); | 
|---|
| 102 |  | 
|---|
| 103 | /** Sets the atoms whose id is stored in given AtomicInfo in \a movedatoms | 
|---|
| 104 | *  to position in \a MovedToVector. | 
|---|
| 105 | * | 
|---|
| 106 | * @param movedatoms atoms whose position to change | 
|---|
| 107 | * @param ForceVector vector with old forces | 
|---|
| 108 | */ | 
|---|
| 109 | void ResetAtomForce(const std::vector<AtomicInfo> &movedatoms, const std::vector<Vector> &ForceVector); | 
|---|
| 110 |  | 
|---|
| 111 | /** Remove all molecules identified by their ids given in \a ids. | 
|---|
| 112 | * | 
|---|
| 113 | * @param ids vector of molecular ids to remove | 
|---|
| 114 | */ | 
|---|
| 115 | void RemoveMoleculesWithAtomsByIds(const std::vector<moleculeId_t> &ids); | 
|---|
| 116 |  | 
|---|
| 117 | /** Removes the time steps in given interval for all \a movedatoms. | 
|---|
| 118 | * | 
|---|
| 119 | * @param movedatoms atoms whose steps in [\a _firststep, \a _laststep] in time to remove | 
|---|
| 120 | * @param _firststep first step in interval to be removed | 
|---|
| 121 | * @param _laststep last step in interval to be removed | 
|---|
| 122 | */ | 
|---|
| 123 | void removeSteps( | 
|---|
| 124 | const std::vector<atomId_t> &movedatoms, | 
|---|
| 125 | const unsigned int _firststep, | 
|---|
| 126 | const unsigned int _laststep); | 
|---|
| 127 |  | 
|---|
| 128 | /** Adds another time step to all \a movedatoms. | 
|---|
| 129 | * | 
|---|
| 130 | * Note that the time step is initialized to zero. | 
|---|
| 131 | * | 
|---|
| 132 | * @param _ids atoms whose last step in time to remove | 
|---|
| 133 | * @param _step which trajectory to insert/assign | 
|---|
| 134 | */ | 
|---|
| 135 | void addNewStep(const std::vector<atomId_t> &_ids, const unsigned int _step); | 
|---|
| 136 |  | 
|---|
| 137 | /** Adds another time step to all \a movedatoms. | 
|---|
| 138 | * | 
|---|
| 139 | * Note that the time step is initialized to zero. This gives you a chance | 
|---|
| 140 | * to set the time step and call setAtomsFromAtomicInfo() yourself. | 
|---|
| 141 | * | 
|---|
| 142 | * @param _movedatoms atoms whose last step in time to remove | 
|---|
| 143 | * @param _step which trajectory to insert/assign | 
|---|
| 144 | */ | 
|---|
| 145 | void addNewStep(const std::vector<AtomicInfo> &_movedatoms, const unsigned int _step); | 
|---|
| 146 |  | 
|---|
| 147 | /** Helper function to extract id information from vector of AtomicInfo. | 
|---|
| 148 | * | 
|---|
| 149 | * @param movedatoms atoms whose ids to extract | 
|---|
| 150 | */ | 
|---|
| 151 | std::vector<atomId_t> getIdsFromAtomicInfo(const std::vector<AtomicInfo> &movedatoms); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 |  | 
|---|
| 156 | #endif /* UNDOREDOHELPERS_HPP_ */ | 
|---|