File: gen_test_params.py

package info (click to toggle)
espresso 6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,068 kB
  • sloc: f90: 447,429; ansic: 52,566; sh: 40,631; xml: 37,561; tcl: 20,077; lisp: 5,923; makefile: 4,503; python: 4,379; perl: 1,219; cpp: 761; fortran: 618; java: 568; awk: 128
file content (67 lines) | stat: -rw-r--r-- 3,021 bytes parent folder | download | duplicates (3)
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
from __future__ import print_function
import re, sys

info = """
This script collects the relevant simulation parameters and generates a 
set of input options for `fft_test.x` that replicate the execution of
vloc_psi done in the production run.
This simplifies the identification of the optimal fft tasking paramete.

Usage: python run_test.py pw_out_file
"""

match_alat = re.compile(r'lattice parameter \(alat\)\s+=\s+([+-]?([0-9]*[.])?[0-9]+)')
match_nbnd = re.compile(r'number of Kohn-Sham states=\s+([+-]?([0-9]*[.])?[0-9]+)')
match_ecutwfc = re.compile(r'kinetic-energy cutoff\s+=\s+([+-]?([0-9]*[.])?[0-9]+)')
match_ecutrho = re.compile(r'charge density cutoff\s+=\s+([+-]?([0-9]*[.])?[0-9]+)')
match_k = re.compile(r'number of k points=\s+(\d+)')


if __name__ == "__main__":
    if len(sys.argv) <= 1:
        print(info)
    else:
        with open(sys.argv[1],'r') as f:
            data = f.read(30000)
            gamma = False
            maxk = ''
            alat = match_alat.findall(data)
            nbnd = match_nbnd.findall(data)
            ewfc = match_ecutwfc.findall(data)
            erho = match_ecutrho.findall(data)
            if len(alat[0]) == 0 or len(nbnd[0]) == 0 or len(ewfc[0]) == 0 or len(erho[0]) == 0:
                print("Could not parse file. Sorry.")
            alat = alat[0][0]; nbnd=nbnd[0][0]; ewfc=ewfc[0][0];erho=erho[0][0]
            a1 = []
            a2 = []
            a3 = []
            lines = data.splitlines()
            for i, line in enumerate(lines):
                if 'gamma-point specific algorithms are used' in line:
                    gamma = True
                if 'crystal axes' in line:
                    a1 = [float(x)*float(alat) for x in lines[i+1].split()[3:6]]
                    a2 = [float(x)*float(alat) for x in lines[i+2].split()[3:6]]
                    a3 = [float(x)*float(alat) for x in lines[i+3].split()[3:6]]
                if 'number of k points' in line:
                    nk = int(match_k.findall(line)[0])
                    if '2pi/alat' in lines[i+1]:
                        nrm2 = 0
                        for k in range(nk):
                            kn, v = re.findall(r"\(([-\d\s\.]*)\)", lines[i+k+2])
                            v2 = [float(x)**2 for x in v.split()]
                            if sum(v2) > nrm2:
                                maxk=v
                    
            print ("To analize performances run with:")
            buf = ("mpirun -np X ./fft_test.x -ntg Y -ecutwfc {ewfc} -ecutrho {erho} " + \
                  "-av1 {av1} -av2 {av2} -av3 {av3} -nbnd {nbnd} -gamma {gamma}").format(\
                       ewfc=ewfc, erho=erho, \
                       av1=' '.join([str(x) for x in a1]), \
                       av2=' '.join([str(x) for x in a2]), \
                       av3=' '.join([str(x) for x in a3]), \
                       nbnd=nbnd, gamma=('.true.' if gamma else '.false.'))
            if maxk:
                buf += " -kmax "+maxk
            print(buf)