~ubuntu-branches/ubuntu/feisty/openbabel/feisty

« back to all changes in this revision

Viewing changes to src/nwchem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-05-14 19:46:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060514194601-h3j1wovvc42cigxl
Tags: 2.0.1-1
* New upstream release. (Closes: #341628)
* debian/patches/04_zipstream_fix.diff: Removed, applied upstream.
* debian/rules (DEB_MAKE_CHECK_TARGET): Readded.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
Copyright (C) 2001-2003 by Geoffrey R. Hutchison
3
 
 
4
 
This program is free software; you can redistribute it and/or modify
5
 
it under the terms of the GNU General Public License as published by
6
 
the Free Software Foundation version 2 of the License.
7
 
 
8
 
This program is distributed in the hope that it will be useful,
9
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
GNU General Public License for more details.
12
 
***********************************************************************/
13
 
 
14
 
#include "mol.h"
15
 
 
16
 
using namespace std;
17
 
 
18
 
namespace OpenBabel {
19
 
 
20
 
bool ReadNWChem(istream &ifs,OBMol &mol,const char *title)
21
 
{
22
 
  char buffer[BUFF_SIZE];
23
 
  string str;
24
 
  double x,y,z;
25
 
  OBAtom *atom;
26
 
  vector<string> vs;
27
 
 
28
 
  mol.BeginModify();
29
 
  while (ifs.getline(buffer,BUFF_SIZE))
30
 
    {
31
 
      if(strstr(buffer,"Output coordinates") != NULL)
32
 
        {
33
 
          // mol.EndModify();
34
 
          mol.Clear();
35
 
          mol.BeginModify();
36
 
          ifs.getline(buffer,BUFF_SIZE);        // blank
37
 
          ifs.getline(buffer,BUFF_SIZE);        // column headings
38
 
          ifs.getline(buffer,BUFF_SIZE);        // ---- ----- ----
39
 
          ifs.getline(buffer,BUFF_SIZE);
40
 
          tokenize(vs,buffer);
41
 
          while (vs.size() == 6)
42
 
            {
43
 
              atom = mol.NewAtom();
44
 
              x = atof((char*)vs[3].c_str());
45
 
              y = atof((char*)vs[4].c_str());
46
 
              z = atof((char*)vs[5].c_str());
47
 
              atom->SetVector(x,y,z); //set coordinates
48
 
 
49
 
              //set atomic number
50
 
              atom->SetAtomicNum(etab.GetAtomicNum(vs[1].c_str()));
51
 
 
52
 
              if (!ifs.getline(buffer,BUFF_SIZE)) break;
53
 
              tokenize(vs,buffer);
54
 
            }
55
 
        } // if "output coordinates"
56
 
    } // while 
57
 
  mol.EndModify();
58
 
  mol.ConnectTheDots();
59
 
  mol.PerceiveBondOrders();
60
 
 
61
 
  mol.SetTitle(title);
62
 
  return(true);
63
 
}
64
 
 
65
 
bool WriteNWChem(ostream &ofs,OBMol &mol)
66
 
{
67
 
  unsigned int i;
68
 
  char buffer[BUFF_SIZE];
69
 
  
70
 
  ofs << "start molecule" << endl << endl;
71
 
  ofs << "title " << endl << " " << mol.GetTitle() << endl << endl;
72
 
 
73
 
  ofs << "geometry units angstroms print xyz autosym" << endl;
74
 
 
75
 
  OBAtom *atom;
76
 
  for(i = 1;i <= mol.NumAtoms(); i++)
77
 
  {
78
 
    atom = mol.GetAtom(i);
79
 
    sprintf(buffer,"%3s%15.5f%15.5f%15.5f",
80
 
            etab.GetSymbol(atom->GetAtomicNum()),
81
 
            atom->GetX(),
82
 
            atom->GetY(),
83
 
            atom->GetZ());
84
 
    ofs << buffer << endl;
85
 
  }
86
 
 
87
 
  ofs << "end" << endl;
88
 
 
89
 
  return(true);
90
 
}
91
 
 
92
 
}