#!/usr/bin/ruby # Main program for preparing gsSearch (Making POSCAR (various composition)) # # Written by k-fleak # class PrepareGS def initialize(compGrid) setCompArray(compGrid) calcNumAtom calcNumAtomArray getPOSCARcomp end private def getPOSCARcomp if !FileTest.exist?("./POSCAR.comp") then Dir::mkdir("./POSCAR.comp") else Dir.entries("./POSCAR.comp/").each do |files| if /POSCAR./ =~ files and FileTest.file?("./POSCAR.comp/#{files}") then File.delete("./POSCAR.comp/#{files}") end end end @compArray.each do |comp| poscarComp = open("./POSCAR.comp/POSCAR.#{comp}", "w") poscar = open("./POFILE/POSCAR", "r") posComp = Array.new poscar.each do |pos| if /NUMATOMS/ =~ pos then ptmp = pos.gsub(/NUMATOMS/, @numAtomArray[comp][0]) posComp.push(ptmp) else posComp.push(pos) end end posComp.each do |pc| poscarComp.write(pc) end poscarComp.close end end def setCompArray(compGrid) @compArray = Array.new comp = compGrid.to_f while comp < 1.0 @compArray.push(comp) comp += compGrid.to_f end @compArray.each do |ca| if ca > 0.99999 then @compArray.delete(ca) end end end def calcNumAtom poscar = open("./POFILE/POSCAR", "r") ntmp = 0 poscar.each do |pos| unless pos.strip.empty? then ntmp += 1 end end @numAtom = ntmp - 7 end def calcNumAtomArray @numAtomArray = Hash.new @compArray.each do |comp| numAatom = (@numAtom * comp).to_i numBatom = (@numAtom - numAatom).to_i @numAtomArray[comp] = ["#{numAatom} #{numBatom} "] end end end pg = PrepareGS.new(ARGV[0])