Class: Mddb::Molecule

Inherits:
Object
  • Object
show all
Includes:
Calculations, MongoMapper::Document
Defined in:
lib/mddb/molecule.rb

Instance Method Summary collapse

Methods included from Calculations

included, #list_calculations, #run

Instance Method Details

#calc_rgObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mddb/molecule.rb', line 13

def calc_rg
  sum_ij = 0
  self.atoms.each do |i|
    self.atoms.each do |j|
      sum_ij += (i.position.distance_to j.position)**2
    end
  end

  rg2 = sum_ij / (2*(32**2))
  rg = rg2**0.5

  self.rg = rg/0.529
  self.save
end

#calc_sasaObject



28
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
55
56
57
58
# File 'lib/mddb/molecule.rb', line 28

def calc_sasa 
  nodes=GsdSphere.new(1000).nodes
  r_oxygen = 1.58
  r_monomer = 1.58
  surface = 0
  origin = Point[0,0,0]
  self.atoms.each do |atom|
    nodes.each do |node|
      pos_tranformation = origin.vector_to atom.position
      
      point = node + pos_tranformation

      v_radius = atom.position.vector_to point

      test_point = atom.position + (v_radius * (r_oxygen + r_monomer))
      other_atoms =  self.atoms - [atom]

      inside = false

      other_atoms.each do |other|
        if (test_point.distance_to other.position) < (r_oxygen + r_monomer)
          inside = true
        end
      end

      surface += 1 if inside == false
    end
  end
  self.sasa = surface.to_f/(self.atoms.count*nodes.count)
  self.save
end

#massObject



72
73
74
75
76
77
78
# File 'lib/mddb/molecule.rb', line 72

def mass
  mass = 0
  self.atoms.each do |a|
    mass += a.mass
  end
  mass
end

#timelineObject



60
61
62
# File 'lib/mddb/molecule.rb', line 60

def timeline
  self.class.where(:mid => self.mid).all
end

#timestep(n = 0) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/mddb/molecule.rb', line 64

def timestep n=0
  if self.fid + n <= Frame.count and self.fid + n > 0
    self.class.where(:mid => self.mid, :fid => (self.fid+n)).all
  else
    raise "Bad timestep. No frame exists or out of range"
  end
end