| [a0bcf1] | 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(); | 
|---|
|  | 264 | bool StorePeriodentafel() 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: | 
|---|
| [090299] | 343 | vector x;       //!< coordinate array of atom, giving position within cell | 
|---|
|  | 344 | vector v;       //!< velocity array of atom | 
|---|
| [a0bcf1] | 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 | 
|---|
| [090299] | 351 | int FixedIon;   //!< config variable that states whether forces act on the ion or not | 
|---|
| [a0bcf1] | 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 | MoleculeListClass * GetAtomicFragments(ofstream *out, int NumberOfTopAtoms, bool IsAngstroem, double factor, enum CutCyclicBond CutCyclic); | 
|---|
|  | 523 | void BreadthFirstSearchAdd(ofstream *out, molecule *Mol, atom **&AddedAtomList, bond **&AddedBondList, atom *Root, bond *Bond, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
|  | 524 | /// -# BottomUp | 
|---|
|  | 525 | MoleculeListClass * FragmentBottomUp(ofstream *out, int BondOrder, config *configuration, enum CutCyclicBond CutCyclic); | 
|---|
|  | 526 | MoleculeListClass * GetEachBondFragmentOfOrder(ofstream *out, int BondOrder, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
|  | 527 | /// -# TopDown | 
|---|
|  | 528 | void FragmentMoleculeByBond(ofstream *out, bond *Bond, molecule **LeftFragment, molecule **RightFragment, bool IsAngstroem, enum CutCyclicBond CutCyclic); | 
|---|
|  | 529 | /// -# BOSSANOVA | 
|---|
|  | 530 | MoleculeListClass * FragmentBOSSANOVA(ofstream *out, int ANOVAOrder, config *configuration); | 
|---|
|  | 531 | int CreateListOfUniqueFragmentsOfOrder(ofstream *out, int Order, Graph *ListOfGraph, KeySet Fragment, double TEFactor, config *configuration); | 
|---|
|  | 532 | bool BuildInducedSubgraph(ofstream *out, const molecule *Father); | 
|---|
|  | 533 | molecule * StoreFragmentFromKeyset(ofstream *&out, KeySet &Leaflet, config *&configuration); | 
|---|
|  | 534 | void SPFragmentGenerator(ofstream *out, struct UniqueFragments *FragmentSearch, int RootDistance, bond **BondsSet, int SetDimension, int SubOrder); | 
|---|
|  | 535 | int LookForRemovalCandidate(ofstream *&out, KeySet *&Leaf, int *&ShortestPathList); | 
|---|
|  | 536 | int GuesstimateFragmentCount(ofstream *out, int order); | 
|---|
|  | 537 |  | 
|---|
|  | 538 | // Recognize doubly appearing molecules in a list of them | 
|---|
|  | 539 | int * IsEqualToWithinThreshold(ofstream *out, molecule *OtherMolecule, double threshold); | 
|---|
|  | 540 | int * GetFatherSonAtomicMap(ofstream *out, molecule *OtherMolecule); | 
|---|
|  | 541 |  | 
|---|
|  | 542 | // Output routines. | 
|---|
|  | 543 | bool Output(ofstream *out); | 
|---|
|  | 544 | bool OutputXYZ(ofstream *out) const; | 
|---|
|  | 545 | bool Checkout(ofstream *out) const; | 
|---|
|  | 546 |  | 
|---|
|  | 547 | private: | 
|---|
|  | 548 | int last_atom;      //!< number given to last atom | 
|---|
|  | 549 | }; | 
|---|
|  | 550 |  | 
|---|
|  | 551 | /** A list of \a molecule classes. | 
|---|
|  | 552 | */ | 
|---|
|  | 553 | class MoleculeListClass { | 
|---|
|  | 554 | public: | 
|---|
|  | 555 | molecule **ListOfMolecules;   //!< pointer list of fragment molecules to check for equality | 
|---|
|  | 556 | int NumberOfMolecules;        //!< Number of entries in \a **FragmentList and of to be returned one. | 
|---|
|  | 557 | int NumberOfTopAtoms;         //!< Number of atoms in the molecule from which all fragments originate | 
|---|
|  | 558 | double *TEList;               //!< List of factors when summing over total energies of all fragment | 
|---|
|  | 559 |  | 
|---|
|  | 560 | MoleculeListClass(); | 
|---|
|  | 561 | MoleculeListClass(int Num, int NumAtoms); | 
|---|
|  | 562 | ~MoleculeListClass(); | 
|---|
|  | 563 |  | 
|---|
|  | 564 | MoleculeListClass * FragmentTopDown(ofstream *out, int BondDegree, double bonddistance, config *configuration, enum CutCyclicBond Saturation); | 
|---|
|  | 565 |  | 
|---|
|  | 566 | /// Reduced list to unique molecules. | 
|---|
|  | 567 | int * GetMappingToUniqueFragments(ofstream *out, double threshold, double *cell_size, double celldistance); | 
|---|
|  | 568 | int ReduceFragmentToUniqueOnes(ofstream *out, int *Map); | 
|---|
|  | 569 | void ReduceToUniqueList(ofstream *out, double *cell_size, double celldistance); | 
|---|
|  | 570 |  | 
|---|
|  | 571 | /// Output configs. | 
|---|
|  | 572 | bool OutputConfigForListOfFragments(char *prefix, config *configuration, int *SortIndex); | 
|---|
|  | 573 | void Output(ofstream *out); | 
|---|
|  | 574 |  | 
|---|
|  | 575 | private: | 
|---|
|  | 576 | }; | 
|---|
|  | 577 |  | 
|---|
|  | 578 |  | 
|---|
|  | 579 | /** A leaf for a tree of \a molecule class | 
|---|
|  | 580 | * Wraps molecules in a tree structure | 
|---|
|  | 581 | */ | 
|---|
|  | 582 | class MoleculeLeafClass { | 
|---|
|  | 583 | public: | 
|---|
|  | 584 | molecule *Leaf;                   //!< molecule of this leaf | 
|---|
|  | 585 | //MoleculeLeafClass *UpLeaf;        //!< Leaf one level up | 
|---|
|  | 586 | //MoleculeLeafClass *DownLeaf;      //!< First leaf one level down | 
|---|
|  | 587 | MoleculeLeafClass *previous;  //!< Previous leaf on this level | 
|---|
|  | 588 | MoleculeLeafClass *next;      //!< Next leaf on this level | 
|---|
|  | 589 |  | 
|---|
|  | 590 | //MoleculeLeafClass(MoleculeLeafClass *Up, MoleculeLeafClass *Previous); | 
|---|
|  | 591 | MoleculeLeafClass(MoleculeLeafClass *PreviousLeaf); | 
|---|
|  | 592 | ~MoleculeLeafClass(); | 
|---|
|  | 593 |  | 
|---|
|  | 594 | bool AddLeaf(molecule *ptr, MoleculeLeafClass *Previous); | 
|---|
|  | 595 | }; | 
|---|
|  | 596 |  | 
|---|
|  | 597 | /** The config file. | 
|---|
|  | 598 | * The class contains all parameters that control a dft run also functions to load and save. | 
|---|
|  | 599 | */ | 
|---|
|  | 600 | class config { | 
|---|
|  | 601 | public: | 
|---|
|  | 602 | int PsiType; | 
|---|
|  | 603 | int MaxPsiDouble; | 
|---|
|  | 604 | int PsiMaxNoUp; | 
|---|
|  | 605 | int PsiMaxNoDown; | 
|---|
|  | 606 | int MaxMinStopStep; | 
|---|
|  | 607 | int InitMaxMinStopStep; | 
|---|
|  | 608 | int ProcPEGamma; | 
|---|
|  | 609 | int ProcPEPsi; | 
|---|
|  | 610 |  | 
|---|
|  | 611 | private: | 
|---|
|  | 612 | char *mainname; | 
|---|
|  | 613 | char *defaultpath; | 
|---|
|  | 614 | char *pseudopotpath; | 
|---|
|  | 615 |  | 
|---|
|  | 616 | int DoOutVis; | 
|---|
|  | 617 | int DoOutMes; | 
|---|
|  | 618 | int DoOutNICS; | 
|---|
|  | 619 | int DoOutOrbitals; | 
|---|
|  | 620 | int DoOutCurrent; | 
|---|
|  | 621 | int DoFullCurrent; | 
|---|
|  | 622 | int DoPerturbation; | 
|---|
|  | 623 | int CommonWannier; | 
|---|
|  | 624 | double SawtoothStart; | 
|---|
|  | 625 | int VectorPlane; | 
|---|
|  | 626 | double VectorCut; | 
|---|
|  | 627 | int UseAddGramSch; | 
|---|
|  | 628 | int Seed; | 
|---|
|  | 629 |  | 
|---|
|  | 630 | int MaxOuterStep; | 
|---|
|  | 631 | double Deltat; | 
|---|
|  | 632 | int OutVisStep; | 
|---|
|  | 633 | int OutSrcStep; | 
|---|
|  | 634 | double TargetTemp; | 
|---|
|  | 635 | int ScaleTempStep; | 
|---|
|  | 636 | int MaxPsiStep; | 
|---|
|  | 637 | double EpsWannier; | 
|---|
|  | 638 |  | 
|---|
|  | 639 | int MaxMinStep; | 
|---|
|  | 640 | double RelEpsTotalEnergy; | 
|---|
|  | 641 | double RelEpsKineticEnergy; | 
|---|
|  | 642 | int MaxMinGapStopStep; | 
|---|
|  | 643 | int MaxInitMinStep; | 
|---|
|  | 644 | double InitRelEpsTotalEnergy; | 
|---|
|  | 645 | double InitRelEpsKineticEnergy; | 
|---|
|  | 646 | int InitMaxMinGapStopStep; | 
|---|
|  | 647 |  | 
|---|
|  | 648 | //double BoxLength[NDIM*NDIM]; | 
|---|
|  | 649 |  | 
|---|
|  | 650 | double ECut; | 
|---|
|  | 651 | int MaxLevel; | 
|---|
|  | 652 | int RiemannTensor; | 
|---|
|  | 653 | int LevRFactor; | 
|---|
|  | 654 | int RiemannLevel; | 
|---|
|  | 655 | int Lev0Factor; | 
|---|
|  | 656 | int RTActualUse; | 
|---|
|  | 657 | int AddPsis; | 
|---|
|  | 658 |  | 
|---|
|  | 659 | double RCut; | 
|---|
|  | 660 | int StructOpt; | 
|---|
|  | 661 | int IsAngstroem; | 
|---|
|  | 662 | int RelativeCoord; | 
|---|
|  | 663 | int MaxTypes; | 
|---|
|  | 664 |  | 
|---|
|  | 665 |  | 
|---|
|  | 666 | 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); | 
|---|
|  | 667 |  | 
|---|
|  | 668 | public: | 
|---|
|  | 669 | config(); | 
|---|
|  | 670 | ~config(); | 
|---|
|  | 671 |  | 
|---|
|  | 672 | int TestSyntax(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
|  | 673 | void Load(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
|  | 674 | void LoadOld(ifstream *file, periodentafel *periode, molecule *mol); | 
|---|
|  | 675 | bool Save(ofstream *file, periodentafel *periode, molecule *mol) const; | 
|---|
|  | 676 | void Edit(molecule *mol); | 
|---|
|  | 677 | bool GetIsAngstroem() const; | 
|---|
|  | 678 | char *GetDefaultPath() const; | 
|---|
|  | 679 | void config::SetDefaultPath(const char *path); | 
|---|
|  | 680 | }; | 
|---|
|  | 681 |  | 
|---|
|  | 682 | #endif /*MOLECULES_HPP_*/ | 
|---|
|  | 683 |  | 
|---|