1 /* 2 * Copyright 2006-2010 Sam Adams <sea36 at users.sourceforge.net> 3 * 4 * This file is part of JNI-InChI. 5 * 6 * JNI-InChI is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * JNI-InChI is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with JNI-InChI. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 package net.sf.jniinchi; 20 21 /** 22 * Encapsulates properties of InChI Atom. See <tt>inchi_api.h</tt>. 23 * @author Sam Adams 24 */ 25 public class JniInchiAtom { 26 27 /** 28 * Indicates relative rather than absolute isotopic mass. Value 29 * from inchi_api.h. 30 */ 31 protected static final int ISOTOPIC_SHIFT_FLAG = 10000; 32 33 /** 34 * Atom x-coordinate. 35 */ 36 private double x; 37 38 /** 39 * Atom y-coordinate. 40 */ 41 private double y; 42 43 /** 44 * Atom z-coordinate. 45 */ 46 private double z; 47 48 /** 49 * Chemical element symbol eg C, O, Fe, Hg. 50 */ 51 private String elname; 52 53 /** 54 * Number of implicit hydrogens on atom. If set to -1, InChI will add 55 * implicit H automatically. 56 */ 57 private int implicitH = -1; 58 59 /** 60 * Number of implicit protiums (isotopic 1-H) on atom. 61 */ 62 private int implicitP = 0; 63 64 /** 65 * Number of implicit deuteriums (isotopic 2-H) on atom. 66 */ 67 private int implicitD = 0; 68 69 /** 70 * Number of implicit tritiums (isotopic 3-H) on atom. 71 */ 72 private int implicitT = 0; 73 74 /** 75 * Mass of isotope. If set to 0, no isotopic mass set; otherwise, isotopic 76 * mass, or ISOTOPIC_SHIFT_FLAG + (mass - average atomic mass). 77 */ 78 private int isotopic_mass = 0; 79 80 /** 81 * Radical status of atom. 82 */ 83 private INCHI_RADICAL radical = INCHI_RADICAL.NONE; 84 85 /** 86 * Charge on atom. 87 */ 88 private int charge = 0; 89 90 /** 91 * <p>Create new atom. 92 * 93 * <p>Coordinates and element symbol must be set (unknown 94 * coordinates/dimensions should be set to zero). All other 95 * parameters are initialised to default values: 96 * <p> 97 * <tt> 98 * Num Implicit H = 0<br> 99 * Num Implicit 1H = 0<br> 100 * Num Implicit 2H = 0<br> 101 * Num Implicit 3H = 0<br> 102 * Isotopic mass = 0 (non isotopic)<br> 103 * Radical status = NONE (radical status not defined) 104 * </tt> 105 * 106 * @param x x-coordinate 107 * @param y y-coordinate 108 * @param z z-coordinate 109 * @param el Chemical element symbol 110 * @throws NullPointerException - if the element symbol is null. 111 */ 112 public JniInchiAtom(final double x, final double y, final double z, final String el) { 113 this.x = x; 114 this.y = y; 115 this.z = z; 116 117 if (el == null) { 118 throw new NullPointerException("Chemical element must not be null"); 119 } 120 this.elname = el; 121 } 122 123 124 /** 125 * Convenience method to create a new atom with zero coordinates. 126 * @param el 127 */ 128 public JniInchiAtom(final String el) { 129 this(0.0, 0.0, 0.0, el); 130 } 131 132 133 /** 134 * Sets charge on atom. 135 * 136 * @param charge 137 */ 138 public void setCharge(final int charge) { 139 this.charge = charge; 140 } 141 142 /** 143 * Sets radical status of atom. 144 * 145 * @param radical 146 */ 147 public void setRadical(final INCHI_RADICAL radical) { 148 this.radical = radical; 149 } 150 151 /** 152 * Sets isotopic mass. If set to 0, non-isotopic. 153 * 154 * @param mass Isotopic mass 155 */ 156 public void setIsotopicMass(final int mass) { 157 this.isotopic_mass = mass; 158 } 159 160 /** 161 * Sets isotopic mass, relative to standard mass. 162 * 163 * @param shift Isotopic mass minus average atomic mass 164 */ 165 public void setIsotopicMassShift(final int shift) { 166 this.isotopic_mass = ISOTOPIC_SHIFT_FLAG + shift; 167 } 168 169 /** 170 * Sets number of implicit hydrogens on atom. If set to -1, InChI will add 171 * implicit H automatically. 172 * 173 * @param n Number of implicit hydrogen 174 */ 175 public void setImplicitH(final int n) { 176 this.implicitH = n; 177 } 178 179 /** 180 * Sets number of implicit protium (1H) on atom. 181 * @param n Number of implicit protium 182 */ 183 public void setImplicitProtium(final int n) { 184 this.implicitP = n; 185 } 186 187 /** 188 * Sets number of implicit deuterium (2H) on atom. 189 * 190 * @param n Number of implicit deuterium 191 */ 192 public void setImplicitDeuterium(final int n) { 193 this.implicitD = n; 194 } 195 196 /** 197 * Sets number of implicit tritium (3H) on atom. 198 * @param n Number of implicit tritium 199 */ 200 public void setImplicitTritium(final int n) { 201 this.implicitT = n; 202 } 203 204 /** 205 * Returns chemical element symbol of atom. 206 * @return 207 */ 208 public String getElementType() { 209 return elname; 210 } 211 212 /** 213 * Returns charge on atom. 214 * @return 215 */ 216 public int getCharge() { 217 return charge; 218 } 219 220 /** 221 * Returns radical state of atom. 222 * @return 223 */ 224 public INCHI_RADICAL getRadical() { 225 return radical; 226 } 227 228 /** 229 * Returns atom's X-coordinate. 230 * @return 231 */ 232 public double getX() { 233 return x; 234 } 235 236 /** 237 * Returns atom's Y-coordinate. 238 * @return 239 */ 240 public double getY() { 241 return y; 242 } 243 244 /** 245 * Returns atom's Z-coordinate. 246 * @return 247 */ 248 public double getZ() { 249 return z; 250 } 251 252 /** 253 * Returns number of implicit hydrogens on atom. 254 * @return 255 */ 256 public int getImplicitH() { 257 return implicitH; 258 } 259 260 /** 261 * Returns number of implicit protiums (1H) on atom. 262 * @return 263 */ 264 public int getImplicitProtium() { 265 return implicitP; 266 } 267 268 /** 269 * Returns number of implicit deuteriums (2H) on atom. 270 * @return 271 */ 272 public int getImplicitDeuterium() { 273 return implicitD; 274 } 275 276 /** 277 * Returns number of implicit tritiums (3H) on atom. 278 * @return 279 */ 280 public int getImplicitTritium() { 281 return implicitT; 282 } 283 284 /** 285 * Returns isotopic mass of atom. 286 * @return 287 */ 288 public int getIsotopicMass() { 289 return isotopic_mass; 290 } 291 292 293 int getInchiRadical() { 294 return radical.getIndx(); 295 } 296 297 void setInchiRadical(int radical) { 298 this.radical = INCHI_RADICAL.getValue(radical); 299 } 300 301 302 /** 303 * Generates string representation of information on atom, 304 * for debugging purposes. 305 */ 306 public String getDebugString() { 307 return "InChI Atom: " 308 + elname 309 + " [" + x + "," + y + "," + z + "] " 310 + "Charge:" + charge + " // " 311 + "Iso Mass:" + isotopic_mass + " // " 312 + "Implicit H:" + implicitH 313 + " P:" + implicitP 314 + " D:" + implicitD 315 + " T:" + implicitT 316 + " // Radical: " + radical; 317 } 318 319 /** 320 * Outputs information on atom, for debugging purposes. 321 */ 322 public void debug() { 323 System.out.println(getDebugString()); 324 } 325 }