jandot-bio 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (335) hide show
  1. data/bin/bioruby +44 -0
  2. data/bin/br_biofetch.rb +47 -0
  3. data/bin/br_bioflat.rb +282 -0
  4. data/bin/br_biogetseq.rb +45 -0
  5. data/bin/br_pmfetch.rb +421 -0
  6. data/doc/Changes-0.7.rd +369 -0
  7. data/doc/KEGG_API.rd +1843 -0
  8. data/doc/KEGG_API.rd.ja +1834 -0
  9. data/doc/Tutorial.rd +1296 -0
  10. data/doc/Tutorial.rd.ja +2640 -0
  11. data/etc/bioinformatics/seqdatabase.ini +210 -0
  12. data/lib/bio.rb +279 -0
  13. data/lib/bio/alignment.rb +2518 -0
  14. data/lib/bio/appl/bl2seq/report.rb +334 -0
  15. data/lib/bio/appl/blast.rb +351 -0
  16. data/lib/bio/appl/blast/format0.rb +1438 -0
  17. data/lib/bio/appl/blast/format8.rb +83 -0
  18. data/lib/bio/appl/blast/report.rb +516 -0
  19. data/lib/bio/appl/blast/rexml.rb +135 -0
  20. data/lib/bio/appl/blast/rpsblast.rb +176 -0
  21. data/lib/bio/appl/blast/wublast.rb +550 -0
  22. data/lib/bio/appl/blast/xmlparser.rb +228 -0
  23. data/lib/bio/appl/blat/report.rb +489 -0
  24. data/lib/bio/appl/clustalw.rb +219 -0
  25. data/lib/bio/appl/clustalw/report.rb +152 -0
  26. data/lib/bio/appl/emboss.rb +203 -0
  27. data/lib/bio/appl/fasta.rb +237 -0
  28. data/lib/bio/appl/fasta/format10.rb +325 -0
  29. data/lib/bio/appl/gcg/msf.rb +212 -0
  30. data/lib/bio/appl/gcg/seq.rb +195 -0
  31. data/lib/bio/appl/genscan/report.rb +552 -0
  32. data/lib/bio/appl/hmmer.rb +126 -0
  33. data/lib/bio/appl/hmmer/report.rb +683 -0
  34. data/lib/bio/appl/iprscan/report.rb +374 -0
  35. data/lib/bio/appl/mafft.rb +259 -0
  36. data/lib/bio/appl/mafft/report.rb +226 -0
  37. data/lib/bio/appl/muscle.rb +52 -0
  38. data/lib/bio/appl/phylip/alignment.rb +129 -0
  39. data/lib/bio/appl/phylip/distance_matrix.rb +96 -0
  40. data/lib/bio/appl/probcons.rb +41 -0
  41. data/lib/bio/appl/psort.rb +548 -0
  42. data/lib/bio/appl/psort/report.rb +457 -0
  43. data/lib/bio/appl/pts1.rb +263 -0
  44. data/lib/bio/appl/sim4.rb +124 -0
  45. data/lib/bio/appl/sim4/report.rb +485 -0
  46. data/lib/bio/appl/sosui/report.rb +151 -0
  47. data/lib/bio/appl/spidey/report.rb +593 -0
  48. data/lib/bio/appl/targetp/report.rb +267 -0
  49. data/lib/bio/appl/tcoffee.rb +55 -0
  50. data/lib/bio/appl/tmhmm/report.rb +222 -0
  51. data/lib/bio/command.rb +337 -0
  52. data/lib/bio/data/aa.rb +349 -0
  53. data/lib/bio/data/codontable.rb +722 -0
  54. data/lib/bio/data/na.rb +223 -0
  55. data/lib/bio/db.rb +329 -0
  56. data/lib/bio/db/aaindex.rb +357 -0
  57. data/lib/bio/db/embl/common.rb +336 -0
  58. data/lib/bio/db/embl/embl.rb +402 -0
  59. data/lib/bio/db/embl/sptr.rb +1283 -0
  60. data/lib/bio/db/embl/swissprot.rb +42 -0
  61. data/lib/bio/db/embl/trembl.rb +41 -0
  62. data/lib/bio/db/embl/uniprot.rb +42 -0
  63. data/lib/bio/db/fantom.rb +599 -0
  64. data/lib/bio/db/fasta.rb +907 -0
  65. data/lib/bio/db/genbank/common.rb +290 -0
  66. data/lib/bio/db/genbank/ddbj.rb +22 -0
  67. data/lib/bio/db/genbank/genbank.rb +215 -0
  68. data/lib/bio/db/genbank/genpept.rb +60 -0
  69. data/lib/bio/db/genbank/refseq.rb +18 -0
  70. data/lib/bio/db/gff.rb +174 -0
  71. data/lib/bio/db/go.rb +481 -0
  72. data/lib/bio/db/kegg/brite.rb +41 -0
  73. data/lib/bio/db/kegg/compound.rb +131 -0
  74. data/lib/bio/db/kegg/drug.rb +98 -0
  75. data/lib/bio/db/kegg/enzyme.rb +148 -0
  76. data/lib/bio/db/kegg/expression.rb +155 -0
  77. data/lib/bio/db/kegg/genes.rb +263 -0
  78. data/lib/bio/db/kegg/genome.rb +241 -0
  79. data/lib/bio/db/kegg/glycan.rb +170 -0
  80. data/lib/bio/db/kegg/keggtab.rb +357 -0
  81. data/lib/bio/db/kegg/kgml.rb +256 -0
  82. data/lib/bio/db/kegg/orthology.rb +136 -0
  83. data/lib/bio/db/kegg/reaction.rb +82 -0
  84. data/lib/bio/db/kegg/taxonomy.rb +331 -0
  85. data/lib/bio/db/lasergene.rb +209 -0
  86. data/lib/bio/db/litdb.rb +107 -0
  87. data/lib/bio/db/medline.rb +323 -0
  88. data/lib/bio/db/nbrf.rb +191 -0
  89. data/lib/bio/db/newick.rb +658 -0
  90. data/lib/bio/db/nexus.rb +1854 -0
  91. data/lib/bio/db/pdb.rb +29 -0
  92. data/lib/bio/db/pdb/atom.rb +77 -0
  93. data/lib/bio/db/pdb/chain.rb +210 -0
  94. data/lib/bio/db/pdb/chemicalcomponent.rb +224 -0
  95. data/lib/bio/db/pdb/model.rb +148 -0
  96. data/lib/bio/db/pdb/pdb.rb +1911 -0
  97. data/lib/bio/db/pdb/residue.rb +176 -0
  98. data/lib/bio/db/pdb/utils.rb +399 -0
  99. data/lib/bio/db/prosite.rb +597 -0
  100. data/lib/bio/db/rebase.rb +457 -0
  101. data/lib/bio/db/soft.rb +404 -0
  102. data/lib/bio/db/transfac.rb +375 -0
  103. data/lib/bio/feature.rb +226 -0
  104. data/lib/bio/io/das.rb +461 -0
  105. data/lib/bio/io/dbget.rb +194 -0
  106. data/lib/bio/io/ddbjxml.rb +581 -0
  107. data/lib/bio/io/ebisoap.rb +158 -0
  108. data/lib/bio/io/ensembl.rb +229 -0
  109. data/lib/bio/io/fastacmd.rb +163 -0
  110. data/lib/bio/io/fetch.rb +181 -0
  111. data/lib/bio/io/flatfile.rb +1309 -0
  112. data/lib/bio/io/flatfile/bdb.rb +253 -0
  113. data/lib/bio/io/flatfile/index.rb +1371 -0
  114. data/lib/bio/io/flatfile/indexer.rb +787 -0
  115. data/lib/bio/io/higet.rb +73 -0
  116. data/lib/bio/io/hinv.rb +442 -0
  117. data/lib/bio/io/keggapi.rb +805 -0
  118. data/lib/bio/io/ncbirest.rb +256 -0
  119. data/lib/bio/io/ncbisoap.rb +155 -0
  120. data/lib/bio/io/pubmed.rb +307 -0
  121. data/lib/bio/io/registry.rb +292 -0
  122. data/lib/bio/io/soapwsdl.rb +119 -0
  123. data/lib/bio/io/sql.rb +365 -0
  124. data/lib/bio/location.rb +772 -0
  125. data/lib/bio/map.rb +410 -0
  126. data/lib/bio/pathway.rb +854 -0
  127. data/lib/bio/reference.rb +623 -0
  128. data/lib/bio/sequence.rb +475 -0
  129. data/lib/bio/sequence/aa.rb +125 -0
  130. data/lib/bio/sequence/common.rb +333 -0
  131. data/lib/bio/sequence/compat.rb +123 -0
  132. data/lib/bio/sequence/format.rb +181 -0
  133. data/lib/bio/sequence/generic.rb +24 -0
  134. data/lib/bio/sequence/na.rb +491 -0
  135. data/lib/bio/shell.rb +44 -0
  136. data/lib/bio/shell/core.rb +578 -0
  137. data/lib/bio/shell/demo.rb +146 -0
  138. data/lib/bio/shell/interface.rb +218 -0
  139. data/lib/bio/shell/irb.rb +95 -0
  140. data/lib/bio/shell/object.rb +71 -0
  141. data/lib/bio/shell/plugin/blast.rb +42 -0
  142. data/lib/bio/shell/plugin/codon.rb +218 -0
  143. data/lib/bio/shell/plugin/das.rb +58 -0
  144. data/lib/bio/shell/plugin/emboss.rb +23 -0
  145. data/lib/bio/shell/plugin/entry.rb +105 -0
  146. data/lib/bio/shell/plugin/flatfile.rb +101 -0
  147. data/lib/bio/shell/plugin/keggapi.rb +181 -0
  148. data/lib/bio/shell/plugin/midi.rb +430 -0
  149. data/lib/bio/shell/plugin/obda.rb +45 -0
  150. data/lib/bio/shell/plugin/psort.rb +56 -0
  151. data/lib/bio/shell/plugin/seq.rb +247 -0
  152. data/lib/bio/shell/plugin/soap.rb +87 -0
  153. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/bioruby_generator.rb +29 -0
  154. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_classes.rhtml +4 -0
  155. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_log.rhtml +27 -0
  156. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_methods.rhtml +11 -0
  157. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_modules.rhtml +4 -0
  158. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/_variables.rhtml +7 -0
  159. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-bg.gif +0 -0
  160. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-gem.png +0 -0
  161. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby-link.gif +0 -0
  162. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.css +368 -0
  163. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby.rhtml +47 -0
  164. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb +144 -0
  165. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_helper.rb +47 -0
  166. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/commands.rhtml +8 -0
  167. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/history.rhtml +10 -0
  168. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/index.rhtml +26 -0
  169. data/lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/spinner.gif +0 -0
  170. data/lib/bio/shell/script.rb +25 -0
  171. data/lib/bio/shell/setup.rb +109 -0
  172. data/lib/bio/shell/web.rb +102 -0
  173. data/lib/bio/tree.rb +850 -0
  174. data/lib/bio/util/color_scheme.rb +191 -0
  175. data/lib/bio/util/color_scheme/buried.rb +59 -0
  176. data/lib/bio/util/color_scheme/helix.rb +59 -0
  177. data/lib/bio/util/color_scheme/hydropathy.rb +64 -0
  178. data/lib/bio/util/color_scheme/nucleotide.rb +31 -0
  179. data/lib/bio/util/color_scheme/strand.rb +59 -0
  180. data/lib/bio/util/color_scheme/taylor.rb +50 -0
  181. data/lib/bio/util/color_scheme/turn.rb +59 -0
  182. data/lib/bio/util/color_scheme/zappo.rb +50 -0
  183. data/lib/bio/util/contingency_table.rb +370 -0
  184. data/lib/bio/util/restriction_enzyme.rb +228 -0
  185. data/lib/bio/util/restriction_enzyme/analysis.rb +249 -0
  186. data/lib/bio/util/restriction_enzyme/analysis_basic.rb +217 -0
  187. data/lib/bio/util/restriction_enzyme/cut_symbol.rb +107 -0
  188. data/lib/bio/util/restriction_enzyme/double_stranded.rb +321 -0
  189. data/lib/bio/util/restriction_enzyme/double_stranded/aligned_strands.rb +130 -0
  190. data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair.rb +103 -0
  191. data/lib/bio/util/restriction_enzyme/double_stranded/cut_location_pair_in_enzyme_notation.rb +38 -0
  192. data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations.rb +76 -0
  193. data/lib/bio/util/restriction_enzyme/double_stranded/cut_locations_in_enzyme_notation.rb +107 -0
  194. data/lib/bio/util/restriction_enzyme/enzymes.yaml +7061 -0
  195. data/lib/bio/util/restriction_enzyme/range/cut_range.rb +24 -0
  196. data/lib/bio/util/restriction_enzyme/range/cut_ranges.rb +47 -0
  197. data/lib/bio/util/restriction_enzyme/range/horizontal_cut_range.rb +67 -0
  198. data/lib/bio/util/restriction_enzyme/range/sequence_range.rb +257 -0
  199. data/lib/bio/util/restriction_enzyme/range/sequence_range/calculated_cuts.rb +242 -0
  200. data/lib/bio/util/restriction_enzyme/range/sequence_range/fragment.rb +51 -0
  201. data/lib/bio/util/restriction_enzyme/range/sequence_range/fragments.rb +41 -0
  202. data/lib/bio/util/restriction_enzyme/range/vertical_cut_range.rb +77 -0
  203. data/lib/bio/util/restriction_enzyme/single_strand.rb +199 -0
  204. data/lib/bio/util/restriction_enzyme/single_strand/cut_locations_in_enzyme_notation.rb +135 -0
  205. data/lib/bio/util/restriction_enzyme/single_strand_complement.rb +23 -0
  206. data/lib/bio/util/restriction_enzyme/string_formatting.rb +111 -0
  207. data/lib/bio/util/sirna.rb +288 -0
  208. data/sample/any2fasta.rb +59 -0
  209. data/sample/biofetch.rb +475 -0
  210. data/sample/color_scheme_na.rb +91 -0
  211. data/sample/dbget +37 -0
  212. data/sample/enzymes.rb +78 -0
  213. data/sample/fasta2tab.rb +99 -0
  214. data/sample/fastagrep.rb +72 -0
  215. data/sample/fastasort.rb +54 -0
  216. data/sample/fsplit.rb +51 -0
  217. data/sample/gb2fasta.rb +30 -0
  218. data/sample/gb2tab.rb +325 -0
  219. data/sample/gbtab2mysql.rb +161 -0
  220. data/sample/genes2nuc.rb +33 -0
  221. data/sample/genes2pep.rb +33 -0
  222. data/sample/genes2tab.rb +81 -0
  223. data/sample/genome2rb.rb +29 -0
  224. data/sample/genome2tab.rb +76 -0
  225. data/sample/goslim.rb +303 -0
  226. data/sample/gt2fasta.rb +47 -0
  227. data/sample/na2aa.rb +34 -0
  228. data/sample/pmfetch.rb +42 -0
  229. data/sample/pmsearch.rb +42 -0
  230. data/sample/psortplot_html.rb +214 -0
  231. data/sample/ssearch2tab.rb +96 -0
  232. data/sample/tdiary.rb +158 -0
  233. data/sample/tfastx2tab.rb +100 -0
  234. data/sample/vs-genes.rb +212 -0
  235. data/test/data/HMMER/hmmpfam.out +64 -0
  236. data/test/data/HMMER/hmmsearch.out +88 -0
  237. data/test/data/SOSUI/sample.report +11 -0
  238. data/test/data/TMHMM/sample.report +21 -0
  239. data/test/data/aaindex/DAYM780301 +30 -0
  240. data/test/data/aaindex/PRAM900102 +20 -0
  241. data/test/data/bl2seq/cd8a_cd8b_blastp.bl2seq +53 -0
  242. data/test/data/bl2seq/cd8a_p53_e-5blastp.bl2seq +37 -0
  243. data/test/data/blast/2.2.15.blastp.m7 +876 -0
  244. data/test/data/blast/b0002.faa +15 -0
  245. data/test/data/blast/b0002.faa.m0 +128 -0
  246. data/test/data/blast/b0002.faa.m7 +65 -0
  247. data/test/data/blast/b0002.faa.m8 +1 -0
  248. data/test/data/embl/AB090716.embl +65 -0
  249. data/test/data/embl/AB090716.embl.rel89 +63 -0
  250. data/test/data/fasta/example1.txt +75 -0
  251. data/test/data/fasta/example2.txt +21 -0
  252. data/test/data/genscan/sample.report +63 -0
  253. data/test/data/iprscan/merged.raw +32 -0
  254. data/test/data/iprscan/merged.txt +74 -0
  255. data/test/data/prosite/prosite.dat +2233 -0
  256. data/test/data/refseq/nm_126355.entret +64 -0
  257. data/test/data/soft/GDS100_partial.soft +92 -0
  258. data/test/data/soft/GSE3457_family_partial.soft +874 -0
  259. data/test/data/uniprot/p53_human.uniprot +1456 -0
  260. data/test/functional/bio/io/test_ensembl.rb +186 -0
  261. data/test/functional/bio/io/test_soapwsdl.rb +52 -0
  262. data/test/runner.rb +14 -0
  263. data/test/unit/bio/appl/bl2seq/test_report.rb +134 -0
  264. data/test/unit/bio/appl/blast/test_report.rb +417 -0
  265. data/test/unit/bio/appl/blast/test_xmlparser.rb +388 -0
  266. data/test/unit/bio/appl/genscan/test_report.rb +182 -0
  267. data/test/unit/bio/appl/hmmer/test_report.rb +342 -0
  268. data/test/unit/bio/appl/iprscan/test_report.rb +338 -0
  269. data/test/unit/bio/appl/mafft/test_report.rb +63 -0
  270. data/test/unit/bio/appl/sosui/test_report.rb +81 -0
  271. data/test/unit/bio/appl/targetp/test_report.rb +146 -0
  272. data/test/unit/bio/appl/test_blast.rb +163 -0
  273. data/test/unit/bio/appl/test_fasta.rb +130 -0
  274. data/test/unit/bio/appl/test_pts1.rb +140 -0
  275. data/test/unit/bio/appl/tmhmm/test_report.rb +126 -0
  276. data/test/unit/bio/data/test_aa.rb +90 -0
  277. data/test/unit/bio/data/test_codontable.rb +107 -0
  278. data/test/unit/bio/data/test_na.rb +80 -0
  279. data/test/unit/bio/db/embl/test_common.rb +117 -0
  280. data/test/unit/bio/db/embl/test_embl.rb +214 -0
  281. data/test/unit/bio/db/embl/test_embl_rel89.rb +219 -0
  282. data/test/unit/bio/db/embl/test_sptr.rb +1775 -0
  283. data/test/unit/bio/db/embl/test_uniprot.rb +31 -0
  284. data/test/unit/bio/db/kegg/test_genes.rb +45 -0
  285. data/test/unit/bio/db/pdb/test_pdb.rb +152 -0
  286. data/test/unit/bio/db/test_aaindex.rb +197 -0
  287. data/test/unit/bio/db/test_fasta.rb +250 -0
  288. data/test/unit/bio/db/test_gff.rb +127 -0
  289. data/test/unit/bio/db/test_lasergene.rb +95 -0
  290. data/test/unit/bio/db/test_newick.rb +293 -0
  291. data/test/unit/bio/db/test_nexus.rb +360 -0
  292. data/test/unit/bio/db/test_prosite.rb +1437 -0
  293. data/test/unit/bio/db/test_rebase.rb +101 -0
  294. data/test/unit/bio/db/test_soft.rb +138 -0
  295. data/test/unit/bio/io/test_ddbjxml.rb +75 -0
  296. data/test/unit/bio/io/test_ensembl.rb +109 -0
  297. data/test/unit/bio/io/test_fastacmd.rb +42 -0
  298. data/test/unit/bio/io/test_flatfile.rb +237 -0
  299. data/test/unit/bio/io/test_soapwsdl.rb +32 -0
  300. data/test/unit/bio/sequence/test_aa.rb +103 -0
  301. data/test/unit/bio/sequence/test_common.rb +174 -0
  302. data/test/unit/bio/sequence/test_compat.rb +69 -0
  303. data/test/unit/bio/sequence/test_na.rb +330 -0
  304. data/test/unit/bio/shell/plugin/test_seq.rb +185 -0
  305. data/test/unit/bio/test_alignment.rb +1025 -0
  306. data/test/unit/bio/test_command.rb +288 -0
  307. data/test/unit/bio/test_db.rb +96 -0
  308. data/test/unit/bio/test_feature.rb +116 -0
  309. data/test/unit/bio/test_location.rb +39 -0
  310. data/test/unit/bio/test_map.rb +230 -0
  311. data/test/unit/bio/test_pathway.rb +473 -0
  312. data/test/unit/bio/test_reference.rb +224 -0
  313. data/test/unit/bio/test_sequence.rb +329 -0
  314. data/test/unit/bio/test_shell.rb +18 -0
  315. data/test/unit/bio/test_tree.rb +593 -0
  316. data/test/unit/bio/util/restriction_enzyme/analysis/test_calculated_cuts.rb +299 -0
  317. data/test/unit/bio/util/restriction_enzyme/analysis/test_cut_ranges.rb +103 -0
  318. data/test/unit/bio/util/restriction_enzyme/analysis/test_sequence_range.rb +240 -0
  319. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_aligned_strands.rb +101 -0
  320. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair.rb +75 -0
  321. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_location_pair_in_enzyme_notation.rb +73 -0
  322. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations.rb +53 -0
  323. data/test/unit/bio/util/restriction_enzyme/double_stranded/test_cut_locations_in_enzyme_notation.rb +104 -0
  324. data/test/unit/bio/util/restriction_enzyme/single_strand/test_cut_locations_in_enzyme_notation.rb +83 -0
  325. data/test/unit/bio/util/restriction_enzyme/test_analysis.rb +246 -0
  326. data/test/unit/bio/util/restriction_enzyme/test_cut_symbol.rb +44 -0
  327. data/test/unit/bio/util/restriction_enzyme/test_double_stranded.rb +115 -0
  328. data/test/unit/bio/util/restriction_enzyme/test_single_strand.rb +147 -0
  329. data/test/unit/bio/util/restriction_enzyme/test_single_strand_complement.rb +147 -0
  330. data/test/unit/bio/util/restriction_enzyme/test_string_formatting.rb +60 -0
  331. data/test/unit/bio/util/test_color_scheme.rb +33 -0
  332. data/test/unit/bio/util/test_contingency_table.rb +94 -0
  333. data/test/unit/bio/util/test_restriction_enzyme.rb +42 -0
  334. data/test/unit/bio/util/test_sirna.rb +245 -0
  335. metadata +479 -0
