Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated and corrected new AtomPlacer3D Test class by danielszisz

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
commit ea2b55e55b90fa6ca91d242fe71ae2c85cf66238 1 parent d83c937
authored April 23, 2012 rajarshi committed May 02, 2012
378  src/test/org/openscience/cdk/modeling/builder3d/FurtherAtomPlacer3DTest.java
... ...
@@ -1,17 +1,34 @@
  1
+/* Copyright (C) 2000-2012  Christoph Steinbeck, Egon Willighagen 
  2
+ *
  3
+ * Contact: cdk-devel@lists.sourceforge.net
  4
+ *
  5
+ * This program is free software; you can redistribute it and/or
  6
+ * modify it under the terms of the GNU Lesser General Public License
  7
+ * as published by the Free Software Foundation; either version 2.1
  8
+ * of the License, or (at your option) any later version.
  9
+ * All we ask is that proper credit is given for our work, which includes
  10
+ * - but is not limited to - adding the above copyright notice to the beginning
  11
+ * of your source code files, and to any copyright notice that you may distribute
  12
+ * with programs based on this work.
  13
+ *
  14
+ * This program is distributed in the hope that it will be useful,
  15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17
+ * GNU Lesser General Public License for more details.
  18
+ *
  19
+ * You should have received a copy of the GNU Lesser General Public License
  20
+ * along with this program; if not, write to the Free Software
  21
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22
+ */
1 23
 package org.openscience.cdk.modeling.builder3d;
2 24
 
3 25
 import javax.vecmath.Point3d;
4  
-import java.util.List;
5  
-import java.util.Map;
6  
-import java.util.HashMap;
7  
-import java.util.ArrayList;
  26
+
8 27
 import org.junit.Assert;
9 28
 import org.junit.Test;
10 29
 import org.openscience.cdk.CDKConstants;
11  
-import org.openscience.cdk.CDKTestCase;
12 30
 import org.openscience.cdk.DefaultChemObjectBuilder;
13 31
 import org.openscience.cdk.exception.CDKException;
14  
-import org.openscience.cdk.exception.InvalidSmilesException;
15 32
 import org.openscience.cdk.interfaces.IAtom;
16 33
 import org.openscience.cdk.interfaces.IAtomContainer;
17 34
 import org.openscience.cdk.interfaces.IBond;
@@ -23,32 +40,23 @@
23 40
 /**
24 41
  * Tests not-yet-tested functionalities of {@link AtomPlacer3D}. 
25 42
  *    
26  
- * @author danielszisz
  43
+ * @author danielszisz 
27 44
  * @cdk.module test-builder3d
28  
- * @created 04/27/2012
29  
- * @version 04/20/2012
  45
+ * @created 04/10/2012
  46
+ * @version 04/22/2012
30 47
  */
31 48
 
