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
-
ANISOUrecord class - ATOM
-
ATOMrecord class - AUTHOR
-
AUTHORrecord class - CAVEAT
-
CAVEATrecord class - CISPEP
-
CISPEPrecord class - COMPND
-
COMPNDrecord class - CONECT
-
CONECTrecord class - CRYST1
-
CRYST1record class - DBREF
-
DBREFrecord class - Default
-
default (or unknown) record class
- Definition
-
definitions (hash)
- ENDMDL
-
ENDMDLrecord class - EXPDTA
-
EXPDTArecord class - End
-
END record class.
Because END is a reserved word of Ruby, it is separately added to the hash
- FORMUL
-
FORMULrecord class - HEADER
-
HEADERrecord class - HELIX
-
HELIXrecord class - HET
-
HETrecord class - HETATM
-
HETATMrecord class - HETNAM
-
HETNAMrecord class - HETSYN
-
HETSYNrecord class - HYDBND
-
HYDBNDrecord class - JRNL
-
‘JRNL’ is defined below
- KEYWDS
-
KEYWDSrecord class - LINK
-
LINKrecord class - MASTER
-
MASTERrecord class - MODEL
-
MODELrecord class - MODRES
-
MODRS record class
- MTRIX1
-
MTRIX1record classMTRIXn n=1,2, or 3
- MTRIX2
-
MTRIX2record class - MTRIX3
-
MTRIX3record class - OBSLTE
-
OBSLTErecord class - ORIGX1
-
ORIGX1record classORIGXn n=1, 2, or 3
- ORIGX2
-
ORIGX2record class - ORIGX3
-
ORIGX3record class - REMARK
-
‘REMARK’ is defined below
- REVDAT
-
REVDATrecord class - RemarkN
- SCALE1
-
SCALE1record classSCALEn n=1, 2, or 3
- SCALE2
-
SCALE2record class - SCALE3
-
SCALE3record class - SEQADV
-
SEQADVrecord class - SEQRES
-
SEQRESrecord class - SHEET
-
SHEETrecord class - SIGATM
-
SIGATMrecord class - SIGUIJ
-
SIGUIJrecord class - SITE
-
SITErecord class - SLTBRG
-
SLTBRGrecord class - SOURCE
-
SOURCErecord class - SPRSDE
-
SPRSDErecord class - SSBOND
-
SSBONDrecord class - TER
-
TERrecord class - TITLE
-
TITLErecord class - TURN
-
TURNrecord class - TVECT
-
TVECTrecord class
Public Class Methods
Source
# File lib/bio/db/pdb/pdb.rb 288 def self.continue? 289 @cont 290 end
Returns true if this record has a field type which allows continuations.
Source
# File lib/bio/db/pdb/pdb.rb 439 def self.create_definition_hash 440 hash = {} 441 constants.each do |x| 442 x = x.intern # keep compatibility both Ruby 1.8 and 1.9 443 hash[x] = const_get(x) if /\A[A-Z][A-Z0-9]+\z/ =~ x.to_s 444 end 445 if x = const_get(:Default) then 446 hash.default = x 447 end 448 hash 449 end
creates definition hash from current classes constants
Source
# File lib/bio/db/pdb/pdb.rb 227 def self.def_rec(*ary) 228 symbolhash, symbolary, cont = parse_field_definitions(ary) 229 230 klass = Class.new(self.new(*symbolary)) 231 klass.module_eval { 232 @definition = ary 233 @symbols = symbolhash 234 @cont = cont 235 } 236 klass.module_eval { 237 symbolary.each do |x| 238 define_method(x) { do_parse; super() } 239 end 240 } 241 klass 242 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.
Source
# File lib/bio/db/pdb/pdb.rb 1390 def self.get_record_class(str) 1391 t = fetch_record_name(str) 1392 t = t.intern unless t.empty? 1393 if d = Definition[t] then 1394 return d 1395 end 1396 case t 1397 when :JRNL 1398 ts = str[12..15].to_s.strip 1399 ts = ts.intern unless ts.empty? 1400 d = Jrnl::Definition[ts] 1401 when :REMARK 1402 case str[7..9].to_i 1403 when 1 1404 ts = str[12..15].to_s.strip 1405 ts = ts.intern unless ts.empty? 1406 d = Remark1::Definition[ts] 1407 when 2 1408 if str[28..37] == 'ANGSTROMS.' then 1409 d = Remark2::ANGSTROMS 1410 elsif str[22..37] == ' NOT APPLICABLE.' then 1411 d = Remark2::NOT_APPLICABLE 1412 else 1413 d = Remark2::Default 1414 end 1415 else 1416 d = RemarkN 1417 end 1418 else 1419 # unknown field 1420 d = Default 1421 end 1422 return d 1423 end
Basically just look up the class in Definition hash do some munging for JRNL and REMARK
Source
# File lib/bio/db/pdb/pdb.rb 258 def self.new_direct(*ary) 259 symbolhash, symbolary, cont = parse_field_definitions(ary) 260 if cont 261 raise 'continuation not allowed. please use def_rec instead' 262 end 263 264 klass = Class.new(self.new(*symbolary)) 265 klass.module_eval { 266 @definition = ary 267 @symbols = symbolhash 268 @cont = cont 269 } 270 klass.module_eval { 271 define_method(:initialize_from_string) { |str| 272 r = super(str) 273 do_parse 274 r 275 } 276 } 277 klass 278 end
Creates new class by given field definition.
Internal use only.
Source
# File lib/bio/db/pdb/pdb.rb 245 def self.new_inherit(klass) 246 newklass = Class.new(klass) 247 newklass.module_eval { 248 @definition = klass.module_eval { @definition } 249 @symbols = klass.module_eval { @symbols } 250 @cont = klass.module_eval { @cont } 251 } 252 newklass 253 end
creates new class which inherits given class.
Source
# File lib/bio/db/pdb/pdb.rb 281 def self.symbols 282 #p self 283 @symbols 284 end
symbols
Public Instance Methods
Source
# File lib/bio/db/pdb/pdb.rb 422 def add_continuation(str) 423 #Check that this record can continue 424 #and that str has the same type and definition 425 return false unless self.continue? 426 return false unless fetch_record_name(str) == @record_name 427 return false unless self.class.get_record_class(str) == self.class 428 return false unless fetch_cont(str) >= 2 429 #If all this is OK then add onto @cont_data 430 unless defined?(@cont_data) 431 @cont_data = [] 432 end 433 @cont_data << str 434 # Returns self (= not nil) if succeeded. 435 self 436 end
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.
Source
# File lib/bio/db/pdb/pdb.rb 294 def continue? 295 self.class.continue? 296 end
Returns true if this record has a field type which allows continuations.
Source
# File lib/bio/db/pdb/pdb.rb 342 def do_parse 343 return self if @parsed or !@str 344 str0 = @str 345 each_symbol do |key, klass, ranges| 346 #If we only have one range then pull that out 347 #and store it in the hash 348 if ranges.size <= 1 then 349 self[key] = klass.new(str0[ranges.first]) 350 else 351 #Go through each range and add the string to an array 352 #set the hash key to point to that array 353 ary = [] 354 ranges.each do |r| 355 ary << klass.new(str0[r]) unless str0[r].to_s.strip.empty? 356 end 357 self[key] = ary 358 end 359 end #each_symbol 360 #If we have continuations then for each line of extra data... 361 if defined?(@cont_data) then 362 @cont_data.each do |str| 363 #Get the symbol, type and range array 364 each_symbol do |key, klass, ranges| 365 #If there's one range then grab that range 366 if ranges.size <= 1 then 367 r1 = ranges.first 368 unless str[r1].to_s.strip.empty? 369 #and concatenate the new data onto the old 370 v = klass.new(str[r1]) 371 self[key].concat(v) if self[key] != v 372 end 373 else 374 #If there's more than one range then add to the array 375 ary = self[key] 376 ranges.each do |r| 377 ary << klass.new(str[r]) unless str[r].to_s.strip.empty? 378 end 379 end 380 end 381 end 382 end 383 @parsed = true 384 self 385 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 .
Source
# File lib/bio/db/pdb/pdb.rb 300 def each_symbol 301 self.class.symbols.each do |k, x| 302 yield k, x[0], x[1] 303 end 304 end
yields the symbol(k), type(x) and array of ranges of each symbol.
Source
# File lib/bio/db/pdb/pdb.rb 324 def initialize_from_string(str) 325 @str = str 326 @record_name = fetch_record_name(str) 327 @parsed = false 328 self 329 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.
Source
Source
# File lib/bio/db/pdb/pdb.rb 311 def original_data 312 if defined?(@cont_data) then 313 [ @str, *@cont_data ] 314 else 315 [ @str ] 316 end 317 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.
Source
# File lib/bio/db/pdb/pdb.rb 409 def record_name 410 @record_name or self.class.to_s.split(/\:\:/)[-1].to_s.upcase 411 end
Record name of this record, e.g. “HEADER”, “ATOM”.