#!/usr/bin/ruby # Main program for copying machine file and making vasp-shell # # Written by k-fleak # require "ftools" require "#{ENV["HOME"]}/myRuby/parseMachineList.rb" class SetMachine def initialize setMachine end private def setMachine parseMachine = ParseMachineList.new @machineList = parseMachine.getMachineList calcNum = 1 @machineList.each do |ml| machineNameArray = Array.new machineNum = ml[1] if ml[2] then machineNum.each do |mn| machineNameArray.push(["#{ml[0] + mn} \n"]) end copyMachine(machineNameArray, ml[2]) mkVaspShell(ml[2], machineNameArray, calcNum) end calcNum += 1 end if FileTest.exist?("./machine") then File.delete("./machine") end end def mkVaspShell(dirArray, machineArray, calcNum) vaspTemp = open("./INPUTS/vaspTemplate.sh", "r") vaspShell = open("vaspAuto#{calcNum}.sh", "w", 0755) vArray = Array.new dirName = "" numMachine = machineArray.size dirArray.each do |dir| dirName += dir + " " end vaspTemp.each do |vt| if /DIRECTORY/ =~ vt then vArray.push(["#{vt.gsub(/DIRECTORY/, dirName)}"]) elsif /NUMMACHINE/ =~ vt then vArray.push(["#{vt.gsub(/NUMMACHINE/, numMachine.to_s)}"]) else vArray.push(vt) end end vArray.each do |va| vaspShell.write(va) end vaspShell.close end def copyMachine(machineArray, dirArray) output = open("./machine", "w") machineArray.each do |ma| output.write(ma) end output.close dirArray.each do |dir| if FileTest.exist?(dir) then File.copy "./machine", "./#{dir}" end end end end sm = SetMachine.new