source: src/molecule.hpp@ 341f22

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 341f22 was 435065, checked in by Frederik Heber <heber@…>, 14 years ago

Rewrote VerletForceIntegration into a functor in Dynamics/.

  • we now have the regression test working with checking against an integrated file which has not been checked though (just by eye and logged output to make sense, not against other code).
  • Property mode set to 100755
File size: 11.0 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 element;
42class ForceMatrix;
43class LinkedCell;
44class molecule;
45class MoleculeLeafClass;
46class MoleculeListClass;
47class periodentafel;
48class RealSpaceMatrix;
49class Vector;
50class Shape;
51
52/******************************** Some definitions for easier reading **********************************/
53
54#define MoleculeList list <molecule *>
55#define MoleculeListTest pair <MoleculeList::iterator, bool>
56
57/************************************* Class definitions ****************************************/
58
59/** The complete molecule.
60 * Class incorporates number of types
61 */
62class molecule : public Observable
63{
64 friend molecule *NewMolecule();
65 friend void DeleteMolecule(molecule *);
66
67public:
68 typedef ATOMSET(std::list) atomSet;
69 typedef ATOMSET(std::vector) atomVector;
70 typedef std::set<atomId_t> atomIdSet;
71 typedef ObservedIterator<atomSet> iterator;
72 typedef atomSet::const_iterator const_iterator;
73
74 const periodentafel * const elemente; //!< periodic table with each element
75 // old deprecated atom handling
76 //atom *start; //!< start of atom list
77 //atom *end; //!< end of atom list
78 //bond *first; //!< start of bond list
79 //bond *last; //!< end of bond list
80 int MDSteps; //!< The number of MD steps in Trajectories
81 mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
82 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
83 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
84 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
85 //Vector Center; //!< Center of molecule in a global box
86 int IndexNr; //!< index of molecule in a MoleculeListClass
87 char name[MAXSTRINGSIZE]; //!< arbitrary name
88
89private:
90 Formula formula;
91 Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
92 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
93 moleculeId_t id;
94 atomSet atoms; //<!list of atoms
95 atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
96protected:
97 //void CountAtoms();
98 /**
99 * this iterator type should be used for internal variables, \
100 * since it will not lock
101 */
102 typedef atomSet::iterator internal_iterator;
103
104 molecule(const periodentafel * const teil);
105 virtual ~molecule();
106
107public:
108 //getter and setter
109 const std::string getName() const;
110 int getAtomCount() const;
111 int doCountAtoms();
112 int getBondCount() const;
113 int doCountBonds() const;
114 moleculeId_t getId() const;
115 void setId(moleculeId_t);
116 void setName(const std::string);
117 const Formula &getFormula() const;
118 unsigned int getElementCount() const;
119 bool hasElement(const element*) const;
120 bool hasElement(atomicNumber_t) const;
121 bool hasElement(const std::string&) const;
122
123 virtual bool changeId(atomId_t newId);
124
125 atomVector getAtomSet() const;
126
127 iterator begin();
128 const_iterator begin() const;
129 iterator end();
130 const_iterator end() const;
131 bool empty() const;
132 size_t size() const;
133 const_iterator erase(const_iterator loc);
134 const_iterator erase(atom * key);
135 const_iterator find(atom * key) const;
136 pair<iterator, bool> insert(atom * const key);
137 bool containsAtom(atom* key);
138
139 /// remove atoms from molecule.
140 bool AddAtom(atom *pointer);
141 bool RemoveAtom(atom *pointer);
142 bool UnlinkAtom(atom *pointer);
143 bool CleanupMolecule();
144 void removeAtomsinMolecule();
145
146 /// Add/remove atoms to/from molecule.
147 atom * AddCopyAtom(atom *pointer);
148 bool AddXYZFile(string filename);
149 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
150 bond * AddBond(atom *first, atom *second, int degree = 1);
151 bool RemoveBond(bond *pointer);
152 bool RemoveBonds(atom *BondPartner);
153 bool hasBondStructure() const;
154
155 /// Find atoms.
156 atom * FindAtom(int Nr) const;
157 atom * AskAtom(string text);
158
159 /// Count and change present atoms' coordination.
160 bool CenterInBox();
161 bool BoundInBox();
162 void CenterEdge(Vector *max);
163 void CenterOrigin();
164 void CenterPeriodic();
165 void CenterAtVector(Vector *newcenter);
166 void Translate(const Vector *x);
167 void TranslatePeriodically(const Vector *trans);
168 void Mirror(const Vector *x);
169 void Align(Vector *n);
170 void Scale(const double ** const factor);
171 void DeterminePeriodicCenter(Vector &center);
172 Vector * DetermineCenterOfGravity() const;
173 Vector * DetermineCenterOfAll() const;
174 Vector * DetermineCenterOfBox() const;
175 void SetNameFromFilename(const char *filename);
176 void SetBoxDimension(Vector *dim);
177 bool ScanForPeriodicCorrection();
178 double VolumeOfConvexEnvelope(bool IsAngstroem);
179 RealSpaceMatrix getInertiaTensor() const;
180 void RotateToPrincipalAxisSystem(Vector &Axis);
181
182 bool CheckBounds(const Vector *x) const;
183 void GetAlignvector(struct lsq_params * par) const;
184
185 /// Initialising routines in fragmentation
186 void CreateAdjacencyListFromDbondFile(ifstream *output,unsigned int skiplines,int id_offset);
187 void OutputBondsList() const;
188 void CyclicBondAnalysis() const;
189 void OutputGraphInfoPerAtom() const;
190 void OutputGraphInfoPerBond() const;
191
192 // Graph analysis
193 MoleculeLeafClass * DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const;
194 void CyclicStructureAnalysis(std::deque<bond *> *BackEdgeStack, int *&MinimumRingSize) const;
195 bool PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const;
196 bond * FindNextUnused(atom *vertex) const;
197 void SetNextComponentNumber(atom *vertex, int nr) const;
198 void ResetAllBondsToUnused() const;
199 int CountCyclicBonds();
200 bool CheckForConnectedSubgraph(KeySet *Fragment);
201 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
202
203 molecule *CopyMolecule() const;
204 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
205
206 /// Fragment molecule by two different approaches:
207 int FragmentMolecule(int Order, std::string &prefix);
208 bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
209 bool StoreBondsToFile(std::string filename, std::string path = "");
210 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
211 bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
212 bool ParseOrderAtSiteFromFile(std::string &path);
213 bool StoreOrderAtSiteFile(std::string &path);
214 bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
215 bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
216 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
217 void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
218
219 /// -# BOSSANOVA
220 void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
221 int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
222 bool BuildInducedSubgraph(const molecule *Father);
223 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
224 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
225 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
226 int GuesstimateFragmentCount(int order);
227
228 // Recognize doubly appearing molecules in a list of them
229 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
230
231 // Output routines.
232 bool Output(std::ostream * const output) const;
233 bool OutputTrajectories(ofstream * const output) const;
234 void OutputListOfBonds() const;
235 bool OutputXYZ(ofstream * const output) const;
236 bool OutputTrajectoriesXYZ(ofstream * const output);
237 bool Checkout(ofstream * const output) const;
238
239 // Manipulation routines
240 void flipActiveFlag();
241
242private:
243 void init_DFS(struct DFSAccounting&) const;
244 int last_atom; //!< number given to last atom
245};
246
247molecule *NewMolecule();
248void DeleteMolecule(molecule* mol);
249
250/** A list of \a molecule classes.
251 */
252class MoleculeListClass : public Observable
253{
254public:
255 MoleculeList ListOfMolecules; //!< List of the contained molecules
256 int MaxIndex;
257
258 MoleculeListClass(World *world);
259 ~MoleculeListClass();
260
261 bool AddHydrogenCorrection(std::string &path);
262 bool StoreForcesFile(std::string &path, int *SortIndex);
263 void insert(molecule *mol);
264 void erase(molecule *mol);
265 molecule * ReturnIndex(int index);
266 bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
267 int NumberOfActiveMolecules();
268 void Enumerate(ostream *out);
269 void Output(ofstream *out);
270 int CountAllAtoms() const;
271
272 // Methods moved here from the menus
273 // TODO: more refactoring needed on these methods
274 void createNewMolecule(periodentafel *periode);
275 void loadFromXYZ(periodentafel *periode);
276 void setMoleculeFilename();
277 void parseXYZIntoMolecule();
278 void eraseMolecule();
279
280private:
281 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
282};
283
284/** A leaf for a tree of \a molecule class
285 * Wraps molecules in a tree structure
286 */
287class MoleculeLeafClass
288{
289public:
290 molecule *Leaf; //!< molecule of this leaf
291 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
292 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
293 MoleculeLeafClass *previous; //!< Previous leaf on this level
294 MoleculeLeafClass *next; //!< Next leaf on this level
295
296 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
297 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
298 ~MoleculeLeafClass();
299
300 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
301 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
302 bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
303 bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
304 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount, bool &FreeList);
305 void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
306 int Count() const;
307};
308
309#endif /*MOLECULES_HPP_*/
310
Note: See TracBrowser for help on using the repository browser.