chemruby 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. data/README +120 -0
  2. data/Rakefile +195 -0
  3. data/ext/extconf.rb +4 -0
  4. data/ext/subcomp.c +416 -0
  5. data/lib/chem.rb +130 -0
  6. data/lib/chem/appl.rb +1 -0
  7. data/lib/chem/appl/chem3dole.rb +36 -0
  8. data/lib/chem/appl/tinker/nucleic.rb +40 -0
  9. data/lib/chem/appl/tinker/tinker_reader.rb +43 -0
  10. data/lib/chem/data.rb +4 -0
  11. data/lib/chem/data/atomic_weight.rb +124 -0
  12. data/lib/chem/data/character.rb +2 -0
  13. data/lib/chem/data/electronegativity.rb +14 -0
  14. data/lib/chem/data/periodic_table.rb +6 -0
  15. data/lib/chem/data/prime_numbers.rb +1 -0
  16. data/lib/chem/data/vdw_radii.rb +1 -0
  17. data/lib/chem/db.rb +64 -0
  18. data/lib/chem/db/cansmi.rb +234 -0
  19. data/lib/chem/db/cdx.rb +1525 -0
  20. data/lib/chem/db/eps.rb +164 -0
  21. data/lib/chem/db/g98.rb +909 -0
  22. data/lib/chem/db/gspan.rb +130 -0
  23. data/lib/chem/db/iupac.rb +5 -0
  24. data/lib/chem/db/iupac/a_1.rb +46 -0
  25. data/lib/chem/db/iupac/iuparser.rb +226 -0
  26. data/lib/chem/db/iupac/iuparser.ry +97 -0
  27. data/lib/chem/db/iupac/postfix.rb +2 -0
  28. data/lib/chem/db/kcf.rb +390 -0
  29. data/lib/chem/db/kcf_glycan.rb +19 -0
  30. data/lib/chem/db/kegg.rb +516 -0
  31. data/lib/chem/db/linucs/linparser.rb +144 -0
  32. data/lib/chem/db/linucs/linucs.ry +53 -0
  33. data/lib/chem/db/mdl.rb +379 -0
  34. data/lib/chem/db/molconnz.rb +12 -0
  35. data/lib/chem/db/mopac.rb +88 -0
  36. data/lib/chem/db/msi.rb +107 -0
  37. data/lib/chem/db/pdb_dic.rb +115 -0
  38. data/lib/chem/db/pdf.rb +131 -0
  39. data/lib/chem/db/pubchem.rb +113 -0
  40. data/lib/chem/db/rmagick.rb +70 -0
  41. data/lib/chem/db/sdf.rb +37 -0
  42. data/lib/chem/db/smbl.rb +88 -0
  43. data/lib/chem/db/smiles.rb +2 -0
  44. data/lib/chem/db/smiles/smiles.ry +203 -0
  45. data/lib/chem/db/smiles/smiparser.rb +375 -0
  46. data/lib/chem/db/swf.rb +74 -0
  47. data/lib/chem/db/sybyl.rb +150 -0
  48. data/lib/chem/db/tinker.rb +77 -0
  49. data/lib/chem/db/types/type_cansmi.rb +9 -0
  50. data/lib/chem/db/types/type_cdx.rb +24 -0
  51. data/lib/chem/db/types/type_gspan.rb +31 -0
  52. data/lib/chem/db/types/type_kcf.rb +28 -0
  53. data/lib/chem/db/types/type_kcf_glycan.rb +26 -0
  54. data/lib/chem/db/types/type_kegg.rb +92 -0
  55. data/lib/chem/db/types/type_mdl.rb +31 -0
  56. data/lib/chem/db/types/type_pdf.rb +33 -0
  57. data/lib/chem/db/types/type_png.rb +31 -0
  58. data/lib/chem/db/types/type_rxn.rb +25 -0
  59. data/lib/chem/db/types/type_sdf.rb +25 -0
  60. data/lib/chem/db/types/type_sybyl.rb +30 -0
  61. data/lib/chem/db/types/type_xyz.rb +26 -0
  62. data/lib/chem/db/vector.rb +128 -0
  63. data/lib/chem/db/xyz.rb +39 -0
  64. data/lib/chem/model.rb +119 -0
  65. data/lib/chem/model/skeleton.rb +37 -0
  66. data/lib/chem/utils.rb +11 -0
  67. data/lib/chem/utils/geometry.rb +27 -0
  68. data/lib/chem/utils/graph_db.rb +146 -0
  69. data/lib/chem/utils/math.rb +17 -0
  70. data/lib/chem/utils/prop.rb +123 -0
  71. data/lib/chem/utils/sssr.rb +101 -0
  72. data/lib/chem/utils/sub.rb +78 -0
  73. data/lib/chem/utils/transform.rb +110 -0
  74. data/lib/chem/utils/traverse.rb +37 -0
  75. data/lib/chem/utils/ullmann.rb +134 -0
  76. data/lib/graph.rb +41 -0
  77. data/lib/graph/cluster.rb +20 -0
  78. data/lib/graph/morgan.rb +38 -0
  79. data/sample/frequent_subgraph.rb +46 -0
  80. data/sample/images/ex1.rb +11 -0
  81. data/sample/images/ex2.rb +4 -0
  82. data/sample/images/ex3.rb +5 -0
  83. data/sample/images/ex4.rb +17 -0
  84. data/sample/images/ex5.rb +10 -0
  85. data/sample/images/mol/adenine.mol +26 -0
  86. data/sample/images/mol/atp.mol +69 -0
  87. data/sample/images/temp/ex5.mol +344 -0
  88. data/sample/kegg_db.rb +116 -0
  89. data/setup.rb +1551 -0
  90. data/test/all.rb +6 -0
  91. data/test/coord_test.rb +17 -0
  92. data/test/ctab_test.rb +31 -0
  93. data/test/data/A_21.tar.gz +0 -0
  94. data/test/data/A_21/aceanthrylene.cdx +0 -0
  95. data/test/data/A_21/aceanthrylene.mol +40 -0
  96. data/test/data/A_21/acenaphthylene.cdx +0 -0
  97. data/test/data/A_21/acenaphthylene.mol +31 -0
  98. data/test/data/A_21/acephenanthrylene.cdx +0 -0
  99. data/test/data/A_21/acephenanthrylene.mol +40 -0
  100. data/test/data/A_21/anthracene.cdx +0 -0
  101. data/test/data/A_21/anthracene.mol +35 -0
  102. data/test/data/A_21/as-indacene.cdx +0 -0
  103. data/test/data/A_21/as-indacene.mol +31 -0
  104. data/test/data/A_21/azulene.cdx +0 -0
  105. data/test/data/A_21/azulene.mol +26 -0
  106. data/test/data/A_21/biphenylene.cdx +0 -0
  107. data/test/data/A_21/biphenylene.mol +31 -0
  108. data/test/data/A_21/chrysene.cdx +0 -0
  109. data/test/data/A_21/chrysene.mol +44 -0
  110. data/test/data/A_21/coronen.cdx +0 -0
  111. data/test/data/A_21/coronen.mol +59 -0
  112. data/test/data/A_21/fluoranthene.cdx +0 -0
  113. data/test/data/A_21/fluoranthene.mol +40 -0
  114. data/test/data/A_21/fluorene.cdx +0 -0
  115. data/test/data/A_21/fluorene.mol +33 -0
  116. data/test/data/A_21/heptacene.cdx +0 -0
  117. data/test/data/A_21/heptacene.mol +71 -0
  118. data/test/data/A_21/heptalene.cdx +0 -0
  119. data/test/data/A_21/heptalene.mol +30 -0
  120. data/test/data/A_21/heptaphene.cdx +0 -0
  121. data/test/data/A_21/heptaphene.mol +71 -0
  122. data/test/data/A_21/hexacene.cdx +0 -0
  123. data/test/data/A_21/hexacene.mol +62 -0
  124. data/test/data/A_21/hexaphene.cdx +0 -0
  125. data/test/data/A_21/hexaphene.mol +62 -0
  126. data/test/data/A_21/indene.cdx +0 -0
  127. data/test/data/A_21/indene.mol +24 -0
  128. data/test/data/A_21/iupac.txt +41 -0
  129. data/test/data/A_21/naphthacene.cdx +0 -0
  130. data/test/data/A_21/naphthacene.mol +44 -0
  131. data/test/data/A_21/naphthalene.cdx +0 -0
  132. data/test/data/A_21/naphthalene.mol +26 -0
  133. data/test/data/A_21/ovalene.cdx +0 -0
  134. data/test/data/A_21/ovalene.mol +78 -0
  135. data/test/data/A_21/pentacene.cdx +0 -0
  136. data/test/data/A_21/pentacene.mol +53 -0
  137. data/test/data/A_21/pentalene.cdx +0 -0
  138. data/test/data/A_21/pentalene.mol +22 -0
  139. data/test/data/A_21/pentaphene.cdx +0 -0
  140. data/test/data/A_21/pentaphene.mol +53 -0
  141. data/test/data/A_21/perylene.cdx +0 -0
  142. data/test/data/A_21/perylene.mol +49 -0
  143. data/test/data/A_21/phenalene.cdx +0 -0
  144. data/test/data/A_21/phenalene.mol +33 -0
  145. data/test/data/A_21/phenanthrene.cdx +0 -0
  146. data/test/data/A_21/phenanthrene.mol +35 -0
  147. data/test/data/A_21/picene.cdx +0 -0
  148. data/test/data/A_21/picene.mol +53 -0
  149. data/test/data/A_21/pleiadene.cdx +0 -0
  150. data/test/data/A_21/pleiadene.mol +44 -0
  151. data/test/data/A_21/pyranthrene.cdx +0 -0
  152. data/test/data/A_21/pyranthrene.mol +72 -0
  153. data/test/data/A_21/pyrene.cdx +0 -0
  154. data/test/data/A_21/pyrene.mol +40 -0
  155. data/test/data/A_21/rubicene.cdx +0 -0
  156. data/test/data/A_21/rubicene.mol +63 -0
  157. data/test/data/A_21/s-indacene.cdx +0 -0
  158. data/test/data/A_21/s-indacene.mol +31 -0
  159. data/test/data/A_21/tetraphenylene.cdx +0 -0
  160. data/test/data/A_21/tetraphenylene.mol +57 -0
  161. data/test/data/A_21/trinaphthylene.cdx +0 -0
  162. data/test/data/A_21/trinaphthylene.mol +71 -0
  163. data/test/data/A_21/triphenylene.cdx +0 -0
  164. data/test/data/A_21/triphenylene.mol +44 -0
  165. data/test/data/C00147.kcf +25 -0
  166. data/test/data/G00147.kcf +13 -0
  167. data/test/data/atp.mol +69 -0
  168. data/test/data/cyclohexane.mol +17 -0
  169. data/test/data/cyclohexane.ps +485 -0
  170. data/test/data/fullerene.mol +155 -0
  171. data/test/data/glycan +33 -0
  172. data/test/data/hypericin.cdx +0 -0
  173. data/test/data/hypericin.cdxml +596 -0
  174. data/test/data/hypericin.chm +0 -0
  175. data/test/data/hypericin.ct +85 -0
  176. data/test/data/hypericin.f1d +0 -0
  177. data/test/data/hypericin.f1q +0 -0
  178. data/test/data/hypericin.gif +0 -0
  179. data/test/data/hypericin.mol +88 -0
  180. data/test/data/hypericin.mol2 +159 -0
  181. data/test/data/hypericin.msm +123 -0
  182. data/test/data/hypericin.pdf +359 -0
  183. data/test/data/hypericin.png +0 -0
  184. data/test/data/hypericin.ps +0 -0
  185. data/test/data/hypericin.skc +0 -0
  186. data/test/data/hypericin2.gif +0 -0
  187. data/test/data/hypericin2.ps +0 -0
  188. data/test/data/kegg/genomes/hsa/hsa_enzyme.list +4 -0
  189. data/test/data/kegg/genomes/hsa/hsa_pfam.list +4 -0
  190. data/test/data/kegg/ligand/mol/C00147.mol +26 -0
  191. data/test/data/kegg/ligand/reaction +14 -0
  192. data/test/data/kegg/ligand/reaction.lst +1 -0
  193. data/test/data/kegg/ligand/reaction_mapformula.lst +3 -0
  194. data/test/data/reaction +14 -0
  195. data/test/data/reaction.lst +1 -0
  196. data/test/data/reaction_mapformula.lst +3 -0
  197. data/test/data/rxn/C00001.mol +6 -0
  198. data/test/data/rxn/C00011.mol +10 -0
  199. data/test/data/rxn/C00014.mol +6 -0
  200. data/test/data/rxn/C01010.mol +18 -0
  201. data/test/data/rxn/sample.rxn +50 -0
  202. data/test/data/rxn/substitution.rxn +45 -0
  203. data/test/data/test.eps +0 -0
  204. data/test/data/test.mol +28 -0
  205. data/test/data/test.sdf +143 -0
  206. data/test/data/test.skc +0 -0
  207. data/test/data/test.xyz +4 -0
  208. data/test/data/test_lf.sdf +143 -0
  209. data/test/heavy_test_pubchem.rb +16 -0
  210. data/test/multiple_test.rb +22 -0
  211. data/test/test_adj.rb +54 -0
  212. data/test/test_canonical_smiles.rb +46 -0
  213. data/test/test_cdx.rb +32 -0
  214. data/test/test_chem.rb +18 -0
  215. data/test/test_cluster.rb +19 -0
  216. data/test/test_db.rb +11 -0
  217. data/test/test_eps.rb +24 -0
  218. data/test/test_geometry.rb +11 -0
  219. data/test/test_gspan.rb +28 -0
  220. data/test/test_iupac.rb +36 -0
  221. data/test/test_kcf.rb +24 -0
  222. data/test/test_kcf_glycan.rb +10 -0
  223. data/test/test_kegg.rb +118 -0
  224. data/test/test_linucs.rb +21 -0
  225. data/test/test_mdl.rb +45 -0
  226. data/test/test_mol2.rb +62 -0
  227. data/test/test_morgan.rb +21 -0
  228. data/test/test_pdf.rb +12 -0
  229. data/test/test_prop.rb +86 -0
  230. data/test/test_rmagick.rb +15 -0
  231. data/test/test_sbdb.rb +23 -0
  232. data/test/test_sdf.rb +30 -0
  233. data/test/test_smiles.rb +84 -0
  234. data/test/test_sssr.rb +18 -0
  235. data/test/test_sub.rb +47 -0
  236. data/test/test_subcomp.rb +37 -0
  237. data/test/test_traverse.rb +29 -0
  238. data/test/test_writer.rb +13 -0
  239. data/test/test_xyz.rb +15 -0
  240. data/test/type_test.rb +25 -0
  241. metadata +290 -0
