| [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 | // system specific headers
 | 
|---|
 | 23 | #include <time.h>
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | #include "helpers.hpp"
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | class atom;
 | 
|---|
 | 29 | class AtomStackClass;
 | 
|---|
 | 30 | class bond;
 | 
|---|
 | 31 | class config;
 | 
|---|
 | 32 | class element;
 | 
|---|
 | 33 | class molecule;
 | 
|---|
 | 34 | class MoleculeListClass;
 | 
|---|
 | 35 | class periodentafel;
 | 
|---|
 | 36 | class vector;
 | 
|---|
 | 37 | class Verbose;
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | /******************************** Some definitions for easier reading **********************************/
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #define KeyStack deque<int>
 | 
|---|
 | 42 | #define KeySet set<int>
 | 
|---|
 | 43 | #define Graph map<KeySet, pair<int, double>, KeyCompare >
 | 
|---|
 | 44 | #define GraphPair pair<KeySet, pair<int, double> >
 | 
|---|
 | 45 | #define KeySetTestPair pair<KeySet::iterator, bool>
 | 
|---|
 | 46 | #define GraphTestPair pair<Graph::iterator, bool>
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 | struct KeyCompare
 | 
|---|
 | 49 | {
 | 
|---|
 | 50 |   bool operator() (const KeySet SubgraphA, const KeySet SubgraphB) const;
 | 
|---|
 | 51 | };
 | 
|---|
 | 52 | //bool operator < (KeySet SubgraphA, KeySet SubgraphB);   //note: this declaration is important, otherwise normal < is used (producing wrong order)
 | 
|---|
 | 53 | inline void InsertFragmentIntoGraph(ofstream *out, struct UniqueFragments *Fragment); // Insert a KeySet into a Graph
 | 
|---|
 | 54 | inline void InsertGraphIntoGraph(ofstream *out, Graph &graph1, Graph &graph2, int *counter);  // Insert all KeySet's in a Graph into another Graph 
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | /******************************** Some templates for list management ***********************************/
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | /** Adds linking of an item to a list.
 | 
|---|
 | 59 |  * \param *walker
 | 
|---|
 | 60 |  * \return true - adding succeeded, false - error in list
 | 
|---|
 | 61 |  */
 | 
|---|
 | 62 | template <typename X> void link(X *walker, X *end)
 | 
|---|
 | 63 | {
 | 
|---|
 | 64 |   X *vorher = end->previous;
 | 
|---|
 | 65 |   if (vorher != NULL)
 | 
|---|
 | 66 |     vorher->next = walker;
 | 
|---|
 | 67 |   end->previous = walker;
 | 
|---|
 | 68 |   walker->previous = vorher;
 | 
|---|
 | 69 |   walker->next = end;
 | 
|---|
 | 70 | };
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | /** Removes linking of an item in a list.
 | 
|---|
 | 73 |  * \param *walker
 | 
|---|
 | 74 |  * \return true - removing succeeded, false - given item not found in list
 | 
|---|
 | 75 |  */
 | 
|---|
 | 76 | template <typename X> void unlink(X *walker)
 | 
|---|
 | 77 | {
 | 
|---|
 | 78 |   if (walker->next != NULL) 
 | 
|---|
 | 79 |     walker->next->previous = walker->previous;
 | 
|---|
 | 80 |   if (walker->previous != NULL)
 | 
|---|
 | 81 |     walker->previous->next = walker->next;
 | 
|---|
 | 82 | };
 | 
|---|
 | 83 | 
 | 
|---|
 | 84 | /** Adds new item before an item \a *end in a list.
 | 
|---|
 | 85 |  * \param *pointer   item to be added
 | 
|---|
 | 86 |  * \param *end  end of list
 | 
|---|
 | 87 |  * \return true - addition succeeded, false - unable to add item to list
 | 
|---|
 | 88 |  */
 | 
|---|
 | 89 | template <typename X>  bool add(X *pointer, X *end)
 | 
|---|
 | 90 | {
 | 
|---|
 | 91 |   if (end != NULL) {
 | 
|---|
 | 92 |     link(pointer, end);
 | 
|---|
 | 93 |   } else {
 | 
|---|
 | 94 |     pointer->previous = NULL;
 | 
|---|
 | 95 |     pointer->next = NULL; 
 | 
|---|
 | 96 |   }
 | 
|---|
 | 97 |   return true;
 | 
|---|
 | 98 | };
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | /** Finds item in list
 | 
|---|
 | 101 |  * \param *suche  search criteria
 | 
|---|
 | 102 |  * \param *start  begin of list
 | 
|---|
 | 103 |  * \param *end  end of list
 | 
|---|
 | 104 |  * \return X - if found, NULL - if not found
 | 
|---|
 | 105 |  */
 | 
|---|
 | 106 | template <typename X, typename Y> X * find(Y *suche, X *start, X *end)
 | 
|---|
 | 107 | {
 | 
|---|
 | 108 |   X *walker = start;
 | 
|---|
 | 109 |   while (walker->next != end) { // go through list
 | 
|---|
 | 110 |     walker = walker->next; // step onward beforehand
 | 
|---|
 | 111 |     if (*walker->sort == *suche) return (walker);
 | 
|---|
 | 112 |   }
 | 
|---|
 | 113 |   return NULL;
 | 
|---|
 | 114 | };
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | /** Removes an item from the list without check.
 | 
|---|
 | 117 |  * \param *walker item to be removed
 | 
|---|
 | 118 |  * \return true - removing succeeded, false - given item not found in list
 | 
|---|
 | 119 |  */
 | 
|---|
 | 120 | template <typename X> void removewithoutcheck(X *walker)
 | 
|---|
 | 121 | {
 | 
|---|
 | 122 |   if (walker != NULL) {
 | 
|---|
 | 123 |     unlink(walker);
 | 
|---|
 | 124 |     delete(walker);
 | 
|---|
 | 125 |     walker = NULL;
 | 
|---|
 | 126 |   }
 | 
|---|
 | 127 | };
 | 
|---|
 | 128 | 
 | 
|---|
 | 129 | /** Removes an item from the list, checks if exists.
 | 
|---|
 | 130 |  * Checks beforehand if atom is really within molecule list.
 | 
|---|
 | 131 |  * \param *pointer   item to be removed
 | 
|---|
 | 132 |  * \param *start  begin of list
 | 
|---|
 | 133 |  * \param *end  end of list
 | 
|---|
 | 134 |  * \return true - removing succeeded, false - given item not found in list
 | 
|---|
 | 135 |  */
 | 
|---|
 | 136 | template <typename X> bool remove(X *pointer, X *start, X *end)
 | 
|---|
 | 137 | {
 | 
|---|
 | 138 |   X *walker = find (pointer->sort, start, end);
 | 
|---|
 | 139 | /*  while (walker->next != pointer) { // search through list
 | 
|---|
 | 140 |     walker = walker->next;
 | 
|---|
 | 141 |     if (walker == end) return false;  // item not found in list
 | 
|---|
 | 142 |   }*/
 | 
|---|
 | 143 |   // atom found, now unlink
 | 
|---|
 | 144 |   if (walker != NULL)
 | 
|---|
 | 145 |     removewithoutcheck(walker);
 | 
|---|
 | 146 |   else
 | 
|---|
 | 147 |     return false;
 | 
|---|
 | 148 |   return true;
 | 
|---|
 | 149 | };
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 | /** Cleans the whole list.
 | 
|---|
 | 152 |  * \param *start begin of list
 | 
|---|
 | 153 |  * \param *end end of list
 | 
|---|
 | 154 |  * \return true - list was cleaned successfully, false - error in list structure
 | 
|---|
 | 155 |  */
 | 
|---|
 | 156 | template <typename X> bool cleanup(X *start, X *end)
 | 
|---|
 | 157 | {
 | 
|---|
 | 158 |   X *pointer = start->next;
 | 
|---|
 | 159 |   X *walker;
 | 
|---|
 | 160 |   while (pointer != end) { // go through list
 | 
|---|
 | 161 |     walker = pointer; // mark current
 | 
|---|
 | 162 |     pointer = pointer->next; // step onward beforehand
 | 
|---|
 | 163 |     // remove walker
 | 
|---|
 | 164 |     unlink(walker);
 | 
|---|
 | 165 |     delete(walker);
 | 
|---|
 | 166 |     walker = NULL;
 | 
|---|
 | 167 |   }
 | 
|---|
 | 168 |   return true;
 | 
|---|
 | 169 | };
 | 
|---|
 | 170 | 
 | 
|---|
 | 171 | /** Returns the first marker in a chain list.
 | 
|---|
 | 172 |  * \param *me one arbitrary item in chain list
 | 
|---|
 | 173 |  * \return poiner to first marker
 | 
|---|
 | 174 |  */
 | 
|---|
 | 175 | template <typename X> X *GetFirst(X *me)
 | 
|---|
 | 176 | {
 | 
|---|
 | 177 |   X *Binder = me;
 | 
|---|
 | 178 |   while(Binder->previous != NULL)
 | 
|---|
 | 179 |     Binder = Binder->previous;
 | 
|---|
 | 180 |   return Binder;
 | 
|---|
 | 181 | }; 
 | 
|---|
 | 182 | 
 | 
|---|
 | 183 | /** Returns the last marker in a chain list.
 | 
|---|
 | 184 |  * \param *me one arbitrary item in chain list
 | 
|---|
 | 185 |  * \return poiner to last marker
 | 
|---|
 | 186 |  */
 | 
|---|
 | 187 | template <typename X> X *GetLast(X *me)
 | 
|---|
 | 188 | {
 | 
|---|
 | 189 |   X *Binder = me;
 | 
|---|
 | 190 |   while(Binder->next != NULL)
 | 
|---|
 | 191 |     Binder = Binder->next;
 | 
|---|
 | 192 |   return Binder;
 | 
|---|
 | 193 | }; 
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 | /** Frees a two-dimensional array.
 | 
|---|
 | 196 |  * \param *ptr pointer to array
 | 
|---|
 | 197 |  * \param dim first dim of array
 | 
|---|
 | 198 |  */
 | 
|---|
 | 199 | template <typename X> void Free2DArray(X **ptr, int dim)
 | 
|---|
 | 200 | {
 | 
|---|
 | 201 |         int i;
 | 
|---|
 | 202 |         if (ptr != NULL) {
 | 
|---|
 | 203 |                 for(i=0;i<dim;i++)
 | 
|---|
 | 204 |                         if (ptr[i] != NULL)
 | 
|---|
 | 205 |                                 free(ptr[i]);
 | 
|---|
 | 206 |                 free(ptr);
 | 
|---|
 | 207 |         }
 | 
|---|
 | 208 | };
 | 
|---|
 | 209 | 
 | 
|---|
 | 210 | int CompareDoubles (const void * a, const void * b);
 | 
|---|
 | 211 | 
 | 
|---|
 | 212 | /************************************* Class definitions ****************************************/
 | 
|---|
 | 213 | 
 | 
|---|
 | 214 | /** Chemical element.
 | 
|---|
 | 215 |  * Class incorporates data for a certain chemical element to be referenced from atom class.
 | 
|---|
 | 216 |  */
 | 
|---|
 | 217 | class element {
 | 
|---|
 | 218 |   public:
 | 
|---|
 | 219 |     double mass;    //!< mass in g/mol
 | 
|---|
 | 220 |     double CovalentRadius;  //!< covalent radius
 | 
|---|
 | 221 |     double VanDerWaalsRadius;  //!< can-der-Waals radius
 | 
|---|
 | 222 |     int Z;          //!< atomic number
 | 
|---|
 | 223 |     char name[64];  //!< atom name, i.e. "Hydrogren"
 | 
|---|
 | 224 |     char symbol[3]; //!< short form of the atom, i.e. "H"
 | 
|---|
 | 225 |     char period[8];    //!< period: n quantum number
 | 
|---|
 | 226 |     char group[8];    //!< group: l quantum number
 | 
|---|
 | 227 |     char block[8];    //!< block: l quantum number
 | 
|---|
 | 228 |     element *previous;  //!< previous item in list
 | 
|---|
 | 229 |     element *next;  //!< next element in list
 | 
|---|
 | 230 |     int *sort;      //!< sorc criteria
 | 
|---|
 | 231 |     int No;         //!< number of element set on periodentafel::Output()
 | 
|---|
 | 232 |     double Valence;             //!< number of valence electrons for this element
 | 
|---|
 | 233 |     int NoValenceOrbitals;  //!< number of valence orbitals, used for determining bond degree in molecule::CreateConnectmatrix()
 | 
|---|
 | 234 |     double HBondDistance[NDIM]; //!< distance in Angstrom of this element to hydrogen  (for single, double and triple bonds)
 | 
|---|
 | 235 |     double HBondAngle[NDIM];     //!< typical angle for one, two, three bonded hydrogen (in degrees)
 | 
|---|
 | 236 | 
 | 
|---|
 | 237 |   element();
 | 
|---|
 | 238 |   ~element();
 | 
|---|
 | 239 | 
 | 
|---|
 | 240 |   //> print element entries to screen
 | 
|---|
 | 241 |   bool Output(ofstream *out) const;
 | 
|---|
 | 242 |   bool Checkout(ofstream *out, const int No, const int NoOfAtoms) const;
 | 
|---|
 | 243 |   
 | 
|---|
 | 244 |   private:
 | 
|---|
 | 245 | };
 | 
|---|
 | 246 | 
 | 
|---|
 | 247 | /** Periodentafel is a list of all elements sorted by their atomic number.
 | 
|---|
 | 248 |  */
 | 
|---|
 | 249 | class periodentafel {
 | 
|---|
 | 250 |   public:
 | 
|---|
 | 251 |     element *start; //!< start of element list
 | 
|---|
 | 252 |     element *end;   //!< end of element list
 | 
|---|
 | 253 |     char header1[255]; //!< store first header line
 | 
|---|
 | 254 |     char header2[255]; //!< store second header line
 | 
|---|
 | 255 |   
 | 
|---|
 | 256 |   periodentafel();
 | 
|---|
 | 257 |   ~periodentafel(); 
 | 
|---|
 | 258 |   
 | 
|---|
 | 259 |   bool AddElement(element *pointer);
 | 
|---|
 | 260 |   bool RemoveElement(element *pointer);
 | 
|---|
 | 261 |   bool CleanupPeriodtable();
 | 
|---|
 | 262 |   element * FindElement(int Z);
 | 
|---|
 | 263 |   element * FindElement(char *shorthand) const;
 | 
|---|
 | 264 |   element * AskElement(); 
 | 
|---|
 | 265 |   bool Output(ofstream *output) const;
 | 
|---|
 | 266 |   bool Checkout(ofstream *output, const int *checkliste) const;
 | 
|---|
 | 267 |   bool LoadPeriodentafel();
 | 
|---|
 | 268 |   bool StorePeriodentafel() const;
 | 
|---|
 | 269 |   
 | 
|---|
 | 270 |   private:
 | 
|---|
 | 271 | };
 | 
|---|
 | 272 | 
 | 
|---|
 | 273 | // some algebraic matrix stuff
 | 
|---|
 | 274 | #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
 | 
|---|
 | 275 | #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
 | 
|---|
 | 276 | 
 | 
|---|
 | 277 | /** Single vector.
 | 
|---|
 | 278 |  * basically, just a x[3] but with helpful functions
 | 
|---|
 | 279 |  */
 | 
|---|
 | 280 | class vector {   
 | 
|---|
 | 281 |   public:
 | 
|---|
 | 282 |     double x[NDIM];
 | 
|---|
 | 283 | 
 | 
|---|
 | 284 |   vector();
 | 
|---|
 | 285 |   ~vector();
 | 
|---|
 | 286 | 
 | 
|---|
 | 287 |   double Distance(const vector *y) const;
 | 
|---|
 | 288 |   double PeriodicDistance(const vector *y, const double *cell_size) const;
 | 
|---|
 | 289 |   double ScalarProduct(const vector *y) const;
 | 
|---|
 | 290 |   double Projection(const vector *y) const;
 | 
|---|
 | 291 |   double Norm() const ;
 | 
|---|
 | 292 |   double Angle(vector *y) const;
 | 
|---|
 | 293 | 
 | 
|---|
 | 294 |   void AddVector(const vector *y);
 | 
|---|
 | 295 |   void SubtractVector(const vector *y);
 | 
|---|
 | 296 |   void CopyVector(const vector *y);
 | 
|---|
 | 297 |   void RotateVector(const vector *y, const double alpha);
 | 
|---|
 | 298 |   void Zero(); 
 | 
|---|
 | 299 |   void Normalize();
 | 
|---|
 | 300 |   void Translate(const vector *x);
 | 
|---|
 | 301 |   void Mirror(const vector *x);
 | 
|---|
 | 302 |   void Scale(double **factor);
 | 
|---|
 | 303 |   void Scale(double *factor);
 | 
|---|
 | 304 |   void Scale(double factor);
 | 
|---|
 | 305 |   void MatrixMultiplication(double *M);
 | 
|---|
 | 306 |   void InverseMatrixMultiplication(double *M);
 | 
|---|
 | 307 |   void KeepPeriodic(ofstream *out, double *matrix);
 | 
|---|
 | 308 |   void LinearCombinationOfVectors(const vector *x1, const vector *x2, const vector *x3, double *factors);
 | 
|---|
 | 309 |   
 | 
|---|
 | 310 |   bool GetOneNormalVector(const vector *x1);
 | 
|---|
 | 311 |   bool MakeNormalVector(const vector *y1);
 | 
|---|
 | 312 |   bool MakeNormalVector(const vector *y1, const vector *y2);
 | 
|---|
 | 313 |   bool MakeNormalVector(const vector *x1, const vector *x2, const vector *x3);
 | 
|---|
 | 314 |   bool SolveSystem(vector *x1, vector *x2, vector *y, double alpha, double beta, double c);
 | 
|---|
 | 315 |         bool LSQdistance(vector **vectors, int dim);
 | 
|---|
 | 316 | 
 | 
|---|
 | 317 |   void AskPosition(double *cell_size, bool check);
 | 
|---|
 | 318 |   bool Output(ofstream *out) const;
 | 
|---|
 | 319 | };
 | 
|---|
 | 320 | 
 | 
|---|
 | 321 | ofstream& operator<<(ofstream& ost, vector& m);
 | 
|---|
 | 322 | 
 | 
|---|
 | 323 | /** Parameter structure for least square minimsation.
 | 
|---|
 | 324 |  */
 | 
|---|
 | 325 | struct LSQ_params {
 | 
|---|
 | 326 |   vector **vectors;
 | 
|---|
 | 327 |   int num;
 | 
|---|
 | 328 | };
 | 
|---|
 | 329 | 
 | 
|---|
 | 330 | double LSQ(const gsl_vector * x, void * params);
 | 
|---|
 | 331 | 
 | 
|---|
 | 332 | /** Parameter structure for least square minimsation.
 | 
|---|
 | 333 |  */
 | 
|---|
 | 334 | struct lsq_params {
 | 
|---|
 | 335 |   gsl_vector *x;
 | 
|---|
 | 336 |   const molecule *mol;
 | 
|---|
 | 337 |   element *type;
 | 
|---|
 | 338 | };
 | 
|---|
 | 339 | 
 | 
|---|
 | 340 | 
 | 
|---|
 | 341 | 
 | 
|---|
 | 342 | /** Single atom.
 | 
|---|
 | 343 |  * Class incoporates position, type
 | 
|---|
 | 344 |  */
 | 
|---|
 | 345 | class atom {
 | 
|---|
 | 346 |   public:
 | 
|---|
| [090299] | 347 |     vector x;       //!< coordinate array of atom, giving position within cell
 | 
|---|
 | 348 |     vector v;       //!< velocity array of atom
 | 
|---|
| [a0bcf1] | 349 |     element *type;  //!< pointing to element
 | 
|---|
 | 350 |     atom *previous; //!< previous atom in molecule list
 | 
|---|
 | 351 |     atom *next;     //!< next atom in molecule list
 | 
|---|
 | 352 |     atom *father;   //!< In many-body bond order fragmentations points to originating atom
 | 
|---|
 | 353 |     atom *Ancestor; //!< "Father" in Depth-First-Search
 | 
|---|
 | 354 |     char *Name;                 //!< unique name used during many-body bond-order fragmentation
 | 
|---|
| [090299] | 355 |     int FixedIon;   //!< config variable that states whether forces act on the ion or not
 | 
|---|
| [a0bcf1] | 356 |     int *sort;      //!< sort criteria
 | 
|---|
 | 357 |     int nr;         //!< continuous, unique number
 | 
|---|
 | 358 |     int GraphNr;      //!< unique number, given in DepthFirstSearchAnalysis()
 | 
|---|
 | 359 |     int *ComponentNr;//!< belongs to this nonseparable components, given in DepthFirstSearchAnalysis() (if more than one, then is SeparationVertex)
 | 
|---|
 | 360 |     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.
 | 
|---|
 | 361 |     bool SeparationVertex; //!< whether this atom separates off subsets of atoms or not, given in DepthFirstSearchAnalysis()
 | 
|---|
 | 362 |   
 | 
|---|
 | 363 |   atom();
 | 
|---|
 | 364 |   ~atom();
 | 
|---|
 | 365 |   
 | 
|---|
 | 366 |   bool Output(int ElementNo, int AtomNo, ofstream *out) const;
 | 
|---|
 | 367 |   bool OutputXYZLine(ofstream *out) const;
 | 
|---|
 | 368 |   atom *GetTrueFather();
 | 
|---|
 | 369 |   bool Compare(atom &ptr);
 | 
|---|
 | 370 |   
 | 
|---|
 | 371 |   private:
 | 
|---|
 | 372 | };
 | 
|---|
 | 373 | 
 | 
|---|
 | 374 | ostream & operator << (ostream &ost, atom &a);
 | 
|---|
 | 375 | 
 | 
|---|
 | 376 | /* Stack of Atoms.
 | 
|---|
 | 377 |  * Is used during DepthFirstSearchAnalysis() to detect nonseparable components.
 | 
|---|
 | 378 |  */
 | 
|---|
 | 379 | class AtomStackClass {
 | 
|---|
 | 380 |   public:
 | 
|---|
 | 381 |   AtomStackClass(int dimension);
 | 
|---|
 | 382 |   ~AtomStackClass();
 | 
|---|
 | 383 |   
 | 
|---|
 | 384 |   bool Push(atom *object);
 | 
|---|
 | 385 |   atom *PopFirst();
 | 
|---|
 | 386 |   atom *PopLast();
 | 
|---|
 | 387 |   bool AtomStackClass::RemoveItem(atom *ptr);
 | 
|---|
 | 388 |   void ClearStack();
 | 
|---|
 | 389 |   bool IsEmpty();
 | 
|---|
 | 390 |   bool IsFull();
 | 
|---|
 | 391 |         int ItemCount();
 | 
|---|
 | 392 |   void Output(ofstream *out) const;
 | 
|---|
 | 393 |   void TestImplementation(ofstream *out, atom *test);
 | 
|---|
 | 394 |   
 | 
|---|
 | 395 |   private:
 | 
|---|
 | 396 |     atom **StackList;   //!< the list containing the atom pointers
 | 
|---|
 | 397 |     int EntryCount;     //!< number of entries in the stack
 | 
|---|
 | 398 |     int CurrentLastEntry;   //!< Current last entry (newest item on stack)
 | 
|---|
 | 399 |     int CurrentFirstEntry;   //!< Current first entry (oldest item on stack)
 | 
|---|
 | 400 |     int NextFreeField;       //!< Current index of next free field
 | 
|---|
 | 401 | };
 | 
|---|
 | 402 | 
 | 
|---|
 | 403 | 
 | 
|---|
 | 404 | /** Bonds between atoms.
 | 
|---|
 | 405 |  * Class incorporates bonds between atoms in a molecule,
 | 
|---|
 | 406 |  * used to derive tge fragments in many-body bond order
 | 
|---|
 | 407 |  * calculations.
 | 
|---|
 | 408 |  */
 | 
|---|
 | 409 | class bond {
 | 
|---|
 | 410 |   public:
 | 
|---|
 | 411 |         atom *leftatom;         //!< first bond partner
 | 
|---|
 | 412 |         atom *rightatom;        //!< second bond partner
 | 
|---|
 | 413 |     bond *previous; //!< previous atom in molecule list
 | 
|---|
 | 414 |     bond *next;     //!< next atom in molecule list
 | 
|---|
 | 415 |         int HydrogenBond;       //!< Number of hydrogen atoms in the bond
 | 
|---|
 | 416 |         int BondDegree;         //!< single, double, triple, ... bond
 | 
|---|
 | 417 |     int nr;           //!< unique number in a molecule, updated by molecule::CreateAdjacencyList()
 | 
|---|
 | 418 |     bool Cyclic;      //!< flag whether bond is part of a cycle or not, given in DepthFirstSearchAnalysis()
 | 
|---|
 | 419 |     enum EdgeType Type;//!< whether this is a tree or back edge 
 | 
|---|
 | 420 |         
 | 
|---|
 | 421 |   atom * GetOtherAtom(atom *Atom) const;
 | 
|---|
 | 422 |   bond * GetFirstBond();
 | 
|---|
 | 423 |   bond * GetLastBond();
 | 
|---|
 | 424 |   
 | 
|---|
 | 425 |   bool MarkUsed(enum Shading color);
 | 
|---|
 | 426 |   enum Shading IsUsed();
 | 
|---|
 | 427 |   void ResetUsed();
 | 
|---|
 | 428 |   bool Contains(const atom *ptr);
 | 
|---|
 | 429 |   bool Contains(const int nr);
 | 
|---|
 | 430 |   
 | 
|---|
 | 431 |   bond();
 | 
|---|
 | 432 |   bond(atom *left, atom *right);
 | 
|---|
 | 433 |   bond(atom *left, atom *right, int degree);
 | 
|---|
 | 434 |   bond(atom *left, atom *right, int degree, int number);
 | 
|---|
 | 435 |   ~bond();
 | 
|---|
 | 436 |     
 | 
|---|
 | 437 |   private: 
 | 
|---|
 | 438 |     enum Shading Used;        //!< marker in depth-first search, DepthFirstSearchAnalysis()
 | 
|---|
 | 439 | };
 | 
|---|
 | 440 | 
 | 
|---|
 | 441 | ostream & operator << (ostream &ost, bond &b);
 | 
|---|
 | 442 | 
 | 
|---|
 | 443 | class MoleculeLeafClass;
 | 
|---|
 | 444 | 
 | 
|---|
 | 445 | /** The complete molecule.
 | 
|---|
 | 446 |  * Class incorporates number of types
 | 
|---|
 | 447 |  */
 | 
|---|
 | 448 | class molecule {
 | 
|---|
 | 449 |   public:
 | 
|---|
 | 450 |     double cell_size[6];//!< cell size
 | 
|---|
 | 451 |     periodentafel *elemente; //!< periodic table with each element
 | 
|---|
 | 452 |     atom *start;        //!< start of atom list
 | 
|---|
 | 453 |     atom *end;          //!< end of atom list
 | 
|---|
 | 454 |     bond *first;        //!< start of bond list
 | 
|---|
 | 455 |     bond *last;         //!< end of bond list
 | 
|---|
 | 456 |     bond ***ListOfBondsPerAtom; //!< pointer list for each atom and each bond it has
 | 
|---|
 | 457 |     int *NumberOfBondsPerAtom;  //!< Number of Bonds each atom has
 | 
|---|
 | 458 |     int AtomCount;                                      //!< number of atoms, brought up-to-date by CountAtoms()
 | 
|---|
 | 459 |     int BondCount;                                      //!< number of atoms, brought up-to-date by CountBonds()
 | 
|---|
 | 460 |     int ElementCount;       //!< how many unique elements are therein
 | 
|---|
 | 461 |     int ElementsInMolecule[MAX_ELEMENTS]; //!< list whether element (sorted by atomic number) is alread present or not
 | 
|---|
 | 462 |     int NoNonHydrogen;  //!< number of non-hydrogen atoms in molecule
 | 
|---|
 | 463 |     int NoNonBonds;     //!< number of non-hydrogen bonds in molecule
 | 
|---|
 | 464 |     int NoCyclicBonds;  //!< number of cyclic bonds in molecule, by DepthFirstSearchAnalysis()
 | 
|---|
 | 465 |     double BondDistance;  //!< typical bond distance used in CreateAdjacencyList() and furtheron
 | 
|---|
 | 466 |   
 | 
|---|
 | 467 |   molecule(periodentafel *teil);
 | 
|---|
 | 468 |   ~molecule();
 | 
|---|
 | 469 |   
 | 
|---|
 | 470 |   /// remove atoms from molecule.
 | 
|---|
 | 471 |   bool AddAtom(atom *pointer);
 | 
|---|
 | 472 |   bool RemoveAtom(atom *pointer);
 | 
|---|
 | 473 |   bool CleanupMolecule();
 | 
|---|
 | 474 | 
 | 
|---|
 | 475 |   /// Add/remove atoms to/from molecule.
 | 
|---|
 | 476 |   atom * AddCopyAtom(atom *pointer);
 | 
|---|
 | 477 |   bool AddXYZFile(string filename);
 | 
|---|
 | 478 |   bool AddHydrogenReplacementAtom(ofstream *out, bond *Bond, atom *BottomOrigin, atom *TopOrigin, atom *TopReplacement, bond **BondList, int NumBond, bool IsAngstroem);  
 | 
|---|
 | 479 |   bond * AddBond(atom *first, atom *second, int degree);
 | 
|---|
 | 480 |   bool RemoveBond(bond *pointer);
 | 
|---|
 | 481 |   bool RemoveBonds(atom *BondPartner);
 | 
|---|
 | 482 |     
 | 
|---|
 | 483 |   /// Find atoms.
 | 
|---|
 | 484 |   atom * FindAtom(int Nr) const; 
 | 
|---|
 | 485 |   atom * AskAtom(char *text);
 | 
|---|
 | 486 | 
 | 
|---|
 | 487 |   /// Count and change present atoms' coordination.
 | 
|---|
 | 488 |   void CountAtoms(ofstream *out);
 | 
|---|
 | 489 |   void CountElements();
 | 
|---|
 | 490 |   void CalculateOrbitals(class config &configuration);
 | 
|---|
 | 491 |   void CenterEdge(ofstream *out, vector *max); 
 | 
|---|
 | 492 |   void CenterOrigin(ofstream *out, vector *max); 
 | 
|---|
 | 493 |   void CenterGravity(ofstream *out, vector *max); 
 | 
|---|
 | 494 |   void Translate(const vector *x);
 | 
|---|
 | 495 |   void Mirror(const vector *x);
 | 
|---|
 | 496 |   void Align(vector *n);
 | 
|---|
 | 497 |   void Scale(double **factor);
 | 
|---|
 | 498 |   void DetermineCenterOfGravity(vector &CenterOfGravity);
 | 
|---|
 | 499 |   void SetBoxDimension(vector *dim);
 | 
|---|
 | 500 |   double * ReturnFullMatrixforSymmetric(double *cell_size);
 | 
|---|
 | 501 |   void ScanForPeriodicCorrection(ofstream *out);
 | 
|---|
 | 502 | 
 | 
|---|
 | 503 |   bool CheckBounds(const vector *x) const;
 | 
|---|
 | 504 |   void GetAlignVector(struct lsq_params * par) const;
 | 
|---|
 | 505 | 
 | 
|---|
 | 506 |   /// Initialising routines in fragmentation  
 | 
|---|
 | 507 |   void CreateAdjacencyList(ofstream *out, double bonddistance);
 | 
|---|
 | 508 |   void CreateListOfBondsPerAtom(ofstream *out);
 | 
|---|
 | 509 |   
 | 
|---|
 | 510 |   // Graph analysis
 | 
|---|
 | 511 |   MoleculeLeafClass * DepthFirstSearchAnalysis(ofstream *out, bool ReturnStack, int &MinimumRingSize);
 | 
|---|
 | 512 |   void CyclicStructureAnalysis(ofstream *out, int &MinimumRingSize);
 | 
|---|
 | 513 |   bond * FindNextUnused(atom *vertex);
 | 
|---|
 | 514 |   void SetNextComponentNumber(atom *vertex, int nr);
 | 
|---|
 | 515 |   void InitComponentNumbers();
 | 
|---|
 | 516 |   void OutputComponentNumber(ofstream *out, atom *vertex);
 | 
|---|
 | 517 |   void ResetAllBondsToUnused();
 | 
|---|
 | 518 |   void ResetAllAtomNumbers();
 | 
|---|
 | 519 |   int CountCyclicBonds(ofstream *out);
 | 
|---|
 | 520 |   char * GetColor(enum Shading color);
 | 
|---|
 | 521 | 
 | 
|---|
 | 522 |   molecule *CopyMolecule();
 | 
|---|
 | 523 |   
 | 
|---|
 | 524 |   /// Fragment molecule by two different approaches:
 | 
|---|
 | 525 |   void FragmentMolecule(ofstream *out, int BottomUpOrder, int TopDownOrder, enum BondOrderScheme Scheme, config *configuration, enum CutCyclicBond CutCyclic);
 | 
|---|
 | 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, config *&configuration);
 | 
|---|
 | 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 | 
 | 
|---|