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