Version2/MainVR2.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$timer = [Diagnostics.Stopwatch]::StartNew() #Stopwatch
#$VasprunFile="./vasprun.xml" #This variable is supplied via function.
# We are already in directory, so only file name required.
$XmlObject = (Read-AsXml -VasprunFile (Convert-Path $VasprunFile))
$loadtime = $timer.Elapsed.TotalSeconds
Write-Host "$([Math]::Round($($loadtime),3)) seconds elapsed while loading vasprun.xml($([Math]::Round(((Get-Item $VasprunFile).length/1MB),3)) MB)" -ForegroundColor Cyan
$timer.Stop();

$weights = Get-FillingWeights -XmlObject $XmlObject
$info = Get-Summary -XmlObject $XmlObject 
$sys = $info.SYSTEM; $NION = $info.NION; $NBANDS = $info.NBANDS; $NKPTS = $info.NKPTS; $filled = $weights.Filled;
Write-Host "▲ " -ForegroundColor Red -NoNewline
Write-Host " SYSTEM: $sys, NIONS: $NION, NBANDS: $NBANDS, Filled: $filled, NKPTS: $($NKPTS-$ibzkpt) " -ForegroundColor White -BackgroundColor Red
# Select Bands range.
$skipB, $NBANDS = @(0, $info.NBANDS); # Collect all bands if NFilled and NEmpty not given
if (-1 -ne $MaxFilled -and -1 -eq $MaxEmpty) {
    #check if only NFilled given.
    [int]$skipB, [int]$NBANDS = $(Get-SkipSelectBands -XmlObject $XmlObject -MaxFilled $MaxFilled); #update indices of bands.
}
elseif (-1 -ne $MaxEmpty -and -1 -eq $MaxFilled) {
    #check if only NEmpty given.
    [int]$skipB, [int]$NBANDS = $(Get-SkipSelectBands -XmlObject $XmlObject -MaxEmpty $MaxEmpty); #update indices of bands.
}
elseif (-1 -ne $MaxEmpty -and -1 -ne $MaxFilled) {
    #check if NFilled and NEmpty given.
    [int]$skipB, [int]$NBANDS = $(Get-SkipSelectBands -XmlObject $XmlObject -MaxFilled $MaxFilled -MaxEmpty $MaxEmpty); #update indices of bands.
} #Bands selction of interval's loop ended.
$filled = $filled - $skipB #Updating filled band with selected interval.
$timer.Start()  #starts timer again
#===========Excluding Extra KPOINTS from IBZKPT, No effect on GGA Calculations========
if ($SkipK -ne -1) {
    #check if $SkipK provided from calling function.
    $ibzkpt = $SkipK
}
Else {
    $ibzkpt = Read-KptsToExclude -XmlObject $XmlObject
}
#====================================================================
Write-Host "$ibzkpt IBZKPT file's KPOINTS Excluded!" -ForegroundColor Yellow
#=============OnlyDOS Switch========================
if ($getonlydos -eq $True) {
    #Skipe Collection of Bands
    $ibzkpt = $NKPTS - 1; $skipB = 0; $NBANDS = 1; $filled = 1;
} #Updated minimal working values to be able to load files
#==============================================================
# Write Bands
Write-Host "Writing file [Bands.txt] ..." -ForegroundColor Red
Write-KptsBands -XmlObject $XmlObject -SkipNKPTS $ibzkpt -SkipSelectNBANDS $skipB, $NBANDS
#=====================Main Part================================
Write-Host "Writing Total DOS on [tDOS.txt] ..." -ForegroundColor Red
Write-TotalDOS -XmlObject $XmlObject -SpinSet 1  #Automatically will write Spin polarized.
Write-Host "Writing Partial DOS on [pDOS.txt] ..." -ForegroundColor Red
Write-PartialDOS -XmlObject $XmlObject -SpinSet 1  #Automatically will write Spin polarized.
Write-Host "Writing IONS Projections on [Projection.txt] in sequence ..." -ForegroundColor Red
Write-Projection -XmlObject $XmlObject -SpinSet 1 -SkipNKPTS $ibzkpt -SkipSelectNBANDS $skipB, $NBANDS
Write-Host @"
 Done ✔: $([Math]::Round($($timer.Elapsed.TotalSeconds),3)) seconds elapsed.
"@
 -ForegroundColor Cyan
$timer.Stop() #close stopwatch
$tTotal = [Math]::Round($($timer.Elapsed.TotalSeconds + $loadtime), 3); 
Write-Host "The process completed in $tTotal seconds." -ForegroundColor Cyan
#Write Information of system only in Bands Folder
if ($getonlydos -eq $True) {
    Write-Host "Only first band is collected for -OnlyDOS switch!" -ForegroundColor Red
}
$infoFile = New-Item ./SysInfo.py  -Force #Create file
Write-Host "Writing System information on file [$($infoFile.BaseName)] ..." -ForegroundColor Yellow -NoNewline
$ElemIndex = $info.ElemIndex -Join ', '; $ElemName = $info.ElemName -Join ', '; #Elements Names and Indices Intervals
$infoString = @"
SYSTEM = `'$sys`'
NKPTS = $($NKPTS-$ibzkpt)
NBANDS = $NBANDS
NFILLED = $filled
TypeION = $($info.TypeION)
NION = $NION
NELECT = $($info.NELECT)
nField_Projection = $($info.nField_Projection)
E_Fermi = $($info.E_Fermi)
ISPIN = $($info.ISPIN)
ElemIndex = [$ElemIndex]
ElemName = [$ElemName]
fields = $($info.fields)
INCAR = dict(
    $($info.INCAR | ForEach-Object {"{0}{1},`n" -f $(' '*25),$_})
                    )
"@

$infoString | Set-Content $infoFile #Here-String written on file
# Crsytal System Information file.
$volume = $info.V
$basis = $info.Basis
$recbasis = $info.RecBasis
$poses = $info.Positions
$basis = $basis -join "],`n ["
$recbasis = $recbasis -join "],`n ["
$poses = $poses -join "],`n ["
$LatticeString = @"
volume = $($volume)
basis = [[$($basis)]]
rec_basis = [[$($recbasis)]]
positions = [[$($poses)]]
"@

$LatticeString | Add-Content $infoFile
#Writing of SysInfo Ends.
Write-Host " Done ✔😎😍✔"
Write-Host "▼ " -ForegroundColor Blue -NoNewline
Write-Host " SYSTEM: $sys, NIONS: $NION, NBANDS: $NBANDS, Filled: $filled, NKPTS: $($NKPTS-$ibzkpt)" -ForegroundColor White -BackgroundColor Blue


Write-Host "Files Generated: " -ForegroundColor Green -NoNewline
$listFiles = Get-ChildItem -Name *.txt
Write-Host $listFiles -Separator ' ' -ForegroundColor Yellow
#Done