source: src/molecule.hpp@ 50c35d

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 50c35d was 6aad6f, checked in by Frederik Heber <heber@…>, 13 years ago

FIX: molecule::containsAtom() is now const and has const param, added AtomIdSet::contains().

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