1 /* 2 * Copyright (c) 2013. John May <jwmay@users.sf.net> 3 * 4 * Contact: cdk-devel@lists.sourceforge.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation; either version 2.1 9 * of the License, or (at your option) any later version. 10 * All we ask is that proper credit is given for our work, which includes 11 * - but is not limited to - adding the above copyright notice to the beginning 12 * of your source code files, and to any copyright notice that you may distribute 13 * with programs based on this work. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * along with this program; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U 23 */ 24 25 package org.openscience.cdk.hash.stereo; 26 27 import org.junit.Assert; 28 import org.junit.Test; 29 import org.openscience.cdk.hash.stereo.GeometricParity; 30 import org.openscience.cdk.hash.stereo.Tetrahedral2DParity; 31 32 import javax.vecmath.Point2d; 33 34 import static org.hamcrest.CoreMatchers.is; 35 36 /** 37 * @author John May 38 * @cdk.module test-hash 39 */ 40 public class Tetrahedral2DParityTest { 41 42 private static final int CLOCKWISE = -1; 43 private static final int ANTICLOCKWISE = +1; 44 private static final int NONE = 0; 45 46 @Test(expected = IllegalArgumentException.class) testConstruction_InvalidCoords()47 public void testConstruction_InvalidCoords() { 48 new Tetrahedral2DParity(new Point2d[0], new int[4]); 49 } 50 51 @Test(expected = IllegalArgumentException.class) testConstruction_InvalidElev()52 public void testConstruction_InvalidElev() { 53 new Tetrahedral2DParity(new Point2d[4], new int[0]); 54 } 55 56 /** 57 * aminoethanol (explicit H) hatch bond on hydrogen (none,none,none,down) 58 * 59 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 60 */ 61 @Test testParity_Four_NNND()62 public void testParity_Four_NNND() { 63 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 64 new Point2d(-6.42, 3.48), // -N 65 new Point2d(-9.09, 3.48), // -C 66 new Point2d(-9.09, 5.02), // -H (down) 67 }; 68 int[] elev = new int[]{0, 0, 0, -1}; 69 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 70 Assert.assertThat(parity.parity(), is(CLOCKWISE)); 71 } 72 73 /** 74 * aminoethanol (explicit H) wedge on hydrogen (none,none,none,up) 75 * 76 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 77 */ 78 @Test testParity_Four_NNNU()79 public void testParity_Four_NNNU() { 80 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 81 new Point2d(-6.42, 3.48), // -N 82 new Point2d(-9.09, 3.48), // -C 83 new Point2d(-9.09, 5.02), // -H (up) 84 }; 85 int[] elev = new int[]{0, 0, 0, 1}; 86 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 87 Assert.assertThat(parity.parity(), is(ANTICLOCKWISE)); 88 } 89 90 /** 91 * aminoethanol (explicit H) with no wedge/hatch bonds 92 * (none,none,none,none) 93 * 94 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 95 */ 96 @Test testParity_Four_NNNN()97 public void testParity_Four_NNNN() { 98 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 99 new Point2d(-6.42, 3.48), // -N 100 new Point2d(-9.09, 3.48), // -C 101 new Point2d(-9.09, 5.02), // -H 102 }; 103 int[] elev = new int[]{0, 0, 0, 0}; // no wedge/hatch bonds 104 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 105 Assert.assertThat(parity.parity(), is(NONE)); 106 } 107 108 /** 109 * aminoethanol (explicit H) with a wedge bond on non hydrogens 110 * (up,up,up,none) 111 * 112 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 113 */ 114 @Test testParity_Four_UUUN()115 public void testParity_Four_UUUN() { 116 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 117 new Point2d(-6.42, 3.48), // -N 118 new Point2d(-9.09, 3.48), // -C 119 new Point2d(-9.09, 5.02), // -H 120 }; 121 int[] elev = new int[]{1, 1, 1, 0}; // no wedge/hatch bonds 122 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 123 Assert.assertThat(parity.parity(), is(CLOCKWISE)); 124 } 125 126 /** 127 * aminoethanol (explicit H) with a wedge bond on non hydrogens 128 * (down,down,down,none) 129 * 130 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 131 */ 132 @Test testParity_Four_DDDN()133 public void testParity_Four_DDDN() { 134 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 135 new Point2d(-6.42, 3.48), // -N 136 new Point2d(-9.09, 3.48), // -C 137 new Point2d(-9.09, 5.02), // -H 138 }; 139 int[] elev = new int[]{-1, -1, -1, 0}; // no wedge/hatch bonds 140 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 141 Assert.assertThat(parity.parity(), is(ANTICLOCKWISE)); 142 } 143 144 /** 145 * aminoethanol (explicit H) with a wedge bond on all atoms (up,up,up,up) - 146 * makes no sense 147 * 148 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 149 */ 150 @Test testParity_Four_UUUU()151 public void testParity_Four_UUUU() { 152 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 153 new Point2d(-6.42, 3.48), // -N 154 new Point2d(-9.09, 3.48), // -C 155 new Point2d(-9.09, 5.02), // -H 156 }; 157 int[] elev = new int[]{1, 1, 1, 1}; // no wedge/hatch bonds 158 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 159 Assert.assertThat(parity.parity(), is(NONE)); 160 } 161 162 /** 163 * aminoethanol (explicit H) with a hatch bond on all atoms 164 * (down,down,down,down) - makes no sense 165 * 166 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 167 */ 168 @Test testParity_Four_DDDD()169 public void testParity_Four_DDDD() { 170 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O 171 new Point2d(-6.42, 3.48), // -N 172 new Point2d(-9.09, 3.48), // -C 173 new Point2d(-9.09, 5.02), // -H 174 }; 175 int[] elev = new int[]{-1, -1, -1, -1}; // no wedge/hatch bonds 176 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 177 Assert.assertThat(parity.parity(), is(NONE)); 178 } 179 180 /** 181 * aminoethanol (implicit H) (up,none,none) 182 * 183 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 184 */ 185 @Test testParity_Three_UNN()186 public void testParity_Three_UNN() { 187 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O (up) 188 new Point2d(-6.42, 3.48), // -N 189 new Point2d(-9.09, 3.48), // -C 190 new Point2d(-7.75, 4.25), // C (centre) 191 }; 192 int[] elev = new int[]{1, 0, 0, 0}; 193 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 194 Assert.assertThat(parity.parity(), is(CLOCKWISE)); 195 } 196 197 /** 198 * aminoethanol (implicit H) (up,up,up) 199 * 200 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 201 */ 202 @Test testParity_Three_UUU()203 public void testParity_Three_UUU() { 204 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O (up) 205 new Point2d(-6.42, 3.48), // -N 206 new Point2d(-9.09, 3.48), // -C 207 new Point2d(-7.75, 4.25), // C (centre) 208 }; 209 int[] elev = new int[]{1, 1, 1, 0}; 210 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 211 Assert.assertThat(parity.parity(), is(CLOCKWISE)); 212 } 213 214 /** 215 * aminoethanol (implicit H) (down, none, none) 216 * 217 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 218 */ 219 @Test testParity_Three_DNN()220 public void testParity_Three_DNN() { 221 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O (down) 222 new Point2d(-6.42, 3.48), // -N 223 new Point2d(-9.09, 3.48), // -C 224 new Point2d(-7.75, 4.25), // C (centre) 225 }; 226 int[] elev = new int[]{-1, 0, 0, 0}; 227 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 228 Assert.assertThat(parity.parity(), is(ANTICLOCKWISE)); 229 } 230 231 /** 232 * aminoethanol (implicit H) (down, none, none) 233 * 234 * @cdk.inchi InChI=1S/C2H7NO/c1-2(3)4/h2,4H,3H2,1H3/t2-/m1/s1 235 */ 236 @Test testParity_Three_DDD()237 public void testParity_Three_DDD() { 238 Point2d[] coords = new Point2d[]{new Point2d(-7.75, 5.79), // -O (down) 239 new Point2d(-6.42, 3.48), // -N 240 new Point2d(-9.09, 3.48), // -C 241 new Point2d(-7.75, 4.25), // C (centre) 242 }; 243 int[] elev = new int[]{-1, -1, -1, 0}; 244 GeometricParity parity = new Tetrahedral2DParity(coords, elev); 245 Assert.assertThat(parity.parity(), is(ANTICLOCKWISE)); 246 } 247 248 } 249