| [57dd40] | 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" | 
|---|
| [af9be32] | 20 | #include "Bond/BondInfo.hpp" | 
|---|
| [6145577] | 21 | #include "WorldTime.hpp" | 
|---|
| [57dd40] | 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 | */ | 
|---|
| [596cfa] | 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); | 
|---|
| [57dd40] | 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 |  | 
|---|
| [af9be32] | 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 |  | 
|---|
| [57dd40] | 61 | /** Sets atoms to state information stored as AtomicInfo. | 
|---|
|  | 62 | * | 
|---|
|  | 63 | * @param movedatoms vector of atomicInfo | 
|---|
| [6145577] | 64 | * @param _step set state information for given world time | 
|---|
| [57dd40] | 65 | */ | 
|---|
| [6145577] | 66 | void SetAtomsFromAtomicInfo( | 
|---|
|  | 67 | const std::vector<AtomicInfo> &_movedatoms, | 
|---|
|  | 68 | const unsigned int _step = WorldTime::getTime()); | 
|---|
| [57dd40] | 69 |  | 
|---|
|  | 70 | /** Selects all atoms inside the given vector | 
|---|
|  | 71 | * | 
|---|
|  | 72 | * @param movedatoms vector of atomicInfo | 
|---|
|  | 73 | */ | 
|---|
| [7e51e1] | 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); | 
|---|
| [57dd40] | 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); | 
|---|
| [8ea3e7] | 94 |  | 
|---|
| [7e51e1] | 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 |  | 
|---|
| [8ea3e7] | 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); | 
|---|
| [7e51e1] | 116 |  | 
|---|
| [8c6b68] | 117 | /** Removes the time steps in given interval for all \a movedatoms. | 
|---|
| [7e51e1] | 118 | * | 
|---|
| [8c6b68] | 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 | 
|---|
| [7e51e1] | 122 | */ | 
|---|
| [8c6b68] | 123 | void removeSteps( | 
|---|
|  | 124 | const std::vector<atomId_t> &movedatoms, | 
|---|
|  | 125 | const unsigned int _firststep, | 
|---|
|  | 126 | const unsigned int _laststep); | 
|---|
| [7e51e1] | 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 | 
|---|
| [8cc22f] | 133 | * @param _step which trajectory to insert/assign | 
|---|
| [7e51e1] | 134 | */ | 
|---|
| [8cc22f] | 135 | void addNewStep(const std::vector<atomId_t> &_ids, const unsigned int _step); | 
|---|
| [7e51e1] | 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 | 
|---|
| [8cc22f] | 143 | * @param _step which trajectory to insert/assign | 
|---|
| [7e51e1] | 144 | */ | 
|---|
| [8cc22f] | 145 | void addNewStep(const std::vector<AtomicInfo> &_movedatoms, const unsigned int _step); | 
|---|
| [7e51e1] | 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); | 
|---|
| [57dd40] | 152 | } | 
|---|
|  | 153 |  | 
|---|
|  | 154 |  | 
|---|
|  | 155 |  | 
|---|
|  | 156 | #endif /* UNDOREDOHELPERS_HPP_ */ | 
|---|