source: src/molecule.hpp@ 687ef1

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 Candidate_v1.7.0 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 687ef1 was cbd409, checked in by Frederik Heber <heber@…>, 10 years ago

Added Cacheable MoleculeCenter to molecule which is cleverly updated.

  • Property mode set to 100755
File size: 13.0 KB
RevLine 
[cee0b57]1/** \file molecule.hpp
[14de469]2 *
[69eb71]3 * Class definitions of atom and molecule, element and periodentafel
[14de469]4 */
5
6#ifndef MOLECULES_HPP_
7#define MOLECULES_HPP_
8
[f66195]9/*********************************************** includes ***********************************/
10
[962d8d]11#ifdef HAVE_CONFIG_H
12#include <config.h>
13#endif
14
[edb93c]15//// STL headers
[14de469]16#include <map>
17#include <set>
[a564be]18#include <stack>
[14de469]19#include <deque>
[d7e30c]20#include <list>
[5e0d1f]21#include <vector>
[14de469]22
[520c8b]23#include <string>
24
[e39e7a]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
[8e1f901]31#include "AtomIdSet.hpp"
[6f0841]32#include "Atom/AtomSet.hpp"
[ad011c]33#include "CodePatterns/Cacheable.hpp"
[02ce36]34#include "CodePatterns/Observer/Observable.hpp"
[30c753]35#include "Descriptors/AtomIdDescriptor.hpp"
[07a47e]36#include "Fragmentation/HydrogenSaturation_enum.hpp"
[389cc8]37#include "Formula.hpp"
[30c753]38#include "Helpers/defs.hpp"
[560bbe]39#include "IdPool_policy.hpp"
40#include "IdPool.hpp"
[c67ff9]41#include "Shapes/Shape.hpp"
[30c753]42#include "types.hpp"
[14de469]43
[f66195]44/****************************************** forward declarations *****************************/
45
46class atom;
47class bond;
[b70721]48class BondedParticle;
49class BondGraph;
[49c059]50class DepthFirstSearchAnalysis;
[f66195]51class element;
52class ForceMatrix;
[dadc74]53class Graph;
[6bd7e0]54class LinkedCell_deprecated;
[6d551c]55class ListOfLocalAtoms_t;
[14de469]56class molecule;
[2319ed]57class MoleculeLeafClass;
[14de469]58class MoleculeListClass;
[c67ff9]59class MoleculeUnittest;
[1f91f4]60class RealSpaceMatrix;
[f66195]61class Vector;
[14de469]62
63/************************************* Class definitions ****************************************/
64
[a7aebd]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
[14de469]71/** The complete molecule.
72 * Class incorporates number of types
73 */
[34c43a]74class molecule : public Observable
[e4afb4]75{
[c67ff9]76 //!> grant unit test access
77 friend class MoleculeUnittest;
78 //!> function may access cstor
[cbc5fb]79 friend molecule *NewMolecule();
[c67ff9]80 //!> function may access dstor
[cbc5fb]81 friend void DeleteMolecule(molecule *);
[bd58fb]82
[e4afb4]83public:
[8e1f901]84 typedef AtomIdSet::atomIdSet atomIdSet;
85 typedef AtomIdSet::iterator iterator;
86 typedef AtomIdSet::const_iterator const_iterator;
[e4afb4]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;
[e791dc]97 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
[458c31]98 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
[e4afb4]99 moleculeId_t id;
[8e1f901]100 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
[560bbe]101 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
[c6ab91]102 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
103 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
[560bbe]104
[e4afb4]105protected:
[ac9b56]106
[4d2b33]107 molecule();
[e4afb4]108 virtual ~molecule();
[042f82]109
[6a3c83]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,
[c32d21]119 AtomMoved,
[6b6959]120 FormulaChanged,
[cbd409]121 MoleculeCenterChanged,
[6a3c83]122 MoleculeNameChanged,
[f54524]123 IndexChanged,
[e39e7a]124 BoundingBoxChanged,
[24edfe]125 AboutToBeRemoved,
[6a3c83]126 NotificationType_MAX
127 };
128
[8c001a]129 //>! access to last changed element (atom)
[fb95a5]130 const atomId_t lastChangedAtomId() const
131 { return _lastchangedatomid; }
[8c001a]132
[cbc5fb]133public:
[520c8b]134 //getter and setter
[73a857]135 const std::string getName() const;
[ea7176]136 int getAtomCount() const;
[e791dc]137 size_t doCountNoNonHydrogen() const;
138 size_t getNoNonHydrogen() const;
[458c31]139 int getBondCount() const;
140 int doCountBonds() const;
[73a857]141 moleculeId_t getId() const;
[cbc5fb]142 void setId(moleculeId_t);
[520c8b]143 void setName(const std::string);
[73a857]144 const Formula &getFormula() const;
145 unsigned int getElementCount() const;
[389cc8]146 bool hasElement(const element*) const;
147 bool hasElement(atomicNumber_t) const;
148 bool hasElement(const std::string&) const;
149
[a7a087]150 virtual bool changeId(atomId_t newId);
[520c8b]151
[f01769]152 World::AtomComposite getAtomSet();
153 World::ConstAtomComposite getAtomSet() const;
[3738f0]154
[8e1f901]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 }
[c67ff9]183
184 /** Returns the set of atomic ids contained in this molecule.
185 *
186 * @return set of atomic ids
187 */
[8e1f901]188 const atomIdSet & getAtomIds() const {
189 return atomIds.getAtomIds();
190 }
191
192 std::pair<iterator, bool> insert(atom * const key);
193
[6aad6f]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 }
[bd58fb]213
[2e4105]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);
[8e1f901]224
[2e4105]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
[560bbe]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
[ceaab1]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
[c6ab91]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
[560bbe]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
[9b3262b]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
[2e4105]280public:
281
[e39e7a]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
[cbd409]314 /** Returns the current center of the molecule.
315 *
316 * \return center
317 */
318 Vector updateMoleculeCenter() const;
319
[e39e7a]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;
[cbd409]324
325 //!> Cacheable for the bounding box, ptr such that
326 boost::shared_ptr< Cacheable<Vector> > MoleculeCenter;
327
[e39e7a]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
[c67ff9]349 /** Function to create a bounding spherical shape for the currently associated atoms.
350 *
[55feea1]351 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
352 * and the shape's surface)
[c67ff9]353 */
[aeb694]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;
[c67ff9]361
[cbd409]362 /** Returns the current center of this molecule.
363 *
364 * \return center of the molecule
365 */
366 Vector getMoleculeCenter() const;
367
[042f82]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);
[06804b]376// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
[88c8ec]377 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
[e4afb4]378 bool hasBondStructure() const;
[042f82]379
380 /// Find atoms.
381 atom * FindAtom(int Nr) const;
[955b91]382 atom * AskAtom(std::string text);
[f01769]383 bool isInMolecule(const atom * const _atom) const;
[042f82]384
385 /// Count and change present atoms' coordination.
[e138de]386 bool CenterInBox();
387 bool BoundInBox();
[833b15]388 void CenterEdge();
[e138de]389 void CenterOrigin();
390 void CenterPeriodic();
[833b15]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);
[9291d04]397 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
[833b15]398 const Vector DetermineCenterOfGravity() const;
399 const Vector DetermineCenterOfAll() const;
[437922]400 void SetNameFromFilename(const char *filename);
[3c58f8]401 bool ScanForPeriodicCorrection();
[e138de]402 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]403 RealSpaceMatrix getInertiaTensor() const;
[5b6a4b7]404 void RotateToPrincipalAxisSystem(const Vector &Axis);
[042f82]405
406 bool CheckBounds(const Vector *x) const;
407 void GetAlignvector(struct lsq_params * par) const;
408
409 /// Initialising routines in fragmentation
[e138de]410 void OutputBondsList() const;
[49c059]411
[88c8ec]412 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
[266237]413
[f01769]414 molecule *CopyMolecule(const Vector &offset = zeroVec);
415 molecule* CopyMoleculeFromSubRegion(const Shape&);
[042f82]416
417 /// Fragment molecule by two different approaches:
[e4afb4]418 bool StoreBondsToFile(std::string filename, std::string path = "");
[6d551c]419 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
[b9772a]420
[042f82]421 // Recognize doubly appearing molecules in a list of them
[f01769]422 int * GetFatherSonAtomicMap(const molecule * const OtherMolecule);
[6d551c]423 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
424 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
[042f82]425
426 // Output routines.
[e4afb4]427 bool Output(std::ostream * const output) const;
[e138de]428 void OutputListOfBonds() const;
[042f82]429
[c68025]430 // Manipulation routines
431 void flipActiveFlag();
432
[c32d21]433 virtual void update(Observable *publisher);
434 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
435 virtual void subjectKilled(Observable *publisher);
436
[e4afb4]437private:
[fb95a5]438 atomId_t _lastchangedatomid;
[8c001a]439
[e4afb4]440 int last_atom; //!< number given to last atom
[cbd409]441
442 Vector molcenter;
[14de469]443};
444
[cbc5fb]445molecule *NewMolecule();
446void DeleteMolecule(molecule* mol);
447
[14de469]448
449
450#endif /*MOLECULES_HPP_*/
451
Note: See TracBrowser for help on using the repository browser.