| 1 | /** \file atom.cpp | 
|---|
| 2 | * | 
|---|
| 3 | * Function implementations for the class atom. | 
|---|
| 4 | * | 
|---|
| 5 | */ | 
|---|
| 6 |  | 
|---|
| 7 | #include "atom.hpp" | 
|---|
| 8 | #include "memoryallocator.hpp" | 
|---|
| 9 |  | 
|---|
| 10 | /************************************* Functions for class atom *************************************/ | 
|---|
| 11 |  | 
|---|
| 12 | /** Constructor of class atom. | 
|---|
| 13 | */ | 
|---|
| 14 | atom::atom() | 
|---|
| 15 | { | 
|---|
| 16 | father = this;  // generally, father is itself | 
|---|
| 17 | previous = NULL; | 
|---|
| 18 | next = NULL; | 
|---|
| 19 | Ancestor = NULL; | 
|---|
| 20 | type = NULL; | 
|---|
| 21 | sort = NULL; | 
|---|
| 22 | FixedIon = 0; | 
|---|
| 23 | GraphNr = -1; | 
|---|
| 24 | ComponentNr = NULL; | 
|---|
| 25 | IsCyclic = false; | 
|---|
| 26 | SeparationVertex = false; | 
|---|
| 27 | LowpointNr = -1; | 
|---|
| 28 | AdaptiveOrder = 0; | 
|---|
| 29 | MaxOrder = false; | 
|---|
| 30 | // set LCNode::Vector to our Vector | 
|---|
| 31 | node = &x; | 
|---|
| 32 | }; | 
|---|
| 33 |  | 
|---|
| 34 | /** Constructor of class atom. | 
|---|
| 35 | */ | 
|---|
| 36 | atom::atom(atom *pointer) | 
|---|
| 37 | { | 
|---|
| 38 | Name = NULL; | 
|---|
| 39 | previous = NULL; | 
|---|
| 40 | next = NULL; | 
|---|
| 41 | father = pointer;  // generally, father is itself | 
|---|
| 42 | Ancestor = NULL; | 
|---|
| 43 | GraphNr = -1; | 
|---|
| 44 | ComponentNr = NULL; | 
|---|
| 45 | IsCyclic = false; | 
|---|
| 46 | SeparationVertex = false; | 
|---|
| 47 | LowpointNr = -1; | 
|---|
| 48 | AdaptiveOrder = 0; | 
|---|
| 49 | MaxOrder = false; | 
|---|
| 50 | type = pointer->type;  // copy element of atom | 
|---|
| 51 | x.CopyVector(&pointer->x); // copy coordination | 
|---|
| 52 | v.CopyVector(&pointer->v); // copy velocity | 
|---|
| 53 | FixedIon = pointer->FixedIon; | 
|---|
| 54 | nr = -1; | 
|---|
| 55 | sort = &nr; | 
|---|
| 56 | node = &x; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 | /** Destructor of class atom. | 
|---|
| 61 | */ | 
|---|
| 62 | atom::~atom() | 
|---|
| 63 | { | 
|---|
| 64 | Free<int>(&ComponentNr, "atom::~atom: *ComponentNr"); | 
|---|
| 65 | Free<char *>(&Name, "atom::~atom: *Name"); | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | /** Climbs up the father list until NULL, last is returned. | 
|---|
| 70 | * \return true father, i.e. whose father points to itself, NULL if it could not be found or has none (added hydrogen) | 
|---|
| 71 | */ | 
|---|
| 72 | atom *atom::GetTrueFather() | 
|---|
| 73 | { | 
|---|
| 74 | atom *walker = this; | 
|---|
| 75 | do { | 
|---|
| 76 | if (walker == walker->father) // top most father is the one that points on itself | 
|---|
| 77 | break; | 
|---|
| 78 | walker = walker->father; | 
|---|
| 79 | } while (walker != NULL); | 
|---|
| 80 | return walker; | 
|---|
| 81 | }; | 
|---|
| 82 |  | 
|---|
| 83 | /** Output of a single atom. | 
|---|
| 84 | * \param ElementNo cardinal number of the element | 
|---|
| 85 | * \param AtomNo cardinal number among these atoms of the same element | 
|---|
| 86 | * \param *out stream to output to | 
|---|
| 87 | * \param *comment commentary after '#' sign | 
|---|
| 88 | */ | 
|---|
| 89 | bool atom::Output(int ElementNo, int AtomNo, ofstream *out, const char *comment) const | 
|---|
| 90 | { | 
|---|
| 91 | if (out != NULL) { | 
|---|
| 92 | *out << "Ion_Type" << ElementNo << "_" << AtomNo << "\t"  << fixed << setprecision(9) << showpoint; | 
|---|
| 93 | *out << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2]; | 
|---|
| 94 | *out << "\t" << FixedIon; | 
|---|
| 95 | if (v.Norm() > MYEPSILON) | 
|---|
| 96 | *out << "\t" << scientific << setprecision(6) << v.x[0] << "\t" << v.x[1] << "\t" << v.x[2] << "\t"; | 
|---|
| 97 | if (comment != NULL) | 
|---|
| 98 | *out << " # " << comment << endl; | 
|---|
| 99 | else | 
|---|
| 100 | *out << " # molecule nr " << nr << endl; | 
|---|
| 101 | return true; | 
|---|
| 102 | } else | 
|---|
| 103 | return false; | 
|---|
| 104 | }; | 
|---|
| 105 |  | 
|---|
| 106 | /** Output of a single atom as one lin in xyz file. | 
|---|
| 107 | * \param *out stream to output to | 
|---|
| 108 | */ | 
|---|
| 109 | bool atom::OutputXYZLine(ofstream *out) const | 
|---|
| 110 | { | 
|---|
| 111 | if (out != NULL) { | 
|---|
| 112 | *out << type->symbol << "\t" << x.x[0] << "\t" << x.x[1] << "\t" << x.x[2] << "\t" << endl; | 
|---|
| 113 | return true; | 
|---|
| 114 | } else | 
|---|
| 115 | return false; | 
|---|
| 116 | }; | 
|---|
| 117 |  | 
|---|
| 118 | ostream & operator << (ostream &ost, const atom &a) | 
|---|
| 119 | { | 
|---|
| 120 | ost << "[" << a.Name << "|" << &a << "]"; | 
|---|
| 121 | return ost; | 
|---|
| 122 | }; | 
|---|
| 123 |  | 
|---|
| 124 | ostream & atom::operator << (ostream &ost) | 
|---|
| 125 | { | 
|---|
| 126 | ost << "[" << Name << "|" << this << "]"; | 
|---|
| 127 | return ost; | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | /** Compares the indices of \a this atom with a given \a ptr. | 
|---|
| 131 | * \param ptr atom to compare index against | 
|---|
| 132 | * \return true - this one's is smaller, false - not | 
|---|
| 133 | */ | 
|---|
| 134 | bool atom::Compare(const atom &ptr) | 
|---|
| 135 | { | 
|---|
| 136 | if (nr < ptr.nr) | 
|---|
| 137 | return true; | 
|---|
| 138 | else | 
|---|
| 139 | return false; | 
|---|
| 140 | }; | 
|---|
| 141 |  | 
|---|
| 142 | bool operator < (atom &a, atom &b) | 
|---|
| 143 | { | 
|---|
| 144 | return a.Compare(b); | 
|---|
| 145 | }; | 
|---|
| 146 |  | 
|---|