source: util/src/convertMPQCout2pcp.py.in@ c03ca6

Last change on this file since c03ca6 was e1a46d, checked in by Frederik Heber <heber@…>, 16 years ago

All of my python script put into ESPACK and adapted with @PYTHON@ and so on.

  • Property mode set to 100755
File size: 3.6 KB
Line 
1#!@PYTHON@
2#
3# converts mpqc output files to pcp.energy.all, pcp.forces.all and pcp.speed for joiner/analyzer to work on
4
5import sys, string, re, math
6wrerr = sys.stderr.write
7
8if len(sys.argv) < 3:
9 wrerr("Usage: "+sys.argv[0]+" <configbase> <prefix>\n")
10 sys.exit(1)
11
12output = open(sys.argv[1]+".conf.out", "r")
13config = open(sys.argv[1]+".conf", "r")
14energy = open(sys.argv[2]+".energy.all", "w")
15forces = open(sys.argv[2]+".forces.all", "w")
16speed = open(sys.argv[2]+".speed", "w")
17
18# prepare the headers
19print >>energy,"Time\t\tTotal"
20print >>forces,"Type\tNo\t\tPos0\t\tPos1\t\tPos2\t\tTotal0\t\tTotal1\t\tTotal2"
21print >>speed,"\nMaxG[] = nA nA nA -> N[] = nA nA nA"
22print >>speed,"LevNo MaxG RMaxG MaxN N[0] N[1] N[2] RLevSStep"
23print >>speed,"0 5147691 10295381 25165824 384 256 256 0"
24print >>speed,"1 643665 1287329 3145728 192 128 128 267"
25print >>speed,"2 80442 160883 393216 96 64 64 267"
26print >>speed,"3 10074 20147 49152 48 32 32 333"
27print >>speed,"4 1264 2527 6144 24 16 16 862"
28print >>speed,"procs proc[0] proc[1] PsiMax PsiDoub PsiUp PsiDown NRStep TotalIons"
29print >>speed,"1 1 1 $Psi $Psi+0 0+0 0+0 1 $nr"
30
31# parse the config file
32nr=0
33limit=0
34for line in config:
35 nr=nr+1
36 if "# ====== MD step" in line:
37 limit=nr
38config.seek(0)
39#print "Beginning with line %d ..." % (limit)
40n=0
41nr=0
42atompos = []
43for line in config:
44 nr=nr+1
45 #print "%d > %d ?" % (limit, nr)
46 if limit > nr:
47 continue
48 #print "%d: %s" % (nr,line)
49 if re.compile("Ion_Type[0-9]+[_]+").match(line):
50 words = line.split("Type")
51 words2 = (words[0]+"Type_"+words[1]).split()
52 #print words2
53 #print words
54 atompos.append(words2[0]+"_"+words2[1]+"_"+words2[2]+"_"+words2[3])
55 n=n+1
56print "I found ",n," atoms."
57
58if n == 0:
59 wrerr("Quitting.\n")
60 sys.exit(1)
61
62# parse the output file for ...
63line = output.readline()
64EnergyWritten = 0
65while (line != ''):
66 # energy
67 if "total scf energy" in line:
68 if EnergyWritten == 0:
69 words = line.split()
70 #print words
71 print >>energy,"0.000000e+00\t",words[4]
72 EnergyWritten = 1
73 # forces
74 if "Total Gradient:" in line:
75 #print "found gradient"
76 mean=0.
77 for i in range(n):
78 line = output.readline()
79 words = line.split()
80 atome = atompos[i].split("_")
81 #print atome
82 #print words
83 print >>forces,"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s" % ( (int(atome[2])-1),(int(atome[3])-1),atome[4],atome[5],atome[6],words[2],words[3],words[4] )
84 mean += math.sqrt(math.pow(float(words[2]),2)+math.pow(float(words[3]),2)+math.pow(float(words[4]),2))
85 print >>forces,"MeanForce:\t",mean/n
86 # speed
87 if "mpqc:" in line:
88 types=["Types"]
89 cpu=["CPU"]
90 wall=["Wall"]
91 for i in range(25):
92 words = line.split(":")
93 times = words[1].split()
94 types.append(words[0])
95 cpu.append(times[0])
96 wall.append(times[1])
97 line = output.readline()
98 for j in range(25):
99 types[j] = types[j].replace('_', '') # TeX does not like underscores in non-math env
100 speed.write(types[j]+"\t")
101 speed.write("\n")
102 for j in range(25):
103 speed.write(cpu[j]+"\t")
104 speed.write("\n")
105 for j in range(25):
106 speed.write(wall[j]+"\t")
107 speed.write("\n")
108 line = output.readline()
Note: See TracBrowser for help on using the repository browser.