[e1a46d] | 1 | #!@PYTHON@
|
---|
| 2 | #
|
---|
| 3 | # checks whether a given bond file actually makes sense in terms of a max distance
|
---|
| 4 |
|
---|
| 5 | import sys, random, math, re
|
---|
| 6 | wrerr=sys.stderr.write
|
---|
| 7 | wrout=sys.stdout.write
|
---|
| 8 |
|
---|
| 9 | # check arguments
|
---|
| 10 | if len(sys.argv) < 3:
|
---|
| 11 | print "Usage: "+sys.argv[0]+" <srcBondFile> <srcPositionFile> <max_dist>"
|
---|
| 12 | sys.exit(1)
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | EPSILON=1e-3
|
---|
| 16 | CUTOFF=2.
|
---|
| 17 | inputBonds = open(sys.argv[1], "r")
|
---|
| 18 | inputPos = open(sys.argv[2], "r")
|
---|
| 19 | maxdist = (float)(sys.argv[3])
|
---|
| 20 |
|
---|
| 21 | def distance(atom1, atom2):
|
---|
| 22 | """# Here we calculate the distance between atom1 and atom2
|
---|
| 23 | """
|
---|
| 24 | dist = 0
|
---|
| 25 | for i in range(len(atom1)):
|
---|
| 26 | dist+=(atom1[i]-atom2[i])*(atom1[i]-atom2[i])
|
---|
| 27 | return( math.sqrt(dist))
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | print "Scanning XYZ file"+sys.argv[2]+"."
|
---|
| 32 | Atoms = []
|
---|
| 33 | Bonds = []
|
---|
| 34 | x = [0.0, 0.0, 0.0]
|
---|
| 35 |
|
---|
| 36 | for line in inputPos:
|
---|
| 37 | entries = line.split()
|
---|
| 38 | if (len(entries)<1 or (entries[0]!="O" and entries[0]!="Si" and entries[0]!="Ca")):
|
---|
| 39 | continue
|
---|
| 40 | for n in range(3):
|
---|
| 41 | x[n] = float(entries[1+n])
|
---|
| 42 | Atoms.append([x[0], x[1], x[2]])
|
---|
| 43 | inputPos.close()
|
---|
| 44 |
|
---|
| 45 | for line in inputBonds:
|
---|
| 46 | entries = line.split()
|
---|
| 47 | Bonds.append([int(entries[0]), int(entries[1])])
|
---|
| 48 | inputBonds.close()
|
---|
| 49 |
|
---|
| 50 | NumViolators =0
|
---|
| 51 |
|
---|
| 52 | for i in range(len(Bonds)):
|
---|
| 53 | try:
|
---|
| 54 | dist =distance(Atoms[Bonds[i][0]], Atoms[Bonds[i][1]])
|
---|
| 55 | except IndexError:
|
---|
| 56 | print "Bonds["+str(i)+"][0] = "+str(Bonds[i][0])+" or Bonds["+str(i)+"][1] = "+str(Bonds[i][1])+" does not exist."
|
---|
| 57 | dist=89
|
---|
| 58 | #if Bonds[i][0]==6096:
|
---|
| 59 | # print "Atoms ", Bonds[i], "have distance: ", dist
|
---|
| 60 | # print Atoms[Bonds[i][0]]
|
---|
| 61 | # print Atoms[Bonds[i][1]]
|
---|
| 62 | if dist>maxdist and dist<88:
|
---|
| 63 | NumViolators+=1
|
---|
| 64 | #print "Atoms ", Bonds[i], Atoms[Bonds[i][0]], Atoms[Bonds[i][1]], "have distance: ", dist
|
---|
| 65 |
|
---|
| 66 | print NumViolators, "Atoms have unreasonable bonds"
|
---|