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 Candidate_v1.7.0 Candidate_v1.7.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
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"
[ad011c]27#include "CodePatterns/Observer.hpp"
28#include "CodePatterns/ObservedIterator.hpp"
29#include "CodePatterns/Cacheable.hpp"
[389cc8]30#include "Formula.hpp"
[14d541]31#include "AtomSet.hpp"
[14de469]32
[97ebf8]33#include "Descriptors/MoleculeDescriptor_impl.hpp"
34
[f66195]35/****************************************** forward declarations *****************************/
36
37class atom;
38class bond;
[b70721]39class BondedParticle;
40class BondGraph;
[f66195]41class element;
42class ForceMatrix;
43class LinkedCell;
[14de469]44class molecule;
[2319ed]45class MoleculeLeafClass;
[14de469]46class MoleculeListClass;
[f66195]47class periodentafel;
[1f91f4]48class RealSpaceMatrix;
[f66195]49class Vector;
[c550dd]50class Shape;
[14de469]51
52/******************************** Some definitions for easier reading **********************************/
53
[edb93c]54#define MoleculeList list <molecule *>
55#define MoleculeListTest pair <MoleculeList::iterator, bool>
56
[14de469]57/************************************* Class definitions ****************************************/
58
59/** The complete molecule.
60 * Class incorporates number of types
61 */
[34c43a]62class molecule : public Observable
[e4afb4]63{
[cbc5fb]64 friend molecule *NewMolecule();
65 friend void DeleteMolecule(molecule *);
[bd58fb]66
[e4afb4]67public:
68 typedef ATOMSET(std::list) atomSet;
[3738f0]69 typedef ATOMSET(std::vector) atomVector;
[e4afb4]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;
[458c31]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()
[e4afb4]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, \
[d3347e]100 * since it will not lock
[e4afb4]101 */
102 typedef atomSet::iterator internal_iterator;
[ac9b56]103
[e4afb4]104 molecule(const periodentafel * const teil);
105 virtual ~molecule();
[042f82]106
[cbc5fb]107public:
[520c8b]108 //getter and setter
[73a857]109 const std::string getName() const;
[ea7176]110 int getAtomCount() const;
111 int doCountAtoms();
[458c31]112 int getBondCount() const;
113 int doCountBonds() const;
[73a857]114 moleculeId_t getId() const;
[cbc5fb]115 void setId(moleculeId_t);
[520c8b]116 void setName(const std::string);
[73a857]117 const Formula &getFormula() const;
118 unsigned int getElementCount() const;
[389cc8]119 bool hasElement(const element*) const;
120 bool hasElement(atomicNumber_t) const;
121 bool hasElement(const std::string&) const;
122
[a7a087]123 virtual bool changeId(atomId_t newId);
[520c8b]124
[3738f0]125 atomVector getAtomSet() const;
126
[bd58fb]127 iterator begin();
128 const_iterator begin() const;
[e87acf]129 iterator end();
130 const_iterator end() const;
[9879f6]131 bool empty() const;
132 size_t size() const;
[e4afb4]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);
[6cfa36]137 bool containsAtom(atom* key);
[bd58fb]138
[042f82]139 /// remove atoms from molecule.
140 bool AddAtom(atom *pointer);
141 bool RemoveAtom(atom *pointer);
142 bool UnlinkAtom(atom *pointer);
143 bool CleanupMolecule();
[9df680]144 void removeAtomsinMolecule();
[042f82]145
146 /// Add/remove atoms to/from molecule.
147 atom * AddCopyAtom(atom *pointer);
148 bool AddXYZFile(string filename);
[e138de]149 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
[cee0b57]150 bond * AddBond(atom *first, atom *second, int degree = 1);
[042f82]151 bool RemoveBond(bond *pointer);
152 bool RemoveBonds(atom *BondPartner);
[e4afb4]153 bool hasBondStructure() const;
[042f82]154
155 /// Find atoms.
156 atom * FindAtom(int Nr) const;
157 atom * AskAtom(string text);
158
159 /// Count and change present atoms' coordination.
[e138de]160 bool CenterInBox();
161 bool BoundInBox();
162 void CenterEdge(Vector *max);
163 void CenterOrigin();
164 void CenterPeriodic();
165 void CenterAtVector(Vector *newcenter);
[042f82]166 void Translate(const Vector *x);
167 void TranslatePeriodically(const Vector *trans);
168 void Mirror(const Vector *x);
169 void Align(Vector *n);
[776b64]170 void Scale(const double ** const factor);
[437922]171 void DeterminePeriodicCenter(Vector &center);
[4bb63c]172 Vector * DetermineCenterOfGravity() const;
[e138de]173 Vector * DetermineCenterOfAll() const;
[eddea2]174 Vector * DetermineCenterOfBox() const;
[437922]175 void SetNameFromFilename(const char *filename);
[042f82]176 void SetBoxDimension(Vector *dim);
[3c58f8]177 bool ScanForPeriodicCorrection();
[ef7d30]178 bool VerletForceIntegration(char *file, config &configuration, const size_t offset);
[e138de]179 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]180 RealSpaceMatrix getInertiaTensor() const;
181 void RotateToPrincipalAxisSystem(Vector &Axis);
[042f82]182
[e4afb4]183 bool LinearInterpolationBetweenConfiguration(int startstep, int endstep, std::string prefix, config &configuration, bool MapByIdentity);
184
[042f82]185 bool CheckBounds(const Vector *x) const;
186 void GetAlignvector(struct lsq_params * par) const;
187
188 /// Initialising routines in fragmentation
[0cbad2]189 void CreateAdjacencyListFromDbondFile(ifstream *output,unsigned int skiplines,int id_offset);
[e138de]190 void OutputBondsList() const;
[fa649a]191 void CyclicBondAnalysis() const;
[e138de]192 void OutputGraphInfoPerAtom() const;
193 void OutputGraphInfoPerBond() const;
[b8b75d]194
[042f82]195 // Graph analysis
[a564be]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;
[fa649a]199 bond * FindNextUnused(atom *vertex) const;
200 void SetNextComponentNumber(atom *vertex, int nr) const;
201 void ResetAllBondsToUnused() const;
[e138de]202 int CountCyclicBonds();
203 bool CheckForConnectedSubgraph(KeySet *Fragment);
[266237]204 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
205
[e4afb4]206 molecule *CopyMolecule() const;
[c550dd]207 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
[042f82]208
209 /// Fragment molecule by two different approaches:
[35b698]210 int FragmentMolecule(int Order, std::string &prefix);
211 bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, std::string path = "");
[e4afb4]212 bool StoreBondsToFile(std::string filename, std::string path = "");
213 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
[35b698]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);
[e138de]218 bool CreateMappingLabelsToConfigSequence(int *&SortIndex);
[9879f6]219 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
[e138de]220 void BreadthFirstSearchAdd(molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem);
[b9772a]221
[042f82]222 /// -# BOSSANOVA
[e138de]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);
[03c77c]227 void SPFragmentGenerator(struct UniqueFragments *FragmentSearch, int RootDistance, std::vector<bond *> &BondsSet, int SetDimension, int SubOrder);
[e138de]228 int LookForRemovalCandidate(KeySet *&Leaf, int *&ShortestPathList);
229 int GuesstimateFragmentCount(int order);
[042f82]230
231 // Recognize doubly appearing molecules in a list of them
[e138de]232 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
[042f82]233
234 // Output routines.
[e4afb4]235 bool Output(std::ostream * const output) const;
236 bool OutputTrajectories(ofstream * const output) const;
[e138de]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);
[042f82]242
[c68025]243 // Manipulation routines
244 void flipActiveFlag();
245
[e4afb4]246private:
[00ef5c]247 void init_DFS(struct DFSAccounting&) const;
[e4afb4]248 int last_atom; //!< number given to last atom
[14de469]249};
250
[cbc5fb]251molecule *NewMolecule();
252void DeleteMolecule(molecule* mol);
253
[14de469]254/** A list of \a molecule classes.
255 */
[e4afb4]256class MoleculeListClass : public Observable
257{
258public:
259 MoleculeList ListOfMolecules; //!< List of the contained molecules
260 int MaxIndex;
[042f82]261
[cbc5fb]262 MoleculeListClass(World *world);
[042f82]263 ~MoleculeListClass();
264
[35b698]265 bool AddHydrogenCorrection(std::string &path);
266 bool StoreForcesFile(std::string &path, int *SortIndex);
[437922]267 void insert(molecule *mol);
[bd6bfa]268 void erase(molecule *mol);
[042f82]269 molecule * ReturnIndex(int index);
[35b698]270 bool OutputConfigForListOfFragments(std::string &prefix, int *SortIndex);
[042f82]271 int NumberOfActiveMolecules();
[24a5e0]272 void Enumerate(ostream *out);
[042f82]273 void Output(ofstream *out);
[568be7]274 int CountAllAtoms() const;
[042f82]275
[477bb2]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
[e4afb4]284private:
[cbc5fb]285 World *world; //!< The world this List belongs to. Needed to avoid deadlocks in the destructor
[14de469]286};
287
288/** A leaf for a tree of \a molecule class
289 * Wraps molecules in a tree structure
290 */
[e4afb4]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
[042f82]299
300 //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous);
301 MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf);
302 ~MoleculeLeafClass();
303
304 bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous);
[c27778]305 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
[e138de]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);
[c27778]308 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount, bool &FreeList);
[e138de]309 void TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph);
[042f82]310 int Count() const;
[14de469]311};
312
313#endif /*MOLECULES_HPP_*/
314
Note: See TracBrowser for help on using the repository browser.