[Wannier] Scripts

Rok Zitko rok.zitko at ijs.si
Wed Mar 17 10:09:07 CET 2010


Hi,

I have some perl scripts for extracting the cell parameters and atomic
positions. "extract_cell_structure" reads cell parameter 'a' from
a pwscf input file ("cublock.in", hardcoded) and the rest of the data
from the output file ("cublock.out", also hardcoded).
To include the resulting files in the .win input file, I then use m4
macro processor on a .win.m4 file containing a block

begin unit_cell_cart
ang
include(`unit_cell.dat')dnl
end unit_cell_cart

begin atoms_cart
ang
include(`atoms_cart.dat')dnl
end atoms_cart

I hope this might be of some use..

Regards,
Rok



extract_cell_structure
======================


#!/usr/bin/env perl
# Extract cell parameters [cartesian, a.u.] and atomic positions
# Rok Zitko, rok.zitko at ijs.si, Jan 2010

use warnings;

# In Ang! Copy from a= in the input file for pwscf.
$a0 = `getparam2 a cublock.in`;
chomp($a0);

print "a0=$a0\n";

$fn = "cublock.out";

open(F, "<$fn") or die "Can't open $fn";

$fn = "unit_cell.dat";
open(U, ">$fn") or die "Can't open $fn";

$fn = "atoms_cart.dat";
open(A, ">$fn") or die "Can't open $fn";

while(<F>) {
    if (/a\([1-3]\) = \(\s+(\S+)\s+(\S+)\s+(\S+)/) {
	$x = $1 * $a0;
	$y = $2 * $a0;
	$z = $3 * $a0;
	print U "$x $y $z\n";
    } elsif (/(\S+)\s+tau\([0-9 ][0-9 ][0-9 ]\) = \(\s+(\S+)\s+(\S+)\s
+(\S+)\s/) {
	$x = $2 * $a0;
	$y = $3 * $a0;
	$z = $4 * $a0;
	print A "$1 $x $y $z\n";
    }	
	
}

close A;
close U;
close F;


getparam2
=========

#!/usr/bin/env perl
# Extract a parameter from 'param' file
# Rok Zitko, rok.zitko at ijs.si, April 2008

if (@ARGV != 1 && @ARGV != 2) {
    die "Usage: getparam <keyword> [param filename]\n";
}

my $keyword = $ARGV[0];

my $fn;
if (@ARGV == 1) {
    $fn = "param";
} else {
    $fn = $ARGV[1];
}

open (F, "<$fn") or die "Can't open $fn for reading: $!\n";

while (<F>) {
    if (/^\s+$keyword\s+=\s+(.*)/) {
	print "$1\n";
    }
}

close(F);





-- 
Rok Zitko
Institut Jozef Stefan, Jamova 39, SI-1001 Ljubljana, Slovenija
Tel.: +386-1 477 3190   Fax.: +386-1 2519 385, +386-1 426 3269
rok.zitko at ijs.si, http://auger.ijs.si/nano/





More information about the Wannier mailing list