-
Notifications
You must be signed in to change notification settings - Fork 0
/
cross-link_ms.py
executable file
·222 lines (174 loc) · 5.51 KB
/
cross-link_ms.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env python3
from __future__ import print_function
import IMP
import IMP.pmi
import IMP.pmi.topology
import IMP.pmi.io
import IMP.pmi.io.crosslink
import IMP.pmi.restraints
import IMP.pmi.restraints.crosslinking
import ihm.cross_linkers
m = IMP.Model()
s = IMP.pmi.topology.System(m)
st1 = s.create_state()
protA = st1.create_molecule("ProtA", "G" * 10, "A")
protA.add_representation(resolutions=[10])
protB = st1.create_molecule("ProtB", "G" * 30, "B")
protB.add_representation(resolutions=[10])
hier = s.build()
beads = IMP.atom.Selection(hier).get_selected_particles()
print(beads)
xyzs = [IMP.core.XYZ(b) for b in beads if IMP.core.XYZ.get_is_setup(b)]
xyzs[0].set_coordinates((0,0,0))
xyzs[1].set_coordinates((-40,0,0))
xyzs[2].set_coordinates((0,0,0))
xyzs[3].set_coordinates((40,0,0))
xldb='''Protein 1,Protein 2,Residue 1,Residue 2,UniqueID,Score
ProtA,ProtB,1,10,1,1.0
ProtA,ProtB,1,11,2,2.0
ProtA,ProtB,1,21,3,2.0
'''
with open('xlinks.csv', 'w') as fh:
fh.write(xldb)
cldbkc = IMP.pmi.io.crosslink.CrossLinkDataBaseKeywordsConverter()
cldbkc.set_protein1_key("Protein 1")
cldbkc.set_protein2_key("Protein 2")
cldbkc.set_residue1_key("Residue 1")
cldbkc.set_residue2_key("Residue 2")
# the unique_id_key and id_score_key are optional,
# and they add features that will be explained below
cldbkc.set_unique_id_key("UniqueID")
cldbkc.set_id_score_key("Score")
cldb = IMP.pmi.io.crosslink.CrossLinkDataBase(cldbkc)
cldb.create_set_from_file("xlinks.csv")
print(cldb)
xl = IMP.pmi.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint(
root_hier=hier, database=cldb, length=21.0, slope=0.0,
resolution=1.0, label="XL", linker=ihm.cross_linkers.dss)
print(xl.rs.unprotected_evaluate(None))
sel = IMP.atom.Selection(hier, molecule="ProtA")
pA, = sel.get_selected_particles()
scores = []
xs = []
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl.rs.unprotected_evaluate(None))
import pylab
pylab.plot(xs, scores)
from IMP.pmi.io.crosslink import FilterOperator
import operator
fo = FilterOperator(cldb.unique_id_key, operator.eq, "2")
fcldb = cldb.filter(fo)
print(fcldb)
xl1 = IMP.pmi.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint(
root_hier=hier, database=fcldb, length=21.0, slope=0.0,
resolution=1.0, label="XL", linker=ihm.cross_linkers.dss)
scores=[]
xs=[]
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl1.rs.unprotected_evaluate(None))
pylab.plot(xs, scores)
sigma = xl1.sigma_dictionary["SIGMA"][0]
scores_list = []
xs_list = []
for s in range(1, 20):
scores = []
xs = []
sigma.set_scale(float(s))
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl1.rs.unprotected_evaluate(None))
scores_list.append(scores)
xs_list.append(xs)
for xs, scores in zip(xs_list, scores_list):
pylab.plot(xs, scores)
sigma.set_scale(11)
psi = xl1.psi_dictionary["PSI"][0]
import numpy as np
scores_list = []
xs_list = []
for s in np.linspace(0.01, 0.5, 10):
scores = []
xs = []
psi.set_scale(float(s))
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl1.rs.unprotected_evaluate(None))
scores_list.append(scores)
xs_list.append(xs)
for xs, scores in zip(xs_list, scores_list):
pylab.plot(xs, scores)
sigma = xl.sigma_dictionary["SIGMA"][0]
scores_list = []
xs_list = []
for s in range(1, 20):
scores = []
xs = []
sigma.set_scale(float(s))
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl.rs.unprotected_evaluate(None))
scores_list.append(scores)
xs_list.append(xs)
for xs, scores in zip(xs_list, scores_list):
pylab.plot(xs, scores)
sigma.set_scale(11)
psi = xl.psi_dictionary["PSI"][0]
import numpy as np
scores_list = []
xs_list = []
for s in np.linspace(0.01, 0.5, 10):
scores = []
xs = []
psi.set_scale(float(s))
for i in range(-100, 100):
xs.append(float(i))
IMP.core.XYZ(pA).set_coordinates((i, 0, 0))
scores.append(xl.rs.unprotected_evaluate(None))
scores_list.append(scores)
xs_list.append(xs)
for xs, scores in zip(xs_list, scores_list):
pylab.plot(xs, scores)
import math
import numpy as np
sel = IMP.atom.Selection(hier, molecule="ProtB")
pB1, pB2, pB3 = sel.get_selected_particles()
IMP.core.XYZ(pA).set_coordinates((0,0,0))
IMP.core.XYZ(pB1).set_coordinates((0,20,0))
IMP.core.XYZ(pB2).set_coordinates((-20*math.sqrt(3)/2,-20/2,0))
IMP.core.XYZ(pB3).set_coordinates((20*math.sqrt(3)/2,-20/2,0))
scores = []
psis = []
sigmas = []
for p in np.linspace(0.01, 0.5, 100):
psi.set_scale(p)
for s in np.linspace(1, 40, 50):
psis.append(p)
sigmas.append(s)
sigma.set_scale(s)
scores.append(xl.rs.unprotected_evaluate(None))
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(psis, sigmas, c=scores, s=30, edgecolor=[])
plt.show()
IMP.core.XYZ(pA).set_coordinates((100, 100, 100))
scores = []
psis = []
sigmas = []
for p in np.linspace(0.01, 0.5, 100):
psi.set_scale(p)
for s in np.linspace(1, 40, 50):
psis.append(p)
sigmas.append(s)
sigma.set_scale(s)
scores.append(xl.rs.unprotected_evaluate(None))
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter(psis, sigmas, c=scores, s=30, edgecolor=[])
plt.show()