source: src/molecule.hpp@ 9e23a3

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 9e23a3 was 9e23a3, checked in by Frederik Heber <heber@…>, 15 years ago

Rewrote MinimiseConstrainedPotential into a functor in Dynamics/.

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