/
Atom.java
422 lines (393 loc) · 14.3 KB
/
Atom.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 2000-2007 Christoph Steinbeck <steinbeck@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IElement;
import org.openscience.cdk.tools.periodictable.PeriodicTable;
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import java.io.Serializable;
/**
* Represents the idea of an chemical atom.
*
* <p>An Atom class is instantiated with at least the atom symbol:
* <pre>
* Atom a = new Atom("C");
* </pre>
*
* <p>Once instantiated all field not filled by passing parameters
* to the constructor are null. Atoms can be configured by using
* the IsotopeFactory.configure() method:
* <pre>
* IsotopeFactory if = IsotopeFactory.getInstance(a.getNewBuilder());
* if.configure(a);
* </pre>
*
* <p>More examples about using this class can be found in the
* Junit test for this class.
*
* @cdk.module data
* @cdk.githash
*
* @author steinbeck
* @cdk.created 2000-10-02
* @cdk.keyword atom
*
* @see org.openscience.cdk.config.IsotopeFactory#getInstance(org.openscience.cdk.interfaces.IChemObjectBuilder)
*/
public class Atom extends AtomType implements IAtom, Serializable, Cloneable {
/* Let's keep this exact specification
* of what kind of point2d we're talking of here,
* since there are so many around in the java standard api */
/**
* Determines if a de-serialized object is compatible with this class.
*
* This value must only be changed if and only if the new version
* of this class is incompatible with the old version. See Sun docs
* for <a href=http://java.sun.com/products/jdk/1.1/docs/guide
* /serialization/spec/version.doc.html>details</a>.
*/
private static final long serialVersionUID = -3137373012494608794L;
/**
* A 2D point specifying the location of this atom in a 2D coordinate
* space.
*/
protected javax.vecmath.Point2d point2d = (Point2d) CDKConstants.UNSET;
/**
* A 3 point specifying the location of this atom in a 3D coordinate
* space.
*/
protected javax.vecmath.Point3d point3d = (Point3d) CDKConstants.UNSET;
/**
* A 3 point specifying the location of this atom in a crystal unit cell.
*/
protected javax.vecmath.Point3d fractionalPoint3d = (Point3d) CDKConstants.UNSET;
/**
* The number of implicitly bound hydrogen atoms for this atom.
*/
protected Integer hydrogenCount = (Integer) CDKConstants.UNSET;
/**
* A stereo parity descriptor for the stereochemistry of this atom.
*/
protected Integer stereoParity = (Integer) CDKConstants.UNSET;
/**
* The partial charge of the atom.
*
* The default value is {@link CDKConstants#UNSET} and serves to provide a check whether the charge has been
* set or not
*/
protected Double charge = (Double) CDKConstants.UNSET;
/**
* Constructs an completely unset Atom.
*/
public Atom() {
super((String)null);
}
/**
* Constructs an Atom from a String containing an element symbol.
*
* @param elementSymbol The String describing the element for the Atom
*/
public Atom(String elementSymbol) {
this(new Element(elementSymbol, PeriodicTable.getAtomicNumber(elementSymbol)));
this.formalCharge = 0;
}
/**
* Constructs an Atom from an Element and a Point3d.
*
* @param elementSymbol The symbol of the atom
* @param point3d The 3D coordinates of the atom
*/
public Atom(String elementSymbol, javax.vecmath.Point3d point3d)
{
this(elementSymbol);
this.point3d = point3d;
}
/**
* Constructs an Atom from an Element and a Point2d.
*
* @param elementSymbol The Element
* @param point2d The Point
*/
public Atom(String elementSymbol, javax.vecmath.Point2d point2d)
{
this(elementSymbol);
this.point2d = point2d;
}
/**
* Constructs an isotope by copying the symbol, atomic number,
* flags, identifier, exact mass, natural abundance, mass
* number, maximum bond order, bond order sum, van der Waals
* and covalent radii, formal charge, hybridization, electron
* valency, formal neighbour count and atom type name from the
* given IAtomType. It does not copy the listeners and
* properties. If the element is an instanceof
* IAtom, then the 2D, 3D and fractional coordinates, partial
* atomic charge, hydrogen count and stereo parity are copied
* too.
*
* @param element IAtomType to copy information from
*/
public Atom(IElement element) {
super(element);
if (element instanceof IAtom) {
if (((IAtom)element).getPoint2d() != null) {
this.point2d = new Point2d(((IAtom)element).getPoint2d());
} else {
this.point2d = null;
}
if (((IAtom)element).getPoint3d() != null) {
this.point3d = new Point3d(((IAtom)element).getPoint3d());
} else {
this.point3d = null;
}
if (((IAtom)element).getFractionalPoint3d() != null) {
this.fractionalPoint3d = new Point3d(((IAtom)element).getFractionalPoint3d());
} else {
this.fractionalPoint3d = null;
}
this.hydrogenCount = ((IAtom)element).getImplicitHydrogenCount();
this.charge = ((IAtom)element).getCharge();
this.stereoParity = ((IAtom)element).getStereoParity();
}
}
/**
* Sets the partial charge of this atom.
*
* @param charge The partial charge
*
* @see #getCharge
*/
public void setCharge(Double charge) {
this.charge = charge;
notifyChanged();
}
/**
* Returns the partial charge of this atom.
*
* If the charge has not been set the return value is Double.NaN
*
* @return the charge of this atom
*
* @see #setCharge
*/
public Double getCharge() {
return this.charge;
}
/**
* Sets the number of implicit hydrogen count of this atom.
*
* @param hydrogenCount The number of hydrogen atoms bonded to this atom.
*
* @see #getImplicitHydrogenCount
*/
public void setImplicitHydrogenCount(Integer hydrogenCount) {
this.hydrogenCount = hydrogenCount;
notifyChanged();
}
/**
* Returns the hydrogen count of this atom.
*
* @return The hydrogen count of this atom.
*
* @see #setImplicitHydrogenCount
*/
public Integer getImplicitHydrogenCount() {
return this.hydrogenCount;
}
/**
*
* Sets a point specifying the location of this
* atom in a 2D space.
*
* @param point2d A point in a 2D plane
*
* @see #getPoint2d
*/
public void setPoint2d(javax.vecmath.Point2d point2d) {
this.point2d = point2d;
notifyChanged();
}
/**
*
* Sets a point specifying the location of this
* atom in 3D space.
*
* @param point3d A point in a 3-dimensional space
*
* @see #getPoint3d
*/
public void setPoint3d(javax.vecmath.Point3d point3d) {
this.point3d = point3d;
notifyChanged();
}
/**
* Sets a point specifying the location of this
* atom in a Crystal unit cell.
*
* @param point3d A point in a 3d fractional unit cell space
*
* @see #getFractionalPoint3d
* @see org.openscience.cdk.Crystal
*/
public void setFractionalPoint3d(javax.vecmath.Point3d point3d) {
this.fractionalPoint3d = point3d;
notifyChanged();
}
/**
* Sets the stereo parity for this atom.
*
* @param stereoParity The stereo parity for this atom
*
* @see org.openscience.cdk.CDKConstants for predefined values.
* @see #getStereoParity
*/
public void setStereoParity(Integer stereoParity) {
this.stereoParity = stereoParity;
notifyChanged();
}
/**
* Returns a point specifying the location of this
* atom in a 2D space.
*
* @return A point in a 2D plane. Null if unset.
*
* @see #setPoint2d
*/
public javax.vecmath.Point2d getPoint2d() {
return this.point2d;
}
/**
* Returns a point specifying the location of this
* atom in a 3D space.
*
* @return A point in 3-dimensional space. Null if unset.
*
* @see #setPoint3d
*/
public javax.vecmath.Point3d getPoint3d() {
return this.point3d;
}
/**
* Returns a point specifying the location of this
* atom in a Crystal unit cell.
*
* @return A point in 3d fractional unit cell space. Null if unset.
*
* @see #setFractionalPoint3d
* @see org.openscience.cdk.CDKConstants for predefined values.
*/
public javax.vecmath.Point3d getFractionalPoint3d() {
return this.fractionalPoint3d;
}
/**
* Returns the stereo parity of this atom. It uses the predefined values
* found in CDKConstants.
*
* @return The stereo parity for this atom
*
* @see org.openscience.cdk.CDKConstants
* @see #setStereoParity
*/
public Integer getStereoParity() {
return this.stereoParity;
}
/**
* Compares a atom with this atom.
*
* @param object of type Atom
* @return true, if the atoms are equal
*/
public boolean compare(Object object)
{
if (!(object instanceof IAtom)) {
return false;
}
if (!super.compare(object)) {
return false;
}
Atom atom = (Atom) object;
if (((point2d==atom.point2d) || ((point2d!=null) && (point2d.equals(atom.point2d)))) &&
((point3d==atom.point3d) || ((point3d!=null) && (point3d.equals(atom.point3d)))) &&
(hydrogenCount==atom.hydrogenCount) &&
(stereoParity==atom.stereoParity) &&
(charge==atom.charge)) {
return true;
}
return false;
}
/**
* Returns a one line string representation of this Atom.
* Methods is conform RFC #9.
*
* @return The string representation of this Atom
*/
public String toString() {
StringBuffer stringContent = new StringBuffer(64);
stringContent.append("Atom(").append(hashCode());
if (getSymbol() != null) {
stringContent.append(", S:").append(getSymbol());
}
if (getImplicitHydrogenCount() != null) {
stringContent.append(", H:").append(getImplicitHydrogenCount());
}
if (getStereoParity() != null) {
stringContent.append(", SP:").append(getStereoParity());
}
if (getPoint2d() != null) {
stringContent.append(", 2D:[").append(getPoint2d()).append(']');
}
if (getPoint3d() != null) {
stringContent.append(", 3D:[").append(getPoint3d()).append(']');
}
if (getFractionalPoint3d() != null) {
stringContent.append(", F3D:[").append(getFractionalPoint3d());
}
if (getCharge() != null) {
stringContent.append(", C:").append(getCharge());
}
stringContent.append(", ").append(super.toString());
stringContent.append(')');
return stringContent.toString();
}
/**
* Clones this atom object and its content.
*
* @return The cloned object
*/
public Object clone() throws CloneNotSupportedException {
Object clone = super.clone();
if (point2d != null) {
((Atom)clone).setPoint2d(new Point2d(point2d.x, point2d.y));
}
if (point3d != null) {
((Atom)clone).setPoint3d(new Point3d(point3d.x, point3d.y, point3d.z));
}
if (fractionalPoint3d != null) {
((Atom)clone).setFractionalPoint3d(new Point3d(fractionalPoint3d.x, fractionalPoint3d.y, fractionalPoint3d.z));
}
return clone;
}
}