1 // FILETRANS.H : Handle import/export through use of the Babel external lib.
2 
3 // Copyright (C) 2000 Geoffrey Hutchison.
4 
5 // This package 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; either version 2 of the License, or
8 // (at your option) any later version.
9 
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 /*################################################################################################*/
20 
21 #ifndef FILETRANS_H
22 #define FILETRANS_H
23 
24 #include "ghemicalconfig2.h"	// ENABLE_OPENBABEL
25 
26 #ifdef ENABLE_OPENBABEL
27 
28 /*################################################################################################*/
29 
30 #include "project.h"
31 
32 // OpenBabel includes...
33 // OpenBabel includes...
34 // OpenBabel includes...
35 
36 #include <openbabel/mol.h>
37 #include <openbabel/obconversion.h>
38 using namespace OpenBabel;
39 
40 #include <string>
41 #include <vector>
42 #include <iostream>
43 #include <fstream>
44 using namespace std;
45 
46 /*################################################################################################*/
47 
48 typedef struct
49 {
50 	atom * atmr;
51 	OBAtom * oba;
52 } atom_name_tag;
53 
54 typedef struct
55 {
56 	string description;
57 	OBFormat * format;
58 } format_record;
59 
60 class file_trans
61 {
62 	private:
63 
64 	vector<format_record> imports;
65 	vector<format_record> exports;
66 
67 	int name_tag_count;
68 	atom_name_tag * tagtab;
69 	project * prj; OBMol * obm;
70 	iter_al itb; iter_al ite;
71 
72 	public:
73 
74 	file_trans();
75 	virtual ~file_trans();
76 
77 	// these expect to be passed the filename to pick the file format
78 	int Import(const char *, istream &, ostream &);
79 	int Export(const char *, istream &, ostream &);
80 
81 	// these check whether the format picked by the filename are valid
82 	bool CanImport(const char *);
83 	bool CanExport(const char *);
84 
85 	// Get a listing of the number of valid import/export types
NumImports()86 	unsigned int NumImports() { return imports.size(); }
NumExports()87 	unsigned int NumExports() { return exports.size(); }
88 
89 	// Get the description associated with this type
90 	string GetExportDescription(unsigned int);
91 	string GetImportDescription(unsigned int);
92 
93 	// These take the unsigned int as a format specifier
94 	int Import(const char *, unsigned int, istream &, ostream &);
95 	int Export(const char *, unsigned int, istream &, ostream &);
96 
97 	// some Babel compatibility methods:
98 	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99 
100 	/// This takes a pair of atom list iterators, and copies all atoms/bonds in this range to OBMol.
101 	OBMol * Copy(project *, iter_al, iter_al);
102 
103 	/// This will copy a molecule (defined by the index) to OBMol.
104 	OBMol * CopyMolecule(project *, int);
105 
106 	/// This will copy everything in this project to OBMol.
107 	OBMol * CopyAll(project *);
108 
109 	/// This will syncronize the project and the OBMol.
110 	void Synchronize(void);
111 };
112 
113 /*################################################################################################*/
114 
115 #endif	// ENABLE_OPENBABEL
116 #endif	// FILETRANS_H
117 
118 // eof
119