source: src/molecule.hpp@ 2a0271

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 2a0271 was 560bbe, checked in by Frederik Heber <heber@…>, 13 years ago

AtomicInfo now also (re)stores ParticleInfo::Nr, molecule has own IdPool.

  • molecule now also has an internal IdPool to be able to hand out unique ids, according to uniqueId policy.
  • new functions: molecule::changeAtomNr(), molecule::setAtomName()
  • molecule::erase() and ::insert() release and set the id (and the name).
  • molecule::setAtomName() uses getNr() with id increased by one.
  • AtomicInfo stores and sets ParticleInfo::Nr.
  • atom::changeNr() is similar to changeId() only for the molecule.
  • molecule::AddAtom() does not set the name anymore, is done by ::insert().
  • simplified molecule::doCountAtoms() a lot, no more naming of atoms.
  • SPEEDUP: This speeds up the GUI already a lot.
  • TESTFIX: changed regression test Tesselation/BigNonConvex due to different ordering of node ids (due to above), surface is still the same (checked).
  • Property mode set to 100755
File size: 8.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 <boost/iterator/transform_iterator.hpp>
24
25#include <string>
26
27#include "Atom/AtomSet.hpp"
28#include "CodePatterns/Cacheable.hpp"
29#include "CodePatterns/Observer/Observable.hpp"
30#include "CodePatterns/Observer/ObservedIterator.hpp"
31#include "Descriptors/AtomIdDescriptor.hpp"
32#include "Fragmentation/HydrogenSaturation_enum.hpp"
33#include "Formula.hpp"
34#include "Helpers/defs.hpp"
35#include "IdPool_policy.hpp"
36#include "IdPool.hpp"
37#include "types.hpp"
38
39// TODO: Was is the include of MoleculeDescriptor_impl.hpp doing in molecule.hpp
40#include "Descriptors/MoleculeDescriptor_impl.hpp"
41
42/****************************************** forward declarations *****************************/
43
44class atom;
45class bond;
46class BondedParticle;
47class BondGraph;
48class DepthFirstSearchAnalysis;
49class element;
50class ForceMatrix;
51class Graph;
52class LinkedCell_deprecated;
53class molecule;
54class MoleculeLeafClass;
55class MoleculeListClass;
56class periodentafel;
57class RealSpaceMatrix;
58class Vector;
59class Shape;
60
61/******************************** Some definitions for easier reading **********************************/
62
63struct FromIdToAtom :
64 public std::unary_function<atom *, atomId_t>
65{
66 atom * operator()(atomId_t id) const {
67 return World::getInstance().getAtom(AtomById(id));
68 }
69};
70
71/************************************* Class definitions ****************************************/
72
73/** The complete molecule.
74 * Class incorporates number of types
75 */
76class molecule : public Observable
77{
78 friend molecule *NewMolecule();
79 friend void DeleteMolecule(molecule *);
80
81public:
82 typedef std::set<atomId_t> atomIdSet;
83 typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
84 typedef boost::transform_iterator<FromIdToAtom, atomIdSet::const_iterator, const atom *, atomId_t const &> const_iterator;
85
86 const periodentafel * const elemente; //!< periodic table with each element
87 int MDSteps; //!< The number of MD steps in Trajectories
88 mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
89 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
90 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
91 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
92 int IndexNr; //!< index of molecule in a MoleculeListClass
93 char name[MAXSTRINGSIZE]; //!< arbitrary name
94
95private:
96 Formula formula;
97 Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
98 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
99 moleculeId_t id;
100 atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
101 IdPool<atomId_t, uniqueId> atomIdPool; //!< pool of internal ids such that way may guarantee uniqueness
102
103protected:
104
105 molecule(const periodentafel * const teil);
106 virtual ~molecule();
107
108public:
109 //getter and setter
110 const std::string getName() const;
111 int getAtomCount() const;
112 int doCountAtoms();
113 int getBondCount() const;
114 int doCountBonds() const;
115 moleculeId_t getId() const;
116 void setId(moleculeId_t);
117 void setName(const std::string);
118 const Formula &getFormula() const;
119 unsigned int getElementCount() const;
120 bool hasElement(const element*) const;
121 bool hasElement(atomicNumber_t) const;
122 bool hasElement(const std::string&) const;
123
124 virtual bool changeId(atomId_t newId);
125
126 World::AtomComposite getAtomSet() const;
127
128 iterator begin();
129 const_iterator begin() const;
130 iterator end();
131 const_iterator end() const;
132 bool empty() const;
133 size_t size() const;
134 const_iterator find(atom * key) const;
135 pair<iterator, bool> insert(atom * const key);
136 bool containsAtom(atom* key);
137
138private:
139 friend void atom::removeFromMolecule();
140 /** Erase an atom from the list.
141 * \note This should only be called by atom::removeFromMolecule(),
142 * otherwise it is not assured that the atom knows about it.
143 *
144 * @param loc locator to atom in list
145 * @return iterator to just after removed item (compliant with standard)
146 */
147 const_iterator erase(const_iterator loc);
148 /** Erase an atom from the list.
149 * \note This should only be called by atom::removeFromMolecule(),
150 * otherwise it is not assured that the atom knows about it.
151 *
152 * @param *key key to atom in list
153 * @return iterator to just after removed item (compliant with standard)
154 */
155 const_iterator erase(atom * key);
156
157private:
158 friend bool atom::changeNr(int newId);
159 /**
160 * used when changing an ParticleInfo::Nr.
161 * Note that this number is local with this molecule.
162 * Unless you are calling this method from inside an atom don't fiddle with the third parameter.
163 *
164 * @param oldNr old Nr
165 * @param newNr new Nr to set
166 * @param *target ref to atom
167 * @return indicates wether the change could be done or not.
168 */
169 bool changeAtomNr(int oldNr, int newNr, atom* target=0);
170
171 /** Sets the name of the atom.
172 *
173 * The name is set via its element symbol and its internal ParticleInfo::Nr.
174 *
175 * @param _atom atom whose name to set
176 */
177 void setAtomName(atom *_atom) const;
178
179public:
180
181 /// remove atoms from molecule.
182 bool AddAtom(atom *pointer);
183 bool RemoveAtom(atom *pointer);
184 bool UnlinkAtom(atom *pointer);
185 bool CleanupMolecule();
186 void removeAtomsinMolecule();
187
188 /// Add/remove atoms to/from molecule.
189 atom * AddCopyAtom(atom *pointer);
190 bool AddXYZFile(string filename);
191 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
192 bond * AddBond(atom *first, atom *second, int degree = 1);
193 bool RemoveBond(bond *pointer);
194 bool RemoveBonds(atom *BondPartner);
195 bool hasBondStructure() const;
196
197 /// Find atoms.
198 atom * FindAtom(int Nr) const;
199 atom * AskAtom(string text);
200 bool isInMolecule(const atom * const _atom);
201
202 /// Count and change present atoms' coordination.
203 bool CenterInBox();
204 bool BoundInBox();
205 void CenterEdge(Vector *max);
206 void CenterOrigin();
207 void CenterPeriodic();
208 void CenterAtVector(Vector *newcenter);
209 void Translate(const Vector *x);
210 void TranslatePeriodically(const Vector *trans);
211 void Mirror(const Vector *x);
212 void Align(Vector *n);
213 void Scale(const double ** const factor);
214 void DeterminePeriodicCenter(Vector &center, const enum HydrogenSaturation _saturation = DoSaturate);
215 Vector * DetermineCenterOfGravity() const;
216 Vector * DetermineCenterOfAll() const;
217 Vector * DetermineCenterOfBox() const;
218 void SetNameFromFilename(const char *filename);
219 void SetBoxDimension(Vector *dim);
220 bool ScanForPeriodicCorrection();
221 double VolumeOfConvexEnvelope(bool IsAngstroem);
222 RealSpaceMatrix getInertiaTensor() const;
223 void RotateToPrincipalAxisSystem(Vector &Axis);
224
225 bool CheckBounds(const Vector *x) const;
226 void GetAlignvector(struct lsq_params * par) const;
227
228 /// Initialising routines in fragmentation
229 void OutputBondsList() const;
230
231 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
232
233 molecule *CopyMolecule() const;
234 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
235
236 /// Fragment molecule by two different approaches:
237 bool StoreBondsToFile(std::string filename, std::string path = "");
238 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
239 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
240
241 // Recognize doubly appearing molecules in a list of them
242 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
243 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
244 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
245
246 // Output routines.
247 bool Output(std::ostream * const output) const;
248 bool OutputTrajectories(ofstream * const output) const;
249 void OutputListOfBonds() const;
250 bool OutputXYZ(ofstream * const output) const;
251 bool OutputTrajectoriesXYZ(ofstream * const output);
252 bool Checkout(ofstream * const output) const;
253
254 // Manipulation routines
255 void flipActiveFlag();
256
257private:
258 int last_atom; //!< number given to last atom
259};
260
261molecule *NewMolecule();
262void DeleteMolecule(molecule* mol);
263
264
265
266#endif /*MOLECULES_HPP_*/
267
Note: See TracBrowser for help on using the repository browser.