source: src/molecule.hpp@ fae462

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since fae462 was 24edfe, checked in by Frederik Heber <heber@…>, 10 years ago

Added AboutToBeRemoved channel to molecule.

  • this allows UI elements to remove all items related a molecule's presence before any destructor has started doing something. Note that subjectKilled() does not work here, as "higher" (in inheritance hierarchy) have already been called and changed the instance. We need to know right when the instance is still intact.
  • Property mode set to 100755
File size: 10.0 KB
Line 
1/** \file molecule.hpp
2 *
3 * Class definitions of atom and molecule, element and periodentafel
4 */
5
6#ifndef MOLECULES_HPP_
7#define MOLECULES_HPP_
8
9/*********************************************** includes ***********************************/
10
11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
15//// STL headers
16#include <map>
17#include <set>
18#include <stack>
19#include <deque>
20#include <list>
21#include <vector>
22
23#include <string>
24
25#include "AtomIdSet.hpp"
26#include "Atom/AtomSet.hpp"
27#include "CodePatterns/Cacheable.hpp"
28#include "CodePatterns/Observer/Observable.hpp"
29#include "Descriptors/AtomIdDescriptor.hpp"
30#include "Fragmentation/HydrogenSaturation_enum.hpp"
31#include "Formula.hpp"
32#include "Helpers/defs.hpp"
33#include "IdPool_policy.hpp"
34#include "IdPool.hpp"
35#include "Shapes/Shape.hpp"
36#include "types.hpp"
37
38/****************************************** forward declarations *****************************/
39
40class atom;
41class bond;
42class BondedParticle;
43class BondGraph;
44class DepthFirstSearchAnalysis;
45class element;
46class ForceMatrix;
47class Graph;
48class LinkedCell_deprecated;
49class ListOfLocalAtoms_t;
50class molecule;
51class MoleculeLeafClass;
52class MoleculeListClass;
53class MoleculeUnittest;
54class RealSpaceMatrix;
55class Vector;
56
57/************************************* Class definitions ****************************************/
58
59/** External function to remove all atoms since this will also delete the molecule
60 *
61 * \param _mol ref pointer to molecule to destroy
62 */
63void removeAtomsinMolecule(molecule *&_mol);
64
65/** The complete molecule.
66 * Class incorporates number of types
67 */
68class molecule : public Observable
69{
70 //!> grant unit test access
71 friend class MoleculeUnittest;
72 //!> function may access cstor
73 friend molecule *NewMolecule();
74 //!> function may access dstor
75 friend void DeleteMolecule(molecule *);
76
77public:
78 typedef AtomIdSet::atomIdSet atomIdSet;
79 typedef AtomIdSet::iterator iterator;
80 typedef AtomIdSet::const_iterator const_iterator;
81
82 int MDSteps; //!< The number of MD steps in Trajectories
83 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
84 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
85 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
86 int IndexNr; //!< index of molecule in a MoleculeListClass
87 char name[MAXSTRINGSIZE]; //!< arbitrary name
88
89private:
90 Formula formula;
91 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
92 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
93 moleculeId_t id;
94 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
95 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
96 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
97 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
98
99protected:
100
101 molecule();
102 virtual ~molecule();
103
104public:
105
106 /******* Notifications *******/
107
108 //!> enumeration of present notification types: only insertion/removal of atoms or molecules
109 enum NotificationType {
110 AtomInserted,
111 AtomRemoved,
112 AtomNrChanged,
113 AtomMoved,
114 MoleculeNameChanged,
115 AboutToBeRemoved,
116 NotificationType_MAX
117 };
118
119 //>! access to last changed element (atom)
120 const atom* lastChanged() const
121 { return _lastchangedatom; }
122
123public:
124 //getter and setter
125 const std::string getName() const;
126 int getAtomCount() const;
127 size_t doCountNoNonHydrogen() const;
128 size_t getNoNonHydrogen() const;
129 int getBondCount() const;
130 int doCountBonds() const;
131 moleculeId_t getId() const;
132 void setId(moleculeId_t);
133 void setName(const std::string);
134 const Formula &getFormula() const;
135 unsigned int getElementCount() const;
136 bool hasElement(const element*) const;
137 bool hasElement(atomicNumber_t) const;
138 bool hasElement(const std::string&) const;
139
140 virtual bool changeId(atomId_t newId);
141
142 World::AtomComposite getAtomSet() const;
143
144 // simply pass on all functions to AtomIdSet
145 iterator begin() {
146 return atomIds.begin();
147 }
148 const_iterator begin() const
149 {
150 return atomIds.begin();
151 }
152 iterator end()
153 {
154 return atomIds.end();
155 }
156 const_iterator end() const
157 {
158 return atomIds.end();
159 }
160 bool empty() const
161 {
162 return atomIds.empty();
163 }
164 size_t size() const
165 {
166 return atomIds.size();
167 }
168 const_iterator find(atom * key) const
169 {
170 return atomIds.find(key);
171 }
172
173 /** Returns the set of atomic ids contained in this molecule.
174 *
175 * @return set of atomic ids
176 */
177 const atomIdSet & getAtomIds() const {
178 return atomIds.getAtomIds();
179 }
180
181 std::pair<iterator, bool> insert(atom * const key);
182
183 /** Predicate whether given \a key is contained in this molecule.
184 *
185 * @param key atom to check
186 * @return true - is contained, false - else
187 */
188 bool containsAtom(const atom* key) const
189 {
190 return atomIds.contains(key);
191 }
192
193 /** Predicate whether given \a id is contained in this molecule.
194 *
195 * @param id atomic id to check
196 * @return true - is contained, false - else
197 */
198 bool containsAtom(const atomId_t id) const
199 {
200 return atomIds.contains(id);
201 }
202
203private:
204 friend void atom::removeFromMolecule();
205 /** Erase an atom from the list.
206 * \note This should only be called by atom::removeFromMolecule(),
207 * otherwise it is not assured that the atom knows about it.
208 *
209 * @param loc locator to atom in list
210 * @return iterator to just after removed item (compliant with standard)
211 */
212 const_iterator erase(const_iterator loc);
213
214 /** Erase an atom from the list.
215 * \note This should only be called by atom::removeFromMolecule(),
216 * otherwise it is not assured that the atom knows about it.
217 *
218 * @param *key key to atom in list
219 * @return iterator to just after removed item (compliant with standard)
220 */
221 const_iterator erase(atom * key);
222
223private:
224 friend bool atom::changeNr(int newId);
225 /**
226 * used when changing an ParticleInfo::Nr.
227 * Note that this number is local with this molecule.
228 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
229 *
230 * @param oldNr old Nr
231 * @param newNr new Nr to set
232 * @param *target ref to atom
233 * @return indicates wether the change could be done or not.
234 */
235 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
236
237 /** Updates the internal lookup fro local to global indices.
238 *
239 * \param pointer pointer to atom
240 */
241 void InsertLocalToGlobalId(atom * const pointer);
242
243 /** Sets the name of the atom.
244 *
245 * The name is set via its element symbol and its internal ParticleInfo::Nr.
246 *
247 * @param _atom atom whose name to set
248 */
249 void setAtomName(atom *_atom) const;
250
251public:
252
253 /** Function to create a bounding spherical shape for the currently associated atoms.
254 *
255 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
256 * and the shape's surface)
257 */
258 Shape getBoundingSphere(const double boundary = 0.) const;
259
260 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
261 *
262 * \param scale extra scale parameter to enlarge the spheres artifically
263 */
264 Shape getBoundingShape(const double scale = 1.) const;
265
266 /// remove atoms from molecule.
267 bool AddAtom(atom *pointer);
268 bool RemoveAtom(atom *pointer);
269 bool UnlinkAtom(atom *pointer);
270 bool CleanupMolecule();
271
272 /// Add/remove atoms to/from molecule.
273 atom * AddCopyAtom(atom *pointer);
274// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
275 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
276 bool hasBondStructure() const;
277
278 /// Find atoms.
279 atom * FindAtom(int Nr) const;
280 atom * AskAtom(std::string text);
281 bool isInMolecule(const atom * const _atom);
282
283 /// Count and change present atoms' coordination.
284 bool CenterInBox();
285 bool BoundInBox();
286 void CenterEdge();
287 void CenterOrigin();
288 void CenterPeriodic();
289 void CenterAtVector(const Vector &newcenter);
290 void Translate(const Vector &x);
291 void TranslatePeriodically(const Vector &trans);
292 void Mirror(const Vector &x);
293 void Align(const Vector &n);
294 void Scale(const double *factor);
295 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
296 const Vector DetermineCenterOfGravity() const;
297 const Vector DetermineCenterOfAll() const;
298 void SetNameFromFilename(const char *filename);
299 bool ScanForPeriodicCorrection();
300 double VolumeOfConvexEnvelope(bool IsAngstroem);
301 RealSpaceMatrix getInertiaTensor() const;
302 void RotateToPrincipalAxisSystem(const Vector &Axis);
303
304 bool CheckBounds(const Vector *x) const;
305 void GetAlignvector(struct lsq_params * par) const;
306
307 /// Initialising routines in fragmentation
308 void OutputBondsList() const;
309
310 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
311
312 molecule *CopyMolecule(const Vector &offset = zeroVec) const;
313 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
314
315 /// Fragment molecule by two different approaches:
316 bool StoreBondsToFile(std::string filename, std::string path = "");
317 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
318
319 // Recognize doubly appearing molecules in a list of them
320 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
321 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
322 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
323
324 // Output routines.
325 bool Output(std::ostream * const output) const;
326 void OutputListOfBonds() const;
327
328 // Manipulation routines
329 void flipActiveFlag();
330
331 virtual void update(Observable *publisher);
332 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
333 virtual void subjectKilled(Observable *publisher);
334
335private:
336 friend const atom *detail::lastChanged<atom>();
337 atom *_lastchangedatom;
338
339 int last_atom; //!< number given to last atom
340};
341
342molecule *NewMolecule();
343void DeleteMolecule(molecule* mol);
344
345
346
347#endif /*MOLECULES_HPP_*/
348
Note: See TracBrowser for help on using the repository browser.