source: util/src/AnalyseStressResults.py.in@ e1a46d

Last change on this file since e1a46d 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: 2.2 KB
Line 
1#!@PYTHON@
2#
3# Creates an Analysis matrix for a number of nanotubes (n,m) with stress files
4
5import sys, random, math
6wrout = sys.stdout.write
7wrerr = sys.stdout.write
8
9# check arguments
10if len(sys.argv) < 2:
11 print "Usage: "+sys.argv[0]+" <input> <output>"
12 sys.exit(1)
13
14if sys.argv[1] in sys.argv[2]:
15 print "Please state two different files!"
16 sys.exit(1)
17input = open(sys.argv[1], "r")
18output = open(sys.argv[2], "w")
19
20# parse lines into array
21chiralities=[ ]
22runs=[ ]
23defects=[ ]
24values=[ ]
25for line in input:
26 if "#" in line:
27 continue
28 entries=line.split()
29 if not entries[0] in chiralities:
30 chiralities.append(entries[0])
31 if not entries[1] in runs:
32 runs.append(entries[1])
33 if not entries[2] in defects:
34 defects.append(entries[2])
35 values.append([entries[0], entries[1], entries[2], entries[3:]])
36 for n in range(len(values[-1])):
37 wrout("%s\t" % (values[-1][n]))
38 wrout("\n")
39input.close()
40
41# sum values
42avg_values=[ ]
43for i in range(len(values)):
44 if (values[i][1] == runs[0]):
45 tmp=[ ]
46 for j in range(len(values[i][3])): # create array initialised to 0
47 tmp.append(0.)
48 avg_values.append([values[i][0],values[i][2],tmp[:]])
49 # look for corresponding index to i in avg_value
50 j=0
51 while (j < len(avg_values)):
52 if ((avg_values[j][0] == values[i][0]) and (avg_values[j][1] == values[i][2])):
53 break
54 j+=1
55 if j < len(avg_values):
56 for n in range(len(values[i][3])/2):
57 avg_values[j][2][2*n]+=float(values[i][3][2*n]) # value
58 avg_values[j][2][2*n+1]+=float(values[i][3][2*n+1])*float(values[i][3][2*n+1]) # value
59 else:
60 wrerr("Cannot sort in values for %s, %s, %s!\n" % (values[i][0], values[i][1], values[i][2]))
61
62# output values
63oldm=-1
64output.write("#n\tm\tdefect\tPoss\tError\tYoungPot\tError\tYoungLag\tError\tPossLag\tError\tYoungLog\tError\tPossLog\tError\tEModulus\tError\n")
65for i in range(len(avg_values)):
66 chiral=avg_values[i][0].split("-")
67 if oldm != chiral[1]:
68 if oldm != -1:
69 output.write("\n\n")
70 oldm=chiral[1]
71 output.write("%s\t%s\t%s\t" % (chiral[0],chiral[1],avg_values[i][1]))
72 for n in range(0,len(avg_values[i][2])/2):
73 output.write("%s\t%s\t" % (avg_values[i][2][2*n]/len(runs),math.sqrt(avg_values[i][2][2*n+1])))
74 output.write("\n")
75output.close()
76
Note: See TracBrowser for help on using the repository browser.