PageRenderTime 39ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/test/unit/bio/db/pdb/test_pdb.rb

https://github.com/phylogenomics/bioruby
Ruby | 3430 lines | 2552 code | 816 blank | 62 comment | 0 complexity | f60e586bd9f9e92cd321d7b91bbb065c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. #
  2. # = test/unit/bio/db/pdb/test_pdb.rb - Unit test for Bio::PDB classes
  3. #
  4. # Copyright:: Copyright (C) 2010 Kazuhiro Hayashi <k.hayashi.info@gmail.com>
  5. # Copyright:: Copyright (C) 2006 Naohisa Goto <ng@bioruby.org>
  6. #
  7. # License:: The Ruby License
  8. #
  9. # $Id:$
  10. #
  11. # loading helper routine for testing bioruby
  12. require 'pathname'
  13. require 'matrix'
  14. load Pathname.new(File.join(File.dirname(__FILE__), ['..'] * 4,
  15. 'bioruby_test_helper.rb')).cleanpath.to_s
  16. # libraries needed for the tests
  17. require 'test/unit'
  18. require 'bio'
  19. module Bio
  20. #This class tests Bio::PDB class.
  21. #The sample record isn't sufficient because it cannot pass through all of the case statement...
  22. class TestPDB < Test::Unit::TestCase
  23. def setup
  24. str =<<EOF
  25. HEADER OXIDOREDUCTASE 12-AUG-09 3INJ
  26. TITLE HUMAN MITOCHONDRIAL ALDEHYDE DEHYDROGENASE COMPLEXED WITH
  27. DBREF 3INJ A 1 500 UNP P05091 ALDH2_HUMAN 18 517
  28. HELIX 1 1 ASP A 55 PHE A 70 1 16
  29. KEYWDS OXIDOREDUCTASE, ALDH, E487K, ROSSMANN FOLD, ALDA-1,
  30. SEQRES 1 A 500 SER ALA ALA ALA THR GLN ALA VAL PRO ALA PRO ASN GLN
  31. SHEET 1 A 2 ILE A 22 ILE A 24 0
  32. SSBOND 1 CYS B 301 CYS B 303 1555 1555 2.97
  33. REVDAT 1 12-JAN-10 3INJ
  34. MODEL 1
  35. ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N
  36. ANISOU 1 N ALA A 7 2406 1892 1614 198 519 -328 N
  37. SIGUIJ 1 N ALA A 7 10 10 10 10 10 10 N
  38. SIGATM 1 N ALA 7 0.040 0.030 0.030 0.00 0.00 N
  39. ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C
  40. ANISOU 2 CA ALA A 7 2748 2004 1679 -21 155 -419 C
  41. SIGUIJ 2 CA ALA A 7 10 10 10 10 10 10 C
  42. SIGATM 2 CA ALA 7 0.040 0.030 0.030 0.00 0.00 C
  43. ATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C
  44. ANISOU 3 C ALA A 7 2555 1955 1468 87 357 -109 C
  45. SIGUIJ 3 C ALA A 7 10 10 10 10 10 10 C
  46. SIGATM 3 N ALA 7 0.040 0.030 0.030 0.00 0.00 C
  47. ATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O
  48. ANISOU 4 O ALA A 7 2555 1955 1468 87 357 -109 O
  49. SIGUIJ 4 O ALA A 7 10 10 10 10 10 10 O
  50. SIGATM 4 O ALA 7 0.040 0.030 0.030 0.00 0.00 O
  51. ATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C
  52. ANISOU 5 CB ALA A 7 2555 1955 1468 87 357 -109 C
  53. SIGUIJ 5 CB ALA A 7 10 10 10 10 10 10 C
  54. SIGATM 1 CB ALA 7 0.040 0.030 0.030 0.00 0.00 C
  55. MODEL 2
  56. ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N
  57. TER 3821 SER A 500
  58. HETATM30582 C1 EDO A 701 -0.205 -27.262 49.961 1.00 34.45 C
  59. HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O
  60. HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C
  61. HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O
  62. HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C
  63. HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O
  64. HETATM30588 C2 EDO A 702 3.678 7.589 66.425 1.00 15.31 C
  65. HETATM30589 O2 EDO A 702 3.391 6.512 65.550 1.00 17.67 O
  66. HETATM30857 O HOH A 502 13.654 -16.451 49.711 1.00 12.79 O
  67. EOF
  68. @pdb = Bio::PDB.new(str)
  69. end
  70. def test_accession
  71. assert_equal("3INJ", @pdb.accession)
  72. end
  73. def test_addModel
  74. assert_nothing_raised{@pdb.addModel(Bio::PDB::Model.new(1,nil))}
  75. end
  76. def test_authors
  77. assert_equal([],@pdb.authors)
  78. end
  79. def test_classification
  80. assert_equal("OXIDOREDUCTASE",@pdb.classification)
  81. end
  82. def test_dbref
  83. assert_instance_of(Bio::PDB::Record::DBREF,@pdb.dbref.first)
  84. assert_instance_of(Bio::PDB::Record::DBREF,@pdb.dbref("A").first)
  85. end
  86. def test_definition
  87. assert_equal("HUMAN MITOCHONDRIAL ALDEHYDE DEHYDROGENASE COMPLEXED WITH",@pdb.definition)
  88. end
  89. def test_each
  90. expected = [nil, 1, 2, 3]
  91. pdb = Bio::PDB.new(" ")
  92. pdb.addModel(Bio::PDB::Model.new(1,nil))
  93. pdb.addModel(Bio::PDB::Model.new(2,nil))
  94. pdb.addModel(Bio::PDB::Model.new(3,nil))
  95. actual = []
  96. pdb.each do |model|
  97. actual << model.serial
  98. end
  99. assert_equal(expected,actual)
  100. end
  101. def test_each_model
  102. expected = [nil, 1, 2, 3]
  103. pdb = Bio::PDB.new("")
  104. pdb.addModel(Bio::PDB::Model.new(1,nil))
  105. pdb.addModel(Bio::PDB::Model.new(2,nil))
  106. pdb.addModel(Bio::PDB::Model.new(3,nil))
  107. actual = []
  108. pdb.each_model do |model|
  109. actual << model.serial
  110. end
  111. assert_equal(expected,actual)
  112. end
  113. def test_entry_id
  114. assert_equal("3INJ", @pdb.entry_id)
  115. end
  116. def test_helix
  117. assert_instance_of(Array, @pdb.helix)
  118. assert_equal(nil,@pdb.helix(1))
  119. end
  120. def test_inspect
  121. assert_equal("#<Bio::PDB entry_id=\"3INJ\">",@pdb.inspect)
  122. end
  123. def test_jrnl
  124. assert_instance_of(Hash, @pdb.jrnl)
  125. end
  126. def test_keywords
  127. assert_equal(["OXIDOREDUCTASE", "ALDH", "E487K", "ROSSMANN FOLD", "ALDA-1"],@pdb.keywords)
  128. end
  129. def test_remark
  130. str =<<EOS
  131. REMARK 1 REFERENCE 1
  132. REMARK 1 AUTH C.H.CHEN,G.R.BUDAS,E.N.CHURCHILL,M.H.DISATNIK
  133. REMARK 2
  134. REMARK 3
  135. EOS
  136. expected =
  137. { 1 => {:remarkNum=>1,
  138. :sub_record=>"AUTH",
  139. :authorList=>["C.H.CHEN", "G.R.BUDAS", "E.N.CHURCHILL", "M.H.DISATNIK"]},
  140. 2=>[],
  141. 3=>[]}
  142. obj = Bio::PDB.new(str)
  143. actual =
  144. { 1 => {:remarkNum=>obj.remark[1][0].remarkNum,
  145. :sub_record=>obj.remark[1][0].sub_record,
  146. :authorList=>obj.remark[1][0].authorList},
  147. 2=>obj.remark[2],
  148. 3=>obj.remark[3]}
  149. assert_equal(actual,expected)
  150. end
  151. def test_record
  152. assert_instance_of(Hash, @pdb.record)
  153. end
  154. def test_seqres
  155. assert_equal({"A"=>"SAAATQAVPAPNQ"},@pdb.seqres)
  156. assert_equal(nil,@pdb.seqres(7)) #I'm not sure why this returns nil
  157. str =<<EOS
  158. SEQRES 1 X 39 U C C C C C G U G C C C A
  159. EOS
  160. obj = Bio::PDB.new(str)
  161. assert_equal({"X"=>"ucccccgugccca"},obj.seqres)
  162. end
  163. # too redundant?
  164. def test_sheet
  165. seq =<<EOS
  166. SHEET 2 BS8 3 LYS 639 LYS 648 -1 N PHE 643 O HIS 662
  167. SHEET 3 BS8 3 ASN 596 VAL 600 -1 N TYR 598 O ILE 646
  168. EOS
  169. s = Bio::PDB.new(seq)
  170. actual = []
  171. s.sheet.each do |obj2|
  172. obj2.each do |obj|
  173. actual <<
  174. {:strand=>obj.strand,
  175. :sheetID=>obj.sheetID,
  176. :numStrands=>obj.numStrands,
  177. :initResName=>obj.initResName,
  178. :initChainID=>obj.initChainID,
  179. :initSeqNum=>obj.initSeqNum,
  180. :initICode=>obj.initICode,
  181. :endResName=>obj.endResName,
  182. :endChainID=>obj.endChainID,
  183. :endSeqNum=>obj.endSeqNum,
  184. :endICode=>obj.endICode,
  185. :sense=>obj.sense,
  186. :curAtom=>obj.curAtom,
  187. :curResName=>obj.curResName,
  188. :curChainId=>obj.curChainId,
  189. :curResSeq=>obj.curResSeq,
  190. :curICode=>obj.curICode,
  191. :prevAtom=>obj.prevAtom,
  192. :prevResName=>obj.prevResName,
  193. :prevChainId=>obj.prevChainId,
  194. :prevResSeq=>obj.prevResSeq,
  195. :prevICode=>obj.prevICode}
  196. end
  197. end
  198. expected =
  199. [
  200. {:strand=>2,
  201. :sheetID=>"BS8",
  202. :numStrands=>3,
  203. :initResName=>"LYS",
  204. :initChainID=>" ",
  205. :initSeqNum=>639,
  206. :initICode=>"",
  207. :endResName=>"LYS",
  208. :endChainID=>" ",
  209. :endSeqNum=>648,
  210. :endICode=>"",
  211. :sense=>-1,
  212. :curAtom=>" N",
  213. :curResName=>"PHE",
  214. :curChainId=>" ",
  215. :curResSeq=>643,
  216. :curICode=>"",
  217. :prevAtom=>" O",
  218. :prevResName=>"HIS",
  219. :prevChainId=>" ",
  220. :prevResSeq=>662,
  221. :prevICode=>""},
  222. {:strand=>3,
  223. :sheetID=>"BS8",
  224. :numStrands=>3,
  225. :initResName=>"ASN",
  226. :initChainID=>" ",
  227. :initSeqNum=>596,
  228. :initICode=>"",
  229. :endResName=>"VAL",
  230. :endChainID=>" ",
  231. :endSeqNum=>600,
  232. :endICode=>"",
  233. :sense=>-1,
  234. :curAtom=>" N",
  235. :curResName=>"TYR",
  236. :curChainId=>" ",
  237. :curResSeq=>598,
  238. :curICode=>"",
  239. :prevAtom=>" O",
  240. :prevResName=>"ILE",
  241. :prevChainId=>" ",
  242. :prevResSeq=>646,
  243. :prevICode=>""}]
  244. actual2 = []
  245. s.sheet("BS8").each do |obj2|
  246. obj2.each do |obj|
  247. actual2 <<
  248. {:strand=>obj.strand,
  249. :sheetID=>obj.sheetID,
  250. :numStrands=>obj.numStrands,
  251. :initResName=>obj.initResName,
  252. :initChainID=>obj.initChainID,
  253. :initSeqNum=>obj.initSeqNum,
  254. :initICode=>obj.initICode,
  255. :endResName=>obj.endResName,
  256. :endChainID=>obj.endChainID,
  257. :endSeqNum=>obj.endSeqNum,
  258. :endICode=>obj.endICode,
  259. :sense=>obj.sense,
  260. :curAtom=>obj.curAtom,
  261. :curResName=>obj.curResName,
  262. :curChainId=>obj.curChainId,
  263. :curResSeq=>obj.curResSeq,
  264. :curICode=>obj.curICode,
  265. :prevAtom=>obj.prevAtom,
  266. :prevResName=>obj.prevResName,
  267. :prevChainId=>obj.prevChainId,
  268. :prevResSeq=>obj.prevResSeq,
  269. :prevICode=>obj.prevICode}
  270. end
  271. end
  272. assert_equal(expected,actual)
  273. assert_equal(expected,actual2)
  274. end
  275. def test_ssbond
  276. assert_instance_of(Bio::PDB::Record::SSBOND,@pdb.ssbond.first)
  277. end
  278. #is this method correct?
  279. def test_to_s
  280. assert_equal("MODEL 1\nATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N \nATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C \nATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C \nATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O \nATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C \nTER\nENDMDL\nMODEL 2\nATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N \nTER\nHETATM30582 C1 EDO A 701 -0.205 -27.262 49.961 1.00 34.45 C \nHETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O \nHETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C \nHETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O \nHETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C \nHETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O \nHETATM30588 C2 EDO A 702 3.678 7.589 66.425 1.00 15.31 C \nHETATM30589 O2 EDO A 702 3.391 6.512 65.550 1.00 17.67 O \nHETATM30857 O HOH A 502 13.654 -16.451 49.711 1.00 12.79 O \nENDMDL\nEND\n",@pdb.to_s)
  281. end
  282. def test_turn
  283. assert_equal([],@pdb.turn)
  284. assert_equal(nil,@pdb.turn(1))
  285. end
  286. def test_version
  287. assert_equal(1,@pdb.version)
  288. end
  289. def test_bracket #test for []
  290. assert_equal(1,@pdb[1].serial)
  291. end
  292. end
  293. #TestPDBRecord::Test* are unit tests for pdb field classes.
  294. #each test class uses one line or several lines of PDB record.
  295. #they tests all the methods described or generated in Bio::PDB::Record.
  296. module TestPDBRecord
  297. # test of Bio::PDB::Record::ATOM
  298. class TestATOM < Test::Unit::TestCase
  299. def setup
  300. # the data is taken from
  301. # http://www.rcsb.org/pdb/file_formats/pdb/pdbguide2.2/part_62.html
  302. @str = 'ATOM 154 CG2BVAL A 25 29.909 16.996 55.922 0.72 13.25 A1 C '
  303. @atom = Bio::PDB::Record::ATOM.new.initialize_from_string(@str)
  304. end
  305. def test_record_name
  306. assert_equal('ATOM', @atom.record_name)
  307. end
  308. def test_serial
  309. assert_equal(154, @atom.serial)
  310. end
  311. def test_name
  312. assert_equal('CG2', @atom.name)
  313. end
  314. def test_altLoc
  315. assert_equal('B', @atom.altLoc)
  316. end
  317. def test_resName
  318. assert_equal('VAL', @atom.resName)
  319. end
  320. def test_chainID
  321. assert_equal('A', @atom.chainID)
  322. end
  323. def test_resSeq
  324. assert_equal(25, @atom.resSeq)
  325. end
  326. def test_iCode
  327. assert_equal('', @atom.iCode)
  328. end
  329. def test_x
  330. assert_in_delta(29.909, @atom.x, 0.0001)
  331. end
  332. def test_y
  333. assert_in_delta(16.996, @atom.y, 0.0001)
  334. end
  335. def test_z
  336. assert_in_delta(55.922, @atom.z, 0.0001)
  337. end
  338. def test_occupancy
  339. assert_in_delta(0.72, @atom.occupancy, 0.001)
  340. end
  341. def test_tempFactor
  342. assert_in_delta(13.25, @atom.tempFactor, 0.001)
  343. end
  344. def test_segID
  345. assert_equal('A1', @atom.segID)
  346. end
  347. def test_element
  348. assert_equal('C', @atom.element)
  349. end
  350. def test_charge
  351. assert_equal('', @atom.charge)
  352. end
  353. def test_xyz
  354. assert_equal(Bio::PDB::Coordinate[
  355. "29.909".to_f,
  356. "16.996".to_f,
  357. "55.922".to_f ], @atom.xyz)
  358. end
  359. def test_to_a
  360. assert_equal([ "29.909".to_f,
  361. "16.996".to_f,
  362. "55.922".to_f ], @atom.to_a)
  363. end
  364. def test_comparable
  365. a = Bio::PDB::Record::ATOM.new
  366. a.serial = 999
  367. assert_equal(-1, @atom <=> a)
  368. a.serial = 154
  369. assert_equal( 0, @atom <=> a)
  370. a.serial = 111
  371. assert_equal( 1, @atom <=> a)
  372. end
  373. def test_to_s
  374. assert_equal(@str + "\n", @atom.to_s)
  375. end
  376. def test_original_data
  377. assert_equal([ @str ], @atom.original_data)
  378. end
  379. def test_do_parse
  380. assert_equal(@atom, @atom.do_parse)
  381. end
  382. def test_residue
  383. assert_equal(nil, @atom.residue)
  384. end
  385. def test_sigatm
  386. assert_equal(nil, @atom.sigatm)
  387. end
  388. def test_anisou
  389. assert_equal(nil, @atom.anisou)
  390. end
  391. def test_ter
  392. assert_equal(nil, @atom.ter)
  393. end
  394. end #class TestATOM
  395. # test of Bio::PDB::Record::ATOM
  396. class TestHETATM < Test::Unit::TestCase
  397. def setup
  398. # the data is taken from
  399. # http://www.rcsb.org/pdb/file_formats/pdb/pdbguide2.2/part_62.html
  400. @str = 'HETATM30581 NA NA A 601 5.037 -39.853 62.809 1.00 17.37 NA '
  401. @hetatm = Bio::PDB::Record::HETATM.new.initialize_from_string(@str)
  402. end
  403. def test_record_name
  404. assert_equal('HETATM', @hetatm.record_name)
  405. end
  406. def test_serial
  407. assert_equal(30581, @hetatm.serial)
  408. end
  409. def test_name
  410. assert_equal('NA', @hetatm.name)
  411. end
  412. def test_altLoc
  413. assert_equal(' ', @hetatm.altLoc)
  414. end
  415. def test_resName
  416. assert_equal('NA', @hetatm.resName)
  417. end
  418. def test_chainID
  419. assert_equal('A', @hetatm.chainID)
  420. end
  421. def test_resSeq
  422. assert_equal(601, @hetatm.resSeq)
  423. end
  424. def test_iCode
  425. assert_equal('', @hetatm.iCode)
  426. end
  427. def test_x
  428. assert_in_delta(5.037, @hetatm.x, 0.0001)
  429. end
  430. def test_y
  431. assert_in_delta(-39.853, @hetatm.y, 0.0001)
  432. end
  433. def test_z
  434. assert_in_delta(62.809, @hetatm.z, 0.0001)
  435. end
  436. def test_occupancy
  437. assert_in_delta(1.00, @hetatm.occupancy, 0.001)
  438. end
  439. def test_tempFactor
  440. assert_in_delta(17.37, @hetatm.tempFactor, 0.001)
  441. end
  442. def test_segID
  443. assert_equal('', @hetatm.segID)
  444. end
  445. def test_element
  446. assert_equal('NA', @hetatm.element)
  447. end
  448. def test_charge
  449. assert_equal('', @hetatm.charge)
  450. end
  451. def test_xyz
  452. assert_equal(Bio::PDB::Coordinate[
  453. "5.037".to_f,
  454. "-39.853".to_f,
  455. "62.809".to_f ], @hetatm.xyz)
  456. end
  457. def test_to_a
  458. assert_equal([ "5.037".to_f,
  459. "-39.853".to_f,
  460. "62.809".to_f ], @hetatm.to_a)
  461. end
  462. def test_comparable
  463. a = Bio::PDB::Record::HETATM.new
  464. a.serial = 40000
  465. assert_equal(-1, @hetatm <=> a)
  466. a.serial = 30581
  467. assert_equal( 0, @hetatm <=> a)
  468. a.serial = 30000
  469. assert_equal( 1, @hetatm <=> a)
  470. end
  471. def test_to_s
  472. assert_equal(@str + "\n", @hetatm.to_s)
  473. end
  474. def test_original_data
  475. assert_equal([ @str ], @hetatm.original_data)
  476. end
  477. def test_do_parse
  478. assert_equal(@hetatm, @hetatm.do_parse)
  479. end
  480. def test_residue
  481. assert_equal(nil, @hetatm.residue)
  482. end
  483. def test_sigatm
  484. assert_equal(nil, @hetatm.sigatm)
  485. end
  486. def test_anisou
  487. assert_equal(nil, @hetatm.anisou)
  488. end
  489. def test_ter
  490. assert_equal(nil, @hetatm.ter)
  491. end
  492. end #class TestATOM
  493. class TestHEADER < Test::Unit::TestCase
  494. def setup
  495. @str = 'HEADER OXIDOREDUCTASE 12-AUG-09 3INJ '
  496. @header = Bio::PDB::Record::HEADER.new.initialize_from_string(@str)
  497. end
  498. def test_classification
  499. assert_equal('OXIDOREDUCTASE', @header.classification)
  500. end
  501. def test_depDate
  502. assert_equal('12-AUG-09', @header.depDate)
  503. end
  504. def test_idCode
  505. assert_equal('3INJ', @header.idCode)
  506. end
  507. end
  508. class TestOBSLTE < Test::Unit::TestCase
  509. def setup
  510. @str = 'OBSLTE 31-JAN-94 1MBP 2MBP '
  511. @obslte = Bio::PDB::Record::OBSLTE.new.initialize_from_string(@str)
  512. end
  513. def test_repDate
  514. assert_equal('31-JAN-94', @obslte.repDate)
  515. end
  516. def test_idCode
  517. assert_equal('1MBP', @obslte.idCode)
  518. end
  519. def test_rIdCode
  520. assert_equal(["2MBP"], @obslte.rIdCode)
  521. end
  522. end
  523. #Is this unit test correct?
  524. class TestTITLE < Test::Unit::TestCase
  525. def setup
  526. @str =
  527. "TITLE HUMAN MITOCHONDRIAL ALDEHYDE DEHYDROGENASE COMPLEXED WITH \n
  528. TITLE 2 AGONIST ALDA-1 "
  529. @title = Bio::PDB::Record::TITLE.new.initialize_from_string(@str)
  530. end
  531. def test_title
  532. assert_equal('HUMAN MITOCHONDRIAL ALDEHYDE DEHYDROGENASE COMPLEXED WITH', @title.title)
  533. end
  534. end
  535. class TestCAVEAT < Test::Unit::TestCase
  536. def setup
  537. @str = 'CAVEAT 1ABC INCORRECT'
  538. @caveat = Bio::PDB::Record::CAVEAT.new.initialize_from_string(@str)
  539. end
  540. def test_idcode
  541. assert_equal('1ABC', @caveat.idcode)
  542. end
  543. def test_comment
  544. assert_equal('INCORRECT', @caveat.comment)
  545. end
  546. end
  547. class TestCOMPND < Test::Unit::TestCase
  548. def setup
  549. @str =<<EOS
  550. COMPND MOL_ID: 1;
  551. COMPND 2 MOLECULE: ALDEHYDE DEHYDROGENASE, MITOCHONDRIAL;
  552. COMPND 3 CHAIN: A, B, C, D, E, F, G, H;
  553. COMPND 4 SYNONYM: ALDH CLASS 2, ALDHI, ALDH-E2;
  554. COMPND 5 EC: 1.2.1.3;
  555. COMPND 6 ENGINEERED: YES
  556. EOS
  557. @compnd = Bio::PDB::Record::COMPND.new.initialize_from_string(@str)
  558. end
  559. def test_compound
  560. assert_equal([["MOL_ID", "1"]], @compnd.compound)
  561. end
  562. end
  563. class TestSOURCE < Test::Unit::TestCase
  564. def setup
  565. @str =<<EOS
  566. SOURCE MOL_ID: 1;
  567. SOURCE 2 ORGANISM_SCIENTIFIC: HOMO SAPIENS;
  568. SOURCE 3 ORGANISM_COMMON: HUMAN;
  569. SOURCE 4 ORGANISM_TAXID: 9606;
  570. SOURCE 5 GENE: ALDH2, ALDM;
  571. SOURCE 6 EXPRESSION_SYSTEM: ESCHERICHIA COLI;
  572. SOURCE 7 EXPRESSION_SYSTEM_TAXID: 562;
  573. SOURCE 8 EXPRESSION_SYSTEM_STRAIN: BL21(DE3);
  574. SOURCE 9 EXPRESSION_SYSTEM_VECTOR_TYPE: PLASMID;
  575. SOURCE 10 EXPRESSION_SYSTEM_PLASMID: PT-7-7
  576. EOS
  577. @source = Bio::PDB::Record::SOURCE.new.initialize_from_string(@str)
  578. end
  579. def test_srcName
  580. expected =
  581. [["MOL_ID", "1"], ["SOURCE 2 ORGANISM_SCIENTIFIC", "HOMO SAPIENS"], ["SOU"]]
  582. assert_equal(expected, @source.srcName)
  583. end
  584. end
  585. class TestKEYWDS < Test::Unit::TestCase
  586. def setup
  587. @str =<<EOF
  588. KEYWDS OXIDOREDUCTASE, ALDH, E487K, ROSSMANN FOLD, ALDA-1,
  589. KEYWDS 2 ACTIVATOR, ACETYLATION, MITOCHONDRION, NAD, POLYMORPHISM,
  590. KEYWDS 3 TRANSIT PEPTIDE
  591. EOF
  592. @keywds = Bio::PDB::Record::KEYWDS.new.initialize_from_string(@str)
  593. end
  594. def test_keywds
  595. assert_equal(["OXIDOREDUCTASE", "ALDH", "E487K", "ROSSMANN FOLD", "ALDA-1", "KEYWDS"], @keywds.keywds)
  596. end
  597. end
  598. class TestEXPDTA < Test::Unit::TestCase
  599. def setup
  600. @str = <<EOF
  601. EXPDTA X-RAY DIFFRACTION
  602. EOF
  603. @expdta = Bio::PDB::Record::EXPDTA.new.initialize_from_string(@str)
  604. end
  605. def test_technique
  606. assert_equal(["X-RAY DIFFRACTION"], @expdta.technique)
  607. end
  608. end
  609. class TestAUTHOR < Test::Unit::TestCase
  610. def setup
  611. @str = 'AUTHOR S.PEREZ-MILLER,T.D.HURLEY'
  612. @author = Bio::PDB::Record::AUTHOR.new.initialize_from_string(@str)
  613. end
  614. def test_authorList
  615. assert_equal(["S.PEREZ-MILLER", "T.D.HURLEY"], @author.authorList)
  616. end
  617. end
  618. class TestREVDAT < Test::Unit::TestCase
  619. def setup
  620. @str = 'REVDAT 1 12-JAN-10 3INJ 0'
  621. @revdat = Bio::PDB::Record::REVDAT.new.initialize_from_string(@str)
  622. end
  623. def test_modNum
  624. assert_equal(1, @revdat.modNum )
  625. end
  626. def test_modDate
  627. assert_equal('12-JAN-10', @revdat.modDate)
  628. end
  629. def test_modId
  630. assert_equal('3INJ', @revdat.modId )
  631. end
  632. def test_modType
  633. assert_equal(0, @revdat.modType)
  634. end
  635. def test_record
  636. assert_equal([], @revdat.record )
  637. end
  638. end
  639. class TestSPRSDE < Test::Unit::TestCase
  640. def setup
  641. @str = 'SPRSDE 17-JUL-84 4HHB 1HHB '
  642. @sprsde = Bio::PDB::Record::SPRSDE.new.initialize_from_string(@str)
  643. end
  644. def test_sprsdeDate
  645. assert_equal('17-JUL-84', @sprsde.sprsdeDate)
  646. end
  647. def test_idCode
  648. assert_equal('4HHB', @sprsde.idCode)
  649. end
  650. def test_sIdCode
  651. assert_equal(["1HHB"], @sprsde.sIdCode)
  652. end
  653. end
  654. class TestDBREF < Test::Unit::TestCase
  655. def setup
  656. @str =<<EOS
  657. DBREF 3INJ A 1 500 UNP P05091 ALDH2_HUMAN 18 517
  658. DBREF 3INJ B 1 500 UNP P05091 ALDH2_HUMAN 18 517
  659. DBREF 3INJ C 1 500 UNP P05091 ALDH2_HUMAN 18 517
  660. DBREF 3INJ D 1 500 UNP P05091 ALDH2_HUMAN 18 517
  661. DBREF 3INJ E 1 500 UNP P05091 ALDH2_HUMAN 18 517
  662. DBREF 3INJ F 1 500 UNP P05091 ALDH2_HUMAN 18 517
  663. DBREF 3INJ G 1 500 UNP P05091 ALDH2_HUMAN 18 517
  664. DBREF 3INJ H 1 500 UNP P05091 ALDH2_HUMAN 18 517
  665. EOS
  666. @dbref = Bio::PDB::Record::DBREF.new.initialize_from_string(@str)
  667. end
  668. def test_idCode
  669. assert_equal('3INJ', @dbref.idCode )
  670. end
  671. def test_chainID
  672. assert_equal('A', @dbref.chainID )
  673. end
  674. def test_seqBegin
  675. assert_equal(1, @dbref.seqBegin )
  676. end
  677. def test_insertBegin
  678. assert_equal('', @dbref.insertBegin)
  679. end
  680. def test_seqEnd
  681. assert_equal(500, @dbref.seqEnd )
  682. end
  683. def test_insertEnd
  684. assert_equal('', @dbref.insertEnd )
  685. end
  686. def test_database
  687. assert_equal('UNP', @dbref.database )
  688. end
  689. def test_dbAccession
  690. assert_equal('P05091', @dbref.dbAccession)
  691. end
  692. def test_dbIdCode
  693. assert_equal('ALDH2_HUMAN', @dbref.dbIdCode )
  694. end
  695. def test_dbseqBegin
  696. assert_equal(18, @dbref.dbseqBegin )
  697. end
  698. def test_idbnsBeg
  699. assert_equal('', @dbref.idbnsBeg )
  700. end
  701. def test_dbseqEnd
  702. assert_equal(517, @dbref.dbseqEnd )
  703. end
  704. end
  705. class TestSEQADV < Test::Unit::TestCase
  706. def setup
  707. @str = 'SEQADV 3ABC MET A -1 UNP P10725 EXPRESSION TAG'
  708. @seqadv = Bio::PDB::Record::SEQADV.new.initialize_from_string(@str)
  709. end
  710. def test_idCode
  711. assert_equal('3ABC', @seqadv.idCode )
  712. end
  713. def test_resName
  714. assert_equal('MET', @seqadv.resName )
  715. end
  716. def test_chainID
  717. assert_equal('A', @seqadv.chainID )
  718. end
  719. def test_seqNum
  720. assert_equal(-1, @seqadv.seqNum )
  721. end
  722. def test_iCode
  723. assert_equal('', @seqadv.iCode )
  724. end
  725. def test_database
  726. assert_equal('UNP', @seqadv.database)
  727. end
  728. def test_dbIdCode
  729. assert_equal('P10725', @seqadv.dbIdCode)
  730. end
  731. def test_dbRes
  732. assert_equal('', @seqadv.dbRes )
  733. end
  734. def test_dbSeq
  735. assert_equal(0, @seqadv.dbSeq )
  736. end
  737. def test_conflict
  738. assert_equal('EXPRESSION TAG', @seqadv.conflict)
  739. end
  740. end
  741. class TestSEQRES < Test::Unit::TestCase
  742. def setup
  743. @str =<<EOS
  744. SEQRES 1 A 500 SER ALA ALA ALA THR GLN ALA VAL PRO ALA PRO ASN GLN
  745. SEQRES 2 A 500 GLN PRO GLU VAL PHE CYS ASN GLN ILE PHE ILE ASN ASN
  746. SEQRES 3 A 500 GLU TRP HIS ASP ALA VAL SER ARG LYS THR PHE PRO THR
  747. SEQRES 4 A 500 VAL ASN PRO SER THR GLY GLU VAL ILE CYS GLN VAL ALA
  748. SEQRES 5 A 500 GLU GLY ASP LYS GLU ASP VAL ASP LYS ALA VAL LYS ALA
  749. SEQRES 6 A 500 ALA ARG ALA ALA PHE GLN LEU GLY SER PRO TRP ARG ARG
  750. SEQRES 7 A 500 MET ASP ALA SER HIS ARG GLY ARG LEU LEU ASN ARG LEU
  751. SEQRES 8 A 500 ALA ASP LEU ILE GLU ARG ASP ARG THR TYR LEU ALA ALA
  752. SEQRES 9 A 500 LEU GLU THR LEU ASP ASN GLY LYS PRO TYR VAL ILE SER
  753. EOS
  754. @seqres = Bio::PDB::Record::SEQRES.new.initialize_from_string(@str)
  755. end
  756. def test_chainID
  757. assert_equal('A', @seqres.chainID)
  758. end
  759. def test_numRes
  760. assert_equal(500, @seqres.numRes )
  761. end
  762. def test_resName
  763. expected =
  764. ["SER",
  765. "ALA",
  766. "ALA",
  767. "ALA",
  768. "THR",
  769. "GLN",
  770. "ALA",
  771. "VAL",
  772. "PRO",
  773. "ALA",
  774. "PRO",
  775. "ASN",
  776. "GLN"]
  777. assert_equal(expected, @seqres.resName)
  778. end
  779. end
  780. class TestMODRES < Test::Unit::TestCase
  781. def setup
  782. @str = 'MODRES 2R0L ASN A 74 ASN GLYCOSYLATION SITE '
  783. @modres = Bio::PDB::Record::MODRES.new.initialize_from_string(@str)
  784. end
  785. def test_idCode
  786. assert_equal('2R0L', @modres.idCode)
  787. end
  788. def test_resName
  789. assert_equal('ASN', @modres.resName)
  790. end
  791. def test_chainID
  792. assert_equal('A', @modres.chainID)
  793. end
  794. def test_seqNum
  795. assert_equal(74, @modres.seqNum)
  796. end
  797. def test_iCode
  798. assert_equal('', @modres.iCode)
  799. end
  800. def test_stdRes
  801. assert_equal('ASN', @modres.stdRes)
  802. end
  803. def test_comment
  804. assert_equal('GLYCOSYLATION SITE', @modres.comment)
  805. end
  806. end
  807. class TestHET < Test::Unit::TestCase
  808. def setup
  809. @str = 'HET NA A 601 1 '
  810. @het = Bio::PDB::Record::HET.new.initialize_from_string(@str)
  811. end
  812. def test_hetID
  813. assert_equal(' NA', @het.hetID)
  814. end
  815. def test_ChainID
  816. assert_equal('A', @het.ChainID)
  817. end
  818. def test_seqNum
  819. assert_equal(601, @het.seqNum)
  820. end
  821. def test_iCode
  822. assert_equal('', @het.iCode)
  823. end
  824. def test_numHetAtoms
  825. assert_equal(1, @het.numHetAtoms)
  826. end
  827. def test_text
  828. assert_equal('', @het.text)
  829. end
  830. end
  831. class TestSHEET < Test::Unit::TestCase
  832. def setup
  833. @str =<<EOS
  834. SHEET 1 A 2 ILE A 22 ILE A 24 0
  835. SHEET 2 A 2 GLU A 27 HIS A 29 -1 O HIS A 29 N ILE A 22
  836. SHEET 1 B 2 THR A 36 VAL A 40 0
  837. EOS
  838. @sheet = Bio::PDB::Record::SHEET.new.initialize_from_string(@str)
  839. end
  840. def test_strand
  841. assert_equal(1, @sheet.strand)
  842. end
  843. def test_sheetID
  844. assert_equal('A', @sheet.sheetID)
  845. end
  846. def test_numStrands
  847. assert_equal(2, @sheet.numStrands)
  848. end
  849. def test_initResName
  850. assert_equal('ILE', @sheet.initResName)
  851. end
  852. def test_initChainID
  853. assert_equal('A', @sheet.initChainID)
  854. end
  855. def test_initSeqNum
  856. assert_equal(22, @sheet.initSeqNum)
  857. end
  858. def test_initICode
  859. assert_equal('', @sheet.initICode)
  860. end
  861. def test_endResName
  862. assert_equal('ILE', @sheet.endResName)
  863. end
  864. def test_endChainID
  865. assert_equal('A', @sheet.endChainID)
  866. end
  867. def test_endSeqNum
  868. assert_equal(24, @sheet.endSeqNum)
  869. end
  870. def test_endICode
  871. assert_equal('', @sheet.endICode)
  872. end
  873. def test_sense
  874. assert_equal(0, @sheet.sense)
  875. end
  876. def test_curAtom
  877. assert_equal('', @sheet.curAtom)
  878. end
  879. def test_curResName
  880. assert_equal('', @sheet.curResName)
  881. end
  882. def test_curChainId
  883. assert_equal(' ', @sheet.curChainId)
  884. end
  885. def test_curResSeq
  886. assert_equal(0, @sheet.curResSeq)
  887. end
  888. def test_curICode
  889. assert_equal('', @sheet.curICode)
  890. end
  891. def test_prevAtom
  892. assert_equal('', @sheet.prevAtom)
  893. end
  894. def test_prevResName
  895. assert_equal('', @sheet.prevResName)
  896. end
  897. def test_prevChainId
  898. assert_equal(' ', @sheet.prevChainId)
  899. end
  900. def test_prevResSeq
  901. assert_equal(0, @sheet.prevResSeq)
  902. end
  903. def test_prevICode
  904. assert_equal('', @sheet.prevICode)
  905. end
  906. end
  907. class TestLINK < Test::Unit::TestCase
  908. def setup
  909. @str = 'LINK O VAL A 40 NA NA A 601 1555 1555 2.41 '
  910. @link = Bio::PDB::Record::LINK.new.initialize_from_string(@str)
  911. end
  912. def test_name1
  913. assert_equal(' O', @link.name1)
  914. end
  915. def test_altLoc1
  916. assert_equal(' ', @link.altLoc1)
  917. end
  918. def test_resName1
  919. assert_equal('VAL', @link.resName1)
  920. end
  921. def test_chainID1
  922. assert_equal('A', @link.chainID1)
  923. end
  924. def test_resSeq1
  925. assert_equal(40, @link.resSeq1)
  926. end
  927. def test_iCode1
  928. assert_equal('', @link.iCode1)
  929. end
  930. def test_name2
  931. assert_equal("NA", @link.name2)
  932. end
  933. def test_altLoc2
  934. assert_equal(' ', @link.altLoc2)
  935. end
  936. def test_resName2
  937. assert_equal(' NA', @link.resName2)
  938. end
  939. def test_chainID2
  940. assert_equal('A', @link.chainID2)
  941. end
  942. def test_resSeq2
  943. assert_equal(601, @link.resSeq2)
  944. end
  945. def test_iCode2
  946. assert_equal('', @link.iCode2)
  947. end
  948. def test_sym1
  949. assert_equal(' 1555', @link.sym1)
  950. end
  951. def test_sym2
  952. assert_equal(' 1555', @link.sym2)
  953. end
  954. end
  955. class TestHYDBND < Test::Unit::TestCase
  956. def setup
  957. @str = 'HYDBND O PHE A 2 A 4 1HN AIB A 4 '
  958. @hydbnd = Bio::PDB::Record::HYDBND.new.initialize_from_string(@str)
  959. end
  960. def test_name1
  961. assert_equal(' O', @hydbnd.name1)
  962. end
  963. def test_altLoc1
  964. assert_equal(' ', @hydbnd.altLoc1)
  965. end
  966. def test_resName1
  967. assert_equal('PHE', @hydbnd.resName1)
  968. end
  969. def test_Chain1
  970. assert_equal('A', @hydbnd.Chain1)
  971. end
  972. def test_resSeq1
  973. assert_equal(2, @hydbnd.resSeq1)
  974. end
  975. def test_ICode1
  976. assert_equal('', @hydbnd.ICode1)
  977. end
  978. def test_nameH
  979. assert_equal('', @hydbnd.nameH)
  980. end
  981. def test_altLocH
  982. assert_equal(' ', @hydbnd.altLocH)
  983. end
  984. def test_ChainH
  985. assert_equal('A', @hydbnd.ChainH)
  986. end
  987. def test_resSeqH
  988. assert_equal(4, @hydbnd.resSeqH)
  989. end
  990. def test_iCodeH
  991. assert_equal('', @hydbnd.iCodeH)
  992. end
  993. def test_name2
  994. assert_equal('1HN', @hydbnd.name2)
  995. end
  996. def test_altLoc2
  997. assert_equal(' ', @hydbnd.altLoc2)
  998. end
  999. def test_resName2
  1000. assert_equal('AIB', @hydbnd.resName2)
  1001. end
  1002. def test_chainID2
  1003. assert_equal('A', @hydbnd.chainID2)
  1004. end
  1005. def test_resSeq2
  1006. assert_equal(4, @hydbnd.resSeq2)
  1007. end
  1008. def test_iCode2
  1009. assert_equal('', @hydbnd.iCode2)
  1010. end
  1011. def test_sym1
  1012. assert_equal('', @hydbnd.sym1)
  1013. end
  1014. def test_sym2
  1015. assert_equal('', @hydbnd.sym2)
  1016. end
  1017. end
  1018. #SLTBRG field is deprecated.
  1019. class TestSLTBRG < Test::Unit::TestCase
  1020. def setup
  1021. @str = ''
  1022. @sltbrg = Bio::PDB::Record::SLTBRG.new.initialize_from_string(@str)
  1023. end
  1024. def test_atom1
  1025. assert_equal('', @sltbrg.atom1)
  1026. end
  1027. def test_altLoc1
  1028. assert_equal("", @sltbrg.altLoc1)
  1029. end
  1030. def test_resName1
  1031. assert_equal("", @sltbrg.resName1)
  1032. end
  1033. def test_chainID1
  1034. assert_equal('', @sltbrg.chainID1)
  1035. end
  1036. def test_resSeq1
  1037. assert_equal(0, @sltbrg.resSeq1)
  1038. end
  1039. def test_iCode1
  1040. assert_equal('', @sltbrg.iCode1)
  1041. end
  1042. def test_atom2
  1043. assert_equal('', @sltbrg.atom2)
  1044. end
  1045. def test_altLoc2
  1046. assert_equal('', @sltbrg.altLoc2)
  1047. end
  1048. def test_resName2
  1049. assert_equal('', @sltbrg.resName2)
  1050. end
  1051. def test_chainID2
  1052. assert_equal('', @sltbrg.chainID2)
  1053. end
  1054. def test_resSeq2
  1055. assert_equal(0, @sltbrg.resSeq2)
  1056. end
  1057. def test_iCode2
  1058. assert_equal('', @sltbrg.iCode2)
  1059. end
  1060. def test_sym1
  1061. assert_equal('', @sltbrg.sym1)
  1062. end
  1063. def test_sym2
  1064. assert_equal('', @sltbrg.sym2)
  1065. end
  1066. end
  1067. class TestCISPEP < Test::Unit::TestCase
  1068. def setup
  1069. @str = 'CISPEP 1 GLY A 116 GLY A 117 0 18.50 '
  1070. @cispep = Bio::PDB::Record::CISPEP.new.initialize_from_string(@str)
  1071. end
  1072. def test_serNum
  1073. assert_equal(1, @cispep.serNum)
  1074. end
  1075. def test_pep1
  1076. assert_equal("GLY", @cispep.pep1)
  1077. end
  1078. def test_chainID1
  1079. assert_equal('A', @cispep.chainID1)
  1080. end
  1081. def test_seqNum1
  1082. assert_equal(116, @cispep.seqNum1)
  1083. end
  1084. def test_icode1
  1085. assert_equal('', @cispep.icode1)
  1086. end
  1087. def test_pep2
  1088. assert_equal('GLY', @cispep.pep2)
  1089. end
  1090. def test_chainID2
  1091. assert_equal('A', @cispep.chainID2)
  1092. end
  1093. def test_seqNum2
  1094. assert_equal(117, @cispep.seqNum2)
  1095. end
  1096. def test_icode2
  1097. assert_equal('', @cispep.icode2)
  1098. end
  1099. def test_modNum
  1100. assert_equal(0, @cispep.modNum)
  1101. end
  1102. def test_measure
  1103. assert_equal(18.5, @cispep.measure)
  1104. end
  1105. end
  1106. class TestSITE < Test::Unit::TestCase
  1107. def setup
  1108. @str =<<EOS
  1109. SITE 1 AC1 5 THR A 39 VAL A 40 ASP A 109 GLN A 196
  1110. SITE 2 AC1 5 HOH A4009
  1111. EOS
  1112. @site = Bio::PDB::Record::SITE.new.initialize_from_string(@str)
  1113. end
  1114. def test_seqNum
  1115. assert_equal(1, @site.seqNum )
  1116. end
  1117. def test_siteID
  1118. assert_equal('AC1', @site.siteID )
  1119. end
  1120. def test_numRes
  1121. assert_equal(5, @site.numRes )
  1122. end
  1123. def test_resName1
  1124. assert_equal('THR', @site.resName1 )
  1125. end
  1126. def test_chainID1
  1127. assert_equal('A', @site.chainID1 )
  1128. end
  1129. def test_seq1
  1130. assert_equal(39, @site.seq1 )
  1131. end
  1132. def test_iCode1
  1133. assert_equal('', @site.iCode1 )
  1134. end
  1135. def test_resName2
  1136. assert_equal('VAL', @site.resName2 )
  1137. end
  1138. def test_chainID2
  1139. assert_equal('A', @site.chainID2 )
  1140. end
  1141. def test_seq2
  1142. assert_equal(40, @site.seq2 )
  1143. end
  1144. def test_iCode2
  1145. assert_equal('', @site.iCode2 )
  1146. end
  1147. def test_resName3
  1148. assert_equal('ASP', @site.resName3 )
  1149. end
  1150. def test_chainID3
  1151. assert_equal('A', @site.chainID3 )
  1152. end
  1153. def test_seq3
  1154. assert_equal(109, @site.seq3 )
  1155. end
  1156. def test_iCode3
  1157. assert_equal('', @site.iCode3 )
  1158. end
  1159. def test_resName4
  1160. assert_equal('GLN', @site.resName4 )
  1161. end
  1162. def test_chainID4
  1163. assert_equal('A', @site.chainID4 )
  1164. end
  1165. def test_seq4
  1166. assert_equal(196, @site.seq4 )
  1167. end
  1168. def test_iCode4
  1169. assert_equal('', @site.iCode4 )
  1170. end
  1171. end
  1172. class TestCRYST1 < Test::Unit::TestCase
  1173. def setup
  1174. @str = 'CRYST1 117.000 15.000 39.000 90.00 90.00 90.00 P 21 21 21 8'
  1175. @cryst1 = Bio::PDB::Record::CRYST1.new.initialize_from_string(@str)
  1176. end
  1177. def test_a
  1178. assert_equal(117.0, @cryst1.a)
  1179. end
  1180. def test_b
  1181. assert_equal(15.0, @cryst1.b)
  1182. end
  1183. def test_c
  1184. assert_equal(39.0, @cryst1.c)
  1185. end
  1186. def test_alpha
  1187. assert_equal(90.0, @cryst1.alpha)
  1188. end
  1189. def test_beta
  1190. assert_equal(90.0, @cryst1.beta)
  1191. end
  1192. def test_gamma
  1193. assert_equal(90.0, @cryst1.gamma)
  1194. end
  1195. def test_sGroup
  1196. assert_equal("P 21 21 21 ", @cryst1.sGroup)
  1197. end
  1198. def test_z
  1199. assert_equal(8, @cryst1.z)
  1200. end
  1201. end
  1202. class TestORIGX1 < Test::Unit::TestCase
  1203. def setup
  1204. @str = 'ORIGX1 1.000000 0.000000 0.000000 0.00000 '
  1205. @origx1 = Bio::PDB::Record::ORIGX1.new.initialize_from_string(@str)
  1206. end
  1207. def test_On1
  1208. assert_equal(1.0, @origx1.On1)
  1209. end
  1210. def test_On2
  1211. assert_equal(0.0, @origx1.On2)
  1212. end
  1213. def test_On3
  1214. assert_equal(0.0, @origx1.On3)
  1215. end
  1216. def test_Tn
  1217. assert_equal(0.0, @origx1.Tn)
  1218. end
  1219. end
  1220. class TestSCALE1 < Test::Unit::TestCase
  1221. def setup
  1222. @str = 'SCALE1 0.019231 0.000000 0.000000 0.00000 '
  1223. @scale1 = Bio::PDB::Record::SCALE1.new.initialize_from_string(@str)
  1224. end
  1225. def test_Sn1
  1226. assert_equal(0.019231, @scale1.Sn1)
  1227. end
  1228. def test_Sn2
  1229. assert_equal(0.0, @scale1.Sn2)
  1230. end
  1231. def test_Sn3
  1232. assert_equal(0.0, @scale1.Sn3)
  1233. end
  1234. def test_Un
  1235. assert_equal(0.0, @scale1.Un)
  1236. end
  1237. end
  1238. class TestSCALE2 < Test::Unit::TestCase
  1239. def setup
  1240. @str = 'SCALE2 0.000000 0.017065 0.000000 0.00000 '
  1241. @scale2 = Bio::PDB::Record::SCALE2.new.initialize_from_string(@str)
  1242. end
  1243. def test_Sn1
  1244. assert_equal(0.0, @scale2.Sn1)
  1245. end
  1246. def test_Sn2
  1247. assert_equal(0.017065, @scale2.Sn2)
  1248. end
  1249. def test_Sn3
  1250. assert_equal(0.0, @scale2.Sn3)
  1251. end
  1252. def test_Un
  1253. assert_equal(0.0, @scale2.Un)
  1254. end
  1255. end
  1256. class TestSCALE3 < Test::Unit::TestCase
  1257. def setup
  1258. @str = 'SCALE3 0.000000 0.000000 0.016155 0.00000 '
  1259. @scale3 = Bio::PDB::Record::SCALE3.new.initialize_from_string(@str)
  1260. end
  1261. def test_Sn1
  1262. assert_equal(0.0, @scale3.Sn1)
  1263. end
  1264. def test_Sn2
  1265. assert_equal(0.0, @scale3.Sn2)
  1266. end
  1267. def test_Sn3
  1268. assert_equal(0.016155, @scale3.Sn3)
  1269. end
  1270. def test_Un
  1271. assert_equal(0.0, @scale3.Un)
  1272. end
  1273. end
  1274. class TestMTRIX1 < Test::Unit::TestCase
  1275. def setup
  1276. @str = 'MTRIX1 1 -1.000000 0.000000 -0.000000 0.00001 1 '
  1277. @mtrix1 = Bio::PDB::Record::MTRIX1.new.initialize_from_string(@str)
  1278. end
  1279. def test_serial
  1280. assert_equal(1, @mtrix1.serial)
  1281. end
  1282. def test_Mn1
  1283. assert_equal(-1.0, @mtrix1.Mn1)
  1284. end
  1285. def test_Mn2
  1286. assert_equal(0.0, @mtrix1.Mn2)
  1287. end
  1288. def test_Mn3
  1289. assert_equal(-0.0, @mtrix1.Mn3)
  1290. end
  1291. def test_Vn
  1292. assert_equal(1.0e-05, @mtrix1.Vn)
  1293. end
  1294. def test_iGiven
  1295. assert_equal(1, @mtrix1.iGiven)
  1296. end
  1297. end
  1298. class TestMTRIX2 < Test::Unit::TestCase
  1299. def setup
  1300. @str = 'MTRIX2 1 -0.000000 1.000000 0.000000 0.00002 1 '
  1301. @mtrix2 = Bio::PDB::Record::MTRIX2.new.initialize_from_string(@str)
  1302. end
  1303. def test_serial
  1304. assert_equal(1, @mtrix2.serial)
  1305. end
  1306. def test_Mn1
  1307. assert_equal(-0.0, @mtrix2.Mn1)
  1308. end
  1309. def test_Mn2
  1310. assert_equal(1.0, @mtrix2.Mn2)
  1311. end
  1312. def test_Mn3
  1313. assert_equal(0.0, @mtrix2.Mn3)
  1314. end
  1315. def test_Vn
  1316. assert_equal(2.0e-05, @mtrix2.Vn)
  1317. end
  1318. def test_iGiven
  1319. assert_equal(1, @mtrix2.iGiven)
  1320. end
  1321. end
  1322. class TestMTRIX3 < Test::Unit::TestCase
  1323. def setup
  1324. @str = 'MTRIX3 1 0.000000 -0.000000 -1.000000 0.00002 1 '
  1325. @mtrix3 = Bio::PDB::Record::MTRIX3.new.initialize_from_string(@str)
  1326. end
  1327. def test_serial
  1328. assert_equal(1, @mtrix3.serial)
  1329. end
  1330. def test_Mn1
  1331. assert_equal(0.0, @mtrix3.Mn1)
  1332. end
  1333. def test_Mn2
  1334. assert_equal(-0.0, @mtrix3.Mn2)
  1335. end
  1336. def test_Mn3
  1337. assert_equal(-1.0, @mtrix3.Mn3)
  1338. end
  1339. def test_Vn
  1340. assert_equal(2.0e-05, @mtrix3.Vn)
  1341. end
  1342. def test_iGiven
  1343. assert_equal(1, @mtrix3.iGiven)
  1344. end
  1345. end
  1346. class TestTVECT < Test::Unit::TestCase
  1347. def setup
  1348. @str = 'TVECT 1 0.00000 0.00000 28.30000 '
  1349. @tvect = Bio::PDB::Record::TVECT.new.initialize_from_string(@str)
  1350. end
  1351. def test_serial
  1352. assert_equal(1, @tvect.serial)
  1353. end
  1354. def test_t1
  1355. assert_equal(0.0, @tvect.t1)
  1356. end
  1357. def test_t2
  1358. assert_equal(0.0, @tvect.t2)
  1359. end
  1360. def test_t3
  1361. assert_equal(28.3, @tvect.t3)
  1362. end
  1363. def test_text
  1364. assert_equal('', @tvect.text)
  1365. end
  1366. end
  1367. class TestMODEL < Test::Unit::TestCase
  1368. def setup
  1369. @str = 'MODEL 1'
  1370. @model = Bio::PDB::Record::MODEL.new.initialize_from_string(@str)
  1371. end
  1372. def test_serial
  1373. assert_equal(1, @model.serial)
  1374. end
  1375. end
  1376. class TestSIGATM < Test::Unit::TestCase
  1377. def setup
  1378. @str = 'SIGATM 230 N PRO 15 0.040 0.030 0.030 0.00 0.00 N'
  1379. @sigatm = Bio::PDB::Record::SIGATM.new.initialize_from_string(@str)
  1380. end
  1381. def test_serial
  1382. assert_equal(230, @sigatm.serial)
  1383. end
  1384. def test_name
  1385. assert_equal(' N', @sigatm.name)
  1386. end
  1387. def test_altLoc
  1388. assert_equal(' ', @sigatm.altLoc)
  1389. end
  1390. def test_resName
  1391. assert_equal('PRO', @sigatm.resName)
  1392. end
  1393. def test_chainID
  1394. assert_equal(' ', @sigatm.chainID)
  1395. end
  1396. def test_resSeq
  1397. assert_equal(15, @sigatm.resSeq)
  1398. end
  1399. def test_iCode
  1400. assert_equal('', @sigatm.iCode)
  1401. end
  1402. def test_sigX
  1403. assert_equal(0.04, @sigatm.sigX)
  1404. end
  1405. def test_sigY
  1406. assert_equal(0.03, @sigatm.sigY)
  1407. end
  1408. def test_sigZ
  1409. assert_equal(0.03, @sigatm.sigZ)
  1410. end
  1411. def test_sigOcc
  1412. assert_equal(0.0, @sigatm.sigOcc)
  1413. end
  1414. def test_sigTemp
  1415. assert_equal(0.0, @sigatm.sigTemp)
  1416. end
  1417. def test_segID
  1418. assert_equal(' ', @sigatm.segID)
  1419. end
  1420. def test_element
  1421. assert_equal(' N', @sigatm.element)
  1422. end
  1423. def test_charge
  1424. assert_equal(' ', @sigatm.charge)
  1425. end
  1426. end
  1427. class TestANISOU < Test::Unit::TestCase
  1428. def setup
  1429. @str = 'ANISOU 107 N GLY 13 2406 1892 1614 198 519 -328 N'
  1430. @anisou = Bio::PDB::Record::ANISOU.new.initialize_from_string(@str)
  1431. end
  1432. def test_serial
  1433. assert_equal(107, @anisou.serial)
  1434. end
  1435. def test_name
  1436. assert_equal(' N', @anisou.name)
  1437. end
  1438. def test_altLoc
  1439. assert_equal(' ', @anisou.altLoc)
  1440. end
  1441. def test_resName
  1442. assert_equal('GLY', @anisou.resName)
  1443. end
  1444. def test_chainID
  1445. assert_equal(' ', @anisou.chainID)
  1446. end
  1447. def test_resSeq
  1448. assert_equal(13, @anisou.resSeq)
  1449. end
  1450. def test_iCode
  1451. assert_equal('', @anisou.iCode)
  1452. end
  1453. def test_U11
  1454. assert_equal(2406, @anisou.U11)
  1455. end
  1456. def test_U22
  1457. assert_equal(1892, @anisou.U22)
  1458. end
  1459. def test_U33
  1460. assert_equal(1614, @anisou.U33)
  1461. end
  1462. def test_U12
  1463. assert_equal(198, @anisou.U12)
  1464. end
  1465. def test_U13
  1466. assert_equal(519, @anisou.U13)
  1467. end
  1468. def test_U23
  1469. assert_equal(-328, @anisou.U23)
  1470. end
  1471. def test_segID
  1472. assert_equal(' ', @anisou.segID)
  1473. end
  1474. def test_element
  1475. assert_equal(' N', @anisou.element)
  1476. end
  1477. def test_charge
  1478. assert_equal(' ', @anisou.charge)
  1479. end
  1480. end
  1481. class TestSIGUIJ < Test::Unit::TestCase
  1482. def setup
  1483. @str = 'SIGUIJ 107 N GLY 13 10 10 10 10 10 10 N'
  1484. @siguij = Bio::PDB::Record::SIGUIJ.new.initialize_from_string(@str)
  1485. end
  1486. def test_serial
  1487. assert_equal(107, @siguij.serial)
  1488. end
  1489. def test_name
  1490. assert_equal(' N', @siguij.name)
  1491. end
  1492. def test_altLoc
  1493. assert_equal(' ', @siguij.altLoc)
  1494. end
  1495. def test_resName
  1496. assert_equal("GLY", @siguij.resName)
  1497. end
  1498. def test_chainID
  1499. assert_equal(" ", @siguij.chainID)
  1500. end
  1501. def test_resSeq
  1502. assert_equal(13, @siguij.resSeq)
  1503. end
  1504. def test_iCode
  1505. assert_equal('', @siguij.iCode)
  1506. end
  1507. def test_SigmaU11
  1508. assert_equal(10, @siguij.SigmaU11)
  1509. end
  1510. def test_SigmaU22
  1511. assert_equal(10, @siguij.SigmaU22)
  1512. end
  1513. def test_SigmaU33
  1514. assert_equal(10, @siguij.SigmaU33)
  1515. end
  1516. def test_SigmaU12
  1517. assert_equal(10, @siguij.SigmaU12)
  1518. end
  1519. def test_SigmaU13
  1520. assert_equal(10, @siguij.SigmaU13)
  1521. end
  1522. def test_SigmaU23
  1523. assert_equal(10, @siguij.SigmaU23)
  1524. end
  1525. def test_segID
  1526. assert_equal(' ', @siguij.segID)
  1527. end
  1528. def test_element
  1529. assert_equal(' N', @siguij.element)
  1530. end
  1531. def test_charge
  1532. assert_equal(' ', @siguij.charge)
  1533. end
  1534. end
  1535. class TestTER < Test::Unit::TestCase
  1536. def setup
  1537. @str = 'TER 3821 SER A 500 '
  1538. @ter = Bio::PDB::Record::TER.new.initialize_from_string(@str)
  1539. end
  1540. def test_serial
  1541. assert_equal(3821, @ter.serial)
  1542. end
  1543. def test_resName
  1544. assert_equal('SER', @ter.resName)
  1545. end
  1546. def test_chainID
  1547. assert_equal('A', @ter.chainID)
  1548. end
  1549. def test_resSeq
  1550. assert_equal(500, @ter.resSeq)
  1551. end
  1552. def test_iCode
  1553. assert_equal('', @ter.iCode)
  1554. end
  1555. end
  1556. class TestENDMDL < Test::Unit::TestCase
  1557. def setup
  1558. @str = 'ENDMDL'
  1559. @endmdl = Bio::PDB::Record::ENDMDL.new.initialize_from_string(@str)
  1560. end
  1561. def test_serial
  1562. assert_equal(0, @endmdl.serial)
  1563. end
  1564. end
  1565. class TestCONECT < Test::Unit::TestCase
  1566. def setup
  1567. @str = 'CONECT 27230581 '
  1568. @conect = Bio::PDB::Record::CONECT.new.initialize_from_string(@str)
  1569. end
  1570. def test_serial
  1571. assert_equal([272, 30581], @conect.serial)
  1572. end
  1573. end
  1574. class TestMASTER < Test::Unit::TestCase
  1575. def setup
  1576. @str = 'MASTER 589 0 41 150 164 0 77 634857 8 322 312 '
  1577. @master = Bio::PDB::Record::MASTER.new.initialize_from_string(@str)
  1578. end
  1579. def test_numRemark
  1580. assert_equal(589, @master.numRemark)
  1581. end
  1582. def test_numHet
  1583. assert_equal(41, @master.numHet)
  1584. end
  1585. def test_numHelix
  1586. assert_equal(150, @master.numHelix)
  1587. end
  1588. def test_numSheet
  1589. assert_equal(164, @master.numSheet)
  1590. end
  1591. def test_numTurn
  1592. assert_equal(0, @master.numTurn)
  1593. end
  1594. def test_numSite
  1595. assert_equal(77, @master.numSite)
  1596. end
  1597. def test_numXform
  1598. assert_equal(6, @master.numXform)
  1599. end
  1600. def test_numCoord
  1601. assert_equal(34857, @master.numCoord)
  1602. end
  1603. def test_numTer
  1604. assert_equal(8, @master.numTer)
  1605. end
  1606. def test_numConect
  1607. assert_equal(322, @master.numConect)
  1608. end
  1609. def test_numSeq
  1610. assert_equal(312, @master.numSeq)
  1611. end
  1612. end
  1613. class TestRemarkN < Test::Unit::TestCase
  1614. def setup
  1615. @str =<<EOS
  1616. REMARK 3 REFINEMENT.
  1617. REMARK 3 PROGRAM : PHENIX (PHENIX.REFINE: 1.4_4)
  1618. REMARK 3 AUTHORS : PAUL ADAMS,PAVEL AFONINE,VICENT CHEN,IAN
  1619. REMARK 3 : DAVIS,KRESHNA GOPAL,RALF GROSSE-
  1620. REMARK 3 : KUNSTLEVE,LI-WEI HUNG,ROBERT IMMORMINO,
  1621. REMARK 3 : TOM IOERGER,AIRLIE MCCOY,ERIK MCKEE,NIGEL
  1622. REMARK 3 : MORIARTY,REETAL PAI,RANDY READ,JANE
  1623. REMARK 3 : RICHARDSON,DAVID RICHARDSON,TOD ROMO,JIM
  1624. REMARK 3 : SACCHETTINI,NICHOLAS SAUTER,JACOB SMITH,
  1625. REMARK 3 : LAURENT STORONI,TOM TERWILLIGER,PETER
  1626. REMARK 3 : ZWART
  1627. REMARK 3
  1628. REMARK 3 REFINEMENT TARGET : TWIN_LSQ_F
  1629. EOS
  1630. @remarkn = Bio::PDB::Record::RemarkN.new.initialize_from_string(@str)
  1631. end
  1632. def test_remarkNum
  1633. assert_equal(3, @remarkn.remarkNum)
  1634. end
  1635. #Is the output correct?
  1636. def test_text
  1637. assert_equal("REFINEMENT.\nREMARK 3 PROGRAM : PHENIX (PHENIX.REFIN", @remarkn.text)
  1638. end
  1639. end
  1640. #What is this record?
  1641. class TestDefault < Test::Unit::TestCase
  1642. def setup
  1643. @str = ''
  1644. @default = Bio::PDB::Record::Default.new.initialize_from_string(@str)
  1645. end
  1646. def test_text
  1647. assert_equal('', @default.text)
  1648. end
  1649. end
  1650. class TestEnd < Test::Unit::TestCase
  1651. def setup
  1652. @str = "END "
  1653. @end = Bio::PDB::Record::End.new.initialize_from_string(@str)
  1654. end
  1655. def test_serial
  1656. assert_equal(0, @end.serial)
  1657. end
  1658. end
  1659. #end
  1660. end #module TestPDBRecord
  1661. #This class tests the behaviors of the complex types defined and used only in Bio::PDB classes.
  1662. class TestDataType < Test::Unit::TestCase
  1663. def test_pdb_integer
  1664. actual = Bio::PDB::DataType::Pdb_Integer.new("1")
  1665. assert_equal(1, actual)
  1666. end
  1667. def test_pdb_slist
  1668. actual = Bio::PDB::DataType::Pdb_SList.new("hoge; foo; bar")
  1669. assert_equal(["hoge", "foo", "bar"], actual)
  1670. end
  1671. def test_pdb_list
  1672. actual = Bio::PDB::DataType::Pdb_List.new("hoge, foo, bar")
  1673. assert_equal(["hoge", "foo", "bar"], actual)
  1674. end
  1675. def test_specification_list
  1676. actual = Bio::PDB::DataType::Pdb_Specification_list.new("hoge: 1; foo: 2; bar: 3;")
  1677. assert_equal([["hoge", "1"], ["foo", "2"], ["bar","3"]], actual)
  1678. end
  1679. def test_pdb_string
  1680. actual = Bio::PDB::DataType::Pdb_String.new("hoge \n ")
  1681. assert_equal("hoge", actual)
  1682. actual =Bio::PDB::DataType::Pdb_String[10].new("hoge")
  1683. assert_equal("hoge ", actual)
  1684. end
  1685. def test_pdb_lstring
  1686. actual = Bio::PDB::DataType::Pdb_LString.new("hoge")
  1687. assert_equal("hoge", actual)
  1688. actual =Bio::PDB::DataType::Pdb_LString[10].new("hoge")
  1689. assert_equal("hoge ", actual)
  1690. end
  1691. def test_pdb_real
  1692. actual = Bio::PDB::DataType::Pdb_Real.new("1.25")
  1693. assert_equal(1.25, actual)
  1694. actual =Bio::PDB::DataType::Pdb_Real[10]
  1695. #include actual
  1696. #assert_equal(10, @@format)
  1697. end
  1698. def test_pdb_stringrj
  1699. actual = Bio::PDB::DataType::Pdb_StringRJ.new(" hoge")
  1700. assert_equal("hoge", actual)
  1701. end
  1702. def test_pdb_date
  1703. actual = Bio::PDB::DataType::Pdb_Date.new("hoge")
  1704. assert_equal("hoge", actual)
  1705. actual =Bio::PDB::DataType::Pdb_Date[10].new("hoge")
  1706. assert_equal("hoge ", actual)
  1707. end
  1708. def test_pdb_idcode
  1709. actual = Bio::PDB::DataType::Pdb_IDcode.new("hoge")
  1710. assert_equal("hoge", actual)
  1711. actual =Bio::PDB::DataType::Pdb_IDcode[10].new("hoge")
  1712. assert_equal("hoge ", actual)
  1713. end
  1714. def test_pdb_resudue_name
  1715. actual = Bio::PDB::DataType::Pdb_Residue_name.new("hoge \n ")
  1716. assert_equal("hoge", actual)
  1717. actual =Bio::PDB::DataType::Pdb_Residue_name[10].new("hoge")
  1718. assert_equal("hoge ", actual)
  1719. end
  1720. def test_pdb_symop
  1721. actual = Bio::PDB::DataType::Pdb_Residue_name.new("hoge")
  1722. assert_equal("hoge", actual)
  1723. actual =Bio::PDB::DataType::Pdb_Residue_name[10].new("hoge")
  1724. assert_equal("hoge ", actual)
  1725. end
  1726. def test_pdb_atom
  1727. actual = Bio::PDB::DataType::Pdb_Residue_name.new("hoge")
  1728. assert_equal("hoge", actual)
  1729. actual =Bio::PDB::DataType::Pdb_Residue_name[10].new("hoge")
  1730. assert_equal("hoge ", actual)
  1731. end
  1732. def test_pdb_achar
  1733. actual = Bio::PDB::DataType::Pdb_Residue_name.new("hoge")
  1734. assert_equal("hoge", actual)
  1735. actual =Bio::PDB::DataType::Pdb_Residue_name[10].new("hoge")
  1736. assert_equal("hoge ", actual)
  1737. end
  1738. def test_pdb_character
  1739. actual = Bio::PDB::DataType::Pdb_Residue_name.new("hoge")
  1740. assert_equal("hoge", actual)
  1741. actual =Bio::PDB::DataType::Pdb_Residue_name[10].new("hoge")
  1742. assert_equal("hoge ", actual)
  1743. end
  1744. def test_const_like_method
  1745. extend Bio::PDB::DataType::ConstLikeMethod
  1746. actual = Pdb_LString(5).new("aaa")
  1747. assert_equal("aaa ", actual)
  1748. actual = Pdb_String(5).new("aaa")
  1749. assert_equal("aaa ", actual)
  1750. actual = Pdb_Real(3).new("1.25")
  1751. assert_equal(1.25, actual)
  1752. end
  1753. end
  1754. # test of Bio::PDB::Record::ATOM
  1755. class TestResidue < Test::Unit::TestCase
  1756. def setup
  1757. @res = Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = "", chain = nil)
  1758. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N"))
  1759. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"))
  1760. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C"))
  1761. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O"))
  1762. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C"))
  1763. end
  1764. def test_get_residue_id_from_atom
  1765. id = Bio::PDB::Residue.get_residue_id_from_atom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 1 N ALA A 7 23.48 4 -35.866 44.510 1.00 28.52 N"))
  1766. assert_equal("7",id)
  1767. end
  1768. def test_addAtom
  1769. assert_nothing_raised {
  1770. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N"))
  1771. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string(" ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"))
  1772. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C"))
  1773. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O"))
  1774. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C"))
  1775. }
  1776. end
  1777. def test_square_bracket
  1778. expected = {:tempFactor=>27.89,
  1779. :iCode=>"",
  1780. :serial=>2,
  1781. :charge=>"",
  1782. :z=>44.904,
  1783. :chainID=>"A",
  1784. :segID=>"",
  1785. :x=>23.849,
  1786. :altLoc=>" ",
  1787. :occupancy=>1.0,
  1788. :resSeq=>7,
  1789. :element=>"C",
  1790. :name=>"CA",
  1791. :y=>-34.509,
  1792. :resName=>"ALA"}
  1793. actual = {}
  1794. @res["CA"].each_pair do |m, v|
  1795. actual[m] = v
  1796. end
  1797. assert_equal(expected, actual)
  1798. end
  1799. def test_each_atom
  1800. expected = [{:serial=>1, :name=>"N", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.484, :y=>-35.866, :z=>44.51, :occupancy=>1.0, :tempFactor=>28.52, :segID=>"", :element=>"N", :charge=>""},
  1801. {:serial=>2, :name=>"CA", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.849, :y=>-34.509, :z=>44.904, :occupancy=>1.0, :tempFactor=>27.89, :segID=>"", :element=>"C", :charge=>""},
  1802. {:serial=>3, :name=>"C", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.102, :y=>-34.082, :z=>46.159, :occupancy=>1.0, :tempFactor=>26.68, :segID=>"", :element=>"C", :charge=>""},{:serial=>4, :name=>"O", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.097, :y=>-32.903, :z=>46.524, :occupancy=>1.0, :tempFactor=>30.02, :segID=>"", :element=>"O", :charge=>""},
  1803. {:serial=>5, :name=>"CB", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.581, :y=>-33.526, :z=>43.77, :occupancy=>1.0, :tempFactor=>31.41, :segID=>"", :element=>"C", :charge=>""}]
  1804. actual = []
  1805. @res.each_atom do |atom|
  1806. actual << {:serial=>atom.serial, :name=>atom.name, :altLoc=>atom.altLoc, :resName=>atom.resName, :chainID=>atom.chainID, :resSeq=>atom.resSeq, :iCode=>atom.iCode, :x=>atom.x, :y=>atom.y, :z=>atom.z, :occupancy=>atom.occupancy, :tempFactor=>atom.tempFactor, :segID=>atom.segID, :element=>atom.element, :charge=>atom.charge}
  1807. end
  1808. assert_equal(expected, actual)
  1809. end
  1810. def test_each
  1811. expected = [{:serial=>1, :name=>"N", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.484, :y=>-35.866, :z=>44.51, :occupancy=>1.0, :tempFactor=>28.52, :segID=>"", :element=>"N", :charge=>""},
  1812. {:serial=>2, :name=>"CA", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.849, :y=>-34.509, :z=>44.904, :occupancy=>1.0, :tempFactor=>27.89, :segID=>"", :element=>"C", :charge=>""},
  1813. {:serial=>3, :name=>"C", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.102, :y=>-34.082, :z=>46.159, :occupancy=>1.0, :tempFactor=>26.68, :segID=>"", :element=>"C", :charge=>""},{:serial=>4, :name=>"O", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.097, :y=>-32.903, :z=>46.524, :occupancy=>1.0, :tempFactor=>30.02, :segID=>"", :element=>"O", :charge=>""},
  1814. {:serial=>5, :name=>"CB", :altLoc=>" ", :resName=>"ALA", :chainID=>"A", :resSeq=>7, :iCode=>"", :x=>23.581, :y=>-33.526, :z=>43.77, :occupancy=>1.0, :tempFactor=>31.41, :segID=>"", :element=>"C", :charge=>""}]
  1815. actual = []
  1816. @res.each do |atom|
  1817. actual << {:serial=>atom.serial, :name=>atom.name, :altLoc=>atom.altLoc, :resName=>atom.resName, :chainID=>atom.chainID, :resSeq=>atom.resSeq, :iCode=>atom.iCode, :x=>atom.x, :y=>atom.y, :z=>atom.z, :occupancy=>atom.occupancy, :tempFactor=>atom.tempFactor, :segID=>atom.segID, :element=>atom.element, :charge=>atom.charge}
  1818. end
  1819. assert_equal(expected, actual)
  1820. end
  1821. def test_het_atom
  1822. assert_equal(false, @res.hetatm)
  1823. end
  1824. def test_iCode
  1825. assert_equal( 1, @res.iCode=1)
  1826. end
  1827. def test_resSeq
  1828. assert_equal( 1, @res.resSeq=1)
  1829. end
  1830. def test_to_s
  1831. expected ="ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N \nATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C \nATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C \nATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O \nATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C \n"
  1832. assert_equal(expected, @res.to_s)
  1833. end
  1834. def test_inspect
  1835. expected = "#<Bio::PDB::Residue resName=\"ALA\" id=\"7\" chain.id=nil resSeq=7 iCode=\"\" atoms.size=5>"
  1836. assert_equal(expected,@res.inspect)
  1837. end
  1838. def test_sort #<=>
  1839. expected = [Bio::PDB::Residue.new(resName="ALA",resSeq = 6, iCode = 2, chain = nil),
  1840. Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 1, chain = nil),
  1841. Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 3, chain = nil)]
  1842. ress = [Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 1, chain = nil)]
  1843. ress << Bio::PDB::Residue.new(resName="ALA",resSeq = 6, iCode = 2, chain = nil)
  1844. ress << Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 3, chain = nil)
  1845. actual = ress.sort do |a, b|
  1846. a <=> b
  1847. end
  1848. assert_equal(expected,actual)
  1849. end
  1850. def test_update_resudue_id
  1851. res = Bio::PDB::Residue.new(resName="ALA", resSeq = nil, iCode = nil, chain = nil)
  1852. assert_equal(nil, res.residue_id)
  1853. end
  1854. end
  1855. class TestHeterogen < Test::Unit::TestCase
  1856. def setup
  1857. @res = Bio::PDB::Heterogen.new(resName="EDO",resSeq = 701, iCode = "", chain = nil)
  1858. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"))
  1859. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"))
  1860. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"))
  1861. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"))
  1862. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O"))
  1863. end
  1864. def test_get_residue_id_from_atom
  1865. id = Bio::PDB::Residue.get_residue_id_from_atom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30582 C1 EDO A 701 -0.205 -27.262 49.961 1.00 34.45 C"))
  1866. assert_equal("701",id)
  1867. end
  1868. def test_addAtom
  1869. assert_nothing_raised {
  1870. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"))
  1871. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"))
  1872. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"))
  1873. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"))
  1874. @res.addAtom(Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O"))
  1875. }
  1876. end
  1877. def test_square_bracket
  1878. expected = {
  1879. :serial=>30586,
  1880. :name=>"C1",
  1881. :altLoc=>" ",
  1882. :resName=>"EDO",
  1883. :chainID=>"A",
  1884. :resSeq=>702,
  1885. :iCode=>"",
  1886. :x=>2.792,
  1887. :y=>7.449,
  1888. :z=>67.655,
  1889. :occupancy=>1.0,
  1890. :tempFactor=>17.09,
  1891. :segID=>"",
  1892. :element=>"C",
  1893. :charge=>""
  1894. }
  1895. actual = {}
  1896. @res["C1"].each_pair do |m, v|
  1897. actual[m] = v
  1898. end
  1899. assert_equal(expected, actual)
  1900. end
  1901. def test_each_hetatm
  1902. expected = [{:z=>49.587, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>35.2, :chainID=>"A", :y=>-26.859, :segID=>"", :x=>-1.516, :name=>"O1", :charge=>"", :element=>"O", :serial=>30583}, {:z=>51.219, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>34.49, :chainID=>"A", :y=>-28.124, :segID=>"", :x=>-0.275, :name=>"C2", :charge=>"", :element=>"C", :serial=>30584}, {:z=>51.167, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>33.95, :chainID=>"A", :y=>-28.941, :segID=>"", :x=>-1.442, :name=>"O2", :charge=>"", :element=>"O", :serial=>30585}, {:z=>67.655, :resName=>"EDO", :altLoc=>" ", :resSeq=>702, :occupancy=>1.0, :iCode=>"", :tempFactor=>17.09, :chainID=>"A", :y=>7.449, :segID=>"", :x=>2.792, :name=>"C1", :charge=>"", :element=>"C", :serial=>30586}, {:z=>67.213, :resName=>"EDO", :altLoc=>" ", :resSeq=>702, :occupancy=>1.0, :iCode=>"", :tempFactor=>15.74, :chainID=>"A", :y=>7.273, :segID=>"", :x=>1.451, :name=>"O1", :charge=>"", :element=>"O", :serial=>30587}]
  1903. actual = []
  1904. @res.each_hetatm do |hetatm|
  1905. actual << {:serial=>hetatm.serial, :name=>hetatm.name, :altLoc=>hetatm.altLoc, :resName=>hetatm.resName, :chainID=>hetatm.chainID, :resSeq=>hetatm.resSeq, :iCode=>hetatm.iCode, :x=>hetatm.x, :y=>hetatm.y, :z=>hetatm.z, :occupancy=>hetatm.occupancy, :tempFactor=>hetatm.tempFactor, :segID=>hetatm.segID, :element=>hetatm.element, :charge=>hetatm.charge}
  1906. end
  1907. assert_equal(expected, actual)
  1908. end
  1909. def test_each
  1910. expected = [{:z=>49.587, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>35.2, :chainID=>"A", :y=>-26.859, :segID=>"", :x=>-1.516, :name=>"O1", :charge=>"", :element=>"O", :serial=>30583}, {:z=>51.219, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>34.49, :chainID=>"A", :y=>-28.124, :segID=>"", :x=>-0.275, :name=>"C2", :charge=>"", :element=>"C", :serial=>30584}, {:z=>51.167, :resName=>"EDO", :altLoc=>" ", :resSeq=>701, :occupancy=>1.0, :iCode=>"", :tempFactor=>33.95, :chainID=>"A", :y=>-28.941, :segID=>"", :x=>-1.442, :name=>"O2", :charge=>"", :element=>"O", :serial=>30585}, {:z=>67.655, :resName=>"EDO", :altLoc=>" ", :resSeq=>702, :occupancy=>1.0, :iCode=>"", :tempFactor=>17.09, :chainID=>"A", :y=>7.449, :segID=>"", :x=>2.792, :name=>"C1", :charge=>"", :element=>"C", :serial=>30586}, {:z=>67.213, :resName=>"EDO", :altLoc=>" ", :resSeq=>702, :occupancy=>1.0, :iCode=>"", :tempFactor=>15.74, :chainID=>"A", :y=>7.273, :segID=>"", :x=>1.451, :name=>"O1", :charge=>"", :element=>"O", :serial=>30587}]
  1911. actual = []
  1912. @res.each do |hetatm|
  1913. actual << {:serial=>hetatm.serial, :name=>hetatm.name, :altLoc=>hetatm.altLoc, :resName=>hetatm.resName, :chainID=>hetatm.chainID, :resSeq=>hetatm.resSeq, :iCode=>hetatm.iCode, :x=>hetatm.x, :y=>hetatm.y, :z=>hetatm.z, :occupancy=>hetatm.occupancy, :tempFactor=>hetatm.tempFactor, :segID=>hetatm.segID, :element=>hetatm.element, :charge=>hetatm.charge}
  1914. end
  1915. assert_equal(expected, actual)
  1916. end
  1917. def test_het_atom
  1918. assert_equal(true, @res.hetatm)
  1919. end
  1920. def test_iCode
  1921. assert_equal( 1, @res.iCode=1)
  1922. end
  1923. def test_resSeq
  1924. assert_equal( 1, @res.resSeq=1)
  1925. end
  1926. def test_to_s
  1927. expected = "HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O \nHETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C \nHETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O \nHETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C \nHETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O \n"
  1928. assert_equal(expected, @res.to_s)
  1929. end
  1930. def test_inspect
  1931. expected = "#<Bio::PDB::Heterogen resName=\"EDO\" id=\"701\" chain.id=nil resSeq=701 iCode=\"\" atoms.size=5>"
  1932. assert_equal(expected,@res.inspect)
  1933. end
  1934. def test_sort #<=>
  1935. expected = [Bio::PDB::Heterogen.new(resName="EDD",resSeq = 1, iCode = 2, chain = nil),
  1936. Bio::PDB::Heterogen.new(resName="EDD",resSeq = 1, iCode = 3, chain = nil),
  1937. Bio::PDB::Heterogen.new(resName="EDD",resSeq = 2, iCode = 1, chain = nil)]
  1938. ress = [Bio::PDB::Heterogen.new(resName="EDD",resSeq = 1, iCode = 2, chain = nil)]
  1939. ress << Bio::PDB::Heterogen.new(resName="EDD",resSeq = 1, iCode = 3, chain = nil)
  1940. ress << Bio::PDB::Heterogen.new(resName="EDD",resSeq = 2, iCode = 1, chain = nil)
  1941. actual = ress.sort do |a, b|
  1942. a <=> b
  1943. end
  1944. assert_equal(expected,actual)
  1945. end
  1946. def test_update_resudue_id
  1947. res = Bio::PDB::Heterogen.new(resName="EDD", resSeq = nil, iCode = nil, chain = nil)
  1948. assert_equal(nil, res.residue_id)
  1949. end
  1950. end
  1951. class TestChain < Test::Unit::TestCase
  1952. def setup
  1953. @chain = Bio::PDB::Chain.new('A',nil)
  1954. @chain.addResidue(Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 1, chain = @chain))
  1955. @chain.addResidue(Bio::PDB::Residue.new(resName="ALA",resSeq = 6, iCode = 2, chain = @chain))
  1956. @chain.addResidue(Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = 3, chain = @chain))
  1957. @chain.addLigand(Bio::PDB::Heterogen.new(resName="EDD",resSeq = 1, iCode = 2, chain = @chain))
  1958. end
  1959. def test_square_brace #[]
  1960. expected = {:iCode=>1,
  1961. :chain_id=>'A',
  1962. :atoms_size=>0,
  1963. :resSeq=>7,
  1964. :id=>"71",
  1965. :resName=>"ALA"}
  1966. residue = @chain["71"]
  1967. actual = {:resName => residue.resName, :id => residue.id, :chain_id => residue.chain.id, :resSeq => residue.resSeq, :iCode => residue.iCode, :atoms_size => residue.atoms.size}
  1968. assert_equal(expected, actual)
  1969. end
  1970. def test_comp #<=>
  1971. expected = [{:iCode=>2,
  1972. :chain_id=>'A',
  1973. :atoms_size=>0,
  1974. :resSeq=>6,
  1975. :id=>"62",
  1976. :resName=>"ALA"},
  1977. {:iCode=>1,
  1978. :chain_id=>'A',
  1979. :atoms_size=>0,
  1980. :resSeq=>7,
  1981. :id=>"71",
  1982. :resName=>"ALA"},
  1983. {:iCode=>3,
  1984. :chain_id=>'A',
  1985. :atoms_size=>0,
  1986. :resSeq=>7,
  1987. :id=>"73",
  1988. :resName=>"ALA"}]
  1989. sorted = @chain.sort do |a, b|
  1990. a<=>b
  1991. end
  1992. actual = []
  1993. sorted.each do |residue|
  1994. actual << {:resName => residue.resName, :id => residue.id, :chain_id => residue.chain.id, :resSeq => residue.resSeq, :iCode => residue.iCode, :atoms_size => residue.atoms.size}
  1995. end
  1996. assert_equal(expected, actual)
  1997. end
  1998. def test_addResidue
  1999. assert_nothing_raised{ @chain.addResidue(Bio::PDB::Residue.new(resName="ALA",resSeq = 9, iCode = 1, chain = @chain))}
  2000. end
  2001. def test_aaseq
  2002. assert_equal("AAA", @chain.aaseq)
  2003. end
  2004. def test_addLigand
  2005. assert_nothing_raised{ @chain.addLigand(Bio::PDB::Heterogen.new(resName="EDD",resSeq = 10, iCode = 2, chain = @chain)) }
  2006. end
  2007. def test_atom_seq
  2008. assert_equal("AAA", @chain.atom_seq)
  2009. end
  2010. def test_each
  2011. expected = [{:atoms_size=>0, :resSeq=>7, :chain_id=>'A', :iCode=>1, :id=>"71", :resName=>"ALA"}, {:atoms_size=>0, :resSeq=>6, :chain_id=>'A', :iCode=>2, :id=>"62", :resName=>"ALA"}, {:atoms_size=>0, :resSeq=>7, :chain_id=>'A', :iCode=>3, :id=>"73", :resName=>"ALA"}]
  2012. actual = []
  2013. @chain.each do |residue|
  2014. actual << {:resName => residue.resName, :id => residue.id, :chain_id => residue.chain.id, :resSeq => residue.resSeq, :iCode => residue.iCode, :atoms_size => residue.atoms.size}
  2015. end
  2016. assert_equal(expected, actual)
  2017. end
  2018. def test_each_residue
  2019. expected = [{:atoms_size=>0, :resSeq=>7, :chain_id=>'A', :iCode=>1, :id=>"71", :resName=>"ALA"}, {:atoms_size=>0, :resSeq=>6, :chain_id=>'A', :iCode=>2, :id=>"62", :resName=>"ALA"}, {:atoms_size=>0, :resSeq=>7, :chain_id=>'A', :iCode=>3, :id=>"73", :resName=>"ALA"}]
  2020. actual = []
  2021. @chain.each do |residue|
  2022. actual << {:resName => residue.resName, :id => residue.id, :chain_id => residue.chain.id, :resSeq => residue.resSeq, :iCode => residue.iCode, :atoms_size => residue.atoms.size}
  2023. end
  2024. assert_equal(expected, actual)
  2025. end
  2026. def test_each_heterogen
  2027. expected = [{:iCode=>2,
  2028. :chain_id=>'A',
  2029. :resSeq=>1,
  2030. :id=>"12",
  2031. :atoms_size=>0,
  2032. :resName=>"EDD"}]
  2033. actual = []
  2034. @chain.each_heterogen do |heterogen|
  2035. actual << {:resName => heterogen.resName, :id => heterogen.id, :chain_id => heterogen.chain.id, :resSeq => heterogen.resSeq, :iCode => heterogen.iCode, :atoms_size => heterogen.atoms.size}
  2036. end
  2037. assert_equal(expected, actual)
  2038. end
  2039. def test_get_heterogen_by_id
  2040. heterogen = @chain.get_heterogen_by_id("12")
  2041. expected = {:iCode=>2,
  2042. :chain_id=>'A',
  2043. :resSeq=>1,
  2044. :id=>"12",
  2045. :atoms_size=>0,
  2046. :resName=>"EDD"}
  2047. actual = {:resName => heterogen.resName, :id => heterogen.id, :chain_id => heterogen.chain.id, :resSeq => heterogen.resSeq, :iCode => heterogen.iCode, :atoms_size => heterogen.atoms.size}
  2048. assert_equal(expected, actual)
  2049. end
  2050. def test_get_residue_by_id
  2051. residue = @chain.get_residue_by_id("71")
  2052. expected = {:atoms_size=>0, :resSeq=>7, :chain_id=>'A', :iCode=>1, :id=>"71", :resName=>"ALA"}
  2053. actual = {:resName => residue.resName, :id => residue.id, :chain_id => residue.chain.id, :resSeq => residue.resSeq, :iCode => residue.iCode, :atoms_size => residue.atoms.size}
  2054. assert_equal(expected, actual)
  2055. end
  2056. def test_inspect
  2057. expected = "#<Bio::PDB::Chain id=\"A\" model.serial=nil residues.size=3 heterogens.size=1 aaseq=\"AAA\">"
  2058. assert_equal(expected, @chain.inspect)
  2059. end
  2060. def test_rehash
  2061. assert_nothing_raised{@chain.rehash}
  2062. end
  2063. def test_rehash_heterogens
  2064. assert_nothing_raised{@chain.rehash_heterogens}
  2065. #assert_raise{@chain.rehash_heterogens}
  2066. end
  2067. def test_rehash_residues
  2068. assert_nothing_raised{@chain.rehash_residues}
  2069. end
  2070. def test_to_s
  2071. assert_equal("TER\n",@chain.to_s)
  2072. end
  2073. end
  2074. class TestModel < Test::Unit::TestCase
  2075. def setup
  2076. @model = Bio::PDB::Model.new(1,nil)
  2077. @model.addChain(Bio::PDB::Chain.new(1, @model))
  2078. @model.addChain(Bio::PDB::Chain.new(2, @model))
  2079. @model.addChain(Bio::PDB::Chain.new(3, @model))
  2080. end
  2081. def test_square_brace #[]
  2082. expected = {:id=>1, :model_serial=>1, :residues_size=>0, :heterogens_size=>0, :aaseq=>""}
  2083. residue = @model[1]
  2084. actual = {:id=>residue.id, :model_serial=>residue.model.serial, :residues_size=>residue.residues.size, :heterogens_size=>residue.heterogens.size, :aaseq=>residue.aaseq}
  2085. assert_equal(expected, actual)
  2086. end
  2087. def test_comp #<=>
  2088. models = [Bio::PDB::Model.new(2,nil), Bio::PDB::Model.new(1,nil), Bio::PDB::Model.new(3,nil)]
  2089. expected = [{:serial=>1, :chains_size=>0},
  2090. {:serial=>2, :chains_size=>0},
  2091. {:serial=>3, :chains_size=>0}]
  2092. sorted = models.sort do |a, b|
  2093. a<=>b
  2094. end
  2095. actual = []
  2096. sorted.each do |model|
  2097. actual << {:serial => model.serial, :chains_size => model.chains.size }
  2098. end
  2099. assert_equal(expected, actual)
  2100. end
  2101. def test_addChain
  2102. assert_nothing_raised{ @model.addChain(Bio::PDB::Chain.new("D", @model))}
  2103. end
  2104. def test_each
  2105. expected = [{:model_serial=>1,
  2106. :aaseq=>"",
  2107. :residues_size=>0,
  2108. :heterogens_size=>0,
  2109. :id=>1},
  2110. {:model_serial=>1,
  2111. :aaseq=>"",
  2112. :residues_size=>0,
  2113. :heterogens_size=>0,
  2114. :id=>2},
  2115. {:model_serial=>1,
  2116. :aaseq=>"",
  2117. :residues_size=>0,
  2118. :heterogens_size=>0,
  2119. :id=>3}]
  2120. actual = []
  2121. @model.each do |m|
  2122. actual << {:id => m.id, :model_serial => m.model.serial, :residues_size => m.residues.size, :heterogens_size => m.heterogens.size, :aaseq => m.aaseq }
  2123. end
  2124. assert_equal(expected, actual)
  2125. end
  2126. def test_each_chain
  2127. expected = [{:model_serial=>1,
  2128. :aaseq=>"",
  2129. :residues_size=>0,
  2130. :heterogens_size=>0,
  2131. :id=>1},
  2132. {:model_serial=>1,
  2133. :aaseq=>"",
  2134. :residues_size=>0,
  2135. :heterogens_size=>0,
  2136. :id=>2},
  2137. {:model_serial=>1,
  2138. :aaseq=>"",
  2139. :residues_size=>0,
  2140. :heterogens_size=>0,
  2141. :id=>3}]
  2142. actual = []
  2143. @model.each_chain do |m|
  2144. actual << {:id => m.id, :model_serial => m.model.serial, :residues_size => m.residues.size, :heterogens_size => m.heterogens.size, :aaseq => m.aaseq }
  2145. end
  2146. assert_equal(expected, actual)
  2147. end
  2148. def test_inspect
  2149. expected = "#<Bio::PDB::Model serial=1 chains.size=3>"
  2150. assert_equal(expected, @model.inspect)
  2151. end
  2152. def test_rehash
  2153. assert_nothing_raised{@model.rehash}
  2154. end
  2155. def test_to_s
  2156. assert_equal("MODEL 1\nTER\nTER\nTER\nENDMDL\n",@model.to_s)
  2157. end
  2158. end
  2159. #this class tests Bio::PDB::Utils with Bio::PDB::Residue class witch is generated directly
  2160. class TestUtils < Test::Unit::TestCase
  2161. def setup
  2162. @res = Bio::PDB::Residue.new(resName="ALA",resSeq = 7, iCode = "", chain = nil)
  2163. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 1 N ALA A 7 23.484 -35.866 44.510 1.00 28.52 N"))
  2164. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"))
  2165. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 3 C ALA A 7 23.102 -34.082 46.159 1.00 26.68 C"))
  2166. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 4 O ALA A 7 23.097 -32.903 46.524 1.00 30.02 O"))
  2167. @res.addAtom(Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 5 CB ALA A 7 23.581 -33.526 43.770 1.00 31.41 C"))
  2168. end
  2169. def test_geometricCentre
  2170. assert_instance_of(Bio::PDB::Coordinate,@res.geometricCentre())
  2171. # assert_equal(Vector[23.4226, -34.1772, 45.1734], @res.geometricCentre())
  2172. expected = [ 23.4226, -34.1772, 45.1734 ]
  2173. @res.geometricCentre().to_a.each do |num|
  2174. assert_in_delta(expected.shift, num, 0.001)
  2175. end
  2176. assert(expected.empty?)
  2177. end
  2178. def test_centreOfGravity
  2179. assert_instance_of(Bio::PDB::Coordinate,@res.centreOfGravity())
  2180. expected = [ 23.4047272727273, -34.1511515151515, 45.2351515151515 ]
  2181. @res.centreOfGravity().to_a.each do |num|
  2182. assert_in_delta(expected.shift, num, 0.001)
  2183. end
  2184. assert(expected.empty?)
  2185. end
  2186. def test_distance
  2187. actual1 = Bio::PDB::Utils.distance(
  2188. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2189. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 7 CA VAL A 8 21.887 -34.822 48.124 1.00 23.78 C")
  2190. )
  2191. actual2 = Bio::PDB::Utils.distance([23.849, -34.509, 44.904], [21.887, -34.822, 48.124])
  2192. assert_in_delta(3.78362432067456, actual1, 0.001)
  2193. assert_in_delta(3.78362432067456, actual2, 0.001)
  2194. end
  2195. def test_dihedral_angle
  2196. actual1 = Bio::PDB::Utils.dihedral_angle(
  2197. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2198. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 7 CA VAL A 8 21.887 -34.822 48.124 1.00 23.78 C"),
  2199. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 14 CA PRO A 9 24.180 -35.345 51.107 1.00 22.35 C"),
  2200. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 21 CA ALA A 10 23.833 -38.844 52.579 1.00 23.41 C")
  2201. )
  2202. actual2 = Bio::PDB::Utils.dihedral_angle(
  2203. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 34.509 44.904 1.00 27.89 C"),
  2204. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 7 CA VAL A 8 21.887 34.822 48.124 1.00 23.78 C"),
  2205. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 14 CA PRO A 9 24.180 35.345 51.107 1.00 22.35 C"),
  2206. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 21 CA ALA A 10 23.833 38.844 52.579 1.00 23.41 C")
  2207. )
  2208. assert_in_delta(-1.94387328933899, actual1, 0.001)
  2209. assert_in_delta( 1.94387328933899, actual2, 0.001)
  2210. end
  2211. def test_rad2deg
  2212. deg = Bio::PDB::Utils::rad2deg(3.14159265358979)
  2213. assert_in_delta(180.0, deg, 0.0000000001)
  2214. end
  2215. end #class Test_Utils
  2216. #The following classes is unit tests for Test_*Finder
  2217. #The sample data are arrays generated from corresponding Bio::PDB::* classes, witch has Bio::PDB::Utils::*Finder
  2218. class TestModelFinder < Test::Unit::TestCase
  2219. def setup
  2220. @models = [Bio::PDB::Model.new(1), Bio::PDB::Model.new(2), Bio::PDB::Model.new(3)]
  2221. def @models.each_model
  2222. self.each do |model|
  2223. yield model
  2224. end
  2225. end
  2226. @models.extend(Bio::PDB::ModelFinder)
  2227. end
  2228. def test_find_model
  2229. expected = [Bio::PDB::Model.new(1), Bio::PDB::Model.new(2), Bio::PDB::Model.new(3)]
  2230. actual = @models.find_model{|m| true}
  2231. assert_equal(expected,actual)
  2232. end
  2233. end
  2234. class TestChainFinder < Test::Unit::TestCase
  2235. def setup
  2236. @model = [Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3)]
  2237. end
  2238. def test_find_chain
  2239. def @model.each_chain
  2240. self.each do |chain|
  2241. yield chain
  2242. end
  2243. end
  2244. @model.extend(Bio::PDB::ChainFinder)
  2245. expected = [Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3)]
  2246. actual = @model.find_chain{|m| true}
  2247. assert_equal(expected,actual)
  2248. end
  2249. def test_each_chain
  2250. expected = [Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3), Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3)]
  2251. models = [@model,@model]
  2252. def models.each_model
  2253. self.each do |model|
  2254. yield model
  2255. end
  2256. end
  2257. models.extend(Bio::PDB::ChainFinder)
  2258. actual = []
  2259. models.each_chain{|chain| actual << chain}
  2260. assert_equal(expected, actual)
  2261. end
  2262. def test_chains
  2263. expected = [Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3), Bio::PDB::Chain.new(1), Bio::PDB::Chain.new(2), Bio::PDB::Chain.new(3)]
  2264. @model.instance_eval{
  2265. def chains
  2266. return self
  2267. end
  2268. }
  2269. models = [@model,@model]
  2270. def models.each_model
  2271. self.each do |model|
  2272. yield model
  2273. end
  2274. end
  2275. models.extend(Bio::PDB::ChainFinder)
  2276. models.extend(Bio::PDB::ModelFinder)
  2277. actual = models.chains
  2278. assert_equal(expected,actual)
  2279. end
  2280. end #TestChainFinder
  2281. class TestResidueFinder < Test::Unit::TestCase
  2282. def setup
  2283. @residues = [Bio::PDB::Residue.new("",1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3)]
  2284. end
  2285. def test_find_residue
  2286. def @residues.each_residue
  2287. self.each do |residue|
  2288. yield residue
  2289. end
  2290. end
  2291. @residues.extend(Bio::PDB::ResidueFinder)
  2292. # expected = [Bio::PDB::Residue.new("",1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3)]
  2293. expected = [
  2294. {:resName=>"", :id=>"1", :chain=>nil, :resSeq=>1, :iCode=>nil, :atoms_size=>0},
  2295. {:resName=>"", :id=>"2", :chain=>nil, :resSeq=>2, :iCode=>nil, :atoms_size=>0},
  2296. {:resName=>"", :id=>"3", :chain=>nil, :resSeq=>3, :iCode=>nil, :atoms_size=>0},
  2297. ]
  2298. finded = @residues.find_residue{|m| true}
  2299. actual = []
  2300. finded.each do |res|
  2301. actual << {:resName=> res.resName, :id=> res.id, :chain=> res.chain, :resSeq=> res.resSeq, :iCode=> res.iCode, :atoms_size=> res.atoms.size}
  2302. end
  2303. assert_equal(expected,actual)
  2304. end
  2305. def test_each_residue
  2306. # expected = [Bio::PDB::Residue.new("", 1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3), Bio::PDB::Residue.new("",1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3)]
  2307. expected = [
  2308. {:resName=>"", :id=>"1", :chain=>nil, :resSeq=>1, :iCode=>nil, :atoms_size=>0},
  2309. {:resName=>"", :id=>"2", :chain=>nil, :resSeq=>2, :iCode=>nil, :atoms_size=>0},
  2310. {:resName=>"", :id=>"3", :chain=>nil, :resSeq=>3, :iCode=>nil, :atoms_size=>0},
  2311. {:resName=>"", :id=>"1", :chain=>nil, :resSeq=>1, :iCode=>nil, :atoms_size=>0},
  2312. {:resName=>"", :id=>"2", :chain=>nil, :resSeq=>2, :iCode=>nil, :atoms_size=>0},
  2313. {:resName=>"", :id=>"3", :chain=>nil, :resSeq=>3, :iCode=>nil, :atoms_size=>0}
  2314. ]
  2315. chains = [@residues,@residues]
  2316. def chains.each_chain
  2317. self.each do |chain|
  2318. yield chain
  2319. end
  2320. end
  2321. chains.extend(Bio::PDB::ResidueFinder)
  2322. actual = []
  2323. chains.each_residue do |res|
  2324. actual << {:resName=> res.resName, :id=> res.id, :chain=> res.chain, :resSeq=> res.resSeq, :iCode=> res.iCode, :atoms_size=> res.atoms.size}
  2325. end
  2326. assert_equal(expected, actual)
  2327. end
  2328. def test_residues
  2329. # expected = [Bio::PDB::Residue.new("", 1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3), Bio::PDB::Residue.new("",1), Bio::PDB::Residue.new("",2), Bio::PDB::Residue.new("",3)]
  2330. expected = [
  2331. {:resName=>"", :id=>"1", :chain=>nil, :resSeq=>1, :iCode=>nil, :atoms_size=>0},
  2332. {:resName=>"", :id=>"2", :chain=>nil, :resSeq=>2, :iCode=>nil, :atoms_size=>0},
  2333. {:resName=>"", :id=>"3", :chain=>nil, :resSeq=>3, :iCode=>nil, :atoms_size=>0},
  2334. {:resName=>"", :id=>"1", :chain=>nil, :resSeq=>1, :iCode=>nil, :atoms_size=>0},
  2335. {:resName=>"", :id=>"2", :chain=>nil, :resSeq=>2, :iCode=>nil, :atoms_size=>0},
  2336. {:resName=>"", :id=>"3", :chain=>nil, :resSeq=>3, :iCode=>nil, :atoms_size=>0}]
  2337. @residues.instance_eval{
  2338. def residues
  2339. return self
  2340. end
  2341. }
  2342. chains = [@residues,@residues]
  2343. def chains.each_chain
  2344. self.each do |chain|
  2345. yield chain
  2346. end
  2347. end
  2348. chains.extend(Bio::PDB::ResidueFinder)
  2349. chains.extend(Bio::PDB::ChainFinder)
  2350. actual = []
  2351. chains.residues.each do |res|
  2352. actual << {:resName=> res.resName, :id=> res.id, :chain=> res.chain, :resSeq=> res.resSeq, :iCode=> res.iCode, :atoms_size=> res.atoms.size}
  2353. end
  2354. assert_equal(expected,actual)
  2355. end
  2356. end #TestResidueFinder
  2357. class TestAtomFinder < Test::Unit::TestCase
  2358. def setup
  2359. @atoms = [Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2360. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2361. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C")]
  2362. end
  2363. def test_find_atom
  2364. expected =
  2365. [Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2366. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2367. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C")]
  2368. def @atoms.each_atom
  2369. self.each do |atom|
  2370. yield atom
  2371. end
  2372. end
  2373. @atoms.extend(Bio::PDB::AtomFinder)
  2374. actual = @atoms.find_atom{|a| true}
  2375. assert_equal(expected,actual)
  2376. end
  2377. def test_each_atom
  2378. expected = [
  2379. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2380. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2381. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2382. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2383. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2384. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C")
  2385. ]
  2386. residues = [@atoms,@atoms]
  2387. def residues.each_residue
  2388. self.each do |residue|
  2389. yield residue
  2390. end
  2391. end
  2392. residues.extend(Bio::PDB::AtomFinder)
  2393. actual = []
  2394. residues.each_atom{|atom| actual << atom}
  2395. assert_equal(expected, actual)
  2396. end
  2397. def test_atoms
  2398. expected = [
  2399. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2400. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2401. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2402. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2403. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C"),
  2404. Bio::PDB::Record::ATOM.new.initialize_from_string("ATOM 2 CA ALA A 7 23.849 -34.509 44.904 1.00 27.89 C")
  2405. ]
  2406. @atoms.instance_eval{
  2407. def atoms
  2408. return self
  2409. end
  2410. }
  2411. residues = [@atoms,@atoms]
  2412. def residues.each_residue
  2413. self.each do |atom|
  2414. yield atom
  2415. end
  2416. end
  2417. residues.extend(Bio::PDB::AtomFinder)
  2418. residues.extend(Bio::PDB::ResidueFinder)
  2419. actual = residues.atoms
  2420. assert_equal(expected,actual)
  2421. end
  2422. end #AtomFinder
  2423. class TestHetatmFinder < Test::Unit::TestCase
  2424. def setup
  2425. @hetatms =
  2426. [Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2427. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2428. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2429. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2430. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O")
  2431. ]
  2432. end
  2433. def test_find_hetatm
  2434. expected =
  2435. [Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2436. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2437. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2438. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2439. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O")
  2440. ]
  2441. def @hetatms.each_hetatm
  2442. self.each do |hetatm|
  2443. yield hetatm
  2444. end
  2445. end
  2446. @hetatms.extend(Bio::PDB::HetatmFinder)
  2447. actual = @hetatms.find_hetatm{|a| true}
  2448. assert_equal(expected,actual)
  2449. end
  2450. def test_each_hetatm
  2451. expected = [
  2452. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2453. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2454. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2455. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2456. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O"),
  2457. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2458. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2459. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2460. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2461. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O")
  2462. ]
  2463. heterogens = [@hetatms,@hetatms]
  2464. def heterogens.each_heterogen
  2465. self.each do |heterogen|
  2466. yield heterogen
  2467. end
  2468. end
  2469. heterogens.extend(Bio::PDB::HetatmFinder)
  2470. actual = []
  2471. heterogens.each_hetatm{|hetatm| actual << hetatm}
  2472. assert_equal(expected, actual)
  2473. end
  2474. def test_hetatms
  2475. expected = [
  2476. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2477. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2478. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2479. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2480. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O"),
  2481. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30583 O1 EDO A 701 -1.516 -26.859 49.587 1.00 35.20 O"),
  2482. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30584 C2 EDO A 701 -0.275 -28.124 51.219 1.00 34.49 C"),
  2483. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30585 O2 EDO A 701 -1.442 -28.941 51.167 1.00 33.95 O"),
  2484. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30586 C1 EDO A 702 2.792 7.449 67.655 1.00 17.09 C"),
  2485. Bio::PDB::Record::HETATM.new.initialize_from_string("HETATM30587 O1 EDO A 702 1.451 7.273 67.213 1.00 15.74 O")
  2486. ]
  2487. @hetatms.instance_eval{
  2488. def hetatms
  2489. return self
  2490. end
  2491. }
  2492. heterogens = [@hetatms,@hetatms]
  2493. def heterogens.each_heterogen
  2494. self.each do |heterogen|
  2495. yield heterogen
  2496. end
  2497. end
  2498. heterogens.extend(Bio::PDB::HetatmFinder)
  2499. heterogens.extend(Bio::PDB::HeterogenFinder)
  2500. actual = heterogens.hetatms
  2501. assert_equal(expected,actual)
  2502. end
  2503. end #HetatmFinder
  2504. class TestHeterogenFinder < Test::Unit::TestCase
  2505. def setup
  2506. @heterogens =
  2507. [Bio::PDB::Heterogen.new(),
  2508. Bio::PDB::Heterogen.new(),
  2509. Bio::PDB::Heterogen.new(),
  2510. Bio::PDB::Heterogen.new()
  2511. ]
  2512. end
  2513. def test_find_heterogen
  2514. def @heterogens.each_heterogen
  2515. self.each do |heterogen|
  2516. yield heterogen
  2517. end
  2518. end
  2519. @heterogens.extend(Bio::PDB::HeterogenFinder)
  2520. expected = [
  2521. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2522. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2523. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2524. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2525. ]
  2526. hets = @heterogens.find_heterogen{|a| true}
  2527. actual = []
  2528. hets.each do |het|
  2529. actual << {:resName=> het.resName, :id=> het.id, :chain=> het.chain, :resSeq=> het.resSeq, :iCode=> het.iCode, :atoms_size=> het.atoms.size}
  2530. end
  2531. assert_equal(expected,actual)
  2532. end
  2533. def test_each_heterogen
  2534. # expected = [
  2535. # Bio::PDB::Heterogen.new(),
  2536. # Bio::PDB::Heterogen.new(),
  2537. # Bio::PDB::Heterogen.new(),
  2538. # Bio::PDB::Heterogen.new(),
  2539. # Bio::PDB::Heterogen.new(),
  2540. # Bio::PDB::Heterogen.new(),
  2541. # Bio::PDB::Heterogen.new(),
  2542. # Bio::PDB::Heterogen.new()
  2543. # ]
  2544. expected = [
  2545. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2546. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2547. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2548. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2549. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2550. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2551. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2552. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0}
  2553. ]
  2554. def @heterogens.each_heterogen
  2555. self.each do |heterogen|
  2556. yield heterogen
  2557. end
  2558. end
  2559. chains = [@heterogens,@heterogens]
  2560. def chains.each_chain
  2561. self.each do |chain|
  2562. yield chain
  2563. end
  2564. end
  2565. chains.extend(Bio::PDB::HeterogenFinder)
  2566. actual = []
  2567. chains.each_heterogen do |het|
  2568. actual << {:resName=> het.resName, :id=> het.id, :chain=> het.chain, :resSeq=> het.resSeq, :iCode=> het.iCode, :atoms_size=> het.atoms.size}
  2569. end
  2570. assert_equal(expected, actual)
  2571. end
  2572. def test_heterogens
  2573. # expected = [
  2574. # Bio::PDB::Heterogen.new(),
  2575. # Bio::PDB::Heterogen.new(),
  2576. # Bio::PDB::Heterogen.new(),
  2577. # Bio::PDB::Heterogen.new(),
  2578. # Bio::PDB::Heterogen.new(),
  2579. # Bio::PDB::Heterogen.new(),
  2580. # Bio::PDB::Heterogen.new(),
  2581. # Bio::PDB::Heterogen.new()
  2582. # ]
  2583. expected = [
  2584. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2585. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2586. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2587. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2588. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2589. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2590. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0},
  2591. {:resName=>nil, :id=>nil, :chain=>nil, :resSeq=>nil, :iCode=>nil, :atoms_size=>0}
  2592. ]
  2593. @heterogens.instance_eval{
  2594. def heterogens
  2595. return self
  2596. end
  2597. }
  2598. chains = [@heterogens,@heterogens]
  2599. def chains.each_chain
  2600. self.each do |chain|
  2601. yield chain
  2602. end
  2603. end
  2604. chains.extend(Bio::PDB::HeterogenFinder)
  2605. chains.extend(Bio::PDB::ChainFinder)
  2606. hets = chains.heterogens
  2607. actual = []
  2608. hets.each do |het|
  2609. actual << {:resName=> het.resName, :id=> het.id, :chain=> het.chain, :resSeq=> het.resSeq, :iCode=> het.iCode, :atoms_size=> het.atoms.size}
  2610. end
  2611. assert_equal(expected,actual)
  2612. end
  2613. end #HetatmFinder
  2614. end #module Bio