3
* $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
6
* Copyright (C) 1997-2007 Bradley A. Smith <bradley@baysmith.com>
8
* Contact: cdk-developers@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
package org.openscience.cdk.config;
26
import java.awt.Color;
27
import java.io.BufferedReader;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.io.InputStreamReader;
31
import java.util.ArrayList;
32
import java.util.List;
33
import java.util.StringTokenizer;
35
import org.openscience.cdk.interfaces.IAtomType;
36
import org.openscience.cdk.interfaces.IChemObjectBuilder;
39
* AtomType list configurator that uses the AtomTypes originally
40
* defined in Jmol v5. This class was added to be able to port
41
* Jmol to CDK. The AtomType's themselves seems have a computational
42
* background, but this is not clear.
46
* @author Bradley A. Smith <bradley@baysmith.com>
48
* @cdk.keyword atom, type
50
public class TXTBasedAtomTypeConfigurator implements IAtomTypeConfigurator {
52
private String configFile = "org/openscience/cdk/config/data/jmol_atomtypes.txt";
53
private InputStream ins = null;
55
public TXTBasedAtomTypeConfigurator() {
59
* Sets the file containing the config data.
61
public void setInputStream(InputStream ins) {
66
* Reads a text based configuration file.
68
* @param builder IChemObjectBuilder used to construct the IAtomType's.
69
* @throws IOException when a problem occured with reading from the InputStream
70
* @return A List with read IAtomType's.
72
public List readAtomTypes(IChemObjectBuilder builder) throws IOException {
73
List atomTypes = new ArrayList();
77
//logger.debug("readAtomTypes getResourceAsStream:"
79
ins = this.getClass().getClassLoader().getResourceAsStream(configFile);
82
throw new IOException("There was a problem getting the default stream: " + configFile);
84
// read the contents from file
85
BufferedReader reader = new BufferedReader(new InputStreamReader(ins), 1024);
86
StringTokenizer tokenizer;
90
string = reader.readLine();
94
if (!string.startsWith("#")) {
97
int atomicNumber = 0, colorR = 0, colorG = 0, colorB = 0;
98
double mass = 0.0, vdwaals = 0.0, covalent = 0.0;
99
tokenizer = new StringTokenizer(string, "\t ,;");
100
int tokenCount = tokenizer.countTokens();
102
if (tokenCount == 9) {
103
name = tokenizer.nextToken();
104
rootType = tokenizer.nextToken();
105
String san = tokenizer.nextToken();
106
String sam = tokenizer.nextToken();
107
String svdwaals = tokenizer.nextToken();
108
String scovalent = tokenizer.nextToken();
109
String sColorR = tokenizer.nextToken();
110
String sColorG = tokenizer.nextToken();
111
String sColorB = tokenizer.nextToken();
114
mass = new Double(sam).doubleValue();
115
vdwaals = new Double(svdwaals).doubleValue();
116
covalent = new Double(scovalent).doubleValue();
117
atomicNumber = Integer.parseInt(san);
118
colorR = Integer.parseInt(sColorR);
119
colorG = Integer.parseInt(sColorG);
120
colorB = Integer.parseInt(sColorB);
121
} catch (NumberFormatException nfe) {
122
throw new IOException("AtomTypeTable.ReadAtypes: " +
126
IAtomType atomType = builder.newAtomType(name, rootType);
127
atomType.setAtomicNumber(atomicNumber);
128
atomType.setExactMass(mass);
129
atomType.setVanderwaalsRadius(vdwaals);
130
atomType.setCovalentRadius(covalent);
131
Color color = new Color(colorR, colorG, colorB);
132
atomType.setProperty("org.openscience.cdk.renderer.color", color);
133
atomTypes.add(atomType);
135
throw new IOException("AtomTypeTable.ReadAtypes: " +
136
"Wrong Number of fields");