~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/tools/AtomicProperties.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $RCSfile: $
 
2
 * $Author: egonw $
 
3
 * $Date: 2006-05-04 19:29:58 +0000 (Thu, 04 May 2006) $
 
4
 * $Revision: 6171 $
 
5
 *
 
6
 * Copyright (C) 2006-2007  Todd Martin (Environmental Protection Agency)
 
7
 *
 
8
 * Contact: cdk-devel@lists.sourceforge.net
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 *
 
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.
 
23
 */
 
24
package org.openscience.cdk.tools;
 
25
 
 
26
import java.io.BufferedReader;
 
27
import java.io.IOException;
 
28
import java.io.InputStream;
 
29
import java.io.InputStreamReader;
 
30
import java.util.Hashtable;
 
31
import java.util.LinkedList;
 
32
 
 
33
public class AtomicProperties {
 
34
 
 
35
        private LoggingTool logger;
 
36
        
 
37
        private static AtomicProperties ap=null;
 
38
        
 
39
        private Hashtable htMass=new Hashtable();
 
40
        private Hashtable htVdWVolume=new Hashtable();
 
41
        private Hashtable htElectronegativity=new Hashtable();
 
42
        private Hashtable htPolarizability=new Hashtable();
 
43
        
 
44
        
 
45
        private AtomicProperties() throws IOException {
 
46
                
 
47
                logger = new LoggingTool(this);
 
48
                
 
49
            String configFile = "src/org/openscience/cdk/config/data/whim_weights.txt";
 
50
            InputStream ins = this.getClass().getClassLoader().getResourceAsStream(configFile);
 
51
                
 
52
                BufferedReader br = new BufferedReader(new InputStreamReader(ins));
 
53
                
 
54
                String Header= br.readLine(); // header
 
55
                
 
56
                String Line="";
 
57
                while (true) {
 
58
                        Line=br.readLine();
 
59
                        if (!(Line instanceof String)) {
 
60
                                break;
 
61
                        }
 
62
                        
 
63
                        LinkedList l = parseStringIntoList(Line,"\t");
 
64
                        
 
65
                        String symbol=(String)l.get(0);
 
66
                        htMass.put(symbol,l.get(1));
 
67
                        htVdWVolume.put(symbol,l.get(2));
 
68
                        htElectronegativity.put(symbol,l.get(3));
 
69
                        htPolarizability.put(symbol,l.get(4));
 
70
                        
 
71
                }
 
72
                                                
 
73
                br.close();
 
74
        }
 
75
 
 
76
        public static LinkedList parseStringIntoList(String Line, String Delimiter) {
 
77
                // parses a delimited string into a list
 
78
                
 
79
                LinkedList myList = new LinkedList();
 
80
                
 
81
                int tabpos = 1;
 
82
                
 
83
                while (tabpos > -1) {
 
84
                        tabpos = Line.indexOf(Delimiter);
 
85
                        
 
86
                        if (tabpos > 0) {
 
87
                                myList.add(Line.substring(0, tabpos));
 
88
                                Line = Line.substring(tabpos + 1, Line.length());
 
89
                        } else if (tabpos == 0) {
 
90
                                myList.add("");
 
91
                                Line = Line.substring(tabpos + 1, Line.length());
 
92
                        } else {
 
93
                                myList.add(Line.trim());
 
94
                        }
 
95
                }
 
96
                
 
97
                return myList;
 
98
                
 
99
        }
 
100
 
 
101
        public double getVdWVolume(String symbol) {
 
102
                double VdWVolume=-99;
 
103
                
 
104
                String strVdWVolume=(String)htVdWVolume.get(symbol);
 
105
                
 
106
                try {
 
107
                        VdWVolume=Double.parseDouble(strVdWVolume);
 
108
                } catch (Exception e) {
 
109
                        logger.error("Error while parsing the Vanderwaals volume: " + e.getMessage());
 
110
                        logger.debug(e);
 
111
                }
 
112
                
 
113
                
 
114
                return VdWVolume;
 
115
                
 
116
        }
 
117
        
 
118
        public double getNormalizedVdWVolume(String symbol) {
 
119
                double VdWVolume=-99;
 
120
                
 
121
                VdWVolume=this.getVdWVolume(symbol)/this.getVdWVolume("C");
 
122
                                
 
123
                return VdWVolume;
 
124
                
 
125
        }
 
126
        
 
127
        public double getElectronegativity(String symbol) {
 
128
                double Electronegativity=-99;
 
129
                
 
130
                String strElectronegativity=(String)htElectronegativity.get(symbol);
 
131
                
 
132
                try {
 
133
                Electronegativity=Double.parseDouble(strElectronegativity);
 
134
                } catch (Exception e) {
 
135
                        logger.error("Error while parsing the electronegativity: " + e.getMessage());
 
136
                        logger.debug(e);
 
137
                }
 
138
                
 
139
                
 
140
                return Electronegativity;
 
141
                
 
142
        }
 
143
        
 
144
        public double getNormalizedElectronegativity(String symbol) {
 
145
                double Electronegativity=-99;
 
146
                
 
147
                Electronegativity=this.getElectronegativity(symbol)/this.getElectronegativity("C");
 
148
                                
 
149
                return Electronegativity;
 
150
                
 
151
        }
 
152
        public double getPolarizability(String symbol) {
 
153
                double Polarizability=-99;
 
154
                
 
155
                String strPolarizability=(String)htPolarizability.get(symbol);
 
156
                
 
157
                try {
 
158
                Polarizability=Double.parseDouble(strPolarizability);
 
159
                } catch (Exception e) {
 
160
                        logger.error("Error while parsing the polarizability: " + e.getMessage());
 
161
                        logger.debug(e);
 
162
                }
 
163
                
 
164
                
 
165
                return Polarizability;
 
166
                
 
167
        }
 
168
        
 
169
        public double getNormalizedPolarizability(String symbol) {
 
170
                double Polarizability=-99;
 
171
                
 
172
                Polarizability=this.getPolarizability(symbol)/this.getPolarizability("C");
 
173
                                
 
174
                return Polarizability;
 
175
                
 
176
        }
 
177
        public double getMass(String symbol) {
 
178
                double mass=-99;
 
179
                
 
180
                String strMass=(String)htMass.get(symbol);
 
181
                
 
182
                try {
 
183
                mass=Double.parseDouble(strMass);
 
184
                
 
185
                } catch (Exception e) {
 
186
                        logger.error("Error while parsing the mass: " + e.getMessage());
 
187
                        logger.debug(e);
 
188
                }
 
189
                
 
190
                
 
191
                return mass;
 
192
                
 
193
        }
 
194
        
 
195
        public double getNormalizedMass(String symbol) {
 
196
                double mass=-99;
 
197
                
 
198
                mass=this.getMass(symbol)/this.getMass("C");
 
199
                                
 
200
                return mass;
 
201
                
 
202
        }
 
203
        
 
204
        
 
205
        
 
206
        public static AtomicProperties getInstance() throws IOException
 
207
        {
 
208
                if (ap == null) {
 
209
                        ap = new AtomicProperties();
 
210
                }
 
211
                return ap;
 
212
        }
 
213
}