oucgc1996 commited on
Commit
1046ab8
1 Parent(s): 34fdcfa

Add application file

Browse files
Files changed (1) hide show
  1. app.py +98 -0
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pyuul import VolumeMaker
2
+ from pyuul import utils
3
+ import os
4
+ from sklearn.cluster import KMeans
5
+ from collections import OrderedDict
6
+ import numpy as np
7
+ import pandas as pd
8
+ import random
9
+ import torch
10
+ import os
11
+ import shutil
12
+ import gradio as gr
13
+
14
+ # 设置随机数种子
15
+ def setup_seed(seed):
16
+ torch.manual_seed(seed)
17
+ torch.cuda.manual_seed_all(seed)
18
+ np.random.seed(seed)
19
+ random.seed(seed)
20
+ torch.backends.cudnn.deterministic = True
21
+ setup_seed(100)
22
+ device = "cuda"
23
+
24
+ def add_file_to_folder(new_file_path, folder):
25
+ ls = os.listdir(new_file_path)
26
+ for line in ls:
27
+ filePath = os.path.join(new_file_path, line)
28
+ if os.path.isfile(filePath):
29
+ shutil.copy(filePath, folder)
30
+
31
+ def copy(files,folder):
32
+ file = os.listdir(folder)
33
+ for i in file:
34
+ if i not in files:
35
+ file_path = os.path.join(folder, i)
36
+ os.remove(file_path)
37
+
38
+ def pyuul(folder,n_clusters):
39
+ coords, atname, pdbname, pdb_num = utils.parsePDB(folder)
40
+ atoms_channel = utils.atomlistToChannels(atname)
41
+ radius = utils.atomlistToRadius(atname)
42
+
43
+ PointCloudSurfaceObject = VolumeMaker.PointCloudVolume(device=device)
44
+
45
+ coords = coords.to(device)
46
+ radius = radius.to(device)
47
+ atoms_channel = atoms_channel.to(device)
48
+
49
+ SurfacePoitCloud = PointCloudSurfaceObject(coords, radius)
50
+ feature = SurfacePoitCloud.view(pdb_num,-1).cpu()
51
+
52
+ kmean = KMeans(n_clusters=n_clusters,n_init=10,init="k-means++",random_state=100)
53
+ y = kmean.fit_predict(feature)
54
+
55
+ pairs = zip(pdbname, y)
56
+ result_dict = {key: value for key, value in pairs}
57
+ ligend_class = result_dict['ligend.pdb']
58
+
59
+ sheet = []
60
+ for key, value in result_dict.items():
61
+ if value == ligend_class:
62
+ sheet.append(key)
63
+ return sheet
64
+
65
+ def kmeans(ligend,n_clusters,n_num):
66
+ peptide_folder_path = "/peptide/"
67
+ pdb_folder = "/temp/"
68
+ shutil.copyfile(ligend,pdb_folder)
69
+ for i in range(1,n_num+1):
70
+ if i == 1:
71
+ add_file_to_folder(peptide_folder_path,pdb_folder)
72
+ output = pyuul(pdb_folder, n_clusters)
73
+ copy(output,pdb_folder)
74
+ else:
75
+ if pdb_folder != None:
76
+ output = pyuul(pdb_folder, n_clusters)
77
+ copy(output,pdb_folder)
78
+
79
+ data = OrderedDict()
80
+ data['Name'] = output
81
+ data = pd.DataFrame(data)
82
+ data.to_csv('outputs.csv', index=False)
83
+ shutil.rmtree(pdb_folder)
84
+ os.mkdir(pdb_folder)
85
+ return 'outputs.csv'
86
+
87
+ iface = gr.Interface(fn=kmeans,
88
+ inputs=["text",
89
+ gr.Textbox(label="n_clusters", placeholder="2", lines=1),
90
+ gr.Textbox(label="Times", placeholder="2", lines=1)
91
+ ],
92
+ outputs= "text"
93
+ )
94
+ iface.launch()
95
+
96
+
97
+
98
+