[e1a46d] | 1 | #! @PYTHON@
|
---|
| 2 | #
|
---|
| 3 | # calculates the density via elements.db
|
---|
| 4 |
|
---|
| 5 | exec_prefix="@prefix@"
|
---|
| 6 | ELEMENTSDB=exec_prefix+"/bin/elements.db"
|
---|
| 7 | import sys, string, re, math
|
---|
| 8 | wrerr = sys.stderr.write
|
---|
| 9 | wrout = sys.stdout.write
|
---|
| 10 |
|
---|
| 11 | # check for parameters
|
---|
| 12 | if len(sys.argv) < 4:
|
---|
| 13 | wrerr("Usage: "+sys.argv[0]+" <datafile> <offsetToElement> <offsetToXYZ\n")
|
---|
| 14 | sys.exit(1)
|
---|
| 15 |
|
---|
| 16 | offset=int(sys.argv[2])
|
---|
| 17 | offsetXYZ=int(sys.argv[3])
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | # parse elements symbol and mass into hash list
|
---|
| 21 | print "Parsing elements db at "+ELEMENTSDB
|
---|
| 22 | elementfile=open(ELEMENTSDB,"r")
|
---|
| 23 | elements={}
|
---|
| 24 | for line in elementfile:
|
---|
| 25 | if "#" in line:
|
---|
| 26 | continue
|
---|
| 27 | entries=line.split()
|
---|
| 28 | if len(entries) > 6:
|
---|
| 29 | elements[entries[1]]=float(entries[6])
|
---|
| 30 | else:
|
---|
| 31 | print "Not parsed: "+line
|
---|
| 32 | elementfile.close()
|
---|
| 33 |
|
---|
| 34 | # go through given data file and sum up
|
---|
| 35 | inputfile=open(sys.argv[1],"r")
|
---|
| 36 | weight=0.
|
---|
| 37 | min=[0., 0., 0.]
|
---|
| 38 | max=[0., 0., 0.]
|
---|
| 39 | for line in inputfile:
|
---|
| 40 | if "#" in line:
|
---|
| 41 | continue
|
---|
| 42 | entries=line.split()
|
---|
| 43 | if weight == 0.:
|
---|
| 44 | for i in range(3):
|
---|
| 45 | min[i]=float(entries[offsetXYZ+i])
|
---|
| 46 | max[i]=float(entries[offsetXYZ+i])
|
---|
| 47 | else:
|
---|
| 48 | for i in range(3):
|
---|
| 49 | if (min[i] > float(entries[offsetXYZ+i])):
|
---|
| 50 | min[i]=float(entries[offsetXYZ+i])
|
---|
| 51 | if (max[i] < float(entries[offsetXYZ+i])):
|
---|
| 52 | max[i]=float(entries[offsetXYZ+i])
|
---|
| 53 | weight += elements[entries[offset]]
|
---|
| 54 | inputfile.close()
|
---|
| 55 |
|
---|
| 56 | volume=1.
|
---|
| 57 | wrout("Bounds are ")
|
---|
| 58 | for i in range(3):
|
---|
| 59 | wrout("[%g, %g]\t" % (min[i], max[i]))
|
---|
| 60 | volume=volume*(max[i]-min[i])
|
---|
| 61 | wrout("\n")
|
---|
| 62 | print "Total Volume of bounding box is "+str(volume)+" angstrom^3."
|
---|
| 63 | print "Total weight is "+str(weight)+" atomicmassunit."
|
---|
| 64 | print "Total density is "+str(weight/volume)+" atomicmassunit/angstrom^3."
|
---|
| 65 | print "Total density is "+str(1.6605387*weight/volume)+" g/cm^3."
|
---|