source: src/molecule.hpp@ 00b59d5

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 00b59d5 was 1f91f4, checked in by Frederik Heber <heber@…>, 14 years ago

factored functionality in PrincipalAxisSystemAction() and RotateToPrincipalAxisSystemAction() into class molecule:

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