Cpmd2fhi Pl
#!/usr/bin/perl

# convert CPMD-style psudopotentials into FHI-style format
# jschrier@haverford.edu, 13 June 02011

# CPMD format has potential, wavefunction, etc. separated
# ref: http://radio.wihome.net/wiki/?article=Description_of_the_CPMD_pseudopotential_format

# whereas the FHI-style format groups each channel together
#http://www.fhi-berlin.mpg.de/th/fhi98md/doc/main/node7.html  (see fig2.2)

my (@channelPre, @channelPot);

$r=-1;
$rPrev=-1;
$rRatio = -1;
@channelOut=('','','','');

while ($_=<STDIN>) {
    if (/\&POTENTIAL/) {
        open (R,">r.tmp") || die;
        open (L0,">l0.tmp") || die;
        open (L1,">l1.tmp") || die;
        open (L2,">l2.tmp") || die;
        open (L3,">l3.tmp") || die;
        chomp($nLines= <STDIN>);
        foreach my $i (1..$nLines) {
            chomp($_=<STDIN>);
            $_ =~ s/^\s+//;
            $rPrev=$r;
            ($r,$l0,$l1,$l2,$l3)=split(/\s+/,$_);
            print R " $i  $r\n";
            print L0 "$l0\n";
            print L1 "$l1\n";
            print L2 "$l2\n";
            print L3 "$l3\n";
        }
        close(R);
        close(L0);
        close(L1);
        close(L2);
        close(L3);
        $rRatio = $r/$rPrev;
    }

    if (/\&WAVEFUNCTION/) {
        $_=<STDIN>;   # assume that this works; tis would be a good place for a sanity check though;
        open (R,"<r.tmp") || die;
        open (L0,"<l0.tmp") || die;
        open (L1,"<l1.tmp") || die;
        open (L2,"<l2.tmp") || die;
        open (L3,"<l3.tmp") || die;

        foreach my $i (1..$nLines) {
            chomp($_=<STDIN>);
            $_ =~ s/^\s+//;

            ($r,$l0,$l1,$l2,$l3)=split(/\s+/,$_);
            chomp($foo = <R>);
            $bar = <L0>;
            $channelOut[0] .= "$foo $l0 $bar";
            $bar = <L1>;
            $channelOut[1] .= "$foo $l1 $bar";
            $bar = <L2>;
            $channelOut[2] .= "$foo $l2 $bar";
            $bar = <L3>;
            $channelOut[3] .= "$foo $l3 $bar";
        }
        close(R);
        close(L0);
        close(L1);
        close(L2);
        close(L3);
        system("rm r.tmp");
        system("rm l0.tmp");
        system("rm l1.tmp");
        system("rm l2.tmp");
        system("rm l3.tmp");
    }
}

foreach my $i (0..3) {
    printf STDOUT "$nLines  %10.8E\n", $rRatio;
    print STDOUT $channelOut[$i];
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License