| 1 | #!@PYTHON@
|
|---|
| 2 | #
|
|---|
| 3 | # converts mpqc hessian output files to pcp.hessian_{xx,xy,..,zz}.all for joiner/analyzer to work on
|
|---|
| 4 |
|
|---|
| 5 | import sys, string, math
|
|---|
| 6 | wrout = sys.stdout.write
|
|---|
| 7 | wrerr = sys.stdout.write
|
|---|
| 8 |
|
|---|
| 9 | if len(sys.argv) < 3:
|
|---|
| 10 | wrerr("Usage: "+sys.argv[0]+" <configbase> <prefix>\n")
|
|---|
| 11 | sys.exit(1)
|
|---|
| 12 |
|
|---|
| 13 | #output = open(sys.argv[1]+".out", "r")
|
|---|
| 14 | #config = open(sys.argv[1]+".conf", "r")
|
|---|
| 15 |
|
|---|
| 16 | # 1. parse symmetrically stored data into list
|
|---|
| 17 | input = open(sys.argv[1]+".hess", "r")
|
|---|
| 18 | comment = input.readline()
|
|---|
| 19 | atomline = input.readline()
|
|---|
| 20 | atoms = string.split(atomline)
|
|---|
| 21 | NoAtom = int(atoms[0])
|
|---|
| 22 | for i in range(0,NoAtom): # skip nuclear coordinates
|
|---|
| 23 | testline = input.readline()
|
|---|
| 24 | hessianlist = []
|
|---|
| 25 | NoValues=0
|
|---|
| 26 | for line in input:
|
|---|
| 27 | if "End Hessian" in line:
|
|---|
| 28 | break
|
|---|
| 29 | else:
|
|---|
| 30 | values = string.split(line)
|
|---|
| 31 | for i in range(len(values)):
|
|---|
| 32 | NoValues = NoValues+1
|
|---|
| 33 | hessianlist.append(float(values[i]))
|
|---|
| 34 | input.close()
|
|---|
| 35 | print "I scanned "+str(NoValues)+" entries in the symmetric matrix for "+atoms[0]+" atoms. First value is "+str(hessianlist[0])+"."
|
|---|
| 36 |
|
|---|
| 37 | # 2. Create full hessian matrix
|
|---|
| 38 | hessianmatrix = []
|
|---|
| 39 | NoValues=0
|
|---|
| 40 | for i in range(3*NoAtom): # row index
|
|---|
| 41 | for j in range(i+1): # column index
|
|---|
| 42 | #print "["+str(3*NoAtom*i+j)+"] = ["+str(hessianlist[NoValues])+"]."
|
|---|
| 43 | hessianmatrix.append(hessianlist[NoValues])
|
|---|
| 44 | NoValues = NoValues+1
|
|---|
| 45 | for j in range(i+1,3*NoAtom):
|
|---|
| 46 | #print "["+str(3*NoAtom*i+j)+"] = [0]."
|
|---|
| 47 | hessianmatrix.append(0)
|
|---|
| 48 | for i in range(3*NoAtom): # row index
|
|---|
| 49 | for j in range(i+1,3*NoAtom): # column index
|
|---|
| 50 | NoValues = NoValues+1
|
|---|
| 51 | index=j+3*NoAtom*i
|
|---|
| 52 | index2=i+3*NoAtom*j
|
|---|
| 53 | hessianmatrix[index]=hessianmatrix[index2]
|
|---|
| 54 | print "I created the full hessian matrix from the symmetric one with a total of "+str(NoValues)+" entries."
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 | # 3. store 9 (NoAtom x NoAtom)-matrices (xx,xy,...,zz)
|
|---|
| 58 | textlist = [ "xx", "xy", "xz", "yx", "yy", "yz", "zx", "zy", "zz" ]
|
|---|
| 59 | for i in range(3): # row index
|
|---|
| 60 | for j in range(3): # column index
|
|---|
| 61 | wrout("Storing "+str(NoAtom)+"x"+str(NoAtom)+" matrix "+textlist[3*i+j]+" to file "+sys.argv[2]+".hessian_"+textlist[3*i+j]+".all ... ")
|
|---|
| 62 | output=open(sys.argv[2]+".hessian_"+textlist[3*i+j]+".all", "w")
|
|---|
| 63 | #print >>output,"# hessian matrix with "+str(NoAtom)+" by "+str(NoAtom)+" entries"
|
|---|
| 64 | output.write("# ")
|
|---|
| 65 | for m in range(NoAtom): # row index
|
|---|
| 66 | output.write("Atom"+str(m+1)+"\t")
|
|---|
| 67 | output.write("\n")
|
|---|
| 68 | for m in range(NoAtom): # row index
|
|---|
| 69 | for n in range(NoAtom): # column index
|
|---|
| 70 | #index = (3*NoAtom)*((NoAtom*i)+m) + (NoAtom*j)+n
|
|---|
| 71 | index = (3*NoAtom)*(i+(3*m)) + (j+(3*n))
|
|---|
| 72 | output.write("%f\t" % (hessianmatrix[index]))
|
|---|
| 73 | output.write("\n")
|
|---|
| 74 | wrout("done.\n")
|
|---|
| 75 |
|
|---|
| 76 | print "Everything is converted."
|
|---|