32 49
 public class FurtherAtomPlacer3DTest extends AtomPlacer3DTest {
33 50
 	
34 51
 	@Test
35  
-	public void testAllHeavyAtomsPlaced_IAtomContainer() {
  52
+	public void testAllHeavyAtomsPlaced_benzene() {
36 53
 		AtomPlacer3D atmplacer=new AtomPlacer3D();
37  
-		List<IAtomContainer> molecules = new ArrayList<IAtomContainer>();
38  
-		molecules.add(MoleculeFactory.makeAlkane(5));
39  
-		molecules.add(MoleculeFactory.makeBenzene());
40  
-		molecules.add(MoleculeFactory.makePhenylAmine());
41  
-		molecules.add(MoleculeFactory.makeCyclobutadiene());
42  
-		for(IAtomContainer ac : molecules) {
43  
-			Assert.assertFalse(atmplacer.allHeavyAtomsPlaced(ac));
44  
-		}
45  
-		for(IAtomContainer ac : molecules) {
46  
-			for(IAtom atom : ac.atoms()) {
  54
+		IAtomContainer benzene = MoleculeFactory.makeBenzene();
  55
+			for(IAtom atom : benzene.atoms()) {
47 56
 				atom.setFlag(CDKConstants.ISPLACED, true);
48 57
 			}
49  
-			Assert.assertTrue(new AtomPlacer3D().allHeavyAtomsPlaced(ac));	
  58
+		Assert.assertTrue(atmplacer.allHeavyAtomsPlaced(benzene));	
50 59
 		}
51  
-	}
52 60
 	
53 61
 	@Test
54 62
 	public void testNumberOfUnplacedHeavyAtoms_IAtomContainer() {
@@ -62,230 +70,240 @@ public void testNumberOfUnplacedHeavyAtoms_IAtomContainer() {
62 70
 	
63 71
 	@Test 
64 72
 	public void testGetPlacedHeavyAtoms_IAtomContainer_IAtom() {
65  
-		AtomPlacer3D placer = new AtomPlacer3D();
  73
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
66 74
 		IAtomContainer molecule = MoleculeFactory.makeBenzene();
67 75
 		for(int j=0; j < 3; j++) {
68 76
 			(molecule.getAtom(j)).setFlag(CDKConstants.ISPLACED, true) ;		
69 77
 	}
70  
-    IAtomContainer placed1 = placer.getPlacedHeavyAtoms(molecule, molecule.getAtom(1));
71  
-    IAtomContainer placed2 = placer.getPlacedHeavyAtoms(molecule, molecule.getAtom(2));
72  
-    IAtomContainer placed4 = placer.getPlacedHeavyAtoms(molecule, molecule.getAtom(4));
73  
-
74  
-    IAtomContainer p1 = molecule.getBuilder().newInstance(IAtomContainer.class);
75  
-    p1.addAtom(molecule.getAtom(0));
76  
-    p1.addAtom(molecule.getAtom(2));
77  
- 
78  
-    IAtomContainer p2 = molecule.getBuilder().newInstance(IAtomContainer.class);
79  
-    p2.addAtom(molecule.getAtom(1));
  78
+    IAtomContainer placedAndConnectedTo1 = atmplacer.getPlacedHeavyAtoms(molecule, molecule.getAtom(1));
  79
+    IAtomContainer placedAndConnectedTo2 = atmplacer.getPlacedHeavyAtoms(molecule, molecule.getAtom(2));
  80
+    IAtomContainer placedAndConnectedTo4 = atmplacer.getPlacedHeavyAtoms(molecule, molecule.getAtom(4));
80 81
     
81  
-    Assert.assertEquals(2, placed1.getAtomCount());
82  
-    Assert.assertEquals(1, placed2.getAtomCount());
83  
-    Assert.assertEquals(0, placed4.getAtomCount());
  82
+    Assert.assertEquals(2, placedAndConnectedTo1.getAtomCount());
  83
+    Assert.assertEquals(1, placedAndConnectedTo2.getAtomCount());
  84
+    Assert.assertEquals(0, placedAndConnectedTo4.getAtomCount());
84 85
 	
85 86
 	}
86 87
 	
87 88
 	@Test
88 89
 	public void testGetPlacedHeavyAtom_IAtomContainer_IAtom_IAtom() {
89  
-		AtomPlacer3D ap = new AtomPlacer3D();
90  
-		IAtomContainer m = MoleculeFactory.makeAlkane(7);
91  
-		for(int j =0; j< 5; j++) {
92  
-			m.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
  90
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  91
+		IAtomContainer molecule = MoleculeFactory.makeAlkane(7);
  92
+		for(int j = 0; j< 5; j++) {
  93
+			molecule.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
93 94
 		}
94  
-		IAtom c = ap.getPlacedHeavyAtom(m, m.getAtom(1), m.getAtom(0));
95  
-		IAtom d = ap.getPlacedHeavyAtom(m, m.getAtom(2), m.getAtom(1));
96  
-		IAtom e = ap.getPlacedHeavyAtom(m, m.getAtom(0), m.getAtom(1));
  95
+		IAtom atom2 = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(1), molecule.getAtom(0));
  96
+		IAtom atom3 = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(2), molecule.getAtom(1));
  97
+		IAtom nullAtom = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(0), molecule.getAtom(1));
97 98
 		
98  
-		Assert.assertEquals(c, m.getAtom(2));
99  
-		Assert.assertEquals(d, m.getAtom(3));
100  
-		Assert.assertNull(e);
  99
+		Assert.assertEquals(atom2, molecule.getAtom(2));
  100
+		Assert.assertEquals(atom3, molecule.getAtom(3));
  101
+		Assert.assertNull(nullAtom);
101 102
 	}
102 103
 	
103  
-	
104 104
 	@Test
105 105
 	public void testGetPlacedHeavyAtom_IAtomContainer_IAtom() {
106  
-		AtomPlacer3D ap = new AtomPlacer3D();
107  
-		IAtomContainer m = MoleculeFactory.makeCyclohexane();
  106
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  107
+		IAtomContainer molecule = MoleculeFactory.makeCyclohexane();
108 108
 //		for(IAtom a : m.atoms()) a.setFlag(CDKConstants.ISPLACED, true);
109  
-	    for(int i=0; i< 3; i++) m.getAtom(i).setFlag(CDKConstants.ISPLACED, true);
  109
+	    for(int i=0; i< 3; i++) {
  110
+	    	molecule.getAtom(i).setFlag(CDKConstants.ISPLACED, true);
  111
+	    }
110 112
 		
111  
-	    IAtom a = ap.getPlacedHeavyAtom(m, m.getAtom(0));
112  
-	    Assert.assertEquals(a, m.getAtom(1));
113  
-	    IAtom b = ap.getPlacedHeavyAtom(m, m.getAtom(2));
114  
-	    Assert.assertEquals(b, m.getAtom(1));
115  
-	    IAtom c = ap.getPlacedHeavyAtom(m, m.getAtom(4));
116  
-	    Assert.assertNull(c);
  113
+	    IAtom atom1 = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(0));
  114
+	    Assert.assertEquals(atom1, molecule.getAtom(1));
  115
+	    IAtom atom2 = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(2));
  116
+	    Assert.assertEquals(atom2, molecule.getAtom(1));
  117
+	    IAtom atom3 = atmplacer.getPlacedHeavyAtom(molecule, molecule.getAtom(4));
  118
+	    Assert.assertNull(atom3);
117 119
 	    
118 120
 	}
119 121
 	
120 122
 	@Test
121 123
 	public void testGeometricCenterAllPlacedAtoms_IAtomContainer() {
122  
-		AtomPlacer3D ap = new AtomPlacer3D();
123  
-		IAtomContainer m = MoleculeFactory.makeAlkane(2);
124  
-		for(IAtom a : m.atoms()) {
125  
-		 a.setFlag(CDKConstants.ISPLACED, true); 	
  124
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  125
+		IAtomContainer molecule = MoleculeFactory.makeAlkane(2);
  126
+		for(IAtom atom : molecule.atoms()) {
  127
+		 atom.setFlag(CDKConstants.ISPLACED, true); 	
126 128
 		}
127  
-		m.getAtom(0).setPoint3d(new Point3d(-1.0, 0.0, 0.0));
128  
-		m.getAtom(1).setPoint3d(new Point3d(1.0, 0.0, 0.0));
  129
+		molecule.getAtom(0).setPoint3d(new Point3d(-1.0, 0.0, 0.0));
  130
+		molecule.getAtom(1).setPoint3d(new Point3d(1.0, 0.0, 0.0));
129 131
 		
130  
-		Point3d c = ap.geometricCenterAllPlacedAtoms(m);
131  
-		Assert.assertEquals(0.0, c.x, 0.01);
132  
-		Assert.assertEquals(0.0, c.y, 0.01);
133  
-		Assert.assertEquals(0.0, c.z, 0.01);
  132
+		Point3d center = atmplacer.geometricCenterAllPlacedAtoms(molecule);
  133
+		Assert.assertEquals(0.0, center.x, 0.01);
  134
+		Assert.assertEquals(0.0, center.y, 0.01);
  135
+		Assert.assertEquals(0.0, center.z, 0.01);
134 136
 		
135 137
 	}
136 138
 	
137 139
 	@Test
138 140
 	public void testGetUnplacedRingHeavyAtom_IAtomContainer_IAtom() {
139  
-		AtomPlacer3D ap = new AtomPlacer3D();
140  
-		IAtomContainer m = MoleculeFactory.makeCyclopentane();
  141
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  142
+		IAtomContainer molecule = MoleculeFactory.makeCyclopentane();
141 143
 		
142  
-		for(IAtom a : m.atoms()) a.setFlag(CDKConstants.ISINRING, true);
  144
+		for(IAtom atom : molecule.atoms()) atom.setFlag(CDKConstants.ISINRING, true);
143 145
 		for(int j=0; j < 2; j++) {
144  
-			m.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
  146
+			molecule.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
145 147
 		}
146  
-		IAtom a1 = m.getAtom(0);
147  
-		IAtom a2 = m.getAtom(1);
148  
-		IAtom n = m.getAtom(4);
  148
+		IAtom atom0 = molecule.getAtom(0);
  149
+		IAtom atom1 = molecule.getAtom(1);
  150
+		IAtom natom = molecule.getAtom(4);
149 151
 		
150  
-		IAtom b1 = ap.getUnplacedRingHeavyAtom(m, a1);
151  
-		IAtom b2 = ap.getUnplacedRingHeavyAtom(m, a2);
152  
-		IAtom nn = ap.getUnplacedRingHeavyAtom(m, n);
  152
+		IAtom atom0pair = atmplacer.getUnplacedRingHeavyAtom(molecule, atom0);
  153
+		IAtom atom1pair = atmplacer.getUnplacedRingHeavyAtom(molecule, atom1);
  154
+		IAtom natompair = atmplacer.getUnplacedRingHeavyAtom(molecule, natom);
153 155
 		
154  
-		Assert.assertEquals(b1, m.getAtom(4));
155  
-		Assert.assertEquals(b2, m.getAtom(2));
  156
+		Assert.assertEquals(atom0pair, molecule.getAtom(4));
  157
+		Assert.assertEquals(atom1pair, molecule.getAtom(2));
  158
+		Assert.assertEquals(atom0.getFlag(CDKConstants.ISPLACED), true);
156 159
 		
157  
-		Assert.assertEquals(m.getAtom(0).getFlag(CDKConstants.ISPLACED), true);
158  
-		for(IBond b : m.bonds()) {
159  
-			if(b.getConnectedAtom(m.getAtom(4)) != null && 
160  
-					!b.getConnectedAtom(m.getAtom(4)).getFlag(CDKConstants.ISPLACED)){
161  
-				
162  
-		  nn = b.getConnectedAtom(m.getAtom(4));		
  160
+		for(IBond bond : molecule.bonds()) {
  161
+			if(bond.getConnectedAtom(molecule.getAtom(4)) != null && 
  162
+					!bond.getConnectedAtom(molecule.getAtom(4)).getFlag(CDKConstants.ISPLACED))
  163
+			{
  164
+				natompair = bond.getConnectedAtom(molecule.getAtom(4));		
163 165
 				}
164 166
 		}
165  
-		Assert.assertEquals(nn, m.getAtom(3));
  167
+		Assert.assertEquals(natompair, molecule.getAtom(3));
166 168
 	}
167 169
 	
168 170
 	@Test
169 171
 	public void testGetFarthestAtom_Point3d_IAtomContainer() {
170  
-		AtomPlacer3D ap = new AtomPlacer3D();
171  
-		IAtomContainer m = MoleculeFactory.makeBenzene();
  172
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  173
+		IAtomContainer molecule = MoleculeFactory.makeBenzene();
172 174
 		
173  
-		m.getAtom(0).setPoint3d(new Point3d(0.0, 0.0, 0.0));
174  
-		m.getAtom(1).setPoint3d(new Point3d(1.0, 1.0, 1.0));
175  
-		m.getAtom(4).setPoint3d(new Point3d(3.0, 2.0, 1.0));
176  
-		m.getAtom(5).setPoint3d(new Point3d(4.0, 4.0, 4.0));
  175
+		molecule.getAtom(0).setPoint3d(new Point3d(0.0, 0.0, 0.0));
  176
+		molecule.getAtom(1).setPoint3d(new Point3d(1.0, 1.0, 1.0));
  177
+		molecule.getAtom(4).setPoint3d(new Point3d(3.0, 2.0, 1.0));
  178
+		molecule.getAtom(5).setPoint3d(new Point3d(4.0, 4.0, 4.0));
177 179
 		
178  
-		IAtom a = ap.getFarthestAtom(m.getAtom(0).getPoint3d(), m);
179  
-		IAtom b = ap.getFarthestAtom(m.getAtom(4).getPoint3d(), m);
  180
+		IAtom farthestFromAtoma = atmplacer.getFarthestAtom(molecule.getAtom(0).getPoint3d(), molecule);
  181
+		IAtom farthestFromAtomb = atmplacer.getFarthestAtom(molecule.getAtom(4).getPoint3d(), molecule);
180 182
 		
181  
-		Assert.assertEquals(m.getAtom(5), a);
182  
-		Assert.assertEquals(m.getAtom(0), b);
  183
+		Assert.assertEquals(molecule.getAtom(5), farthestFromAtoma);
  184
+		Assert.assertEquals(molecule.getAtom(0), farthestFromAtomb);
183 185
 		
184 186
 	}
185 187
 	
186 188
 	@Test
187 189
 	public void testGetNextPlacedHeavyAtomWithUnplacedRingNeighbour_IAtomContainer() {
188  
-		AtomPlacer3D ap = new AtomPlacer3D();
189  
-		IAtomContainer m1 = MoleculeFactory.makeAlkane(3);
190  
-		IAtomContainer m2 = MoleculeFactory.makeCyclopentane();
  190
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  191
+		IAtomContainer acyclicAlkane = MoleculeFactory.makeAlkane(3);
  192
+		IAtomContainer cycloPentane = MoleculeFactory.makeCyclopentane();
191 193
 		
192 194
 		//MoleculeFactory does not set ISINRING flags for cyclic molecules 
193  
-		Assert.assertEquals(false, m2.getAtom(0).getFlag(CDKConstants.ISINRING));
194  
-		for(IAtom a : m2.atoms()) a.setFlag(CDKConstants.ISINRING, true);
  195
+		Assert.assertEquals(false, cycloPentane.getAtom(0).getFlag(CDKConstants.ISINRING));
  196
+		for(IAtom atom : cycloPentane.atoms()) {
  197
+			atom.setFlag(CDKConstants.ISINRING, true);
  198
+		}
195 199
 		
196 200
 		//acyclic molecule so null is expected		
197  
-		for(IAtom a : m1.atoms()) a.setFlag(CDKConstants.ISPLACED, true);
198  
-		Assert.assertNull(ap.getNextPlacedHeavyAtomWithUnplacedRingNeighbour(m1));
  201
+		for(IAtom atom : acyclicAlkane.atoms()) {
  202
+			atom.setFlag(CDKConstants.ISPLACED, true);
  203
+		}
  204
+		Assert.assertNull(atmplacer.getNextPlacedHeavyAtomWithUnplacedRingNeighbour(acyclicAlkane));
199 205
 	
200  
-		//this method loops on the edges this is why it does not find 0 as the
201  
-		//next atom which is placed and has an unplaced ring atom neighbour, but
202  
-		//atom number 2
203  
-		for(int j=0; j < 3; j++) m2.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
204  
-		Assert.assertEquals(m2.getAtom(2), ap.getNextPlacedHeavyAtomWithUnplacedRingNeighbour(m2));
  206
+		for(int j=0; j < 3; j++) {
  207
+			cycloPentane.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
  208
+		}
  209
+		Assert.assertEquals(cycloPentane.getAtom(2), atmplacer.getNextPlacedHeavyAtomWithUnplacedRingNeighbour(cycloPentane));
205 210
 				
206  
-		
207 211
 	}
208 212
 	
209 213
 	@Test
210 214
 	public void testGetNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour_IAtomContainer() {
211  
-		AtomPlacer3D ap = new AtomPlacer3D();
212  
-		IAtomContainer m1 = MoleculeFactory.makeBenzene();
213  
-		IAtomContainer m2 = MoleculeFactory.makeAlkane(5);
  215
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  216
+		IAtomContainer benzene = MoleculeFactory.makeBenzene();
  217
+		IAtomContainer acyclicAlkane = MoleculeFactory.makeAlkane(5);
214 218
 		
215  
-		for(IAtom a : m1.atoms()) a.setFlag(CDKConstants.ISINRING, true);
216  
-		for(IAtom a : m2.atoms() ) a.setFlag(CDKConstants.ISALIPHATIC, true);		
  219
+		for(IAtom atom : benzene.atoms()) atom.setFlag(CDKConstants.ISINRING, true);
  220
+		for(IAtom atom : acyclicAlkane.atoms()) atom.setFlag(CDKConstants.ISALIPHATIC, true);		
217 221
 		
218  
-		for(int j=0; j< 3; j++) m1.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
219  
-		IAtom searchedatom1 = ap.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(m1);
  222
+		for(int j=0; j< 3; j++) benzene.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
  223
+		IAtom searchedatom1 = atmplacer.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(benzene);
220 224
 		Assert.assertNull(searchedatom1);
221 225
 		
222  
-		for(IAtom a : m1.atoms()) {
223  
-			if(!a.getFlag(CDKConstants.ISPLACED)) a.setFlag(CDKConstants.ISPLACED, true);
  226
+		for(IAtom atom : benzene.atoms()) {
  227
+			if(!atom.getFlag(CDKConstants.ISPLACED)) {
  228
+				atom.setFlag(CDKConstants.ISPLACED, true);
  229
+			}
224 230
 		}
225  
-		IAtom searchedatom2 = ap.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(m1);
  231
+		IAtom searchedatom2 = atmplacer.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(benzene);
226 232
 		Assert.assertNull(searchedatom2);
227 233
 		
228  
-		for(int k=0; k < 3; k++) m2.getAtom(k).setFlag(CDKConstants.ISPLACED, true);
229  
-		IAtom a = ap.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(m2);
230  
-		Assert.assertEquals(m2.getAtom(2), a);
231  
-		
  234
+		for(int k=0; k < 3; k++) {
  235
+			acyclicAlkane.getAtom(k).setFlag(CDKConstants.ISPLACED, true);
  236
+		}
  237
+		IAtom nextAtom = atmplacer.getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(acyclicAlkane);
  238
+		Assert.assertEquals(acyclicAlkane.getAtom(2), nextAtom);
232 239
 		
233 240
 	}
234 241
 	
235 242
 	@Test
236 243
 	public void testGetNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour_IAtomContainer() {
237  
-		AtomPlacer3D ap = new AtomPlacer3D();
238  
-		IAtomContainer m1 = MoleculeFactory.makeCyclobutane();
239  
-		IAtomContainer m2 = MoleculeFactory.makeAlkane(6);
  244
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  245
+		IAtomContainer cyclobutane = MoleculeFactory.makeCyclobutane();
  246
+		IAtomContainer acyclicAlkane = MoleculeFactory.makeAlkane(6);
240 247
 		
241  
-		for(IAtom a : m1.atoms()) a.setFlag(CDKConstants.ISINRING, true);
242  
-		for(IAtom a : m2.atoms()) a.setFlag(CDKConstants.ISALIPHATIC, true);
243  
-				
244  
-	    for(int j=0; j < 3; j++) m1.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
245  
-	    IAtom s1 = ap.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(m1);
246  
-	    Assert.assertNull(s1);
  248
+		for(IAtom atom : cyclobutane.atoms()) {
  249
+			atom.setFlag(CDKConstants.ISINRING, true);
  250
+		}
  251
+		for(IAtom atom : acyclicAlkane.atoms()) {
  252
+			atom.setFlag(CDKConstants.ISALIPHATIC, true);
  253
+		}
  254
+	    for(int j=0; j < 3; j++) {
  255
+	    	cyclobutane.getAtom(j).setFlag(CDKConstants.ISPLACED, true);
  256
+	    }
  257
+	    IAtom nextHeavyAtom = atmplacer.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(cyclobutane);
  258
+	    Assert.assertNull(nextHeavyAtom);
247 259
 	    
248  
-	    for(IAtom a : m1.atoms()) {
249  
-			if(!a.getFlag(CDKConstants.ISPLACED)) a.setFlag(CDKConstants.ISPLACED, true);
  260
+	    for(IAtom atom : cyclobutane.atoms()) {
  261
+			if(!atom.getFlag(CDKConstants.ISPLACED)) {
  262
+				atom.setFlag(CDKConstants.ISPLACED, true);
  263
+			}
250 264
 		}
251  
-		IAtom s2 = ap.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(m1);
252  
-		Assert.assertNull(s2);
  265
+		IAtom nextHeavyAtom2 = atmplacer.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(cyclobutane);
  266
+		Assert.assertNull(nextHeavyAtom2);
253 267
 		
254  
-		for(int k=0; k < 3; k++) m2.getAtom(k).setFlag(CDKConstants.ISPLACED, true);
255  
-		IAtom a = ap.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(m2);
256  
-		Assert.assertEquals(m2.getAtom(3), a);
  268
+		for(int k=0; k < 3; k++) {
  269
+			acyclicAlkane.getAtom(k).setFlag(CDKConstants.ISPLACED, true);
  270
+		}
  271
+		IAtom nextSuchUnPlacedHeavyAtom = atmplacer.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(acyclicAlkane);
  272
+		Assert.assertEquals(acyclicAlkane.getAtom(3), nextSuchUnPlacedHeavyAtom);
257 273
 	    
258  
-		for(IAtom atom : m2.atoms()) atom.setFlag(CDKConstants.ISPLACED, true);
259  
-	    IAtom s3 = ap.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(m2);
260  
-		Assert.assertNull(s3);
  274
+		for(IAtom atom : acyclicAlkane.atoms()) {
  275
+			atom.setFlag(CDKConstants.ISPLACED, true);
  276
+		}
  277
+	    nextSuchUnPlacedHeavyAtom = atmplacer.getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(acyclicAlkane);
  278
+		Assert.assertNull(nextSuchUnPlacedHeavyAtom);
261 279
 	}
262 280
 	
263 281
 	@Test
264 282
 	public void testGetAngleValue_String_String_String() throws Exception {
265  
-	SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
266  
-	String smiles = "CCCCCC";
267  
-	IAtomContainer molecule = sp.parseSmiles(smiles);
268  
-	Assert.assertNotNull(molecule);
269  
-	ForceFieldConfigurator ffc= new ForceFieldConfigurator();
270  
-	ffc.setForceFieldConfigurator("mmff94");
271  
-	AtomPlacer3D atomPlacer3d= new AtomPlacer3D();
272  
-	atomPlacer3d.initilize(ffc.getParameterSet());
273  
-	ffc.assignAtomTyps(molecule);
274  
-	
275  
-	String id1 = molecule.getAtom(1).getAtomTypeName();
276  
-	String id2 = molecule.getAtom(2).getAtomTypeName();
277  
-	String id3 = molecule.getAtom(3).getAtomTypeName();
278  
-	
279  
-	double anglev = atomPlacer3d.getAngleValue(id1, id2, id3);
280  
-	Assert.assertTrue(anglev==109.608);
281  
-	
  283
+		SmilesParser parser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  284
+		String smiles = "CCCCCC";
  285
+		IAtomContainer molecule = parser.parseSmiles(smiles);
  286
+		Assert.assertNotNull(molecule);
  287
+		ForceFieldConfigurator ffc= new ForceFieldConfigurator();
  288
+		ffc.setForceFieldConfigurator("mmff94");
  289
+		AtomPlacer3D atomPlacer3d= new AtomPlacer3D();
  290
+		atomPlacer3d.initilize(ffc.getParameterSet());
  291
+		ffc.assignAtomTyps(molecule);
  292
+		
  293
+		String id1 = molecule.getAtom(1).getAtomTypeName();
  294
+		String id2 = molecule.getAtom(2).getAtomTypeName();
  295
+		String id3 = molecule.getAtom(3).getAtomTypeName();
  296
+		
  297
+		double anglev = atomPlacer3d.getAngleValue(id1, id2, id3);
  298
+		Assert.assertEquals(109.608, anglev, 0.001);
  299
+		
282 300
 	}
283 301
 	
284 302
 	@Test
285 303
 	public void testGetBondLengthValue_String_String() throws Exception {
286  
-		SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  304
+		SmilesParser parser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
287 305
 		String smiles = "CCCCCC";
288  
-		IAtomContainer molecule = sp.parseSmiles(smiles);
  306
+		IAtomContainer molecule = parser.parseSmiles(smiles);
289 307
 		Assert.assertNotNull(molecule);
290 308
 		ForceFieldConfigurator ffc= new ForceFieldConfigurator();
291 309
 		ffc.setForceFieldConfigurator("mmff94");
@@ -301,35 +319,37 @@ public void testGetBondLengthValue_String_String() throws Exception {
301 319
 		Assert.assertNotSame(mmff94id2, id2);
302 320
 		
303 321
 		double bondlength = atomPlacer3d.getBondLengthValue(id1, id2);
304  
-		Assert.assertTrue(bondlength==1.508);
  322
+		Assert.assertEquals(1.508, bondlength, 0.001);
305 323
 	}
306 324
 	
307 325
 	@Test 
308 326
 	public void testMarkPlaced_IAtomContainer()  {
309  
-		AtomPlacer3D ap = new AtomPlacer3D();
310  
-		IAtomContainer m = MoleculeFactory.makeAlkane(5);
311  
-		IAtomContainer pm = ap.markPlaced(m);
312  
-		for(IAtom a : pm.atoms()) Assert.assertTrue(a.getFlag(CDKConstants.ISPLACED));		
  327
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
  328
+		IAtomContainer molecule = MoleculeFactory.makeAlkane(5);
  329
+		IAtomContainer placedMolecule = atmplacer.markPlaced(molecule);
  330
+		for(IAtom atom : placedMolecule.atoms()) {
  331
+			Assert.assertTrue(atom.getFlag(CDKConstants.ISPLACED));		
  332
+		}
313 333
 	}
314 334
 	
315 335
 	@Test
316 336
 	public void testZmatrixChainToCartesian_IAtomContainer_boolean() throws CDKException {
317  
-		AtomPlacer3D ap = new AtomPlacer3D();
  337
+		AtomPlacer3D atmplacer = new AtomPlacer3D();
318 338
 	    ForceFieldConfigurator ffc= new ForceFieldConfigurator();
319 339
 	    ffc.setForceFieldConfigurator("mmff92");
320  
-		SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
321  
-		String s1 = "CCCCCCCCCCCCCCCCCC";
322  
-		String s2 = "CCCCCC(CCCC)CCCC";
323  
-		IAtomContainer m1 = sp.parseSmiles(s1);
324  
-		IAtomContainer m2 = sp.parseSmiles(s2);
325  
-		ffc.assignAtomTyps(m1);
326  
-		ffc.assignAtomTyps(m2);
327  
-		ap.placeAliphaticHeavyChain(m1, m1);
328  
-		ap.placeAliphaticHeavyChain(m2, m2);
329  
-		ap.zmatrixChainToCartesian(m1, false);
330  
-		ap.zmatrixChainToCartesian(m2, true);
331  
-	    ModelBuilder3DTest.checkAverageBondLength(m1);
332  
-	    ModelBuilder3DTest.checkAverageBondLength(m2);
  340
+		SmilesParser parser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  341
+		String smiles1 = "CCCCCCCCCCCCCCCCCC";
  342
+		String smiles2 = "CCCCCC(CCCC)CCCC";
  343
+		IAtomContainer notBranchedAlkane = parser.parseSmiles(smiles1);
  344
+		IAtomContainer branchedAlkane = parser.parseSmiles(smiles2);
  345
+		ffc.assignAtomTyps(notBranchedAlkane);
  346
+		ffc.assignAtomTyps(branchedAlkane);
  347
+		atmplacer.placeAliphaticHeavyChain(branchedAlkane, branchedAlkane);
  348
+		atmplacer.placeAliphaticHeavyChain(notBranchedAlkane, notBranchedAlkane);
  349
+		atmplacer.zmatrixChainToCartesian(notBranchedAlkane, false);
  350
+		atmplacer.zmatrixChainToCartesian(branchedAlkane, true);
  351
+	    ModelBuilder3DTest.checkAverageBondLength(notBranchedAlkane);
  352
+	    ModelBuilder3DTest.checkAverageBondLength(branchedAlkane);
333 353
 	}
334 354
 	
335 355
 	

0 notes on commit ea2b55e

Please sign in to comment.
Something went wrong with that request. Please try again.