source: src/molecule.hpp@ c0f2fc

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

atom now uses associate... and disassociatedAtomWithMolecule().

  • this is used to gather all functions that need to be called when a new atom joins a molecule such as signing on to certain channels or updating certain internal values of the molecule.
  • Property mode set to 100755
File size: 14.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 <boost/bimap/bimap.hpp>
26#include <boost/bimap/unordered_set_of.hpp>
27#include <boost/bimap/multiset_of.hpp>
28#include <boost/optional.hpp>
29#include <boost/shared_ptr.hpp>
30
31#include "AtomIdSet.hpp"
32#include "Atom/AtomSet.hpp"
33#include "CodePatterns/Cacheable.hpp"
34#include "CodePatterns/Observer/Observable.hpp"
35#include "Descriptors/AtomIdDescriptor.hpp"
36#include "Fragmentation/HydrogenSaturation_enum.hpp"
37#include "Formula.hpp"
38#include "Helpers/defs.hpp"
39#include "IdPool_policy.hpp"
40#include "IdPool.hpp"
41#include "Shapes/Shape.hpp"
42#include "types.hpp"
43
44/****************************************** forward declarations *****************************/
45
46class atom;
47class bond;
48class BondedParticle;
49class BondGraph;
50class DepthFirstSearchAnalysis;
51class element;
52class ForceMatrix;
53class Graph;
54class LinkedCell_deprecated;
55class ListOfLocalAtoms_t;
56class molecule;
57class MoleculeLeafClass;
58class MoleculeUnittest;
59class RealSpaceMatrix;
60class Vector;
61
62/************************************* Class definitions ****************************************/
63
64/** External function to remove all atoms since this will also delete the molecule
65 *
66 * \param _mol ref pointer to molecule to destroy
67 */
68void removeAtomsinMolecule(molecule *&_mol);
69
70/** The complete molecule.
71 * Class incorporates number of types
72 */
73class molecule : public Observable
74{
75 //!> grant unit test access
76 friend class MoleculeUnittest;
77 //!> function may access cstor
78 friend molecule *NewMolecule();
79 //!> function may access dstor
80 friend void DeleteMolecule(molecule *);
81
82public:
83 typedef AtomIdSet::atomIdSet atomIdSet;
84 typedef AtomIdSet::iterator iterator;
85 typedef AtomIdSet::const_iterator const_iterator;
86
87 int MDSteps; //!< The number of MD steps in Trajectories
88 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
89 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
90 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
91 int IndexNr; //!< index of molecule in a MoleculeListClass
92 char name[MAXSTRINGSIZE]; //!< arbitrary name
93
94private:
95 Formula formula;
96 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
97 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
98 moleculeId_t id;
99 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
100 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
101 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
102 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
103
104protected:
105
106 molecule();
107 virtual ~molecule();
108
109public:
110
111 /******* Notifications *******/
112
113 //!> enumeration of present notification types: only insertion/removal of atoms or molecules
114 enum NotificationType {
115 AtomInserted,
116 AtomRemoved,
117 AtomNrChanged,
118 AtomMoved,
119 FormulaChanged,
120 MoleculeCenterChanged,
121 MoleculeNameChanged,
122 IndexChanged,
123 BoundingBoxChanged,
124 AboutToBeRemoved,
125 SelectionChanged,
126 NotificationType_MAX
127 };
128
129 //>! access to last changed element (atom)
130 const atomId_t lastChangedAtomId() const
131 { return _lastchangedatomid; }
132
133public:
134 //getter and setter
135 const std::string getName() const;
136 int getAtomCount() const;
137 size_t doCountNoNonHydrogen() const;
138 size_t getNoNonHydrogen() const;
139 int getBondCount() const;
140 int doCountBonds() const;
141 moleculeId_t getId() const;
142 void setId(moleculeId_t);
143 void setName(const std::string);
144 const Formula &getFormula() const;
145 unsigned int getElementCount() const;
146 bool hasElement(const element*) const;
147 bool hasElement(atomicNumber_t) const;
148 bool hasElement(const std::string&) const;
149
150 virtual bool changeId(atomId_t newId);
151
152 World::AtomComposite getAtomSet();
153 World::ConstAtomComposite getAtomSet() const;
154
155 // simply pass on all functions to AtomIdSet
156 iterator begin() {
157 return atomIds.begin();
158 }
159 const_iterator begin() const
160 {
161 return atomIds.begin();
162 }
163 iterator end()
164 {
165 return atomIds.end();
166 }
167 const_iterator end() const
168 {
169 return atomIds.end();
170 }
171 bool empty() const
172 {
173 return atomIds.empty();
174 }
175 size_t size() const
176 {
177 return atomIds.size();
178 }
179 const_iterator find(atom * key) const
180 {
181 return atomIds.find(key);
182 }
183
184 /** Returns the set of atomic ids contained in this molecule.
185 *
186 * @return set of atomic ids
187 */
188 const atomIdSet & getAtomIds() const {
189 return atomIds.getAtomIds();
190 }
191
192 std::pair<iterator, bool> insert(atom * const key);
193
194 /** Predicate whether given \a key is contained in this molecule.
195 *
196 * @param key atom to check
197 * @return true - is contained, false - else
198 */
199 bool containsAtom(const atom* key) const
200 {
201 return atomIds.contains(key);
202 }
203
204 /** Predicate whether given \a id is contained in this molecule.
205 *
206 * @param id atomic id to check
207 * @return true - is contained, false - else
208 */
209 bool containsAtom(const atomId_t id) const
210 {
211 return atomIds.contains(id);
212 }
213
214private:
215 friend void atom::removeFromMolecule();
216 /** Erase an atom from the list.
217 * \note This should only be called by atom::removeFromMolecule(),
218 * otherwise it is not assured that the atom knows about it.
219 *
220 * @param loc locator to atom in list
221 * @return iterator to just after removed item (compliant with standard)
222 */
223 const_iterator erase(const_iterator loc);
224
225 /** Erase an atom from the list.
226 * \note This should only be called by atom::removeFromMolecule(),
227 * otherwise it is not assured that the atom knows about it.
228 *
229 * @param *key key to atom in list
230 * @return iterator to just after removed item (compliant with standard)
231 */
232 const_iterator erase(atom * key);
233
234private:
235 friend bool atom::changeNr(int newId);
236 /**
237 * used when changing an ParticleInfo::Nr.
238 * Note that this number is local with this molecule.
239 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
240 *
241 * @param oldNr old Nr
242 * @param newNr new Nr to set
243 * @param *target ref to atom
244 * @return indicates wether the change could be done or not.
245 */
246 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
247
248 friend bool atom::changeId(atomId_t newId);
249 /**
250 * used when changing an ParticleInfo::Id.
251 * Note that this number is global (and the molecule uses it to know which atoms belong to it)
252 *
253 * @param oldId old Id
254 * @param newId new Id to set
255 * @return indicates wether the change could be done or not.
256 */
257 bool changeAtomId(int oldId, int newId);
258
259 /** Updates the internal lookup fro local to global indices.
260 *
261 * \param pointer pointer to atom
262 */
263 void InsertLocalToGlobalId(atom * const pointer);
264
265 /** Sets the name of the atom.
266 *
267 * The name is set via its element symbol and its internal ParticleInfo::Nr.
268 *
269 * @param _atom atom whose name to set
270 */
271 void setAtomName(atom *_atom) const;
272
273 /** Resets the formula for this molecule.
274 *
275 * This is required in case an atom changes its element as we then don't
276 * have any knowledge about its previous element anymore.
277 */
278 void resetFormula();
279
280 //!> grant World (only) access to selection state changers
281 friend class World;
282
283 /** Sets the internal selection state to true.
284 *
285 */
286 void select();
287
288 /** Unsets the internal selection state to true.
289 *
290 */
291 void unselect();
292
293public:
294
295 /** Getter to internal selection status.
296 *
297 * \return true - molecule is selected, false - else
298 */
299 bool getSelected() const { return selected; }
300
301 /** Structure for the required information on the bounding box.
302 *
303 */
304 struct BoundingBoxInfo {
305 //!> position of center
306 Vector position;
307 //!> radius of sphere
308 double radius;
309
310 /** Equivalence operator for bounding box.
311 *
312 * \return true - both bounding boxes have same position and radius
313 */
314 bool operator==(const BoundingBoxInfo &_other) const
315 { return (radius == _other.radius) && (position == _other.position); }
316
317 /** Inequivalence operator for bounding box.
318 *
319 * \return true - bounding boxes have either different positions or different radii or both
320 */
321 bool operator!=(const BoundingBoxInfo &_other) const
322 { return !(*this == _other); }
323 };
324
325private:
326
327 /** Returns the current bounding box.
328 *
329 * \return Shape with center and extension of box
330 */
331 BoundingBoxInfo updateBoundingBox() const;
332
333 /** Returns the current center of the molecule.
334 *
335 * \return center
336 */
337 Vector updateMoleculeCenter() const;
338
339 // stuff for keeping bounding box up-to-date efficiently
340
341 //!> Cacheable for the bounding box, ptr such that
342 boost::shared_ptr< Cacheable<BoundingBoxInfo> > BoundingBox;
343
344 //!> Cacheable for the bounding box, ptr such that
345 boost::shared_ptr< Cacheable<Vector> > MoleculeCenter;
346
347 /** Bimap storing atomic ids and the component per axis.
348 *
349 * We need a bimap in order to have the components sorted and be able to
350 * access max and min values in linear time and also access the ids in
351 * constant time in order to update the map, when atoms move, are inserted,
352 * or removed.
353 */
354 typedef boost::bimaps::bimap<
355 boost::bimaps::unordered_set_of< atomId_t >,
356 boost::bimaps::multiset_of< double, std::greater<double> >
357 > AtomDistanceMap_t;
358 std::vector<AtomDistanceMap_t> BoundingBoxSweepingAxis;
359
360 //!> make setMolecule friend to access associateAtomWithMolecule()
361 friend void atom::setMolecule(molecule *);
362
363 /** Helper function only to be called by specific atom function.
364 *
365 * \param _atom atom to be added to this molecule
366 */
367 void associateAtomWithMolecule(atom *_atom);
368
369 /** Helper function only to be called by specific atom function.
370 *
371 * \param _atom atom to be added to this molecule
372 */
373 void disassociateAtomWithMolecule(atom *_atom);
374
375public:
376
377 /** Returns the current bounding box of this molecule.
378 *
379 * \return bounding box info with center and radius
380 */
381 BoundingBoxInfo getBoundingBox() const;
382
383 /** Function to create a bounding spherical shape for the currently associated atoms.
384 *
385 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
386 * and the shape's surface)
387 */
388 Shape getBoundingSphere(const double boundary = 0.) const;
389
390 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
391 *
392 * \param scale extra scale parameter to enlarge the spheres artifically
393 */
394 Shape getBoundingShape(const double scale = 1.) const;
395
396 /** Returns the current center of this molecule.
397 *
398 * \return center of the molecule
399 */
400 Vector getMoleculeCenter() const;
401
402 /// remove atoms from molecule.
403 bool AddAtom(atom *pointer);
404 bool RemoveAtom(atom *pointer);
405 bool UnlinkAtom(atom *pointer);
406 bool CleanupMolecule();
407
408 /// Add/remove atoms to/from molecule.
409 atom * AddCopyAtom(atom *pointer);
410// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
411 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
412 bool hasBondStructure() const;
413
414 /// Find atoms.
415 atom * FindAtom(int Nr) const;
416 atom * AskAtom(std::string text);
417 bool isInMolecule(const atom * const _atom) const;
418
419 /// Count and change present atoms' coordination.
420 bool CenterInBox();
421 bool BoundInBox();
422 void CenterEdge();
423 void CenterOrigin();
424 void CenterPeriodic();
425 void CenterAtVector(const Vector &newcenter);
426 void Translate(const Vector &x);
427 void TranslatePeriodically(const Vector &trans);
428 void Mirror(const Vector &x);
429 void Align(const Vector &n);
430 void Scale(const double *factor);
431 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
432 const Vector DetermineCenterOfGravity() const;
433 const Vector DetermineCenterOfAll() const;
434 void SetNameFromFilename(const char *filename);
435 bool ScanForPeriodicCorrection();
436 double VolumeOfConvexEnvelope(bool IsAngstroem);
437 RealSpaceMatrix getInertiaTensor() const;
438 void RotateToPrincipalAxisSystem(const Vector &Axis);
439
440 bool CheckBounds(const Vector *x) const;
441 void GetAlignvector(struct lsq_params * par) const;
442
443 /// Initialising routines in fragmentation
444 void OutputBondsList() const;
445
446 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
447
448 molecule *CopyMolecule(const Vector &offset = zeroVec);
449 molecule* CopyMoleculeFromSubRegion(const Shape&);
450
451 /// Fragment molecule by two different approaches:
452 bool StoreBondsToFile(std::string filename, std::string path = "");
453 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
454
455 // Recognize doubly appearing molecules in a list of them
456 int * GetFatherSonAtomicMap(const molecule * const OtherMolecule);
457 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
458 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
459
460 // Output routines.
461 bool Output(std::ostream * const output) const;
462 void OutputListOfBonds() const;
463
464 // Manipulation routines
465 void flipActiveFlag();
466
467 virtual void update(Observable *publisher);
468 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
469 virtual void subjectKilled(Observable *publisher);
470
471private:
472 //!> id of last atom that signalled changed associated with this molecule
473 atomId_t _lastchangedatomid;
474
475 int last_atom; //!< number given to last atom
476
477 //!> center of the molecule
478 Vector molcenter;
479
480 //!> internal state whether atom is selected or not
481 bool selected;
482};
483
484molecule *NewMolecule();
485void DeleteMolecule(molecule* mol);
486
487
488
489#endif /*MOLECULES_HPP_*/
490
Note: See TracBrowser for help on using the repository browser.