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