File: cache.cpp

package info (click to toggle)
ghemical 0.82-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 9,448 kB
  • ctags: 18,571
  • sloc: ansic: 68,828; cpp: 51,774; fortran: 35,324; sh: 2,505; makefile: 475; perl: 70
file content (110 lines) | stat: -rw-r--r-- 3,809 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**********************************************************************
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.

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 version 2 of the License.

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.
***********************************************************************/

#include "mol.h"

namespace OpenBabel
{

bool WriteCache(ostream &ofs,OBMol &mol)
{ 
  char type_name[10];
  char buffer[BUFF_SIZE];
  
  mol.Kekulize();

  ofs << "molstruct88_Apr_30_1993_11:02:29 <molecule> 0x1d00" << endl;
  ofs << "Written by Molecular Editor on <date>" << endl;
  ofs << "Using data dictionary         9/9/93  4:47 AM" << endl;
  ofs << "Version 6" << endl;
  ofs << "local_transform" << endl;
  ofs << "0.100000 0.000000 0.000000 0.000000" << endl;
  ofs << "0.000000 0.100000 0.000000 0.000000" << endl;
  ofs << "0.000000 0.000000 0.100000 0.000000" << endl;
  ofs << "0.000000 0.000000 0.000000 1.000000" << endl;
  ofs << "object_class atom" << endl;
  ofs << "property xyz_coordinates MoleculeEditor angstrom 6 3 FLOAT" << endl;
  ofs << "property anum MoleculeEditor unit 0 1 INTEGER" << endl;
  ofs << "property sym MoleculeEditor noUnit 0 2 STRING" << endl;
  ofs << "property chrg MoleculeEditor charge_au 0 1 INTEGER" << endl;
  ofs << "property rflag MoleculeEditor noUnit 0 1 HEX" << endl;
  ofs << "ID xyz_coordinates             anum sym	chrg rflag" << endl;

  OBAtom *atom;
  vector<OBNodeBase*>::iterator i;
  for(atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
  {
    strcpy(type_name,etab.GetSymbol(atom->GetAtomicNum()));
    
    sprintf(buffer,"%3d %10.6f %10.6f %10.6f %2d %2s %2d 0x7052",
            atom->GetIdx(),
	    atom->x(),
	    atom->y(),
	    atom->z(),
	    atom->GetAtomicNum(),
	    type_name,
	    atom->GetFormalCharge());
    ofs << buffer << endl;
  }

  ofs << "property_flags:" << endl;
  ofs << "object_class bond" << endl;
  ofs << "property rflag MoleculeEditor noUnit 0 1 HEX" << endl;
  ofs << "property type MoleculeEditor noUnit 0 1 NAME" << endl;
  ofs << "property bond_order MoleculeEditor noUnit 4 1 FLOAT" << endl;
  ofs << "ID rflag type bond_order" << endl;

  char bstr[10];
  OBBond *bond;
  vector<OBEdgeBase*>::iterator j;
  for (bond = mol.BeginBond(j);bond;bond = mol.NextBond(j))
    {
      switch (bond->GetBO())
	{
	case 1: strcpy(bstr,"single"); break;
	case 2: strcpy(bstr,"double"); break;
	case 3: strcpy(bstr,"triple"); break;
	default: strcpy(bstr,"weak");
	}

      sprintf(buffer,"%3d 0x7005 %s", bond->GetIdx()+1,bstr);
      ofs << buffer << endl;
    }

  ofs << "property_flags:" << endl;
  ofs << "object_class connector" << endl;
  ofs << "property dflag MoleculeEditor noUnit 0 1 HEX" << endl;
  ofs << "property objCls1 MoleculeEditor noUnit 0 1 NAME" << endl;
  ofs << "property objCls2 MoleculeEditor noUnit 0 1 NAME" << endl;
  ofs << "property objID1 MoleculeEditor noUnit 0 1 INTEGER" << endl;
  ofs << "property objID2 MoleculeEditor noUnit 0 1 INTEGER" << endl;
  ofs << "ID dflag objCls1 objCls2 objID1 objID2" << endl;


  int k;
  for (bond = mol.BeginBond(j),k=1;bond;bond = mol.NextBond(j))
    {
      sprintf(buffer,"%3d 0xa1 atom bond %d %d",
	      k++,bond->GetBeginAtomIdx(),bond->GetIdx()+1);
      ofs << buffer << endl;
      sprintf(buffer,"%3d 0xa1 atom bond %d %d",
	      k++,bond->GetEndAtomIdx(),bond->GetIdx()+1);
      ofs << buffer << endl;
    }

  sprintf(buffer,"property_flags:"); ofs << buffer << endl;
  return(true);
}


}