-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_graph_d.py
42 lines (39 loc) · 1.55 KB
/
create_graph_d.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
# Function: create contact graph from gro file
import numpy as np
import pandas as pd
import csv
thresh = 1.0 #unit nm
num_files = 34
def main():
for flag in ['A','B']:
for k in range(1,num_files+1):
for m in range(1,17):
t = round(0.0-0.2*(m-1),1)
path = 'raw_data/monomer/structure/'+str(k)+'_'+str(t)+'ns-'+flag+'.gro'
df = pd.read_csv(path,
sep = '[\s]{1,}',
engine = 'python',
header = None,
index_col = False,
skiprows=2,#skip str 3
skipfooter=1,#skip end 1
names= ["residue","atom","atomid","x","y","z"])
df_CA = df[df['atom'] == 'CA']
row = []
col = []
for i in range(df_CA.iloc[:,0].size):
for j in range(df_CA.iloc[:,0].size):
p_i = df_CA.iloc[i,3:6]#x y z col
p_j = df_CA.iloc[j,3:6]#x y z col
distance = np.linalg.norm(p_i - p_j)
if distance < thresh :
row.append(i)
col.append(j)
filepath = './contact_graph/contactg_'+str(k)+'_'+str(t)+'ns-'+flag+'.csv'
rows = zip(row,col)
with open(filepath,"w",newline='') as f:
writer = csv.writer(f)
writer.writerows(rows)
print("done!")
if __name__ == '__main__':
main()