/
IAtomContainer.java
760 lines (676 loc) · 23.4 KB
/
IAtomContainer.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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/* Copyright (C) 2006-2007,2010 Egon Willighagen <egonw@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 License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* 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 License for more details.
*
* You should have received a copy of the GNU Lesser General 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.interfaces;
import org.openscience.cdk.exception.NoSuchAtomException;
import org.openscience.cdk.interfaces.IBond.Order;
import java.util.List;
/**
* Base class for all chemical objects that maintain a list of Atoms and
* ElectronContainers. <p>
* <p>
* Looping over all <code>IBond</code>s in the <code>IAtomContainer</code>
* is typically done like:
* <pre>
* for (IBond bond : atomContainer.bonds()) {
* // do something
* }
* </pre>
* If you do need an explicit Iterator then use
* <pre>{@code
* Iterator<IBond> bondIter = atomContainer.bonds().iterator();
* }</pre>
*
* @author steinbeck
* @cdk.module interfaces
* @cdk.githash
* @cdk.created 2000-10-02
*/
public interface IAtomContainer extends IChemObject, IChemObjectListener {
/**
* Adds a stereo element to this container.
*
* @param element The new {@link IStereoElement} for this container
* @see #stereoElements()
*/
void addStereoElement(IStereoElement element);
/**
* Set the stereo elements - this will replace the existing instance
* with a new instance.
*
* @param elements the new stereo elements
*/
void setStereoElements(List<IStereoElement> elements);
/**
* Returns the stereo elements defined for this atom container.
*
* @return An {@link Iterable} of {@link IStereoElement}s.
* @see #addStereoElement(IStereoElement)
*/
Iterable<IStereoElement> stereoElements();
/**
* Sets the array of atoms of this AtomContainer.
*
* @param atoms The array of atoms to be assigned to this AtomContainer
* @see #atoms
*/
void setAtoms(IAtom[] atoms);
/**
* Sets the array of bonds of this AtomContainer.
*
* @param bonds The array of bonds to be assigned to
* this AtomContainer
* @see #bonds
*/
void setBonds(IBond[] bonds);
/**
* Set the atom at <code>idx</code>, the index must have an existing atom
* and therefore be in the range 0 ≤ idx < mol.getAtomCount().
*
* @param idx The index of the atom to be set.
* @param atom The atom to be stored at position <code>idx</code>
* @throws IndexOutOfBoundsException index is out of bounds
* @throws IllegalArgumentException the atom could not be set
* @see #getAtom
*/
void setAtom(int idx, IAtom atom);
/**
* Get the atom at the specified <b>idx</b>, the index should be in the
* range 0 ≤ <i>idx</i> < {@link #getAtomCount()}.
*
* @param idx atom index
* @return the atom stored at the index
* @see #setAtom
* @throws IndexOutOfBoundsException the index is out of range
*/
IAtom getAtom(int idx);
/**
* Get the bond at the specified <b>idx</b>, the index should be in the
* range 0 ≤ <i>idx</i> < {@link #getBondCount()}.
*
* @param idx bond index
* @return the bond stored at the index
* @throws IndexOutOfBoundsException the index is out of range
*/
IBond getBond(int idx);
/**
* Get the lone pair at the specified <b>idx</b>, the index should be in the
* range 0 ≤ <i>idx</i> < {@link #getLonePairCount()}.
*
* @param idx lone pair index
* @return the lone pair stored at the index
* @throws IndexOutOfBoundsException the index is out of range
*/
ILonePair getLonePair(int idx);
/**
* Get the single electron at the specified <b>idx</b>, the index should
* be in the range 0 ≤ <i>idx</i> < {@link #getSingleElectronCount()}.
*
* @param idx single electron index
* @return the single electron stored at the index
* @throws IndexOutOfBoundsException the index is out of range
*/
ISingleElectron getSingleElectron(int idx);
/**
* Returns an Iterable for looping over all atoms in this container.
*
* @return An Iterable with the atoms in this container
*/
Iterable<IAtom> atoms();
/**
* Returns an Iterable for looping over all bonds in this container.
*
* @return An Iterable with the bonds in this container
*/
Iterable<IBond> bonds();
/**
* Returns an Iterable for looping over all lone pairs in this container.
*
* @return An Iterable with the lone pairs in this container
*/
Iterable<ILonePair> lonePairs();
/**
* Returns an Iterable for looping over all single electrons in this container.
*
* @return An Iterable with the single electrons in this container
*/
Iterable<ISingleElectron> singleElectrons();
/**
* Returns an Iterable for looping over all electron containers in this container.
*
* @return An Iterable with the electron containers in this container
*/
Iterable<IElectronContainer> electronContainers();
/**
* Returns the atom at position 0 in the container.
*
* @return The atom at position 0 .
* @deprecated use {@link #getAtom(int)}
*/
@Deprecated
IAtom getFirstAtom();
/**
* Returns the atom at the last position in the container.
*
* @return The atom at the last position
* @deprecated use {@link #getAtom(int)}
*/
@Deprecated
IAtom getLastAtom();
/**
* Returns the position of a given atom in the atoms array. It returns -1 if
* the atom atom does not exist.
*
* @param atom The atom to be sought
* @return The Position of the atom in the atoms array in [0,..].
* @deprecated use {@link #indexOf(IAtom)}
*/
@Deprecated
int getAtomNumber(IAtom atom);
/**
* Returns the position of the bond between two given atoms in the
* electronContainers array. It returns -1 if the bond does not exist.
*
* @param atom1 The first atom
* @param atom2 The second atom
* @return The Position of the bond between a1 and a2 in the
* electronContainers array.
* @deprecated use {@link #indexOf(IBond)}
*/
@Deprecated
int getBondNumber(IAtom atom1, IAtom atom2);
/**
* Returns the position of a given bond in the electronContainers array. It
* returns -1 if the bond does not exist.
*
* @param bond The bond to be sought
* @return The Position of the bond in the electronContainers array in [0,..].
* @deprecated use {@link #indexOf(IBond)}
*/
@Deprecated
int getBondNumber(IBond bond);
/**
* Returns the position of a given lone pair in the lone pair array.
* It returns -1 if the lone pair does not exist.
*
* @param lonePair The lone pair to be sought
* @return The Position of the lone pair in the array..
* @deprecated use {@link #indexOf(ILonePair)}
*/
@Deprecated
int getLonePairNumber(ILonePair lonePair);
/**
* Returns the position of a given single electron in the single electron array.
* It returns -1 if the single electron does not exist.
*
* @param singleElectron The single electron to be sought
* @return The Position of the single electron in the array.
* @deprecated use {@link #indexOf(ISingleElectron)}
*/
int getSingleElectronNumber(ISingleElectron singleElectron);
/**
* Access the storage index of an atom.
*
* @param atom atom instance to find
* @return the index, -1 if not found
*/
int indexOf(IAtom atom);
/**
* Access the storage index of a bond.
*
* @param bond bond instance to find
* @return the index, -1 if not found
*/
int indexOf(IBond bond);
/**
* Access the storage index of a single electron (radical).
*
* @param electron the electron
* @return the index, -1 if not found
*/
int indexOf(ISingleElectron electron);
/**
* Access the storage index of a long pair.
*
* @param pair the long pair
* @return the index, -1 if not found
*/
int indexOf(ILonePair pair);
/**
* Returns the ElectronContainer at position <code>number</code> in the
* container.
*
* @param number The position of the ElectronContainer to be returned.
* @return The ElectronContainer at position <code>number</code>.
* @see #addElectronContainer(IElectronContainer)
*/
IElectronContainer getElectronContainer(int number);
/**
* Returns the bond that connects the two given atoms.
*
* @param atom1 The first atom
* @param atom2 The second atom
* @return The bond that connects the two atoms
*/
IBond getBond(IAtom atom1, IAtom atom2);
/**
* Returns the number of Atoms in this Container.
*
* @return The number of Atoms in this Container
*/
int getAtomCount();
/**
* Returns the number of Bonds in this Container.
*
* @return The number of Bonds in this Container
*/
int getBondCount();
/**
* Returns the number of LonePairs in this Container.
*
* @return The number of LonePairs in this Container
*/
int getLonePairCount();
/**
* Returns the number of the single electrons in this container.
*
* @return The number of SingleElectron objects of this AtomContainer
*/
int getSingleElectronCount();
/**
* Returns the number of ElectronContainers in this Container.
*
* @return The number of ElectronContainers in this Container
*/
int getElectronContainerCount();
/**
* Returns the atoms connected connected to the specified atom by
* a bond.
*
* @param atom the atom
* @return connected atoms
* @throws java.util.NoSuchElementException the atom is not present
*/
List<IAtom> getConnectedAtomsList(IAtom atom);
/**
* Returns the bonds connected connected to the specified atom.
*
* @param atom the atom
* @return connected bonds
* @throws java.util.NoSuchElementException the atom is not present
*/
List<IBond> getConnectedBondsList(IAtom atom);
/**
* Returns the lone pairs connected connected to the specified atom.
*
* @param atom the atom
* @return connected lone pairs
* @throws java.util.NoSuchElementException the atom is not present
*/
List<ILonePair> getConnectedLonePairsList(IAtom atom);
/**
* Returns the single electrons connected connected to the specified atom.
*
* @param atom the atom
* @return connected lone pairs
* @throws java.util.NoSuchElementException the atom is not present
*/
List<ISingleElectron> getConnectedSingleElectronsList(IAtom atom);
/**
* Returns the electron containers (bonds, radicals, and lone pairs )
* connected connected to the specified atom.
*
* @param atom the atom
* @return connected lone pairs
* @throws java.util.NoSuchElementException the atom is not present
*/
List<IElectronContainer> getConnectedElectronContainersList(IAtom atom);
/**
* Returns the number of connected atoms (explicit degree) to the
* specified atom. This does not include bonds to implicit
* hydrogens.
*
* @param atom the atom
* @return number of connected bonds
* @throws java.util.NoSuchElementException the atom is not present
* @deprecated use {@link #getConnectedBondsCount(IAtom)}
*/
@Deprecated
int getConnectedAtomsCount(IAtom atom);
/**
* Returns the number of connected bonds (explicit degree) to the
* specified atom. This does not include bonds to implicit
* hydrogens.
*
* @param atom the atom
* @return number of connected bonds
* @throws java.util.NoSuchElementException the atom is not present
*/
int getConnectedBondsCount(IAtom atom);
/**
* Returns the number of connected bonds (explicit degree) to atom
* at the specified index. This does not include bonds to implicit
* hydrogens.
*
* @param idx the atom idx
* @return number of connected bonds
* @throws IndexOutOfBoundsException the index is not in range
*/
int getConnectedBondsCount(int idx);
/**
* Returns the number of lone pairs connected to the specified atom.
*
* @param atom the atom
* @return number of connected bonds
* @throws java.util.NoSuchElementException the atom is not present
*/
int getConnectedLonePairsCount(IAtom atom);
/**
* Returns the number of single electrons connected to the specified atom.
*
* @param atom the atom
* @return number of connected bonds
* @throws java.util.NoSuchElementException the atom is not present
*/
int getConnectedSingleElectronsCount(IAtom atom);
/**
* Returns the sum of the bond orders for a given Atom.
*
* @param atom The atom
* @return The number of bondorders for this atom
*/
double getBondOrderSum(IAtom atom);
/**
* Returns the maximum bond order that this atom currently has in the context
* of this AtomContainer. If the atom has no bonds
* but does have implicit hydrogens the minimum bond order is
* {@link IBond.Order#SINGLE}, otherwise the bond is unset
* {@link IBond.Order#UNSET}.
*
* @param atom The atom
* @return The maximum bond order that this atom currently has
* @throws java.util.NoSuchElementException atom does not belong to this container
*/
Order getMaximumBondOrder(IAtom atom);
/**
* Returns the minimum bond order that this atom currently has
* in the context of this AtomContainer. If the atom has no bonds
* but does have implicit hydrogens the minimum bond order is
* {@link IBond.Order#SINGLE}, otherwise the bond is unset
* {@link IBond.Order#UNSET}.
*
* @param atom The atom
* @return The minimum bond order that this atom currently has
* @throws java.util.NoSuchElementException atom does not belong to this container
*/
Order getMinimumBondOrder(IAtom atom);
/**
* Adds all atoms and electronContainers of a given atomcontainer to this
* container.
*
* @param atomContainer The atomcontainer to be added
*/
void add(IAtomContainer atomContainer);
/**
* Adds an atom to this container.
*
* @param atom The atom to be added to this container
*/
void addAtom(IAtom atom);
/**
* Adds a Bond to this AtomContainer.
*
* @param bond The bond to added to this container
* @throws NoSuchAtomException optionally thrown if the atoms of the bond
* have not yet been added
*/
void addBond(IBond bond);
/**
* Adds a lone pair to this AtomContainer.
*
* @param lonePair The LonePair to added to this container
*/
void addLonePair(ILonePair lonePair);
/**
* Adds a single electron to this AtomContainer.
*
* @param singleElectron The SingleElectron to added to this container
*/
void addSingleElectron(ISingleElectron singleElectron);
/**
* Adds a ElectronContainer to this AtomContainer.
*
* @param electronContainer The ElectronContainer to added to this container
*/
void addElectronContainer(IElectronContainer electronContainer);
/**
* Removes all atoms and electronContainers of a given atomcontainer from this
* container.
*
* @param atomContainer The atomcontainer to be removed
*/
void remove(IAtomContainer atomContainer);
/**
* Unsafely remove atom at index.
* <br>
* Removes the atom at the given position from the AtomContainer. Note that
* the electronContainers are unaffected: you also have to take care of
* removing all electronContainers to this atom from the container manually.
*
* @param position The position of the atom to be removed.
*/
void removeAtomOnly(int position);
/**
* Unsafely remove atom.
* <br>
* Removes the given atom from the AtomContainer. Note that the
* electronContainers are unaffected: you also have to take care of removeing
* all electronContainers to this atom from the container.
*
* @param atom The atom to be removed
*/
void removeAtomOnly(IAtom atom);
/**
* Removes the bond at the given position from the AtomContainer.
*
* @param position The position of the bond to be removed.
* @return the bond at the given position
*/
IBond removeBond(int position);
/**
* Removes the bond that connects the two given atoms.
*
* @param atom1 The first atom
* @param atom2 The second atom
* @return The bond that connects the two atoms
*/
IBond removeBond(IAtom atom1, IAtom atom2);
/**
* Removes the bond from this container.
*
* @param bond The bond to be removed.
*/
void removeBond(IBond bond);
/**
* Removes the lone pair at the given position from the AtomContainer.
*
* @param position The position of the LonePair to be removed.
* @return The removed ILonePair.
*/
ILonePair removeLonePair(int position);
/**
* Removes the lone pair from the AtomContainer.
*
* @param lonePair The LonePair to be removed.
*/
void removeLonePair(ILonePair lonePair);
/**
* Removes the single electron at the given position from the AtomContainer.
*
* @param position The position of the SingleElectron to be removed.
* @return The removed ISingleElectron
*/
ISingleElectron removeSingleElectron(int position);
/**
* Removes the single electron from the AtomContainer.
*
* @param singleElectron The SingleElectron to be removed.
*/
void removeSingleElectron(ISingleElectron singleElectron);
/**
* Removes the bond at the given position from this container.
*
* @param position The position of the bond in the electronContainers array
* @return the IElectronContainer that was removed
*/
IElectronContainer removeElectronContainer(int position);
/**
* Removes this ElectronContainer from this container.
*
* @param electronContainer The electronContainer to be removed
*/
void removeElectronContainer(IElectronContainer electronContainer);
/**
* Safely remove an atom from the container.
* <br>
* Removes a single atom from the container updating all internal
* state to be consistent. All bonds connected to the atom will be
* deleted as well as all stereo elements. If multiple atoms/bonds are
* being deleted they should be gathered into a single transaction
* and removed with {@link #remove(IAtomContainer)}.
* <br>
* If you are removing hydrogens one of the
* utility methods (e.g. AtomContainerManipulator.removeHydrogens(IAtomContainer))
* is preferable.
*
* @param atom the atom to be removed
*/
void removeAtom(IAtom atom);
/**
* Safely remove an atom from the container.
* <br>
* Removes a single atom from the container updating all internal
* state to be consistent. All bonds connected to the atom will be
* deleted as well as all stereo elements. If multiple atoms/bonds are
* being deleted they should be gathered into a single transaction
* and removed with {@link #remove(IAtomContainer)}.
* <br>
* If you are removing hydrogens one of the
* utility methods (e.g. AtomContainerManipulator.removeHydrogens(IAtomContainer))
* is preferable.
*
* @param pos the position of the atom to be removed
*/
void removeAtom(int pos);
/**
* Safely remove an atom from the container.
* @see #removeAtom(IAtom)
* @deprecated Method has be renamed {@link #removeAtom(IAtom)}.
*/
@Deprecated
void removeAtomAndConnectedElectronContainers(IAtom atom);
/**
* Removes all atoms, bonds and stereo elements from this container.
*/
void removeAllElements();
/**
* Removes electronContainers from this container.
*/
void removeAllElectronContainers();
/**
* Removes all Bonds from this container.
*/
void removeAllBonds();
/**
* Adds a bond to this container.
*
* @param atom1 Id of the first atom of the Bond in [0,..]
* @param atom2 Id of the second atom of the Bond in [0,..]
* @param order Bondorder
* @param stereo Stereochemical orientation
*/
void addBond(int atom1, int atom2, IBond.Order order, IBond.Stereo stereo);
/**
* Adds a bond to this container.
*
* @param atom1 Id of the first atom of the Bond in [0,..]
* @param atom2 Id of the second atom of the Bond in [0,..]
* @param order Bondorder
*/
void addBond(int atom1, int atom2, IBond.Order order);
/**
* Adds a LonePair to this Atom.
*
* @param atomID The atom number to which the LonePair is added in [0,..]
*/
void addLonePair(int atomID);
/**
* Adds a SingleElectron to this Atom.
*
* @param atomID The atom number to which the SingleElectron is added in [0,..]
*/
void addSingleElectron(int atomID);
/**
* True, if the AtomContainer contains the given atom object.
*
* @param atom the atom this AtomContainer is searched for
* @return True, if the AtomContainer contains the given atom object
*/
boolean contains(IAtom atom);
/**
* True, if the AtomContainer contains the given bond object.
*
* @param bond the bond this AtomContainer is searched for
* @return True, if the AtomContainer contains the given bond object
*/
boolean contains(IBond bond);
/**
* True, if the AtomContainer contains the given LonePair object.
*
* @param lonePair the LonePair this AtomContainer is searched for
* @return True, if the AtomContainer contains the given LonePair object
*/
boolean contains(ILonePair lonePair);
/**
* True, if the AtomContainer contains the given SingleElectron object.
*
* @param singleElectron the SingleElectron this AtomContainer is searched for
* @return True, if the AtomContainer contains the given SingleElectron object
*/
boolean contains(ISingleElectron singleElectron);
/**
* True, if the AtomContainer contains the given ElectronContainer object.
*
* @param electronContainer ElectronContainer that is searched for
* @return True, if the AtomContainer contains the given bond object
*/
boolean contains(IElectronContainer electronContainer);
/**
* Indicates whether this container is empty. The container is considered empty if
* there are no atoms. Bonds are not checked as a graph with no vertexes can not
* have edges.
*
* @return whether the container is empty
*/
boolean isEmpty();
/**
* {@inheritDoc}
*/
@Override
IAtomContainer clone() throws CloneNotSupportedException;
}