Module: Chem::MDL::MdlMolParser

Included in:
KEGG::KeggCompound, MdlMolecule
Defined in:
lib/chem/db/mdl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



178
179
180
# File 'lib/chem/db/mdl.rb', line 178

def filename
  @filename
end

#mol_nameObject (readonly)

Returns the value of attribute mol_name.



190
191
192
# File 'lib/chem/db/mdl.rb', line 190

def mol_name
  @mol_name
end

Instance Method Details

#date_timeObject



194
195
196
197
198
199
200
201
202
203
# File 'lib/chem/db/mdl.rb', line 194

def date_time
  year_last_two = @header_line2[14..15].to_i
  year = year_last_two + (year_last_two > 80 ? 1900 : 2000)
  @date ||= DateTime.new(
                         year,
                         @header_line2[10..11].to_i,
                         @header_line2[12..13].to_i,
                         @header_line2[16..17].to_i,
                         @header_line2[18..19].to_i)
end

#dimensional_codesObject



205
206
207
# File 'lib/chem/db/mdl.rb', line 205

def dimensional_codes
  @dimensional_codes ||=  @header_line2[20..21]
end

#entryObject Also known as: name



185
186
187
# File 'lib/chem/db/mdl.rb', line 185

def entry
  @title
end

#open(filename) ⇒ Object



179
180
181
182
183
# File 'lib/chem/db/mdl.rb', line 179

def open(filename)
  @filename = filename
  input = File.open(filename)
  parse(input)
end

#parse(input) ⇒ Object

Raises:

  • (MDLException)


209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/chem/db/mdl.rb', line 209

def parse(input)
  @mol_name = input.readline.chop
  @header_line2 = input.readline.chop
  raise MDLException if @comment = input.readline == nil
  line = input.readline
  n_atom = line[0..2].to_i
  n_bond = line[3..5].to_i

  if 0 > n_atom or 999 < n_atom or 0 > n_bond or 999 < n_bond
    raise "counts line format error"
  end

  n_atom.times do |n|
    mol = MDLAtom.new(input.readline)
    mol.number = n + 1
    @nodes.push(mol)
  end

  n_bond.times do |n|
    line = input.readline
    b = MDLBond.new line
    b_n = line[0..2].to_i
    e_n = line[3..5].to_i
    if (b_n > n_atom || b_n < 1 || e_n > n_atom || e_n < 1)
      p line
      raise "MDL bond line format error"
    end

    @edges.push([b, @nodes[b_n - 1], @nodes[e_n - 1]])
  end
  input.each do |line|
    break if /M  END/.match(line)
  end
  self
end

#program_nameObject



192
# File 'lib/chem/db/mdl.rb', line 192

def program_name ; @program_name ||= @header_line2[2..9] end