Class: DCD

Inherits:
Object
  • Object
show all
Defined in:
lib/dcd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, lazy = false) ⇒ DCD

Returns a new instance of DCD.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dcd.rb', line 4

def initialize(io, lazy=false)
  @io_pointer = io
   @read_length = 0
   @type = ''
   @endian = ''
   @title = ''
    = {}
   @frames = {}
   @valid = true

  if !lazy
    read_header
     read_atoms
  end
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



2
3
4
# File 'lib/dcd.rb', line 2

def frames
  @frames
end

#metadataObject (readonly)

Returns the value of attribute metadata.



2
3
4
# File 'lib/dcd.rb', line 2

def 
  
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'lib/dcd.rb', line 2

def title
  @title
end

Instance Method Details



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dcd.rb', line 56

def print
  if @title == '' or !@frames[:x]
    warn "DCD has not been processed" 
    return nil
  end

  puts "#{@metadata[:is_charmm] ? 'CHARMM' : 'X-PLOR'} #{@type == 'l' ? '32' : '64'}-bit Trajectory File #{@endian == '>' ? 'Big' : 'Little'} Endian"
  puts "#{@title}"
  puts "Nset: #{@metadata[:nset]}"
  puts "Istart: #{@metadata[:istart]}"
  puts "Nsavc: #{@metadata[:nsavc]}"
  puts "Nstep: #{@metadata[:nstep]}"
  puts "Step size: #{@metadata[:step]} picoseconds"
  puts "Number of atoms per frame: #{@metadata[:num_atoms]}"
  @frames[:x].each_with_index do |coords, i|
    puts "Frame #{i}  coordinates"
    coords.each_with_index do |coord, j|
      puts "(#{j})\t\t\t#{@frames[:x][i][j]}\t\t#{@frames[:y][i][j]}\t\t#{@frames[:z][i][j]}"
    end
  end
end

#read_atomsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dcd.rb', line 29

def read_atoms
  @frames[:x], @frames[:y], @frames[:z], @frames[:w] = [], [], [], []

  [:nset].times do |i|
    if [:extrablock]
      # Unit cell info
      i = @io_pointer.read(@read_length + 48 + @read_length).unpack("L#{endian}*")[0]
      warn "Incorrect frame size in unit cell for step #{i}" if i[0] != i[-1]
      # TODO: Process this data
    end

    # Treat first frame and fixed atoms DCD files differently
    if i == 0 or [:num_fixed] == 0
      # Read each frame
      read_coord(:x)
      read_coord(:y)
      read_coord(:z)
      read_coord(:w) if [:w_coords]
    else
      read_fixed_coord(:x)
      read_fixed_coord(:y)
      read_fixed_coord(:z)
      read_coord(:w) if [:w_coords]
    end
  end
end

#read_headerObject

Loads the header, which determines endianness and the initial metadata about the DCD file



22
23
24
25
26
27
# File 'lib/dcd.rb', line 22

def read_header
   determine_endianness
   
   read_title
   
end