source: src/molecule.hpp@ 2affd1

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

Removed molecules_deprecated from World and unnecessary includes of MoleculeListClass and all insert/erase.

  • this goes along the lines of removing "remove me when we don't need MoleculeCistClass anymore".
  • Property mode set to 100755
File size: 13.5 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;
[c67ff9]58class MoleculeUnittest;
[1f91f4]59class RealSpaceMatrix;
[f66195]60class Vector;
[14de469]61
62/************************************* Class definitions ****************************************/
63
[a7aebd]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
[14de469]70/** The complete molecule.
71 * Class incorporates number of types
72 */
[34c43a]73class molecule : public Observable
[e4afb4]74{
[c67ff9]75 //!> grant unit test access
76 friend class MoleculeUnittest;
77 //!> function may access cstor
[cbc5fb]78 friend molecule *NewMolecule();
[c67ff9]79 //!> function may access dstor
[cbc5fb]80 friend void DeleteMolecule(molecule *);
[bd58fb]81
[e4afb4]82public:
[8e1f901]83 typedef AtomIdSet::atomIdSet atomIdSet;
84 typedef AtomIdSet::iterator iterator;
85 typedef AtomIdSet::const_iterator const_iterator;
[e4afb4]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;
[e791dc]96 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
[458c31]97 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
[e4afb4]98 moleculeId_t id;
[8e1f901]99 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
[560bbe]100 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
[c6ab91]101 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
102 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
[560bbe]103
[e4afb4]104protected:
[ac9b56]105
[4d2b33]106 molecule();
[e4afb4]107 virtual ~molecule();
[042f82]108
[6a3c83]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,
[c32d21]118 AtomMoved,
[6b6959]119 FormulaChanged,
[cbd409]120 MoleculeCenterChanged,
[6a3c83]121 MoleculeNameChanged,
[f54524]122 IndexChanged,
[e39e7a]123 BoundingBoxChanged,
[24edfe]124 AboutToBeRemoved,
[b71881]125 SelectionChanged,
[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
[b71881]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
[2e4105]293public:
294
[b71881]295 /** Getter to internal selection status.
296 *
297 * \return true - molecule is selected, false - else
298 */
299 bool getSelected() const { return selected; }
300
[e39e7a]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
[cbd409]333 /** Returns the current center of the molecule.
334 *
335 * \return center
336 */
337 Vector updateMoleculeCenter() const;
338
[e39e7a]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;
[cbd409]343
344 //!> Cacheable for the bounding box, ptr such that
345 boost::shared_ptr< Cacheable<Vector> > MoleculeCenter;
346
[e39e7a]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
360public:
361
362 /** Returns the current bounding box of this molecule.
363 *
364 * \return bounding box info with center and radius
365 */
366 BoundingBoxInfo getBoundingBox() const;
367
[c67ff9]368 /** Function to create a bounding spherical shape for the currently associated atoms.
369 *
[55feea1]370 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
371 * and the shape's surface)
[c67ff9]372 */
[aeb694]373 Shape getBoundingSphere(const double boundary = 0.) const;
374
375 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
376 *
377 * \param scale extra scale parameter to enlarge the spheres artifically
378 */
379 Shape getBoundingShape(const double scale = 1.) const;
[c67ff9]380
[cbd409]381 /** Returns the current center of this molecule.
382 *
383 * \return center of the molecule
384 */
385 Vector getMoleculeCenter() const;
386
[042f82]387 /// remove atoms from molecule.
388 bool AddAtom(atom *pointer);
389 bool RemoveAtom(atom *pointer);
390 bool UnlinkAtom(atom *pointer);
391 bool CleanupMolecule();
392
393 /// Add/remove atoms to/from molecule.
394 atom * AddCopyAtom(atom *pointer);
[06804b]395// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
[88c8ec]396 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
[e4afb4]397 bool hasBondStructure() const;
[042f82]398
399 /// Find atoms.
400 atom * FindAtom(int Nr) const;
[955b91]401 atom * AskAtom(std::string text);
[f01769]402 bool isInMolecule(const atom * const _atom) const;
[042f82]403
404 /// Count and change present atoms' coordination.
[e138de]405 bool CenterInBox();
406 bool BoundInBox();
[833b15]407 void CenterEdge();
[e138de]408 void CenterOrigin();
409 void CenterPeriodic();
[833b15]410 void CenterAtVector(const Vector &newcenter);
411 void Translate(const Vector &x);
412 void TranslatePeriodically(const Vector &trans);
413 void Mirror(const Vector &x);
414 void Align(const Vector &n);
415 void Scale(const double *factor);
[9291d04]416 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
[833b15]417 const Vector DetermineCenterOfGravity() const;
418 const Vector DetermineCenterOfAll() const;
[437922]419 void SetNameFromFilename(const char *filename);
[3c58f8]420 bool ScanForPeriodicCorrection();
[e138de]421 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]422 RealSpaceMatrix getInertiaTensor() const;
[5b6a4b7]423 void RotateToPrincipalAxisSystem(const Vector &Axis);
[042f82]424
425 bool CheckBounds(const Vector *x) const;
426 void GetAlignvector(struct lsq_params * par) const;
427
428 /// Initialising routines in fragmentation
[e138de]429 void OutputBondsList() const;
[49c059]430
[88c8ec]431 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
[266237]432
[f01769]433 molecule *CopyMolecule(const Vector &offset = zeroVec);
434 molecule* CopyMoleculeFromSubRegion(const Shape&);
[042f82]435
436 /// Fragment molecule by two different approaches:
[e4afb4]437 bool StoreBondsToFile(std::string filename, std::string path = "");
[6d551c]438 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
[b9772a]439
[042f82]440 // Recognize doubly appearing molecules in a list of them
[f01769]441 int * GetFatherSonAtomicMap(const molecule * const OtherMolecule);
[6d551c]442 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
443 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
[042f82]444
445 // Output routines.
[e4afb4]446 bool Output(std::ostream * const output) const;
[e138de]447 void OutputListOfBonds() const;
[042f82]448
[c68025]449 // Manipulation routines
450 void flipActiveFlag();
451
[c32d21]452 virtual void update(Observable *publisher);
453 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
454 virtual void subjectKilled(Observable *publisher);
455
[e4afb4]456private:
[b71881]457 //!> id of last atom that signalled changed associated with this molecule
[fb95a5]458 atomId_t _lastchangedatomid;
[8c001a]459
[e4afb4]460 int last_atom; //!< number given to last atom
[cbd409]461
[b71881]462 //!> center of the molecule
[cbd409]463 Vector molcenter;
[b71881]464
465 //!> internal state whether atom is selected or not
466 bool selected;
[14de469]467};
468
[cbc5fb]469molecule *NewMolecule();
470void DeleteMolecule(molecule* mol);
471
[14de469]472
473
474#endif /*MOLECULES_HPP_*/
475
Note: See TracBrowser for help on using the repository browser.