Source code: joelib/data/JOEIsotopeTable.java
1 ///////////////////////////////////////////////////////////////////////////////
2 // Filename: $RCSfile: JOEIsotopeTable.java,v $
3 // Purpose: Isotope element table.
4 // Language: Java
5 // Compiler: JDK 1.4
6 // Authors: Joerg K. Wegner
7 // Version: $Revision: 1.6 $
8 // $Date: 2003/08/19 13:11:24 $
9 // $Author: wegner $
10 // Original Author: ???, OpenEye Scientific Software
11 // Original Version: babel 2.0a1
12 //
13 // Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 ///////////////////////////////////////////////////////////////////////////////
24 package joelib.data;
25
26 import joelib.util.JHM;
27
28 import joelib.util.types.DoubleInt;
29
30 import wsi.ra.tool.PropertyHolder;
31
32 /*==========================================================================*
33 * IMPORTS
34 *========================================================================== */
35 import java.util.Properties;
36 import java.util.Vector;
37
38 import org.apache.log4j.Category;
39
40
41 /*==========================================================================*
42 * CLASS DECLARATION
43 *========================================================================== */
44
45 /**
46 * Isotope element table.
47 * The definition file can be defined in the
48 * <tt>joelib.data.JOEIsotopeTable.resourceFile</tt> property in the {@link wsi.ra.tool.PropertyHolder}.
49 * The {@link wsi.ra.tool.ResourceLoader} loads the <tt>joelib.properties</tt> file for default.
50 *
51 * <p>
52 * Default:<br>
53 * joelib.data.JOEIsotopeTable.resourceFile=<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/joelib/joelib/src/joelib/data/plain/isotope.txt?rev=HEAD&content-type=text/vnd.viewcvs-markup">joelib/data/plain/isotope.txt</a>
54 *
55 * @author wegnerj
56 * @license GPL
57 * @cvsversion $Revision: 1.6 $, $Date: 2003/08/19 13:11:24 $
58 */
59 public class JOEIsotopeTable extends JOEGlobalDataBase
60 {
61 //~ Static fields/initializers /////////////////////////////////////////////
62
63 /*-------------------------------------------------------------------------*
64 * public static member variables
65 *------------------------------------------------------------------------- */
66
67 // Obtain a suitable logger.
68 private static Category logger = Category.getInstance(
69 "joelib.data.JOEIsotopeTable");
70 private static JOEIsotopeTable isotopeTable;
71 protected static final String DEFAULT_RESOURCE = "joelib/data/plain/isotope.txt";
72
73 //~ Instance fields ////////////////////////////////////////////////////////
74
75 /*-------------------------------------------------------------------------*
76 * public member variables
77 *------------------------------------------------------------------------- */
78
79 /**
80 * {@link java.util.Vector} of type {@link joelib.util.types.DoubleInt} to store isotope number and mass.
81 */
82 private Vector _isotopes;
83
84 //~ Constructors ///////////////////////////////////////////////////////////
85
86 /*-------------------------------------------------------------------------*
87 * constructor
88 *------------------------------------------------------------------------- */
89
90 /**
91 * Constructor for the JOETypeTable object
92 */
93 private JOEIsotopeTable()
94 {
95 initialized = false;
96
97 Properties prop = PropertyHolder.instance().getProperties();
98 resourceFile = prop.getProperty(this.getClass().getName() +
99 ".resourceFile", DEFAULT_RESOURCE);
100
101 _isotopes = new Vector();
102
103 logger.info("Using isotope table: " + resourceFile);
104 }
105
106 //~ Methods ////////////////////////////////////////////////////////////////
107
108 /**
109 * Description of the Method
110 */
111 public void finalize()
112 {
113 }
114
115 /*-------------------------------------------------------------------------*
116 * public methods
117 *------------------------------------------------------------------------- */
118
119 /**
120 * Description of the Method
121 *
122 * @return Description of the Return Value
123 */
124 public static synchronized JOEIsotopeTable instance()
125 {
126 if (isotopeTable == null)
127 {
128 isotopeTable = new JOEIsotopeTable();
129 }
130
131 return isotopeTable;
132 }
133
134 /**
135 * Return the exact masss of the isotope.
136 * (or by default, the most abundant isotope)
137 */
138 public double getExactMass(int atomicNum)
139 {
140 return getExactMass(atomicNum, 0);
141 }
142
143 /**
144 * Return the exact masss of the isotope.
145 * (or by default, the most abundant isotope)
146 */
147 public double getExactMass(int atomicNum, int isotope)
148 {
149 if (!initialized)
150 {
151 init();
152 }
153
154 if ((atomicNum > _isotopes.size()) || (atomicNum < 0))
155 {
156 return 0.0;
157 }
158
159 int iso;
160 Vector elemVector = (Vector) _isotopes.get(atomicNum);
161 DoubleInt entry;
162
163 for (iso = 0; iso < elemVector.size(); iso++)
164 {
165 entry = (DoubleInt) elemVector.get(iso);
166
167 if (isotope == entry.i)
168 {
169 return entry.d;
170 }
171 }
172
173 return 0.0;
174 }
175
176 /**
177 * Description of the Method
178 *
179 * @param buffer Description of the Parameter
180 */
181 public void parseLine(String buffer)
182 {
183 // of type String
184 Vector vs = new Vector();
185
186 //int atomicNum;
187 int i;
188
189 // of type DoubleInt
190 Vector row = new Vector();
191 DoubleInt di;
192
193 // skip comment line (at the top)
194 if (!buffer.trim().equals("") && (buffer.charAt(0) != '#'))
195 {
196 JHM.tokenize(vs, buffer);
197
198 if (vs.size() > 3) // atomic number, 0, most abundant mass (...)
199 {
200 //atomicNum = Integer.parseInt((String) vs.get(0));
201 for (i = 1; i < (vs.size() - 1); i += 2) // make sure i+1 still exists
202 {
203 di = new DoubleInt();
204 di.i = Integer.parseInt((String) vs.get(i));
205 di.d = Double.parseDouble((String) vs.get(i + 1));
206 row.add(di);
207 }
208
209 _isotopes.add(row);
210 }
211 }
212 }
213 }
214 ///////////////////////////////////////////////////////////////////////////////
215 // END OF FILE.
216 ///////////////////////////////////////////////////////////////////////////////