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

« back to all changes in this revision

Viewing changes to src/feat.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) 1998-2001 by OpenEye Scientific Software, Inc.
3
 
Some portions Copyright (c) 2001-2003 by Geoffrey R. Hutchison
4
 
 
5
 
This program is free software; you can redistribute it and/or modify
6
 
it under the terms of the GNU General Public License as published by
7
 
the Free Software Foundation version 2 of the License.
8
 
 
9
 
This program is distributed in the hope that it will be useful,
10
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
GNU General Public License for more details.
13
 
***********************************************************************/
14
 
 
15
 
#include "mol.h"
16
 
 
17
 
using namespace std;
18
 
 
19
 
namespace OpenBabel
20
 
{
21
 
 
22
 
bool ReadFeat(istream &ifs,OBMol &mol, const char *title)
23
 
{
24
 
  char buffer[BUFF_SIZE];
25
 
  int i,natoms;
26
 
 
27
 
  ifs.getline(buffer,BUFF_SIZE);
28
 
  sscanf(buffer,"%d",&natoms);
29
 
 
30
 
  mol.ReserveAtoms(natoms);
31
 
  mol.BeginModify();
32
 
 
33
 
  if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
34
 
  mol.SetTitle(buffer);
35
 
 
36
 
  double x,y,z;
37
 
  char type[20];
38
 
  OBAtom *atom;
39
 
  for (i = 0; i < natoms;i++)
40
 
  {
41
 
    if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
42
 
    sscanf(buffer,"%s %lf %lf %lf",
43
 
           type,
44
 
           &x,
45
 
           &y,
46
 
           &z);
47
 
    CleanAtomType(type);
48
 
    atom = mol.NewAtom();
49
 
    atom->SetVector(x,y,z);
50
 
    atom->SetAtomicNum(etab.GetAtomicNum(type));
51
 
  }
52
 
 
53
 
  mol.EndModify();
54
 
  return(true);
55
 
}
56
 
 
57
 
bool WriteFeat(ostream &ofs,OBMol &mol)
58
 
59
 
  char buffer[BUFF_SIZE];
60
 
  
61
 
  ofs << mol.NumAtoms() << endl;
62
 
  ofs << mol.GetTitle() << endl;
63
 
 
64
 
  OBAtom *atom;
65
 
  vector<OBNodeBase*>::iterator i;
66
 
  for(atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
67
 
  {
68
 
    sprintf(buffer,"%-3s %8.5f  %8.5f  %8.5f ",
69
 
            etab.GetSymbol(atom->GetAtomicNum()),
70
 
            atom->x(),
71
 
            atom->y(),
72
 
            atom->z());
73
 
    ofs << buffer << endl;
74
 
  }
75
 
 
76
 
  return(true);
77
 
}
78
 
 
79
 
}