source: src/molecule.hpp@ 458c31

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 Candidate_v1.7.0 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 458c31 was 458c31, checked in by Frederik Heber <heber@…>, 15 years ago

molecule::BondCount is now Cachable and private.

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