Commit 9f2b5750 by Francois Gygi

added utility shell script


git-svn-id: http://qboxcode.org/svn/qb/trunk@1419 cba15fb0-1239-40c8-b417-11db7ca47a34
parent b7768b66
#!/bin/bash
# compute Egap = E(n+1) - E(n)
# use: egap.sh n file.r
declare -i nocc=$1
shift
declare -i nl=nocc/5+1
#echo "nl=" $nl
declare -i nfrac=nocc-5*\(nocc/5\)
#echo "nfrac=" $nfrac
grep -h -A$nl '<eigenvalues ' ${*}| \
awk -v nl=$nl -v nfrac=$nfrac \
' NR%(nl+2)==nl {e[0] = $5;} \
NR%(nl+2)==(nl+1) \
{ e[1]=$1; e[2]=$2; e[3]=$3; e[4]=$4; e[5]=$5; \
e_homo = e[nfrac]; e_lumo = e[nfrac+1]; \
print "E_HOMO=",e_homo, "E_LUMO=",e_lumo, "Eg=",e_lumo-e_homo}' -
#!/bin/bash
# get_atomset: extract atomset from a Qbox sample
#
# use: get_atomset sample.xml
#
nlines=$(grep /atomset -m 1 -n $1 | cut -f1 -d: - )
head -$nlines $1
echo "</fpmd:sample>"
#!/bin/bash
# get the largest force component in a file of "<force> fx fy fz </force>"
# use: qbox_maxforce nat file.r
grep '<force>' $2 | tail -$1 | \
awk '{
if ( mx*mx < $2*$2 ) mx = $2;
if ( my*my < $3*$3 ) my = $3;
if ( mz*mz < $4*$4 ) mz = $4;
} END {printf("%9.2e %9.2e %9.2e\n", mx, my, mz)}' -
#!/bin/bash
#
# qbox_replicate: replicate the unit cell in the a0,a1,a2 directions.
# use: qbox_replicate cell.sys n0 n1 n2 > newcell.sys
#
if (( $# != 4 ))
then echo "use: qbox_replicate cell.sys n0 n1 n2 > newcell.sys"
exit
fi
gawk -v n0=$2 -v n1=$3 -v n2=$4 \
' / cell/ {a0x=$3;a0y=$4;a0z=$5; \
a1x=$6;a1y=$7;a1z=$8; \
a2x=$9;a2y=$10;a2z=$11; \
print "set cell ", \
n0*$3,n0*$4,n0*$5, n1*$6,n1*$7,n1*$8, n2*$9,n2*$10,n2*$11} \
/ref_cell/ { \
print "set ref_cell ", \
n0*$3,n0*$4,n0*$5, n1*$6,n1*$7,n1*$8, n2*$9,n2*$10,n2*$11} \
/species/ {print} \
/atom/ {x=$4 - (n0-1)*a0x/2 - (n1-1)*a1x/2 - (n2-1)*a2x/2; \
y=$5 - (n0-1)*a0y/2 - (n1-1)*a1y/2 - (n2-1)*a2y/2; \
z=$6 - (n0-1)*a0z/2 - (n1-1)*a1z/2 - (n2-1)*a2z/2; \
for ( i=0; i<n0; i++ )
for ( j=0; j<n1; j++ )
for ( k=0; k<n2; k++ )
printf("atom %s_%d%d%d %s %12.6f %12.6f %12.6f\n", \
$2,i,j,k,$3, \
x+i*a0x+j*a1x+k*a2x, \
y+i*a0y+j*a1y+k*a2y, \
z+i*a0z+j*a1z+k*a2z) \
}' $1
#!/bin/bash
# qbox_translate: translate all atoms
# use: qbox_replicate cell.sys dx dy dz > newcell.sys
#
if (( $# != 4 ))
then echo "use: qbox_translate cell.sys dx dy dz > newcell.sys"
exit
fi
awk -v dx=$2 -v dy=$3 -v dz=$4 \
' /^#/ {print} \
/ cell/ {print} \
/ref_cell/ {print}
/species/ {print} \
/atom/ {x=$4 + dx; y=$5 + dy; z=$6 + dz; \
printf("atom %s %s %12.6f %12.6f %12.6f\n", \
$2,$3,x,y,z) \
}' $1
#!/bin/bash
# qbox_xyz.sh: get atomic positions from an MD simulation in xyz format
# use: qbox_xyz.sh mdrun.r > file.xyz
#
xsltproc - $1 << EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fpmd="http://www.quantum-simulation.org/ns/fpmd/fpmd-1.0">
<xsl:output method="text" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="//iteration/atomset"/>
</xsl:template>
<xsl:template match="iteration/atomset">
<xsl:value-of select="count(child::atom)"/> <xsl:text>
</xsl:text>
<xsl:number count="iteration"/> <xsl:text>
</xsl:text>
<xsl:apply-templates select="atom"/>
</xsl:template>
<xsl:template match="atom">
<xsl:variable name="sym" select="substring(@name,1,2)"/>
<xsl:variable name="symbol" select="translate(\$sym,'0123456789_-:.',' ')"/>
<xsl:value-of select="\$symbol"/> <xsl:text> </xsl:text>
<xsl:variable name="pos" select="normalize-space(position)"/>
<xsl:variable name="x" select="substring-before(\$pos,' ')"/>
<xsl:variable name="y" select="substring-before(substring-after(\$pos,' '),' ')"/>
<xsl:variable name="z" select="substring-after(substring-after(\$pos,' '),' ')"/>
<xsl:value-of select="\$x * 0.529177"/> <xsl:text> </xsl:text>
<xsl:value-of select="\$y * 0.529177"/> <xsl:text> </xsl:text>
<xsl:value-of select="\$z * 0.529177"/> <xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
EOF
#!/bin/bash
# sample_to_move.sh
# generate a set of Qbox commands to move atoms to the positions
# in a given sample.
# use: sample_to_move.sh sample.xml
#
xsltproc - $1 << EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fpmd="http://www.quantum-simulation.org/ns/fpmd/fpmd-1.0">
<xsl:output method="text" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/fpmd:sample">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="atomset">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="atom">
<xsl:text>move </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text> to </xsl:text>
<xsl:value-of select="position"/> <xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
EOF
#!/bin/bash
# sample_to_sys.sh: extract atomic positions from a sample and generate
# a Qbox input file to create atoms at these positions
# use: sample_to_sys.sh sample.xml > sample.sys
#
xsltproc - $1 << EOF
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fpmd="http://www.quantum-simulation.org/ns/fpmd/fpmd-1.0">
<xsl:output method="text" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/fpmd:sample">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="atomset">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="unit_cell">
<xsl:text>set cell </xsl:text>
<xsl:value-of select="@a"/> <xsl:text> </xsl:text>
<xsl:value-of select="@b"/> <xsl:text> </xsl:text>
<xsl:value-of select="@c"/> <xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="species">
<xsl:text>species </xsl:text>
<xsl:value-of select="@name"/> <xsl:text> </xsl:text>
<xsl:value-of select="@href"/> <xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="atom">
<xsl:text>atom </xsl:text>
<xsl:value-of select="@name"/> <xsl:text> </xsl:text>
<xsl:value-of select="@species"/> <xsl:text> </xsl:text>
<xsl:value-of select="position"/> <xsl:text> </xsl:text>
<xsl:value-of select="velocity"/> <xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
EOF
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment