Class Rubidium::Converter
In: lib/rubidium/lang.rb
Parent: Object

A general-purpose molecular language converter.

Usage:

 require 'rubidium/lang'

 c = Rubidium::Converter.new # Defaults to toolkit = 'CDK'

 c.set_formats 'smi', 'inchi'
 c.convert 'c1ccccc1' # => "InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H"
 c.molecule # returns the molecule representing benzene

Methods

Attributes

in_format  [R] 
molecule  [RW] 
out_format  [R] 
toolkit  [R] 

Public Class methods

Constructs a CDK converter by default.

[Source]

    # File lib/rubidium/lang.rb, line 41
41:     def initialize(toolkit = 'CDK')
42:       @toolkit = toolkit
43:       @readers = create_readers
44:       @writers = create_writers
45:     end

Public Instance methods

Converts given input based on the formats defined in set_formats.

[Source]

    # File lib/rubidium/lang.rb, line 65
65:     def convert input
66:       read input
67:       write
68:     end

Reads the molecule encoded by input in the format defined by in_format.

[Source]

    # File lib/rubidium/lang.rb, line 92
92:     def read input
93:       raise "No input format" unless @in_format
94: 
95:       @molecule = @readers[@in_format].read input
96: 
97:       @molecule != nil
98:     end

Sets the input and output formats for this Converter. CDK converters recognize the input formats: ‘mol’ (MDL V2000 molfile); ‘inchi’, and ‘smi’ (SMILES). Recognized output formats are: ‘mol’, ‘inchi’, and ‘smi’.

[Source]

    # File lib/rubidium/lang.rb, line 52
52:     def set_formats in_format, out_format
53:       set_in_format in_format
54:       set_out_format out_format
55: 
56:       true
57:     end

Sets the input format to one of the formats defined in set_formats.

[Source]

    # File lib/rubidium/lang.rb, line 72
72:     def set_in_format format
73:       raise "No input format matching #{format}" unless @readers[format]
74: 
75:       @in_format = format
76:     end

Sets the output format to one of the formats defined in set_formats.

[Source]

    # File lib/rubidium/lang.rb, line 80
80:     def set_out_format format
81:       raise "No output format matching #{format}" unless @writers[format]
82: 
83:       @out_format = format
84:     end

Writes the molecule encoded by the previous call to read in the format defined by out_format.

[Source]

     # File lib/rubidium/lang.rb, line 106
106:     def write
107:       raise "No output format" unless @out_format
108: 
109:       @writers[@out_format].write @molecule
110:     end

[Validate]