-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgt-log2xyz.py
66 lines (50 loc) · 1.29 KB
/
gt-log2xyz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# Description: Create successful run and turn into xyz files
# Usage: gt-log2xyz.py [ < file | file1 file2 .... ]
import sys, os
# in order to print count has to be 3
def generatexyz(db, filename):
filen = str(os.path.splitext(filename)[0]).split("/")[-1]
fd = open("%s.xyz"%filen, "w")
count = 0
lines = []
for line in db:
if '' in line:
count = count + 1
if count == 3:
lines.append(line)
print(len(lines[2:]),file=fd)
print("This was generated by gt-log2xyz.py", file=fd)
for [ln] in lines[2:]:
print (ln.replace(',', " "), file=fd)
print("",file=fd)
fd.flush()
def fn (string, file):
db = []
flag = 0
linenew2=''
for line in string:
linenew = line.strip()
if "1\\1\\" in linenew:
linenew2 = linenew2 + linenew
flag = 1
elif "@" in linenew:
linenew2 = linenew2 + linenew
data=[]
data=linenew2.split('\\')
for line2 in data:
db.append([line2])
flag = 0
linenew=''
linenew2=''
elif flag == 1:
linenew2 = linenew2 + linenew
generatexyz(db, file)
files = sys.argv[1:]
if not files:
string = sys.stdin
fn ( string )
else:
for file in files:
string = open ( file, 'r' ).readlines()
fn ( string, file )