Added a tool to convert ibrav/celldm to lattice vectors (not so useful) and another to convert the lattice vectors (in bohr or angstrom) to ibrav/celldm

Added documentation, sort of, for all the tools (README)

Does anybody know if bs.awk and mv.awk are used for anything, or can understand what they do?



git-svn-id: http://qeforge.qe-forge.org/svn/q-e/trunk/espresso@13419 c92efa57-630b-4861-b058-cf58834340f0
This commit is contained in:
paulatto 2017-03-21 21:29:27 +00:00
parent 0c6aa7ed23
commit b5f0d1361b
4 changed files with 251 additions and 1 deletions

View File

@ -13,13 +13,18 @@ TLDEPS= bindir mods libs pw libfft libla
LIBOBJS = ../../clib/clib.a ../../iotk/src/libiotk.a
all : tldeps dist.x ev.x kpoints.x pwi2xsf.x
all : tldeps dist.x ev.x kpoints.x pwi2xsf.x ibrav2cell.x
dist.x : dist.o $(PWOBJS) $(QEMODS) $(LIBOBJS)
$(LD) $(LDFLAGS) -o $@ \
dist.o $(PWOBJS) $(QEMODS) $(LIBOBJS) $(LIBS)
- ( cd ../../bin ; ln -fs ../PW/tools/$@ . )
ibrav2cell.x : ibrav2cell.o $(PWOBJS) $(QEMODS) $(LIBOBJS)
$(LD) $(LDFLAGS) -o $@ \
ibrav2cell.o $(PWOBJS) $(QEMODS) $(LIBOBJS) $(LIBS)
- ( cd ../../bin ; ln -fs ../PW/tools/$@ . )
ev.x : ev.o ev_xml.o $(PWOBJS) $(QEMODS) $(LIBOBJS)
$(LD) $(LDFLAGS) -o $@ \
ev.o ev_xml.o $(PWOBJS) $(QEMODS) $(LIBOBJS) $(LIBS)

36
PW/tools/README Normal file
View File

@ -0,0 +1,36 @@
A collection of simple tools for specific tasks:
ev.x :
Run interatively. It reads a file containing 2 columns: lattice parameter and
corresponding total energy, it gives in output optimized lattice parameter,
bulk modulus and more.
Contributions by Eyvaz Isaev
dist.x :
Same input as pw.x, find distances, nearest neighbors, angles
taking into account periodicity
ibrav2cell.x :
read a &system namelist containing only ibrav and celldm(1..6) (same meaning as in pw.x and cp.x)
prints on standard output the unit cell in Bohr
cell2ibrav.py :
python script that takes a unit cell in Bohr or Angstrom units and find the value
of ibrav and celldm(1..6) that generate it. Run 'cell2ibrav.py -h' for help.
(it works in the stupidest way possible, by checking all of them, it uses ibrav2cell.x)
pwi2xsf.sh, pwo2xsf.sh :
convert a pw.x input or output to the xcrysden format
qeout2axsf.sh :
convert pw.x output to aniimated xcrysden file
cif2qe.sh :
generate a pw.x format from the crystal structure in a cif file
castep2qe.sh :
convert a CASTEP input to pw.x
md_analyzer.sh :
it reads the pw.x output of an md run and prints, for each step, total, kinetic and potential energies, and temperature

177
PW/tools/cell2ibrav.py Executable file
View File

