View Javadoc

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 Bond.  See <tt>inchi_api.h</tt>.
23   * @author Sam Adams
24   */
25  public class JniInchiBond {
26  
27      /**
28       * Origin atom in bond.
29       */
30      private JniInchiAtom atomOrigin;
31  
32      /**
33       * Target atom in bond.
34       */
35      private JniInchiAtom atomTarget;
36  
37      /**
38       * Bond type.
39       */
40      private INCHI_BOND_TYPE type = INCHI_BOND_TYPE.NONE;
41  
42      /**
43       * Bond 2D stereo definition.
44       */
45      private INCHI_BOND_STEREO stereo = INCHI_BOND_STEREO.NONE;
46  
47      /**
48       * Create bond.
49       *
50       * @param atO        Origin atom
51       * @param atT        Target atom
52       * @param type        Bond type
53       * @param stereo    Bond 2D stereo definition
54       */
55      public JniInchiBond(JniInchiAtom atO, JniInchiAtom atT,
56              INCHI_BOND_TYPE type, INCHI_BOND_STEREO stereo) {
57  
58          this.atomOrigin = atO;
59          this.atomTarget = atT;
60          this.type = type;
61          this.stereo = stereo;
62      }
63      
64      
65      JniInchiBond(JniInchiAtom atO, JniInchiAtom atT,
66              int type, int stereo) {
67  
68      	this(atO, atT, INCHI_BOND_TYPE.getValue(type), INCHI_BOND_STEREO.getValue(stereo));
69      }
70  
71      /**
72       * Create bond.
73       *
74       * @param atO        Origin atom
75       * @param atT        Target atom
76       * @param type        Bond type
77       */
78      public JniInchiBond(JniInchiAtom atO, JniInchiAtom atT,
79              INCHI_BOND_TYPE type) {
80  
81          this(atO, atT, type, INCHI_BOND_STEREO.NONE);
82      }
83  
84      /**
85       * Set 2D stereo definition.
86       *
87       * @param stereo    Bond 2D stereo definition
88       */
89      public void setStereoDefinition(INCHI_BOND_STEREO stereo) {
90          this.stereo = stereo;
91      }
92  
93      /**
94       * Returns atom at bond origin.
95       * @return
96       */
97      public JniInchiAtom getOriginAtom() {
98          return atomOrigin;
99      }
100 
101     /**
102      * Returns atom at bond target.
103      * @return
104      */
105     public JniInchiAtom getTargetAtom() {
106         return atomTarget;
107     }
108 
109     /**
110      * Returns bond type.
111      * @return
112      */
113     public INCHI_BOND_TYPE getBondType() {
114         return type;
115     }
116 
117     /**
118      * Returns bond stereochemistry.
119      * @return
120      */
121     public INCHI_BOND_STEREO getBondStereo() {
122         return stereo;
123     }
124 
125     /**
126      * Generates string representation of information on bond,
127      * for debugging purposes.
128      */
129     public String getDebugString() {
130         return("InChI Bond: "
131         + atomOrigin.getElementType()
132         + "-" + atomTarget.getElementType()
133         + " // Type: " + type
134         + " // Stereo: " + stereo
135         );
136     }
137 
138     /**
139      * Outputs information on bond, for debugging purposes.
140      */
141     public void debug() {
142         System.out.println(getDebugString());
143     }
144     
145     int getInchiBondType() {
146     	return type.getIndx();
147     }
148     
149     int getInchiBondStereo() {
150     	return stereo.getIndx();
151     }
152     
153 }