#!/usr/bin/ruby # Main program for calculating dHmix and GS-structure # # Written by k-fleak # require "#{ENV["HOME"]}/myRuby/parseCMCout.rb" require "#{ENV["HOME"]}/myRuby/parseMCin.rb" class GroundState def initialize(project) @project = project calcComposition calcPureEnergy calcEnergy # per atom calcFormationEnergy writeHform end private def calcComposition @compArray = Array.new @compArray.push(0.0) @compArray.push(1.0) Dir.entries("./out.eci-#{@project}").each do |file| if FileTest.file?("./out.eci-#{@project}/#{file}") and /cmc.out./ =~ file and !(/prototype/ =~ file) then @compArray.push(file.gsub(/cmc.out./, '').to_f) end end @compArray.sort! end def calcPureEnergy @pureE = Hash.new input = open("PureEnergy.#{@project}", "r") input.each do |inp| unless inp.strip.empty? then lineArr = inp.strip.split @pureE[lineArr[0].to_f] = lineArr[1].to_f end end end def calcEnergy @energy = Hash.new parseMCin = ParseMCin.new("MC.in") numCell = parseMCin.getNcell parseCMC = ParseCMCout.new("./out.eci-#{@project}/cmc.out.prototype") numAtomMCcell = parseCMC.getNumAtomMCcell numAtomOrigCell = numAtomMCcell / numCell @compArray.each do |comp| etmp = 0.0 if comp < 0.00001 then etmp = @pureE[0.0] / numAtomOrigCell elsif comp > 0.99999 then etmp = @pureE[1.0] / numAtomOrigCell else parse = ParseCMCout.new("./out.eci-#{@project}/cmc.out.#{comp}") etmp = parse.getAveEnergy / numAtomMCcell end @energy[comp] = etmp end end def calcFormationEnergy hFormArray = Array.new @energy.each do |eng| comp = eng[0] energy = eng[1] segLimit = (@energy[1.0] - @energy[0.0]) * comp + @energy[0.0] hForm = energy - segLimit hFormArray.push(["#{comp} #{hForm} \n"]) end @Hform = hFormArray.sort end def writeHform output = open("Hform.eci-#{@project}", "w") @Hform.each do |hf| output.write(hf) end output.close end end gs = GroundState.new(ARGV[0])