source: src/molecule.hpp@ cbd409

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

Added Cacheable MoleculeCenter to molecule which is cleverly updated.

  • Property mode set to 100755
File size: 13.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 MoleculeListClass;
59class MoleculeUnittest;
60class RealSpaceMatrix;
61class Vector;
62
63/************************************* Class definitions ****************************************/
64
65/** External function to remove all atoms since this will also delete the molecule
66 *
67 * \param _mol ref pointer to molecule to destroy
68 */
69void removeAtomsinMolecule(molecule *&_mol);
70
71/** The complete molecule.
72 * Class incorporates number of types
73 */
74class molecule : public Observable
75{
76 //!> grant unit test access
77 friend class MoleculeUnittest;
78 //!> function may access cstor
79 friend molecule *NewMolecule();
80 //!> function may access dstor
81 friend void DeleteMolecule(molecule *);
82
83public:
84 typedef AtomIdSet::atomIdSet atomIdSet;
85 typedef AtomIdSet::iterator iterator;
86 typedef AtomIdSet::const_iterator const_iterator;
87
88 int MDSteps; //!< The number of MD steps in Trajectories
89 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
90 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
91 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
92 int IndexNr; //!< index of molecule in a MoleculeListClass
93 char name[MAXSTRINGSIZE]; //!< arbitrary name
94
95private:
96 Formula formula;
97 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
98 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
99 moleculeId_t id;
100 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
101 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
102 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
103 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
104
105protected:
106
107 molecule();
108 virtual ~molecule();
109
110public:
111
112 /******* Notifications *******/
113
114 //!> enumeration of present notification types: only insertion/removal of atoms or molecules
115 enum NotificationType {
116 AtomInserted,
117 AtomRemoved,
118 AtomNrChanged,
119 AtomMoved,
120 FormulaChanged,
121 MoleculeCenterChanged,
122 MoleculeNameChanged,
123 IndexChanged,
124 BoundingBoxChanged,
125 AboutToBeRemoved,
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
280public:
281
282 /** Structure for the required information on the bounding box.
283 *
284 */
285 struct BoundingBoxInfo {
286 //!> position of center
287 Vector position;
288 //!> radius of sphere
289 double radius;
290
291 /** Equivalence operator for bounding box.
292 *
293 * \return true - both bounding boxes have same position and radius
294 */
295 bool operator==(const BoundingBoxInfo &_other) const
296 { return (radius == _other.radius) && (position == _other.position); }
297
298 /** Inequivalence operator for bounding box.
299 *
300 * \return true - bounding boxes have either different positions or different radii or both
301 */
302 bool operator!=(const BoundingBoxInfo &_other) const
303 { return !(*this == _other); }
304 };
305
306private:
307
308 /** Returns the current bounding box.
309 *
310 * \return Shape with center and extension of box
311 */
312 BoundingBoxInfo updateBoundingBox() const;
313
314 /** Returns the current center of the molecule.
315 *
316 * \return center
317 */
318 Vector updateMoleculeCenter() const;
319
320 // stuff for keeping bounding box up-to-date efficiently
321
322 //!> Cacheable for the bounding box, ptr such that
323 boost::shared_ptr< Cacheable<BoundingBoxInfo> > BoundingBox;
324
325 //!> Cacheable for the bounding box, ptr such that
326 boost::shared_ptr< Cacheable<Vector> > MoleculeCenter;
327
328 /** Bimap storing atomic ids and the component per axis.
329 *
330 * We need a bimap in order to have the components sorted and be able to
331 * access max and min values in linear time and also access the ids in
332 * constant time in order to update the map, when atoms move, are inserted,
333 * or removed.
334 */
335 typedef boost::bimaps::bimap<
336 boost::bimaps::unordered_set_of< atomId_t >,
337 boost::bimaps::multiset_of< double, std::greater<double> >
338 > AtomDistanceMap_t;
339 std::vector<AtomDistanceMap_t> BoundingBoxSweepingAxis;
340
341public:
342
343 /** Returns the current bounding box of this molecule.
344 *
345 * \return bounding box info with center and radius
346 */
347 BoundingBoxInfo getBoundingBox() const;
348
349 /** Function to create a bounding spherical shape for the currently associated atoms.
350 *
351 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
352 * and the shape's surface)
353 */
354 Shape getBoundingSphere(const double boundary = 0.) const;
355
356 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
357 *
358 * \param scale extra scale parameter to enlarge the spheres artifically
359 */
360 Shape getBoundingShape(const double scale = 1.) const;
361
362 /** Returns the current center of this molecule.
363 *
364 * \return center of the molecule
365 */
366 Vector getMoleculeCenter() const;
367
368 /// remove atoms from molecule.
369 bool AddAtom(atom *pointer);
370 bool RemoveAtom(atom *pointer);
371 bool UnlinkAtom(atom *pointer);
372 bool CleanupMolecule();
373
374 /// Add/remove atoms to/from molecule.
375 atom * AddCopyAtom(atom *pointer);
376// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
377 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
378 bool hasBondStructure() const;
379
380 /// Find atoms.
381 atom * FindAtom(int Nr) const;
382 atom * AskAtom(std::string text);
383 bool isInMolecule(const atom * const _atom) const;
384
385 /// Count and change present atoms' coordination.
386 bool CenterInBox();
387 bool BoundInBox();
388 void CenterEdge();
389 void CenterOrigin();
390 void CenterPeriodic();
391 void CenterAtVector(const Vector &newcenter);
392 void Translate(const Vector &x);
393 void TranslatePeriodically(const Vector &trans);
394 void Mirror(const Vector &x);
395 void Align(const Vector &n);
396 void Scale(const double *factor);
397 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
398 const Vector DetermineCenterOfGravity() const;
399 const Vector DetermineCenterOfAll() const;
400 void SetNameFromFilename(const char *filename);
401 bool ScanForPeriodicCorrection();
402 double VolumeOfConvexEnvelope(bool IsAngstroem);
403 RealSpaceMatrix getInertiaTensor() const;
404 void RotateToPrincipalAxisSystem(const Vector &Axis);
405
406 bool CheckBounds(const Vector *x) const;
407 void GetAlignvector(struct lsq_params * par) const;
408
409 /// Initialising routines in fragmentation
410 void OutputBondsList() const;
411
412 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
413
414 molecule *CopyMolecule(const Vector &offset = zeroVec);
415 molecule* CopyMoleculeFromSubRegion(const Shape&);
416
417 /// Fragment molecule by two different approaches:
418 bool StoreBondsToFile(std::string filename, std::string path = "");
419 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
420
421 // Recognize doubly appearing molecules in a list of them
422 int * GetFatherSonAtomicMap(const molecule * const OtherMolecule);
423 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
424 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
425
426 // Output routines.
427 bool Output(std::ostream * const output) const;
428 void OutputListOfBonds() const;
429
430 // Manipulation routines
431 void flipActiveFlag();
432
433 virtual void update(Observable *publisher);
434 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
435 virtual void subjectKilled(Observable *publisher);
436
437private:
438 atomId_t _lastchangedatomid;
439
440 int last_atom; //!< number given to last atom
441
442 Vector molcenter;
443};
444
445molecule *NewMolecule();
446void DeleteMolecule(molecule* mol);
447
448
449
450#endif /*MOLECULES_HPP_*/
451
Note: See TracBrowser for help on using the repository browser.