#include "atom.h"
#include "tokenizer.h"

std::map<std::string,CAtom::atomdata> m_ptable;

CAtom::CAtom()
{
  m_selected=m_irradiated=false;
}

CAtom::~CAtom()
{}

//masses taken from    http://www.webelements.com/
double CAtom::GetAtomicMass()
{
  std::map<std::string,CAtom::atomdata>::iterator it=m_ptable.find(StringTokenizer::toupper(name));
  return (*it).second.mass;
}

void CAtom::GetColor(float* r, float* g, float* b)
{
  std::map<std::string,CAtom::atomdata>::iterator it=m_ptable.find(StringTokenizer::toupper(name));
  if (it == m_ptable.end())
    return;
  *r=(*it).second.color.r/255.;
  *g=(*it).second.color.g/255.;
  *b=(*it).second.color.b/255.;
}

void CAtom::SetZ(int z)
{
  std::map<std::string,CAtom::atomdata>::iterator it=m_ptable.begin();

  for(it=m_ptable.begin();it!=m_ptable.end();++it)
  {
    if ( it->second.Z ==  z)
    {
      name=it->first;
      return;
    }
  }
}

double CAtom::GetVdW()
{

  std::map<std::string,CAtom::atomdata>::iterator it=m_ptable.find(StringTokenizer::toupper(name));
  if (it == m_ptable.end())
    return 2.0;
  else
    return (*it).second.vdw;

}


