| 1 | /** \file molecules.hpp | 
|---|
| 2 | * | 
|---|
| 3 | * Class definitions of atom and molecule, element and periodentafel | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef MOLECULES_HPP_ | 
|---|
| 7 | #define MOLECULES_HPP_ | 
|---|
| 8 |  | 
|---|
| 9 | using namespace std; | 
|---|
| 10 |  | 
|---|
| 11 | // GSL headers | 
|---|
| 12 | #include <gsl/gsl_multimin.h> | 
|---|
| 13 | #include <gsl/gsl_vector.h> | 
|---|
| 14 | #include <gsl/gsl_matrix.h> | 
|---|
| 15 | #include <gsl/gsl_heapsort.h> | 
|---|
| 16 |  | 
|---|
| 17 | // STL headers | 
|---|
| 18 | #include <map> | 
|---|
| 19 | #include <set> | 
|---|
| 20 | #include <deque> | 
|---|
| 21 |  | 
|---|
| 22 | #include "helpers.hpp" | 
|---|
| 23 |  | 
|---|
| 24 | class atom; | 
|---|
| 25 | class AtomStackClass; | 
|---|
| 26 | class bond; | 
|---|
| 27 | class config; | 
|---|
| 28 | class element; | 
|---|
| 29 | class molecule; | 
|---|
| 30 | class MoleculeListClass; | 
|---|
| 31 | class periodentafel; | 
|---|
| 32 | class vector; | 
|---|
| 33 | class Verbose; | 
|---|
| 34 |  | 
|---|
| 35 | /******************************** Some definitions for easier reading **********************************/ | 
|---|
| 36 |  | 
|---|
| 37 | #define KeyStack deque<int> | 
|---|
| 38 | #define KeySet set<int> | 
|---|
| 39 | #define Graph map<KeySet, pair<int, double>, KeyCompare > | 
|---|
| 40 | #define GraphPair pair<KeySet, pair<int, double> > | 
|---|
| 41 | #define KeySetTestPair pair<KeySet::iterator, bool> | 
|---|
| 42 | #define GraphTestPair pair<Graph::iterator, bool> | 
|---|
| 43 |  | 
|---|
| 44 | struct KeyCompare | 
|---|
| 45 | { | 
|---|
| 46 | bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const; | 
|---|
| 47 | }; | 
|---|
| 48 | //bool operator < (KeySet SubgraphA, KeySet SubgraphB);   //note: this declaration is important, otherwise normal < is used (producing wrong order) | 
|---|
| 49 | inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph | 
|---|
| 50 | inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter);  // Insert all KeySet's in a Graph into another Graph | 
|---|
| 51 |  | 
|---|
| 52 | /******************************** Some templates for list management ***********************************/ | 
|---|
| 53 |  | 
|---|
| 54 | /** Adds linking of an item to a list. | 
|---|
| 55 | * \param *walker | 
|---|
| 56 | * \return true - adding succeeded, false - error in list | 
|---|
| 57 | */ | 
|---|
| 58 | template <typename X> void link(X *walker, X *end) | 
|---|
| 59 | { | 
|---|
| 60 | X *vorher = end->previous; | 
|---|
| 61 | if (vorher != NULL) | 
|---|
| 62 | vorher->next = walker; | 
|---|
| 63 | end->previous = walker; | 
|---|
| 64 | walker->previous = vorher; | 
|---|
| 65 | walker->next = end; | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 | /** Removes linking of an item in a list. | 
|---|
| 69 | * \param *walker | 
|---|
| 70 | * \return true - removing succeeded, false - given item not found in list | 
|---|
| 71 | */ | 
|---|
| 72 | template <typename X> void unlink(X *walker) | 
|---|
| 73 | { | 
|---|
| 74 | if (walker->next != NULL) | 
|---|
| 75 | walker->next->previous = walker->previous; | 
|---|
| 76 | if (walker->previous != NULL) | 
|---|
| 77 | walker->previous->next = walker->next; | 
|---|
| 78 | }; | 
|---|
| 79 |  | 
|---|
| 80 | /** Adds new item before an item \a *end in a list. | 
|---|
| 81 | * \param *pointer   item to be added | 
|---|
| 82 | * \param *end  end of list | 
|---|
| 83 | * \return true - addition succeeded, false - unable to add item to list | 
|---|
| 84 | */ | 
|---|
| 85 | template <typename X>  bool add(X *pointer, X *end) | 
|---|
| 86 | { | 
|---|
| 87 | if (end != NULL) { | 
|---|
| 88 | link(pointer, end); | 
|---|
| 89 | } else { | 
|---|
| 90 | pointer->previous = NULL; | 
|---|
| 91 | pointer->next = NULL; | 
|---|
| 92 | } | 
|---|
| 93 | return true; | 
|---|
| 94 | }; | 
|---|
| 95 |  | 
|---|
| 96 | /** Finds item in list | 
|---|
| 97 | * \param *suche  search criteria | 
|---|
| 98 | * \param *start  begin of list | 
|---|
| 99 | * \param *end  end of list | 
|---|
| 100 | * \return X - if found, NULL - if not found | 
|---|
| 101 | */ | 
|---|
| 102 | template <typename X, typename Y> X * find(Y *suche, X *start, X *end) | 
|---|
| 103 | { | 
|---|
| 104 | X *walker = start; | 
|---|
| 105 | while (walker->next != end) { // go through list | 
|---|
| 106 | walker = walker->next; // step onward beforehand | 
|---|
| 107 | if (*walker->sort == *suche) return (walker); | 
|---|
| 108 | } | 
|---|
| 109 | return NULL; | 
|---|
| 110 | }; | 
|---|
| 111 |  | 
|---|
| 112 | /** Removes an item from the list without check. | 
|---|
| 113 | * \param *walker item to be removed | 
|---|
| 114 | * \return true - removing succeeded, false - given item not found in list | 
|---|
| 115 | */ | 
|---|
| 116 | template <typename X> void removewithoutcheck(X *walker) | 
|---|
| 117 | { | 
|---|
| 118 | if (walker != NULL) { | 
|---|
| 119 | unlink(walker); | 
|---|
| 120 | delete(walker); | 
|---|
| 121 | walker = NULL; | 
|---|
| 122 | } | 
|---|
| 123 | }; | 
|---|
| 124 |  | 
|---|
| 125 | /** Removes an item from the list, checks if exists. | 
|---|
| 126 | * Checks beforehand if atom is really within molecule list. | 
|---|
| 127 | * \param *pointer   item to be removed | 
|---|
| 128 | * \param *start  begin of list | 
|---|
| 129 | * \param *end  end of list | 
|---|
| 130 | * \return true - removing succeeded, false - given item not found in list | 
|---|
| 131 | */ | 
|---|
| 132 | template <typename X> bool remove(X *pointer, X *start, X *end) | 
|---|
| 133 | { | 
|---|
| 134 | X *walker = find (pointer->sort, start, end); | 
|---|
| 135 | /*  while (walker->next != pointer) { // search through list | 
|---|
| 136 | walker = walker->next; | 
|---|
| 137 | if (walker == end) return false;  // item not found in list | 
|---|
| 138 | }*/ | 
|---|
| 139 | // atom found, now unlink | 
|---|
| 140 | if (walker != NULL) | 
|---|
| 141 | removewithoutcheck(walker); | 
|---|
| 142 | else | 
|---|
| 143 | return false; | 
|---|
| 144 | return true; | 
|---|
| 145 | }; | 
|---|
| 146 |  | 
|---|
| 147 | /** Cleans the whole list. | 
|---|
| 148 | * \param *start begin of list | 
|---|
| 149 | * \param *end end of list | 
|---|
| 150 | * \return true - list was cleaned successfully, false - error in list structure | 
|---|
| 151 | */ | 
|---|
| 152 | template <typename X> bool cleanup(X *start, X *end) | 
|---|
| 153 | { | 
|---|
| 154 | X *pointer = start->next; | 
|---|
| 155 | X *walker; | 
|---|
| 156 | while (pointer != end) { // go through list | 
|---|
| 157 | walker = pointer; // mark current | 
|---|
| 158 | pointer = pointer->next; // step onward beforehand | 
|---|
| 159 | // remove walker | 
|---|
| 160 | unlink(walker); | 
|---|
| 161 | delete(walker); | 
|---|
| 162 | walker = NULL; | 
|---|
| 163 | } | 
|---|
| 164 | return true; | 
|---|
| 165 | }; | 
|---|
| 166 |  | 
|---|
| 167 | /** Returns the first marker in a chain list. | 
|---|
| 168 | * \param *me one arbitrary item in chain list | 
|---|
| 169 | * \return poiner to first marker | 
|---|
| 170 | */ | 
|---|
| 171 | template <typename X> X *GetFirst(X *me) | 
|---|
| 172 | { | 
|---|
| 173 | X *Binder = me; | 
|---|
| 174 | while(Binder->previous != NULL) | 
|---|
| 175 | Binder = Binder->previous; | 
|---|
| 176 | return Binder; | 
|---|
| 177 | }; | 
|---|
| 178 |  | 
|---|
| 179 | /** Returns the last marker in a chain list. | 
|---|
| 180 | * \param *me one arbitrary item in chain list | 
|---|
| 181 | * \return poiner to last marker | 
|---|
| 182 | */ | 
|---|
| 183 | template <typename X> X *GetLast(X *me) | 
|---|
| 184 | { | 
|---|
| 185 | X *Binder = me; | 
|---|
| 186 | while(Binder->next != NULL) | 
|---|
| 187 | Binder = Binder->next; | 
|---|
| 188 | return Binder; | 
|---|
| 189 | }; | 
|---|
| 190 |  | 
|---|
| 191 | /** Frees a two-dimensional array. | 
|---|
| 192 | * \param *ptr pointer to array | 
|---|
| 193 | * \param dim first dim of array | 
|---|
| 194 | */ | 
|---|
| 195 | template <typename X> void Free2DArray(X **ptr, int dim) | 
|---|
| 196 | { | 
|---|
| 197 | int i; | 
|---|
| 198 | if (ptr != NULL) { | 
|---|
| 199 | for(i=0;i<dim;i++) | 
|---|
| 200 | if (ptr[i] != NULL) | 
|---|
| 201 | free(ptr[i]); | 
|---|
| 202 | free(ptr); | 
|---|
| 203 | } | 
|---|
| 204 | }; | 
|---|
| 205 |  | 
|---|
| 206 | int CompareDoubles (const void * a, const void * b); | 
|---|
| 207 |  | 
|---|
| 208 | /************************************* Class definitions ****************************************/ | 
|---|
| 209 |  | 
|---|
| 210 | /** Chemical element. | 
|---|
| 211 | * Class incorporates data for a certain chemical element to be referenced from atom class. | 
|---|
| 212 | */ | 
|---|
| 213 | class element { | 
|---|
| 214 | public: | 
|---|
| 215 | double mass;    //!< mass in g/mol | 
|---|
| 216 | double CovalentRadius;  //!< covalent radius | 
|---|
| 217 | double VanDerWaalsRadius;  //!< can-der-Waals radius | 
|---|
| 218 | int Z;          //!< atomic number | 
|---|
| 219 | char name[64];  //!< atom name, i.e. "Hydrogren" | 
|---|
| 220 | char symbol[3]; //!< short form of the atom, i.e. "H" | 
|---|
| 221 | char period[8];    //!< period: n quantum number | 
|---|
| 222 | char group[8];    //!< group: l quantum number | 
|---|
| 223 | char block[8];    //!< block: l quantum number | 
|---|
| 224 | element *previous;  //!< previous item in list | 
|---|
| 225 | element *next;  //!< next element in list | 
|---|
| 226 | int *sort;      //!< sorc criteria | 
|---|
| 227 | int No;         //!< number of element set on periodentafel::Output() | 
|---|
| 228 | double Valence;             //!< number of valence electrons for this element | 
|---|
| 229 | int NoValenceOrbitals;  //!< number of valence orbitals, used for determining bond degree in molecule::CreateConnectmatrix() | 
|---|
| 230 | double HBondDistance[NDIM]; //!< distance in Angstrom of this element to hydrogen  (for single, double and triple bonds) | 
|---|
| 231 | double HBondAngle[NDIM];     //!< typical angle for one, two, three bonded hydrogen (in degrees) | 
|---|
| 232 |  | 
|---|
| 233 | element(); | 
|---|
| 234 | ~element(); | 
|---|
| 235 |  | 
|---|
| 236 | //> print element entries to screen | 
|---|
| 237 | bool Output(ofstream *out) const; | 
|---|
| 238 | bool Checkout(ofstream *out, const int No, const int NoOfAtoms) const; | 
|---|
| 239 |  | 
|---|
| 240 | private: | 
|---|
| 241 | }; | 
|---|
| 242 |  | 
|---|
| 243 | /** Periodentafel is a list of all elements sorted by their atomic number. | 
|---|
| 244 | */ | 
|---|
| 245 | class periodentafel { | 
|---|
| 246 | public: | 
|---|
| 247 | element *start; //!< start of element list | 
|---|
| 248 | element *end;   //!< end of element list | 
|---|
| 249 | char header1[255]; //!< store first header line | 
|---|
| 250 | char header2[255]; //!< store second header line | 
|---|
| 251 |  | 
|---|
| 252 | periodentafel(); | 
|---|
| 253 | ~periodentafel(); | 
|---|
| 254 |  | 
|---|
| 255 | bool AddElement(element *pointer); | 
|---|
| 256 | bool RemoveElement(element *pointer); | 
|---|
| 257 | bool CleanupPeriodtable(); | 
|---|
| 258 | element * FindElement(int Z); | 
|---|
| 259 | element * FindElement(char *shorthand) const; | 
|---|
| 260 | element * AskElement(); | 
|---|
| 261 | bool Output(ofstream *output) const; | 
|---|
| 262 | bool Checkout(ofstream *output, const int *checkliste) const; | 
|---|
| 263 | bool LoadPeriodentafel(char *filename = NULL); | 
|---|
| 264 | bool StorePeriodentafel(char *filename = NULL) const; | 
|---|
| 265 |  | 
|---|
| 266 | private: | 
|---|
| 267 | }; | 
|---|
| 268 |  | 
|---|
| 269 | // some algebraic matrix stuff | 
|---|
| 270 | #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix | 
|---|
| 271 | #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix | 
|---|
| 272 |  | 
|---|
| 273 | /** Single vector. | 
|---|
| 274 | * basically, just a x[3] but with helpful functions | 
|---|
| 275 | */ | 
|---|
| 276 | class vector { | 
|---|
| 277 | public: | 
|---|
| 278 | double x[NDIM]; | 
|---|
| 279 |  | 
|---|
| 280 | vector(); | 
|---|
| 281 | ~vector(); | 
|---|
| 282 |  | 
|---|
| 283 | double Distance(const vector *y) const; | 
|---|
| 284 | double PeriodicDistance(const vector *y, const double *cell_size) const; | 
|---|
| 285 | double ScalarProduct(const vector *y) const; | 
|---|
| 286 | double Projection(const vector *y) const; | 
|---|
| 287 | double Norm() const ; | 
|---|
| 288 | double Angle(vector *y) const; | 
|---|
| 289 |  | 
|---|
| 290 | void AddVector(const vector *y); | 
|---|
| 291 | void SubtractVector(const vector *y); | 
|---|
| 292 | void CopyVector(const vector *y); | 
|---|
| 293 | void RotateVector(const vector *y, const double alpha); | 
|---|
| 294 | void Zero(); | 
|---|
| 295 | void Normalize(); | 
|---|
| 296 | void Translate(const vector *x); | 
|---|
| 297 | void Mirror(const vector *x); | 
|---|
| 298 | void Scale(double **factor); | 
|---|
| 299 | void Scale(double *factor); | 
|---|
| 300 | void Scale(double factor); | 
|---|
| 301 | void MatrixMultiplication(double *M); | 
|---|
| 302 | void InverseMatrixMultiplication(double *M); | 
|---|
| 303 | void KeepPeriodic(ofstream *out, double *matrix); | 
|---|
| 304 | void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors); | 
|---|
| 305 |  | 
|---|
| 306 | bool GetOneNormalVector(const vector *x1); | 
|---|
| 307 | bool MakeNormalVector(const vector *y1); | 
|---|
| 308 | bool MakeNormalVector(const vector *y1, const vector *y2); | 
|---|
| 309 | bool MakeNormalVector(const vector *x1, const vector *x2, const vector *x3); | 
|---|
| 310 | bool SolveSystem(vector *x1, vector *x2, vector *y, double alpha, double beta, double c); | 
|---|
| 311 | bool LSQdistance(vector **vectors, int dim); | 
|---|
| 312 |  | 
|---|
| 313 | void AskPosition(double *cell_size, bool check); | 
|---|
| 314 | bool Output(ofstream *out) const; | 
|---|
| 315 | }; | 
|---|
| 316 |  | 
|---|
| 317 | ofstream& operator<<(ofstream& ost, vector& m); | 
|---|
| 318 |  | 
|---|
| 319 | /** Parameter structure for least square minimsation. | 
|---|
| 320 | */ | 
|---|
| 321 | struct LSQ_params { | 
|---|
| 322 | vector **vectors; | 
|---|
| 323 | int num; | 
|---|
| 324 | }; | 
|---|
| 325 |  | 
|---|
| 326 | double LSQ(const gsl_vector * x, void * params); | 
|---|
| 327 |  | 
|---|
| 328 | /** Parameter structure for least square minimsation. | 
|---|
| 329 | */ | 
|---|
| 330 | struct lsq_params { | 
|---|
| 331 | gsl_vector *x; | 
|---|
| 332 | const molecule *mol; | 
|---|
| 333 | element *type; | 
|---|
| 334 | }; | 
|---|
| 335 |  | 
|---|
| 336 |  | 
|---|
| 337 |  | 
|---|
| 338 | /** Single atom. | 
|---|
| 339 | * Class incoporates position, type | 
|---|
| 340 | */ | 
|---|
| 341 | class atom { | 
|---|
| 342 | public: | 
|---|
| 343 | vector x;       //!< coordinate array of atom, giving position within cell | 
|---|
| 344 | vector v;       //!< velocity array of atom | 
|---|
| 345 | element *type;  //!< pointing to element | 
|---|
| 346 | atom *previous; //!< previous atom in molecule list | 
|---|
| 347 | atom *next;     //!< next atom in molecule list | 
|---|
| 348 | atom *father;   //!< In many-body bond order fragmentations points to originating atom | 
|---|
| 349 | atom *Ancestor; //!< "Father" in Depth-First-Search | 
|---|
| 350 | char *Name;                 //!< unique name used during many-body bond-order fragmentation | 
|---|
| 351 | int FixedIon;   //!< config variable that states whether forces act on the ion or not | 
|---|
| 352 | int *sort;      //!< sort criteria | 
|---|
| 353 | int nr;         //!< continuous, unique number | 
|---|
| 354 | int GraphNr;      //!< unique number, given in DepthFirstSearchAnalysis() | 
|---|
| 355 | int *ComponentNr;//!< belongs to this nonseparable components, given in DepthFirstSearchAnalysis() (if more than one, then is SeparationVertex) | 
|---|
| 356 | int LowpointNr; //!< needed in DepthFirstSearchAnalysis() to detect nonseparable components, is the lowest possible number of an atom to reach via tree edges only followed by at most one back edge. | 
|---|
| 357 | bool SeparationVertex; //!< whether this atom separates off subsets of atoms or not, given in DepthFirstSearchAnalysis() | 
|---|
| 358 |  | 
|---|
| 359 | atom(); | 
|---|
| 360 | ~atom(); | 
|---|
| 361 |  | 
|---|
| 362 | bool Output(int ElementNo, int AtomNo, ofstream *out) const; | 
|---|
| 363 | bool OutputXYZLine(ofstream *out) const; | 
|---|
| 364 | atom *GetTrueFather(); | 
|---|
| 365 | bool Compare(atom &ptr); | 
|---|
| 366 |  | 
|---|
| 367 | private: | 
|---|
| 368 | }; | 
|---|
| 369 |  | 
|---|
| 370 | ostream & operator << (ostream &ost, atom &a); | 
|---|
| 371 |  | 
|---|
| 372 | /* Stack of Atoms. | 
|---|
| 373 | * Is used during DepthFirstSearchAnalysis() to detect nonseparable components. | 
|---|
| 374 | */ | 
|---|
| 375 | class AtomStackClass { | 
|---|
| 376 | public: | 
|---|
| 377 | AtomStackClass(int dimension); | 
|---|
| 378 | ~AtomStackClass(); | 
|---|
| 379 |  | 
|---|
| 380 | bool Push(atom *object); | 
|---|
| 381 | atom *PopFirst(); | 
|---|
| 382 | atom *PopLast(); | 
|---|
| 383 | bool AtomStackClass::RemoveItem(atom *ptr); | 
|---|
| 384 | void ClearStack(); | 
|---|
| 385 | bool IsEmpty(); | 
|---|
| 386 | bool IsFull(); | 
|---|
| 387 | int ItemCount(); | 
|---|
| 388 | void Output(ofstream *out) const; | 
|---|
| 389 | void TestImplementation(ofstream *out, atom *test); | 
|---|
| 390 |  | 
|---|
| 391 | private: | 
|---|
| 392 | atom **StackList;   //!< the list containing the atom pointers | 
|---|
| 393 | int EntryCount;     //!< number of entries in the stack | 
|---|
| 394 | int CurrentLastEntry;   //!< Current last entry (newest item on stack) | 
|---|
| 395 | int CurrentFirstEntry;   //!< Current first entry (oldest item on stack) | 
|---|
| 396 | int NextFreeField;       //!< Current index of next free field | 
|---|
| 397 | }; | 
|---|
| 398 |  | 
|---|
| 399 |  | 
|---|
| 400 | /** Bonds between atoms. | 
|---|
| 401 | * Class incorporates bonds between atoms in a molecule, | 
|---|
| 402 | * used to derive tge fragments in many-body bond order | 
|---|
| 403 | * calculations. | 
|---|
| 404 | */ | 
|---|
| 405 | class bond { | 
|---|
| 406 | public: | 
|---|
| 407 | atom *leftatom;         //!< first bond partner | 
|---|
| 408 | atom *rightatom;        //!< second bond partner | 
|---|
| 409 | bond *previous; //!< previous atom in molecule list | 
|---|
| 410 | bond *next;     //!< next atom in molecule list | 
|---|
| 411 | int HydrogenBond;       //!< Number of hydrogen atoms in the bond | 
|---|
| 412 | int BondDegree;         //!< single, double, triple, ... bond | 
|---|
| 413 | int nr;           //!< unique number in a molecule, updated by molecule::CreateAdjacencyList() | 
|---|
| 414 | bool Cyclic;      //!< flag whether bond is part of a cycle or not, given in DepthFirstSearchAnalysis() | 
|---|
| 415 | enum EdgeType Type;//!< whether this is a tree or back edge | 
|---|
| 416 |  | 
|---|
| 417 | atom * GetOtherAtom(atom *Atom) const; | 
|---|
| 418 | bond * GetFirstBond(); | 
|---|
| 419 | bond * GetLastBond(); | 
|---|
| 420 |  | 
|---|
| 421 | bool MarkUsed(enum Shading color); | 
|---|
| 422 | enum Shading IsUsed(); | 
|---|
| 423 | void ResetUsed(); | 
|---|
| 424 | bool Contains(const atom *ptr); | 
|---|
| 425 | bool Contains(const int nr); | 
|---|
| 426 |  | 
|---|
| 427 | bond(); | 
|---|
| 428 | bond(atom *left, atom *right); | 
|---|
| 429 | bond(atom *left, atom *right, int degree); | 
|---|
| 430 | bond(atom *left, atom *right, int degree, int number); | 
|---|
| 431 | ~bond(); | 
|---|
| 432 |  | 
|---|
| 433 | private: | 
|---|
| 434 | enum Shading Used;        //!< marker in depth-first search, DepthFirstSearchAnalysis() | 
|---|
| 435 | }; | 
|---|
| 436 |  | 
|---|
| 437 | ostream & operator << (ostream &ost, bond &b); | 
|---|
| 438 |  | 
|---|
| 439 | class MoleculeLeafClass; | 
|---|
| 440 |  | 
|---|
| 441 | /** The complete molecule. | 
|---|
| 442 | * Class incorporates number of types | 
|---|
| 443 | */ | 
|---|
| 444 | class molecule { | 
|---|
| 445 | public: | 
|---|
| 446 | double cell_size[6];//!< cell size | 
|---|
| 447 | periodentafel *elemente; //!< periodic table with each element | 
|---|
| 448 | atom *start;        //!< start of atom list | 
|---|
| 449 | atom *end;          //!< end of atom list | 
|---|
| 450 | bond *first;        //!< start of bond list | 
|---|
| 451 | bond *last;         //!< end of bond list | 
|---|
| 452 | bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has | 
|---|
| 453 | int *NumberOfBondsPerAtom;  //!< Number of Bonds each atom has | 
|---|
| 454 | int AtomCount;                                      //!< number of atoms, brought up-to-date by CountAtoms() | 
|---|
| 455 | int BondCount;                                      //!< number of atoms, brought up-to-date by CountBonds() | 
|---|
| 456 | int ElementCount;       //!< how many unique elements are therein | 
|---|
| 457 | int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not | 
|---|
| 458 | int NoNonHydrogen;  //!< number of non-hydrogen atoms in molecule | 
|---|
| 459 | int NoNonBonds;     //!< number of non-hydrogen bonds in molecule | 
|---|
| 460 | int NoCyclicBonds;  //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis() | 
|---|
| 461 | double BondDistance;  //!< typical bond distance used in CreateAdjacencyList() and furtheron | 
|---|
| 462 |  | 
|---|
| 463 | molecule(periodentafel *teil); | 
|---|
| 464 | ~molecule(); | 
|---|
| 465 |  | 
|---|
| 466 | /// remove atoms from molecule. | 
|---|
| 467 | bool AddAtom(atom *pointer); | 
|---|
| 468 | bool RemoveAtom(atom *pointer); | 
|---|
| 469 | bool CleanupMolecule(); | 
|---|
| 470 |  | 
|---|
| 471 | /// Add/remove atoms to/from molecule. | 
|---|
| 472 | atom * AddCopyAtom(atom *pointer); | 
|---|
| 473 | bool AddXYZFile(string filename); | 
|---|
| 474 | bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem); | 
|---|
| 475 | bond * AddBond(atom *first, atom *second, int degree); | 
|---|
| 476 | bool RemoveBond(bond *pointer); | 
|---|
| 477 | bool RemoveBonds(atom *BondPartner); | 
|---|
| 478 |  | 
|---|
| 479 | /// Find atoms. | 
|---|
| 480 | atom * FindAtom(int Nr) const; | 
|---|
| 481 | atom * AskAtom(char *text); | 
|---|
| 482 |  | 
|---|
| 483 | /// Count and change present atoms' coordination. | 
|---|
| 484 | void CountAtoms(ofstream *out); | 
|---|
| 485 | void CountElements(); | 
|---|
| 486 | void CalculateOrbitals(class config &configuration); | 
|---|
| 487 | void CenterEdge(ofstream *out, vector *max); | 
|---|
| 488 | void CenterOrigin(ofstream *out, vector *max); | 
|---|
| 489 | void CenterGravity(ofstream *out, vector *max); | 
|---|
| 490 | void Translate(const vector *x); | 
|---|
| 491 | void Mirror(const vector *x); | 
|---|
| 492 | void Align(vector *n); | 
|---|
| 493 | void Scale(double **factor); | 
|---|
| 494 | void DetermineCenterOfGravity(vector &CenterOfGravity); | 
|---|
| 495 | void SetBoxDimension(vector *dim); | 
|---|
| 496 | double * ReturnFullMatrixforSymmetric(double *cell_size); | 
|---|
| 497 | void ScanForPeriodicCorrection(ofstream *out); | 
|---|
| 498 |  | 
|---|
| 499 | bool CheckBounds(const vector *x) const; | 
|---|
| 500 | void GetAlignVector(struct lsq_params * par) const; | 
|---|
| 501 |  | 
|---|
| 502 | /// Initialising routines in fragmentation | 
|---|
| 503 | void CreateAdjacencyList(ofstream *out, double bonddistance); | 
|---|
| 504 | void CreateListOfBondsPerAtom(ofstream *out); | 
|---|
| 505 |  | 
|---|
| 506 | // Graph analysis | 
|---|
| 507 | MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int &MinimumRingSize); | 
|---|
| 508 | void CyclicStructureAnalysis(ofstream *out, int &MinimumRingSize); | 
|---|
| 509 | bond * FindNextUnused(atom *vertex); | 
|---|
| 510 | void SetNextComponentNumber(atom *vertex, int nr); | 
|---|
| 511 | void InitComponentNumbers(); | 
|---|
| 512 | void OutputComponentNumber(ofstream *out, atom *vertex); | 
|---|
| 513 | void ResetAllBondsToUnused(); | 
|---|
| 514 | void ResetAllAtomNumbers(); | 
|---|
| 515 | int CountCyclicBonds(ofstream *out); | 
|---|
| 516 | char * GetColor(enum Shading color); | 
|---|
| 517 |  | 
|---|
| 518 | molecule *CopyMolecule(); | 
|---|
| 519 |  | 
|---|
| 520 | /// Fragment molecule by two different approaches: | 
|---|
| 521 | void FragmentMolecule(ofstream *out, int BottomUpOrder, int TopDownOrder, enum BondOrderScheme Scheme, config *configuration, enum CutCyclicBond CutCyclic); | 
|---|
| 522 | bool StoreAdjacencyToFile(ofstream *out, char *path); | 
|---|
| 523 | bool CheckAdjacencyFileAgainstMolecule(ofstream *out, char *path, atom **ListOfAtoms); | 
|---|
| 524 | bool ParseKeySetFile(ofstream *out, char *filename, atom **ListOfAtoms, MoleculeListClass *&FragmentList, bool IsAngstroem); | 
|---|
| 525 | bool ScanBufferIntoKeySet(ofstream *out, char *buffer, KeySet &CurrentSet); | 
|---|
| 526 | MoleculeListClass * GetAtomicFragments(ofstream *out, int NumberOfTopAtoms, bool IsAngstroem, double factor, enum CutCyclicBond CutCyclic); | 
|---|
| 527 | void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
| 528 | /// -# BottomUp | 
|---|
| 529 | MoleculeListClass * FragmentBottomUp(ofstream *out, int BondOrder, config *configuration, enum CutCyclicBond CutCyclic); | 
|---|
| 530 | MoleculeListClass * GetEachBondFragmentOfOrder(ofstream *out, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
| 531 | /// -# TopDown | 
|---|
| 532 | void FragmentMoleculeByBond(ofstream *out, bond *Bond, molecule **LeftFragment, molecule **RightFragment, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
| 533 | /// -# BOSSANOVA | 
|---|
| 534 | MoleculeListClass * FragmentBOSSANOVA(ofstream *out, int ANOVAOrder, config *configuration); | 
|---|
| 535 | int CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, Graph *ListOfGraph, KeySet Fragment, double TEFactor, config *configuration); | 
|---|
| 536 | bool BuildInducedSubgraph(ofstream *out, const molecule *Father); | 
|---|
| 537 | molecule * StoreFragmentFromKeySet(ofstream *out, KeySet &Leaflet, bool IsAngstroem); | 
|---|
| 538 | void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder); | 
|---|
| 539 | int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList); | 
|---|
| 540 | int GuesstimateFragmentCount(ofstream *out, int order); | 
|---|
| 541 |  | 
|---|
| 542 | // Recognize doubly appearing molecules in a list of them | 
|---|
| 543 | int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold); | 
|---|
| 544 | int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule); | 
|---|
| 545 |  | 
|---|
| 546 | // Output routines. | 
|---|
| 547 | bool Output(ofstream *out); | 
|---|
| 548 | bool OutputXYZ(ofstream *out) const; | 
|---|
| 549 | bool Checkout(ofstream *out) const; | 
|---|
| 550 |  | 
|---|
| 551 | private: | 
|---|
| 552 | int last_atom;      //!< number given to last atom | 
|---|
| 553 | }; | 
|---|
| 554 |  | 
|---|
| 555 | /** A list of \a molecule classes. | 
|---|
| 556 | */ | 
|---|
| 557 | class MoleculeListClass { | 
|---|
| 558 | public: | 
|---|
| 559 | molecule **ListOfMolecules;   //!< pointer list of fragment molecules to check for equality | 
|---|
| 560 | int NumberOfMolecules;        //!< Number of entries in \a **FragmentList and of to be returned one. | 
|---|
| 561 | int NumberOfTopAtoms;         //!< Number of atoms in the molecule from which all fragments originate | 
|---|
| 562 | double *TEList;               //!< List of factors when summing over total energies of all fragment | 
|---|
| 563 |  | 
|---|
| 564 | MoleculeListClass(); | 
|---|
| 565 | MoleculeListClass(int Num, int NumAtoms); | 
|---|
| 566 | ~MoleculeListClass(); | 
|---|
| 567 |  | 
|---|
| 568 | MoleculeListClass * FragmentTopDown(ofstream *out, int BondDegree, double bonddistance, config *configuration, enum CutCyclicBond Saturation); | 
|---|
| 569 |  | 
|---|
| 570 | /// Reduced list to unique molecules. | 
|---|
| 571 | int * GetMappingToUniqueFragments(ofstream *out, double threshold, double *cell_size, double celldistance); | 
|---|
| 572 | int ReduceFragmentToUniqueOnes(ofstream *out, int *Map); | 
|---|
| 573 | void ReduceToUniqueList(ofstream *out, double *cell_size, double celldistance); | 
|---|
| 574 |  | 
|---|
| 575 | /// Output configs. | 
|---|
| 576 | bool OutputConfigForListOfFragments(char *prefix, config *configuration, int *SortIndex); | 
|---|
| 577 | void Output(ofstream *out); | 
|---|
| 578 |  | 
|---|
| 579 | private: | 
|---|
| 580 | }; | 
|---|
| 581 |  | 
|---|
| 582 |  | 
|---|
| 583 | /** A leaf for a tree of \a molecule class | 
|---|
| 584 | * Wraps molecules in a tree structure | 
|---|
| 585 | */ | 
|---|
| 586 | class MoleculeLeafClass { | 
|---|
| 587 | public: | 
|---|
| 588 | molecule *Leaf;                   //!< molecule of this leaf | 
|---|
| 589 | //MoleculeLeafClass *UpLeaf;        //!< Leaf one level up | 
|---|
| 590 | //MoleculeLeafClass *DownLeaf;      //!< First leaf one level down | 
|---|
| 591 | MoleculeLeafClass *previous;  //!< Previous leaf on this level | 
|---|
| 592 | MoleculeLeafClass *next;      //!< Next leaf on this level | 
|---|
| 593 |  | 
|---|
| 594 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous); | 
|---|
| 595 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf); | 
|---|
| 596 | ~MoleculeLeafClass(); | 
|---|
| 597 |  | 
|---|
| 598 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous); | 
|---|
| 599 | }; | 
|---|
| 600 |  | 
|---|
| 601 | /** The config file. | 
|---|
| 602 | * The class contains all parameters that control a dft run also functions to load and save. | 
|---|
| 603 | */ | 
|---|
| 604 | class config { | 
|---|
| 605 | public: | 
|---|
| 606 | int PsiType; | 
|---|
| 607 | int MaxPsiDouble; | 
|---|
| 608 | int PsiMaxNoUp; | 
|---|
| 609 | int PsiMaxNoDown; | 
|---|
| 610 | int MaxMinStopStep; | 
|---|
| 611 | int InitMaxMinStopStep; | 
|---|
| 612 | int ProcPEGamma; | 
|---|
| 613 | int ProcPEPsi; | 
|---|
| 614 |  | 
|---|
| 615 | private: | 
|---|
| 616 | char *mainname; | 
|---|
| 617 | char *defaultpath; | 
|---|
| 618 | char *pseudopotpath; | 
|---|
| 619 |  | 
|---|
| 620 | int DoOutVis; | 
|---|
| 621 | int DoOutMes; | 
|---|
| 622 | int DoOutNICS; | 
|---|
| 623 | int DoOutOrbitals; | 
|---|
| 624 | int DoOutCurrent; | 
|---|
| 625 | int DoFullCurrent; | 
|---|
| 626 | int DoPerturbation; | 
|---|
| 627 | int CommonWannier; | 
|---|
| 628 | double SawtoothStart; | 
|---|
| 629 | int VectorPlane; | 
|---|
| 630 | double VectorCut; | 
|---|
| 631 | int UseAddGramSch; | 
|---|
| 632 | int Seed; | 
|---|
| 633 |  | 
|---|
| 634 | int MaxOuterStep; | 
|---|
| 635 | double Deltat; | 
|---|
| 636 | int OutVisStep; | 
|---|
| 637 | int OutSrcStep; | 
|---|
| 638 | double TargetTemp; | 
|---|
| 639 | int ScaleTempStep; | 
|---|
| 640 | int MaxPsiStep; | 
|---|
| 641 | double EpsWannier; | 
|---|
| 642 |  | 
|---|
| 643 | int MaxMinStep; | 
|---|
| 644 | double RelEpsTotalEnergy; | 
|---|
| 645 | double RelEpsKineticEnergy; | 
|---|
| 646 | int MaxMinGapStopStep; | 
|---|
| 647 | int MaxInitMinStep; | 
|---|
| 648 | double InitRelEpsTotalEnergy; | 
|---|
| 649 | double InitRelEpsKineticEnergy; | 
|---|
| 650 | int InitMaxMinGapStopStep; | 
|---|
| 651 |  | 
|---|
| 652 | //double BoxLength[NDIM*NDIM]; | 
|---|
| 653 |  | 
|---|
| 654 | double ECut; | 
|---|
| 655 | int MaxLevel; | 
|---|
| 656 | int RiemannTensor; | 
|---|
| 657 | int LevRFactor; | 
|---|
| 658 | int RiemannLevel; | 
|---|
| 659 | int Lev0Factor; | 
|---|
| 660 | int RTActualUse; | 
|---|
| 661 | int AddPsis; | 
|---|
| 662 |  | 
|---|
| 663 | double RCut; | 
|---|
| 664 | int StructOpt; | 
|---|
| 665 | int IsAngstroem; | 
|---|
| 666 | int RelativeCoord; | 
|---|
| 667 | int MaxTypes; | 
|---|
| 668 |  | 
|---|
| 669 |  | 
|---|
| 670 | int ParseForParameter(int verbose, ifstream *file, const char *name, int sequential, int const xth, int const yth, int type, void *value, int repetition, int critical); | 
|---|
| 671 |  | 
|---|
| 672 | public: | 
|---|
| 673 | config(); | 
|---|
| 674 | ~config(); | 
|---|
| 675 |  | 
|---|
| 676 | int TestSyntax(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
| 677 | void Load(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
| 678 | void LoadOld(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
| 679 | bool Save(ofstream *file, periodentafel *periode, molecule *mol) const; | 
|---|
| 680 | void Edit(molecule *mol); | 
|---|
| 681 | bool GetIsAngstroem() const; | 
|---|
| 682 | char *GetDefaultPath() const; | 
|---|
| 683 | void config::SetDefaultPath(const char *path); | 
|---|
| 684 | }; | 
|---|
| 685 |  | 
|---|
| 686 | #endif /*MOLECULES_HPP_*/ | 
|---|
| 687 |  | 
|---|