-
Notifications
You must be signed in to change notification settings - Fork 154
/
InChIGeneratorTest.java
994 lines (898 loc) · 39.7 KB
/
InChIGeneratorTest.java
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/* Copyright (C) 2006-2007 Sam Adams <sea36@users.sf.net>
* 2010,2012 Egon Willighagen <egonw@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.inchi;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
import net.sf.jniinchi.INCHI_OPTION;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Bond;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.SingleElectron;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IDoubleBondStereochemistry;
import org.openscience.cdk.interfaces.IStereoElement;
import org.openscience.cdk.interfaces.ITetrahedralChirality;
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
import org.openscience.cdk.io.MDLV2000Reader;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesGenerator;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.stereo.DoubleBondStereochemistry;
import org.openscience.cdk.stereo.ExtendedTetrahedral;
import org.openscience.cdk.stereo.TetrahedralChirality;
import net.sf.jniinchi.INCHI_RET;
/**
* TestCase for the InChIGenerator.
*
* @cdk.module test-inchi
*
* @see org.openscience.cdk.inchi.InChIGenerator
*/
public class InChIGeneratorTest extends CDKTestCase {
protected static InChIGeneratorFactory factory;
protected InChIGeneratorFactory getFactory() throws Exception {
if (factory == null) {
factory = InChIGeneratorFactory.getInstance();
}
return (factory);
}
/**
* Tests element name is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromChlorineAtom() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("ClH"));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
}
@Test
public void testGetLog() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertNotNull(gen.getLog());
}
@Test
public void testGetAuxInfo() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(3);
a2.setImplicitHydrogenCount(3);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.SINGLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "");
Assert.assertNotNull(gen.getAuxInfo());
Assert.assertTrue(gen.getAuxInfo().startsWith("AuxInfo="));
}
@Test
public void testGetMessage() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(
"Because this generation should work, I expected an empty message String.",
"", gen.getMessage());
}
@Test
public void testGetWarningMessage() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("Cl"));
ac.addAtom(new Atom("H"));
ac.addBond(0, 1, Order.TRIPLE);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertNotNull(gen.getMessage());
Assert.assertTrue(gen.getMessage().contains("Accepted unusual valence"));
}
/**
* Tests charge is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromLithiumIon() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Li");
a.setFormalCharge(+1);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/Li/q+1", gen.getInchi());
}
/**
* Tests isotopic mass is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromChlorine37Atom() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("ClH");
a.setMassNumber(37);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H/i1+2", gen.getInchi());
}
/**
* Tests implicit hydrogen count is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromHydrogenChlorideImplicitH() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/ClH/h1H", gen.getInchi());
}
/**
* Tests radical state is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromMethylRadical() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("C");
a.setImplicitHydrogenCount(3);
ac.addAtom(a);
ac.addSingleElectron(new SingleElectron(a));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/CH3/h1H3", gen.getInchi());
}
/**
* Tests single bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromEthane() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(3);
a2.setImplicitHydrogenCount(3);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.SINGLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H6/c1-2/h1-2H3", gen.getInchi());
Assert.assertEquals("OTMSDBZUPAUEDD-UHFFFAOYNA-N", gen.getInchiKey());
}
/**
* Test generation of non-standard InChIs.
*
* @throws Exception
* @cdk.bug 1384
* @see <a href="https://sourceforge.net/p/cdk/bugs/1384/">BUG:1384</a>
*/
@Test
public void nonStandardInChIWithEnumOptions() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(3);
a2.setImplicitHydrogenCount(3);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.SINGLE));
List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
options.add(INCHI_OPTION.FixedH);
options.add(INCHI_OPTION.SAbs);
options.add(INCHI_OPTION.SAsXYZ);
options.add(INCHI_OPTION.SPXYZ);
options.add(INCHI_OPTION.FixSp3Bug);
options.add(INCHI_OPTION.AuxNone);
InChIGenerator gen = getFactory().getInChIGenerator(ac, options);
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H6/c1-2/h1-2H3", gen.getInchi());
Assert.assertEquals("OTMSDBZUPAUEDD-UHFFFAOYNA-N", gen.getInchiKey());
}
/**
* Tests double bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromEthene() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(2);
a2.setImplicitHydrogenCount(2);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.DOUBLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H4/c1-2/h1-2H2", gen.getInchi());
}
/**
* Tests triple bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromEthyne() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(1);
a2.setImplicitHydrogenCount(1);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.TRIPLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac, "FixedH");
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H2/c1-2/h1-2H", gen.getInchi());
}
/**
* Tests 2D coordinates are correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiEandZ12Dichloroethene2D() throws Exception {
// (E)-1,2-dichloroethene
IAtomContainer acE = new AtomContainer();
IAtom a1E = new Atom("C", new Point2d(2.866, -0.250));
IAtom a2E = new Atom("C", new Point2d(3.732, 0.250));
IAtom a3E = new Atom("Cl", new Point2d(2.000, 2.500));
IAtom a4E = new Atom("Cl", new Point2d(4.598, -0.250));
a1E.setImplicitHydrogenCount(1);
a2E.setImplicitHydrogenCount(1);
acE.addAtom(a1E);
acE.addAtom(a2E);
acE.addAtom(a3E);
acE.addAtom(a4E);
acE.addBond(new Bond(a1E, a2E, Order.DOUBLE));
acE.addBond(new Bond(a1E, a3E, Order.SINGLE));
acE.addBond(new Bond(a2E, a4E, Order.SINGLE));
InChIGenerator genE = getFactory().getInChIGenerator(acE, "FixedH");
Assert.assertEquals(genE.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+", genE.getInchi());
// (Z)-1,2-dichloroethene
IAtomContainer acZ = new AtomContainer();
IAtom a1Z = new Atom("C", new Point2d(2.866, -0.440));
IAtom a2Z = new Atom("C", new Point2d(3.732, 0.060));
IAtom a3Z = new Atom("Cl", new Point2d(2.000, 0.060));
IAtom a4Z = new Atom("Cl", new Point2d(3.732, 1.060));
a1Z.setImplicitHydrogenCount(1);
a2Z.setImplicitHydrogenCount(1);
acZ.addAtom(a1Z);
acZ.addAtom(a2Z);
acZ.addAtom(a3Z);
acZ.addAtom(a4Z);
acZ.addBond(new Bond(a1Z, a2Z, Order.DOUBLE));
acZ.addBond(new Bond(a1Z, a3Z, Order.SINGLE));
acZ.addBond(new Bond(a2Z, a4Z, Order.SINGLE));
InChIGenerator genZ = getFactory().getInChIGenerator(acZ, "FixedH");
Assert.assertEquals(genZ.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C2H2Cl2/c3-1-2-4/h1-2H/b2-1-", genZ.getInchi());
}
/**
* Tests 3D coordinates are correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetInchiFromLandDAlanine3D() throws Exception {
// L-Alanine
IAtomContainer acL = new AtomContainer();
IAtom a1L = new Atom("C", new Point3d(-0.358, 0.819, 20.655));
IAtom a2L = new Atom("C", new Point3d(-1.598, -0.032, 20.905));
IAtom a3L = new Atom("N", new Point3d(-0.275, 2.014, 21.574));
IAtom a4L = new Atom("C", new Point3d(0.952, 0.043, 20.838));
IAtom a5L = new Atom("O", new Point3d(-2.678, 0.479, 21.093));
IAtom a6L = new Atom("O", new Point3d(-1.596, -1.239, 20.958));
a1L.setImplicitHydrogenCount(1);
a3L.setImplicitHydrogenCount(2);
a4L.setImplicitHydrogenCount(3);
a5L.setImplicitHydrogenCount(1);
acL.addAtom(a1L);
acL.addAtom(a2L);
acL.addAtom(a3L);
acL.addAtom(a4L);
acL.addAtom(a5L);
acL.addAtom(a6L);
acL.addBond(new Bond(a1L, a2L, Order.SINGLE));
acL.addBond(new Bond(a1L, a3L, Order.SINGLE));
acL.addBond(new Bond(a1L, a4L, Order.SINGLE));
acL.addBond(new Bond(a2L, a5L, Order.SINGLE));
acL.addBond(new Bond(a2L, a6L, Order.DOUBLE));
InChIGenerator genL = getFactory().getInChIGenerator(acL, "FixedH");
Assert.assertEquals(genL.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1/f/h5H", genL.getInchi());
// D-Alanine
IAtomContainer acD = new AtomContainer();
IAtom a1D = new Atom("C", new Point3d(0.358, 0.819, 20.655));
IAtom a2D = new Atom("C", new Point3d(1.598, -0.032, 20.905));
IAtom a3D = new Atom("N", new Point3d(0.275, 2.014, 21.574));
IAtom a4D = new Atom("C", new Point3d(-0.952, 0.043, 20.838));
IAtom a5D = new Atom("O", new Point3d(2.678, 0.479, 21.093));
IAtom a6D = new Atom("O", new Point3d(1.596, -1.239, 20.958));
a1D.setImplicitHydrogenCount(1);
a3D.setImplicitHydrogenCount(2);
a4D.setImplicitHydrogenCount(3);
a5D.setImplicitHydrogenCount(1);
acD.addAtom(a1D);
acD.addAtom(a2D);
acD.addAtom(a3D);
acD.addAtom(a4D);
acD.addAtom(a5D);
acD.addAtom(a6D);
acD.addBond(new Bond(a1D, a2D, Order.SINGLE));
acD.addBond(new Bond(a1D, a3D, Order.SINGLE));
acD.addBond(new Bond(a1D, a4D, Order.SINGLE));
acD.addBond(new Bond(a2D, a5D, Order.SINGLE));
acD.addBond(new Bond(a2D, a6D, Order.DOUBLE));
InChIGenerator genD = getFactory().getInChIGenerator(acD, "FixedH");
Assert.assertEquals(genD.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m1/s1/f/h5H", genD.getInchi());
}
// ensure only
@Test
public void zeroHydrogenCount() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("O"));
ac.getAtom(0).setImplicitHydrogenCount(0);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/O", gen.getInchi());
}
/**
* Tests element name is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromChlorineAtom() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("ClH"));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
}
/**
* Tests charge is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromLithiumIon() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Li");
a.setFormalCharge(+1);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/Li/q+1", gen.getInchi());
}
/**
* Tests isotopic mass is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromChlorine37Atom() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("ClH");
a.setMassNumber(37);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/ClH/h1H/i1+2", gen.getInchi());
}
/**
* Tests implicit hydrogen count is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromHydrogenChlorideImplicitH() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("Cl");
a.setImplicitHydrogenCount(1);
ac.addAtom(a);
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(gen.getReturnStatus(), INCHI_RET.OKAY);
Assert.assertEquals("InChI=1S/ClH/h1H", gen.getInchi());
}
/**
* Tests radical state is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromMethylRadical() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a = new Atom("C");
a.setImplicitHydrogenCount(3);
ac.addAtom(a);
ac.addSingleElectron(new SingleElectron(a));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/CH3/h1H3", gen.getInchi());
}
/**
* Tests single bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromEthane() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(3);
a2.setImplicitHydrogenCount(3);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.SINGLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H6/c1-2/h1-2H3", gen.getInchi());
Assert.assertEquals("OTMSDBZUPAUEDD-UHFFFAOYSA-N", gen.getInchiKey());
}
/**
* Tests double bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromEthene() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(2);
a2.setImplicitHydrogenCount(2);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.DOUBLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H4/c1-2/h1-2H2", gen.getInchi());
}
/**
* Tests triple bond is correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromEthyne() throws Exception {
IAtomContainer ac = new AtomContainer();
IAtom a1 = new Atom("C");
IAtom a2 = new Atom("C");
a1.setImplicitHydrogenCount(1);
a2.setImplicitHydrogenCount(1);
ac.addAtom(a1);
ac.addAtom(a2);
ac.addBond(new Bond(a1, a2, Order.TRIPLE));
InChIGenerator gen = getFactory().getInChIGenerator(ac);
Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H2/c1-2/h1-2H", gen.getInchi());
}
/**
* Tests 2D coordinates are correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiEandZ12Dichloroethene2D() throws Exception {
// (E)-1,2-dichloroethene
IAtomContainer acE = new AtomContainer();
IAtom a1E = new Atom("C", new Point2d(2.866, -0.250));
IAtom a2E = new Atom("C", new Point2d(3.732, 0.250));
IAtom a3E = new Atom("Cl", new Point2d(2.000, 2.500));
IAtom a4E = new Atom("Cl", new Point2d(4.598, -0.250));
a1E.setImplicitHydrogenCount(1);
a2E.setImplicitHydrogenCount(1);
acE.addAtom(a1E);
acE.addAtom(a2E);
acE.addAtom(a3E);
acE.addAtom(a4E);
acE.addBond(new Bond(a1E, a2E, Order.DOUBLE));
acE.addBond(new Bond(a1E, a3E, Order.SINGLE));
acE.addBond(new Bond(a2E, a4E, Order.SINGLE));
InChIGenerator genE = getFactory().getInChIGenerator(acE);
Assert.assertEquals(INCHI_RET.OKAY, genE.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+", genE.getInchi());
// (Z)-1,2-dichloroethene
IAtomContainer acZ = new AtomContainer();
IAtom a1Z = new Atom("C", new Point2d(2.866, -0.440));
IAtom a2Z = new Atom("C", new Point2d(3.732, 0.060));
IAtom a3Z = new Atom("Cl", new Point2d(2.000, 0.060));
IAtom a4Z = new Atom("Cl", new Point2d(3.732, 1.060));
a1Z.setImplicitHydrogenCount(1);
a2Z.setImplicitHydrogenCount(1);
acZ.addAtom(a1Z);
acZ.addAtom(a2Z);
acZ.addAtom(a3Z);
acZ.addAtom(a4Z);
acZ.addBond(new Bond(a1Z, a2Z, Order.DOUBLE));
acZ.addBond(new Bond(a1Z, a3Z, Order.SINGLE));
acZ.addBond(new Bond(a2Z, a4Z, Order.SINGLE));
InChIGenerator genZ = getFactory().getInChIGenerator(acZ);
Assert.assertEquals(INCHI_RET.OKAY, genZ.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1-", genZ.getInchi());
}
/**
* Tests 3D coordinates are correctly passed to InChI.
*
* @throws Exception
*/
@Test
public void testGetStandardInchiFromLandDAlanine3D() throws Exception {
// L-Alanine
IAtomContainer acL = new AtomContainer();
IAtom a1L = new Atom("C", new Point3d(-0.358, 0.819, 20.655));
IAtom a2L = new Atom("C", new Point3d(-1.598, -0.032, 20.905));
IAtom a3L = new Atom("N", new Point3d(-0.275, 2.014, 21.574));
IAtom a4L = new Atom("C", new Point3d(0.952, 0.043, 20.838));
IAtom a5L = new Atom("O", new Point3d(-2.678, 0.479, 21.093));
IAtom a6L = new Atom("O", new Point3d(-1.596, -1.239, 20.958));
a1L.setImplicitHydrogenCount(1);
a3L.setImplicitHydrogenCount(2);
a4L.setImplicitHydrogenCount(3);
a5L.setImplicitHydrogenCount(1);
acL.addAtom(a1L);
acL.addAtom(a2L);
acL.addAtom(a3L);
acL.addAtom(a4L);
acL.addAtom(a5L);
acL.addAtom(a6L);
acL.addBond(new Bond(a1L, a2L, Order.SINGLE));
acL.addBond(new Bond(a1L, a3L, Order.SINGLE));
acL.addBond(new Bond(a1L, a4L, Order.SINGLE));
acL.addBond(new Bond(a2L, a5L, Order.SINGLE));
acL.addBond(new Bond(a2L, a6L, Order.DOUBLE));
InChIGenerator genL = getFactory().getInChIGenerator(acL);
Assert.assertEquals(INCHI_RET.OKAY, genL.getReturnStatus());
Assert.assertEquals("InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1", genL.getInchi());
// D-Alanine
IAtomContainer acD = new AtomContainer();
IAtom a1D = new Atom("C", new Point3d(0.358, 0.819, 20.655));
IAtom a2D = new Atom("C", new Point3d(1.598, -0.032, 20.905));
IAtom a3D = new Atom("N", new Point3d(0.275, 2.014, 21.574));
IAtom a4D = new Atom("C", new Point3d(-0.952, 0.043, 20.838));
IAtom a5D = new Atom("O", new Point3d(2.678, 0.479, 21.093));
IAtom a6D = new Atom("O", new Point3d(1.596, -1.239, 20.958));
a1D.setImplicitHydrogenCount(1);
a3D.setImplicitHydrogenCount(2);
a4D.setImplicitHydrogenCount(3);
a5D.setImplicitHydrogenCount(1);
acD.addAtom(a1D);
acD.addAtom(a2D);
acD.addAtom(a3D);
acD.addAtom(a4D);
acD.addAtom(a5D);
acD.addAtom(a6D);
acD.addBond(new Bond(a1D, a2D, Order.SINGLE));
acD.addBond(new Bond(a1D, a3D, Order.SINGLE));
acD.addBond(new Bond(a1D, a4D, Order.SINGLE));
acD.addBond(new Bond(a2D, a5D, Order.SINGLE));
acD.addBond(new Bond(a2D, a6D, Order.DOUBLE));
InChIGenerator genD = getFactory().getInChIGenerator(acD);
Assert.assertEquals(INCHI_RET.OKAY, genD.getReturnStatus());
Assert.assertEquals("InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m1/s1", genD.getInchi());
}
@Test
public void testTetrahedralStereo() throws Exception {
// L-Alanine
IAtomContainer acL = new AtomContainer();
IAtom[] ligandAtoms = new IAtom[4];
IAtom a1 = new Atom("C");
IAtom a1H = new Atom("H");
ligandAtoms[0] = a1H;
IAtom a2 = new Atom("C");
ligandAtoms[1] = a2;
IAtom a3 = new Atom("N");
ligandAtoms[2] = a3;
IAtom a4 = new Atom("C");
ligandAtoms[3] = a4;
IAtom a5 = new Atom("O");
IAtom a6 = new Atom("O");
a1.setImplicitHydrogenCount(0);
a3.setImplicitHydrogenCount(2);
a4.setImplicitHydrogenCount(3);
a5.setImplicitHydrogenCount(1);
acL.addAtom(a1);
acL.addAtom(a1H);
acL.addAtom(a2);
acL.addAtom(a3);
acL.addAtom(a4);
acL.addAtom(a5);
acL.addAtom(a6);
acL.addBond(new Bond(a1, a1H, Order.SINGLE));
acL.addBond(new Bond(a1, a2, Order.SINGLE));
acL.addBond(new Bond(a1, a3, Order.SINGLE));
acL.addBond(new Bond(a1, a4, Order.SINGLE));
acL.addBond(new Bond(a2, a5, Order.SINGLE));
acL.addBond(new Bond(a2, a6, Order.DOUBLE));
ITetrahedralChirality chirality = new TetrahedralChirality(a1, ligandAtoms, Stereo.ANTI_CLOCKWISE);
acL.addStereoElement(chirality);
InChIGenerator genL = getFactory().getInChIGenerator(acL);
Assert.assertEquals(INCHI_RET.OKAY, genL.getReturnStatus());
Assert.assertEquals("InChI=1S/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1", genL.getInchi());
}
@Test
public void testDoubleBondStereochemistry() throws Exception {
// (E)-1,2-dichloroethene
IAtomContainer acE = new AtomContainer();
IAtom a1E = new Atom("C");
IAtom a2E = new Atom("C");
IAtom a3E = new Atom("Cl");
IAtom a4E = new Atom("Cl");
a1E.setImplicitHydrogenCount(1);
a2E.setImplicitHydrogenCount(1);
acE.addAtom(a1E);
acE.addAtom(a2E);
acE.addAtom(a3E);
acE.addAtom(a4E);
acE.addBond(new Bond(a1E, a2E, Order.DOUBLE));
acE.addBond(new Bond(a1E, a3E, Order.SINGLE));
acE.addBond(new Bond(a2E, a4E, Order.SINGLE));
IBond[] ligands = new IBond[2];
ligands[0] = acE.getBond(1);
ligands[1] = acE.getBond(2);
IDoubleBondStereochemistry stereo = new DoubleBondStereochemistry(acE.getBond(0), ligands,
org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation.OPPOSITE);
acE.addStereoElement(stereo);
InChIGenerator genE = getFactory().getInChIGenerator(acE);
Assert.assertEquals(INCHI_RET.OKAY, genE.getReturnStatus());
Assert.assertEquals("InChI=1S/C2H2Cl2/c3-1-2-4/h1-2H/b2-1+", genE.getInchi());
}
/**
* @cdk.bug 1295
*/
@Test
public void bug1295() throws Exception {
MDLV2000Reader reader = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/bug1295.mol"));
try {
IAtomContainer container = reader.read(new AtomContainer());
InChIGenerator generator = getFactory().getInChIGenerator(container);
Assert.assertEquals("InChI=1S/C7H15NO/c1-4-7(3)6-8-9-5-2/h6-7H,4-5H2,1-3H3", generator.getInchi());
} finally {
reader.close();
}
}
@Test
public void r_penta_2_3_diene_impl_h() throws Exception {
IAtomContainer m = new AtomContainer(5, 4, 0, 0);
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("CH"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("CH"));
m.addAtom(new Atom("CH3"));
m.addBond(0, 1, IBond.Order.SINGLE);
m.addBond(1, 2, IBond.Order.DOUBLE);
m.addBond(2, 3, IBond.Order.DOUBLE);
m.addBond(3, 4, IBond.Order.SINGLE);
int[][] atoms = new int[][]{{0, 1, 3, 4}, {1, 0, 3, 4}, {1, 0, 4, 3}, {0, 1, 4, 3}, {4, 3, 1, 0}, {4, 3, 0, 1},
{3, 4, 0, 1}, {3, 4, 1, 0},};
Stereo[] stereos = new Stereo[]{Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE,
Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE};
for (int i = 0; i < atoms.length; i++) {
IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[]{m.getAtom(atoms[i][0]),
m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3])}, stereos[i]);
m.setStereoElements(Collections.singletonList(element));
InChIGenerator generator = getFactory().getInChIGenerator(m);
assertThat(generator.getInchi(), is("InChI=1S/C5H8/c1-3-5-4-2/h3-4H,1-2H3/t5-/m0/s1"));
}
}
@Test
public void s_penta_2_3_diene_impl_h() throws Exception {
IAtomContainer m = new AtomContainer(5, 4, 0, 0);
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("CH"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("CH"));
m.addAtom(new Atom("CH3"));
m.addBond(0, 1, IBond.Order.SINGLE);
m.addBond(1, 2, IBond.Order.DOUBLE);
m.addBond(2, 3, IBond.Order.DOUBLE);
m.addBond(3, 4, IBond.Order.SINGLE);
int[][] atoms = new int[][]{{0, 1, 3, 4}, {1, 0, 3, 4}, {1, 0, 4, 3}, {0, 1, 4, 3}, {4, 3, 1, 0}, {4, 3, 0, 1},
{3, 4, 0, 1}, {3, 4, 1, 0},};
Stereo[] stereos = new Stereo[]{Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE,
Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE};
for (int i = 0; i < atoms.length; i++) {
IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[]{m.getAtom(atoms[i][0]),
m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3])}, stereos[i]);
m.setStereoElements(Collections.singletonList(element));
InChIGenerator generator = getFactory().getInChIGenerator(m);
assertThat(generator.getInchi(), is("InChI=1S/C5H8/c1-3-5-4-2/h3-4H,1-2H3/t5-/m1/s1"));
}
}
@Test
public void r_penta_2_3_diene_expl_h() throws Exception {
IAtomContainer m = new AtomContainer(5, 4, 0, 0);
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("H"));
m.addAtom(new Atom("H"));
m.addBond(0, 1, IBond.Order.SINGLE);
m.addBond(1, 2, IBond.Order.DOUBLE);
m.addBond(2, 3, IBond.Order.DOUBLE);
m.addBond(3, 4, IBond.Order.SINGLE);
m.addBond(1, 5, IBond.Order.SINGLE);
m.addBond(3, 6, IBond.Order.SINGLE);
int[][] atoms = new int[][]{{0, 5, 6, 4}, {5, 0, 6, 4}, {5, 0, 4, 6}, {0, 5, 4, 6}, {4, 6, 5, 0}, {4, 6, 0, 5},
{6, 4, 0, 5}, {6, 4, 5, 0},};
Stereo[] stereos = new Stereo[]{Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE,
Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE};
for (int i = 0; i < atoms.length; i++) {
IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[]{m.getAtom(atoms[i][0]),
m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3])}, stereos[i]);
m.setStereoElements(Collections.singletonList(element));
InChIGenerator generator = getFactory().getInChIGenerator(m);
assertThat(generator.getInchi(), is("InChI=1S/C5H8/c1-3-5-4-2/h3-4H,1-2H3/t5-/m0/s1"));
}
}
@Test
public void s_penta_2_3_diene_expl_h() throws Exception {
IAtomContainer m = new AtomContainer(5, 4, 0, 0);
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("C"));
m.addAtom(new Atom("CH3"));
m.addAtom(new Atom("H"));
m.addAtom(new Atom("H"));
m.addBond(0, 1, IBond.Order.SINGLE);
m.addBond(1, 2, IBond.Order.DOUBLE);
m.addBond(2, 3, IBond.Order.DOUBLE);
m.addBond(3, 4, IBond.Order.SINGLE);
m.addBond(1, 5, IBond.Order.SINGLE);
m.addBond(3, 6, IBond.Order.SINGLE);
int[][] atoms = new int[][]{{0, 5, 6, 4}, {5, 0, 6, 4}, {5, 0, 4, 6}, {0, 5, 4, 6}, {4, 6, 5, 0}, {4, 6, 0, 5},
{6, 4, 0, 5}, {6, 4, 5, 0},};
Stereo[] stereos = new Stereo[]{Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE,
Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE, Stereo.CLOCKWISE, Stereo.ANTI_CLOCKWISE};
for (int i = 0; i < atoms.length; i++) {
IStereoElement element = new ExtendedTetrahedral(m.getAtom(2), new IAtom[]{m.getAtom(atoms[i][0]),
m.getAtom(atoms[i][1]), m.getAtom(atoms[i][2]), m.getAtom(atoms[i][3])}, stereos[i]);
m.setStereoElements(Collections.singletonList(element));
InChIGenerator generator = getFactory().getInChIGenerator(m);
assertThat(generator.getInchi(), is("InChI=1S/C5H8/c1-3-5-4-2/h3-4H,1-2H3/t5-/m1/s1"));
}
}
@Test(timeout = 1500)
public void timeout() throws Exception {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
String smiles = "C(CCCNC(=N)N)(COCC(COP([O])(=O)OCCCCCCNC(NC1=CC(=C(C=C1)C2(C3=CC=C(C=C3OC=4C2=CC=C(C4)O)O)C)C(=O)[O])=S)OP(=O)([O])OCC(COCC(CCC/[NH]=C(\\[NH])/N)(CCCNC(=N)N)CCCNC(=N)N)OP(=O)([O])OCC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)OP(OCC(COCC(CCCNC(=N)N)(CCCNC(=N)N)CCC/[NH]=C(\\[NH])/N)OP(=O)([O])OCC(COCC(CCCNC(=N)N)(CCCNC(N)=N)CCC/[NH]=C(/N)\\[NH])OP([O])(=O)CCC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)OP([O])(=O)OCC(COCC(CCCNC(N)=N)(CCCNC(N)=N)CCC/[NH]=C(\\[NH])/N)OP(OCC(COCC(CCCNC(N)=N)(CCC/[NH]=C(/N)\\[NH])CCCNC(N)=N)O=P([O])(OCC(COP(=OC(COCC(CCC/[NH]=C(\\[NH])/N)(CCCNC(N)=N)CCCNC(N)=N)COP([O])(=O)OC(COP(OC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)COP(OC(COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)COP([O])(=O)OC(COP(OC(COP(OC(COP(=O)([O])OC(COCC(CCC/[NH]=C(/N)\\[NH])(CCCNC(N)=N)CCCNC(=N)N)COP([O])(=O)OCCCCCCNC(NC=5C=CC(=C(C5)C(=O)[O])C6(C7=CC=C(C=C7OC=8C6=CC=C(C8)O)O)C)=S)COCC(CCCNC(N)=N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)([O])=O)COCC(CCCNC(=N)N)(CCC/[NH]=C(\\[NH])/N)CCCNC(=N)N)([O])=O)COCC(CCCNC(=N)N)(CCCNC(=N)N)CCC/[NH]=C(\\[NH])/N)([O])=O)([O])=O)COCC(CCC/[NH]=C(/N)\\[NH])(CCCNC(=N)N)CCCNC(=N)N)([O])[O])(C)COP(OCCCCCCO)(=O)[O])[O])(=O)[O])([O])=O)(CCC/[NH]=C(\\[NH])/[NH])CCCNC(=N)N";
IAtomContainer mol = smipar.parseSmiles(smiles);
InChIGeneratorFactory inchiFact = InChIGeneratorFactory.getInstance();
InChIGenerator generator = inchiFact.getInChIGenerator(mol, "W0.01");
assertThat(generator.getReturnStatus(), is(INCHI_RET.ERROR));
assertThat(generator.getMessage(),
containsString("Time limit exceeded"));
}
/**
* Standard inchi for guanine.
* @cdk.smiles NC1=NC2=C(N=CN2)C(=O)N1
*/
@Test
public void guanine_std() throws Exception {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
String smiles = "NC1=NC2=C(N=CN2)C(=O)N1";
IAtomContainer mol = smipar.parseSmiles(smiles);
InChIGeneratorFactory inchiFact = InChIGeneratorFactory.getInstance();
InChIGenerator inchigen = inchiFact.getInChIGenerator(mol);
assertThat(inchigen.getReturnStatus(), is(INCHI_RET.OKAY));
assertThat(inchigen.getInchi(), is("InChI=1S/C5H5N5O/c6-5-9-3-2(4(11)10-5)7-1-8-3/h1H,(H4,6,7,8,9,10,11)"));
}
/**
* Ensures KET (Keto-enol) option can be passed to InChI for guanine.
* @cdk.smiles NC1=NC2=C(N=CN2)C(=O)N1
*/
@Test
public void guanine_ket() throws Exception {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
String smiles = "NC1=NC2=C(N=CN2)C(=O)N1";
IAtomContainer mol = smipar.parseSmiles(smiles);
InChIGeneratorFactory inchiFact = InChIGeneratorFactory.getInstance();
InChIGenerator inchigen = inchiFact.getInChIGenerator(mol, "KET");
assertThat(inchigen.getReturnStatus(),
is(INCHI_RET.OKAY));
assertThat(inchigen.getInchi(),
is("InChI=1/C5H5N5O/c6-5-9-3-2(4(11)10-5)7-1-8-3/h1H,(H4,2,6,7,8,9,10,11)"));
}
/**
* Standard test for aminopropenol.
* @cdk.smiles N\C=C/C=O
*/
@Test
public void aminopropenol_std() throws Exception {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
String smiles = "N\\C=C/C=O";
IAtomContainer mol = smipar.parseSmiles(smiles);
InChIGeneratorFactory inchiFact = InChIGeneratorFactory.getInstance();
InChIGenerator stdinchi = inchiFact.getInChIGenerator(mol);
assertThat(stdinchi.getReturnStatus(), is(INCHI_RET.OKAY));
assertThat(stdinchi.getInchi(),
is("InChI=1S/C3H5NO/c4-2-1-3-5/h1-3H,4H2/b2-1-"));
InChIGenerator inchigen = inchiFact.getInChIGenerator(mol, "15T");
assertThat(inchigen.getReturnStatus(), is(INCHI_RET.OKAY));
assertThat(inchigen.getInchi(),
is("InChI=1/C3H5NO/c4-2-1-3-5/h1-3H,(H2,4,5)"));
}
/**
* Ensures 15T (1,5-shifts) option can be passed to InChI for aminopropenol.
* @cdk.smiles N\C=C/C=O
*/
@Test
public void aminopropenol_15T() throws Exception {
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
String smiles = "N\\C=C/C=O";
IAtomContainer mol = smipar.parseSmiles(smiles);
InChIGeneratorFactory inchiFact = InChIGeneratorFactory.getInstance();
InChIGenerator inchigen = inchiFact.getInChIGenerator(mol, "15T");
assertThat(inchigen.getReturnStatus(), is(INCHI_RET.OKAY));
assertThat(inchigen.getInchi(),
is("InChI=1/C3H5NO/c4-2-1-3-5/h1-3H,(H2,4,5)"));
}
/**
* Ensures default timeout option is passed with proper switch character.
*/
@Test
public void testFiveSecondTimeoutFlag() throws Exception {
IAtomContainer ac = new AtomContainer();
ac.addAtom(new Atom("C"));
InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
InChIGenerator generator = factory.getInChIGenerator(ac);
assertThat(generator.options.getTimeoutMilliSeconds(), is(5000L));
}
}