source: src/molecule.hpp@ 30c753

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

Removed atomSet atoms in class molecule and replaced by a boost::transform_iterator.

  • atoms causes us a O(N2) complexity due to having to remove atoms from this linearized vector (in O(N) not O(log N) as for the atomIds.
  • marked Molecules/BondFile and Tesselation/BigNonConvex as XFAIL due to interchanged ids.
  • thanks to Jan Hamaekers for pointing this out.
  • NOTE: so far we have not specialized molecule::const_iterator, it simply points to molecule::iterator.
  • Property mode set to 100755
File size: 7.9 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
[30c753]23#include <boost/iterator/transform_iterator.hpp>
24
[520c8b]25#include <string>
26
[30c753]27#include "AtomSet.hpp"
[ad011c]28#include "CodePatterns/Observer.hpp"
29#include "CodePatterns/ObservedIterator.hpp"
30#include "CodePatterns/Cacheable.hpp"
[30c753]31#include "Descriptors/AtomIdDescriptor.hpp"
[07a47e]32#include "Fragmentation/HydrogenSaturation_enum.hpp"
[389cc8]33#include "Formula.hpp"
[30c753]34#include "Helpers/defs.hpp"
35#include "types.hpp"
[14de469]36
[30c753]37// TODO: Was is the include of MoleculeDescriptor_impl.hpp doing in molecule.hpp
[97ebf8]38#include "Descriptors/MoleculeDescriptor_impl.hpp"
39
[f66195]40/****************************************** forward declarations *****************************/
41
42class atom;
43class bond;
[b70721]44class BondedParticle;
45class BondGraph;
[49c059]46class DepthFirstSearchAnalysis;
[f66195]47class element;
48class ForceMatrix;
[dadc74]49class Graph;
[f66195]50class LinkedCell;
[14de469]51class molecule;
[2319ed]52class MoleculeLeafClass;
[14de469]53class MoleculeListClass;
[f66195]54class periodentafel;
[1f91f4]55class RealSpaceMatrix;
[f66195]56class Vector;
[c550dd]57class Shape;
[14de469]58
59/******************************** Some definitions for easier reading **********************************/
60
[30c753]61struct FromIdToAtom :
62 public std::unary_function<atom *, atomId_t>
63{
64 atom * operator()(atomId_t id) const {
65 return World::getInstance().getAtom(AtomById(id));
66 }
67};
68
[14de469]69/************************************* Class definitions ****************************************/
70
71/** The complete molecule.
72 * Class incorporates number of types
73 */
[34c43a]74class molecule : public Observable
[e4afb4]75{
[cbc5fb]76 friend molecule *NewMolecule();
77 friend void DeleteMolecule(molecule *);
[bd58fb]78
[e4afb4]79public:
[30c753]80 typedef ATOMSET(std::set) atomSet;
[e4afb4]81 typedef std::set<atomId_t> atomIdSet;
[30c753]82 typedef boost::transform_iterator<FromIdToAtom, atomIdSet::iterator, atom *, atomId_t> iterator;
83 typedef iterator const_iterator;
[e4afb4]84
85 const periodentafel * const elemente; //!< periodic table with each element
86 // old deprecated atom handling
87 //atom *start; //!< start of atom list
88 //atom *end; //!< end of atom list
89 //bond *first; //!< start of bond list
90 //bond *last; //!< end of bond list
91 int MDSteps; //!< The number of MD steps in Trajectories
92 mutable int NoNonHydrogen; //!< number of non-hydrogen atoms in molecule
93 mutable int NoNonBonds; //!< number of non-hydrogen bonds in molecule
94 mutable int NoCyclicBonds; //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
95 bool ActiveFlag; //!< in a MoleculeListClass used to discern active from inactive molecules
96 //Vector Center; //!< Center of molecule in a global box
97 int IndexNr; //!< index of molecule in a MoleculeListClass
98 char name[MAXSTRINGSIZE]; //!< arbitrary name
99
100private:
101 Formula formula;
[458c31]102 Cacheable<int> AtomCount; //!< number of atoms, brought up-to-date by doCountAtoms()
103 Cacheable<int> BondCount; //!< number of atoms, brought up-to-date by doCountBonds()
[e4afb4]104 moleculeId_t id;
105 atomIdSet atomIds; //<!set of atomic ids to check uniqueness of atoms
106protected:
107 //void CountAtoms();
108 /**
109 * this iterator type should be used for internal variables, \
[d3347e]110 * since it will not lock
[e4afb4]111 */
112 typedef atomSet::iterator internal_iterator;
[ac9b56]113
[e4afb4]114 molecule(const periodentafel * const teil);
115 virtual ~molecule();
[042f82]116
[cbc5fb]117public:
[520c8b]118 //getter and setter
[73a857]119 const std::string getName() const;
[ea7176]120 int getAtomCount() const;
121 int doCountAtoms();
[458c31]122 int getBondCount() const;
123 int doCountBonds() const;
[73a857]124 moleculeId_t getId() const;
[cbc5fb]125 void setId(moleculeId_t);
[520c8b]126 void setName(const std::string);
[73a857]127 const Formula &getFormula() const;
128 unsigned int getElementCount() const;
[389cc8]129 bool hasElement(const element*) const;
130 bool hasElement(atomicNumber_t) const;
131 bool hasElement(const std::string&) const;
132
[a7a087]133 virtual bool changeId(atomId_t newId);
[520c8b]134
[9317be]135 World::AtomComposite getAtomSet() const;
[3738f0]136
[bd58fb]137 iterator begin();
138 const_iterator begin() const;
[e87acf]139 iterator end();
140 const_iterator end() const;
[9879f6]141 bool empty() const;
142 size_t size() const;
[e4afb4]143 const_iterator find(atom * key) const;
144 pair<iterator, bool> insert(atom * const key);
[6cfa36]145 bool containsAtom(atom* key);
[bd58fb]146
[2e4105]147private:
148 friend void atom::removeFromMolecule();
149 /** Erase an atom from the list.
150 * \note This should only be called by atom::removeFromMolecule(),
151 * otherwise it is not assured that the atom knows about it.
152 *
153 * @param loc locator to atom in list
154 * @return iterator to just after removed item (compliant with standard)
155 */
156 const_iterator erase(const_iterator loc);
157 /** Erase an atom from the list.
158 * \note This should only be called by atom::removeFromMolecule(),
159 * otherwise it is not assured that the atom knows about it.
160 *
161 * @param *key key to atom in list
162 * @return iterator to just after removed item (compliant with standard)
163 */
164 const_iterator erase(atom * key);
165
166public:
167
[042f82]168 /// remove atoms from molecule.
169 bool AddAtom(atom *pointer);
170 bool RemoveAtom(atom *pointer);
171 bool UnlinkAtom(atom *pointer);
172 bool CleanupMolecule();
[9df680]173 void removeAtomsinMolecule();
[042f82]174
175 /// Add/remove atoms to/from molecule.
176 atom * AddCopyAtom(atom *pointer);
177 bool AddXYZFile(string filename);
[e138de]178 bool AddHydrogenReplacementAtom(bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bool IsAngstroem);
[cee0b57]179 bond * AddBond(atom *first, atom *second, int degree = 1);
[042f82]180 bool RemoveBond(bond *pointer);
181 bool RemoveBonds(atom *BondPartner);
[e4afb4]182 bool hasBondStructure() const;
[042f82]183
184 /// Find atoms.
185 atom * FindAtom(int Nr) const;
186 atom * AskAtom(string text);
187
188 /// Count and change present atoms' coordination.
[e138de]189 bool CenterInBox();
190 bool BoundInBox();
191 void CenterEdge(Vector *max);
192 void CenterOrigin();
193 void CenterPeriodic();
194 void CenterAtVector(Vector *newcenter);
[042f82]195 void Translate(const Vector *x);
196 void TranslatePeriodically(const Vector *trans);
197 void Mirror(const Vector *x);
198 void Align(Vector *n);
[776b64]199 void Scale(const double ** const factor);
[07a47e]200 void DeterminePeriodicCenter(Vector &center, const enum HydrogenSaturation _saturation = DoSaturate);
[4bb63c]201 Vector * DetermineCenterOfGravity() const;
[e138de]202 Vector * DetermineCenterOfAll() const;
[eddea2]203 Vector * DetermineCenterOfBox() const;
[437922]204 void SetNameFromFilename(const char *filename);
[042f82]205 void SetBoxDimension(Vector *dim);
[3c58f8]206 bool ScanForPeriodicCorrection();
[e138de]207 double VolumeOfConvexEnvelope(bool IsAngstroem);
[1f91f4]208 RealSpaceMatrix getInertiaTensor() const;
209 void RotateToPrincipalAxisSystem(Vector &Axis);
[042f82]210
211 bool CheckBounds(const Vector *x) const;
212 void GetAlignvector(struct lsq_params * par) const;
213
214 /// Initialising routines in fragmentation
[e138de]215 void OutputBondsList() const;
[49c059]216
[266237]217 bond * CopyBond(atom *left, atom *right, bond *CopyBond);
218
[e4afb4]219 molecule *CopyMolecule() const;
[c550dd]220 molecule* CopyMoleculeFromSubRegion(const Shape&) const;
[042f82]221
222 /// Fragment molecule by two different approaches:
[e4afb4]223 bool StoreBondsToFile(std::string filename, std::string path = "");
224 bool StoreAdjacencyToFile(std::string filename, std::string path = "");
[9879f6]225 bool CreateFatherLookupTable(atom **&LookupTable, int count = 0);
[b9772a]226
[042f82]227 // Recognize doubly appearing molecules in a list of them
[e138de]228 int * GetFatherSonAtomicMap(molecule *OtherMolecule);
[99752a]229 bool FillBondStructureFromReference(const molecule * const reference, atom **&ListOfLocalAtoms, bool FreeList = false);
[c6123b]230 bool FillListOfLocalAtoms(atom **&ListOfLocalAtoms, const int GlobalAtomCount);
[042f82]231
232 // Output routines.
[e4afb4]233 bool Output(std::ostream * const output) const;
234 bool OutputTrajectories(ofstream * const output) const;
[e138de]235 void OutputListOfBonds() const;
236 bool OutputXYZ(ofstream * const output) const;
237 bool OutputTrajectoriesXYZ(ofstream * const output);
238 bool Checkout(ofstream * const output) const;
[042f82]239
[c68025]240 // Manipulation routines
241 void flipActiveFlag();
242
[e4afb4]243private:
244 int last_atom; //!< number given to last atom
[14de469]245};
246
[cbc5fb]247molecule *NewMolecule();
248void DeleteMolecule(molecule* mol);
249
[14de469]250
251
252#endif /*MOLECULES_HPP_*/
253
Note: See TracBrowser for help on using the repository browser.