source: src/molecule.hpp@ 4782599

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

FIX: FillVoidWithMolecule() now centers filler molecule at its center of gravity.

  • this is the only sensible option if we later rotate the molecule.
  • atom::clone() reduced a lot, as copy constructors contains it all.
  • FillVoidWithMolecule() - filler is now selected to reside entirely within the domain. Otherwise, we seg'fault on save on exit, as one of the father atoms for all copied atoms is missing and hence, we cannot look at its additional...Data for various parsers.
  • new function molecule::removeAtomsInMolecule() which destroys all the molecule's atoms.

TESTFIXES:

  • Filling/3: filled water box has changed due to different center of water molecules.
  • Property mode set to 100755
File size: 13.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 "PointCloud.hpp"
28#include "CodePatterns/Observer.hpp"
29#include "CodePatterns/ObservedIterator.hpp"
30#include "CodePatterns/Cacheable.hpp"
31#include "Formula.hpp"
32#include "AtomSet.hpp"
33
34#include "Descriptors/MoleculeDescriptor_impl.hpp"
35
36/****************************************** forward declarations *****************************/
37
38class atom;
39class bond;
40class BondedParticle;
41class BondGraph;
42class element;
43class ForceMatrix;
44class LinkedCell;
45class molecule;
46class MoleculeLeafClass;
47class MoleculeListClass;
48class periodentafel;
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 PointCloud, 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 //int AtomCount; //!< number of atoms, brought up-to-date by CountAtoms()
101 int BondCount; //!< number of atoms, brought up-to-date by CountBonds()
102 mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
103 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
104 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
105 double BondDistance; //!< typical bond distance used in CreateAdjacencyList() and furtheron
106 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
107 //Vector Center; //!< Center of molecule in a global box
108 int IndexNr; //!< index of molecule in a MoleculeListClass
109 char name[MAXSTRINGSIZE]; //!< arbitrary name
110
111private:
112 Formula formula;
113 Cacheable<int> AtomCount;
114 moleculeId_t id;
115 atomSet atoms; //<!list of atoms
116 atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
117protected:
118 //void CountAtoms();
119 /**
120 * this iterator type should be used for internal variables, \
121 * since it will not lock
122 */
123 typedef atomSet::iterator internal_iterator;
124
125 molecule(const periodentafel * const teil);
126 virtual ~molecule();
127
128public:
129 //getter and setter
130 const std::string getName() const;
131 int getAtomCount() const;
132 int doCountAtoms();
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 TesselPoint * getValue(const_iterator &rhs) const;
145 TesselPoint * getValue(iterator &rhs) const;
146 iterator begin();
147 const_iterator begin() const;
148 iterator end();
149 const_iterator end() const;
150 bool empty() const;
151 size_t size() const;
152 const_iterator erase(const_iterator loc);
153 const_iterator erase(atom * key);
154 const_iterator find(atom * key) const;
155 pair<iterator, bool> insert(atom * const key);
156 bool containsAtom(atom* key);
157
158 // re-definition of virtual functions from PointCloud
159 const char * const GetName() const;
160 Vector *GetCenter() const;
161 TesselPoint *GetPoint() const;
162 int GetMaxId() const;
163 void GoToNext() const;
164 void GoToFirst() const;
165 bool IsEmpty() const;
166 bool IsEnd() const;
167
168 /// remove atoms from molecule.
169 bool AddAtom(atom *pointer);
170 bool RemoveAtom(atom *pointer);
171 bool UnlinkAtom(atom *pointer);
172 bool CleanupMolecule();
173 void removeAtomsinMolecule();
174
175 /// Add/remove atoms to/from molecule.
176 atom * AddCopyAtom(atom *pointer);
177 bool AddXYZFile(string filename);
178 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
179 bond * AddBond(atom *first, atom *second, int degree = 1);
180 bool RemoveBond(bond *pointer);
181 bool RemoveBonds(atom *BondPartner);
182 bool hasBondStructure() const;
183 unsigned int CountBonds() const;
184
185 /// Find atoms.
186 atom * FindAtom(int Nr) const;
187 atom * AskAtom(string text);
188
189 /// Count and change present atoms' coordination.
190 bool CenterInBox();
191 bool BoundInBox();
192 void CenterEdge(Vector *max);
193 void CenterOrigin();
194 void CenterPeriodic();
195 void CenterAtVector(Vector *newcenter);
196 void Translate(const Vector *x);
197 void TranslatePeriodically(const Vector *trans);
198 void Mirror(const Vector *x);
199 void Align(Vector *n);
200 void Scale(const double ** const factor);
201 void DeterminePeriodicCenter(Vector &center);
202 Vector * DetermineCenterOfGravity() const;
203 Vector * DetermineCenterOfAll() const;
204 Vector * DetermineCenterOfBox() const;
205 void SetNameFromFilename(const char *filename);
206 void SetBoxDimension(Vector *dim);
207 void ScanForPeriodicCorrection();
208 bool VerletForceIntegration(char *file, config &configuration, const size_t offset);
209 double VolumeOfConvexEnvelope(bool IsAngstroem);
210
211 double ConstrainedPotential(struct EvaluatePotential &Params);
212 double MinimiseConstrainedPotential(atom **&permutation, int startstep, int endstep, bool IsAngstroem);
213 void EvaluateConstrainedForces(int startstep, int endstep, atom **PermutationMap, ForceMatrix *Force);
214 bool LinearInterpolationBetweenConfiguration(int startstep, int endstep, std::string prefix, config &configuration, bool MapByIdentity);
215
216 bool CheckBounds(const Vector *x) const;
217 void GetAlignvector(struct lsq_params * par) const;
218
219 /// Initialising routines in fragmentation
220 void CreateAdjacencyListFromDbondFile(ifstream *output);
221 void CreateAdjacencyList(double bonddistance, bool IsAngstroem, void(BondGraph::*f)(BondedParticle * const , BondedParticle * const , double &, double &, bool), BondGraph *BG = NULL);
222 int CorrectBondDegree() const;
223 void OutputBondsList() const;
224 void CyclicBondAnalysis() const;
225 void OutputGraphInfoPerAtom() const;
226 void OutputGraphInfoPerBond() const;
227
228 // Graph analysis
229 MoleculeLeafClass * DepthFirstSearchAnalysis(std::deque<bond *> *&BackEdgeStack) const;
230 void CyclicStructureAnalysis(std::deque<bond *> *BackEdgeStack, int *&MinimumRingSize) const;
231 bool PickLocalBackEdges(atom **ListOfLocalAtoms, std::deque<bond *> *&ReferenceStack, std::deque<bond *> *&LocalStack) const;
232 bond * FindNextUnused(atom *vertex) const;
233 void SetNextComponentNumber(atom *vertex, int nr) const;
234 void ResetAllBondsToUnused() const;
235 int CountCyclicBonds();
236 bool CheckForConnectedSubgraph(KeySet *Fragment);
237 string GetColor(enum Shading color) const;
238 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
239
240 molecule *CopyMolecule() const;
241 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
242
243 /// Fragment molecule by two different approaches:
244 int FragmentMolecule(int Order, std::string &prefix);
245 bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
246 bool StoreBondsToFile(std::string filename, std::string path = "");
247 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
248 bool CheckAdjacencyFileAgainstMolecule(std::string &path, atom **ListOfAtoms);
249 bool ParseOrderAtSiteFromFile(std::string &path);
250 bool StoreOrderAtSiteFile(std::string &path);
251 bool StoreForcesFile(MoleculeListClass *BondFragments, std::string &path, int *SortIndex);
252 bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
253 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
254 void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
255 /// -# BOSSANOVA
256 void FragmentBOSSANOVA(Graph *&FragmentList, KeyStack &RootStack, int *MinimumRingSize);
257 int PowerSetGenerator(int Order, struct UniqueFragments &FragmentSearch, KeySet RestrictedKeySet);
258 bool BuildInducedSubgraph(const molecule *Father);
259 molecule * StoreFragmentFromKeySet(KeySet &Leaflet, bool IsAngstroem);
260 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder);
261 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
262 int GuesstimateFragmentCount(int order);
263
264 // Recognize doubly appearing molecules in a list of them
265 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
266
267 // Output routines.
268 bool Output(std::ostream * const output) const;
269 bool OutputTrajectories(ofstream * const output) const;
270 void OutputListOfBonds() const;
271 bool OutputXYZ(ofstream * const output) const;
272 bool OutputTrajectoriesXYZ(ofstream * const output);
273 bool Checkout(ofstream * const output) const;
274 bool OutputTemperatureFromTrajectories(ofstream * const output, int startstep, int endstep);
275
276 // Manipulation routines
277 void flipActiveFlag();
278
279private:
280 void init_DFS(struct DFSAccounting&) const;
281 int last_atom; //!< number given to last atom
282 mutable internal_iterator InternalPointer; //!< internal pointer for PointCloud
283};
284
285molecule *NewMolecule();
286void DeleteMolecule(molecule* mol);
287
288/** A list of \a molecule classes.
289 */
290class MoleculeListClass : public Observable
291{
292public:
293 MoleculeList ListOfMolecules; //!< List of the contained molecules
294 int MaxIndex;
295
296 MoleculeListClass(World *world);
297 ~MoleculeListClass();
298
299 bool AddHydrogenCorrection(std::string &path);
300 bool StoreForcesFile(std::string &path, int *SortIndex);
301 void insert(molecule *mol);
302 void erase(molecule *mol);
303 molecule * ReturnIndex(int index);
304 bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
305 int NumberOfActiveMolecules();
306 void Enumerate(ostream *out);
307 void Output(ofstream *out);
308 int CountAllAtoms() const;
309
310 // Methods moved here from the menus
311 // TODO: more refactoring needed on these methods
312 void createNewMolecule(periodentafel *periode);
313 void loadFromXYZ(periodentafel *periode);
314 void setMoleculeFilename();
315 void parseXYZIntoMolecule();
316 void eraseMolecule();
317
318private:
319 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
320};
321
322/** A leaf for a tree of \a molecule class
323 * Wraps molecules in a tree structure
324 */
325class MoleculeLeafClass
326{
327public:
328 molecule *Leaf; //!< molecule of this leaf
329 //MoleculeLeafClass *UpLeaf; //!< Leaf one level up
330 //MoleculeLeafClass *DownLeaf; //!< First leaf one level down
331 MoleculeLeafClass *previous; //!< Previous leaf on this level
332 MoleculeLeafClass *next; //!< Next leaf on this level
333
334 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
335 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
336 ~MoleculeLeafClass();
337
338 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
339 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
340 bool FillRootStackForSubgraphs(KeyStack *&RootStack, bool *AtomMask, int &FragmentCounter);
341 bool AssignKeySetsToFragment(molecule *reference, Graph *KeySetList, atom ***&ListOfLocalAtoms, Graph **&FragmentList, int &FragmentCounter, bool FreeList = false);
342 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount, bool &FreeList);
343 void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
344 int Count() const;
345};
346
347#endif /*MOLECULES_HPP_*/
348
Note: See TracBrowser for help on using the repository browser.