courbet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/courbet.gemspec +17 -0
- data/lib/courbet/array.rb +5 -0
- data/lib/courbet/camera.rb +14 -0
- data/lib/courbet/create.rb +68 -0
- data/lib/courbet/light.rb +13 -0
- data/lib/courbet/sphere.rb +19 -0
- data/lib/courbet/templates/camera.erb +6 -0
- data/lib/courbet/templates/light.erb +3 -0
- data/lib/courbet/templates/sphere.erb +6 -0
- data/lib/courbet/version.rb +3 -0
- data/lib/courbet.rb +16 -0
- metadata +61 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Thomas Mulvaney
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Courbet
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'courbet'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install courbet
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/courbet.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/courbet/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Thomas Mulvaney"]
|
6
|
+
gem.email = ["thom.mulvaney@gmail.com"]
|
7
|
+
gem.description = %q{Turn Molecular Dynamics XYZ files into PovRay files}
|
8
|
+
gem.summary = %q{Turn Molecular Dynamics XYZ files into PovRay files}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "courbet"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Courbet::VERSION
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Courbet
|
2
|
+
class Camera
|
3
|
+
def initialize opts={}
|
4
|
+
@position = opts[:position]
|
5
|
+
@watching = opts[:watching]
|
6
|
+
file = File.join($templates,'camera.erb')
|
7
|
+
@template = ERB.new File.open(file).read
|
8
|
+
end
|
9
|
+
|
10
|
+
def render
|
11
|
+
@template.result(binding)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Courbet
|
2
|
+
class Scene
|
3
|
+
attr_accessor :objects
|
4
|
+
def initialize
|
5
|
+
@objects = {}
|
6
|
+
@atoms = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def atoms n
|
10
|
+
@atoms = n
|
11
|
+
end
|
12
|
+
|
13
|
+
def draw atom
|
14
|
+
begin
|
15
|
+
@objects[atom[0]].render atom[1..3].map {|d| d.to_f}
|
16
|
+
rescue
|
17
|
+
# $stderr.puts "atom '#{atom[0]}': no design was given for this atom type"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def paint!
|
22
|
+
frame = 1
|
23
|
+
lineno = 1
|
24
|
+
@file = File.open("f#{frame}.pov","w")
|
25
|
+
@file.puts self.stage
|
26
|
+
ARGF.each do |line|
|
27
|
+
atom = line.chomp.split("\t")
|
28
|
+
if atom.count == 4 and atom[0].length < 2
|
29
|
+
@file.puts draw atom
|
30
|
+
lineno += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
if lineno == (@atoms + 1)
|
34
|
+
frame += 1
|
35
|
+
lineno = 1
|
36
|
+
if $test and frame > 1
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
@file = File.open("f#{frame}.pov","w")
|
40
|
+
@file.puts self.stage
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def sphere (name, opts={})
|
46
|
+
s = Sphere.new opts
|
47
|
+
@objects[name] = s
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.with &block
|
51
|
+
s = self.new
|
52
|
+
block[s]
|
53
|
+
s
|
54
|
+
end
|
55
|
+
|
56
|
+
def camera opts
|
57
|
+
@objects['camera'] = Camera.new(opts)
|
58
|
+
end
|
59
|
+
|
60
|
+
def light opts
|
61
|
+
@objects['light'] = Light.new(opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
def stage
|
65
|
+
@objects['camera'].render + @objects['light'].render
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Courbet
|
2
|
+
class Sphere
|
3
|
+
def initialize opts={}
|
4
|
+
@color = opts[:color]
|
5
|
+
@radius = opts[:radius]
|
6
|
+
file = File.join($templates,'sphere.erb')
|
7
|
+
@template = ERB.new File.open(file).read
|
8
|
+
end
|
9
|
+
|
10
|
+
def render coords
|
11
|
+
if @color.is_a? Proc
|
12
|
+
color = @color.call(*coords)
|
13
|
+
else
|
14
|
+
color = @color
|
15
|
+
end
|
16
|
+
@template.result(binding)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/courbet.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "courbet/version"
|
2
|
+
require "erb"
|
3
|
+
require "trollop"
|
4
|
+
require 'courbet/array'
|
5
|
+
require "courbet/camera"
|
6
|
+
require "courbet/light"
|
7
|
+
require "courbet/sphere"
|
8
|
+
require "courbet/create"
|
9
|
+
|
10
|
+
module Courbet
|
11
|
+
opts = Trollop::options do
|
12
|
+
opt :test, "Renders only one frame"
|
13
|
+
end
|
14
|
+
$test = opts[:test]
|
15
|
+
$templates = File.join(File.dirname(__FILE__),'courbet/templates')
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: courbet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Mulvaney
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-27 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Turn Molecular Dynamics XYZ files into PovRay files
|
15
|
+
email:
|
16
|
+
- thom.mulvaney@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- courbet.gemspec
|
27
|
+
- lib/courbet.rb
|
28
|
+
- lib/courbet/array.rb
|
29
|
+
- lib/courbet/camera.rb
|
30
|
+
- lib/courbet/create.rb
|
31
|
+
- lib/courbet/light.rb
|
32
|
+
- lib/courbet/sphere.rb
|
33
|
+
- lib/courbet/templates/camera.erb
|
34
|
+
- lib/courbet/templates/light.erb
|
35
|
+
- lib/courbet/templates/sphere.erb
|
36
|
+
- lib/courbet/version.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.10
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Turn Molecular Dynamics XYZ files into PovRay files
|
61
|
+
test_files: []
|