@@ -0,0 +1,21 @@
1
+ #
2
+ # test_adj.rb - Test for adjacency
3
+ #
4
+ #
5
+ # $Id: test_linucs.rb 127 2006-02-03 02:47:57Z tanaka $
6
+ #
7
+
8
+ require 'test/all'
9
+
10
+ require 'chem'
11
+ require 'chem/db/linucs/linparser'
12
+
13
+ class LinucsTest < Test::Unit::TestCase
14
+
15
+ def test_linucs
16
+ assert(true)
17
+ # parser = LinucsParser.new
18
+ # parser.parse("[][Asn]{[(4+1)][b-D-GlcpNAc]{[(4+1)][b-D-GlcpNAc]{[(4+1)][b-D-Manp]{[(3+1)][a-D-Manp]{[(2+1)][a-D-Manp]{[(2+1)][a-D-Manp]{}}}[(6+1)][a-D-Manp]{[(3+1)][a-D-Manp]{[(2+1)][a-D-Manp]{}}[(6+1)][a-D-Manp]{[(2+1)][a-D-Manp]{}}}}}}}")
19
+ end
20
+
21
+ end
@@ -0,0 +1,45 @@
1
+ # $Id: test_mdl.rb 151 2006-02-08 08:21:08Z tanaka $
2
+
3
+ # Tests to ensure functionality
4
+
5
+ require 'test/all'
6
+
7
+ require 'test/type_test'
8
+ require 'test/ctab_test'
9
+ require 'test/coord_test'
10
+
11
+ require 'chem'
12
+
13
+ class MDLTest < Test::Unit::TestCase
14
+
15
+ include Chem::TypeTest
16
+ include Chem::CtabTest
17
+ include Chem::CoordTest
18
+
19
+ def setup
20
+ (@entries = []).push(Chem.open_mol($data_dir + "hypericin.mol"))
21
+ @parser = Chem::MDL::MdlMolecule
22
+ @file_type = Chem::Type::MdlMolType
23
+ end
24
+
25
+ def test_to_mdl
26
+ @entries[0].save(File.join(%w(temp save_test.mol)))
27
+ end
28
+
29
+ def test_bond_stereo
30
+ mol = Chem.open_mol($data_dir + "atp.mol")
31
+ types = mol.edges.inject({}){|ret, (b, a1, a2)| ret[b.stereo] ||= 0 ; ret[b.stereo] += 1 ; ret}
32
+ assert_equal(2, types[:down])
33
+ assert_equal(2, types[:up])
34
+ assert_equal(29, types[:not_stereo])
35
+ end
36
+
37
+ def test_bond_type
38
+ mol = Chem.open_mol($data_dir + "atp.mol")
39
+ types = mol.edges.inject({}){|ret, (b, a1, a2)| ret[b.bond_type] ||= 0 ; ret[b.bond_type] += 1 ; ret}
40
+ assert_equal(7, types[:double])
41
+ assert_equal(26, types[:single])
42
+ end
43
+
44
+ end
45
+
@@ -0,0 +1,62 @@
1
+ # $Id: test_mdl.rb 84 2005-12-01 10:01:04Z tanaka $
2
+
3
+ # Tests to ensure functionality
4
+
5
+ require 'test/all'
6
+
7
+ require 'test/type_test'
8
+ require 'test/ctab_test'
9
+ require 'test/coord_test'
10
+
11
+ require 'chem'
12
+
13
+ class SybylTest < Test::Unit::TestCase
14
+
15
+ include Chem::TypeTest
16
+ include Chem::CtabTest
17
+ # include Chem::CoordTest
18
+
19
+ def setup
20
+ (@entries = []).push(Chem.open_mol($data_dir + "hypericin.mol2"))
21
+ @parser = Chem::Sybyl::SybylMolecule
22
+ @file_type = Chem::Type::SybylType
23
+ end
24
+
25
+ def test_counts_line
26
+ mol = @entries[0]
27
+ assert_equal(67, mol.n_atoms)
28
+ assert_equal(70, mol.n_bonds)
29
+ end
30
+
31
+ def test_atom
32
+ atom = Chem::Sybyl::SybylAtom.new(" 60 H60 -4.920329 -2.301872 1.618476 H 1 <1> 0.024481 ")
33
+ assert_equal(:H, atom.element)
34
+ assert_in_delta(-4.920329, atom.x, 0.0001)
35
+ assert_in_delta(-2.301872, atom.y, 0.0001)
36
+ assert_in_delta( 1.618476, atom.z, 0.0001)
37
+ atom2 = Chem::Sybyl::SybylAtom.new(" 1 C1 -3.262565 -0.588014 -0.082185 C.3 1 <1> -0.020001 ")
38
+ assert_equal(:C, atom2.element)
39
+ end
40
+
41
+ def test_save_sybyl_atom
42
+ atom = Chem::SkeletonAtom.new
43
+ atom.x = -3.262565
44
+ atom.y = -0.588014
45
+ atom.z = -0.082185
46
+
47
+ assert_equal(" 1", atom.to_sybyl[0..7])
48
+ # assert_equal("", atom.to_sybyl[
49
+ end
50
+
51
+ def test_bond
52
+ bond = Chem::Sybyl::SybylBond.new(" 1 10 13 1 ")
53
+ assert_equal(10, bond.b)
54
+ assert_equal(13, bond.e)
55
+ assert_equal( 1, bond.v)
56
+ end
57
+
58
+ def test_mol
59
+ assert_equal((0..66).to_a, @entries[0].match_by_ullmann(@entries[0]))
60
+ end
61
+
62
+ end
@@ -0,0 +1,21 @@
1
+ # $Id: test_mdl.rb 37 2005-09-23 22:58:24Z tanaka $
2
+
3
+ # Tests to ensure functionality
4
+
5
+ require 'test/all'
6
+
7
+ require 'chem'
8
+
9
+ class MorganTest < Test::Unit::TestCase
10
+
11
+ def test_morgan
12
+ mol = Chem.open_mol(File.join($data_dir, "hypericin.mol"))
13
+ ec, tec, priority = mol.morgan#_index
14
+ require 'set'
15
+ assert_equal(Set.new([82, 123, 184, 216, 164, 120, 227, 216, 164, 153,
16
+ 184, 123, 82, 120, 184, 216, 227, 216, 184, 123,
17
+ 82, 120, 164, 153, 164, 120, 82, 123, 40, 42, 51,
18
+ 40, 42, 42, 40, 51, 40, 42]), Set.new(ec.values))
19
+ end
20
+
21
+ end
@@ -0,0 +1,12 @@
1
+
2
+ require 'chem'
3
+
4
+ class PDFTest < Test::Unit::TestCase
5
+
6
+ def test_pdf
7
+ mol = Chem.open_mol($data_dir + "hypericin.mol")
8
+ mol.nodes.each{|node| node.visible = true unless node.element == :C}
9
+ Chem.save(mol, File.join(%w(temp temp.pdf)))
10
+ end
11
+
12
+ end
@@ -0,0 +1,86 @@
1
+ # $Id: test_prop.rb 73 2005-11-16 09:16:15Z tanaka $
2
+
3
+ require 'test/all'
4
+
5
+ require 'chem'
6
+
7
+ class PropTest < Test::Unit::TestCase
8
+
9
+ def test_electro_negativity
10
+ assert_equal(3.16, SMILES("Cl").nodes[0].electro_negativity)
11
+ end
12
+
13
+ def test_natural_bond_order
14
+ assert_equal(4, SMILES("C").nodes[0].natural_bond_order)
15
+ assert_equal(3, SMILES("N").nodes[0].natural_bond_order)
16
+ end
17
+
18
+ def test_oxidation_number
19
+ mgcl2 = SMILES("ClMgCl")
20
+ mg = mgcl2.nodes.find{|n| n.element == :Mg}
21
+ assert(2, mgcl2.oxidation_number(mg))
22
+
23
+ get_en = lambda{|smiles|
24
+ mol = SMILES(smiles)
25
+ c = mol.nodes.find{|atom| atom.element == :C}
26
+ mol.oxidation_number(c)
27
+ }
28
+ assert_equal(-4, get_en.call("HC(H)(H)H"))
29
+ assert_equal(-2, get_en.call("HC(H)(H)F"))
30
+ assert_equal(0, get_en.call("HC(H)(F)F"))
31
+ assert_equal(-2, get_en.call("HC(H)(H)OH"))
32
+ assert_equal(0, get_en.call("HC(H)=O"))
33
+ assert_equal(2, get_en.call("HC(=O)OH"))
34
+ assert_equal(4, get_en.call("O=C=O"))
35
+
36
+ # implicit hydrogen atom
37
+ assert_equal(-4, get_en.call("C"))
38
+ assert_equal(2, get_en.call("C(=O)O"))
39
+ # partially implicit
40
+ assert_equal(0, get_en.call("C(H)(F)F"))
41
+
42
+ end
43
+
44
+ def test_n_hydrogen
45
+ ch4 = SMILES("C")
46
+ assert_equal(4, ch4.n_hydrogen(ch4.nodes[0]))
47
+ hcooh = SMILES("C(=O)O")
48
+ c = hcooh.nodes.find{|n| n.element == :C}
49
+ assert_equal(1, hcooh.n_hydrogen(c))
50
+ end
51
+
52
+ def test_composition
53
+ comp = Chem.open_mol($data_dir + "rxn/C01010.mol").composition
54
+ assert_equal(2, comp[:C])
55
+ assert_equal(2, comp[:N])
56
+ assert_equal(3, comp[:O])
57
+ end
58
+
59
+ # return 1 if self.composition > to.composition
60
+ # return 0 if self.composition == to.composition
61
+ # return -1 if self.composition < to.composition
62
+ # return false if self.composition <> to.composition
63
+ def test_subset_in_composition
64
+ comp1 = Chem.parse_smiles("CCNOC")
65
+ comp2 = Chem.parse_smiles("CCCCC")
66
+ comp3 = Chem.parse_smiles("CNOCC")
67
+ comp4 = Chem.parse_smiles("CNOC")
68
+ comp5 = Chem.parse_smiles("CCC")
69
+ comp6 = Chem.parse_smiles("CNNOC")
70
+ comp7 = Chem.parse_smiles("ClOO")
71
+
72
+ # different species
73
+ assert_equal(false, comp2.subset_in_composition?(comp3))
74
+ assert_equal(false, comp7.subset_in_composition?(comp1))
75
+ assert_equal(1, comp3.subset_in_composition?(comp5))
76
+ assert_equal(-1, comp5.subset_in_composition?(comp3))
77
+
78
+ # same species
79
+ assert_equal(0, comp1.subset_in_composition?(comp3))
80
+ assert_equal(1, comp3.subset_in_composition?(comp4))
81
+ assert_equal(-1, comp4.subset_in_composition?(comp3))
82
+ assert_equal(false, comp3.subset_in_composition?(comp6))
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,15 @@
1
+ require 'chem'
2
+
3
+ class RMagickTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_rmagick
9
+ mol = Chem.open_mol($data_dir + "hypericin.mol")
10
+ mol.nodes.each{|node| node.visible = true unless node.element == :C}
11
+ mol.save(File.join(%w(temp save_test.png)))
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,23 @@
1
+ # $Id: test_sbdb.rb 135 2006-02-06 05:48:56Z tanaka $
2
+
3
+ require 'test/all'
4
+
5
+ require 'chem'
6
+ require 'chem/utils/ullmann'
7
+
8
+ class SBDBTest < Test::Unit::TestCase
9
+
10
+ def test_create_db
11
+
12
+ # db = GraphDB.new("kegg")
13
+ # mol = Chem.parse_file($data_dir + "cyclohexane.mol")
14
+
15
+ # db.insert(mol)
16
+
17
+ # db.select(mol)
18
+
19
+ # assert(true)
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,30 @@
1
+ # $Id: test_sdf.rb 151 2006-02-08 08:21:08Z tanaka $
2
+
3
+ require 'test/type_test'
4
+ require 'chem/db/types/type_sdf'
5
+
6
+ require 'test/multiple_test'
7
+
8
+ class SdfTest < Test::Unit::TestCase
9
+
10
+ include Chem::MultipleTest
11
+
12
+ def setup
13
+ @entries = Chem.open_mol($data_dir + "test.sdf")
14
+ @file_type = Chem::Type::SdfType
15
+ @mod = Chem::MDL::SdfParser
16
+ end
17
+
18
+ def test_autodetection
19
+ assert_equal(Chem::Type::SdfType, Chem::autodetect($data_dir + "test.sdf"))
20
+ end
21
+
22
+ def test_sdf_file
23
+ assert_equal(2, @entries.to_a.length)
24
+ @entries.each do |mol|
25
+ assert_not_nil(mol)
26
+ end
27
+ assert_equal(2, Chem.open_mol($data_dir + "test_lf.sdf").to_a.length)
28
+ end
29
+
30
+ end
@@ -0,0 +1,84 @@
1
+ # $Id: test_smiles.rb 124 2006-01-16 09:15:20Z tanaka $
2
+ require 'chem/db/smiles'
3
+
4
+ require 'test/all'
5
+
6
+ require 'test/ctab_test'
7
+
8
+
9
+ class SmilesTest < Test::Unit::TestCase
10
+
11
+ include Chem::CtabTest
12
+
13
+ def test_cubane
14
+ Chem.parse_smiles("C12C3C4C1C5C2C3C45")
15
+ end
16
+
17
+ def test_atom_types
18
+ [
19
+ ["H" , {:element => :H}],
20
+ ["C" , {:element => :C, :is_aromatic => false, :mass => 12.0107}],
21
+ ["c" , {:element => :C, :is_aromatic => true}],
22
+ ["se" , {:element => :Se, :is_aromatic => true}],
23
+ ["[235U]" , {:element => :U, :mass => 235.0}],
24
+ ["[nH]" , {:element => :N, :is_aromatic => true}], # Hydrogen
25
+ ["[OH3+]" , {:element => :O, :hydrogen_count => 3}],
26
+ ["[Fe2+]" , {:element => :Fe, :charge => 2}],
27
+ ["[Fe++]" , {:element => :Fe, :charge => 2}],
28
+ ["[13CH4]", {:element => :C, :hydrogen_count => 4, :mass => 13}],
29
+ ["[2H]" , {:element => :H, :mass => 2}],
30
+ # ["[C@H]" , {:element => :H}],
31
+ # ["[C@@H]" , {:element => :H}],
32
+ ].each do |sm, prop|
33
+ mol = SMILES(sm)
34
+ prop.each do |key, val|
35
+ assert_equal(val, mol.nodes[0].send(key))
36
+ end
37
+ end
38
+ end
39
+
40
+ def setup
41
+ @entries = []
42
+
43
+ [
44
+ "C",
45
+ "[Au]",
46
+ "[235U]",
47
+ "CC",
48
+ "CCC",
49
+ "C=O",
50
+ "C=CC=C",
51
+ "C#N",
52
+ "CC(C)C(=O)O",
53
+ "O=Cl(=O)(=O)[O-]", # Cl(=O)(=O)(=O)[O-]
54
+ "CCCC(C(=O)O)CCC", # 4-heptanoic acid
55
+ # Ring
56
+ "C1CCCCC1", # Cyclohexane
57
+ "C1=CCCCC1", # cyclohexene
58
+ "c12c(cccc1)cccc2", # naphthalene
59
+ "c1ccccc1c2ccccc2", # biphenyl
60
+ "C12C3C4C1C5C4C3C25", # Cubane
61
+ # Isotopic specification
62
+ "[C]", # elemental carbon
63
+ "[12C]", # elemental carbon-12
64
+ "[13C]", # elemental carbon-13
65
+ "[13CH4]", # C-13 methane
66
+ # Specifying double-bond configuration
67
+ 'F/C=C/F', # trans-difluoroethene
68
+ 'F\C=C\F', # trans-difluoroethene
69
+ 'F/C=C\F', # cis-difluoroethene
70
+ 'F\C=C/F', # cis-difluoroethene
71
+ # Specifying tetrahedral chirality
72
+ "N[C@@H](C)C(=O)O", # L-alanine
73
+ "N[C@H](C)C(=O)O", # D-alanine
74
+ "O[C@H]1CCCC[C@H]1O", # cis-resorcinol
75
+ "C1C[C@H]2CCCC[C@H]CC1", #cis-decaline
76
+ # http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=043383,niaid
77
+ "C1=CC2=C3C(=C1)C=CC4=C3C(=CC5=C4[C@H]([C@H](C=C5)O)O)C=C2",
78
+ "NC(Cc1c[nH]c2cc[se]c12)C(O)=O", # pointed out by Dr. ktaz
79
+ ].each do |smiles|
80
+ @entries.push(Chem.parse_smiles(smiles))
81
+ end
82
+ # mass : NUMBER
83
+ end
84
+ end
@@ -0,0 +1,18 @@
1
+ # $Id: test_sssr.rb 65 2005-10-25 17:17:36Z tanaka $
2
+
3
+ require 'chem/utils/sssr'
4
+
5
+ require 'test/all'
6
+ require 'test/ctab_test'
7
+
8
+ class SssrTest < Test::Unit::TestCase
9
+
10
+ def setup
11
+ end
12
+
13
+ def test_coronen
14
+ coronen = Chem.open_mol($data_dir + '/A_21/coronen.mol')
15
+ coronen.find_sssr
16
+ end
17
+
18
+ end
@@ -0,0 +1,47 @@
1
+ # $Id: test_sub.rb 65 2005-10-25 17:17:36Z tanaka $
2
+
3
+ require 'chem'
4
+
5
+ require 'test/all'
6
+
7
+ class SubTest < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @cyclohexane = Chem.open_mol($data_dir + 'cyclohexane.mol')
11
+ end
12
+
13
+ def test_induced_subgraph
14
+ sub = @cyclohexane.induced_sub(@cyclohexane.nodes[0..2])
15
+ assert_equal(sub.nodes.length, 3)
16
+ end
17
+
18
+ def test_minus
19
+ sub = @cyclohexane.induced_sub(@cyclohexane.nodes[0..2])
20
+ sub2 = @cyclohexane - sub
21
+ assert_equal(sub2.nodes.length, 3)
22
+ end
23
+
24
+ def test_connection
25
+ mol = Chem.parse_smiles("CCCC.NNNNN")
26
+ mol2 = Chem.parse_smiles("CCCCNNNNN")
27
+ assert_equal(false, mol.connected?)
28
+ assert(mol2.connected?)
29
+ end
30
+
31
+ def test_divide
32
+ mol = Chem.parse_smiles("CC.N1NN1.OOOO")
33
+ ary = mol.divide
34
+ ary.each do |mol|
35
+ case mol.nodes[0].element
36
+ when :C
37
+ assert_equal(2, mol.nodes.length)
38
+ when :N
39
+ assert_equal(3, mol.nodes.length)
40
+ when :O
41
+ assert_equal(4, mol.nodes.length)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+