File: WrapperTests.java

package info (click to toggle)
rdkit 202503.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 222,024 kB
  • sloc: cpp: 411,111; python: 78,482; ansic: 26,181; java: 8,285; javascript: 4,404; sql: 2,393; yacc: 1,626; lex: 1,267; cs: 1,090; makefile: 580; xml: 229; fortran: 183; sh: 121
file content (388 lines) | stat: -rw-r--r-- 12,435 bytes parent folder | download | duplicates (2)
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
/* 
 * $Id: WrapperTests.java 131 2011-01-20 22:01:29Z ebakke $
 *
 *  Copyright (c) 2010, Novartis Institutes for BioMedical Research Inc.
 *  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: 
 *
 *     * Redistributions of source code must retain the above copyright 
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following 
 *       disclaimer in the documentation and/or other materials provided 
 *       with the distribution.
 *     * Neither the name of Novartis Institutes for BioMedical Research Inc. 
 *       nor the names of its contributors may be used to endorse or promote 
 *       products derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package org.RDKit;

import static org.junit.Assert.*;
import java.io.*;
import java.io.File;
import java.util.ArrayList;

import org.junit.*;


public class WrapperTests extends GraphMolTest {

	private ArrayList<String> tmpFiles = new ArrayList<String>();

	@After
	public void tearDown() {
		for (String fn : tmpFiles) {
			new File(fn).delete();
		}
	}
	@Test 
    public void testBasicInstantiation_Conformer() {
        Conformer conformer = new Conformer();
        assertNotNull(conformer);
    }
    @Test 
    public void testBasicInstantiation_QueryAtom() {
	QueryAtom queryAtom = new QueryAtom();
        assertNotNull(queryAtom);
    }
    @Test
    public void testBasicInstantiation_QueryBond() {
	QueryBond queryBond = new QueryBond();
        assertNotNull(queryBond);
    }
    @Test
    public void testBasicInstantiation_QueryOps() {
        // Comes from QueryOps.cpp
        RecursiveStructureQuery rsQuery = new RecursiveStructureQuery();
        assertNotNull(rsQuery);

        AtomRingQuery arQuery = new AtomRingQuery();
        assertNotNull(arQuery);
    }
    @Test 
    public void testBasicInstantiation_Atom() {
	Atom atom = new Atom();
	assertNotNull(atom);
    }
    @Test 
    public void testBasicInstantiation_ROMol() {
	ROMol roMol = new ROMol();
	assertNotNull(roMol);
    }
    @Test 
    public void testBasicInstantiation_Bond() {
	Bond bond = new Bond();
	assertNotNull(bond);
    }
    @Test 
    public void testBasicInstantiation_MolStackElem() {
	// Came from Canon.cpp
	MolStackElem molStack = new MolStackElem(1);
	assertNotNull(molStack);
    }
    @Test 
    public void testBasicInstantiation_RWMol() {
	RWMol rwMol = new RWMol();
	assertNotNull(rwMol);
    }
    @Test
    public void testBasicInstantiation_PeriodicTable() {
        assertNotNull(PeriodicTable.getTable());
    }
    @Test
    public void testBasicInstantiation_MolSanitizeException() {
        MolSanitizeException sanit = new MolSanitizeException("some error message");
        assertNotNull(sanit);
    }
    @Test
    public void testBasicInstantiation_SmilesParseException() {
        SmilesParseException parse = new SmilesParseException("some error message");
        assertNotNull(parse);
    }
    @Test
    public void testBasicInstantiation_RingInfo() {
        RingInfo rInfo = new RingInfo();
        assertNotNull(rInfo);
    }
    @Test
    public void testBasicInstantiation_ChemicalReaction() {
        ChemicalReaction reaction = new ChemicalReaction();
        assertNotNull(reaction);
    }
       
    @Test
    public void testBasicInstantiation_BondIterator() {
       	ROMol m = RWMol.MolFromSmiles("CS");
    	BondIterator bonditer = new BondIterator(m);
        assertNotNull(bonditer);
    }
    @Test
    public void testBasicInstantiation_ConstBondIterator() {
       	ROMol m = RWMol.MolFromSmiles("CS");
    	ConstBondIterator bonditer = new ConstBondIterator(m);
        assertNotNull(bonditer);
    }
    @Test
    public void testBasicInstantiation_AtomIterator() {
       	ROMol m = RWMol.MolFromSmiles("CS");
        AtomIterator atomiter = new AtomIterator(m);
        assertNotNull(atomiter);
    }
    @Test
    public void testBasicInstantiation_HeteroatomIterator() {
    	ROMol m = RWMol.MolFromSmiles("CS");
    	HeteroatomIterator atomiter = new HeteroatomIterator(m);
        assertNotNull(atomiter);
    }
    @Test
    public void testBasicInstantiation_QueryAtomIterator() {
       	ROMol m = RWMol.MolFromSmiles("CS");
    	QueryAtomIterator atomiter = new QueryAtomIterator(m, new QueryAtom(6));
        assertNotNull(atomiter);
    }
    @Test
    public void testBasicInstantiation_AromaticAtomIterator() {
       	ROMol m = RWMol.MolFromSmiles("Cc1ccccc1");
    	AromaticAtomIterator atomiter = new AromaticAtomIterator(m);
        assertNotNull(atomiter);
    }
    @Test
    public void testBasicInstantiation_SDMolSupplier() {
        SDMolSupplier sup = new SDMolSupplier();
        assertNotNull(sup);
    }
    @Test
    public void testBasicInstantiation_ForwardSDMolSupplier() {
    	ForwardSDMolSupplier sup = new ForwardSDMolSupplier();
        assertNotNull(sup);
    }
    @Test
    public void testBasicInstantiation_SmilesMolSupplier() {
        SmilesMolSupplier sup = new SmilesMolSupplier();
        assertNotNull(sup);
    }
    @Test
    public void testBasicInstantiation_TDTMolSupplier() {
        TDTMolSupplier sup = new TDTMolSupplier();
        assertNotNull(sup);
    }

    @Test
    public void testBasicInstantiation_ResonanceMolSupplier() {
       	ROMol m = RWMol.MolFromSmiles("CC(=O)[O-]");
        ResonanceMolSupplier sup = new ResonanceMolSupplier(m);
        assertNotNull(sup);
    }

    @Test
    public void testBasicInstantiation_SDMWriter() {
        SDWriter mw = new SDWriter("tmp.sdf");
        mw.close();
        tmpFiles.add("tmp.sdf");
        assertNotNull(mw);
    }

    @Test
    public void testBasicInstantiation_TDTWriter() {
        TDTWriter mw = new TDTWriter("tmp.tdt");
        mw.close();
        tmpFiles.add("tmp.tdt");
        assertNotNull(mw);
    }
    @Test
    public void testBasicInstantiation_SmilesWriter() {
        SmilesWriter mw = new SmilesWriter("tmp.smi");
        mw.close();
        tmpFiles.add("tmp.smi");
        assertNotNull(mw);
    }
    @Test
    public void testBasicInstantiation_Transform2D() {
        Transform2D tr = new Transform2D();
        assertNotNull(tr);
    }
    @Test
    public void testBasicInstantiation_Transform3D() {
        Transform3D tr = new Transform3D();
        assertNotNull(tr);
    }

    //Tests for Exception#getMessage() wrapping
    private static final String TEST_MESSAGE = "test message";

    @Test
    public void testChemicalReactionException() {
        final ChemicalReactionException e =
                new ChemicalReactionException(TEST_MESSAGE);
        assertEquals(TEST_MESSAGE, e.getMessage());

    }

    @Test
    public void testChemicalReactionParserException() {
        final ChemicalReactionParserException e =
                new ChemicalReactionParserException(TEST_MESSAGE);
        assertEquals(TEST_MESSAGE, e.getMessage());

    }

    @Test
    public void testConformerException() {
        ROMol mol = null;
        try {
            mol = RWMol.MolFromSmiles("c1ccccc1");
            mol.getConformer();
        } catch (ConformerException e) {
            assertEquals("No conformations available on the molecule",
                    e.getMessage());
        } finally {
            if (mol != null) {
                mol.delete();
            }
        }

    }

    @Test
    public void testMolPicklerException() {
        final MolPicklerException e = new MolPicklerException(TEST_MESSAGE);
        assertEquals(TEST_MESSAGE, e.getMessage());

    }

    @Test
    public void testMolSanitizeException() {
        RWMol mol = null;
        try {
            mol = RWMol.MolFromSmiles("c1cccc1");
            mol.sanitizeMol();
        } catch (MolSanitizeException e) {
            assertEquals("Can't kekulize mol.  Unkekulized atoms: 0 1 2 3 4",
                    e.getMessage());
        } finally {
            if (mol != null) {
                mol.delete();
            }
        }
    }

    @Test
    public void testSmilesParseException() {
        SmilesParseException e = new SmilesParseException(TEST_MESSAGE);
        assertEquals(TEST_MESSAGE, e.getMessage());
    }

    @Test
    public void testGenericRDKitException() {
        final GenericRDKitException e =
                new GenericRDKitException(TEST_MESSAGE);
        assertEquals(TEST_MESSAGE, e.getMessage());

    }

    @Test
    public void testAtomSanitizeException() {
        final AtomSanitizeException e =
                new AtomSanitizeException(TEST_MESSAGE, 1L);
        assertEquals(TEST_MESSAGE, e.getMessage());

    }

    @Test
    public void testAtomValenceException() {
        final AtomValenceException e =
                new AtomValenceException(TEST_MESSAGE, 1L);
        assertEquals(TEST_MESSAGE, e.getMessage());
    }

    @Test
    public void testAtomKekulizeException() {
        final AtomKekulizeException e =
                new AtomKekulizeException(TEST_MESSAGE, 1L);
        assertEquals(TEST_MESSAGE, e.getMessage());
    }

    @Test
    public void testKekulizeException() {
        final UInt_Vect uInt_Vect = new UInt_Vect();
        uInt_Vect.add(1L);
        final KekulizeException e =
                new KekulizeException(TEST_MESSAGE, uInt_Vect);
        assertEquals(TEST_MESSAGE, e.getMessage());
        uInt_Vect.delete();
        e.delete();
    }

    @Test
    public void cdxmlReader() {
	String rdpath = System.getenv("RDBASE");
	if (rdpath == null)
	    org.junit.Assert.fail("No definition for RDBASE");
	File base = new File(rdpath);
	File testFile = new File(base, "Code" + File.separator + "GraphMol"
				 + File.separator + "test_data" + File.separator +
				 "CDXML" + File.separator + "beta-cypermethrin.cdxml");
	String fn = testFile.getAbsolutePath();
	RWMol_Vect prods = RWMol.MolsFromCDXMLFile(fn);
	assertEquals(prods.size(), 1);
	for(int idx = 0; idx < prods.size(); idx++) {
	    if(idx == 0) {
            System.out.print(prods.get(idx).MolToSmiles(true));
            System.out.print("\n");
		assertEquals(prods.get(idx).MolToSmiles(true), "CC1(C)[C@H](C=C(Cl)Cl)[C@H]1C(=O)O[C@@H](C#N)c1cccc(Oc2ccccc2)c1");
	    }
	}
	CDXMLParserParams params = new CDXMLParserParams();
	prods = RWMol.MolsFromCDXMLFile(fn, params);
	assertEquals(prods.size(), 1);
	for(int idx = 0; idx < prods.size(); idx++) {
	    if(idx == 0) {
            System.out.print(prods.get(idx).MolToSmiles(true));
            System.out.print("\n");
		assertEquals(prods.get(idx).MolToSmiles(true), "CC1(C)[C@H](C=C(Cl)Cl)[C@H]1C(=O)O[C@@H](C#N)c1cccc(Oc2ccccc2)c1");
	    }
	}

	testFile = new File(base, "Code" + File.separator + "GraphMol"
				 + File.separator + "test_data" + File.separator +
				 "CDXML" + File.separator + "ring-stereo1.cdx");
	fn = testFile.getAbsolutePath();
	params = new CDXMLParserParams(true, true, CDXMLFormat.CDX);
	prods = RWMol.MolsFromCDXMLFile(fn, params);
	assertEquals(prods.size(), 1);

	params = new CDXMLParserParams(true, true, CDXMLFormat.Auto);
	prods = RWMol.MolsFromCDXMLFile(fn, params);
	assertEquals(prods.size(), 1);

	params = new CDXMLParserParams(true, true, CDXMLFormat.CDXML);
	boolean e = false;
	try {
	    prods = RWMol.MolsFromCDXMLFile(fn, params);
	} catch(GenericRDKitException ex) {
	    e = true;
	}
	assertEquals(true, e);
	
    }    
    public static void main(String args[]) {
      org.junit.runner.JUnitCore.main("org.RDKit.WrapperTests");
    }
}