$darkmode
DENOPTIM
ZMatrixAtom.java
Go to the documentation of this file.
1package denoptim.molecularmodeling.zmatrix;
2
3import denoptim.constants.DENOPTIMConstants;
4
8public class ZMatrixAtom
9{
10 private int id;
11 private String symbol;
12 private String type;
16 private Double bondLength;
17 private Double angleValue;
18 private Double angle2Value;
19 private Integer chiralFlag;
20
21//--------------------------------------------------------------------------
22
36 public ZMatrixAtom(int id, String symbol, String type,
39 Double angle2Value, Integer chiralFlag)
40 {
41 this.id = id;
42 this.symbol = symbol;
43 this.type = type;
44 this.bondRefAtom = bondRefAtom;
45 this.angleRefAtom = angleRefAtom;
46 this.angle2RefAtom = angle2RefAtom;
47 this.bondLength = bondLength;
48 this.angleValue = angleValue;
49 this.angle2Value = angle2Value;
50 this.chiralFlag = chiralFlag;
51 }
52
53//--------------------------------------------------------------------------
54
59 public int getId()
60 {
61 return id;
62 }
63
64//--------------------------------------------------------------------------
65
70 public void setId(int id)
71 {
72 this.id = id;
73 }
74
75//--------------------------------------------------------------------------
76
81 public String getSymbol()
82 {
83 return symbol;
84 }
85
86//--------------------------------------------------------------------------
87
92 public void setSymbol(String symbol)
93 {
94 this.symbol = symbol;
95 }
96
97//--------------------------------------------------------------------------
98
103 public String getType()
104 {
105 return type;
106 }
107
108//--------------------------------------------------------------------------
109
114 public void setType(String type)
115 {
116 this.type = type;
117 }
118
119//--------------------------------------------------------------------------
120
126 {
127 return bondRefAtom;
128 }
129
130//--------------------------------------------------------------------------
131
137 {
138 return angleRefAtom;
139 }
140
141//--------------------------------------------------------------------------
142
148 {
149 return angle2RefAtom;
150 }
151
152//--------------------------------------------------------------------------
153
158 public Double getBondLength()
159 {
160 return bondLength;
161 }
162
163//--------------------------------------------------------------------------
164
169 public Double getAngleValue()
170 {
171 return angleValue;
172 }
173
174//--------------------------------------------------------------------------
175
180 public Double getAngle2Value()
181 {
182 return angle2Value;
183 }
184
185//--------------------------------------------------------------------------
186
191 public void setBondLength(Double bondLength)
192 {
193 this.bondLength = bondLength;
194 }
195
196//--------------------------------------------------------------------------
197
202 public void setAngleValue(Double angleValue)
203 {
204 this.angleValue = angleValue;
205 }
206
207//--------------------------------------------------------------------------
208
213 public void setAngle2Value(Double angle2Value)
214 {
215 this.angle2Value = angle2Value;
216 }
217
218//--------------------------------------------------------------------------
219
224 public void setChiralFlag(Integer chiralFlag)
225 {
226 this.chiralFlag = chiralFlag;
227 }
228
229//--------------------------------------------------------------------------
230
235 public Integer getChiralFlag()
236 {
237 return chiralFlag;
238 }
239
240//--------------------------------------------------------------------------
241
246 public boolean usesProperTorsion()
247 {
248 return chiralFlag != null && chiralFlag == 0;
249 }
250
251//--------------------------------------------------------------------------
252
257 {
258 this.bondRefAtom = bondRefAtom;
259 }
260
261//--------------------------------------------------------------------------
262
267 {
268 this.angleRefAtom = angleRefAtom;
269 }
270
271//--------------------------------------------------------------------------
272
277 {
278 this.angle2RefAtom = angle2RefAtom;
279 }
280
281//--------------------------------------------------------------------------
282
287//--------------------------------------------------------------------------
288
289 @Override
290 public boolean equals(Object o)
291 {
292 if (o == null)
293 return false;
294
295 if (o == this)
296 return true;
297
298 if (o.getClass() != getClass())
299 return false;
300
301 ZMatrixAtom other = (ZMatrixAtom) o;
302
303 // Compare primitive and object fields
304 if (this.id != other.id)
305 return false;
306
307 if (this.symbol == null ? other.symbol != null : !this.symbol.equals(other.symbol))
308 return false;
309
310 if (this.type == null ? other.type != null : !this.type.equals(other.type))
311 return false;
312
313 // Compare Double fields (handle null and use tolerance for comparison)
314 // Both null -> equal, one null -> not equal, both not null -> compare with tolerance
315 if (this.bondLength == null && other.bondLength == null)
316 {
317 // Both null, considered equal - continue
318 }
319 else if (this.bondLength == null || other.bondLength == null)
320 {
321 // One is null, the other is not - not equal
322 return false;
323 }
324 else
325 {
326 // Both not null - compare with tolerance
327 if (Math.abs(this.bondLength - other.bondLength) >
329 return false;
330 }
331
332 if (this.angleValue == null && other.angleValue == null)
333 {
334 // Both null, considered equal - continue
335 }
336 else if (this.angleValue == null || other.angleValue == null)
337 {
338 // One is null, the other is not - not equal
339 return false;
340 }
341 else
342 {
343 // Both not null - compare with tolerance
344 if (Math.abs(this.angleValue - other.angleValue) >
346 return false;
347 }
348
349 if (this.angle2Value == null && other.angle2Value == null)
350 {
351 // Both null, considered equal - continue
352 }
353 else if (this.angle2Value == null || other.angle2Value == null)
354 {
355 // One is null, the other is not - not equal
356 return false;
357 }
358 else
359 {
360 // Both not null - compare with tolerance
361 if (Math.abs(this.angle2Value - other.angle2Value) >
363 return false;
364 }
365
366 // Compare Integer field (handle null)
367 if (this.chiralFlag == null ? other.chiralFlag != null
368 : !this.chiralFlag.equals(other.chiralFlag))
369 return false;
370
371 // Compare reference atoms by ID to avoid circular reference issues
372 int thisBondRefId = (this.bondRefAtom != null) ? this.bondRefAtom.getId() : -1;
373 int otherBondRefId = (other.bondRefAtom != null) ? other.bondRefAtom.getId() : -1;
374 if (thisBondRefId != otherBondRefId)
375 return false;
376
377 int thisAngleRefId = (this.angleRefAtom != null) ? this.angleRefAtom.getId() : -1;
378 int otherAngleRefId = (other.angleRefAtom != null) ? other.angleRefAtom.getId() : -1;
379 if (thisAngleRefId != otherAngleRefId)
380 return false;
381
382 int thisAngle2RefId = (this.angle2RefAtom != null) ? this.angle2RefAtom.getId() : -1;
383 int otherAngle2RefId = (other.angle2RefAtom != null) ? other.angle2RefAtom.getId() : -1;
384 if (thisAngle2RefId != otherAngle2RefId)
385 return false;
386
387 return true;
388 }
389
390//--------------------------------------------------------------------------
391
392 @Override
393 public int hashCode()
394 {
395 int result = 17;
396 result = 31 * result + id;
397 result = 31 * result + (symbol != null ? symbol.hashCode() : 0);
398 result = 31 * result + (type != null ? type.hashCode() : 0);
399 result = 31 * result + (bondRefAtom != null ? bondRefAtom.getId() : 0);
400 result = 31 * result + (angleRefAtom != null ? angleRefAtom.getId() : 0);
401 result = 31 * result + (angle2RefAtom != null ? angle2RefAtom.getId() : 0);
402 result = 31 * result + (bondLength != null ? bondLength.hashCode() : 0);
403 result = 31 * result + (angleValue != null ? angleValue.hashCode() : 0);
404 result = 31 * result + (angle2Value != null ? angle2Value.hashCode() : 0);
405 result = 31 * result + (chiralFlag != null ? chiralFlag.hashCode() : 0);
406 return result;
407 }
408
409//--------------------------------------------------------------------------
410
411 @Override
412 public String toString()
413 {
414 return id + " " + symbol + " " + type + " "
415 + (bondRefAtom != null ? bondRefAtom.getId() : "null") + " "
416 + (angleRefAtom != null ? angleRefAtom.getId() : "null") + " "
417 + (angle2RefAtom != null ? angle2RefAtom.getId() : "null") + " "
418 + (bondLength != null ? bondLength : "null") + " "
419 + (angleValue != null ? angleValue : "null") + " "
420 + (angle2Value != null ? angle2Value : "null") + " "
421 + (chiralFlag != null ? chiralFlag : "null");
422 }
423
424//--------------------------------------------------------------------------
425}
426
General set of constants used in DENOPTIM.
static final double FLOATCOMPARISONTOLERANCE
Smallest difference for comparison of double and float numbers.
Representation of an atom in the ZMatrix.
Definition: ZMatrixAtom.java:9
ZMatrixAtom(int id, String symbol, String type, ZMatrixAtom bondRefAtom, ZMatrixAtom angleRefAtom, ZMatrixAtom angle2RefAtom, Double bondLength, Double angleValue, Double angle2Value, Integer chiralFlag)
Constructor for ZMatrixAtom.
String getSymbol()
Get the symbol of the atom.
Double getAngle2Value()
Get the angle2 value.
void setBondLength(Double bondLength)
Set the bond length.
void setId(int id)
Set the id of the atom.
Integer getChiralFlag()
Get the chiral flag.
boolean usesProperTorsion()
Check if the atom uses proper torsion.
void setChiralFlag(Integer chiralFlag)
Set the chiral flag.
void setBondRefAtom(ZMatrixAtom bondRefAtom)
Package-private setter for bond reference atom (used for cloning).
ZMatrixAtom getBondRefAtom()
Get the bond reference atom.
ZMatrixAtom getAngle2RefAtom()
Get the angle2 reference atom.
void setType(String type)
Set the type of the atom.
void setAngleValue(Double angleValue)
Set the angle value.
void setAngle2Value(Double angle2Value)
Set the angle2 value.
String getType()
Get the type of the atom.
void setSymbol(String symbol)
Set the symbol of the atom.
void setAngle2RefAtom(ZMatrixAtom angle2RefAtom)
Package-private setter for angle2 reference atom (used for cloning).
boolean equals(Object o)
Get the string representation of the atom.
Double getBondLength()
Get the bond length.
void setAngleRefAtom(ZMatrixAtom angleRefAtom)
Package-private setter for angle reference atom (used for cloning).
Double getAngleValue()
Get the angle value.
ZMatrixAtom getAngleRefAtom()
Get the angle reference atom.