source: src/molecule.hpp@ fb95a5

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

Added lastChanged..Id() to both World and molecule.

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