~vcs-imports/openbabel/trunk

« back to all changes in this revision

Viewing changes to nwchem.cpp

  • Committer: ghutchis
  • Date: 2001-11-27 18:50:36 UTC
  • Revision ID: svn-v4:86f38270-e075-4da6-bf68-7dcd545c500b:openbabel/trunk:46
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
Copyright (C) 2001 by Geoffrey 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
namespace OpenEye {
 
17
 
 
18
bool ReadNWChem(istream &ifs,OEMol &mol,char *title)
 
19
{
 
20
  char buffer[BUFF_SIZE];
 
21
  string str;
 
22
  float x,y,z;
 
23
  OEAtom *atom;
 
24
  vector<string> vs;
 
25
 
 
26
  ttab.SetFromType("XYZ");
 
27
  mol.BeginModify();
 
28
  while (ifs.getline(buffer,BUFF_SIZE))
 
29
    {
 
30
      if(strstr(buffer,"Output coordinates") != NULL)
 
31
        {
 
32
          // mol.EndModify();
 
33
          mol.Clear();
 
34
          mol.BeginModify();
 
35
          ifs.getline(buffer,BUFF_SIZE);        // blank
 
36
          ifs.getline(buffer,BUFF_SIZE);        // column headings
 
37
          ifs.getline(buffer,BUFF_SIZE);        // ---- ----- ----
 
38
          ifs.getline(buffer,BUFF_SIZE);
 
39
          tokenize(vs,buffer);
 
40
          while (vs.size() == 6)
 
41
            {
 
42
              atom = mol.NewAtom();
 
43
              x = atof((char*)vs[3].c_str());
 
44
              y = atof((char*)vs[4].c_str());
 
45
              z = atof((char*)vs[5].c_str());
 
46
              atom->SetVector(x,y,z); //set coordinates
 
47
 
 
48
              //set atomic number
 
49
              atom->SetAtomicNum(etab.GetAtomicNum(vs[1].c_str()));
 
50
              //set type
 
51
              ttab.SetToType("INT"); ttab.Translate(str,vs[1]); 
 
52
              atom->SetType(str);
 
53
 
 
54
              if (!ifs.getline(buffer,BUFF_SIZE)) break;
 
55
              tokenize(vs,buffer);
 
56
            }
 
57
        } // if "output coordinates"
 
58
    } // while 
 
59
  mol.EndModify();
 
60
  mol.ConnectTheDots();
 
61
 
 
62
  mol.SetTitle(title);
 
63
  return(true);
 
64
}
 
65
 
 
66
bool WriteNWChem(ostream &ofs,OEMol &mol)
 
67
{
 
68
  unsigned int i;
 
69
  char buffer[BUFF_SIZE];
 
70
  
 
71
  ofs << "start molecule" << endl << endl;
 
72
  ofs << "title " << endl << " " << mol.GetTitle() << endl << endl;
 
73
 
 
74
  ofs << "geometry units angstroms print xyz autosym" << endl;
 
75
 
 
76
  OEAtom *atom;
 
77
  for(i = 1;i <= mol.NumAtoms(); i++)
 
78
  {
 
79
    atom = mol.GetAtom(i);
 
80
    sprintf(buffer,"%3s%15.5f%15.5f%15.5f",
 
81
            etab.GetSymbol(atom->GetAtomicNum()),
 
82
            atom->GetX(),
 
83
            atom->GetY(),
 
84
            atom->GetZ());
 
85
    ofs << buffer << endl;
 
86
  }
 
87
 
 
88
  ofs << "end" << endl;
 
89
 
 
90
  return(true);
 
91
}
 
92
 
 
93
}