source: src/molecule.hpp@ 2fa1dc

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 2fa1dc was 49c059, checked in by Frederik Heber <heber@…>, 14 years ago

Moved DepthFirstSearchAnalysis into functor in Graph/.

Smaller fixes:

TESTFIXES:

  • Property mode set to 100755
File size: 10.7 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 "types.hpp"
26#include "graph.hpp"
27#include "CodePatterns/Observer.hpp"
28#include "CodePatterns/ObservedIterator.hpp"
29#include "CodePatterns/Cacheable.hpp"
30#include "Formula.hpp"
31#include "AtomSet.hpp"
32
33#include "Descriptors/MoleculeDescriptor_impl.hpp"
34
35/****************************************** forward declarations *****************************/
36
37class atom;
38class bond;
39class BondedParticle;
40class BondGraph;
41class DepthFirstSearchAnalysis;
42class element;
43class ForceMatrix;
44class LinkedCell;
45class molecule;
46class MoleculeLeafClass;
47class MoleculeListClass;
48class periodentafel;
49class RealSpaceMatrix;
50class Vector;
51class Shape;
52
53/******************************** Some definitions for easier reading **********************************/
54
55#define MoleculeList list <molecule *>
56#define MoleculeListTest pair <MoleculeList::iterator, bool>
57
58/************************************* Class definitions ****************************************/
59
60/** The complete molecule.
61 * Class incorporates number of types
62 */
63class molecule : public Observable
64{
65 friend molecule *NewMolecule();
66 friend void DeleteMolecule(molecule *);
67
68public:
69 typedef ATOMSET(std::list) atomSet;
70 typedef ATOMSET(std::vector) atomVector;
71 typedef std::set<atomId_t> atomIdSet;
72 typedef ObservedIterator<atomSet> iterator;
73 typedef atomSet::const_iterator const_iterator;
74
75 const periodentafel * const elemente; //!< periodic table with each element
76 // old deprecated atom handling
77 //atom *start; //!< start of atom list
78 //atom *end; //!< end of atom list
79 //bond *first; //!< start of bond list
80 //bond *last; //!< end of bond list
81 int MDSteps; //!< The number of MD steps in Trajectories
82 mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
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 //Vector Center; //!< Center of molecule in a global box
87 int IndexNr; //!< index of molecule in a MoleculeListClass
88 char name[MAXSTRINGSIZE]; //!< arbitrary name
89
90private:
91 Formula formula;
92 Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
93 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
94 moleculeId_t id;
95 atomSet atoms; //<!list of atoms
96 atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
97protected:
98 //void CountAtoms();
99 /**
100 * this iterator type should be used for internal variables, \
101 * since it will not lock
102 */
103 typedef atomSet::iterator internal_iterator;
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 atomVector 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
157public:
158
159 /// remove atoms from molecule.
160 bool AddAtom(atom *pointer);
161 bool RemoveAtom(atom *pointer);
162 bool UnlinkAtom(atom *pointer);
163 bool CleanupMolecule();
164 void removeAtomsinMolecule();
165
166 /// Add/remove atoms to/from molecule.
167 atom * AddCopyAtom(atom *pointer);
168 bool AddXYZFile(string filename);
169 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
170 bond * AddBond(atom *first, atom *second, int degree = 1);
171 bool RemoveBond(bond *pointer);
172 bool RemoveBonds(atom *BondPartner);
173 bool hasBondStructure() const;
174
175 /// Find atoms.
176 atom * FindAtom(int Nr) const;
177 atom * AskAtom(string text);
178
179 /// Count and change present atoms' coordination.
180 bool CenterInBox();
181 bool BoundInBox();
182 void CenterEdge(Vector *max);
183 void CenterOrigin();
184 void CenterPeriodic();
185 void CenterAtVector(Vector *newcenter);
186 void Translate(const Vector *x);
187 void TranslatePeriodically(const Vector *trans);
188 void Mirror(const Vector *x);
189 void Align(Vector *n);
190 void Scale(const double ** const factor);
191 void DeterminePeriodicCenter(Vector &center);
192 Vector * DetermineCenterOfGravity() const;
193 Vector * DetermineCenterOfAll() const;
194 Vector * DetermineCenterOfBox() const;
195 void SetNameFromFilename(const char *filename);
196 void SetBoxDimension(Vector *dim);
197 bool ScanForPeriodicCorrection();
198 double VolumeOfConvexEnvelope(bool IsAngstroem);
199 RealSpaceMatrix getInertiaTensor() const;
200 void RotateToPrincipalAxisSystem(Vector &Axis);
201
202 bool CheckBounds(const Vector *x) const;
203 void GetAlignvector(struct lsq_params * par) const;
204
205 /// Initialising routines in fragmentation
206 void OutputBondsList() const;
207
208 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
209
210 molecule *CopyMolecule() const;
211 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
212
213 /// Fragment molecule by two different approaches:
214 int FragmentMolecule(int Order, std::string &prefix, DepthFirstSearchAnalysis &DFS);
215 bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, std::string path = "");
216 bool StoreBondsToFile(std::string filename, std::string path = "");
217 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
218 bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
219 bool ParseOrderAtSiteFromFile(std::string &path);
220 bool StoreOrderAtSiteFile(std::string &path);
221 bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
222 bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
223 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
224
225 /// -# BOSSANOVA
226 void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack);
227 int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
228 bool BuildInducedSubgraph(const molecule *Father);
229 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
230 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
231 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
232 int GuesstimateFragmentCount(int order);
233
234 // Recognize doubly appearing molecules in a list of them
235 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
236 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
237 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
238
239 // Output routines.
240 bool Output(std::ostream * const output) const;
241 bool OutputTrajectories(ofstream * const output) const;
242 void OutputListOfBonds() const;
243 bool OutputXYZ(ofstream * const output) const;
244 bool OutputTrajectoriesXYZ(ofstream * const output);
245 bool Checkout(ofstream * const output) const;
246
247 // Manipulation routines
248 void flipActiveFlag();
249
250private:
251 int last_atom; //!< number given to last atom
252};
253
254molecule *NewMolecule();
255void DeleteMolecule(molecule* mol);
256
257/** A list of \a molecule classes.
258 */
259class MoleculeListClass : public Observable
260{
261public:
262 MoleculeList ListOfMolecules; //!< List of the contained molecules
263 int MaxIndex;
264
265 MoleculeListClass(World *world);
266 ~MoleculeListClass();
267
268 bool AddHydrogenCorrection(std::string &path);
269 bool StoreForcesFile(std::string &path, int *SortIndex);
270 void insert(molecule *mol);
271 void erase(molecule *mol);
272 molecule * ReturnIndex(int index);
273 bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
274 int NumberOfActiveMolecules();
275 void Enumerate(ostream *out);
276 void Output(ofstream *out);
277 int CountAllAtoms() const;
278
279 // Methods moved here from the menus
280 // TODO: more refactoring needed on these methods
281 void createNewMolecule(periodentafel *periode);
282 void loadFromXYZ(periodentafel *periode);
283 void setMoleculeFilename();
284 void parseXYZIntoMolecule();
285 void eraseMolecule();
286
287private:
288 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
289};
290
291/** A leaf for a tree of \a molecule class
292 * Wraps molecules in a tree structure
293 */
294class MoleculeLeafClass
295{
296public:
297 molecule *Leaf; //!< molecule of this leaf
298 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
299 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
300 MoleculeLeafClass *previous; //!< Previous leaf on this level
301 MoleculeLeafClass *next; //!< Next leaf on this level
302
303 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
304 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
305 ~MoleculeLeafClass();
306
307 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
308 bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
309 bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
310 void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
311 int Count() const;
312};
313
314#endif /*MOLECULES_HPP_*/
315
Note: See TracBrowser for help on using the repository browser.