class Bio::PDB::Record
The ancestor of every single PDB
record class. It inherits Struct
class. Basically, each line of a PDB
file corresponds to an instance of each corresponding child class. If continuation exists, multiple lines may correspond to single instance.
Constants
- ANISOU
ANISOU
record class- ATOM
ATOM
record class- AUTHOR
AUTHOR
record class- CAVEAT
CAVEAT
record class- CISPEP
CISPEP
record class- COMPND
COMPND
record class- CONECT
CONECT
record class- CRYST1
CRYST1
record class- DBREF
DBREF
record class- Default
default (or unknown) record class
- Definition
definitions (hash)
- ENDMDL
ENDMDL
record class- EXPDTA
EXPDTA
record class- End
END record class.
Because END is a reserved word of Ruby, it is separately added to the hash
- FORMUL
FORMUL
record class- HEADER
HEADER
record class- HELIX
HELIX
record class- HET
HET
record class- HETATM
HETATM
record class- HETNAM
HETNAM
record class- HETSYN
HETSYN
record class- HYDBND
HYDBND
record class- JRNL
‘JRNL’ is defined below
- KEYWDS
KEYWDS
record class- LINK
LINK
record class- MASTER
MASTER
record class- MODEL
MODEL
record class- MODRES
MODRS record class
- MTRIX1
MTRIX1
record classMTRIXn n=1,2, or 3
- MTRIX2
MTRIX2
record class- MTRIX3
MTRIX3
record class- OBSLTE
OBSLTE
record class- ORIGX1
ORIGX1
record classORIGXn n=1, 2, or 3
- ORIGX2
ORIGX2
record class- ORIGX3
ORIGX3
record class- REMARK
‘REMARK’ is defined below
- REVDAT
REVDAT
record class- RemarkN
- SCALE1
SCALE1
record classSCALEn n=1, 2, or 3
- SCALE2
SCALE2
record class- SCALE3
SCALE3
record class- SEQADV
SEQADV
record class- SEQRES
SEQRES
record class- SHEET
SHEET
record class- SIGATM
SIGATM
record class- SIGUIJ
SIGUIJ
record class- SITE
SITE
record class- SLTBRG
SLTBRG
record class- SOURCE
SOURCE
record class- SPRSDE
SPRSDE
record class- SSBOND
SSBOND
record class- TER
TER
record class- TITLE
TITLE
record class- TURN
TURN
record class- TVECT
TVECT
record class
Public Class Methods
Returns true if this record has a field type which allows continuations.
# File lib/bio/db/pdb/pdb.rb 287 def self.continue? 288 @cont 289 end
creates definition hash from current classes constants
# File lib/bio/db/pdb/pdb.rb 438 def self.create_definition_hash 439 hash = {} 440 constants.each do |x| 441 x = x.intern # keep compatibility both Ruby 1.8 and 1.9 442 hash[x] = const_get(x) if /\A[A-Z][A-Z0-9]+\z/ =~ x.to_s 443 end 444 if x = const_get(:Default) then 445 hash.default = x 446 end 447 hash 448 end
Creates new class by given field definition The difference from new_direct
() is the class created by the method does lazy evaluation.
Internal use only.
# File lib/bio/db/pdb/pdb.rb 226 def self.def_rec(*ary) 227 symbolhash, symbolary, cont = parse_field_definitions(ary) 228 229 klass = Class.new(self.new(*symbolary)) 230 klass.module_eval { 231 @definition = ary 232 @symbols = symbolhash 233 @cont = cont 234 } 235 klass.module_eval { 236 symbolary.each do |x| 237 define_method(x) { do_parse; super() } 238 end 239 } 240 klass 241 end
Basically just look up the class in Definition
hash do some munging for JRNL
and REMARK
# File lib/bio/db/pdb/pdb.rb 1389 def self.get_record_class(str) 1390 t = fetch_record_name(str) 1391 t = t.intern unless t.empty? 1392 if d = Definition[t] then 1393 return d 1394 end 1395 case t 1396 when :JRNL 1397 ts = str[12..15].to_s.strip 1398 ts = ts.intern unless ts.empty? 1399 d = Jrnl::Definition[ts] 1400 when :REMARK 1401 case str[7..9].to_i 1402 when 1 1403 ts = str[12..15].to_s.strip 1404 ts = ts.intern unless ts.empty? 1405 d = Remark1::Definition[ts] 1406 when 2 1407 if str[28..37] == 'ANGSTROMS.' then 1408 d = Remark2::ANGSTROMS 1409 elsif str[22..37] == ' NOT APPLICABLE.' then 1410 d = Remark2::NOT_APPLICABLE 1411 else 1412 d = Remark2::Default 1413 end 1414 else 1415 d = RemarkN 1416 end 1417 else 1418 # unknown field 1419 d = Default 1420 end 1421 return d 1422 end
Creates new class by given field definition.
Internal use only.
# File lib/bio/db/pdb/pdb.rb 257 def self.new_direct(*ary) 258 symbolhash, symbolary, cont = parse_field_definitions(ary) 259 if cont 260 raise 'continuation not allowed. please use def_rec instead' 261 end 262 263 klass = Class.new(self.new(*symbolary)) 264 klass.module_eval { 265 @definition = ary 266 @symbols = symbolhash 267 @cont = cont 268 } 269 klass.module_eval { 270 define_method(:initialize_from_string) { |str| 271 r = super(str) 272 do_parse 273 r 274 } 275 } 276 klass 277 end
creates new class which inherits given class.
# File lib/bio/db/pdb/pdb.rb 244 def self.new_inherit(klass) 245 newklass = Class.new(klass) 246 newklass.module_eval { 247 @definition = klass.module_eval { @definition } 248 @symbols = klass.module_eval { @symbols } 249 @cont = klass.module_eval { @cont } 250 } 251 newklass 252 end
symbols
# File lib/bio/db/pdb/pdb.rb 280 def self.symbols 281 #p self 282 @symbols 283 end
Public Instance Methods
Internal use only.
Adds continuation data to the record from str if str is really the continuation of current record. Returns self (= not nil) if str is the continuation. Otherwaise, returns false.
# File lib/bio/db/pdb/pdb.rb 421 def add_continuation(str) 422 #Check that this record can continue 423 #and that str has the same type and definition 424 return false unless self.continue? 425 return false unless fetch_record_name(str) == @record_name 426 return false unless self.class.get_record_class(str) == self.class 427 return false unless fetch_cont(str) >= 2 428 #If all this is OK then add onto @cont_data 429 unless defined?(@cont_data) 430 @cont_data = [] 431 end 432 @cont_data << str 433 # Returns self (= not nil) if succeeded. 434 self 435 end
Returns true if this record has a field type which allows continuations.
# File lib/bio/db/pdb/pdb.rb 293 def continue? 294 self.class.continue? 295 end
In order to speeding up processing of PDB
file format, fields have not been parsed before calling this method.
Normally, it is automatically called and you don’t explicitly need to call it .
# File lib/bio/db/pdb/pdb.rb 341 def do_parse 342 return self if @parsed or !@str 343 str0 = @str 344 each_symbol do |key, klass, ranges| 345 #If we only have one range then pull that out 346 #and store it in the hash 347 if ranges.size <= 1 then 348 self[key] = klass.new(str0[ranges.first]) 349 else 350 #Go through each range and add the string to an array 351 #set the hash key to point to that array 352 ary = [] 353 ranges.each do |r| 354 ary << klass.new(str0[r]) unless str0[r].to_s.strip.empty? 355 end 356 self[key] = ary 357 end 358 end #each_symbol 359 #If we have continuations then for each line of extra data... 360 if defined?(@cont_data) then 361 @cont_data.each do |str| 362 #Get the symbol, type and range array 363 each_symbol do |key, klass, ranges| 364 #If there's one range then grab that range 365 if ranges.size <= 1 then 366 r1 = ranges.first 367 unless str[r1].to_s.strip.empty? 368 #and concatenate the new data onto the old 369 v = klass.new(str[r1]) 370 self[key].concat(v) if self[key] != v 371 end 372 else 373 #If there's more than one range then add to the array 374 ary = self[key] 375 ranges.each do |r| 376 ary << klass.new(str[r]) unless str[r].to_s.strip.empty? 377 end 378 end 379 end 380 end 381 end 382 @parsed = true 383 self 384 end
yields the symbol(k), type(x) and array of ranges of each symbol.
# File lib/bio/db/pdb/pdb.rb 299 def each_symbol 300 self.class.symbols.each do |k, x| 301 yield k, x[0], x[1] 302 end 303 end
initialize this record from the given string. str must be a line (in PDB
format).
You can add continuation lines later using add_continuation
method.
# File lib/bio/db/pdb/pdb.rb 323 def initialize_from_string(str) 324 @str = str 325 @record_name = fetch_record_name(str) 326 @parsed = false 327 self 328 end
Return original string (except that “n” are truncated) for this record (usually just @str, but sometimes add on the continuation data from other lines. Returns an array of string.
# File lib/bio/db/pdb/pdb.rb 310 def original_data 311 if defined?(@cont_data) then 312 [ @str, *@cont_data ] 313 else 314 [ @str ] 315 end 316 end
Record
name of this record, e.g. “HEADER”, “ATOM”.
# File lib/bio/db/pdb/pdb.rb 408 def record_name 409 @record_name or self.class.to_s.split(/\:\:/)[-1].to_s.upcase 410 end