lib/vasputils/poscar.rb in vasputils-0.1.6 vs lib/vasputils/poscar.rb in vasputils-0.1.7

- old
+ new

@@ -3,11 +3,11 @@ require "rubygems" require "crystalcell" # Class to manage POSCAR format of VASP. -# +# # parse と dump のどちらかだけでなく、両方を統括して扱うクラス。 class VaspUtils::Poscar class ElementMismatchError < Exception; end class ParseError < Exception; end @@ -128,24 +128,26 @@ nums_elements[atom.element] += 1 end nums_elements = elements.map{|elem| nums_elements[elem]} positions = [] - movable_flags = [] + #movable_flags = [] selective_dynamics = false atoms.each do |atom| positions << atom.position - movable_flags << atom.movable_flags - selective_dynamics = true if movable_flags + #movable_flags << atom.movable_flags + #selective_dynamics = true if movable_flags end - selective_dynamics = movable_flags if movable_flags + #selective_dynamics = movable_flags if movable_flags + selective_dynamics = false options = { :comment => cell.comment , :scale => 1.0 , - :axes => cell.axes.to_a, + #:axes => cell.axes.to_a, + :axes => cell.axes, :elements => elements , :nums_elements => nums_elements , :selective_dynamics => selective_dynamics, :direct => true, :positions => positions , @@ -162,11 +164,10 @@ # # io は書き出すファイルハンドル。 # 'version' indicates a poscar style for vasp 4 or 5. #def dump(io, elements = nil, version = 5) def dump(io, version = 5) - elements = @elements unless elements elem_indices = elements.map {|elem| @elements.find_index(elem)} unless (Mapping::map?(@elements.uniq, elements){ |i, j| i == j }) raise ElementMismatchError, "elements [#{elements.join(",")}] mismatches to cell.elements [#{cell.elements.join(",")}." end @@ -210,11 +211,11 @@ movable_flags = nil if @selective_dynamics movable_flags = @selective_dynamics[total_id] end atoms << CrystalCell::Atom.new( - element, + element, @positions[total_id], movable_flags ) total_id += 1 end @@ -272,21 +273,21 @@ } VaspUtils::Poscar.new(hash) end - # + # def ==(other) result = true - result = false unless @comment == other.comment - result = false unless @scale == other.scale - result = false unless @axes == other.axes - result = false unless @elements == other.elements - result = false unless @nums_elements == other.nums_elements - result = false unless @selective_dynamics == other.selective_dynamics - result = false unless @direct == other.direct - result = false unless @positions == other.positions + result = false unless @comment == other.comment + result = false unless @scale == other.scale + result = false unless @axes == other.axes + result = false unless @elements == other.elements + result = false unless @nums_elements == other.nums_elements + result = false unless @selective_dynamics == other.selective_dynamics + result = false unless @direct == other.direct + result = false unless @positions == other.positions result end def substitute(elem1, elem2) result = Marshal.load(Marshal.dump(self)) @@ -294,11 +295,11 @@ result end def substitute!(elem1, elem2) @elements.map! do |elem| - if elem == elem1 + if elem == elem1 elem2 else elem end end @@ -324,20 +325,19 @@ val.each do |pos| @positions << pos end end end - + def periodic_nearest(coord0, coord1) pcell = CrystalCell::PeriodicCell.new( [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], ]) result = coord1.to_v3di + pcell.nearest_direction( coord0.to_v3di, coord1.to_v3di) result.to_a end - def interpolate_coords(coord0, coord1, ratio) ((coord0.to_v3d * (1-ratio) + coord1.to_v3d * ratio)).to_a end