#!@PYTHON@ # # Removes random atoms from a TREMOLO data file import sys, random # check arguments if len(sys.argv) < 2: print "Usage: "+sys.argv[0]+" " sys.exit(1) input = open(sys.argv[1], "r") output = open(sys.argv[1]+".defect", "w") defectcount=int(sys.argv[2]) # parse lines into array lines=[] comments=0 nr=0 for line in input: if "#" in line: comments=comments+1 lines.append(line) nr=len(lines) input.close() print "I have scanned "+str(nr)+" lines in "+sys.argv[1]+" with "+str(comments)+" comments." if (nr-comments)>int(defectcount): for i in range(defectcount): while True: linenr=random.randint(comments,nr-1) if not "removed" in lines[linenr]: lines[linenr]="removed" break else: print "There are fewer atoms present than you want removed, aborting." sys.exit(1) print "I have removed "+str(defectcount)+" atoms." for i in range(nr): if not "removed" in lines[i]: output.write(lines[i]) output.close() print "I have stored the new configuration." print "All done." sys.exit(0)