mddb 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/mddb +11 -0
- data/config.yml +39 -0
- data/lib/mddb.rb +21 -0
- data/lib/mddb/atom.rb +28 -0
- data/lib/mddb/calculations.rb +36 -0
- data/lib/mddb/cli.rb +28 -0
- data/lib/mddb/commands/console.rb +20 -0
- data/lib/mddb/commands/load.rb +50 -0
- data/lib/mddb/commands/new.rb +33 -0
- data/lib/mddb/config.rb +31 -0
- data/lib/mddb/frame.rb +7 -0
- data/lib/mddb/generators.rb +32 -0
- data/lib/mddb/generators/atom.rb +18 -0
- data/lib/mddb/generators/molecule.rb +18 -0
- data/lib/mddb/molecule.rb +23 -0
- data/lib/mddb/parser.rb +28 -0
- data/lib/mddb/point.rb +62 -0
- data/lib/mddb/sphere.rb +22 -0
- data/lib/mddb/templates/README.tt +21 -0
- data/lib/mddb/templates/atom.rb.tt +3 -0
- data/lib/mddb/templates/config.yml.tt +37 -0
- data/lib/mddb/templates/frame.rb.tt +8 -0
- data/lib/mddb/templates/molecule.rb.tt +4 -0
- data/lib/mddb/templates/spec/atom_spec.rb.tt +0 -0
- data/lib/mddb/templates/spec/molecule_spec.rb.tt +0 -0
- data/lib/mddb/vector.rb +62 -0
- data/lib/mddb/version.rb +3 -0
- data/mddb.gemspec +26 -0
- data/quick.xyz +7700 -0
- data/spec/atom_spec.rb +8 -0
- data/spec/oxygen_spec.rb +12 -0
- data/spec/spec_helper.rb +8 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/mddb
ADDED
data/config.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Example config
|
2
|
+
#
|
3
|
+
# database:
|
4
|
+
# host: localhost
|
5
|
+
# port: 12345
|
6
|
+
# name: 'sim1'
|
7
|
+
#
|
8
|
+
#
|
9
|
+
# If host or port are not defined, localhost and 27017
|
10
|
+
# MongoDB's default port, will be used.
|
11
|
+
#
|
12
|
+
# Only the database name must be strictly defined. It is important
|
13
|
+
# that you choose a database name that does not already exist, if
|
14
|
+
# you not want to mess up an older database.
|
15
|
+
|
16
|
+
database:
|
17
|
+
host:
|
18
|
+
port:
|
19
|
+
name: 'mddb'
|
20
|
+
|
21
|
+
simulation:
|
22
|
+
file: 'quick.xyz'
|
23
|
+
frames: 5
|
24
|
+
dimensions: 24.8522, 24.8522, 24.8522
|
25
|
+
count: 1538 # total number of objects per frame
|
26
|
+
objects:
|
27
|
+
water:
|
28
|
+
count: 512
|
29
|
+
start: 1
|
30
|
+
atom:
|
31
|
+
- oxygen
|
32
|
+
- hydrogen
|
33
|
+
- hydrogen
|
34
|
+
chain:
|
35
|
+
count: 1
|
36
|
+
start: 1537
|
37
|
+
atom:
|
38
|
+
- phobe
|
39
|
+
- phobe
|
data/lib/mddb.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "mddb/version"
|
2
|
+
require "mddb/calculations"
|
3
|
+
require "mddb/cli"
|
4
|
+
require "mongo_mapper"
|
5
|
+
require "mddb/config"
|
6
|
+
require "mddb/parser"
|
7
|
+
|
8
|
+
if File.exists? "config.yml"
|
9
|
+
Mddb::Config.config = "config.yml"
|
10
|
+
require "mddb/point"
|
11
|
+
require "mddb/vector"
|
12
|
+
require "mddb/atom"
|
13
|
+
require "mddb/frame"
|
14
|
+
require "mddb/molecule"
|
15
|
+
require "require_all"
|
16
|
+
require_all 'models' unless Dir.glob('models/**/*.rb').size == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
module Mddb
|
20
|
+
TEMPLATES = File.expand_path('../mddb/templates', __FILE__)
|
21
|
+
end
|
data/lib/mddb/atom.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mddb/calculations'
|
2
|
+
require 'mddb/point'
|
3
|
+
require 'mongo_mapper'
|
4
|
+
module Mddb
|
5
|
+
class Atom
|
6
|
+
include MongoMapper::EmbeddedDocument
|
7
|
+
include Mddb::Calculations
|
8
|
+
key :position, Point
|
9
|
+
key :fid, Integer
|
10
|
+
|
11
|
+
def distance_to a
|
12
|
+
if a.is_a? Point
|
13
|
+
self.position.distance_to a
|
14
|
+
elsif a.is_a? Mddb::Atom
|
15
|
+
self.position.distance_to a.position
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def vector_to a
|
20
|
+
if a.is_a? Point
|
21
|
+
self.position.vector_to a
|
22
|
+
elsif a.is_a? Mddb::Atom
|
23
|
+
self.position.vector_to a.position
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mddb
|
2
|
+
module Calculations
|
3
|
+
# This module provides a simple way
|
4
|
+
# of ordering calculation methods in a
|
5
|
+
# Mddb Model
|
6
|
+
|
7
|
+
# Run the calculations on an instance
|
8
|
+
def run_calculations
|
9
|
+
self.get_calculations.each do |calc|
|
10
|
+
self.send calc
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.included(base)
|
15
|
+
base.extend(ClassMethods)
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
@@calculations = []
|
20
|
+
|
21
|
+
def get_calculations
|
22
|
+
@@calculations
|
23
|
+
end
|
24
|
+
|
25
|
+
def calculations *args
|
26
|
+
args.each do |arg|
|
27
|
+
@@calculations.push "calc_#{arg}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def list_calculations
|
32
|
+
return @@calculations
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mddb/cli.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mddb/version'
|
2
|
+
module Mddb
|
3
|
+
class CLI
|
4
|
+
def self.run
|
5
|
+
if ARGV.empty?
|
6
|
+
puts "Using MDDB v." + Mddb::VERSION
|
7
|
+
puts "Options:"
|
8
|
+
puts " new Creates a new project"
|
9
|
+
puts " generate <model> Creates a new model."
|
10
|
+
puts " Leave blank for list of available "
|
11
|
+
puts " models"
|
12
|
+
puts " console Starts an interactice MDDB console"
|
13
|
+
elsif %w{-v --version --v}.include? ARGV.first
|
14
|
+
puts Mddb::VERSION
|
15
|
+
elsif ARGV.first == 'new'
|
16
|
+
ARGV.shift
|
17
|
+
require 'mddb/commands/new'
|
18
|
+
elsif ARGV.first == 'console'
|
19
|
+
require 'mddb/commands/console'
|
20
|
+
elsif ARGV.first == 'load'
|
21
|
+
require 'mddb/commands/load'
|
22
|
+
elsif %w{g generate}.include? ARGV.first
|
23
|
+
ARGV.shift
|
24
|
+
require 'mddb/generators'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
def start_console
|
4
|
+
require 'irb'
|
5
|
+
require 'irb/completion'
|
6
|
+
require 'require_all'
|
7
|
+
require 'hirb'
|
8
|
+
Hirb.enable
|
9
|
+
# Require all our models
|
10
|
+
require_all 'models' unless Dir.glob('models/**/*.rb').size == 0
|
11
|
+
ARGV.clear
|
12
|
+
puts "Wecome to Mddb!"
|
13
|
+
IRB.start
|
14
|
+
end
|
15
|
+
|
16
|
+
if File.exists? 'config.yml'
|
17
|
+
start_console
|
18
|
+
else
|
19
|
+
puts "Your not in the project root directory"
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
def start_console
|
4
|
+
require 'mddb'
|
5
|
+
require 'mddb/point'
|
6
|
+
require 'irb'
|
7
|
+
require 'irb/completion'
|
8
|
+
ARGV.clear
|
9
|
+
puts "loading xyz"
|
10
|
+
c = YAML.load File.open('config.yml').read
|
11
|
+
sim = c['simulation']
|
12
|
+
objects = sim['objects']
|
13
|
+
objects.keys.each do |key|
|
14
|
+
unless Object.const_defined?(key.capitalize)
|
15
|
+
puts "No model for #{key}! Please create one!"
|
16
|
+
end
|
17
|
+
objects[key]['atom'].each do |a|
|
18
|
+
unless Object.const_defined?(a.capitalize)
|
19
|
+
puts "No model for #{a}! Please create one!"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
p = Mddb::Parser::Parser.new
|
24
|
+
fid = 1
|
25
|
+
p.each_frame do |f|
|
26
|
+
puts "Frame: #{fid}"
|
27
|
+
frame = Frame.new :fid => fid
|
28
|
+
objects.keys.each do |mol|
|
29
|
+
(objects[mol]['start']..(objects[mol]['start']+objects[mol]['count']) - 1).to_a.each do |i|
|
30
|
+
m = Object.const_get(mol.capitalize).new :mid => i, :fid => fid
|
31
|
+
objects[mol]['atom'].each_with_index do |a,z|
|
32
|
+
line = z*objects[mol]['count'] + i
|
33
|
+
a = Object.const_get(a.capitalize).new :aid => (z+1), :position => f[line-1], :fid => fid
|
34
|
+
m.atoms << a
|
35
|
+
end
|
36
|
+
m.save
|
37
|
+
frame.send(mol.pluralize) << m
|
38
|
+
end
|
39
|
+
end
|
40
|
+
frame.save
|
41
|
+
fid +=1
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
if File.exists? 'config.yml'
|
47
|
+
start_console
|
48
|
+
else
|
49
|
+
puts "Your not in the project root directory"
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
class New < Thor::Group
|
4
|
+
include Thor::Actions
|
5
|
+
argument :name
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
File.expand_path('../../templates', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def README
|
12
|
+
template "README.tt", "#{name}/README"
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
template "config.yml.tt", "#{name}/config.yml"
|
17
|
+
end
|
18
|
+
|
19
|
+
def models
|
20
|
+
empty_directory "#{name}/models"
|
21
|
+
end
|
22
|
+
|
23
|
+
def frame
|
24
|
+
template "frame.rb.tt", "#{name}/models/frame.rb"
|
25
|
+
end
|
26
|
+
|
27
|
+
def spec
|
28
|
+
empty_directory "#{name}/spec"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
New.start
|
data/lib/mddb/config.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mddb
|
2
|
+
module Config
|
3
|
+
def self.database
|
4
|
+
@@config['database'] ||= {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.simulation
|
8
|
+
@@config['simulation']
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.config=(file)
|
12
|
+
config = YAML.load_file(file)
|
13
|
+
config['database']['host'] = 'localhost' if config['database']['host'].nil?
|
14
|
+
config['database']['port'] = 27017 if config['database']['port'].nil?
|
15
|
+
raise "bad config file: database name needs to be defined" if config['database']['name'].nil?
|
16
|
+
config['simulation']['dimensions'] = config['simulation']['dimensions'].split(',').collect {|a| a.to_f}
|
17
|
+
@@config = config
|
18
|
+
self.connect
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# The ranges of atoms in the config file are described as strings, we need
|
23
|
+
# to make them into ruby strings.
|
24
|
+
def self.connect
|
25
|
+
host = Mddb::Config.database['host']
|
26
|
+
database = Mddb::Config.database['name']
|
27
|
+
MongoMapper.connection = Mongo::Connection.new(host)
|
28
|
+
MongoMapper.database = database
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/mddb/frame.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'mddb/generators/atom'
|
2
|
+
require 'mddb/generators/molecule'
|
3
|
+
module Mddb
|
4
|
+
module Generators
|
5
|
+
def Generators.list
|
6
|
+
gens = Mddb::Generators.constants.map {|x| x.to_s.downcase}
|
7
|
+
gens - ['run']
|
8
|
+
end
|
9
|
+
|
10
|
+
class Run
|
11
|
+
def self.start
|
12
|
+
if ARGV.empty?
|
13
|
+
puts "try one of the following"
|
14
|
+
Mddb::Generators.list.each do |g|
|
15
|
+
puts " #{g} <name>"
|
16
|
+
end
|
17
|
+
elsif Mddb::Generators.list.include? ARGV.first
|
18
|
+
gen = ARGV.first
|
19
|
+
ARGV.shift
|
20
|
+
if ARGV.empty?
|
21
|
+
puts "supply a name"
|
22
|
+
else
|
23
|
+
eval("Mddb::Generators::" + gen.capitalize + ".start")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Mddb::Generators::Run.start
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
module Mddb::Generators
|
4
|
+
class Atom < Thor::Group
|
5
|
+
argument :name
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
File.expand_path('../../templates', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def atom
|
13
|
+
template "atom.rb.tt", "models/atoms/#{name}.rb"
|
14
|
+
template "spec/atom_spec.rb.tt", "spec/atoms/#{name}_spec.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/group'
|
3
|
+
module Mddb::Generators
|
4
|
+
class Molecule < Thor::Group
|
5
|
+
argument :name
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
File.expand_path('../../templates', __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def atom
|
13
|
+
template "molecule.rb.tt", "models/molecules/#{name}.rb"
|
14
|
+
template "spec/molecule_spec.rb.tt", "spec/molecules/#{name}_spec.rb"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'mddb/calculations'
|
2
|
+
module Mddb
|
3
|
+
class Molecule
|
4
|
+
include MongoMapper::Document
|
5
|
+
include Mddb::Calculations
|
6
|
+
key :fid, Integer
|
7
|
+
key :mid, Integer
|
8
|
+
belongs_to :frame, :class_name => 'Mddb::Frame'
|
9
|
+
many :atoms, :class_name => 'Mddb::Atom'
|
10
|
+
|
11
|
+
def timeline
|
12
|
+
self.class.where(:mid => self.mid).all
|
13
|
+
end
|
14
|
+
|
15
|
+
def timestep n=0
|
16
|
+
if self.fid + n <= Frame.count and self.fid + n > 0
|
17
|
+
self.class.where(:mid => self.mid, :fid => (self.fid+n)).all
|
18
|
+
else
|
19
|
+
raise "Bad timestep. No frame exists or out of range"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mddb/parser.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Mddb
|
2
|
+
module Parser
|
3
|
+
|
4
|
+
class Parser
|
5
|
+
def initialize
|
6
|
+
@file = File.open(Mddb::Config.simulation['file']).readlines
|
7
|
+
@objects = Mddb::Config.simulation['count']
|
8
|
+
end
|
9
|
+
|
10
|
+
def each_frame
|
11
|
+
frame = nil
|
12
|
+
@file.each do |line|
|
13
|
+
if line == "#{@objects}\n"
|
14
|
+
yield(frame) if frame != nil
|
15
|
+
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
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|