source: src/molecule.hpp@ d67e6c

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

Wrote faster molecule::FindAtom().

  • due to local id nature in Fragmentation many functions there make heavy use of this function. However, has it scales linearly, this severly limits the abilitiy to tackle large molecules.
  • as quick short-cut we installed a map from local to global ids, updated by insert() and erase() and used by FindAtom().
  • Property mode set to 100755
File size: 9.3 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
59/** The complete molecule.
60 * Class incorporates number of types
61 */
[34c43a]62class molecule : public Observable
[e4afb4]63{
[c67ff9]64 //!> grant unit test access
65 friend class MoleculeUnittest;
66 //!> function may access cstor
[cbc5fb]67 friend molecule *NewMolecule();
[c67ff9]68 //!> function may access dstor
[cbc5fb]69 friend void DeleteMolecule(molecule *);
[bd58fb]70
[e4afb4]71public:
[8e1f901]72 typedef AtomIdSet::atomIdSet atomIdSet;
73 typedef AtomIdSet::iterator iterator;
74 typedef AtomIdSet::const_iterator const_iterator;
[e4afb4]75
76 int MDSteps; //!< The number of MD steps in Trajectories
77 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
78 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
79 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
80 int IndexNr; //!< index of molecule in a MoleculeListClass
81 char name[MAXSTRINGSIZE]; //!< arbitrary name
82
83private:
84 Formula formula;
[e791dc]85 Cacheable<size_t> NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
[458c31]86 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
[e4afb4]87 moleculeId_t id;
[8e1f901]88 AtomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
[560bbe]89 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
[c6ab91]90 typedef std::map<atomId_t,atom *> LocalToGlobalId_t;
91 LocalToGlobalId_t LocalToGlobalId; //!< internal map to ease FindAtom
[560bbe]92
[e4afb4]93protected:
[ac9b56]94
[4d2b33]95 molecule();
[e4afb4]96 virtual ~molecule();
[042f82]97
[6a3c83]98public:
99
100 /******* Notifications *******/
101
102 //!> enumeration of present notification types: only insertion/removal of atoms or molecules
103 enum NotificationType {
104 AtomInserted,
105 AtomRemoved,
106 AtomNrChanged,
107 MoleculeNameChanged,
108 NotificationType_MAX
109 };
110
[cbc5fb]111public:
[520c8b]112 //getter and setter
[73a857]113 const std::string getName() const;
[ea7176]114 int getAtomCount() const;
[e791dc]115 size_t doCountNoNonHydrogen() const;
116 size_t getNoNonHydrogen() const;
[458c31]117 int getBondCount() const;
118 int doCountBonds() const;
[73a857]119 moleculeId_t getId() const;
[cbc5fb]120 void setId(moleculeId_t);
[520c8b]121 void setName(const std::string);
[73a857]122 const Formula &getFormula() const;
123 unsigned int getElementCount() const;
[389cc8]124 bool hasElement(const element*) const;
125 bool hasElement(atomicNumber_t) const;
126 bool hasElement(const std::string&) const;
127
[a7a087]128 virtual bool changeId(atomId_t newId);
[520c8b]129
[9317be]130 World::AtomComposite getAtomSet() const;
[3738f0]131
[8e1f901]132 // simply pass on all functions to AtomIdSet
133 iterator begin() {
134 return atomIds.begin();
135 }
136 const_iterator begin() const
137 {
138 return atomIds.begin();
139 }
140 iterator end()
141 {
142 return atomIds.end();
143 }
144 const_iterator end() const
145 {
146 return atomIds.end();
147 }
148 bool empty() const
149 {
150 return atomIds.empty();
151 }
152 size_t size() const
153 {
154 return atomIds.size();
155 }
156 const_iterator find(atom * key) const
157 {
158 return atomIds.find(key);
159 }
[c67ff9]160
161 /** Returns the set of atomic ids contained in this molecule.
162 *
163 * @return set of atomic ids
164 */
[8e1f901]165 const atomIdSet & getAtomIds() const {
166 return atomIds.getAtomIds();
167 }
168
169 std::pair<iterator, bool> insert(atom * const key);
170
[6aad6f]171 /** Predicate whether given \a key is contained in this molecule.
172 *
173 * @param key atom to check
174 * @return true - is contained, false - else
175 */
176 bool containsAtom(const atom* key) const
177 {
178 return atomIds.contains(key);
179 }
180
181 /** Predicate whether given \a id is contained in this molecule.
182 *
183 * @param id atomic id to check
184 * @return true - is contained, false - else
185 */
186 bool containsAtom(const atomId_t id) const
187 {
188 return atomIds.contains(id);
189 }
[bd58fb]190
[2e4105]191private:
192 friend void atom::removeFromMolecule();
193 /** Erase an atom from the list.
194 * \note This should only be called by atom::removeFromMolecule(),
195 * otherwise it is not assured that the atom knows about it.
196 *
197 * @param loc locator to atom in list
198 * @return iterator to just after removed item (compliant with standard)
199 */
200 const_iterator erase(const_iterator loc);
[8e1f901]201
[2e4105]202 /** Erase an atom from the list.
203 * \note This should only be called by atom::removeFromMolecule(),
204 * otherwise it is not assured that the atom knows about it.
205 *
206 * @param *key key to atom in list
207 * @return iterator to just after removed item (compliant with standard)
208 */
209 const_iterator erase(atom * key);
210
[560bbe]211private:
212 friend bool atom::changeNr(int newId);
213 /**
214 * used when changing an ParticleInfo::Nr.
215 * Note that this number is local with this molecule.
216 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
217 *
218 * @param oldNr old Nr
219 * @param newNr new Nr to set
220 * @param *target ref to atom
221 * @return indicates wether the change could be done or not.
222 */
223 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
224
[c6ab91]225 /** Updates the internal lookup fro local to global indices.
226 *
227 * \param pointer pointer to atom
228 */
229 void InsertLocalToGlobalId(atom * const pointer);
230
[560bbe]231 /** Sets the name of the atom.
232 *
233 * The name is set via its element symbol and its internal ParticleInfo::Nr.
234 *
235 * @param _atom atom whose name to set
236 */
237 void setAtomName(atom *_atom) const;
238
[2e4105]239public:
240
[c67ff9]241 /** Function to create a bounding spherical shape for the currently associated atoms.
242 *
[55feea1]243 * \param boundary extra boundary of shape around (i.e. distance between outermost atom
244 * and the shape's surface)
[c67ff9]245 */
[55feea1]246 Shape getBoundingShape(const double boundary = 0.) const;
[c67ff9]247
[042f82]248 /// remove atoms from molecule.
249 bool AddAtom(atom *pointer);
250 bool RemoveAtom(atom *pointer);
251 bool UnlinkAtom(atom *pointer);
252 bool CleanupMolecule();
[9df680]253 void removeAtomsinMolecule();
[042f82]254
255 /// Add/remove atoms to/from molecule.
256 atom * AddCopyAtom(atom *pointer);
[88c8ec]257 bool AddHydrogenReplacementAtom(bond::ptr Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
258 bond::ptr AddBond(atom *first, atom *second, int degree = 1);
[e4afb4]259 bool hasBondStructure() const;
[042f82]260
261 /// Find atoms.
262 atom * FindAtom(int Nr) const;
[955b91]263 atom * AskAtom(std::string text);
[59fff1]264 bool isInMolecule(const atom * const _atom);
[042f82]265
266 /// Count and change present atoms' coordination.
[e138de]267 bool CenterInBox();
268 bool BoundInBox();
269 void CenterEdge(Vector *max);
270 void CenterOrigin();
271 void CenterPeriodic();
272 void CenterAtVector(Vector *newcenter);
[042f82]273 void Translate(const Vector *x);
274 void TranslatePeriodically(const Vector *trans);
275 void Mirror(const Vector *x);
276 void Align(Vector *n);
[776b64]277 void Scale(const double ** const factor);
[9291d04]278 void DeterminePeriodicCenter(Vector &center, const enum HydrogenTreatment _treatment = ExcludeHydrogen);
[4bb63c]279 Vector * DetermineCenterOfGravity() const;
[e138de]280 Vector * DetermineCenterOfAll() const;
[eddea2]281 Vector * DetermineCenterOfBox() const;
[437922]282 void SetNameFromFilename(const char *filename);
[042f82]283 void SetBoxDimension(Vector *dim);
[3c58f8]284 bool ScanForPeriodicCorrection();
[e138de]285 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]286 RealSpaceMatrix getInertiaTensor() const;
[5b6a4b7]287 void RotateToPrincipalAxisSystem(const Vector &Axis);
[042f82]288
289 bool CheckBounds(const Vector *x) const;
290 void GetAlignvector(struct lsq_params * par) const;
291
292 /// Initialising routines in fragmentation
[e138de]293 void OutputBondsList() const;
[49c059]294
[88c8ec]295 bond::ptr CopyBond(atom *left, atom *right, bond::ptr CopyBond);
[266237]296
[c67ff9]297 molecule *CopyMolecule(const Vector &offset = zeroVec) const;
[c550dd]298 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
[042f82]299
300 /// Fragment molecule by two different approaches:
[e4afb4]301 bool StoreBondsToFile(std::string filename, std::string path = "");
[6d551c]302 bool CreateFatherLookupTable(ListOfLocalAtoms_t &LookupTable, int count = 0);
[b9772a]303
[042f82]304 // Recognize doubly appearing molecules in a list of them
[e138de]305 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
[6d551c]306 bool FillBondStructureFromReference(const molecule * const reference, ListOfLocalAtoms_t &ListOfLocalAtoms, bool FreeList = false);
307 bool FillListOfLocalAtoms(ListOfLocalAtoms_t &ListOfLocalAtoms, const int GlobalAtomCount);
[042f82]308
309 // Output routines.
[e4afb4]310 bool Output(std::ostream * const output) const;
[e138de]311 void OutputListOfBonds() const;
[042f82]312
[c68025]313 // Manipulation routines
314 void flipActiveFlag();
315
[e4afb4]316private:
317 int last_atom; //!< number given to last atom
[14de469]318};
319
[cbc5fb]320molecule *NewMolecule();
321void DeleteMolecule(molecule* mol);
322
[14de469]323
324
325#endif /*MOLECULES_HPP_*/
326
Note: See TracBrowser for help on using the repository browser.