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:

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

# Constrain atoms below some z value
geom.each{|atom| 
  if (atom.z < someValue)
      atom.constrain = true
  end
}
File.open("new_geometry.in", "w") do |f|
   f.puts geom.format_geometry_in
end

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



55
56
57
58
59
60
# File 'lib/aims/geometry_parser.rb', line 55

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aims/geometry_parser.rb', line 29

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)
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



22
23
24
# File 'lib/aims/geometry_parser.rb', line 22

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