@ -0,0 +1,177 @@
#!/usr/bin/python
from os.path import realpath
from sys import argv
binary=realpath(__file__)
#myself=argv[0].replace("./","")
binary = binary.replace("cell2ibrav.py","ibrav2cell.x")
#print binary
binary = "/home/paulatto/espresso/bin/ibrav2cell.x"
def main() :
from numpy import array
from argparse import ArgumentParser
parser = ArgumentParser()
#parser.add_argument('-t', type=str, default="pbtex", dest="type_cal")
#parser.add_argument('-n', type=int, default=1, dest="n_random")
#parser.add_argument('-d', type=str, default="./", dest="data_dir")
#parser.add_argument('-p', type=int, default=1, dest="population")
#parser.add_argument('-f', type=str, default="2x2_dynq", dest="fildyn_prefix_harmonic")
##parser.add_argument('--e0', type=float, default=0., dest="e0")
#parser.add_argument('--nq', type=int, default=[3, 2, 2, 2], nargs=4, dest="nq",
#metavar=("NQ_irr","NQ_x","NQ_y","NQ_z"))
#parser.add_argument('--const', action='append', type=str, metavar="par=value", default=[])
#parser.add_argument(metavar='par', type=str, nargs='*', default=["p3", "p4"], dest="parameters",
#help="name of the parameters to minimize." )
parser.add_argument('-i', action='append', type=int, metavar="ibrav", dest="ibrav_list", default=[],
help="ibrav value to explore, can be repeated (default: all)")
parser.add_argument('-c', type=float, default=[0, 0, 0, 0, 0, 0, 0, 0, 0], nargs=9, dest="at",
metavar=("a1x","a1y","a1z","a2x","a2y","a2z", "a3x", "a3y", "a3z"),
help="cell parameters (default: read from standard input)")
parser.add_argument('-A', default=False, action="store_true", dest="angst", help="cell is entered in Agstrom units (default: bohr")
parser.add_argument('--celldm', type=float, default=[1, 1, 1, 0.5, 0.5, 0.5], nargs=6, dest="celldm",
metavar=("1","2","3","4","5","6"), help="initial values of celldm(1..6), you have to specify all 6 (default: '1 0 0 0 0 0')")
parser.add_argument('-t', type=float, default=1.e-3, dest="mthr", help="match threshold", metavar="THR")
parser.add_argument('-k', type=float, default=1.e-15, dest="kthr", help="convergence threshold", metavar="THR")
parser.add_argument('-x', type=str, dest="binary", help="full path to the ibrav2cell.x tool from PW/tools/ (default: look in the same directory as this program)", metavar="/path/to/ibrav2cell.x")
args = parser.parse_args()
ibrav_list = [1,2,3,4,5,-5,6,7,8,9,-9,10,11,12,-12,13,14]
if args.ibrav_list == []:
args.ibrav_list = ibrav_list
#print args
if args.binary:
global binary
binary = args.binary
# cell = [ 3.900896593574796, -2.252183691403927, 18.043044401344225,
# 0.000000000000000, 4.504367382807855, 18.043044401344225,
# -3.900896593574796, -2.252183691403927, 18.043044401344225]
# cell = [ 1.200000000000000E+01, 0.000000000000000E+00, 0.000000000000000E+00,
# 1.224000000000000E+01, 7.585670702053973E+00, 0.000000000000000E+00,
# 7.979999999999999E+00, 1.474991525399383E+00, 2.168870673876157E+00]
cell = args.at
if all(array(cell) == 0) :
cell = cell_stdin()
if args.angst:
cell = array(cell)*1.889725989
bnds = ((0,None), (0,None), (0,None), (-1,1), (-1,1), (-1,1))
for ibrav in args.ibrav_list:
p=args.celldm #[1,1,1,0.5,0.5,0.5]
options = { "ibrav" : ibrav,
"cell" : cell
}
from scipy.optimize import minimize
from scipy.optimize import basinhopping
#r = basinhopping(recompute, p, minimizer_kwargs={"args":tuple([options])}, niter=10, bounds=bnds)
r = minimize(recompute, p, args=tuple([options]), method="L-BFGS-B", tol=args.kthr, bounds=bnds)
if r["fun"] < args.mthr:
print "match found: ibrav =", ibrav
check_zero(r["x"], ibrav)
#print make_namelist(ibrav,r["x"])
def run_command(executable_file, input_data):
import subprocess
proc = subprocess.Popen(executable_file,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
output, error = proc.communicate(input_data)
return (output, error)
def make_namelist(ibrav,p):
replacements = { "ibrav" : ibrav,
"celldm1" : p[0],
"celldm2" : p[1],
"celldm3" : p[2],
"celldm4" : p[3],
"celldm5" : p[4],
"celldm6" : p[5]
}
systemnl = """
&system
ibrav = {ibrav},
celldm(1) ={celldm1},
celldm(2) ={celldm2},
celldm(3) ={celldm3},
celldm(4) ={celldm4},
celldm(5) ={celldm5},
celldm(6) ={celldm6}
/
"""
return systemnl.format(**replacements)
def constraint(p):
result = all(p[0:3]>=0)
result = result and all(abs(p[4:7])<=1)
if result:
return 0
else:
return 1
def cell_stdin():
import fileinput
from sys import argv
print "Type '{} -h' for help".format(argv[0])
print
print "Please enter cell parameters: "
at = []
for line in fileinput.input():
for w in map(float, line.split()):
at.append(w)
if(len(at)>=9) :
print " ------------------------ok"
return at
def compute_cell(namelist):
from numpy import isnan
output,error = run_command(binary,namelist)
try:
at = map(float, output.split())
except ValueError:
at = [0,0,0, 0,0,0, 0,0,0]
if any(isnan(at)):
at = [0,0,0, 0,0,0, 0,0,0]
return at
def check_zero(p, ibrav):
from numpy import array
from numpy.linalg import norm
namelist = make_namelist(ibrav,p)
at0 = array(compute_cell(namelist))
p_out=list(p)
for i in range(len(p)):
q = list(p)
q[i] = 0
namelist = make_namelist(ibrav,q)
at1 = array(compute_cell(namelist))
if norm(at0-at1)==0:
p_out[i] = 0
else:
print " celldm({:d}) = {:.6f}".format(i+1, p[i])
return array(p_out)
def recompute(p, options):
from numpy import array
from numpy.linalg import norm
namelist = make_namelist(options["ibrav"],p)
at = compute_cell(namelist)
at1 = array(at)
at0 = array(options["cell"])
return norm(at1-at0)
main()

32
PW/tools/ibrav2cell.f90 Normal file
View File

@ -0,0 +1,32 @@
!
! Copyright (C) 2014 Quantum ESPRESSO group
! This file is ibrav2cellributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present ibrav2cellribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!----------------------------------------------------------------------
PROGRAM ibrav2cell
!----------------------------------------------------------------------
!
USE Kinds, ONLY : DP
!
IMPLICIT NONE
INTEGER :: ibrav
REAL(DP) :: celldm(6)
!
REAL(DP) :: at(3,3), omega, alat
!
NAMELIST /system/ ibrav, celldm
READ(*,system)
CALL latgen( ibrav, celldm, at(:,1), at(:,2), at(:,3), omega )
! at=at/celldm(1)
! CALL recips(at(:,1), at(:,2), at(:,3), bg(:,1), bg(:,2), bg(:,3))
!WRITE(*,'(a)') "Unit cell (bohr):"
WRITE(*,'(3es24.15)') at(:,1)
WRITE(*,'(3es24.15)') at(:,2)
WRITE(*,'(3es24.15)') at(:,3)
!WRITE(*,'(a,es24.15)') "Volume (bohr^3):", omega
!
END PROGRAM ibrav2cell
!----------------------------------------------------------------------