| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
| 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | /** \file element.cpp
 | 
|---|
| 9 |  * 
 | 
|---|
| 10 |  * Function implementations for the class element.
 | 
|---|
| 11 |  * 
 | 
|---|
| 12 |  */
 | 
|---|
| 13 | 
 | 
|---|
| 14 | // include config.h
 | 
|---|
| 15 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 16 | #include <config.h>
 | 
|---|
| 17 | #endif
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include <iomanip>
 | 
|---|
| 22 | #include <fstream>
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 25 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 26 | #include "element.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | using namespace std;
 | 
|---|
| 29 | 
 | 
|---|
| 30 | /************************************* Functions for class element **********************************/
 | 
|---|
| 31 | 
 | 
|---|
| 32 | /** Constructor of class element.
 | 
|---|
| 33 |  */
 | 
|---|
| 34 | element::element() :
 | 
|---|
| 35 |   mass(0),
 | 
|---|
| 36 |   CovalentRadius(0),
 | 
|---|
| 37 |   VanDerWaalsRadius(0),
 | 
|---|
| 38 |         Z(-1),
 | 
|---|
| 39 |         Valence(0),
 | 
|---|
| 40 |         NoValenceOrbitals(0)
 | 
|---|
| 41 | {
 | 
|---|
| 42 | };
 | 
|---|
| 43 | 
 | 
|---|
| 44 | element::element(const element &src) :
 | 
|---|
| 45 |   mass(src.mass),
 | 
|---|
| 46 |   CovalentRadius(src.CovalentRadius),
 | 
|---|
| 47 |   VanDerWaalsRadius(src.VanDerWaalsRadius),
 | 
|---|
| 48 |   Z(src.Z),
 | 
|---|
| 49 |   Valence(src.Valence),
 | 
|---|
| 50 |   NoValenceOrbitals(src.NoValenceOrbitals),
 | 
|---|
| 51 |   name(src.name),
 | 
|---|
| 52 |   symbol(src.symbol)
 | 
|---|
| 53 | {
 | 
|---|
| 54 |   period = src.period;
 | 
|---|
| 55 |   group = src.group;
 | 
|---|
| 56 |   block = src.block;
 | 
|---|
| 57 |   for (size_t i =0; i<3;++i)
 | 
|---|
| 58 |     color[i] = src.color[i];
 | 
|---|
| 59 | }
 | 
|---|
| 60 | 
 | 
|---|
| 61 | /** Destructor of class element.
 | 
|---|
| 62 |  */
 | 
|---|
| 63 | element::~element() {};
 | 
|---|
| 64 | 
 | 
