/
SmilesParserTest.java
1842 lines (1597 loc) · 60 KB
/
SmilesParserTest.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
995
996
997
998
999
1000
/* $Revision$ $Author$ $Date$
*
* Copyright (C) 1997-2007 The Chemistry Development Kit (CDK) project
*
* 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.smiles;
import java.util.Iterator;
import java.util.List;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.CDKTestCase;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.graph.ConnectivityChecker;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.isomorphism.IsomorphismTester;
import org.openscience.cdk.isomorphism.UniversalIsomorphismTester;
import org.openscience.cdk.layout.StructureDiagramGenerator;
import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder;
import org.openscience.cdk.templates.MoleculeFactory;
import org.openscience.cdk.tools.CDKHydrogenAdder;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.AtomTypeManipulator;
import org.openscience.cdk.tools.manipulator.BondManipulator;
/**
* Please see the test.gui package for visual feedback on tests.
*
* @author steinbeck
* @cdk.module test-smiles
* @cdk.created 2003-09-19
*
* @see org.openscience.cdk.gui.smiles.SmilesParserTest
*/
public class SmilesParserTest extends CDKTestCase {
private static SmilesParser sp = new SmilesParser(NoNotificationChemObjectBuilder.getInstance());
/** @cdk.bug 1363882 */
@Test (timeout=1000)
public void testBug1363882() throws Exception {
String smiles = "[H]c2c([H])c(c1c(nc(n1([H]))C(F)(F)F)c2Cl)Cl";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(18, mol.getAtomCount());
Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol));
}
/** @cdk.bug 1535587 */
@Test (timeout=1000)
public void testBug1535587() throws Exception {
String smiles = "COC(=O)c2ccc3n([H])c1ccccc1c3(c2)";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(18, mol.getAtomCount());
Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol));
Assert.assertEquals("N", mol.getAtom(8).getSymbol());
Assert.assertTrue(mol.getAtom(8).getFlag(CDKConstants.ISAROMATIC));
}
/** @cdk.bug 1579235 */
@Test (timeout=1000)
public void testBug1579235() throws Exception {
String smiles = "c2cc1cccn1cc2";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(9, mol.getAtomCount());
Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol));
Assert.assertEquals("N", mol.getAtom(6).getSymbol());
for (IAtom atom : mol.atoms()) {
if (atom.getSymbol().equals("C")) {
Assert.assertEquals(IAtomType.Hybridization.SP2, atom.getHybridization());
} else {
Assert.assertEquals(IAtomType.Hybridization.PLANAR3, atom.getHybridization());
}
}
}
@Test (timeout=1000)
public void testBug1579229() throws Exception {
String smiles = "c1c(c23)ccc(c34)ccc4ccc2c1";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(14, mol.getAtomCount());
Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol));
for (IAtom atom : mol.atoms()) {
Assert.assertEquals(IAtomType.Hybridization.SP2, atom.getHybridization());
}
}
/** @cdk.bug 1579230 */
@Test (timeout=1000)
public void testBug1579230() throws Exception {
String smiles = "Cc1cccc2sc3nncn3c12";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(13, mol.getAtomCount());
Assert.assertTrue(CDKHueckelAromaticityDetector.detectAromaticity(mol));
for (int i=1;i<13;i++) { // first atom is not aromatic
IAtom atom = mol.getAtom(i);
if (atom.getSymbol().equals("C"))
Assert.assertEquals(IAtomType.Hybridization.SP2, atom.getHybridization());
if (atom.getSymbol().equals("N") || atom.getSymbol().equals("S")) {
Assert.assertTrue(
IAtomType.Hybridization.SP2 == atom.getHybridization() ||
IAtomType.Hybridization.PLANAR3 == atom.getHybridization()
);
}
}
}
@org.junit.Test (timeout=1000)
public void testPyridine_N_oxideUncharged() throws Exception {
String smiles = "O=n1ccccc1";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(7, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testPyridine_N_oxideCharged() throws Exception {
String smiles = "[O-][n+]1ccccc1";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(7, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testPositivePhosphor() throws Exception {
String smiles = "[Cl+3]([O-])([O-])([O-])[O-].[P+]([O-])(c1ccccc1)(c1ccccc1)c1cc([nH0+](C)c(c1)c1ccccc1)c1ccccc1";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(0, mol.getAtom(22).getHydrogenCount().intValue());
assertAtomTypesPerceived(mol);
Assert.assertEquals(38, mol.getAtomCount());
Assert.assertEquals("P", mol.getAtom(5).getSymbol());
Assert.assertEquals(+1, mol.getAtom(5).getFormalCharge().intValue());
Assert.assertEquals("Cl", mol.getAtom(0).getSymbol());
Assert.assertEquals(+3, mol.getAtom(0).getFormalCharge().intValue());
}
/*
* The next methods tests compounds with several conjugated rings
* These compounds would not fail if the Aromaticity Detection was changed
* so that a ring is aromatic if all the atoms in a ring have already been flagged
* as aromatic from the testing of other rings in the system.
*/
@org.junit.Test (timeout=1000)
public void testUnusualConjugatedRings() throws Exception {
//7090-41-7:
String smiles = "c1(Cl)cc2c3cc(Cl)c(Cl)cc3c2cc1Cl";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(16, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testUnusualConjugatedRings_2() throws Exception {
//206-44-0:
String smiles = "c(c(ccc1)ccc2)(c1c(c3ccc4)c4)c23";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(16, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testUnusualConjugatedRings_3() throws Exception {
Assume.assumeTrue(runSlowTests());
//207-08-9:
String smiles = "c2ccc1cc3c(cc1c2)c4cccc5cccc3c45";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(20, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testUnusualConjugatedRings_4() throws Exception {
//2693-46-1:
String smiles = "Nc1c(c23)cccc3c4ccccc4c2cc1";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(17, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testUnusualConjugatedRings_5() throws Exception {
//205-99-2:
String smiles = "c12ccccc1cc3c4ccccc4c5c3c2ccc5";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(20, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void test187_78_0 () throws Exception {
// are all 4 rings aromatic? Is smiles correct?
String smiles = "c1c(c23)ccc(c34)ccc4ccc2c1";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(14, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void test187_78_0_PubChem() throws Exception {
// are all 4 rings aromatic? Is smiles correct?
String smiles = "C1=CC2=C3C(=CC=C4C3=C1C=C4)C=C2";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(14, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void test41814_78_2 () throws Exception {
String smiles = "Cc1cccc2sc3nncn3c12";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(13, mol.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void test239_64_5 () throws Exception {
String smiles = "c1ccc4c(c1)ccc5c3ccc2ccccc2c3nc45";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(21, mol.getAtomCount());
}
/*
* Compounds like Indolizine (274-40-8) with a fused nitrogen as part of a 6 membered ring
* and another ring do not parse
*/
@org.junit.Test (timeout=1000)
public void testIndolizine () throws Exception {
String smiles = "c2cc1cccn1cc2";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(9, mol.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles1() throws Exception {
String smiles = "C1c2c(c3c(c(O)cnc3)cc2)CC(=O)C1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(16, molecule.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles2() throws Exception {
String smiles = "O=C(O3)C1=COC(OC4OC(CO)C(O)C(O)C4O)C2C1C3C=C2COC(C)=O";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(29, molecule.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles3() throws Exception
{
String smiles = "CN1C=NC2=C1C(N(C)C(N2C)=O)=O";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(14, molecule.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles4() throws Exception {
String smiles = "CN(C)CCC2=CNC1=CC=CC(OP(O)(O)=O)=C12";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(19, molecule.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles5() throws Exception {
String smiles = "O=C(O)C1C(OC(C3=CC=CC=C3)=O)CC2N(C)C1CC2";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(21, molecule.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSmiles6() throws Exception {
String smiles = "C1(C2(C)(C))C(C)=CCC2C1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertEquals(10, molecule.getAtomCount());
}
@org.junit.Test (timeout=1000)
public void testSmiles7() throws Exception {
String smiles = "C1(C=C(C=C(C=C(C=C(C=CC%35=C%36)C%31=C%35C%32=C%33C%36=C%34)C%22=C%31C%23=C%32C%24=C%25C%33=C%26C%34=CC%27=CC%28=CC=C%29)C%14=C%22C%15=C%23C%16=C%24C%17=C%18C%25=C%19C%26=C%27C%20=C%28C%29=C%21)C6=C%14C7=C%15C8=C%16C9=C%17C%12=C%11C%18=C%10C%19=C%20C%21=CC%10=CC%11=CC(C=C%30)=C%12%13)=C(C6=C(C7=C(C8=C(C9=C%13C%30=C5)C5=C4)C4=C3)C3=C2)C2=CC=C1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertNotNull(molecule);
}
@org.junit.Test (timeout=1000)
public void testSmiles8() throws Exception {
String smiles = "CC1(C(=C(CC(C1)O)C)C=CC(=CC=CC(=CC=CC=C(C=CC=C(C=CC1=C(CC(CC1(C)C)O)C)C)C)C)C)C";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertNotNull(molecule);
}
@org.junit.Test (timeout=1000)
public void testSmiles9() throws Exception {
String smiles = "NC(C(C)C)C(NC(C(C)O)C(NC(C(C)C)C(NC(CCC(N)=O)C(NC(CC([O-])[O-])C(NCC(NC(CC(N)=O)C(NC(Cc1ccccc1)C(NC(CO)C(NC(Cc2ccccc2)C(NC(CO)C(NC(CC(C)C)C(NC(CCC([O-])[O-])C(NC(CO)C(NC(C(C)C)C(NC(CCCC[N+])C(NC(CCCC[N+])C(NC(CC(C)C)C(NC(CCCC[N+])C(NC(CC([O-])[O-])C(NC(CC(C)C)C(NC(CCC(N)=O)C(NC(CCC([O-])[O-])C(N3CCCC3C(NC(CCC(N)=O)C(NC(CCC([O-])[O-])C(N4CCCC4C(NC(CCCNC([N+])[N+])C(NC(C(C)C)C(NCC(NC(CCCC[N+])C(NC(CC(C)C)C(NC(CCCNC([N+])[N+])C(NC(CC(N)=O)C(NC(Cc5ccccc5)C(NC(C)C(N6CCCC6C(NC(C(C)CC)C(N7CCCC7C(NCC(NC(CCC([O-])[O-])C(N8CCCC8C(NC(C(C)C)C(NC(C(C)C)C(N9CCCC9C(NC(C(C)CC)C(NC(CC(C)C)C(NC%19C[S][S]CC(C(NC(CCCC[N+])C(NC(CCC([O-])[O-])C(N%10CCCC%10C(NC(CC(N)=O)C(NC(C)C(NC(CCC(N)=O)C(NC(CCC([O-])[O-])C(NC(C(C)CC)C(NC(CC(C)C)C(NC(CCC(N)=O)C(NC(CCCNC([N+])[N+])C(NC(CC(C)C)C(NC(CCC([O-])[O-])C(NC(CCC([O-])[O-])C(NC(C(C)CC)C(NC(C)C(NC(CCC([O-])[O-])C(NC(CC([O-])[O-])C(N%11CCCC%11C(NCC(NC(C(C)O)C(NC%14C[S][S]CC%13C(NC(C(C)O)C(NCC(NC(C[S][S]CC(C(NC(C)C(NC(Cc%12ccc(O)cc%12)C(NC(C)C(NC(C)C(N%13)=O)=O)=O)=O)=O)NC(=O)C(C(C)CC)NC(=O)C(CCC([O-])[O-])NC%14=O)C(O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)NC(=O)C(CC(C)C)NC(=O)C%15CCCN%15C(=O)C(CCCC[N+])NC(=O)C(CC(C)C)NC(=O)C(CCC([O-])[O-])NC(=O)C(CCC([O-])[O-])NC(=O)C%16CCCN%16C(=O)C(Cc%17ccccc%17)NC(=O)C(CC(N)=O)NC(=O)C%18CCCN%18C(=O)C(CC(N)=O)NC(=O)C(CO)NC%19=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O)=O";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertNotNull(molecule);
}
/**
* @cdk.bug 1296113
*/
@org.junit.Test (timeout=1000)
public void testSFBug1296113() throws Exception {
String smiles = "S(=O)(=O)(-O)-c1c2c(c(ccc2-N-c2ccccc2)-N=N-c2c3c(c(cc2)-N=N-c2c4c(c(ccc4)-S(=O)(=O)-O)ccc2)cccc3)ccc1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertNotNull(molecule);
}
/**
* @cdk.bug 1324105
*/
@org.junit.Test (timeout=1000)
public void testAromaticSmiles2() throws Exception {
String smiles = "n12:n:n:n:c:2:c:c:c:c:1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Iterator bonds = molecule.bonds().iterator();
while (bonds.hasNext()) Assert.assertTrue(((IBond)bonds.next()).getFlag(CDKConstants.ISAROMATIC));
}
/**
* A unit test for JUnit. It is currently ignored because the SMILES
* given is invalid: the negative has an implied zero hydrogen count,
* making it have an unfilled valency.
*/
@Ignore @Test (timeout=1000)
public void testAromaticSmilesWithCharge() throws Exception {
String smiles = "c1cc[c-]c1";
IMolecule molecule = sp.parseSmiles(smiles);
assertAtomTypesPerceived(molecule);
Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.ISAROMATIC));
Assert.assertTrue(molecule.getBond(0).getFlag(CDKConstants.ISAROMATIC));
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testAromaticSmiles() throws Exception {
String smiles = "c1ccccc1";
IMolecule molecule = sp.parseSmiles(smiles);
Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.ISAROMATIC));
Assert.assertTrue(molecule.getBond(0).getFlag(CDKConstants.ISAROMATIC));
}
/**
* @cdk.bug 630475
*/
@org.junit.Test (timeout=1000)
public void testSFBug630475() throws Exception {
String smiles = "CC1(C(=C(CC(C1)O)C)C=CC(=CC=CC(=CC=CC=C(C=CC=C(C=CC1=C(CC(CC1(C)C)O)C)C)C)C)C)C";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertTrue(mol.getAtomCount() > 0);
}
/**
* @cdk.bug 585811
*/
@org.junit.Test (timeout=1000)
public void testSFBug585811() throws Exception {
String smiles = "CC(C(C8CCC(CC8)=O)C3C4C(CC5(CCC(C9=CC(C=CN%10)=C%10C=C9)CCCC5)C4)C2CCC1CCC7(CCC7)C6(CC6)C1C2C3)=O";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertTrue(mol.getAtomCount() > 0);
}
/**
* @cdk.bug 593648
*/
@org.junit.Test (timeout=1000)
public void testSFBug593648() throws Exception {
String smiles = "CC1=CCC2CC1C(C)2C";
IMolecule mol = sp.parseSmiles(smiles);
IMolecule apinene = mol.getBuilder().newMolecule();
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 1
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 2
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 3
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 4
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 5
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 6
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 7
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 8
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 9
apinene.addAtom(mol.getBuilder().newAtom("C"));
// 10
apinene.addBond(0, 1, IBond.Order.DOUBLE);
// 1
apinene.addBond(1, 2, IBond.Order.SINGLE);
// 2
apinene.addBond(2, 3, IBond.Order.SINGLE);
// 3
apinene.addBond(3, 4, IBond.Order.SINGLE);
// 4
apinene.addBond(4, 5, IBond.Order.SINGLE);
// 5
apinene.addBond(5, 0, IBond.Order.SINGLE);
// 6
apinene.addBond(0, 6, IBond.Order.SINGLE);
// 7
apinene.addBond(3, 7, IBond.Order.SINGLE);
// 8
apinene.addBond(5, 7, IBond.Order.SINGLE);
// 9
apinene.addBond(7, 8, IBond.Order.SINGLE);
// 10
apinene.addBond(7, 9, IBond.Order.SINGLE);
// 11
IsomorphismTester it = new IsomorphismTester(apinene);
Assert.assertTrue(it.isIsomorphic(mol));
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testReadingOfTwoCharElements() throws Exception {
String smiles = "[Na+]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("Na", mol.getAtom(0).getSymbol());
}
@org.junit.Test (timeout=1000)
public void testReadingOfOneCharElements() throws Exception {
String smiles = "[K+]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("K", mol.getAtom(0).getSymbol());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testOrganicSubsetUnderstanding() throws Exception {
String smiles = "[Ni+2]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("Ni", mol.getAtom(0).getSymbol());
smiles = "Ni";
mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals("N", mol.getAtom(0).getSymbol());
Assert.assertEquals("I", mol.getAtom(1).getSymbol());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testMassNumberReading() throws Exception {
String smiles = "[13C]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("C", mol.getAtom(0).getSymbol());
Assert.assertEquals(13, mol.getAtom(0).getMassNumber().intValue());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testFormalChargeReading() throws Exception {
String smiles = "[OH-]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("O", mol.getAtom(0).getSymbol());
Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testReadingPartionedMolecules() throws Exception {
String smiles = "[Na+].[OH-]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(0, mol.getBondCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testExplicitSingleBond() throws Exception {
String smiles = "C-C";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(1, mol.getBondCount());
Assert.assertEquals(IBond.Order.SINGLE, mol.getBond(0).getOrder());
}
/**
* @cdk.bug 1175478
*/
@org.junit.Test (timeout=1000)
public void testSFBug1175478() throws Exception {
String smiles = "c1cc-2c(cc1)C(c3c4c2onc4c(cc3N5CCCC5)N6CCCC6)=O";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(27, mol.getAtomCount());
Assert.assertEquals(32, mol.getBondCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testUnkownAtomType() throws Exception {
String smiles = "*C";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(1, mol.getBondCount());
Assert.assertTrue(mol.getAtom(0) instanceof IPseudoAtom);
Assert.assertFalse(mol.getAtom(1) instanceof IPseudoAtom);
smiles = "[*]C";
mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(1, mol.getBondCount());
Assert.assertTrue(mol.getAtom(0) instanceof IPseudoAtom);
Assert.assertFalse(mol.getAtom(1) instanceof IPseudoAtom);
}
/**
* @cdk.bug 2596061
* @throws InvalidSmilesException
*/
@org.junit.Test
public void testUnknownAtomType2() throws InvalidSmilesException {
String smiles = "[12*H2-]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals(0, mol.getBondCount());
Assert.assertTrue(mol.getAtom(0) instanceof IPseudoAtom);
Assert.assertEquals(12, mol.getAtom(0).getMassNumber().intValue());
Assert.assertEquals(2, mol.getAtom(0).getHydrogenCount().intValue());
Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testBondCreation() throws Exception {
String smiles = "CC";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(1, mol.getBondCount());
smiles = "cc";
mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtomCount());
Assert.assertEquals(1, mol.getBondCount());
}
/**
* @cdk.bug 784433
*/
@org.junit.Test (timeout=1000)
public void testSFBug784433() throws Exception {
String smiles = "c1cScc1";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(5, mol.getAtomCount());
Assert.assertEquals(5, mol.getBondCount());
}
/**
* @cdk.bug 873783.
*/
@org.junit.Test (timeout=1000)
public void testProton() throws Exception {
String smiles = "[H+]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals(1, mol.getAtom(0).getFormalCharge().intValue());
}
/**
* @cdk.bug 881330.
*/
@org.junit.Test (timeout=1000)
public void testSMILESFromXYZ() throws Exception {
String smiles = "C.C.N.[Co].C.C.C.[H].[He].[H].[H].[H].[H].C.C.[H].[H].[H].[H].[H]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(20, mol.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSingleBracketH() throws Exception {
String smiles = "[H]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testSingleH() {
try {
String smiles = "H";
sp.parseSmiles(smiles);
Assert.fail("The SMILES string 'H' is not valid: H is not in the organic element subset");
} catch (Exception e) {
// yes! it should fail
}
}
/**
* @cdk.bug 862930.
*/
@org.junit.Test (timeout=1000)
public void testHydroxonium() throws Exception {
String smiles = "[H][O+]([H])[H]";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(4, mol.getAtomCount());
}
/**
* @cdk.bug 809412
*/
@org.junit.Test (timeout=1000)
public void testSFBug809412() throws Exception {
String smiles = "Nc4cc3[n+](c2c(c1c(cccc1)cc2)nc3c5c4cccc5)c6c7c(ccc6)cccc7";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(33, mol.getAtomCount());
}
/**
* A bug found with JCP.
*
* @cdk.bug 956926
*/
@org.junit.Test (timeout=1000)
public void testSFBug956926() throws Exception {
String smiles = "[c+]1ccccc1";
// C6H5+, phenyl cation
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(6, mol.getAtomCount());
Assert.assertEquals(1, mol.getAtom(0).getFormalCharge().intValue());
// I can also check whether all carbons have exact two neighbors
for (int i = 0; i < mol.getAtomCount(); i++)
{
Assert.assertEquals(2, mol.getConnectedAtomsCount(mol.getAtom(i)));
}
// and the number of implicit hydrogens
int hCount = 0;
for (int i = 0; i < mol.getAtomCount(); i++)
{
hCount += mol.getAtom(i).getHydrogenCount();
}
Assert.assertEquals(5, hCount);
}
/**
* A bug found with JCP.
*
* @cdk.bug 956929
* @cdk.inchi InChI=1/C4H5N/c1-2-4-5-3-1/h1-5H
*/
@org.junit.Test (timeout=1000)
public void testPyrole() throws Exception {
String smiles = "c1ccc[NH]1";
IMolecule mol = sp.parseSmiles(smiles);
StructureDiagramGenerator sdg=new StructureDiagramGenerator(mol);
sdg.generateCoordinates();
/*MoleculeViewer2D v2d=new MoleculeViewer2D(mol);
v2d.display();
Thread.sleep(100000);*/
for(int i=0;i<mol.getAtomCount();i++){
if(mol.getAtom(i).getSymbol().equals("N")){
Assert.assertEquals(IBond.Order.SINGLE,((IBond)mol.getConnectedBondsList(mol.getAtom(i)).get(0)).getOrder());
Assert.assertEquals(IBond.Order.SINGLE,((IBond)mol.getConnectedBondsList(mol.getAtom(i)).get(1)).getOrder());
}
}
}
/**
* @cdk.bug 2679607
* @throws Exception
*/
@org.junit.Test (timeout=1000)
public void testHardCodedHydrogenCount() throws Exception {
String smiles = "c1ccc[NH]1";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtom(4).getHydrogenCount().intValue());
smiles = "[n]1cc[nH]c1";
mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtom(4).getHydrogenCount().intValue());
Assert.assertEquals(0, mol.getAtom(0).getHydrogenCount().intValue());
smiles = "[nH]1cc[n]c1";
mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtom(0).getHydrogenCount().intValue());
Assert.assertEquals(0, mol.getAtom(3).getHydrogenCount().intValue());
}
/**
* @throws Exception
* @cdk.bug 2679607
*/
@org.junit.Test
public void testHardCodedHydrogenCount2() throws Exception {
String smiles = "[CH2]CNC";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(2, mol.getAtom(0).getHydrogenCount().intValue());
}
/**
* A bug found with JCP.
*
* @cdk.bug 956929
*/
@org.junit.Test (timeout=1000)
public void testSFBug956929() throws Exception {
String smiles = "Cn1cccc1";
IMolecule mol = sp.parseSmiles(smiles);
StructureDiagramGenerator sdg=new StructureDiagramGenerator(mol);
sdg.generateCoordinates();
Assert.assertEquals(6, mol.getAtomCount());
// I can also check whether the total neighbor count around the
// nitrogen is 3, all single bonded
org.openscience.cdk.interfaces.IAtom nitrogen = mol.getAtom(1);
// the second atom
Assert.assertEquals("N", nitrogen.getSymbol());
List<IBond> bondsList = mol.getConnectedBondsList(nitrogen);
Assert.assertEquals(3, bondsList.size());
int totalBondOrder = BondManipulator.getSingleBondEquivalentSum(bondsList);
Assert.assertEquals(3.0, totalBondOrder, 0.001);
}
/**
* A bug found with JCP.
*
* @cdk.bug 956921
*/
@org.junit.Test (timeout=1000)
public void testSFBug956921() throws Exception {
String smiles = "[cH-]1cccc1";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(5, mol.getAtomCount());
// each atom should have 1 implicit hydrogen, and two neighbors
java.util.Iterator atoms = mol.atoms().iterator();
while (atoms.hasNext())
{
IAtom atomi = (IAtom)atoms.next();
Assert.assertEquals(1, atomi.getHydrogenCount().intValue());
Assert.assertEquals(2, mol.getConnectedAtomsCount(atomi));
}
// and the first atom should have a negative charge
Assert.assertEquals(-1, mol.getAtom(0).getFormalCharge().intValue());
}
/**
* @cdk.bug 1274464
*/
@org.junit.Test (timeout=1000)
public void testSFBug1274464() throws Exception {
IAtomContainer fromSmiles = new SmilesParser(DefaultChemObjectBuilder.getInstance()).parseSmiles("C1=CC=CC=C1");
AtomContainer fromFactory = MoleculeFactory.makeBenzene();
CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(fromFactory.getBuilder());
Iterator<IAtom> atoms = fromFactory.atoms().iterator();
CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(fromFactory.getBuilder());
while (atoms.hasNext()) {
IAtom nextAtom = atoms.next();
IAtomType type = matcher.findMatchingAtomType(fromFactory, nextAtom);
AtomTypeManipulator.configure(nextAtom, type);
hAdder.addImplicitHydrogens(fromFactory, nextAtom);
}
CDKHueckelAromaticityDetector.detectAromaticity(fromFactory);
boolean result = UniversalIsomorphismTester.isIsomorph(fromFactory,
fromSmiles);
Assert.assertTrue(result);
}
/**
* @cdk.bug 1095696
*/
@org.junit.Test (timeout=1000)
public void testSFBug1095696() throws Exception {
String smiles = "Nc1ncnc2[nH]cnc12";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(10, mol.getAtomCount());
Assert.assertEquals("N", mol.getAtom(6).getSymbol());
Assert.assertEquals(1, mol.getAtom(6).getHydrogenCount().intValue());
}
/**
* Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 89
* (Part I).
*/
@org.junit.Test (timeout=1000)
public void testNonBond() throws Exception {
String sodiumPhenoxide = "c1cc([O-].[Na+])ccc1";
IMolecule mol = sp.parseSmiles(sodiumPhenoxide);
Assert.assertEquals(8, mol.getAtomCount());
Assert.assertEquals(7, mol.getBondCount());
IMoleculeSet fragments = ConnectivityChecker.partitionIntoMolecules(mol);
int fragmentCount = fragments.getMoleculeCount();
Assert.assertEquals(2, fragmentCount);
org.openscience.cdk.interfaces.IMolecule mol1 = fragments.getMolecule(0);
org.openscience.cdk.interfaces.IMolecule mol2 = fragments.getMolecule(1);
// one should have one atom, the other seven atoms
// in any order, so just test the difference
Assert.assertEquals(6, Math.abs(mol1.getAtomCount() - mol2.getAtomCount()));
}
/**
* Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 89
* (Part I).
*/
@org.junit.Test (timeout=1000)
public void testConnectedByRingClosure() throws Exception {
String sodiumPhenoxide = "C1.O2.C12";
IMolecule mol = sp.parseSmiles(sodiumPhenoxide);
Assert.assertEquals(3, mol.getAtomCount());
Assert.assertEquals(2, mol.getBondCount());
IMoleculeSet fragments = ConnectivityChecker.partitionIntoMolecules(mol);
int fragmentCount = fragments.getMoleculeCount();
Assert.assertEquals(1, fragmentCount);
org.openscience.cdk.interfaces.IMolecule mol1 = fragments.getMolecule(0);
Assert.assertEquals(3, mol1.getAtomCount());
}
/**
* Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 89
* (Part I).
*/
@org.junit.Test (timeout=1000)
public void testReaction() throws Exception {
String reactionSmiles = "O>>[H+].[OH-]";
IReaction reaction = sp.parseReactionSmiles(reactionSmiles);
Assert.assertEquals(1, reaction.getReactantCount());
Assert.assertEquals(2, reaction.getProductCount());
}
/**
* Example taken from 'Handbook of Chemoinformatics', Gasteiger, 2003, page 90
* (Part I).
*/
@org.junit.Test (timeout=1000)
public void testReactionWithAgents() throws Exception {
String reactionSmiles = "CCO.CC(=O)O>[H+]>CC(=O)OCC.O";
IReaction reaction = sp.parseReactionSmiles(reactionSmiles);
Assert.assertEquals(2, reaction.getReactantCount());
Assert.assertEquals(2, reaction.getProductCount());
Assert.assertEquals(1, reaction.getAgents().getMoleculeCount());
Assert.assertEquals(1, reaction.getAgents().getMolecule(0).getAtomCount());
}
/**
* A unit test for JUnit
*/
@org.junit.Test (timeout=1000)
public void testImplicitHydrogenCount() throws Exception {
String smiles = "C";
IMolecule mol = sp.parseSmiles(smiles);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals(4, mol.getAtom(0).getHydrogenCount().intValue());
}
/**
* @cdk.bug 2028780
*/
@Test(timeout=1000)
public void testTungsten() throws Exception {
String smiles = "[W]";
IMolecule mol = sp.parseSmiles(smiles);
assertAtomTypesPerceived(mol);
Assert.assertEquals(1, mol.getAtomCount());
Assert.assertEquals("W", mol.getAtom(0).getSymbol());
}
/**
* A unit test for JUnit
*/