void BuildPeriodicTable()
{
  typedef CAtom::atomdata data;
  m_ptable.insert(std::pair<std::string,data>("H",data(1,1.00794,1.20,data::rgb(180,180,180))));
  m_ptable.insert(std::pair<std::string,data>("HE",data(2,4.002602,0,data::rgb(233,194,243))));
  m_ptable.insert(std::pair<std::string,data>("LI",data(3,6.941,0,data::rgb(50,73,255))));
  m_ptable.insert(std::pair<std::string,data>("BE",data(4,9.012182,0,data::rgb(169,170,255))));
  m_ptable.insert(std::pair<std::string,data>("B",data(5,10.811,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("C",data(6,12.0107,1.70,data::rgb(100,255,100))));
  m_ptable.insert(std::pair<std::string,data>("N",data(7,14.0067,0,data::rgb(100,100,255))));
  m_ptable.insert(std::pair<std::string,data>("O",data(8,15.9994 ,1.52,data::rgb(255,100,100))));
  m_ptable.insert(std::pair<std::string,data>("F",data(9,18.9984032 ,0,data::rgb(181,243,184))));
  m_ptable.insert(std::pair<std::string,data>("NE",data(10,20.1797 ,0,data::rgb(233,194,243))));
  m_ptable.insert(std::pair<std::string,data>("NA",data(11,22.989770 ,0,data::rgb(50,73,255))));
  m_ptable.insert(std::pair<std::string,data>("MG",data(12,24.3050 ,0,data::rgb(169,170,255))));
  m_ptable.insert(std::pair<std::string,data>("AL",data(13,26.981538 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("SI",data(14,28.0855 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("P",data(15,30.973761 ,0,data::rgb(197,117,243))));
  m_ptable.insert(std::pair<std::string,data>("S",data(16,32.065 ,0,data::rgb(228,243,91))));
  m_ptable.insert(std::pair<std::string,data>("CL",data(17,35.453 ,0,data::rgb(181,243,184))));
  m_ptable.insert(std::pair<std::string,data>("AR",data(18,39.948 ,0,data::rgb(128,128,128))));
  m_ptable.insert(std::pair<std::string,data>("K",data(19,39.0983 ,0,data::rgb(50,73,255))));
  m_ptable.insert(std::pair<std::string,data>("CA",data(20,40.078 ,0,data::rgb(169,170,255))));
  m_ptable.insert(std::pair<std::string,data>("SC",data(21,44.955910 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TI",data(22,47.867 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("V",data(23,50.9415 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("CR",data(24,51.9961 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("MN",data(25,54.938049 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("FE",data(26,55.845 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("CO",data(27,58.933200 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("NI",data(28,58.6934 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("CU",data(29,63.546 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("ZN",data(30,65.409 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("GA",data(31,69.723 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("GE",data(32,72.64 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("AS",data(33,74.92160 ,0,data::rgb(197,117,243))));
  m_ptable.insert(std::pair<std::string,data>("SE",data(34,78.96 ,0,data::rgb(228,243,91))));
  m_ptable.insert(std::pair<std::string,data>("BR",data(35,79.904 ,0,data::rgb(181,243,184))));
  m_ptable.insert(std::pair<std::string,data>("KR",data(36,83.798 ,0,data::rgb(233,194,243))));
  m_ptable.insert(std::pair<std::string,data>("RB",data(37,85.4678 ,0,data::rgb(50,73,255))));
  m_ptable.insert(std::pair<std::string,data>("SR",data(38,87.62 ,0,data::rgb(169,170,255))));
  m_ptable.insert(std::pair<std::string,data>("Y",data(39,88.90585 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("ZR",data(40,91.224 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("NB",data(41,92.90638 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("MO",data(42,95.94 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TE",data(43,98. ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("RU",data(44,101.07 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("RH",data(45,102.90550 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("PD",data(46,106.42 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("AG",data(47,107.8682 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("CD",data(48,112.411 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("IN",data(49,114.818 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("SN",data(50,118.710 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("SB",data(51,121.760 ,0,data::rgb(197,117,243))));
  m_ptable.insert(std::pair<std::string,data>("TE",data(52,127.60 ,0,data::rgb(228,243,91))));
  m_ptable.insert(std::pair<std::string,data>("I",data(53,126.90447 ,0,data::rgb(181,243,184))));
  m_ptable.insert(std::pair<std::string,data>("XE",data(54,131.293 ,0,data::rgb(233,194,243))));
  m_ptable.insert(std::pair<std::string,data>("CS",data(55,132.90545 ,0,data::rgb(50,73,255))));
  m_ptable.insert(std::pair<std::string,data>("BA",data(56,137.327 ,0,data::rgb(169,170,255))));
  m_ptable.insert(std::pair<std::string,data>("LA",data(57,138.9055 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("CE",data(58,140.116 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("PR",data(59,140.90765 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("ND",data(60,144.24 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("PM",data(61,145. ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("SM",data(62,150.36 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("EU",data(63,151.964 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("GD",data(64,157.25 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TB",data(65,158.92534 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("DY",data(66,162.500 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("HO",data(67,164.93032 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("ER",data(68,167.259 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TM",data(69,168.932421 ,0,data::rgb(100,100,100))));
  m_ptable.insert(std::pair<std::string,data>("YB",data(70,173.04 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("LU",data(71,174.967 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("HF",data(72,178.49 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TA",data(73,180.9479 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("W",data(74,183.84 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("RE",data(75,186.207 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("OS",data(76,190.23 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("IR",data(77,192.217 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("PT",data(78,195.078 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("AU",data(79,196.96655 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("HG",data(80,200.59 ,0,data::rgb(214,41,201))));
  m_ptable.insert(std::pair<std::string,data>("TL",data(81,204.3833 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("PB",data(82,207.2 ,0,data::rgb(193,211,201))));
  m_ptable.insert(std::pair<std::string,data>("BI",data(83,208.98038 ,0,data::rgb(197,117,243))));
  m_ptable.insert(std::pair<std::string,data>("PO",data(84,209. ,0,data::rgb(228,243,91))));
  m_ptable.insert(std::pair<std::string,data>("AT",data(85,210. ,0,data::rgb(181,243,184))));
  m_ptable.insert(std::pair<std::string,data>("RN",data(86,222. ,0,data::rgb(233,194,243))));


}

const PeriodicTable& GetPeriodicTable()
{
  return m_ptable;
}