@@ -0,0 +1,148 @@
1
+ #
2
+ # = bio/db/pdb/model.rb - model class for PDB
3
+ #
4
+ # Copyright:: Copyright (C) 2004, 2006
5
+ # Alex Gutteridge <alexg@ebi.ac.uk>
6
+ # Naohisa Goto <ng@bioruby.org>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id: model.rb,v 1.10 2007/12/18 13:48:42 ngoto Exp $
10
+ #
11
+ # = Bio::PDB::Model
12
+ #
13
+ # Please refer Bio::PDB::Model.
14
+ #
15
+
16
+ require 'bio/db/pdb'
17
+
18
+ module Bio
19
+
20
+ class PDB
21
+
22
+ # Bio::PDB::Model is a class to store a model.
23
+ #
24
+ # The object would contain some chains (Bio::PDB::Chain objects).
25
+ class Model
26
+
27
+ include Utils
28
+ include AtomFinder
29
+ include ResidueFinder
30
+ include ChainFinder
31
+
32
+ include HetatmFinder
33
+ include HeterogenFinder
34
+
35
+ include Enumerable
36
+ include Comparable
37
+
38
+ # Creates a new Model object
39
+ def initialize(serial = nil, structure = nil)
40
+
41
+ @serial = serial
42
+ @structure = structure
43
+ @chains = []
44
+ @chains_hash = {}
45
+ @solvents = Chain.new('', self)
46
+ end
47
+
48
+ # chains in this model
49
+ attr_reader :chains
50
+
51
+ # (OBSOLETE) solvents (water, HOH) in this model
52
+ attr_reader :solvents
53
+
54
+ # serial number of this model. (Integer or nil)
55
+ attr_accessor :serial
56
+
57
+ # for backward compatibility
58
+ alias model_serial serial
59
+
60
+ # (reserved for future extension)
61
+ attr_reader :structure
62
+
63
+ # Adds a chain to this model
64
+ def addChain(chain)
65
+ raise "Expecting a Bio::PDB::Chain" unless chain.is_a? Bio::PDB::Chain
66
+ @chains.push(chain)
67
+ if @chains_hash[chain.chain_id] then
68
+ $stderr.puts "Warning: chain_id #{chain.chain_id.inspect} is already used" if $VERBOSE
69
+ else
70
+ @chains_hash[chain.chain_id] = chain
71
+ end
72
+ self
73
+ end
74
+
75
+ # rehash chains hash
76
+ def rehash
77
+ begin
78
+ chains_bak = @chains
79
+ chains_hash_bak = @chains_hash
80
+ @chains = []
81
+ @chains_hash = {}
82
+ chains_bak.each do |chain|
83
+ self.addChain(chain)
84
+ end
85
+ rescue RuntimeError
86
+ @chains = chains_bak
87
+ @chains_hash = chains_hash_bak
88
+ raise
89
+ end
90
+ self
91
+ end
92
+
93
+ # (OBSOLETE) Adds a solvent molecule to this model
94
+ def addSolvent(solvent)
95
+ raise "Expecting a Bio::PDB::Residue" unless solvent.is_a? Bio::PDB::Residue
96
+ @solvents.addResidue(solvent)
97
+ end
98
+
99
+ # (OBSOLETE) not recommended to use this method
100
+ def removeSolvent
101
+ @solvents = nil
102
+ end
103
+
104
+ # Iterates over each chain
105
+ def each(&x) #:yields: chain
106
+ @chains.each(&x)
107
+ end
108
+ # Alias to override ChainFinder#each_chain
109
+ alias each_chain each
110
+
111
+ # Operator aimed to sort models based on serial number
112
+ def <=>(other)
113
+ return @serial <=> other.model_serial
114
+ end
115
+
116
+ # Keyed access to chains
117
+ def [](key)
118
+ #chain = @chains.find{ |chain| key == chain.id }
119
+ @chains_hash[key]
120
+ end
121
+
122
+ # stringifies to chains
123
+ def to_s
124
+ string = ""
125
+ if model_serial
126
+ string = "MODEL #{model_serial}\n" #Should use proper formatting
127
+ end
128
+ @chains.each{ |chain| string << chain.to_s }
129
+ #if solvent
130
+ # string << @solvent.to_s
131
+ #end
132
+ if model_serial
133
+ string << "ENDMDL\n"
134
+ end
135
+ return string
136
+ end
137
+
138
+ # returns a string containing human-readable representation
139
+ # of this object.
140
+ def inspect
141
+ "#<#{self.class.to_s} serial=#{serial.inspect} chains.size=#{chains.size}>"
142
+ end
143
+
144
+ end #class Model
145
+
146
+ end #class PDB
147
+
148
+ end #module Bio
@@ -0,0 +1,1911 @@
1
+ #
2
+ # = bio/db/pdb/pdb.rb - PDB database class for PDB file format
3
+ #
4
+ # Copyright:: Copyright (C) 2003-2006
5
+ # GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
6
+ # Alex Gutteridge <alexg@ebi.ac.uk>
7
+ # License:: The Ruby License
8
+ #
9
+ # $Id: pdb.rb,v 1.28 2008/04/01 10:36:44 ngoto Exp $
10
+ #
11
+ # = About Bio::PDB
12
+ #
13
+ # Please refer document of Bio::PDB class.
14
+ #
15
+ # = References
16
+ #
17
+ # * ((<URL:http://www.rcsb.org/pdb/>))
18
+ # * PDB File Format Contents Guide Version 2.2 (20 December 1996)
19
+ # ((<URL:http://www.rcsb.org/pdb/file_formats/pdb/pdbguide2.2/guide2.2_frame.html>))
20
+ #
21
+ # = *** CAUTION ***
22
+ # This is beta version. Specs shall be changed frequently.
23
+ #
24
+
25
+ require 'bio/db/pdb'
26
+ require 'bio/data/aa'
27
+
28
+ module Bio
29
+
30
+ # This is the main PDB class which takes care of parsing, annotations
31
+ # and is the entry way to the co-ordinate data held in models.
32
+ #
33
+ # There are many related classes.
34
+ #
35
+ # Bio::PDB::Model
36
+ # Bio::PDB::Chain
37
+ # Bio::PDB::Residue
38
+ # Bio::PDB::Heterogen
39
+ # Bio::PDB::Record::ATOM
40
+ # Bio::PDB::Record::HETATM
41
+ # Bio::PDB::Record::*
42
+ # Bio::PDB::Coordinate
43
+ #
44
+ class PDB
45
+
46
+ include Utils
47
+ include AtomFinder
48
+ include ResidueFinder
49
+ include ChainFinder
50
+ include ModelFinder
51
+
52
+ include HetatmFinder
53
+ include HeterogenFinder
54
+
55
+ include Enumerable
56
+
57
+ # delimiter for reading via Bio::FlatFile
58
+ DELIMITER = RS = nil # 1 file 1 entry
59
+
60
+ # Modules required by the field definitions
61
+ module DataType
62
+
63
+ Pdb_Continuation = nil
64
+
65
+ module Pdb_Integer
66
+ def self.new(str)
67
+ str.to_i
68
+ end
69
+ end
70
+
71
+ module Pdb_SList
72
+ def self.new(str)
73
+ str.to_s.strip.split(/\;\s*/)
74
+ end
75
+ end
76
+
77
+ module Pdb_List
78
+ def self.new(str)
79
+ str.to_s.strip.split(/\,\s*/)
80
+ end
81
+ end
82
+
83
+ module Pdb_Specification_list
84
+ def self.new(str)
85
+ a = str.to_s.strip.split(/\;\s*/)
86
+ a.collect! { |x| x.split(/\:\s*/, 2) }
87
+ a
88
+ end
89
+ end
90
+
91
+ module Pdb_String
92
+ def self.new(str)
93
+ str.to_s.gsub(/\s+\z/, '')
94
+ end
95
+
96
+ #Creates a new module with a string left justified to the
97
+ #length given in nn
98
+ def self.[](nn)
99
+ m = Module.new
100
+ m.module_eval %Q{
101
+ @@nn = nn
102
+ def self.new(str)
103
+ str.to_s.gsub(/\s+\z/, '').ljust(@@nn)[0, @@nn]
104
+ end
105
+ }
106
+ m
107
+ end
108
+ end #module Pdb_String
109
+
110
+ module Pdb_LString
111
+ def self.[](nn)
112
+ m = Module.new
113
+ m.module_eval %Q{
114
+ @@nn = nn
115
+ def self.new(str)
116
+ str.to_s.ljust(@@nn)[0, @@nn]
117
+ end
118
+ }
119
+ m
120
+ end
121
+ def self.new(str)
122
+ String.new(str.to_s)
123
+ end
124
+ end
125
+
126
+ module Pdb_Real
127
+ def self.[](fmt)
128
+ m = Module.new
129
+ m.module_eval %Q{
130
+ @@format = fmt
131
+ def self.new(str)
132
+ str.to_f
133
+ end
134
+ }
135
+ m
136
+ end
137
+ def self.new(str)
138
+ str.to_f
139
+ end
140
+ end
141
+
142
+ module Pdb_StringRJ
143
+ def self.new(str)
144
+ str.to_s.gsub(/\A\s+/, '')
145
+ end
146
+ end
147
+
148
+ Pdb_Date = Pdb_String
149
+ Pdb_IDcode = Pdb_String
150
+ Pdb_Residue_name = Pdb_String
151
+ Pdb_SymOP = Pdb_String
152
+ Pdb_Atom = Pdb_String
153
+ Pdb_AChar = Pdb_String
154
+ Pdb_Character = Pdb_LString
155
+
156
+ module ConstLikeMethod
157
+ def Pdb_LString(nn)
158
+ Pdb_LString[nn]
159
+ end
160
+
161
+ def Pdb_String(nn)
162
+ Pdb_String[nn]
163
+ end
164
+
165
+ def Pdb_Real(fmt)
166
+ Pdb_Real[fmt]
167
+ end
168
+ end #module ConstLikeMethod
169
+ end #module DataType
170
+
171
+ # The ancestor of every single PDB record class.
172
+ # It inherits <code>Struct</code> class.
173
+ # Basically, each line of a PDB file corresponds to
174
+ # an instance of each corresponding child class.
175
+ # If continuation exists, multiple lines may correspond to
176
+ # single instance.
177
+ #
178
+ class Record < Struct
179
+ include DataType
180
+ extend DataType::ConstLikeMethod
181
+
182
+ # Internal use only.
183
+ #
184
+ # parse filed definitions.
185
+ def self.parse_field_definitions(ary)
186
+ symbolhash = {}
187
+ symbolary = []
188
+ cont = false
189
+
190
+ # For each field definition (range(start, end), type,symbol)
191
+ ary.each do |x|
192
+ range = (x[0] - 1)..(x[1] - 1)
193
+ # If type is nil (Pdb_Continuation) then set 'cont' to the range
194
+ # (other wise it is false to indicate no continuation
195
+ unless x[2] then
196
+ cont = range
197
+ else
198
+ klass = x[2]
199
+ sym = x[3]
200
+ # If the symbol is a proper symbol then...
201
+ if sym.is_a?(Symbol) then
202
+ # ..if we have the symbol already in the symbol hash
203
+ # then add the range onto the range array
204
+ if symbolhash.has_key?(sym) then
205
+ symbolhash[sym][1] << range
206
+ else
207
+ # Other wise put a new symbol in with its type and range
208
+ # range is given its own array. You can have
209
+ # anumber of ranges.
210
+ symbolhash[sym] = [ klass, [ range ] ]
211
+ symbolary << sym
212
+ end
213
+ end
214
+ end
215
+ end #each
216
+ [ symbolhash, symbolary, cont ]
217
+ end
218
+ private_class_method :parse_field_definitions
219
+
220
+ # Creates new class by given field definition
221
+ # The difference from new_direct() is the class
222
+ # created by the method does lazy evaluation.
223
+ #
224
+ # Internal use only.
225
+ def self.def_rec(*ary)
226
+ symbolhash, symbolary, cont = parse_field_definitions(ary)
227
+
228
+ klass = Class.new(self.new(*symbolary))
229
+ klass.module_eval {
230
+ @definition = ary
231
+ @symbols = symbolhash
232
+ @cont = cont
233
+ }
234
+ klass.module_eval {
235
+ symbolary.each do |x|
236
+ define_method(x) { do_parse; super() }
237
+ end
238
+ }
239
+ klass
240
+ end #def self.def_rec
241
+
242
+ # creates new class which inherits given class.
243
+ def self.new_inherit(klass)
244
+ newklass = Class.new(klass)
245
+ newklass.module_eval {
246
+ @definition = klass.module_eval { @definition }
247
+ @symbols = klass.module_eval { @symbols }
248
+ @cont = klass.module_eval { @cont }
249
+ }
250
+ newklass
251
+ end
252
+
253
+ # Creates new class by given field definition.
254
+ #
255
+ # Internal use only.
256
+ def self.new_direct(*ary)
257
+ symbolhash, symbolary, cont = parse_field_definitions(ary)
258
+ if cont
259
+ raise 'continuation not allowed. please use def_rec instead'
260
+ end
261
+
262
+ klass = Class.new(self.new(*symbolary))
263
+ klass.module_eval {
264
+ @definition = ary
265
+ @symbols = symbolhash
266
+ @cont = cont
267
+ }
268
+ klass.module_eval {
269
+ define_method(:initialize_from_string) { |str|
270
+ r = super(str)
271
+ do_parse
272
+ r
273
+ }
274
+ }
275
+ klass
276
+ end #def self.new_direct
277
+
278
+ # symbols
279
+ def self.symbols
280
+ #p self
281
+ @symbols
282
+ end
283
+
284
+ # Returns true if this record has a field type which allows
285
+ # continuations.
286
+ def self.continue?
287
+ @cont
288
+ end
289
+
290
+ # Returns true if this record has a field type which allows
291
+ # continuations.
292
+ def continue?
293
+ self.class.continue?
294
+ end
295
+
296
+ # yields the symbol(k), type(x[0]) and array of ranges
297
+ # of each symbol.
298
+ def each_symbol
299
+ self.class.symbols.each do |k, x|
300
+ yield k, x[0], x[1]
301
+ end
302
+ end
303
+
304
+ # Return original string (except that "\n" are truncated)
305
+ # for this record (usually just @str, but
306
+ # sometimes add on the continuation data from other lines.
307
+ # Returns an array of string.
308
+ #
309
+ def original_data
310
+ if defined?(@cont_data) then
311
+ [ @str, *@cont_data ]
312
+ else
313
+ [ @str ]
314
+ end
315
+ end
316
+
317
+ # initialize this record from the given string.
318
+ # <em>str</em> must be a line (in PDB format).
319
+ #
320
+ # You can add continuation lines later using
321
+ # <code>add_continuation</code> method.
322
+ def initialize_from_string(str)
323
+ @str = str
324
+ @record_name = fetch_record_name(str)
325
+ @parsed = false
326
+ self
327
+ end
328
+
329
+ #--
330
+ # Called when we need to access the data, takes the string
331
+ # and the array of FieldDefs and parses it out.
332
+ #++
333
+
334
+ # In order to speeding up processing of PDB file format,
335
+ # fields have not been parsed before calling this method.
336
+ #
337
+ # Normally, it is automatically called and you don't explicitly
338
+ # need to call it .
339
+ #
340
+ def do_parse
341
+ return self if @parsed or !@str
342
+ str = @str
343
+ each_symbol do |key, klass, ranges|
344
+ #If we only have one range then pull that out
345
+ #and store it in the hash
346
+ if ranges.size <= 1 then
347
+ self[key] = klass.new(str[ranges.first])
348
+ else
349
+ #Go through each range and add the string to an array
350
+ #set the hash key to point to that array
351
+ ary = []
352
+ ranges.each do |r|
353
+ ary << klass.new(str[r]) unless str[r].to_s.strip.empty?
354
+ end
355
+ self[key] = ary
356
+ end
357
+ end #each_symbol
358
+ #If we have continuations then for each line of extra data...
359
+ if defined?(@cont_data) then
360
+ @cont_data.each do |str|
361
+ #Get the symbol, type and range array
362
+ each_symbol do |key, klass, ranges|
363
+ #If there's one range then grab that range
364
+ if ranges.size <= 1 then
365
+ r = ranges.first
366
+ unless str[r].to_s.strip.empty?
367
+ #and concatenate the new data onto the old
368
+ v = klass.new(str[r])
369
+ self[key].concat(v) if self[key] != v
370
+ end
371
+ else
372
+ #If there's more than one range then add to the array
373
+ ary = self[key]
374
+ ranges.each do |r|
375
+ ary << klass.new(str[r]) unless str[r].to_s.strip.empty?
376
+ end
377
+ end
378
+ end
379
+ end
380
+ end
381
+ @parsed = true
382
+ self
383
+ end
384
+
385
+ # fetches record name
386
+ def fetch_record_name(str)
387
+ str[0..5].strip
388
+ end
389
+ private :fetch_record_name
390
+
391
+ # fetches record name
392
+ def self.fetch_record_name(str)
393
+ str[0..5].strip
394
+ end
395
+ private_class_method :fetch_record_name
396
+
397
+ # If given <em>str</em> can be the continuation of the current record,
398
+ # then return the order number of the continuation associated with
399
+ # the Pdb_Continuation field definition.
400
+ # Otherwise, returns -1.
401
+ def fetch_cont(str)
402
+ (c = continue?) ? str[c].to_i : -1
403
+ end
404
+ private :fetch_cont
405
+
406
+ # Record name of this record, e.g. "HEADER", "ATOM".
407
+ def record_name
408
+ @record_name or self.class.to_s.split(/\:\:/)[-1].to_s.upcase
409
+ end
410
+ # keeping compatibility with old version
411
+ alias record_type record_name
412
+
413
+ # Internal use only.
414
+ #
415
+ # Adds continuation data to the record from str if str is
416
+ # really the continuation of current record.
417
+ # Returns self (= not nil) if str is the continuation.
418
+ # Otherwaise, returns false.
419
+ #
420
+ def add_continuation(str)
421
+ #Check that this record can continue
422
+ #and that str has the same type and definition
423
+ return false unless self.continue?
424
+ return false unless fetch_record_name(str) == @record_name
425
+ return false unless self.class.get_record_class(str) == self.class
426
+ return false unless fetch_cont(str) >= 2
427
+ #If all this is OK then add onto @cont_data
428
+ unless defined?(@cont_data)
429
+ @cont_data = []
430
+ end
431
+ @cont_data << str
432
+ # Returns self (= not nil) if succeeded.
433
+ self
434
+ end
435
+
436
+ # creates definition hash from current classes constants
437
+ def self.create_definition_hash
438
+ hash = {}
439
+ constants.each do |x|
440
+ x = x.intern # keep compatibility both Ruby 1.8 and 1.9
441
+ hash[x] = const_get(x) if /\A[A-Z][A-Z0-9]+\z/ =~ x.to_s
442
+ end
443
+ if x = const_get(:Default) then
444
+ hash.default = x
445
+ end
446
+ hash
447
+ end
448
+
449
+ # same as Struct#inspect.
450
+ #
451
+ # Note that <code>do_parse</code> is automatically called
452
+ # before <code>inspect</code>.
453
+ #
454
+ # (Warning: The do_parse might sweep hidden bugs in PDB classes.)
455
+ def inspect
456
+ do_parse
457
+ super
458
+ end
459
+
460
+ #--
461
+ #
462
+ # definitions
463
+ # contains all the rules for parsing each field
464
+ # based on format V 2.2, 16-DEC-1996
465
+ #
466
+ # http://www.rcsb.org/pdb/docs/format/pdbguide2.2/guide2.2_frame.html
467
+ # http://www.rcsb.org/pdb/docs/format/pdbguide2.2/Contents_Guide_21.html
468
+ #
469
+ # Details of following data are taken from these documents.
470
+
471
+ # [ 1..6, :Record_name, nil ],
472
+
473
+ # XXXXXX =
474
+ # new([ start, end, type of data, symbol to access ], ...)
475
+ #
476
+ #++
477
+
478
+ # HEADER record class
479
+ HEADER =
480
+ def_rec([ 11, 50, Pdb_String, :classification ], #Pdb_String(40)
481
+ [ 51, 59, Pdb_Date, :depDate ],
482
+ [ 63, 66, Pdb_IDcode, :idCode ]
483
+ )
484
+
485
+ # OBSLTE record class
486
+ OBSLTE =
487
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
488
+ [ 12, 20, Pdb_Date, :repDate ],
489
+ [ 22, 25, Pdb_IDcode, :idCode ],
490
+ [ 32, 35, Pdb_IDcode, :rIdCode ],
491
+ [ 37, 40, Pdb_IDcode, :rIdCode ],
492
+ [ 42, 45, Pdb_IDcode, :rIdCode ],
493
+ [ 47, 50, Pdb_IDcode, :rIdCode ],
494
+ [ 52, 55, Pdb_IDcode, :rIdCode ],
495
+ [ 57, 60, Pdb_IDcode, :rIdCode ],
496
+ [ 62, 65, Pdb_IDcode, :rIdCode ],
497
+ [ 67, 70, Pdb_IDcode, :rIdCode ]
498
+ )
499
+
500
+ # TITLE record class
501
+ TITLE =
502
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
503
+ [ 11, 70, Pdb_String, :title ]
504
+ )
505
+
506
+ # CAVEAT record class
507
+ CAVEAT =
508
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
509
+ [ 12, 15, Pdb_IDcode, :idcode ],
510
+ [ 20, 70, Pdb_String, :comment ]
511
+ )
512
+
513
+ # COMPND record class
514
+ COMPND =
515
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
516
+ [ 11, 70, Pdb_Specification_list, :compound ]
517
+ )
518
+
519
+ # SOURCE record class
520
+ SOURCE =
521
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
522
+ [ 11, 70, Pdb_Specification_list, :srcName ]
523
+ )
524
+
525
+ # KEYWDS record class
526
+ KEYWDS =
527
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
528
+ [ 11, 70, Pdb_List, :keywds ]
529
+ )
530
+
531
+ # EXPDTA record class
532
+ EXPDTA =
533
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
534
+ [ 11, 70, Pdb_SList, :technique ]
535
+ )
536
+
537
+ # AUTHOR record class
538
+ AUTHOR =
539
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
540
+ [ 11, 70, Pdb_List, :authorList ]
541
+ )
542
+
543
+ # REVDAT record class
544
+ REVDAT =
545
+ def_rec([ 8, 10, Pdb_Integer, :modNum ],
546
+ [ 11, 12, Pdb_Continuation, nil ],
547
+ [ 14, 22, Pdb_Date, :modDate ],
548
+ [ 24, 28, Pdb_String, :modId ], # Pdb_String(5)
549
+ [ 32, 32, Pdb_Integer, :modType ],
550
+ [ 40, 45, Pdb_LString(6), :record ],
551
+ [ 47, 52, Pdb_LString(6), :record ],
552
+ [ 54, 59, Pdb_LString(6), :record ],
553
+ [ 61, 66, Pdb_LString(6), :record ]
554
+ )
555
+
556
+ # SPRSDE record class
557
+ SPRSDE =
558
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
559
+ [ 12, 20, Pdb_Date, :sprsdeDate ],
560
+ [ 22, 25, Pdb_IDcode, :idCode ],
561
+ [ 32, 35, Pdb_IDcode, :sIdCode ],
562
+ [ 37, 40, Pdb_IDcode, :sIdCode ],
563
+ [ 42, 45, Pdb_IDcode, :sIdCode ],
564
+ [ 47, 50, Pdb_IDcode, :sIdCode ],
565
+ [ 52, 55, Pdb_IDcode, :sIdCode ],
566
+ [ 57, 60, Pdb_IDcode, :sIdCode ],
567
+ [ 62, 65, Pdb_IDcode, :sIdCode ],
568
+ [ 67, 70, Pdb_IDcode, :sIdCode ]
569
+ )
570
+
571
+ # 'JRNL' is defined below
572
+ JRNL = nil
573
+
574
+ # 'REMARK' is defined below
575
+ REMARK = nil
576
+
577
+ # DBREF record class
578
+ DBREF =
579
+ def_rec([ 8, 11, Pdb_IDcode, :idCode ],
580
+ [ 13, 13, Pdb_Character, :chainID ],
581
+ [ 15, 18, Pdb_Integer, :seqBegin ],
582
+ [ 19, 19, Pdb_AChar, :insertBegin ],
583
+ [ 21, 24, Pdb_Integer, :seqEnd ],
584
+ [ 25, 25, Pdb_AChar, :insertEnd ],
585
+ [ 27, 32, Pdb_String, :database ], #Pdb_LString
586
+ [ 34, 41, Pdb_String, :dbAccession ], #Pdb_LString
587
+ [ 43, 54, Pdb_String, :dbIdCode ], #Pdb_LString
588
+ [ 56, 60, Pdb_Integer, :dbseqBegin ],
589
+ [ 61, 61, Pdb_AChar, :idbnsBeg ],
590
+ [ 63, 67, Pdb_Integer, :dbseqEnd ],
591
+ [ 68, 68, Pdb_AChar, :dbinsEnd ]
592
+ )
593
+
594
+ # SEQADV record class
595
+ SEQADV =
596
+ def_rec([ 8, 11, Pdb_IDcode, :idCode ],
597
+ [ 13, 15, Pdb_Residue_name, :resName ],
598
+ [ 17, 17, Pdb_Character, :chainID ],
599
+ [ 19, 22, Pdb_Integer, :seqNum ],
600
+ [ 23, 23, Pdb_AChar, :iCode ],
601
+ [ 25, 28, Pdb_String, :database ], #Pdb_LString
602
+ [ 30, 38, Pdb_String, :dbIdCode ], #Pdb_LString
603
+ [ 40, 42, Pdb_Residue_name, :dbRes ],
604
+ [ 44, 48, Pdb_Integer, :dbSeq ],
605
+ [ 50, 70, Pdb_LString, :conflict ]
606
+ )
607
+
608
+ # SEQRES record class
609
+ SEQRES =
610
+ def_rec(#[ 9, 10, Pdb_Integer, :serNum ],
611
+ [ 9, 10, Pdb_Continuation, nil ],
612
+ [ 12, 12, Pdb_Character, :chainID ],
613
+ [ 14, 17, Pdb_Integer, :numRes ],
614
+ [ 20, 22, Pdb_Residue_name, :resName ],
615
+ [ 24, 26, Pdb_Residue_name, :resName ],
616
+ [ 28, 30, Pdb_Residue_name, :resName ],
617
+ [ 32, 34, Pdb_Residue_name, :resName ],
618
+ [ 36, 38, Pdb_Residue_name, :resName ],
619
+ [ 40, 42, Pdb_Residue_name, :resName ],
620
+ [ 44, 46, Pdb_Residue_name, :resName ],
621
+ [ 48, 50, Pdb_Residue_name, :resName ],
622
+ [ 52, 54, Pdb_Residue_name, :resName ],
623
+ [ 56, 58, Pdb_Residue_name, :resName ],
624
+ [ 60, 62, Pdb_Residue_name, :resName ],
625
+ [ 64, 66, Pdb_Residue_name, :resName ],
626
+ [ 68, 70, Pdb_Residue_name, :resName ]
627
+ )
628
+
629
+ # MODRS record class
630
+ MODRES =
631
+ def_rec([ 8, 11, Pdb_IDcode, :idCode ],
632
+ [ 13, 15, Pdb_Residue_name, :resName ],
633
+ [ 17, 17, Pdb_Character, :chainID ],
634
+ [ 19, 22, Pdb_Integer, :seqNum ],
635
+ [ 23, 23, Pdb_AChar, :iCode ],
636
+ [ 25, 27, Pdb_Residue_name, :stdRes ],
637
+ [ 30, 70, Pdb_String, :comment ]
638
+ )
639
+
640
+ # HET record class
641
+ HET =
642
+ def_rec([ 8, 10, Pdb_LString(3), :hetID ],
643
+ [ 13, 13, Pdb_Character, :ChainID ],
644
+ [ 14, 17, Pdb_Integer, :seqNum ],
645
+ [ 18, 18, Pdb_AChar, :iCode ],
646
+ [ 21, 25, Pdb_Integer, :numHetAtoms ],
647
+ [ 31, 70, Pdb_String, :text ]
648
+ )
649
+
650
+ # HETNAM record class
651
+ HETNAM =
652
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
653
+ [ 12, 14, Pdb_LString(3), :hetID ],
654
+ [ 16, 70, Pdb_String, :text ]
655
+ )
656
+
657
+ # HETSYN record class
658
+ HETSYN =
659
+ def_rec([ 9, 10, Pdb_Continuation, nil ],
660
+ [ 12, 14, Pdb_LString(3), :hetID ],
661
+ [ 16, 70, Pdb_SList, :hetSynonyms ]
662
+ )
663
+
664
+ # FORMUL record class
665
+ FORMUL =
666
+ def_rec([ 9, 10, Pdb_Integer, :compNum ],
667
+ [ 13, 15, Pdb_LString(3), :hetID ],
668
+ [ 17, 18, Pdb_Integer, :continuation ],
669
+ [ 19, 19, Pdb_Character, :asterisk ],
670
+ [ 20, 70, Pdb_String, :text ]
671
+ )
672
+
673
+ # HELIX record class
674
+ HELIX =
675
+ def_rec([ 8, 10, Pdb_Integer, :serNum ],
676
+ #[ 12, 14, Pdb_LString(3), :helixID ],
677
+ [ 12, 14, Pdb_StringRJ, :helixID ],
678
+ [ 16, 18, Pdb_Residue_name, :initResName ],
679
+ [ 20, 20, Pdb_Character, :initChainID ],
680
+ [ 22, 25, Pdb_Integer, :initSeqNum ],
681
+ [ 26, 26, Pdb_AChar, :initICode ],
682
+ [ 28, 30, Pdb_Residue_name, :endResName ],
683
+ [ 32, 32, Pdb_Character, :endChainID ],
684
+ [ 34, 37, Pdb_Integer, :endSeqNum ],
685
+ [ 38, 38, Pdb_AChar, :endICode ],
686
+ [ 39, 40, Pdb_Integer, :helixClass ],
687
+ [ 41, 70, Pdb_String, :comment ],
688
+ [ 72, 76, Pdb_Integer, :length ]
689
+ )
690
+
691
+ # SHEET record class
692
+ SHEET =
693
+ def_rec([ 8, 10, Pdb_Integer, :strand ],
694
+ #[ 12, 14, Pdb_LString(3), :sheetID ],
695
+ [ 12, 14, Pdb_StringRJ, :sheetID ],
696
+ [ 15, 16, Pdb_Integer, :numStrands ],
697
+ [ 18, 20, Pdb_Residue_name, :initResName ],
698
+ [ 22, 22, Pdb_Character, :initChainID ],
699
+ [ 23, 26, Pdb_Integer, :initSeqNum ],
700
+ [ 27, 27, Pdb_AChar, :initICode ],
701
+ [ 29, 31, Pdb_Residue_name, :endResName ],
702
+ [ 33, 33, Pdb_Character, :endChainID ],
703
+ [ 34, 37, Pdb_Integer, :endSeqNum ],
704
+ [ 38, 38, Pdb_AChar, :endICode ],
705
+ [ 39, 40, Pdb_Integer, :sense ],
706
+ [ 42, 45, Pdb_Atom, :curAtom ],
707
+ [ 46, 48, Pdb_Residue_name, :curResName ],
708
+ [ 50, 50, Pdb_Character, :curChainId ],
709
+ [ 51, 54, Pdb_Integer, :curResSeq ],
710
+ [ 55, 55, Pdb_AChar, :curICode ],
711
+ [ 57, 60, Pdb_Atom, :prevAtom ],
712
+ [ 61, 63, Pdb_Residue_name, :prevResName ],
713
+ [ 65, 65, Pdb_Character, :prevChainId ],
714
+ [ 66, 69, Pdb_Integer, :prevResSeq ],
715
+ [ 70, 70, Pdb_AChar, :prevICode ]
716
+ )
717
+
718
+ # TURN record class
719
+ TURN =
720
+ def_rec([ 8, 10, Pdb_Integer, :seq ],
721
+ #[ 12, 14, Pdb_LString(3), :turnId ],
722
+ [ 12, 14, Pdb_StringRJ, :turnId ],
723
+ [ 16, 18, Pdb_Residue_name, :initResName ],
724
+ [ 20, 20, Pdb_Character, :initChainId ],
725
+ [ 21, 24, Pdb_Integer, :initSeqNum ],
726
+ [ 25, 25, Pdb_AChar, :initICode ],
727
+ [ 27, 29, Pdb_Residue_name, :endResName ],
728
+ [ 31, 31, Pdb_Character, :endChainId ],
729
+ [ 32, 35, Pdb_Integer, :endSeqNum ],
730
+ [ 36, 36, Pdb_AChar, :endICode ],
731
+ [ 41, 70, Pdb_String, :comment ]
732
+ )
733
+
734
+ # SSBOND record class
735
+ SSBOND =
736
+ def_rec([ 8, 10, Pdb_Integer, :serNum ],
737
+ [ 12, 14, Pdb_LString(3), :pep1 ], # "CYS"
738
+ [ 16, 16, Pdb_Character, :chainID1 ],
739
+ [ 18, 21, Pdb_Integer, :seqNum1 ],
740
+ [ 22, 22, Pdb_AChar, :icode1 ],
741
+ [ 26, 28, Pdb_LString(3), :pep2 ], # "CYS"
742
+ [ 30, 30, Pdb_Character, :chainID2 ],
743
+ [ 32, 35, Pdb_Integer, :seqNum2 ],
744
+ [ 36, 36, Pdb_AChar, :icode2 ],
745
+ [ 60, 65, Pdb_SymOP, :sym1 ],
746
+ [ 67, 72, Pdb_SymOP, :sym2 ]
747
+ )
748
+
749
+ # LINK record class
750
+ LINK =
751
+ def_rec([ 13, 16, Pdb_Atom, :name1 ],
752
+ [ 17, 17, Pdb_Character, :altLoc1 ],
753
+ [ 18, 20, Pdb_Residue_name, :resName1 ],
754
+ [ 22, 22, Pdb_Character, :chainID1 ],
755
+ [ 23, 26, Pdb_Integer, :resSeq1 ],
756
+ [ 27, 27, Pdb_AChar, :iCode1 ],
757
+ [ 43, 46, Pdb_Atom, :name2 ],
758
+ [ 47, 47, Pdb_Character, :altLoc2 ],
759
+ [ 48, 50, Pdb_Residue_name, :resName2 ],
760
+ [ 52, 52, Pdb_Character, :chainID2 ],
761
+ [ 53, 56, Pdb_Integer, :resSeq2 ],
762
+ [ 57, 57, Pdb_AChar, :iCode2 ],
763
+ [ 60, 65, Pdb_SymOP, :sym1 ],
764
+ [ 67, 72, Pdb_SymOP, :sym2 ]
765
+ )
766
+
767
+ # HYDBND record class
768
+ HYDBND =
769
+ def_rec([ 13, 16, Pdb_Atom, :name1 ],
770
+ [ 17, 17, Pdb_Character, :altLoc1 ],
771
+ [ 18, 20, Pdb_Residue_name, :resName1 ],
772
+ [ 22, 22, Pdb_Character, :Chain1 ],
773
+ [ 23, 27, Pdb_Integer, :resSeq1 ],
774
+ [ 28, 28, Pdb_AChar, :ICode1 ],
775
+ [ 30, 33, Pdb_Atom, :nameH ],
776
+ [ 34, 34, Pdb_Character, :altLocH ],
777
+ [ 36, 36, Pdb_Character, :ChainH ],
778
+ [ 37, 41, Pdb_Integer, :resSeqH ],
779
+ [ 42, 42, Pdb_AChar, :iCodeH ],
780
+ [ 44, 47, Pdb_Atom, :name2 ],
781
+ [ 48, 48, Pdb_Character, :altLoc2 ],
782
+ [ 49, 51, Pdb_Residue_name, :resName2 ],
783
+ [ 53, 53, Pdb_Character, :chainID2 ],
784
+ [ 54, 58, Pdb_Integer, :resSeq2 ],
785
+ [ 59, 59, Pdb_AChar, :iCode2 ],
786
+ [ 60, 65, Pdb_SymOP, :sym1 ],
787
+ [ 67, 72, Pdb_SymOP, :sym2 ]
788
+ )
789
+
790
+ # SLTBRG record class
791
+ SLTBRG =
792
+ def_rec([ 13, 16, Pdb_Atom, :atom1 ],
793
+ [ 17, 17, Pdb_Character, :altLoc1 ],
794
+ [ 18, 20, Pdb_Residue_name, :resName1 ],
795
+ [ 22, 22, Pdb_Character, :chainID1 ],
796
+ [ 23, 26, Pdb_Integer, :resSeq1 ],
797
+ [ 27, 27, Pdb_AChar, :iCode1 ],
798
+ [ 43, 46, Pdb_Atom, :atom2 ],
799
+ [ 47, 47, Pdb_Character, :altLoc2 ],
800
+ [ 48, 50, Pdb_Residue_name, :resName2 ],
801
+ [ 52, 52, Pdb_Character, :chainID2 ],
802
+ [ 53, 56, Pdb_Integer, :resSeq2 ],
803
+ [ 57, 57, Pdb_AChar, :iCode2 ],
804
+ [ 60, 65, Pdb_SymOP, :sym1 ],
805
+ [ 67, 72, Pdb_SymOP, :sym2 ]
806
+ )
807
+
808
+ # CISPEP record class
809
+ CISPEP =
810
+ def_rec([ 8, 10, Pdb_Integer, :serNum ],
811
+ [ 12, 14, Pdb_LString(3), :pep1 ],
812
+ [ 16, 16, Pdb_Character, :chainID1 ],
813
+ [ 18, 21, Pdb_Integer, :seqNum1 ],
814
+ [ 22, 22, Pdb_AChar, :icode1 ],
815
+ [ 26, 28, Pdb_LString(3), :pep2 ],
816
+ [ 30, 30, Pdb_Character, :chainID2 ],
817
+ [ 32, 35, Pdb_Integer, :seqNum2 ],
818
+ [ 36, 36, Pdb_AChar, :icode2 ],
819
+ [ 44, 46, Pdb_Integer, :modNum ],
820
+ [ 54, 59, Pdb_Real('6.2'), :measure ]
821
+ )
822
+
823
+ # SITE record class
824
+ SITE =
825
+ def_rec([ 8, 10, Pdb_Integer, :seqNum ],
826
+ [ 12, 14, Pdb_LString(3), :siteID ],
827
+ [ 16, 17, Pdb_Integer, :numRes ],
828
+ [ 19, 21, Pdb_Residue_name, :resName1 ],
829
+ [ 23, 23, Pdb_Character, :chainID1 ],
830
+ [ 24, 27, Pdb_Integer, :seq1 ],
831
+ [ 28, 28, Pdb_AChar, :iCode1 ],
832
+ [ 30, 32, Pdb_Residue_name, :resName2 ],
833
+ [ 34, 34, Pdb_Character, :chainID2 ],
834
+ [ 35, 38, Pdb_Integer, :seq2 ],
835
+ [ 39, 39, Pdb_AChar, :iCode2 ],
836
+ [ 41, 43, Pdb_Residue_name, :resName3 ],
837
+ [ 45, 45, Pdb_Character, :chainID3 ],
838
+ [ 46, 49, Pdb_Integer, :seq3 ],
839
+ [ 50, 50, Pdb_AChar, :iCode3 ],
840
+ [ 52, 54, Pdb_Residue_name, :resName4 ],
841
+ [ 56, 56, Pdb_Character, :chainID4 ],
842
+ [ 57, 60, Pdb_Integer, :seq4 ],
843
+ [ 61, 61, Pdb_AChar, :iCode4 ]
844
+ )
845
+
846
+ # CRYST1 record class
847
+ CRYST1 =
848
+ def_rec([ 7, 15, Pdb_Real('9.3'), :a ],
849
+ [ 16, 24, Pdb_Real('9.3'), :b ],
850
+ [ 25, 33, Pdb_Real('9.3'), :c ],
851
+ [ 34, 40, Pdb_Real('7.2'), :alpha ],
852
+ [ 41, 47, Pdb_Real('7.2'), :beta ],
853
+ [ 48, 54, Pdb_Real('7.2'), :gamma ],
854
+ [ 56, 66, Pdb_LString, :sGroup ],
855
+ [ 67, 70, Pdb_Integer, :z ]
856
+ )
857
+
858
+ # ORIGX1 record class
859
+ #
860
+ # ORIGXn n=1, 2, or 3
861
+ ORIGX1 =
862
+ def_rec([ 11, 20, Pdb_Real('10.6'), :On1 ],
863
+ [ 21, 30, Pdb_Real('10.6'), :On2 ],
864
+ [ 31, 40, Pdb_Real('10.6'), :On3 ],
865
+ [ 46, 55, Pdb_Real('10.5'), :Tn ]
866
+ )
867
+
868
+ # ORIGX2 record class
869
+ ORIGX2 = new_inherit(ORIGX1)
870
+ # ORIGX3 record class
871
+ ORIGX3 = new_inherit(ORIGX1)
872
+
873
+ # SCALE1 record class
874
+ #
875
+ # SCALEn n=1, 2, or 3
876
+ SCALE1 =
877
+ def_rec([ 11, 20, Pdb_Real('10.6'), :Sn1 ],
878
+ [ 21, 30, Pdb_Real('10.6'), :Sn2 ],
879
+ [ 31, 40, Pdb_Real('10.6'), :Sn3 ],
880
+ [ 46, 55, Pdb_Real('10.5'), :Un ]
881
+ )
882
+
883
+ # SCALE2 record class
884
+ SCALE2 = new_inherit(SCALE1)
885
+ # SCALE3 record class
886
+ SCALE3 = new_inherit(SCALE1)
887
+
888
+ # MTRIX1 record class
889
+ #
890
+ # MTRIXn n=1,2, or 3
891
+ MTRIX1 =
892
+ def_rec([ 8, 10, Pdb_Integer, :serial ],
893
+ [ 11, 20, Pdb_Real('10.6'), :Mn1 ],
894
+ [ 21, 30, Pdb_Real('10.6'), :Mn2 ],
895
+ [ 31, 40, Pdb_Real('10.6'), :Mn3 ],
896
+ [ 46, 55, Pdb_Real('10.5'), :Vn ],
897
+ [ 60, 60, Pdb_Integer, :iGiven ]
898
+ )
899
+
900
+ # MTRIX2 record class
901
+ MTRIX2 = new_inherit(MTRIX1)
902
+ # MTRIX3 record class
903
+ MTRIX3 = new_inherit(MTRIX1)
904
+
905
+ # TVECT record class
906
+ TVECT =
907
+ def_rec([ 8, 10, Pdb_Integer, :serial ],
908
+ [ 11, 20, Pdb_Real('10.5'), :t1 ],
909
+ [ 21, 30, Pdb_Real('10.5'), :t2 ],
910
+ [ 31, 40, Pdb_Real('10.5'), :t3 ],
911
+ [ 41, 70, Pdb_String, :text ]
912
+ )
913
+
914
+ # MODEL record class
915
+ MODEL =
916
+ def_rec([ 11, 14, Pdb_Integer, :serial ]
917
+ )
918
+ # ChangeLog: model_serial are changed to serial
919
+
920
+ # ATOM record class
921
+ ATOM =
922
+ new_direct([ 7, 11, Pdb_Integer, :serial ],
923
+ [ 13, 16, Pdb_Atom, :name ],
924
+ [ 17, 17, Pdb_Character, :altLoc ],
925
+ [ 18, 20, Pdb_Residue_name, :resName ],
926
+ [ 22, 22, Pdb_Character, :chainID ],
927
+ [ 23, 26, Pdb_Integer, :resSeq ],
928
+ [ 27, 27, Pdb_AChar, :iCode ],
929
+ [ 31, 38, Pdb_Real('8.3'), :x ],
930
+ [ 39, 46, Pdb_Real('8.3'), :y ],
931
+ [ 47, 54, Pdb_Real('8.3'), :z ],
932
+ [ 55, 60, Pdb_Real('6.2'), :occupancy ],
933
+ [ 61, 66, Pdb_Real('6.2'), :tempFactor ],
934
+ [ 73, 76, Pdb_LString(4), :segID ],
935
+ [ 77, 78, Pdb_LString(2), :element ],
936
+ [ 79, 80, Pdb_LString(2), :charge ]
937
+ )
938
+
939
+ # ATOM record class
940
+ class ATOM
941
+
942
+ include Utils
943
+ include Comparable
944
+
945
+ # for backward compatibility
946
+ alias occ occupancy
947
+ # for backward compatibility
948
+ alias bfac tempFactor
949
+
950
+ # residue the atom belongs to.
951
+ attr_accessor :residue
952
+
953
+ # SIGATM record
954
+ attr_accessor :sigatm
955
+
956
+ # ANISOU record
957
+ attr_accessor :anisou
958
+
959
+ # TER record
960
+ attr_accessor :ter
961
+
962
+ #Returns a Coordinate class instance of the xyz positions
963
+ def xyz
964
+ Coordinate[ x, y, z ]
965
+ end
966
+
967
+ #Returns an array of the xyz positions
968
+ def to_a
969
+ [ x, y, z ]
970
+ end
971
+
972
+ #Sorts based on serial numbers
973
+ def <=>(other)
974
+ return serial <=> other.serial
975
+ end
976
+
977
+ def do_parse
978
+ return self if @parsed or !@str
979
+ self.serial = @str[6..10].to_i
980
+ self.name = @str[12..15].strip
981
+ self.altLoc = @str[16..16]
982
+ self.resName = @str[17..19].strip
983
+ self.chainID = @str[21..21]
984
+ self.resSeq = @str[22..25].to_i
985
+ self.iCode = @str[26..26].strip
986
+ self.x = @str[30..37].to_f
987
+ self.y = @str[38..45].to_f
988
+ self.z = @str[46..53].to_f
989
+ self.occupancy = @str[54..59].to_f
990
+ self.tempFactor = @str[60..65].to_f
991
+ self.segID = @str[72..75].to_s.rstrip
992
+ self.element = @str[76..77].to_s.lstrip
993
+ self.charge = @str[78..79].to_s.strip
994
+ @parsed = true
995
+ self
996
+ end
997
+
998
+ def justify_atomname
999
+ atomname = self.name.to_s
1000
+ return atomname[0, 4] if atomname.length >= 4
1001
+ case atomname.length
1002
+ when 0
1003
+ return ' '
1004
+ when 1
1005
+ return ' ' + atomname + ' '
1006
+ when 2
1007
+ if /\A[0-9]/ =~ atomname then
1008
+ return sprintf('%-4s', atomname)
1009
+ elsif /[0-9]\z/ =~ atomname then
1010
+ return sprintf(' %-3s', atomname)
1011
+ end
1012
+ when 3
1013
+ if /\A[0-9]/ =~ atomname then
1014
+ return sprintf('%-4s', atomname)
1015
+ end
1016
+ end
1017
+ # ambiguous case for two- or three-letter name
1018
+ elem = self.element.to_s.strip
1019
+ if elem.size > 0 and i = atomname.index(elem) then
1020
+ if i == 0 and elem.size == 1 then
1021
+ return sprintf(' %-3s', atomname)
1022
+ else
1023
+ return sprintf('%-4s', atomname)
1024
+ end
1025
+ end
1026
+ if self.kind_of?(HETATM) then
1027
+ if /\A(B[^AEHIKR]|C[^ADEFLMORSU]|F[^EMR]|H[^EFGOS]|I[^NR]|K[^R]|N[^ABDEIOP]|O[^S]|P[^ABDMORTU]|S[^BCEGIMNR]|V|W|Y[^B])/ =~
1028
+ atomname then
1029
+ return sprintf(' %-3s', atomname)
1030
+ else
1031
+ return sprintf('%-4s', atomname)
1032
+ end
1033
+ else # ATOM
1034
+ if /\A[CHONSP]/ =~ atomname then
1035
+ return sprintf(' %-3s', atomname)
1036
+ else
1037
+ return sprintf('%-4s', atomname)
1038
+ end
1039
+ end
1040
+ # could not be reached here
1041
+ raise 'bug!'
1042
+ end
1043
+ private :justify_atomname
1044
+
1045
+ def to_s
1046
+ atomname = justify_atomname
1047
+ sprintf("%-6s%5d %-4s%-1s%3s %-1s%4d%-1s %8.3f%8.3f%8.3f%6.2f%6.2f %-4s%2s%-2s\n",
1048
+ self.record_name,
1049
+ self.serial,
1050
+ atomname,
1051
+ self.altLoc,
1052
+ self.resName,
1053
+ self.chainID,
1054
+ self.resSeq,
1055
+ self.iCode,
1056
+ self.x, self.y, self.z,
1057
+ self.occupancy,
1058
+ self.tempFactor,
1059
+ self.segID,
1060
+ self.element,
1061
+ self.charge)
1062
+ end
1063
+ end #class ATOM
1064
+
1065
+ # SIGATM record class
1066
+ SIGATM =
1067
+ def_rec([ 7, 11, Pdb_Integer, :serial ],
1068
+ [ 13, 16, Pdb_Atom, :name ],
1069
+ [ 17, 17, Pdb_Character, :altLoc ],
1070
+ [ 18, 20, Pdb_Residue_name, :resName ],
1071
+ [ 22, 22, Pdb_Character, :chainID ],
1072
+ [ 23, 26, Pdb_Integer, :resSeq ],
1073
+ [ 27, 27, Pdb_AChar, :iCode ],
1074
+ [ 31, 38, Pdb_Real('8.3'), :sigX ],
1075
+ [ 39, 46, Pdb_Real('8.3'), :sigY ],
1076
+ [ 47, 54, Pdb_Real('8.3'), :sigZ ],
1077
+ [ 55, 60, Pdb_Real('6.2'), :sigOcc ],
1078
+ [ 61, 66, Pdb_Real('6.2'), :sigTemp ],
1079
+ [ 73, 76, Pdb_LString(4), :segID ],
1080
+ [ 77, 78, Pdb_LString(2), :element ],
1081
+ [ 79, 80, Pdb_LString(2), :charge ]
1082
+ )
1083
+
1084
+ # ANISOU record class
1085
+ ANISOU =
1086
+ def_rec([ 7, 11, Pdb_Integer, :serial ],
1087
+ [ 13, 16, Pdb_Atom, :name ],
1088
+ [ 17, 17, Pdb_Character, :altLoc ],
1089
+ [ 18, 20, Pdb_Residue_name, :resName ],
1090
+ [ 22, 22, Pdb_Character, :chainID ],
1091
+ [ 23, 26, Pdb_Integer, :resSeq ],
1092
+ [ 27, 27, Pdb_AChar, :iCode ],
1093
+ [ 29, 35, Pdb_Integer, :U11 ],
1094
+ [ 36, 42, Pdb_Integer, :U22 ],
1095
+ [ 43, 49, Pdb_Integer, :U33 ],
1096
+ [ 50, 56, Pdb_Integer, :U12 ],
1097
+ [ 57, 63, Pdb_Integer, :U13 ],
1098
+ [ 64, 70, Pdb_Integer, :U23 ],
1099
+ [ 73, 76, Pdb_LString(4), :segID ],
1100
+ [ 77, 78, Pdb_LString(2), :element ],
1101
+ [ 79, 80, Pdb_LString(2), :charge ]
1102
+ )
1103
+
1104
+ # ANISOU record class
1105
+ class ANISOU
1106
+ # SIGUIJ record
1107
+ attr_accessor :siguij
1108
+ end #class ANISOU
1109
+
1110
+ # SIGUIJ record class
1111
+ SIGUIJ =
1112
+ def_rec([ 7, 11, Pdb_Integer, :serial ],
1113
+ [ 13, 16, Pdb_Atom, :name ],
1114
+ [ 17, 17, Pdb_Character, :altLoc ],
1115
+ [ 18, 20, Pdb_Residue_name, :resName ],
1116
+ [ 22, 22, Pdb_Character, :chainID ],
1117
+ [ 23, 26, Pdb_Integer, :resSeq ],
1118
+ [ 27, 27, Pdb_AChar, :iCode ],
1119
+ [ 29, 35, Pdb_Integer, :SigmaU11 ],
1120
+ [ 36, 42, Pdb_Integer, :SigmaU22 ],
1121
+ [ 43, 49, Pdb_Integer, :SigmaU33 ],
1122
+ [ 50, 56, Pdb_Integer, :SigmaU12 ],
1123
+ [ 57, 63, Pdb_Integer, :SigmaU13 ],
1124
+ [ 64, 70, Pdb_Integer, :SigmaU23 ],
1125
+ [ 73, 76, Pdb_LString(4), :segID ],
1126
+ [ 77, 78, Pdb_LString(2), :element ],
1127
+ [ 79, 80, Pdb_LString(2), :charge ]
1128
+ )
1129
+
1130
+ # TER record class
1131
+ TER =
1132
+ def_rec([ 7, 11, Pdb_Integer, :serial ],
1133
+ [ 18, 20, Pdb_Residue_name, :resName ],
1134
+ [ 22, 22, Pdb_Character, :chainID ],
1135
+ [ 23, 26, Pdb_Integer, :resSeq ],
1136
+ [ 27, 27, Pdb_AChar, :iCode ]
1137
+ )
1138
+
1139
+ #HETATM =
1140
+ # new_direct([ 7, 11, Pdb_Integer, :serial ],
1141
+ # [ 13, 16, Pdb_Atom, :name ],
1142
+ # [ 17, 17, Pdb_Character, :altLoc ],
1143
+ # [ 18, 20, Pdb_Residue_name, :resName ],
1144
+ # [ 22, 22, Pdb_Character, :chainID ],
1145
+ # [ 23, 26, Pdb_Integer, :resSeq ],
1146
+ # [ 27, 27, Pdb_AChar, :iCode ],
1147
+ # [ 31, 38, Pdb_Real('8.3'), :x ],
1148
+ # [ 39, 46, Pdb_Real('8.3'), :y ],
1149
+ # [ 47, 54, Pdb_Real('8.3'), :z ],
1150
+ # [ 55, 60, Pdb_Real('6.2'), :occupancy ],
1151
+ # [ 61, 66, Pdb_Real('6.2'), :tempFactor ],
1152
+ # [ 73, 76, Pdb_LString(4), :segID ],
1153
+ # [ 77, 78, Pdb_LString(2), :element ],
1154
+ # [ 79, 80, Pdb_LString(2), :charge ]
1155
+ # )
1156
+
1157
+ # HETATM record class
1158
+ HETATM = new_inherit(ATOM)
1159
+
1160
+ # HETATM record class.
1161
+ # It inherits ATOM class.
1162
+ class HETATM; end
1163
+
1164
+ # ENDMDL record class
1165
+ ENDMDL =
1166
+ def_rec([ 2, 1, Pdb_Integer, :serial ] # dummy field (always 0)
1167
+ )
1168
+
1169
+ # CONECT record class
1170
+ CONECT =
1171
+ def_rec([ 7, 11, Pdb_Integer, :serial ],
1172
+ [ 12, 16, Pdb_Integer, :serial ],
1173
+ [ 17, 21, Pdb_Integer, :serial ],
1174
+ [ 22, 26, Pdb_Integer, :serial ],
1175
+ [ 27, 31, Pdb_Integer, :serial ],
1176
+ [ 32, 36, Pdb_Integer, :serial ],
1177
+ [ 37, 41, Pdb_Integer, :serial ],
1178
+ [ 42, 46, Pdb_Integer, :serial ],
1179
+ [ 47, 51, Pdb_Integer, :serial ],
1180
+ [ 52, 56, Pdb_Integer, :serial ],
1181
+ [ 57, 61, Pdb_Integer, :serial ]
1182
+ )
1183
+
1184
+ # MASTER record class
1185
+ MASTER =
1186
+ def_rec([ 11, 15, Pdb_Integer, :numRemark ],
1187
+ [ 16, 20, Pdb_Integer, "0" ],
1188
+ [ 21, 25, Pdb_Integer, :numHet ],
1189
+ [ 26, 30, Pdb_Integer, :numHelix ],
1190
+ [ 31, 35, Pdb_Integer, :numSheet ],
1191
+ [ 36, 40, Pdb_Integer, :numTurn ],
1192
+ [ 41, 45, Pdb_Integer, :numSite ],
1193
+ [ 46, 50, Pdb_Integer, :numXform ],
1194
+ [ 51, 55, Pdb_Integer, :numCoord ],
1195
+ [ 56, 60, Pdb_Integer, :numTer ],
1196
+ [ 61, 65, Pdb_Integer, :numConect ],
1197
+ [ 66, 70, Pdb_Integer, :numSeq ]
1198
+ )
1199
+
1200
+ # JRNL record classes
1201
+ class Jrnl < self
1202
+ # subrecord of JRNL
1203
+ # 13, 16
1204
+ # JRNL AUTH record class
1205
+ AUTH =
1206
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "AUTH"
1207
+ [ 17, 18, Pdb_Continuation, nil ],
1208
+ [ 20, 70, Pdb_List, :authorList ]
1209
+ )
1210
+
1211
+ # JRNL TITL record class
1212
+ TITL =
1213
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "TITL"
1214
+ [ 17, 18, Pdb_Continuation, nil ],
1215
+ [ 20, 70, Pdb_LString, :title ]
1216
+ )
1217
+
1218
+ # JRNL EDIT record class
1219
+ EDIT =
1220
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "EDIT"
1221
+ [ 17, 18, Pdb_Continuation, nil ],
1222
+ [ 20, 70, Pdb_List, :editorList ]
1223
+ )
1224
+
1225
+ # JRNL REF record class
1226
+ REF =
1227
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "REF"
1228
+ [ 17, 18, Pdb_Continuation, nil ],
1229
+ [ 20, 47, Pdb_LString, :pubName ],
1230
+ [ 50, 51, Pdb_LString(2), "V." ],
1231
+ [ 52, 55, Pdb_String, :volume ],
1232
+ [ 57, 61, Pdb_String, :page ],
1233
+ [ 63, 66, Pdb_Integer, :year ]
1234
+ )
1235
+
1236
+ # JRNL PUBL record class
1237
+ PUBL =
1238
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "PUBL"
1239
+ [ 17, 18, Pdb_Continuation, nil ],
1240
+ [ 20, 70, Pdb_LString, :pub ]
1241
+ )
1242
+
1243
+ # JRNL REFN record class
1244
+ REFN =
1245
+ def_rec([ 13, 16, Pdb_String, :sub_record ], # "REFN"
1246
+ [ 20, 23, Pdb_LString(4), "ASTM" ],
1247
+ [ 25, 30, Pdb_LString(6), :astm ],
1248
+ [ 33, 34, Pdb_LString(2), :country ],
1249
+ [ 36, 39, Pdb_LString(4), :BorS ], # "ISBN" or "ISSN"
1250
+ [ 41, 65, Pdb_LString, :isbn ],
1251
+ [ 67, 70, Pdb_LString(4), :coden ] # "0353" for unpublished
1252
+ )
1253
+
1254
+ # default or unknown record
1255
+ #
1256
+ Default =
1257
+ def_rec([ 13, 16, Pdb_String, :sub_record ]) # ""
1258
+
1259
+ # definitions (hash)
1260
+ Definition = create_definition_hash
1261
+ end #class JRNL
1262
+
1263
+ # REMARK record classes for REMARK 1
1264
+ class Remark1 < self
1265
+ # 13, 16
1266
+ # REMARK 1 REFERENCE record class
1267
+ EFER =
1268
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1269
+ [ 12, 20, Pdb_String, :sub_record ], # "REFERENCE"
1270
+ [ 22, 70, Pdb_Integer, :refNum ]
1271
+ )
1272
+
1273
+ # REMARK 1 AUTH record class
1274
+ AUTH =
1275
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1276
+ [ 13, 16, Pdb_String, :sub_record ], # "AUTH"
1277
+ [ 17, 18, Pdb_Continuation, nil ],
1278
+ [ 20, 70, Pdb_List, :authorList ]
1279
+ )
1280
+
1281
+ # REMARK 1 TITL record class
1282
+ TITL =
1283
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1284
+ [ 13, 16, Pdb_String, :sub_record ], # "TITL"
1285
+ [ 17, 18, Pdb_Continuation, nil ],
1286
+ [ 20, 70, Pdb_LString, :title ]
1287
+ )
1288
+
1289
+ # REMARK 1 EDIT record class
1290
+ EDIT =
1291
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1292
+ [ 13, 16, Pdb_String, :sub_record ], # "EDIT"
1293
+ [ 17, 18, Pdb_Continuation, nil ],
1294
+ [ 20, 70, Pdb_LString, :editorList ]
1295
+ )
1296
+
1297
+ # REMARK 1 REF record class
1298
+ REF =
1299
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1300
+ [ 13, 16, Pdb_LString(3), :sub_record ], # "REF"
1301
+ [ 17, 18, Pdb_Continuation, nil ],
1302
+ [ 20, 47, Pdb_LString, :pubName ],
1303
+ [ 50, 51, Pdb_LString(2), "V." ],
1304
+ [ 52, 55, Pdb_String, :volume ],
1305
+ [ 57, 61, Pdb_String, :page ],
1306
+ [ 63, 66, Pdb_Integer, :year ]
1307
+ )
1308
+
1309
+ # REMARK 1 PUBL record class
1310
+ PUBL =
1311
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1312
+ [ 13, 16, Pdb_String, :sub_record ], # "PUBL"
1313
+ [ 17, 18, Pdb_Continuation, nil ],
1314
+ [ 20, 70, Pdb_LString, :pub ]
1315
+ )
1316
+
1317
+ # REMARK 1 REFN record class
1318
+ REFN =
1319
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1320
+ [ 13, 16, Pdb_String, :sub_record ], # "REFN"
1321
+ [ 20, 23, Pdb_LString(4), "ASTM" ],
1322
+ [ 25, 30, Pdb_LString, :astm ],
1323
+ [ 33, 34, Pdb_LString, :country ],
1324
+ [ 36, 39, Pdb_LString(4), :BorS ],
1325
+ [ 41, 65, Pdb_LString, :isbn ],
1326
+ [ 68, 70, Pdb_LString(4), :coden ]
1327
+ )
1328
+
1329
+ # default (or unknown) record class for REMARK 1
1330
+ Default =
1331
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "1"
1332
+ [ 13, 16, Pdb_String, :sub_record ] # ""
1333
+ )
1334
+
1335
+ # definitions (hash)
1336
+ Definition = create_definition_hash
1337
+ end #class Remark1
1338
+
1339
+ # REMARK record classes for REMARK 2
1340
+ class Remark2 < self
1341
+ # 29, 38 == 'ANGSTROMS.'
1342
+ ANGSTROMS =
1343
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "2"
1344
+ [ 12, 22, Pdb_LString(11), :sub_record ], # "RESOLUTION."
1345
+ [ 23, 27, Pdb_Real('5.2'), :resolution ],
1346
+ [ 29, 38, Pdb_LString(10), "ANGSTROMS." ]
1347
+ )
1348
+
1349
+ # 23, 38 == ' NOT APPLICABLE.'
1350
+ NOT_APPLICABLE =
1351
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "2"
1352
+ [ 12, 22, Pdb_LString(11), :sub_record ], # "RESOLUTION."
1353
+ [ 23, 38, Pdb_LString(16), :resolution ], # " NOT APPLICABLE."
1354
+ [ 41, 70, Pdb_String, :comment ]
1355
+ )
1356
+
1357
+ # others
1358
+ Default =
1359
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ], # "2"
1360
+ [ 12, 22, Pdb_LString(11), :sub_record ], # "RESOLUTION."
1361
+ [ 24, 70, Pdb_String, :comment ]
1362
+ )
1363
+ end #class Remark2
1364
+
1365
+ # REMARK record class for REMARK n (n>=3)
1366
+ RemarkN =
1367
+ def_rec([ 8, 10, Pdb_Integer, :remarkNum ],
1368
+ [ 12, 70, Pdb_LString, :text ]
1369
+ )
1370
+
1371
+ # default (or unknown) record class
1372
+ Default = def_rec([ 8, 70, Pdb_LString, :text ])
1373
+
1374
+ # definitions (hash)
1375
+ Definition = create_definition_hash
1376
+
1377
+ # END record class.
1378
+ #
1379
+ # Because END is a reserved word of Ruby, it is separately
1380
+ # added to the hash
1381
+ End =
1382
+ def_rec([ 2, 1, Pdb_Integer, :serial ]) # dummy field (always 0)
1383
+
1384
+ Definition['END'.intern] = End
1385
+
1386
+ # Basically just look up the class in Definition hash
1387
+ # do some munging for JRNL and REMARK
1388
+ def self.get_record_class(str)
1389
+ t = fetch_record_name(str)
1390
+ t = t.intern unless t.empty?
1391
+ if d = Definition[t] then
1392
+ return d
1393
+ end
1394
+ case t
1395
+ when :JRNL
1396
+ ts = str[12..15].to_s.strip
1397
+ ts = ts.intern unless ts.empty?
1398
+ d = Jrnl::Definition[ts]
1399
+ when :REMARK
1400
+ case str[7..9].to_i
1401
+ when 1
1402
+ ts = str[12..15].to_s.strip
1403
+ ts = ts.intern unless ts.empty?
1404
+ d = Remark1::Definition[ts]
1405
+ when 2
1406
+ if str[28..37] == 'ANGSTROMS.' then
1407
+ d = Remark2::ANGSTROMS
1408
+ elsif str[22..37] == ' NOT APPLICABLE.' then
1409
+ d = Remark2::NOT_APPLICABLE
1410
+ else
1411
+ d = Remark2::Default
1412
+ end
1413
+ else
1414
+ d = RemarkN
1415
+ end
1416
+ else
1417
+ # unknown field
1418
+ d = Default
1419
+ end
1420
+ return d
1421
+ end
1422
+ end #class Record
1423
+
1424
+ Coordinate_fileds = {
1425
+ 'MODEL' => true,
1426
+ :MODEL => true,
1427
+ 'ENDMDL' => true,
1428
+ :ENDMDL => true,
1429
+ 'ATOM' => true,
1430
+ :ATOM => true,
1431
+ 'HETATM' => true,
1432
+ :HETATM => true,
1433
+ 'SIGATM' => true,
1434
+ :SIGATM => true,
1435
+ 'SIGUIJ' => true,
1436
+ :SIGUIJ => true,
1437
+ 'ANISOU' => true,
1438
+ :ANISOU => true,
1439
+ 'TER' => true,
1440
+ :TER => true,
1441
+ }
1442
+
1443
+ # Creates a new Bio::PDB object from given <em>str</em>.
1444
+ def initialize(str)
1445
+ #Aha! Our entry into the world of PDB parsing, we initialise a PDB
1446
+ #object with the whole PDB file as a string
1447
+ #each PDB has an array of the lines of the original file
1448
+ #a bit memory-tastic! A hash of records and an array of models
1449
+ #also has an id
1450
+
1451
+ @data = str.split(/[\r\n]+/)
1452
+ @hash = {}
1453
+ @models = []
1454
+ @id = nil
1455
+
1456
+ #Flag to say whether the current line is part of a continuation
1457
+ cont = false
1458
+
1459
+ #Empty current model
1460
+ cModel = Model.new
1461
+ cChain = nil #Chain.new
1462
+ cResidue = nil #Residue.new
1463
+ cLigand = nil #Heterogen.new
1464
+ c_atom = nil
1465
+
1466
+ #Goes through each line and replace that line with a PDB::Record
1467
+ @data.collect! do |line|
1468
+ #Go to next if the previous line was contiunation able, and
1469
+ #add_continuation returns true. Line is added by add_continuation
1470
+ next if cont and cont = cont.add_continuation(line)
1471
+
1472
+ #Make the new record
1473
+ f = Record.get_record_class(line).new.initialize_from_string(line)
1474
+ #p f
1475
+ #Set cont
1476
+ cont = f if f.continue?
1477
+ #Set the hash to point to this record either by adding to an
1478
+ #array, or on it's own
1479
+ key = f.record_name
1480
+ if a = @hash[key] then
1481
+ a << f
1482
+ else
1483
+ @hash[key] = [ f ]
1484
+ end
1485
+
1486
+ # Do something for ATOM and HETATM
1487
+ if key == 'ATOM' or key == 'HETATM' then
1488
+ if cChain and f.chainID == cChain.id
1489
+ chain = cChain
1490
+ else
1491
+ if chain = cModel[f.chainID]
1492
+ cChain = chain unless cChain
1493
+ else
1494
+ # If we don't have chain, add a new chain
1495
+ newChain = Chain.new(f.chainID, cModel)
1496
+ cModel.addChain(newChain)
1497
+ cChain = newChain
1498
+ chain = newChain
1499
+ end
1500
+ # chain might be changed, clearing cResidue and cLigand
1501
+ cResidue = nil
1502
+ cLigand = nil
1503
+ end
1504
+ end
1505
+
1506
+ case key
1507
+ when 'ATOM'
1508
+ c_atom = f
1509
+ residueID = Residue.get_residue_id_from_atom(f)
1510
+
1511
+ if cResidue and residueID == cResidue.id
1512
+ residue = cResidue
1513
+ else
1514
+ if residue = chain.get_residue_by_id(residueID)
1515
+ cResidue = residue unless cResidue
1516
+ else
1517
+ # add a new residue
1518
+ newResidue = Residue.new(f.resName, f.resSeq, f.iCode, chain)
1519
+ chain.addResidue(newResidue)
1520
+ cResidue = newResidue
1521
+ residue = newResidue
1522
+ end
1523
+ end
1524
+
1525
+ f.residue = residue
1526
+ residue.addAtom(f)
1527
+
1528
+ when 'HETATM'
1529
+ c_atom = f
1530
+ residueID = Heterogen.get_residue_id_from_atom(f)
1531
+
1532
+ if cLigand and residueID == cLigand.id
1533
+ ligand = cLigand
1534
+ else
1535
+ if ligand = chain.get_heterogen_by_id(residueID)
1536
+ cLigand = ligand unless cLigand
1537
+ else
1538
+ # add a new heterogen
1539
+ newLigand = Heterogen.new(f.resName, f.resSeq, f.iCode, chain)
1540
+ chain.addLigand(newLigand)
1541
+ cLigand = newLigand
1542
+ ligand = newLigand
1543
+ #Each model has a special solvent chain. (for compatibility)
1544
+ if f.resName == 'HOH'
1545
+ cModel.addSolvent(newLigand)
1546
+ end
1547
+ end
1548
+ end
1549
+
1550
+ f.residue = ligand
1551
+ ligand.addAtom(f)
1552
+
1553
+ when 'MODEL'
1554
+ c_atom = nil
1555
+ cChain = nil
1556
+ cResidue = nil
1557
+ cLigand = nil
1558
+ if cModel.model_serial or cModel.chains.size > 0 then
1559
+ self.addModel(cModel)
1560
+ end
1561
+ cModel = Model.new(f.serial)
1562
+
1563
+ when 'TER'
1564
+ if c_atom
1565
+ c_atom.ter = f
1566
+ else
1567
+ #$stderr.puts "Warning: stray TER?"
1568
+ end
1569
+ when 'SIGATM'
1570
+ if c_atom
1571
+ #$stderr.puts "Warning: duplicated SIGATM?" if c_atom.sigatm
1572
+ c_atom.sigatm = f
1573
+ else
1574
+ #$stderr.puts "Warning: stray SIGATM?"
1575
+ end
1576
+ when 'ANISOU'
1577
+ if c_atom
1578
+ #$stderr.puts "Warning: duplicated ANISOU?" if c_atom.anisou
1579
+ c_atom.anisou = f
1580
+ else
1581
+ #$stderr.puts "Warning: stray ANISOU?"
1582
+ end
1583
+ when 'SIGUIJ'
1584
+ if c_atom and c_atom.anisou
1585
+ #$stderr.puts "Warning: duplicated SIGUIJ?" if c_atom.anisou.siguij
1586
+ c_atom.anisou.siguij = f
1587
+ else
1588
+ #$stderr.puts "Warning: stray SIGUIJ?"
1589
+ end
1590
+
1591
+ else
1592
+ c_atom = nil
1593
+
1594
+ end
1595
+ f
1596
+ end #each
1597
+ #At the end we need to add the final model
1598
+ self.addModel(cModel)
1599
+ @data.compact!
1600
+ end #def initialize
1601
+
1602
+ # all records in this entry as an array.
1603
+ attr_reader :data
1604
+
1605
+ # all records in this entry as an hash accessed by record names.
1606
+ attr_reader :hash
1607
+
1608
+ # models in this entry (array).
1609
+ attr_reader :models
1610
+
1611
+ # Adds a <code>Bio::Model</code> object to the current strucutre.
1612
+ # Adds a model to the current structure.
1613
+ # Returns self.
1614
+ def addModel(model)
1615
+ raise "Expecting a Bio::PDB::Model" if not model.is_a? Bio::PDB::Model
1616
+ @models.push(model)
1617
+ self
1618
+ end
1619
+
1620
+ # Iterates over each model.
1621
+ # Iterates over each of the models in the structure.
1622
+ # Returns <code>self</code>.
1623
+ def each
1624
+ @models.each{ |model| yield model }
1625
+ self
1626
+ end
1627
+ # Alias needed for Bio::PDB::ModelFinder
1628
+ alias each_model each
1629
+
1630
+ # Provides keyed access to the models based on serial number
1631
+ # returns nil if it's not there
1632
+ def [](key)
1633
+ @models.find{ |model| key == model.model_serial }
1634
+ end
1635
+ #--
1636
+ # (should it raise an exception?)
1637
+ #++
1638
+
1639
+ #--
1640
+ #Stringifies to a list of atom records - we could add the annotation
1641
+ #as well if needed
1642
+ #++
1643
+
1644
+ # Returns a string of Bio::PDB::Models. This propogates down the heirarchy
1645
+ # till you get to Bio::PDB::Record::ATOM which are outputed in PDB format
1646
+ def to_s
1647
+ string = ""
1648
+ @models.each{ |model| string << model.to_s }
1649
+ string << "END\n"
1650
+ return string
1651
+ end
1652
+
1653
+ #Makes a hash out of an array of PDB::Records and some kind of symbol
1654
+ #.__send__ invokes the method specified by the symbol.
1655
+ #Essentially it ends up with a hash with keys given in the sub_record
1656
+ #Not sure I fully understand this
1657
+ def make_hash(ary, meth)
1658
+ h = {}
1659
+ ary.each do |f|
1660
+ k = f.__send__(meth)
1661
+ h[k] = [] unless h.has_key?(k)
1662
+ h[k] << f
1663
+ end
1664
+ h
1665
+ end
1666
+ private :make_hash
1667
+
1668
+ #Takes an array and returns another array of PDB::Records
1669
+ def make_grouping(ary, meth)
1670
+ a = []
1671
+ k_prev = nil
1672
+ ary.each do |f|
1673
+ k = f.__send__(meth)
1674
+ if k_prev and k_prev == k then
1675
+ a.last << f
1676
+ else
1677
+ a << []
1678
+ a.last << f
1679
+ end
1680
+ k_prev = k
1681
+ end
1682
+ a
1683
+ end
1684
+ private :make_grouping
1685
+
1686
+ # Gets all records whose record type is _name_.
1687
+ # Returns an array of <code>Bio::PDB::Record::*</code> objects.
1688
+ #
1689
+ # if _name_ is nil, returns hash storing all record data.
1690
+ #
1691
+ # Example:
1692
+ # p pdb.record('HETATM')
1693
+ # p pdb.record['HETATM']
1694
+ #
1695
+ def record(name = nil)
1696
+ name ? (@hash[name] || []) : @hash
1697
+ end
1698
+
1699
+ #--
1700
+ # PDB original methods
1701
+ #Returns a hash of the REMARK records based on the remarkNum
1702
+ #++
1703
+
1704
+ # Gets REMARK records.
1705
+ # If no arguments, it returns all REMARK records as a hash.
1706
+ # If remark number is specified, returns only corresponding REMARK records.
1707
+ # If number == 1 or 2 ("REMARK 1" or "REMARK 2"), returns an array
1708
+ # of Bio::PDB::Record instances. Otherwise, returns an array of strings.
1709
+ #
1710
+ def remark(nn = nil)
1711
+ unless defined?(@remark)
1712
+ h = make_hash(self.record('REMARK'), :remarkNum)
1713
+ h.each do |i, a|
1714
+ a.shift # remove first record (= space only)
1715
+ if i != 1 and i != 2 then
1716
+ a.collect! { |f| f.text.gsub(/\s+\z/, '') }
1717
+ end
1718
+ end
1719
+ @remark = h
1720
+ end
1721
+ nn ? @remark[nn] : @remark
1722
+ end
1723
+
1724
+ # Gets JRNL records.
1725
+ # If no arguments, it returns all JRNL records as a hash.
1726
+ # If sub record name is specified, it returns only corresponding records
1727
+ # as an array of Bio::PDB::Record instances.
1728
+ #
1729
+ def jrnl(sub_record = nil)
1730
+ unless defined?(@jrnl)
1731
+ @jrnl = make_hash(self.record('JRNL'), :sub_record)
1732
+ end
1733
+ sub_record ? @jrnl[sub_record] : @jrnl
1734
+ end
1735
+
1736
+ #--
1737
+ #Finding methods - just grabs the record with the appropriate id
1738
+ #or returns and array of all of them
1739
+ #++
1740
+
1741
+ # Gets HELIX records.
1742
+ # If no arguments are given, it returns all HELIX records.
1743
+ # (Returns an array of <code>Bio::PDB::Record::HELIX</code> instances.)
1744
+ # If <em>helixID</em> is given, it only returns records
1745
+ # corresponding to given <em>helixID</em>.
1746
+ # (Returns an <code>Bio::PDB::Record::HELIX</code> instance.)
1747
+ #
1748
+ def helix(helixID = nil)
1749
+ if helixID then
1750
+ self.record('HELIX').find { |f| f.helixID == helixID }
1751
+ else
1752
+ self.record('HELIX')
1753
+ end
1754
+ end
1755
+
1756
+ # Gets TURN records.
1757
+ # If no arguments are given, it returns all TURN records.
1758
+ # (Returns an array of <code>Bio::PDB::Record::TURN</code> instances.)
1759
+ # If <em>turnId</em> is given, it only returns a record
1760
+ # corresponding to given <em>turnId</em>.
1761
+ # (Returns an <code>Bio::PDB::Record::TURN</code> instance.)
1762
+ #
1763
+ def turn(turnId = nil)
1764
+ if turnId then
1765
+ self.record('TURN').find { |f| f.turnId == turnId }
1766
+ else
1767
+ self.record('TURN')
1768
+ end
1769
+ end
1770
+
1771
+ # Gets SHEET records.
1772
+ # If no arguments are given, it returns all SHEET records
1773
+ # as an array of arrays of <code>Bio::PDB::Record::SHEET</code> instances.
1774
+ # If <em>sheetID</em> is given, it returns an array of
1775
+ # <code>Bio::PDB::Record::SHEET</code> instances.
1776
+ def sheet(sheetID = nil)
1777
+ unless defined?(@sheet)
1778
+ @sheet = make_grouping(self.record('SHEET'), :sheetID)
1779
+ end
1780
+ if sheetID then
1781
+ @sheet.find_all { |f| f.first.sheetID == sheetID }
1782
+ else
1783
+ @sheet
1784
+ end
1785
+ end
1786
+
1787
+ # Gets SSBOND records.
1788
+ def ssbond
1789
+ self.record('SSBOND')
1790
+ end
1791
+
1792
+ #--
1793
+ # Get seqres - we get this to return a nice Bio::Seq object
1794
+ #++
1795
+
1796
+ # Amino acid or nucleic acid sequence of backbone residues in "SEQRES".
1797
+ # If <em>chainID</em> is given, it returns corresponding sequence
1798
+ # as an array of string.
1799
+ # Otherwise, returns a hash which contains all sequences.
1800
+ #
1801
+ def seqres(chainID = nil)
1802
+ unless defined?(@seqres)
1803
+ h = make_hash(self.record('SEQRES'), :chainID)
1804
+ newHash = {}
1805
+ h.each do |k, a|
1806
+ a.collect! { |f| f.resName }
1807
+ a.flatten!
1808
+ # determine nuc or aa?
1809
+ tmp = Hash.new(0)
1810
+ a[0,13].each { |x| tmp[x.to_s.strip.size] += 1 }
1811
+ if tmp[3] >= tmp[1] then
1812
+ # amino acid sequence
1813
+ a.collect! do |aa|
1814
+ #aa is three letter code: i.e. ALA
1815
+ #need to look up with Ala
1816
+ aa = aa.capitalize
1817
+ (begin
1818
+ Bio::AminoAcid.three2one(aa)
1819
+ rescue ArgumentError
1820
+ nil
1821
+ end || 'X')
1822
+ end
1823
+ seq = Bio::Sequence::AA.new(a.to_s)
1824
+ else
1825
+ # nucleic acid sequence
1826
+ a.collect! do |na|
1827
+ na = na.delete('^a-zA-Z')
1828
+ na.size == 1 ? na : 'n'
1829
+ end
1830
+ seq = Bio::Sequence::NA.new(a.to_s)
1831
+ end
1832
+ newHash[k] = seq
1833
+ end
1834
+ @seqres = newHash
1835
+ end
1836
+ if chainID then
1837
+ @seqres[chainID]
1838
+ else
1839
+ @seqres
1840
+ end
1841
+ end
1842
+
1843
+ # Gets DBREF records.
1844
+ # Returns an array of Bio::PDB::Record::DBREF objects.
1845
+ #
1846
+ # If <em>chainID</em> is given, it returns corresponding DBREF records.
1847
+ def dbref(chainID = nil)
1848
+ if chainID then
1849
+ self.record('DBREF').find_all { |f| f.chainID == chainID }
1850
+ else
1851
+ self.record('DBREF')
1852
+ end
1853
+ end
1854
+
1855
+ # Keywords in "KEYWDS".
1856
+ # Returns an array of string.
1857
+ def keywords
1858
+ self.record('KEYWDS').collect { |f| f.keywds }.flatten
1859
+ end
1860
+
1861
+ # Classification in "HEADER".
1862
+ def classification
1863
+ f = self.record('HEADER').first
1864
+ f ? f.classification : nil
1865
+ end
1866
+
1867
+ # Get authors in "AUTHOR".
1868
+ def authors
1869
+ self.record('AUTHOR').collect { |f| f.authorList }.flatten
1870
+ end
1871
+
1872
+ #--
1873
+ # Bio::DB methods
1874
+ #++
1875
+
1876
+ # PDB identifier written in "HEADER". (e.g. 1A00)
1877
+ def entry_id
1878
+ unless @id
1879
+ f = self.record('HEADER').first
1880
+ @id = f ? f.idCode : nil
1881
+ end
1882
+ @id
1883
+ end
1884
+
1885
+ # Same as <tt>Bio::PDB#entry_id</tt>.
1886
+ def accession
1887
+ self.entry_id
1888
+ end
1889
+
1890
+ # Title of this entry in "TITLE".
1891
+ def definition
1892
+ f = self.record('TITLE').first
1893
+ f ? f.title : nil
1894
+ end
1895
+
1896
+ # Current modification number in "REVDAT".
1897
+ def version
1898
+ f = self.record('REVDAT').first
1899
+ f ? f.modNum : nil
1900
+ end
1901
+
1902
+ # returns a string containing human-readable representation
1903
+ # of this object.
1904
+ def inspect
1905
+ "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>"
1906
+ end
1907
+
1908
+ end #class PDB
1909
+
1910
+ end #module Bio
1911
+