source: src/molecule.hpp@ b6d92e

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 b6d92e was a7aebd, checked in by Frederik Heber <heber@…>, 10 years ago

World removes empty molecules.

  • on destroyAtom() of molecule's last atom, destroyMolecule() is called.
  • FIX: destroyMolecule(molecule *) did use OBSERVE unncessarily. This caused seg'fault.
  • extracted removeAtomsinMolecule from molecule class. This is necessary since World will automatically remove empty molecules.
  • 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 NotificationType_MAX
116 };
117
118 //>! access to last changed element (atom)
119 const atom* lastChanged() const
120 { return _lastchangedatom; }
121
122public:
123 //getter and setter
124 const std::string getName() const;
125 int getAtomCount() const;
126 size_t doCountNoNonHydrogen() const;
127 size_t getNoNonHydrogen() const;
128 int getBondCount() const;
129 int doCountBonds() const;
130 moleculeId_t getId() const;
131 void setId(moleculeId_t);
132 void setName(const std::string);
133 const Formula &getFormula() const;
134 unsigned int getElementCount() const;
135 bool hasElement(const element*) const;
136 bool hasElement(atomicNumber_t) const;
137 bool hasElement(const std::string&) const;
138
139 virtual bool changeId(atomId_t newId);
140
141 World::AtomComposite getAtomSet() const;
142
143 // simply pass on all functions to AtomIdSet
144 iterator begin() {
145 return atomIds.begin();
146 }
147 const_iterator begin() const
148 {
149 return atomIds.begin();
150 }
151 iterator end()
152 {
153 return atomIds.end();
154 }
155 const_iterator end() const
156 {
157 return atomIds.end();
158 }
159 bool empty() const
160 {
161 return atomIds.empty();
162 }
163 size_t size() const
164 {
165 return atomIds.size();
166 }
167 const_iterator find(atom * key) const
168 {
169 return atomIds.find(key);
170 }
171
172 /** Returns the set of atomic ids contained in this molecule.
173 *
174 * @return set of atomic ids
175 */
176 const atomIdSet & getAtomIds() const {
177 return atomIds.getAtomIds();
178 }
179
180 std::pair<iterator, bool> insert(atom * const key);
181
182 /** Predicate whether given \a key is contained in this molecule.
183 *
184 * @param key atom to check
185 * @return true - is contained, false - else
186 */
187 bool containsAtom(const atom* key) const
188 {
189 return atomIds.contains(key);
190 }
191
192 /** Predicate whether given \a id is contained in this molecule.
193 *
194 * @param id atomic id to check
195 * @return true - is contained, false - else
196 */
197 bool containsAtom(const atomId_t id) const
198 {
199 return atomIds.contains(id);
200 }
201
202private:
203 friend void atom::removeFromMolecule();
204 /** Erase an atom from the list.
205 * \note This should only be called by atom::removeFromMolecule(),
206 * otherwise it is not assured that the atom knows about it.
207 *
208 * @param loc locator to atom in list
209 * @return iterator to just after removed item (compliant with standard)
210 */
211 const_iterator erase(const_iterator loc);
212
213 /** Erase an atom from the list.
214 * \note This should only be called by atom::removeFromMolecule(),
215 * otherwise it is not assured that the atom knows about it.
216 *
217 * @param *key key to atom in list
218 * @return iterator to just after removed item (compliant with standard)
219 */
220 const_iterator erase(atom * key);
221
222private:
223 friend bool atom::changeNr(int newId);
224 /**
225 * used when changing an ParticleInfo::Nr.
226 * Note that this number is local with this molecule.
227 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
228 *
229 * @param oldNr old Nr
230 * @param newNr new Nr to set
231 * @param *target ref to atom
232 * @return indicates wether the change could be done or not.
233 */
234 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
235
236 /** Updates the internal lookup fro local to global indices.
237 *
238 * \param pointer pointer to atom
239 */
240 void InsertLocalToGlobalId(atom * const pointer);
241
242 /** Sets the name of the atom.
243 *
244 * The name is set via its element symbol and its internal ParticleInfo::Nr.
245 *
246 * @param _atom atom whose name to set
247 */
248 void setAtomName(atom *_atom) const;
249
250public:
251
252 /** Function to create a bounding spherical shape for the currently associated atoms.
253 *
254 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
255 * and the shape's surface)
256 */
257 Shape getBoundingSphere(const double boundary = 0.) const;
258
259 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
260 *
261 * \param scale extra scale parameter to enlarge the spheres artifically
262 */
263 Shape getBoundingShape(const double scale = 1.) const;
264
265 /// remove atoms from molecule.
266 bool AddAtom(atom *pointer);
267 bool RemoveAtom(atom *pointer);
268 bool UnlinkAtom(atom *pointer);
269 bool CleanupMolecule();
270
271 /// Add/remove atoms to/from molecule.
272 atom * AddCopyAtom(atom *pointer);
273// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
274 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
275 bool hasBondStructure() const;
276
277 /// Find atoms.
278 atom * FindAtom(int Nr) const;
279 atom * AskAtom(std::string text);
280 bool isInMolecule(const atom * const _atom);
281
282 /// Count and change present atoms' coordination.
283 bool CenterInBox();
284 bool BoundInBox();
285 void CenterEdge();
286 void CenterOrigin();
287 void CenterPeriodic();
288 void CenterAtVector(const Vector &newcenter);
289 void Translate(const Vector &x);
290 void TranslatePeriodically(const Vector &trans);
291 void Mirror(const Vector &x);
292 void Align(const Vector &n);
293 void Scale(const double *factor);
294 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
295 const Vector DetermineCenterOfGravity() const;
296 const Vector DetermineCenterOfAll() const;
297 void SetNameFromFilename(const char *filename);
298 bool ScanForPeriodicCorrection();
299 double VolumeOfConvexEnvelope(bool IsAngstroem);
300 RealSpaceMatrix getInertiaTensor() const;
301 void RotateToPrincipalAxisSystem(const Vector &Axis);
302
303 bool CheckBounds(const Vector *x) const;
304 void GetAlignvector(struct lsq_params * par) const;
305
306 /// Initialising routines in fragmentation
307 void OutputBondsList() const;
308
309 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
310
311 molecule *CopyMolecule(const Vector &offset = zeroVec) const;
312 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
313
314 /// Fragment molecule by two different approaches:
315 bool StoreBondsToFile(std::string filename, std::string path = "");
316 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
317
318 // Recognize doubly appearing molecules in a list of them
319 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
320 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
321 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
322
323 // Output routines.
324 bool Output(std::ostream * const output) const;
325 void OutputListOfBonds() const;
326
327 // Manipulation routines
328 void flipActiveFlag();
329
330 virtual void update(Observable *publisher);
331 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
332 virtual void subjectKilled(Observable *publisher);
333
334private:
335 friend const atom *detail::lastChanged<atom>();
336 atom *_lastchangedatom;
337
338 int last_atom; //!< number given to last atom
339};
340
341molecule *NewMolecule();
342void DeleteMolecule(molecule* mol);
343
344
345
346#endif /*MOLECULES_HPP_*/
347
Note: See TracBrowser for help on using the repository browser.