/***************************************************************************
 *   Copyright (C) 2004 by Armando Navarro Vázquez                         *
 *   armando@rmntec                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <iostream>
#include "tinkerparser.h"
#include "molecule.h"
#include "tokenizer.h"

TinkerParser::TinkerParser(const char* file) : QuantumParser(file)
{}


TinkerParser::TinkerParser(std::istream* stream) : QuantumParser(stream)
{}

TinkerParser::~ TinkerParser()
{}

bool TinkerParser::ParseFile(std::streampos pos)
{
  std::cout << "Tinker Parser" << std::endl;
  m_file->clear();
  m_file->seekg(0,std::ios::beg);
  std::string line;
  std::getline(*m_file,line);
  StringTokenizer token(line," \t");
  int natoms=atoi(token.at(0).c_str());
  std::cout << "natoms " << natoms << std::endl;
  CMolecule molecule;
  molecule.m_atom.resize(natoms);
  std::vector<CAtom>::iterator it=molecule.m_atom.begin();

  for(int i=0;i<natoms;i++)
  {
    std::getline(*m_file,line);
    StringTokenizer token(line," \t");
    it->name=token.at(1);
//    it->label=token.at(0);
    it->c.x=atof(token.at(2).c_str());
    it->c.y=atof(token.at(3).c_str());
    it->c.z=atof(token.at(4).c_str());
    it++;
    //for(int j=

  }
  molecule.SetConexions();
  molecule.CalculateMassCenter();
  m_molecule->push_back(molecule);
  return true;

}

