rbtk 0.1.0-jruby

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2007 Richard L. Apodaca
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README ADDED
@@ -0,0 +1,60 @@
1
+ = Rubidium: Cheminformatics for Ruby
2
+
3
+ {Project Home Page}[http://rbtk.rubyforge.org]
4
+
5
+ {RubyForge Project}[http://rubyforge.org/projects/rbtk]
6
+
7
+ == DESCRIPTION
8
+
9
+ Rubidium is a full-featured cheminformatics scripting environment for Ruby. It provides a clean, well-documented interface to the best open source cheminformatics software.
10
+
11
+ == Dependencies
12
+
13
+ * {JRuby 1.0.0}[http://jruby.codehaus.org]
14
+
15
+ == Download
16
+
17
+ Rubidium can be {downloaded from RubyForge}[http://rubyforge.org/frs/?group_id=4671]
18
+
19
+ == Installation
20
+
21
+ <tt>$ jruby -S gem install rbtk</tt>
22
+
23
+ == Examples
24
+
25
+ ===Convert Benzene SMILES into InChI
26
+ require 'rubidium/lang'
27
+
28
+ c = Rubidium::Converter.new
29
+
30
+ c.set_formats 'smi', 'inchi'
31
+ c.convert 'c1ccccc1' => "InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H"
32
+
33
+ ===Create a CDK molecule from a SMILES string and count its atoms.
34
+
35
+ require 'cdk/lang'
36
+
37
+ r = CDK::SmilesReader.new
38
+ mol = r.read 'c1ccccc1'
39
+
40
+ mol.atom_count # => 6
41
+
42
+ == Authors
43
+
44
+ Copyright (C) 2007 {Richard L. Apodaca}[http://depth-first.com]
45
+
46
+ == Acknowledgments
47
+
48
+ This library combines capabilities from a variety of open source projects:
49
+
50
+ - {Chemistry Development Kit}[http://cdk.sf.net], distributed under the {GNU Lesser GPL}[http://www.opensource.org/licenses/lgpl-license.php]
51
+
52
+ Many thanks to those contributing to these projects.
53
+
54
+ Rubidium was made possible with the support of {Metamolecular, LLC}[http://metamolecular.com].
55
+
56
+ == License
57
+
58
+ This library is distributed under the MIT License. Please see the LICENSE[link://files/LICENSE.html] file for more details.
59
+
60
+
@@ -0,0 +1,65 @@
1
+ # ==================================
2
+ # Rubidium: Cheminformatics for Ruby
3
+ # ==================================
4
+ #
5
+ # Copyright (C) 2007 Richard L. Apodaca
6
+ #
7
+ # http://rbtk.rubyforge.org
8
+ #
9
+ # This library is open source software distributed under
10
+ # the terms of the MIT License. See the LICENSE file for
11
+ # details.
12
+
13
+ require 'rake'
14
+ require 'rake/testtask'
15
+ require 'rake/rdoctask'
16
+ require 'rake/gempackagetask'
17
+
18
+ PKG_VERSION = "0.1.0"
19
+
20
+ desc "Default task"
21
+ task :default => [:test]
22
+
23
+ Rake::TestTask.new do |t|
24
+ t.libs << "test"
25
+ t.test_files = FileList['test/*_test.rb']
26
+ t.verbose = true
27
+ end
28
+
29
+ rd = Rake::RDocTask.new do |rdoc|
30
+ rdoc.rdoc_dir = 'doc'
31
+ rdoc.title = "Rubidium: Cheminformatics for Ruby"
32
+ rdoc.rdoc_files.include('README', 'LICENSE')
33
+ rdoc.options << '--line-numbers'
34
+ rdoc.options << '--inline-source'
35
+ rdoc.options << '--main' << 'README'
36
+ rdoc.rdoc_files.include('lib/**/*.rb')
37
+ end
38
+
39
+ PKG_FILES = FileList[
40
+ "Rakefile", "README", "LICENSE",
41
+ "lib/**/*.rb",
42
+ "test/**/*",
43
+ "ext/lib/*.jar"
44
+ ]
45
+
46
+ spec = Gem::Specification.new do |s|
47
+ s.name = 'rbtk'
48
+ s.version = PKG_VERSION
49
+ s.author = "Richard L. Apodaca"
50
+ s.homepage = "http://rubyforge.org/projects/rbtk"
51
+ s.platform = 'jruby'
52
+ s.require_path = 'lib'
53
+ s.autorequire = 'rubidium'
54
+ s.has_rdoc = true
55
+ s.files = PKG_FILES
56
+ s.summary = "The Ruby Cheminformatics Toolkit"
57
+ s.description = s.summary
58
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
59
+ s.rdoc_options = rd.options
60
+ end
61
+
62
+ Rake::GemPackageTask.new(spec) do |gem|
63
+ gem.need_tar_gz = true
64
+ gem.package_files += PKG_FILES
65
+ end
Binary file
@@ -0,0 +1,24 @@
1
+ =begin
2
+ # ==================================
3
+ # Rubidium: Cheminformatics for Ruby
4
+ # ==================================
5
+ #
6
+ # Copyright (C) 2007 Richard L. Apodaca
7
+ #
8
+ # http://rbtk.rubyforge.org
9
+ #
10
+ # This library is open source software distributed under
11
+ # the terms of the MIT License. See the LICENSE file for
12
+ # details.
13
+ =end
14
+
15
+ $:.unshift File.join(File.dirname(__FILE__), "..")
16
+
17
+ require 'java'
18
+ require 'ext/lib/cdk-1.0.1.jar'
19
+
20
+ # Selected functionality from the Chemistry Development
21
+ # Kit. Convenience layer for commonly-used CDK tasks.
22
+ module CDK
23
+
24
+ end
@@ -0,0 +1,152 @@
1
+ =begin
2
+ # ==================================
3
+ # Rubidium: Cheminformatics for Ruby
4
+ # ==================================
5
+ #
6
+ # Copyright (C) 2007 Richard L. Apodaca
7
+ #
8
+ # http://rbtk.rubyforge.org
9
+ #
10
+ # This library is open source software distributed under
11
+ # the terms of the MIT License. See the LICENSE file for
12
+ # details.
13
+ =end
14
+
15
+ $:.unshift File.join(File.dirname(__FILE__), "..")
16
+
17
+ require 'cdk'
18
+
19
+ module CDK
20
+
21
+ # String-based molfile reader.
22
+ class MolfileReader
23
+ import 'java.io.StringReader'
24
+ import 'org.openscience.cdk.io.MDLReader'
25
+ import 'org.openscience.cdk.Molecule'
26
+
27
+ def initialize
28
+ @reader = MDLReader.new
29
+ end
30
+
31
+ # Returns the molecule encoded by the given molfile.
32
+ #
33
+ # call-seq:
34
+ # MolfileReader.read(molfile) => org.openscience.cdk.Molecule
35
+ #
36
+ def read molfile
37
+ @reader.set_reader StringReader.new(molfile)
38
+ @reader.read Molecule.new
39
+ end
40
+ end
41
+
42
+ # String-based InChI reader.
43
+ class InChIReader
44
+ import 'org.openscience.cdk.inchi.InChIGeneratorFactory'
45
+ import 'org.openscience.cdk.Molecule'
46
+
47
+ def initialize
48
+ @factory = InChIGeneratorFactory.new
49
+ end
50
+
51
+ # Returns the molecule encoded by the given InChI
52
+ # string.
53
+ #
54
+ # call-seq:
55
+ # InChIReader.read(inchi) => org.openscience.cdk.Molecule
56
+ #
57
+ def read inchi
58
+ Molecule.new @factory.getInChIToStructure(inchi).atom_container
59
+ end
60
+ end
61
+
62
+ # String-based SMILES reader.
63
+ class SmilesReader
64
+ import 'org.openscience.cdk.smiles.SmilesParser'
65
+
66
+ def initialize
67
+ @reader = SmilesParser.new
68
+ end
69
+
70
+ # Returns the molecule encoded by the given SMILES
71
+ # string.
72
+ #
73
+ # call-seq:
74
+ # InChIReader.read(inchi) => org.openscience.cdk.Molecule
75
+ #
76
+ def read smiles
77
+ @reader.parse_smiles smiles
78
+ end
79
+ end
80
+
81
+ # String-based molfile writer.
82
+ class MolfileWriter
83
+ import 'java.io.StringWriter'
84
+ import 'org.openscience.cdk.io.MDLWriter'
85
+
86
+ def initialize
87
+ @writer = MDLWriter.new
88
+ end
89
+
90
+ # Returns the molfile representation of the given molecule.
91
+ #
92
+ # call-seq:
93
+ # MolfileWriter.write(mol) => string
94
+ #
95
+ def write mol
96
+ string_writer = StringWriter.new
97
+
98
+ @writer.set_writer string_writer
99
+ @writer.write_molecule mol
100
+ @writer.close
101
+
102
+ string_writer.to_string
103
+ end
104
+ end
105
+
106
+ # String-based InChI writer.
107
+ class InChIWriter
108
+ import 'org.openscience.cdk.inchi.InChIGeneratorFactory'
109
+ import 'org.openscience.cdk.tools.HydrogenAdder'
110
+
111
+ def initialize
112
+ @factory = InChIGeneratorFactory.new
113
+ @hydrogen_adder = HydrogenAdder.new
114
+ end
115
+
116
+ # Returns the InChI representation of the given molecule.
117
+ #
118
+ # call-seq:
119
+ # InChIWriter.write(mol) => string
120
+ #
121
+ def write mol
122
+ @hydrogen_adder.add_implicit_hydrogens_to_satisfy_valency mol
123
+ @factory.getInChIGenerator(mol).inchi
124
+ end
125
+ end
126
+
127
+ # String-based SMILES writer.
128
+ class SmilesWriter
129
+ import 'java.io.StringWriter'
130
+ import 'org.openscience.cdk.io.SMILESWriter'
131
+
132
+ def initialize
133
+ @writer = SMILESWriter.new
134
+ end
135
+
136
+ # Returns the SMILES representation of the given molecule.
137
+ #
138
+ #
139
+ # call-seq:
140
+ # SmilesWriter.write(mol) => string
141
+ #
142
+ def write mol
143
+ string_writer = StringWriter.new
144
+
145
+ @writer.set_writer string_writer
146
+ @writer.write mol
147
+ @writer.close
148
+
149
+ string_writer.to_string.strip
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,23 @@
1
+ =begin
2
+ # ==================================
3
+ # Rubidium: Cheminformatics for Ruby
4
+ # ==================================
5
+ #
6
+ # Copyright (C) 2007 Richard L. Apodaca
7
+ #
8
+ # http://rbtk.rubyforge.org
9
+ #
10
+ # This library is open source software distributed under
11
+ # the terms of the MIT License. See the LICENSE file for
12
+ # details.
13
+ =end
14
+
15
+ # TODO: This file will ultimately be used to determine
16
+ # whether JRuby or MRI is being used. If MRI, then the
17
+ # file 'rubidium/java' will be included, giving the same
18
+ # interface to Java classes and methods as JRuby.
19
+
20
+ # Main module for Rubidium.
21
+ module Rubidium
22
+
23
+ end
@@ -0,0 +1,124 @@
1
+ =begin
2
+ # ==================================
3
+ # Rubidium: Cheminformatics for Ruby
4
+ # ==================================
5
+ #
6
+ # Copyright (C) 2007 Richard L. Apodaca
7
+ #
8
+ # http://rbtk.rubyforge.org
9
+ #
10
+ # This library is open source software distributed under
11
+ # the terms of the MIT License. See the LICENSE file for
12
+ # details.
13
+ =end
14
+
15
+ $:.unshift File.join(File.dirname(__FILE__), "..")
16
+
17
+ module Rubidium
18
+ require 'cdk/lang'
19
+
20
+ # A general-purpose molecular language converter.
21
+ #
22
+ # Usage:
23
+ #
24
+ # require 'rubidium/lang'
25
+ #
26
+ # c = Rubidium::Converter.new # Defaults to toolkit = 'CDK'
27
+ #
28
+ # c.set_formats 'smi', 'inchi'
29
+ # c.convert 'c1ccccc1' # => "InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H"
30
+ # c.molecule # returns the molecule representing benzene
31
+ #
32
+ class Converter
33
+ attr_accessor :molecule
34
+ attr_reader :in_format
35
+ attr_reader :out_format
36
+ attr_reader :toolkit
37
+
38
+ # Constructs a CDK converter by default.
39
+ def initialize(toolkit = 'CDK')
40
+ @toolkit = toolkit
41
+ @readers = create_readers
42
+ @writers = create_writers
43
+ end
44
+
45
+ # Sets the input and output formats for this Converter.
46
+ # CDK converters recognize the input formats: 'mol'
47
+ # (MDL V2000 molfile); 'inchi', and 'smi' (SMILES).
48
+ # Recognized output formats are: 'mol', 'inchi', and
49
+ # 'smi'.
50
+ def set_formats in_format, out_format
51
+ set_in_format in_format
52
+ set_out_format out_format
53
+
54
+ true
55
+ end
56
+
57
+ # Converts given input based on the formats
58
+ # defined in #set_formats.
59
+ #
60
+ # call-seq:
61
+ # convert(input) => string
62
+ #
63
+ def convert input
64
+ read input
65
+ write
66
+ end
67
+
68
+ # Sets the input format to one of the formats
69
+ # defined in #set_formats.
70
+ def set_in_format format
71
+ raise "No input format matching #{format}" unless @readers[format]
72
+
73
+ @in_format = format
74
+ end
75
+
76
+ # Sets the output format to one of the formats
77
+ # defined in #set_formats.
78
+ def set_out_format format
79
+ raise "No output format matching #{format}" unless @writers[format]
80
+
81
+ @out_format = format
82
+ end
83
+
84
+ # Reads the molecule encoded by +input+ in the format
85
+ # defined by #in_format.
86
+ #
87
+ # call-seq:
88
+ # input(input) => boolean
89
+ #
90
+ def read input
91
+ raise "No input format" unless @in_format
92
+
93
+ @molecule = @readers[@in_format].read input
94
+
95
+ @molecule != nil
96
+ end
97
+
98
+ # Writes the molecule encoded by the previous call to
99
+ # #read in the format defined by #out_format.
100
+ #
101
+ # call-seq:
102
+ # write => string
103
+ #
104
+ def write
105
+ raise "No output format" unless @out_format
106
+
107
+ @writers[@out_format].write @molecule
108
+ end
109
+
110
+ private
111
+
112
+ def create_readers
113
+ {'mol' => CDK::MolfileReader.new,
114
+ 'inchi' => CDK::InChIReader.new,
115
+ 'smi' => CDK::SmilesReader.new}
116
+ end
117
+
118
+ def create_writers
119
+ {'mol' => CDK::MolfileWriter.new,
120
+ 'inchi' => CDK::InChIWriter.new,
121
+ 'smi' => CDK::SmilesWriter.new}
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,56 @@
1
+ # ==================================
2
+ # Rubidium: Cheminformatics for Ruby
3
+ # ==================================
4
+ #
5
+ # Copyright (C) 2007 Richard L. Apodaca
6
+ #
7
+ # http://rbtk.rubyforge.org
8
+ #
9
+ # This library is open source software distributed under
10
+ # the terms of the MIT License. See the LICENSE file for
11
+ # details.
12
+
13
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
14
+
15
+ require 'test/unit'
16
+ require 'rubidium/lang'
17
+
18
+ class TestConverter < Test::Unit::TestCase
19
+ def test_create_conversion
20
+ c = Rubidium::Converter.new
21
+
22
+ assert_not_nil c
23
+ end
24
+
25
+ def test_set_valid_in_format
26
+ c = Rubidium::Converter.new
27
+
28
+ assert_nothing_raised{c.set_in_format 'smi'}
29
+ assert_equal 'smi', c.in_format
30
+ end
31
+
32
+ def test_set_invalid_in_format
33
+ c = Rubidium::Converter.new
34
+
35
+ assert_raise(RuntimeError){c.set_in_format 'nonsense'}
36
+ end
37
+
38
+ def test_read_valid_input
39
+ c = Rubidium::Converter.new
40
+
41
+ c.set_in_format 'smi'
42
+
43
+ assert_nothing_raised{c.read 'c1ccccc1'}
44
+
45
+ assert_not_nil c.molecule
46
+ assert_equal 6, c.molecule.atom_count
47
+ end
48
+
49
+ def test_read_invalid_input
50
+ c = Rubidium::Converter.new
51
+
52
+ c.set_in_format 'smi'
53
+
54
+ assert_raise(NativeException){c.read 'nonsense'}
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.3
3
+ specification_version: 1
4
+ name: rbtk
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-11-06 00:00:00 -08:00
8
+ summary: The Ruby Cheminformatics Toolkit
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage: http://rubyforge.org/projects/rbtk
13
+ rubyforge_project:
14
+ description: The Ruby Cheminformatics Toolkit
15
+ autorequire: rubidium
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: jruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Richard L. Apodaca
31
+ files:
32
+ - Rakefile
33
+ - README
34
+ - LICENSE
35
+ - lib/rubidium/lang.rb
36
+ - lib/cdk/lang.rb
37
+ - lib/rubidium.rb
38
+ - lib/cdk.rb
39
+ - test/converter_test.rb
40
+ - ext/lib/cdk-1.0.1.jar
41
+ test_files: []
42
+
43
+ rdoc_options:
44
+ - --line-numbers
45
+ - --inline-source
46
+ - --main
47
+ - README
48
+ extra_rdoc_files:
49
+ - README
50
+ - LICENSE
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ requirements: []
56
+
57
+ dependencies: []
58
+