-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.py
More file actions
180 lines (145 loc) · 4.08 KB
/
remove.py
File metadata and controls
180 lines (145 loc) · 4.08 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# #%%
# from multiprocessing.connection import answer_challenge
# from operator import mod
# import pdb
# from select import select
# from tracemalloc import start
# from turtle import pd
# import pymol
# from pymol import cmd as cmd
# import os
# from Bio.PDB import *
# from Bio.Seq import Seq
# import pymol2
# #%%
# # for i in range(len(dir_list)):
# # if "pre_leap" == os.path.splitext(dir_list[i])[0]: ## os.path.splitext()[1]で拡張子を取得
# # pdb_file = os.path.join(dir_list[i])
# #%%
# pdb_parser = PDBParser()
# structure = pdb_parser.get_structure('X', 'test.pdb')
# model = structure[0].get_list()
# chain = model[0].get_list()
# residue = chain[0].get_list()
# #%%
# for r in chain:
# print(r.get_resname())
# #%%
# res = structure.get_residues()
# print(res)
# #%%
# print(len(chain))
# #%%
# residues = structure.chains[0].get_list()
# for r in residues:
# print(r.get_id())
# #%%
# pymol.finish_launching()
# cmd.load("test.pdb", "master")
# #%%
# cmd.select("fpp", "resn FPP")
# #%%
# last = str(len(chain))
# last30 = str(len(chain) - 30)
# answer = "resi " + last30 + ":" + last
# cmd.select("start", answer)
# #%%
# print(answer)
# cmd.select("start")
# # %%
# cmd.select("outs","byres resn * within 5.0 of resn fpp")
# cmd.select("not (resn outs) and start")
# #%%
# cmd.delete("start and outs")
# # %%
# p1 = pymol2.PyMOL()
# p1.start()
# p1.cmd.fragment('ala')
# p1.cmd.zoom()
# p1.cmd.png('ala.png', 1000, 800, dpi=150, ray=1)
# p1.stop()
# # %%
# p2 = pymol2.PyMOL()
# p2.start()
# p2.cmd.load("test.pdb", "aaa")
# p2.cmd.zoom()
# p2.cmd.png("aaa.png", 1000, 800, dpi=300, ray=1)
# p2.stop
# %%
import os
from threading import currentThread
import pymol2
import Bio.PDB
currentdir = os.path.abspath("./")
if os.path.isfile(f"{currentdir}/.DS_Store") == True:
os.remove(currentdir + "/.DS_Store")
dirlist = os.listdir(currentdir)
pdbfiles = []
def get_end(pdbfile_path):
pdb_parser = Bio.PDB.PDBParser()
struct = pdb_parser.get_structure("seq", pdbfile_path)
res = struct[0]["A"].get_list()
length = -4
for r in res:
length += 1
return length
for d in dirlist:
iddir_list = []
iddir = os.path.join(currentdir, d)
try:
iddir_list += os.listdir(iddir)
except:
pass
for f in iddir_list:
if "pre_leap.pdb" == f:
pdbfiles.append(os.path.join(iddir, f))
for (i, pdbfile) in enumerate(pdbfiles):
iddir = os.path.dirname(pdbfile)
pymol_i = f"pymol_{i}"
exec("pymol_i = pymol2.PyMOL()")
pymol_i.start()
pymol_i.cmd.load(pdbfile, "protain")
pymol_i.cmd.select("fpp", "resn FPP")
len = get_end(pdbfile)
pymol_i.cmd.select("start30", "resi 1:20")
pymol_i.cmd.select("end30", f"resi {len-20}:len")
pymol_i.cmd.select("7A_aroundfpp", "byres resn * within 7.0 of fpp")
pymol_i.cmd.select("remove1", "start30 and (not 7A_aroundfpp)")
pymol_i.cmd.select("remove2", "end30 and (not 7A_aroundfpp)")
pymol_i.cmd.select("newprotain", "protain and (not remove1) and (not remove2)")
pymol_i.cmd.save(f"{iddir}/pre_leap.pdb", "newprotain")
pymol_i.stop()
# # %%
# import os
# import pymol2
# import Bio.PDB
# def get_end(pdbfile_path):
# pdb_parser = Bio.PDB.PDBParser()
# struct = pdb_parser.get_structure("seq", pdbfile_path)
# res = struct[0]["A"].get_list()
# length = -4
# for r in res:
# length += 1
# return length
# pymol_i = pymol2.PyMOL()
# pymol_i.start()
# pymol_i.cmd.load("./test.pdb", "protain")
# pymol_i.cmd.select("fpp", "resn FPP")
# len = get_end("test.pdb")
# pymol_i.cmd.select("start30", "resi 1:30")
# pymol_i.cmd.select("end30", f"resi {len-30}:len")
# pymol_i.cmd.select("10A_aroundfpp", "byres resn * within 7.0 of fpp")
# pymol_i.cmd.select("remove1", "start30 and (not 7A_aroundfpp)")
# pymol_i.cmd.select("remove2", "end30 and (not 7A_aroundfpp)")
# pymol_i.cmd.select("newprotain", "protain and (not remove1) and (not remove2)")
# pymol_i.cmd.save("pre_leap.pdb", "newprotain")
# pymol_i.stop()
# #%%
# # %%
# print(currentdir)
# # %%
# %%
print(pdbfiles)
# %%
print(os.path.dirname(pdbfiles[0]))
# %%