Class: Aims::GeometryParser

Inherits:
Object
  • Object
show all
Defined in:
lib/aims/geometry_parser.rb

Overview

Utility class for parsing an Aims geometry file Example Usage:

uc = Aims::GeometryParser.parse("geometry.in")

Class Method Summary collapse

Class Method Details

.parse(filename) ⇒ Object

Parse a geometry.in file

  • filename the file to parse

  • return the Aims::Geometry object



45
46
47
48
49
50
# File 'lib/aims/geometry_parser.rb', line 45

def GeometryParser.parse(filename)
  f = File.open(filename, 'r')
  cell = GeometryParser.parse_io(f)
  f.close
  return cell
end

.parse_io(io) ⇒ Object

Parse an IO object representation of a geometry.in file

  • io The IO object to parse

  • Return the Aims::Geometry object that was parsed



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aims/geometry_parser.rb', line 19

def GeometryParser.parse_io(io)
  atoms = Array.new
  vectors = nil
  io.each_line{|line|
    case line
    when /\w*#.*/
      # Comment line, Do nothing
    when /atom/
      a, x, y, z, species = line.split(' ')
atom = Atom.new(x.to_f,y.to_f,z.to_f,species)
      atoms << atom
    when /lattice_vector/
      a, x, y, z = line.split(' ')
      vectors = Array.new if vectors.nil?
      vectors << Vector[x.to_f,y.to_f,z.to_f]
    when /constrain_relaxation/
      a, c = line.split(' ')
      atoms.last.constrain << c
    end
  }
  Geometry.new(atoms, vectors, false)
end

.parse_string(str) ⇒ Object

Parse a String representation of a geometry.in file

  • str The String to parse

  • Return the Aims::Geometry object that was parsed



12
13
14
# File 'lib/aims/geometry_parser.rb', line 12

def GeometryParser.parse_string(str)
  GeometryParser.parse_io(str)
end