#!/usr/bin/ruby # Main program for getting energy and correlation for # "pure" surface layer # # Written by k-fleak # require "#{ENV["HOME"]}/myRuby/parseCORRELATION.rb" require "#{ENV["HOME"]}/myRuby/parseENERGY.rb" require "#{ENV["HOME"]}/myRuby/parseSigmaSet.rb" require "#{ENV["HOME"]}/myRuby/parseECI.rb" require "#{ENV["HOME"]}/myRuby/parseClusterOutSort.rb" require "#{ENV["HOME"]}/myRuby/identifyCluster.rb" require "getopts" class PureSurfInfo def initialize(sigmaOutBulkFile, sigmaOutSurfFile, eciBulkFile, coutBulkFile, coutSurfFile, corrSurfFile, energySurfFile, flags, multiplyCell) parseECI = ParseECI.new(eciBulkFile) @eciBulk = parseECI.getECI parseSigmaSetBulk = ParseSigmaSet.new(sigmaOutBulkFile) @numClusterBulk = parseSigmaSetBulk.getNumCluster parseSigmaSetSurf = ParseSigmaSet.new(sigmaOutSurfFile) @numClusterSurf = parseSigmaSetSurf.getNumCluster parseEnergy = ParseEnergy.new(energySurfFile) @energySurf = parseEnergy.getEnergy @energySurfArray = parseEnergy.getEnergyArray parseCorr = ParseCorrelation.new(corrSurfFile) @corrSurf = parseCorr.getCorrelation parseCoutSurf = ParseClusterOutSearch.new(coutSurfFile) @indexRelation = parseCoutSurf.getIndexRelation @flags = flags @multiplyCell = multiplyCell getECIBulkPerCluster getBulkSublatticeInSurf(coutSurfFile) calcBulkClusterIndexInSurf(coutBulkFile, coutSurfFile, @flags) calcNumBulkClusterInSurf end def getPureSurfLayerEnergy calcPureSurfLayerEnergy @energySurfArray.each do |es| struct = es[0] energy = @pureSurfLayerEnergy[es[0]] print struct print " " print energy print "\n" end end def getBulkClusterIndexInSurf @bulkClusterIndexInSurf end def getLSinPureSurfLayer(lSinSurfFile) calcLSinPureSurfLayer(lSinSurfFile) @lsIn.each do |ls| print ls print "\n" end end def getNumBulkClusterInSurf @numBulkClusterInSurf end private def getECIBulkPerCluster @eciBulkPerClus = Hash.new() @eciBulk.each do |eciB| numCluster = @numClusterBulk[eciB[0]] @eciBulkPerClus[eciB[0]] = eciB[1] / numCluster end end def getBulkSublatticeInSurf(coutSurfFile) coutSurf = ParseClusterOutOrig.new(coutSurfFile) pointDataSurf = coutSurf.getPointData @bulkSublatticeInSurf = -1 pointDataSurf.each do |pdata| btmp = pdata[1][0].to_i if btmp > @bulkSublatticeInSurf then @bulkSublatticeInSurf = btmp end end end # @bulkClusterIndexInSurf: [Cluster Index in bulk, Corresponding cluster indexes [after sorting] in surf] def calcBulkClusterIndexInSurf(coutBulkFile, coutSurfFile, flags) @bulkClusterIndexInSurf = Hash.new() @eciBulkPerClus.each do |eciB| ids = IdentifyCluster.new(coutBulkFile, coutSurfFile, eciB[0].to_s) ids.start() sameCluster = ids.getSameCluster latticeArray = Array.new() ptmp = Array.new() unless ids.nBody == 0 then ids.nBody.times do latticeArray.push(@bulkSublatticeInSurf.to_s) end sameCluster.each do |sc| case flags when 0 # Clusters with ALL sublattice has bulk sublattice are treated as bulk if sc[0] == latticeArray then case ids.nBody when 1 ptmp.push(sc[1][1]) else ptmp.push(sc[sc.size - 1]) end end else # Clusters with AT LEAST ONE sublattice has bulk sublattice are treated as bulk if sc[0].include?(@bulkSublatticeInSurf.to_s) then case ids.nBody when 1 ptmp.push(sc[1][1]) else ptmp.push(sc[sc.size - 1]) end end end end @bulkClusterIndexInSurf[eciB[0]] = ptmp end end end # @numBulkClusterInSurf: key => Cluster index in bulk, value => [corresponding cluster index (after sorting) in surf, num cluster] def calcNumBulkClusterInSurf @numBulkClusterInSurf = Hash.new() @bulkClusterIndexInSurf.each do |bCArray| atmp = Array.new() @numBulkClusterInSurf[bCArray[0]] = atmp bCArray[1].each do |bc| numClusterAll = 0 indexOrigSurf = @indexRelation[bc] indexOrigSurf.each do |ios| numCluster = @numClusterSurf[ios.to_i] / @multiplyCell numClusterAll += numCluster end ptmp = [bc, numClusterAll] @numBulkClusterInSurf[bCArray[0]].push(ptmp) end end end def calcPureSurfLayerEnergy @pureSurfLayerEnergy = Hash.new() @energySurf.each do |eSurf| structure = eSurf[0] correlation = @corrSurf[eSurf[0]] bulkLayerEnergy = 0.0 cIndex = 0 @numBulkClusterInSurf.each do |nbc| bulkClusterIndex = nbc[0] eci = @eciBulkPerClus[bulkClusterIndex] surfCluster = nbc[1] sigmaProd = 0 surfCluster.each do |sc| sigmaProd += correlation[sc[0]] * sc[1].to_f end bulkLayerEnergy += eci * sigmaProd end @pureSurfLayerEnergy[structure] = eSurf[1] - bulkLayerEnergy end end def calcLSinPureSurfLayer(lSinSurfFile) @lsIn = Array.new lsIn = open(lSinSurfFile, "r") lsIn.each do |lines| unless lines.strip.empty? then @lsIn.push(lines.strip.to_i) end end @bulkClusterIndexInSurf.each do |bci| bci[1].each do |cIndex| @lsIn.delete(cIndex) end end end end # Usage # # option: -e => Getting pure surface layer energy # -l => Getting pure surface layer LS.in # # > ./getPureSurfLayerInfo.rb -e [sigmaSet.out.bulk] [sigmaSet.out.surf] [ECI.bulk] [cluster.out.sort.bulk] [cluster.out.sort.surf] # [CORRELATION.surf] [ENERGY.surf] flag(0: Treat bulk as [b,b,b,b...] sublattice, # 1: Treat bulk as at least with one bulk sublattice) # multiplyCell (If sigmaSet.out.surf is for multiplied cell compared to ENERGY.surf, # specify multiply number) # # > ./getPureSurfLayerInfo.rb -l [sigmaSet.out.bulk] [sigmaSet.out.surf] [ECI.bulk] [cluster.out.sort.bulk] [cluster.out.sort.surf] # [CORRELATION.surf] [ENERGY.surf] flag(0: Treat bulk as [b,b,b,b...] sublattice, # 1: Treat bulk as at least with one bulk sublattice) # multiplyCell (If sigmaSet.out.surf is for multiplied cell compared to ENERGY.surf, # specify multiply number) # [LS.in.surf(After sorting)] if /-e/ =~ ARGV[0] then psurf = PureSurfInfo.new(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5], ARGV[6], ARGV[7], ARGV[8].to_i, ARGV[9].to_f) psurf.getPureSurfLayerEnergy elsif /-l/ =~ ARGV[0] then psurf = PureSurfInfo.new(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5], ARGV[6], ARGV[7], ARGV[8].to_i, ARGV[9].to_f) psurf.getLSinPureSurfLayer(ARGV[10]) end