|---|
| 65 | element &element::operator=(const element &src){
 | 
|---|
| 66 |   if(this!=&src){
 | 
|---|
| 67 |     mass=src.mass;
 | 
|---|
| 68 |     CovalentRadius=src.CovalentRadius;
 | 
|---|
| 69 |     VanDerWaalsRadius=src.VanDerWaalsRadius;
 | 
|---|
| 70 |     Z=src.Z;
 | 
|---|
| 71 |     Valence=src.Valence;
 | 
|---|
| 72 |     NoValenceOrbitals=src.NoValenceOrbitals;
 | 
|---|
| 73 |     name=src.name;
 | 
|---|
| 74 |     symbol=src.symbol;
 | 
|---|
| 75 |     for (size_t i =0; i<3;++i)
 | 
|---|
| 76 |       color[i] = src.color[i];
 | 
|---|
| 77 |     period = src.period;
 | 
|---|
| 78 |     group = src.group;
 | 
|---|
| 79 |     block = src.block;
 | 
|---|
| 80 |   }
 | 
|---|
| 81 |   return *this;
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | /** Prints element data to \a *out.
 | 
|---|
| 85 |  * \param *out outstream
 | 
|---|
| 86 |  */
 | 
|---|
| 87 | bool element::Output(ostream * const out) const
 | 
|---|
| 88 | { 
 | 
|---|
| 89 |   if (out != NULL) {
 | 
|---|
| 90 |     *out << name << "\t" << symbol << "\t" << period << "\t" << group << "\t" << block << "\t" << Z << "\t" << mass << "\t" << CovalentRadius << "\t" << VanDerWaalsRadius << endl;
 | 
|---|
| 91 |     //*out << Z << "\t"  << fixed << setprecision(11) << showpoint << mass << "g/mol\t" << name << "\t" << symbol << "\t" << endl;
 | 
|---|
| 92 |     return true;
 | 
|---|
| 93 |   } else
 | 
|---|
| 94 |     return false;
 | 
|---|
| 95 | };
 | 
|---|
| 96 | 
 | 
|---|
| 97 | /** Prints element data to \a *out.
 | 
|---|
| 98 |  * \param *out outstream
 | 
|---|
| 99 |  * \param No  cardinal number of element
 | 
|---|
| 100 |  * \param NoOfAtoms total number of atom of this element type
 | 
|---|
| 101 |  */
 | 
|---|
| 102 | bool element::Checkout(ostream * const out, const int Number, const int NoOfAtoms) const
 | 
|---|
| 103 | { 
 | 
|---|
| 104 |   if (out != NULL) {
 | 
|---|
| 105 |     *out << "Ion_Type" << Number << "\t" << NoOfAtoms << "\t" << Z << "\t1.0\t3\t3\t" << fixed << setprecision(11) << showpoint << mass << "\t" << name << "\t" << symbol <<endl;
 | 
|---|
| 106 |     return true;
 | 
|---|
| 107 |   } else
 | 
|---|
| 108 |     return false;
 | 
|---|
| 109 | };
 | 
|---|
| 110 | 
 | 
|---|
| 111 | atomicNumber_t element::getNumber() const{
 | 
|---|
| 112 |   return Z;
 | 
|---|
| 113 | }
 | 
|---|
| 114 | 
 | 
|---|
| 115 | double element::getMass() const
 | 
|---|
| 116 | {
 | 
|---|
| 117 |   return mass;
 | 
|---|
| 118 | }
 | 
|---|
| 119 | 
 | 
|---|
| 120 | double element::getCovalentRadius() const
 | 
|---|
| 121 | {
 | 
|---|
| 122 |   return CovalentRadius;
 | 
|---|
| 123 | }
 | 
|---|
| 124 | 
 | 
|---|
| 125 | const unsigned char * element::getColor() const
 | 
|---|
| 126 | {
 | 
|---|
| 127 |   return color;
 | 
|---|
| 128 | }
 | 
|---|
| 129 | 
 | 
|---|
| 130 | double element::getElectronegativity() const
 | 
|---|
| 131 | {
 | 
|---|
| 132 |   return Electronegativity;
 | 
|---|
| 133 | }
 | 
|---|
| 134 | 
 | 
|---|
| 135 | double element::getVanDerWaalsRadius() const
 | 
|---|
| 136 | {
 | 
|---|
| 137 |   return VanDerWaalsRadius;
 | 
|---|
| 138 | }
 | 
|---|
| 139 | 
 | 
|---|
| 140 | int element::getAtomicNumber() const
 | 
|---|
| 141 | {
 | 
|---|
| 142 |   return Z;
 | 
|---|
| 143 | }
 | 
|---|
| 144 | 
 | 
|---|
| 145 | double element::getValence() const
 | 
|---|
| 146 | {
 | 
|---|
| 147 |   return Valence;
 | 
|---|
| 148 | }
 | 
|---|
| 149 | 
 | 
|---|
| 150 | int element::getNoValenceOrbitals() const
 | 
|---|
| 151 | {
 | 
|---|
| 152 |   return NoValenceOrbitals;
 | 
|---|
| 153 | }
 | 
|---|
| 154 | 
 | 
|---|
| 155 | double element::getHBondDistance(const int i) const
 | 
|---|
| 156 | {
 | 
|---|
| 157 |   ASSERT((i>=0) && (i<3), "Access to element::HBondDistance out of bounds.");
 | 
|---|
| 158 |   return HBondDistance[i];
 | 
|---|
| 159 | }
 | 
|---|
| 160 | 
 | 
|---|
| 161 | double element::getHBondAngle(const int i) const
 | 
|---|
| 162 | {
 | 
|---|
| 163 |   ASSERT((i>=0) && (i<3), "Access to element::HBondAngle out of bounds.");
 | 
|---|
| 164 |   return HBondAngle[i];
 | 
|---|
| 165 | }
 | 
|---|
| 166 | 
 | 
|---|
| 167 | string &element::getSymbol(){
 | 
|---|
| 168 |   return symbol;
 | 
|---|
| 169 | }
 | 
|---|
| 170 | 
 | 
|---|
| 171 | const string &element::getSymbol() const{
 | 
|---|
| 172 |   return symbol;
 | 
|---|
| 173 | }
 | 
|---|
| 174 | 
 | 
|---|
| 175 | void element::setSymbol(const std::string &temp)
 | 
|---|
| 176 | {
 | 
|---|
| 177 |   symbol = temp;
 | 
|---|
| 178 | }
 | 
|---|
| 179 | 
 | 
|---|
| 180 | std::string &element::getName(){
 | 
|---|
| 181 |   return name;
 | 
|---|
| 182 | }
 | 
|---|
| 183 | 
 | 
|---|
| 184 | const std::string &element::getName() const{
 | 
|---|
| 185 |   return name;
 | 
|---|
| 186 | }
 | 
|---|
| 187 | 
 | 
|---|
| 188 | void element::setName(const std::string &temp)
 | 
|---|
| 189 | {
 | 
|---|
| 190 |   name = temp;
 | 
|---|
| 191 | }
 | 
|---|
| 192 | 
 | 
|---|
| 193 | std::ostream &operator<<(std::ostream &ost,const element &elem){
 | 
|---|
| 194 |   ost << elem.getName() << "(" << elem.getNumber() << ")";
 | 
|---|
| 195 |   return ost;
 | 
|---|
| 196 | }
 | 
|---|