source: util/src/CheckMap.py.in@ a3ffb44

Last change on this file since a3ffb44 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: 1.7 KB
Line 
1#!@PYTHON@
2#
3# checks whether a given bond file actually makes sense in terms of a max distance
4
5import sys, random, math, re
6wrerr=sys.stderr.write
7wrout=sys.stdout.write
8
9# check arguments
10if len(sys.argv) < 3:
11 print "Usage: "+sys.argv[0]+" <srcBondFile> <srcPositionFile> <max_dist>"
12 sys.exit(1)
13
14
15EPSILON=1e-3
16CUTOFF=2.
17inputBonds = open(sys.argv[1], "r")
18inputPos = open(sys.argv[2], "r")
19maxdist = (float)(sys.argv[3])
20
21def 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
31print "Scanning XYZ file"+sys.argv[2]+"."
32Atoms = []
33Bonds = []
34x = [0.0, 0.0, 0.0]
35
36for 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]])
43inputPos.close()
44
45for line in inputBonds:
46 entries = line.split()
47 Bonds.append([int(entries[0]), int(entries[1])])
48inputBonds.close()
49
50NumViolators =0
51
52for 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
66print NumViolators, "Atoms have unreasonable bonds"
Note: See TracBrowser for help on using the repository browser.