-
Notifications
You must be signed in to change notification settings - Fork 0
/
hop_count.py'
36 lines (31 loc) · 1.07 KB
/
hop_count.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
#!/usr/bin/env python
#
import os
workdir = os.getcwd()
transitions = 0
accumulatedhops = 0
old_id = "1"
source_id = "1"
r1 = open('hop_count_simple-transitions.ts','w')
r2 = open('hop_count_ht_accumulated.ts','w')
f = open('id.txt',"r")
content = f.readlines()
f.close()
for contentline in content:
if not contentline.startswith("#"):
frame, ox_id = contentline.split()
#if id remains the same, do nothing
if not ox_id == old_id: #if id changes:
transitions = transitions +1
accumulatedhops = accumulatedhops +1
if ox_id == source_id: #check if this is the previous oxygen. if so, the proton went back to the source
accumulatedhops = accumulatedhops -2 #so effectively -1
else:
source_id = old_id #if this is not a backhop but a forward one, update the proton source id
old_id = ox_id # update the current reading frame
r1.write(frame+'\t'+str(transitions)+'\n')
r2.write(frame+'\t'+str(accumulatedhops)+'\n')
print("number of hops in total: " + str(transitions)+'\n')
print("number of accumulated hops: " + str(accumulatedhops)+'\n')
r1.close()
r2.close()