source: util/src/RemoveRandomAtoms.py.in@ 086db0

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