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 import java.util.ArrayList;
22 import java.util.List;
23
24 /**
25 *
26 * @author Sam Adams
27 */
28 public class JniInchiStructure {
29
30 /**
31 * List of atoms.
32 */
33 private List atomList = new ArrayList();
34
35 /**
36 * List of bonds.
37 */
38 private List bondList = new ArrayList();
39
40 /**
41 * List of stero parities.
42 */
43 private List stereoList = new ArrayList();
44
45
46 /**
47 * Returns number of atoms in structure.
48 */
49 public int getNumAtoms() {
50 return atomList.size();
51 }
52
53 /**
54 * Returns number of bonds in structure.
55 */
56 public int getNumBonds() {
57 return bondList.size();
58 }
59
60 /**
61 * Returns number of stereo parities in strucuture.
62 */
63 public int getNumStereo0D() {
64 return stereoList.size();
65 }
66
67
68 /**
69 * Adds atom to inchi molecule.
70 *
71 * @param atom Atom to add
72 * @return Added atom
73 */
74 @SuppressWarnings("unchecked")
75 public JniInchiAtom addAtom(JniInchiAtom atom) {
76 atomList.add(atom);
77 return atom;
78 }
79
80
81 /**
82 * Convenience method to add multiple atoms to molecule.
83 * @param atoms
84 */
85 public void addAtoms(JniInchiAtom... atoms) {
86 for (JniInchiAtom atom : atoms) {
87 addAtom(atom);
88 }
89 }
90
91 /**
92 * Adds bond to inchi molecule.
93 *
94 * @param bond Bond to add
95 * @return Added bond
96 */
97 @SuppressWarnings("unchecked")
98 public JniInchiBond addBond(JniInchiBond bond) {
99 bondList.add(bond);
100 return bond;
101 }
102
103 /**
104 * Convenience method to add multiple bonds to molecule.
105 * @param bonds
106 */
107 public void addBonds(JniInchiBond... bonds) {
108 for (JniInchiBond bond : bonds) {
109 addBond(bond);
110 }
111 }
112
113 /**
114 * Adds 0D stereo parity to inchi molecule.
115 *
116 * @param parity Parity to add
117 * @return Added parity
118 */
119 @SuppressWarnings("unchecked")
120 public JniInchiStereo0D addStereo0D(JniInchiStereo0D parity) {
121 stereoList.add(parity);
122 return parity;
123 }
124
125
126 /**
127 * Returns atom from structure.
128 * @param i Index of atom to return.
129 * @return
130 */
131 public JniInchiAtom getAtom(final int i) {
132 return (JniInchiAtom) atomList.get(i);
133 }
134
135 /**
136 * Returns bond from structure.
137 * @param i Index of bond to return.
138 * @return
139 */
140 public JniInchiBond getBond(final int i) {
141 return (JniInchiBond) bondList.get(i);
142 }
143
144 /**
145 * Returns stereo parity from structure.
146 * @param i Index of stereo parity to return.
147 * @return
148 */
149 public JniInchiStereo0D getStereo0D(final int i) {
150 return (JniInchiStereo0D) stereoList.get(i);
151 }
152
153 public void setStructure(JniInchiStructure structure) {
154 this.atomList = structure.atomList;
155 this.bondList = structure.bondList;
156 this.stereoList = structure.stereoList;
157 }
158
159 int getAtomIndex(JniInchiAtom atom) {
160 return atomList.indexOf(atom);
161 }
162
163 int getStereo0DIndex(JniInchiStereo0D stereo) {
164 return stereoList.indexOf(stereo);
165 }
166 }