mddb 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mddb/atom.rb +15 -0
- data/lib/mddb/calculations.rb +20 -24
- data/lib/mddb/commands/load.rb +6 -1
- data/lib/mddb/frame.rb +1 -1
- data/lib/mddb/generators/molecule.rb +4 -1
- data/lib/mddb/molecule.rb +57 -0
- data/lib/mddb/parser.rb +17 -9
- data/lib/mddb/templates/frame.rb.tt +1 -1
- data/lib/mddb/version.rb +1 -1
- data/lib/mddb.rb +31 -1
- data/spec/oxygen_spec.rb +39 -5
- metadata +10 -10
data/lib/mddb/atom.rb
CHANGED
@@ -23,6 +23,21 @@ module Mddb
|
|
23
23
|
self.position.vector_to a.position
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
def mass
|
28
|
+
begin
|
29
|
+
self.class::MASS
|
30
|
+
rescue
|
31
|
+
raise "Please define a MASS constant in #{self.class} class"
|
32
|
+
end
|
33
|
+
end
|
26
34
|
|
35
|
+
def charge
|
36
|
+
begin
|
37
|
+
self.class::CHARGE
|
38
|
+
rescue
|
39
|
+
raise "Please define a CHARGE constant in #{self.class} class"
|
40
|
+
end
|
41
|
+
end
|
27
42
|
end
|
28
43
|
end
|
data/lib/mddb/calculations.rb
CHANGED
@@ -1,35 +1,31 @@
|
|
1
1
|
module Mddb
|
2
2
|
module Calculations
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
self.send calc
|
3
|
+
def run
|
4
|
+
begin
|
5
|
+
get_calculations.each do |c|
|
6
|
+
self.send(c)
|
7
|
+
end
|
8
|
+
rescue
|
9
|
+
raise "You haven't added any calculations to the calculations macro"
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
|
-
def self.included(base)
|
15
|
-
base.extend(ClassMethods)
|
16
|
-
end
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
def list_calculations
|
14
|
+
begin
|
15
|
+
get_calculations
|
16
|
+
rescue
|
17
|
+
raise "You haven't added any calculations to the calculations macro"
|
23
18
|
end
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
21
|
+
def self.included(klass)
|
22
|
+
klass.extend ClassMethods
|
23
|
+
end
|
30
24
|
|
31
|
-
|
32
|
-
|
25
|
+
module ClassMethods
|
26
|
+
def calculations *args
|
27
|
+
a = args.map {|a| "calc_#{a}"}
|
28
|
+
define_method :get_calculations, lambda {a}
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
data/lib/mddb/commands/load.rb
CHANGED
@@ -6,6 +6,11 @@ def start_console
|
|
6
6
|
require 'irb'
|
7
7
|
require 'irb/completion'
|
8
8
|
ARGV.clear
|
9
|
+
begin
|
10
|
+
last_frame = Frame.sort(:fid.desc).first.fid
|
11
|
+
rescue
|
12
|
+
last_frame = 0
|
13
|
+
end
|
9
14
|
puts "loading xyz"
|
10
15
|
c = YAML.load File.open('config.yml').read
|
11
16
|
sim = c['simulation']
|
@@ -21,7 +26,7 @@ def start_console
|
|
21
26
|
end
|
22
27
|
end
|
23
28
|
p = Mddb::Parser::Parser.new
|
24
|
-
fid = 1
|
29
|
+
fid = 1 + last_frame
|
25
30
|
p.each_frame do |f|
|
26
31
|
puts "Frame: #{fid}"
|
27
32
|
frame = Frame.new :fid => fid
|
data/lib/mddb/frame.rb
CHANGED
@@ -9,8 +9,11 @@ module Mddb::Generators
|
|
9
9
|
File.expand_path('../../templates', __FILE__)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
12
|
+
def molecule
|
13
13
|
template "molecule.rb.tt", "models/molecules/#{name}.rb"
|
14
|
+
inject_into_class "models/frame.rb", Frame do
|
15
|
+
" many :#{name.pluralize}, :class_name => '#{name.capitalize}'\n"
|
16
|
+
end
|
14
17
|
template "spec/molecule_spec.rb.tt", "spec/molecules/#{name}_spec.rb"
|
15
18
|
end
|
16
19
|
end
|
data/lib/mddb/molecule.rb
CHANGED
@@ -5,9 +5,58 @@ module Mddb
|
|
5
5
|
include Mddb::Calculations
|
6
6
|
key :fid, Integer
|
7
7
|
key :mid, Integer
|
8
|
+
key :rg, Float
|
9
|
+
key :sasa, Float
|
8
10
|
belongs_to :frame, :class_name => 'Mddb::Frame'
|
9
11
|
many :atoms, :class_name => 'Mddb::Atom'
|
10
12
|
|
13
|
+
def calc_rg
|
14
|
+
sum_ij = 0
|
15
|
+
self.atoms.each do |i|
|
16
|
+
self.atoms.each do |j|
|
17
|
+
sum_ij += (i.position.distance_to j.position)**2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
rg2 = sum_ij / (2*(32**2))
|
22
|
+
rg = rg2**0.5
|
23
|
+
|
24
|
+
self.rg = rg/0.529
|
25
|
+
self.save
|
26
|
+
end
|
27
|
+
|
28
|
+
def calc_sasa
|
29
|
+
nodes=GsdSphere.new(1000).nodes
|
30
|
+
r_oxygen = 1.58
|
31
|
+
r_monomer = 1.58
|
32
|
+
surface = 0
|
33
|
+
origin = Point[0,0,0]
|
34
|
+
self.atoms.each do |atom|
|
35
|
+
nodes.each do |node|
|
36
|
+
pos_tranformation = origin.vector_to atom.position
|
37
|
+
|
38
|
+
point = node + pos_tranformation
|
39
|
+
|
40
|
+
v_radius = atom.position.vector_to point
|
41
|
+
|
42
|
+
test_point = atom.position + (v_radius * (r_oxygen + r_monomer))
|
43
|
+
other_atoms = self.atoms - [atom]
|
44
|
+
|
45
|
+
inside = false
|
46
|
+
|
47
|
+
other_atoms.each do |other|
|
48
|
+
if (test_point.distance_to other.position) < (r_oxygen + r_monomer)
|
49
|
+
inside = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
surface += 1 if inside == false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
self.sasa = surface.to_f/(self.atoms.count*nodes.count)
|
57
|
+
self.save
|
58
|
+
end
|
59
|
+
|
11
60
|
def timeline
|
12
61
|
self.class.where(:mid => self.mid).all
|
13
62
|
end
|
@@ -19,5 +68,13 @@ module Mddb
|
|
19
68
|
raise "Bad timestep. No frame exists or out of range"
|
20
69
|
end
|
21
70
|
end
|
71
|
+
|
72
|
+
def mass
|
73
|
+
mass = 0
|
74
|
+
self.atoms.each do |a|
|
75
|
+
mass += a.mass
|
76
|
+
end
|
77
|
+
mass
|
78
|
+
end
|
22
79
|
end
|
23
80
|
end
|
data/lib/mddb/parser.rb
CHANGED
@@ -7,18 +7,26 @@ module Mddb
|
|
7
7
|
@objects = Mddb::Config.simulation['count']
|
8
8
|
end
|
9
9
|
|
10
|
+
def new_frame? lineno
|
11
|
+
lineno == 3
|
12
|
+
end
|
13
|
+
|
14
|
+
def end_of_frame? lineno
|
15
|
+
lineno == @objects + 2
|
16
|
+
end
|
17
|
+
|
10
18
|
def each_frame
|
11
|
-
frame =
|
19
|
+
frame = []
|
20
|
+
lineno = 0
|
12
21
|
@file.each do |line|
|
13
|
-
|
14
|
-
|
22
|
+
lineno += 1
|
23
|
+
raw = line.split
|
24
|
+
point = Point[raw[1].to_f, raw[2].to_f, raw[3].to_f]
|
25
|
+
frame.push point
|
26
|
+
if end_of_frame? lineno
|
27
|
+
lineno = 0
|
28
|
+
yield(frame[2..(frame.count - 1)]) if frame != nil
|
15
29
|
frame = []
|
16
|
-
else
|
17
|
-
if line.split.count == 4
|
18
|
-
raw = line.split
|
19
|
-
point = Point[raw[1].to_f, raw[2].to_f, raw[3].to_f]
|
20
|
-
frame.push point
|
21
|
-
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/lib/mddb/version.rb
CHANGED
data/lib/mddb.rb
CHANGED
@@ -9,8 +9,8 @@ if File.exists? "config.yml"
|
|
9
9
|
Mddb::Config.config = "config.yml"
|
10
10
|
require "mddb/point"
|
11
11
|
require "mddb/vector"
|
12
|
-
require "mddb/atom"
|
13
12
|
require "mddb/frame"
|
13
|
+
require "mddb/atom"
|
14
14
|
require "mddb/molecule"
|
15
15
|
require "require_all"
|
16
16
|
require_all 'models' unless Dir.glob('models/**/*.rb').size == 0
|
@@ -18,4 +18,34 @@ end
|
|
18
18
|
|
19
19
|
module Mddb
|
20
20
|
TEMPLATES = File.expand_path('../mddb/templates', __FILE__)
|
21
|
+
|
22
|
+
def Mddb.run opts = {}
|
23
|
+
if opts[:all]
|
24
|
+
frames = Frame.all
|
25
|
+
else
|
26
|
+
frames = Frame.where(:fid.gte => opts[:from], :fid.lte => opts[:to]).all
|
27
|
+
end
|
28
|
+
if frames.empty?
|
29
|
+
puts "There were no frames in in this range"
|
30
|
+
else
|
31
|
+
klasses = Frame.associations.keys.map {|k| k.to_s.classify}
|
32
|
+
if klasses.empty?
|
33
|
+
puts "There are no objects associated with frame"
|
34
|
+
else
|
35
|
+
puts "#{klasses.count} models found"
|
36
|
+
frames.each do |f|
|
37
|
+
klasses.each do |k|
|
38
|
+
begin
|
39
|
+
puts "attempting to run #{k}"
|
40
|
+
m = Object.const_get(k).where(:fid => f.fid).all
|
41
|
+
m.each {|m| m.run}
|
42
|
+
rescue
|
43
|
+
puts "couldn't run calculation on #{k}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
f.run
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
21
51
|
end
|
data/spec/oxygen_spec.rb
CHANGED
@@ -1,12 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Atoms" do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe "OxygenWithContants" do
|
5
|
+
class OxygenWithConstants < Mddb::Atom
|
6
|
+
include Mddb::Calculations
|
7
|
+
MASS = 1.23
|
8
|
+
CHARGE = -4.23
|
9
|
+
calculations :fun, :bad, :ok
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have 3 calculations" do
|
13
|
+
OxygenWithConstants.new.list_calculations.should == %W(calc_fun calc_bad calc_ok)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a charge method" do
|
17
|
+
OxygenWithConstants.new.charge.should == -4.23
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a mass method" do
|
21
|
+
OxygenWithConstants.new.mass.should == 1.23
|
22
|
+
end
|
7
23
|
end
|
8
24
|
|
9
|
-
|
10
|
-
|
25
|
+
describe "OxygenWithoutContants" do
|
26
|
+
class OxygenWithoutConstants < Mddb::Atom
|
27
|
+
include Mddb::Calculations
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise an error on charge method" do
|
31
|
+
lambda {OxygenWithoutConstants.new.charge }.should raise_error(RuntimeError, "Please define a CHARGE constant in OxygenWithoutConstants class")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should raise an error on mass method" do
|
35
|
+
lambda {OxygenWithoutConstants.new.mass}.should raise_error RuntimeError
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise an error on list_calculations" do
|
39
|
+
lambda {OxygenWithoutConstants.new.list_calculations}.should raise_error RuntimeError
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should raise an error on run" do
|
43
|
+
lambda {OxygenWithoutConstants.new.run}.should raise_error RuntimeError
|
44
|
+
end
|
11
45
|
end
|
12
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70212474145840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70212474145840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: mongo_mapper
|
27
|
-
requirement: &
|
27
|
+
requirement: &70212474145420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70212474145420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: hirb
|
38
|
-
requirement: &
|
38
|
+
requirement: &70212474145000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70212474145000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: thor
|
49
|
-
requirement: &
|
49
|
+
requirement: &70212474144540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70212474144540
|
58
58
|
description: MDDB makes analysing molecular dynamics simulations easy
|
59
59
|
email:
|
60
60
|
- thom.mulvaney@gmail.com
|