source: src/molecule.hpp@ 795c0f

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

FIX: molecule's Formula is not changed when atom changes element.

  • Property mode set to 100755
File size: 10.2 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
[8e1f901]25#include "AtomIdSet.hpp"
[6f0841]26#include "Atom/AtomSet.hpp"
[ad011c]27#include "CodePatterns/Cacheable.hpp"
[02ce36]28#include "CodePatterns/Observer/Observable.hpp"
[30c753]29#include "Descriptors/AtomIdDescriptor.hpp"
[07a47e]30#include "Fragmentation/HydrogenSaturation_enum.hpp"
[389cc8]31#include "Formula.hpp"
[30c753]32#include "Helpers/defs.hpp"
[560bbe]33#include "IdPool_policy.hpp"
34#include "IdPool.hpp"
[c67ff9]35#include "Shapes/Shape.hpp"
[30c753]36#include "types.hpp"
[14de469]37
[f66195]38/****************************************** forward declarations *****************************/
39
40class atom;
41class bond;
[b70721]42class BondedParticle;
43class BondGraph;
[49c059]44class DepthFirstSearchAnalysis;
[f66195]45class element;
46class ForceMatrix;
[dadc74]47class Graph;
[6bd7e0]48class LinkedCell_deprecated;
[6d551c]49class ListOfLocalAtoms_t;
[14de469]50class molecule;
[2319ed]51class MoleculeLeafClass;
[14de469]52class MoleculeListClass;
[c67ff9]53class MoleculeUnittest;
[1f91f4]54class RealSpaceMatrix;
[f66195]55class Vector;
[14de469]56
57/************************************* Class definitions ****************************************/
58
[a7aebd]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
[14de469]65/** The complete molecule.
66 * Class incorporates number of types
67 */
[34c43a]68class molecule : public Observable
[e4afb4]69{
[c67ff9]70 //!> grant unit test access
71 friend class MoleculeUnittest;
72 //!> function may access cstor
[cbc5fb]73 friend molecule *NewMolecule();
[c67ff9]74 //!> function may access dstor
[cbc5fb]75 friend void DeleteMolecule(molecule *);
[bd58fb]76
[e4afb4]77public:
[8e1f901]78 typedef AtomIdSet::atomIdSet atomIdSet;
79 typedef AtomIdSet::iterator iterator;
80 typedef AtomIdSet::const_iterator const_iterator;
[e4afb4]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;
[e791dc]91 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
[458c31]92 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
[e4afb4]93 moleculeId_t id;
[8e1f901]94 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
[560bbe]95 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
[c6ab91]96 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
97 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
[560bbe]98
[e4afb4]99protected:
[ac9b56]100
[4d2b33]101 molecule();
[e4afb4]102 virtual ~molecule();
[042f82]103
[6a3c83]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,
[c32d21]113 AtomMoved,
[6b6959]114 FormulaChanged,
[6a3c83]115 MoleculeNameChanged,
[24edfe]116 AboutToBeRemoved,
[6a3c83]117 NotificationType_MAX
118 };
119
[8c001a]120 //>! access to last changed element (atom)
121 const atom* lastChanged() const
122 { return _lastchangedatom; }
123
[cbc5fb]124public:
[520c8b]125 //getter and setter
[73a857]126 const std::string getName() const;
[ea7176]127 int getAtomCount() const;
[e791dc]128 size_t doCountNoNonHydrogen() const;
129 size_t getNoNonHydrogen() const;
[458c31]130 int getBondCount() const;
131 int doCountBonds() const;
[73a857]132 moleculeId_t getId() const;
[cbc5fb]133 void setId(moleculeId_t);
[520c8b]134 void setName(const std::string);
[73a857]135 const Formula &getFormula() const;
136 unsigned int getElementCount() const;
[389cc8]137 bool hasElement(const element*) const;
138 bool hasElement(atomicNumber_t) const;
139 bool hasElement(const std::string&) const;
140
[a7a087]141 virtual bool changeId(atomId_t newId);
[520c8b]142
[9317be]143 World::AtomComposite getAtomSet() const;
[3738f0]144
[8e1f901]145 // simply pass on all functions to AtomIdSet
146 iterator begin() {
147 return atomIds.begin();
148 }
149 const_iterator begin() const
150 {
151 return atomIds.begin();
152 }
153 iterator end()
154 {
155 return atomIds.end();
156 }
157 const_iterator end() const
158 {
159 return atomIds.end();
160 }
161 bool empty() const
162 {
163 return atomIds.empty();
164 }
165 size_t size() const
166 {
167 return atomIds.size();
168 }
169 const_iterator find(atom * key) const
170 {
171 return atomIds.find(key);
172 }
[c67ff9]173
174 /** Returns the set of atomic ids contained in this molecule.
175 *
176 * @return set of atomic ids
177 */
[8e1f901]178 const atomIdSet & getAtomIds() const {
179 return atomIds.getAtomIds();
180 }
181
182 std::pair<iterator, bool> insert(atom * const key);
183
[6aad6f]184 /** Predicate whether given \a key is contained in this molecule.
185 *
186 * @param key atom to check
187 * @return true - is contained, false - else
188 */
189 bool containsAtom(const atom* key) const
190 {
191 return atomIds.contains(key);
192 }
193
194 /** Predicate whether given \a id is contained in this molecule.
195 *
196 * @param id atomic id to check
197 * @return true - is contained, false - else
198 */
199 bool containsAtom(const atomId_t id) const
200 {
201 return atomIds.contains(id);
202 }
[bd58fb]203
[2e4105]204private:
205 friend void atom::removeFromMolecule();
206 /** Erase an atom from the list.
207 * \note This should only be called by atom::removeFromMolecule(),
208 * otherwise it is not assured that the atom knows about it.
209 *
210 * @param loc locator to atom in list
211 * @return iterator to just after removed item (compliant with standard)
212 */
213 const_iterator erase(const_iterator loc);
[8e1f901]214
[2e4105]215 /** Erase an atom from the list.
216 * \note This should only be called by atom::removeFromMolecule(),
217 * otherwise it is not assured that the atom knows about it.
218 *
219 * @param *key key to atom in list
220 * @return iterator to just after removed item (compliant with standard)
221 */
222 const_iterator erase(atom * key);
223
[560bbe]224private:
225 friend bool atom::changeNr(int newId);
226 /**
227 * used when changing an ParticleInfo::Nr.
228 * Note that this number is local with this molecule.
229 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
230 *
231 * @param oldNr old Nr
232 * @param newNr new Nr to set
233 * @param *target ref to atom
234 * @return indicates wether the change could be done or not.
235 */
236 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
237
[c6ab91]238 /** Updates the internal lookup fro local to global indices.
239 *
240 * \param pointer pointer to atom
241 */
242 void InsertLocalToGlobalId(atom * const pointer);
243
[560bbe]244 /** Sets the name of the atom.
245 *
246 * The name is set via its element symbol and its internal ParticleInfo::Nr.
247 *
248 * @param _atom atom whose name to set
249 */
250 void setAtomName(atom *_atom) const;
251
[9b3262b]252 /** Resets the formula for this molecule.
253 *
254 * This is required in case an atom changes its element as we then don't
255 * have any knowledge about its previous element anymore.
256 */
257 void resetFormula();
258
[2e4105]259public:
260
[c67ff9]261 /** Function to create a bounding spherical shape for the currently associated atoms.
262 *
[55feea1]263 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
264 * and the shape's surface)
[c67ff9]265 */
[aeb694]266 Shape getBoundingSphere(const double boundary = 0.) const;
267
268 /** Creates the bounding box by adding van der Waals-Spheres around every atom.
269 *
270 * \param scale extra scale parameter to enlarge the spheres artifically
271 */
272 Shape getBoundingShape(const double scale = 1.) const;
[c67ff9]273
[042f82]274 /// remove atoms from molecule.
275 bool AddAtom(atom *pointer);
276 bool RemoveAtom(atom *pointer);
277 bool UnlinkAtom(atom *pointer);
278 bool CleanupMolecule();
279
280 /// Add/remove atoms to/from molecule.
281 atom * AddCopyAtom(atom *pointer);
[06804b]282// bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
[88c8ec]283 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
[e4afb4]284 bool hasBondStructure() const;
[042f82]285
286 /// Find atoms.
287 atom * FindAtom(int Nr) const;
[955b91]288 atom * AskAtom(std::string text);
[59fff1]289 bool isInMolecule(const atom * const _atom);
[042f82]290
291 /// Count and change present atoms' coordination.
[e138de]292 bool CenterInBox();
293 bool BoundInBox();
[833b15]294 void CenterEdge();
[e138de]295 void CenterOrigin();
296 void CenterPeriodic();
[833b15]297 void CenterAtVector(const Vector &newcenter);
298 void Translate(const Vector &x);
299 void TranslatePeriodically(const Vector &trans);
300 void Mirror(const Vector &x);
301 void Align(const Vector &n);
302 void Scale(const double *factor);
[9291d04]303 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
[833b15]304 const Vector DetermineCenterOfGravity() const;
305 const Vector DetermineCenterOfAll() const;
[437922]306 void SetNameFromFilename(const char *filename);
[3c58f8]307 bool ScanForPeriodicCorrection();
[e138de]308 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]309 RealSpaceMatrix getInertiaTensor() const;
[5b6a4b7]310 void RotateToPrincipalAxisSystem(const Vector &Axis);
[042f82]311
312 bool CheckBounds(const Vector *x) const;
313 void GetAlignvector(struct lsq_params * par) const;
314
315 /// Initialising routines in fragmentation
[e138de]316 void OutputBondsList() const;
[49c059]317
[88c8ec]318 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
[266237]319
[c67ff9]320 molecule *CopyMolecule(const Vector &offset = zeroVec) const;
[c550dd]321 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
[042f82]322
323 /// Fragment molecule by two different approaches:
[e4afb4]324 bool StoreBondsToFile(std::string filename, std::string path = "");
[6d551c]325 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
[b9772a]326
[042f82]327 // Recognize doubly appearing molecules in a list of them
[e138de]328 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
[6d551c]329 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
330 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
[042f82]331
332 // Output routines.
[e4afb4]333 bool Output(std::ostream * const output) const;
[e138de]334 void OutputListOfBonds() const;
[042f82]335
[c68025]336 // Manipulation routines
337 void flipActiveFlag();
338
[c32d21]339 virtual void update(Observable *publisher);
340 virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
341 virtual void subjectKilled(Observable *publisher);
342
[e4afb4]343private:
[8c001a]344 friend const atom *detail::lastChanged<atom>();
345 atom *_lastchangedatom;
346
[e4afb4]347 int last_atom; //!< number given to last atom
[14de469]348};
349
[cbc5fb]350molecule *NewMolecule();
351void DeleteMolecule(molecule* mol);
352
[14de469]353
354
355#endif /*MOLECULES_HPP_*/
356
Note: See TracBrowser for help on using the repository browser.