Last change
on this file since 086db0 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.1 KB
|
Line | |
---|
1 | #!@PYTHON@
|
---|
2 | #
|
---|
3 | # Removes random atoms from a TREMOLO data file
|
---|
4 |
|
---|
5 | import sys, random
|
---|
6 |
|
---|
7 | # check arguments
|
---|
8 | if len(sys.argv) < 2:
|
---|
9 | print "Usage: "+sys.argv[0]+" <datafile> <NoDefects>"
|
---|
10 | sys.exit(1)
|
---|
11 |
|
---|
12 | input = open(sys.argv[1], "r")
|
---|
13 | output = open(sys.argv[1]+".defect", "w")
|
---|
14 | defectcount=int(sys.argv[2])
|
---|
15 |
|
---|
16 | # parse lines into array
|
---|
17 | lines=[]
|
---|
18 | comments=0
|
---|
19 | nr=0
|
---|
20 | for line in input:
|
---|
21 | if "#" in line:
|
---|
22 | comments=comments+1
|
---|
23 | lines.append(line)
|
---|
24 | nr=len(lines)
|
---|
25 | input.close()
|
---|
26 | print "I have scanned "+str(nr)+" lines in "+sys.argv[1]+" with "+str(comments)+" comments."
|
---|
27 |
|
---|
28 | if (nr-comments)>int(defectcount):
|
---|
29 | for i in range(defectcount):
|
---|
30 | while True:
|
---|
31 | linenr=random.randint(comments,nr-1)
|
---|
32 | if not "removed" in lines[linenr]:
|
---|
33 | lines[linenr]="removed"
|
---|
34 | break
|
---|
35 | else:
|
---|
36 | print "There are fewer atoms present than you want removed, aborting."
|
---|
37 | sys.exit(1)
|
---|
38 | print "I have removed "+str(defectcount)+" atoms."
|
---|
39 |
|
---|
40 | for i in range(nr):
|
---|
41 | if not "removed" in lines[i]:
|
---|
42 | output.write(lines[i])
|
---|
43 | output.close()
|
---|
44 | print "I have stored the new configuration."
|
---|
45 |
|
---|
46 | print "All done."
|
---|
47 |
|
---|
48 | sys.exit(0)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.