source: src/molecule.hpp@ e355762

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 e355762 was 8009ce, checked in by Frederik Heber <heber@…>, 14 years ago

Rewrote OutputTemperature into a functor in Dynamics/

  • Property mode set to 100755
File size: 11.1 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 bool VerletForceIntegration(char *file, config &configuration, const size_t offset);
179 double VolumeOfConvexEnvelope(bool IsAngstroem);
180 RealSpaceMatrix getInertiaTensor() const;
181 void RotateToPrincipalAxisSystem(Vector &Axis);
182
183 bool CheckBounds(const Vector *x) const;
184 void GetAlignvector(struct lsq_params * par) const;
185
186 /// Initialising routines in fragmentation
187 void CreateAdjacencyListFromDbondFile(ifstream *output,unsigned int skiplines,int id_offset);
188 void OutputBondsList() const;
189 void CyclicBondAnalysis() const;
190 void OutputGraphInfoPerAtom() const;
191 void OutputGraphInfoPerBond() const;
192
193 // Graph analysis
194 MoleculeLeafClass * DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const;
195 void CyclicStructureAnalysis(std::deque<bond *> *BackEdgeStack, int *&MinimumRingSize) const;
196 bool PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const;
197 bond * FindNextUnused(atom *vertex) const;
198 void SetNextComponentNumber(atom *vertex, int nr) const;
199 void ResetAllBondsToUnused() const;
200 int CountCyclicBonds();
201 bool CheckForConnectedSubgraph(KeySet *Fragment);
202 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
203
204 molecule *CopyMolecule() const;
205 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
206
207 /// Fragment molecule by two different approaches:
208 int FragmentMolecule(int Order, std::string &prefix);
209 bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
210 bool StoreBondsToFile(std::string filename, std::string path = "");
211 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
212 bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
213 bool ParseOrderAtSiteFromFile(std::string &path);
214 bool StoreOrderAtSiteFile(std::string &path);
215 bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
216 bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
217 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
218 void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
219
220 /// -# BOSSANOVA
221 void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
222 int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
223 bool BuildInducedSubgraph(const molecule *Father);
224 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
225 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
226 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
227 int GuesstimateFragmentCount(int order);
228
229 // Recognize doubly appearing molecules in a list of them
230 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
231
232 // Output routines.
233 bool Output(std::ostream * const output) const;
234 bool OutputTrajectories(ofstream * const output) const;
235 void OutputListOfBonds() const;
236 bool OutputXYZ(ofstream * const output) const;
237 bool OutputTrajectoriesXYZ(ofstream * const output);
238 bool Checkout(ofstream * const output) const;
239
240 // Manipulation routines
241 void flipActiveFlag();
242
243private:
244 void init_DFS(struct DFSAccounting&) const;
245 int last_atom; //!< number given to last atom
246};
247
248molecule *NewMolecule();
249void DeleteMolecule(molecule* mol);
250
251/** A list of \a molecule classes.
252 */
253class MoleculeListClass : public Observable
254{
255public:
256 MoleculeList ListOfMolecules; //!< List of the contained molecules
257 int MaxIndex;
258
259 MoleculeListClass(World *world);
260 ~MoleculeListClass();
261
262 bool AddHydrogenCorrection(std::string &path);
263 bool StoreForcesFile(std::string &path, int *SortIndex);
264 void insert(molecule *mol);
265 void erase(molecule *mol);
266 molecule * ReturnIndex(int index);
267 bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
268 int NumberOfActiveMolecules();
269 void Enumerate(ostream *out);
270 void Output(ofstream *out);
271 int CountAllAtoms() const;
272
273 // Methods moved here from the menus
274 // TODO: more refactoring needed on these methods
275 void createNewMolecule(periodentafel *periode);
276 void loadFromXYZ(periodentafel *periode);
277 void setMoleculeFilename();
278 void parseXYZIntoMolecule();
279 void eraseMolecule();
280
281private:
282 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
283};
284
285/** A leaf for a tree of \a molecule class
286 * Wraps molecules in a tree structure
287 */
288class MoleculeLeafClass
289{
290public:
291 molecule *Leaf; //!< molecule of this leaf
292 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
293 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
294 MoleculeLeafClass *previous; //!< Previous leaf on this level
295 MoleculeLeafClass *next; //!< Next leaf on this level
296
297 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
298 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
299 ~MoleculeLeafClass();
300
301 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
302 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
303 bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
304 bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
305 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount, bool &FreeList);
306 void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
307 int Count() const;
308};
309
310#endif /*MOLECULES_HPP_*/
311
Note: See TracBrowser for help on using the repository browser.