1 """@namespace IMP.pmi.nonmaintained
5 from __future__
import print_function
12 self.rigid_bodies = []
13 self.floppy_bodies = []
14 self.maxtrans_rb = 2.0
15 self.maxtrans_fb = 2.0
18 def add_protein(self, name, res):
19 (firstres, lastres) = res
20 from math
import pi, cos, sin
23 nres = lastres - firstres
24 radius = (nres) * 5 / 2 / pi
26 for res
in range(firstres, lastres):
27 alpha = 2 * pi / nres * (res - firstres)
28 x = radius * cos(alpha)
29 y = radius * sin(alpha)
34 d.set_coordinates_are_optimized(
True)
36 self.hier.add_child(h)
38 def get_hierarchy(self):
41 def set_rod(self, chainname, res):
42 (firstres, lastres) = res
47 residue_indexes=list(range(
50 ps = sel.get_selected_particles()
52 self.rigid_bodies.append(rb)
54 def get_particles_to_sample(self):
59 ps[
"Floppy_Bodies_Rods"] = (self.floppy_bodies, self.maxtrans_fb)
60 ps[
"Rigid_Bodies_Rods"] = (
69 def __init__(self, m):
74 self.floppy_bodies = []
75 self.maxtrans_fb = 0.2
76 self.particle_database = {}
78 def add_bead(self, radius, label="None", color=None):
82 self.particle_database[label] = p
83 self.floppy_bodies.append(p)
87 d.set_coordinates_are_optimized(
True)
94 self.hier.add_child(p)
96 self.set_color(label, color)
97 return self.particle_database[label]
99 def set_color(self, label, value):
100 p = self.particle_database[label]
104 def set_floppy_bodies_max_trans(self, maxtrans):
105 self.maxtrans_fb = maxtrans
107 def get_hierarchy(self):
110 def get_bead(self, label):
111 return self.particle_database[label]
113 def set_maxtrans_fb(self, maxtrans_fb):
114 self.maxtrans_fb = maxtrans_fb
116 def get_particles_to_sample(self):
121 ps[
"Floppy_Bodies_Beads"] = (self.floppy_bodies, self.maxtrans_fb)
125 class MultipleStates(object):
127 def __init__(self, nstates, m):
128 global itertools, tools, restraints
134 self.floppy_bodies = []
135 self.rigid_bodies = []
136 for ncopy
in range(nstates):
137 self.floppy_bodies.append([])
138 self.rigid_bodies.append([])
140 self.rigid_bodies_are_sampled =
True
141 self.floppy_bodies_are_sampled =
True
144 self.prot_lowres = {}
145 self.nstates = nstates
149 self.xyzmodellist = []
151 self.maxtrans_rb = 0.15
152 self.maxrot_rb = 0.03
153 self.maxtrans_fb = 0.15
159 def set_label(self, label):
162 def set_rigid_bodies_are_sampled(self, input=True):
163 self.rigid_bodies_are_sampled = input
165 def set_floppy_bodies_are_sampled(self, input=True):
166 self.floppy_bodies_are_sampled = input
168 def get_rigid_bodies(self):
169 return self.rigid_bodies
171 def set_rigid_bodies_max_trans(self, maxtrans):
172 self.maxtrans_rb = maxtrans
174 def set_rigid_bodies_max_rot(self, maxrot):
175 self.maxrot_rb = maxrot
177 def set_floppy_bodies_max_trans(self, maxtrans):
178 self.maxtrans_fb = maxtrans
180 def get_hierarchies(self):
183 def destroy_residues(self, segments):
186 for prot
in self.prot:
187 for segment
in segments:
189 if (segment[0] == -1
or segment[1] == -1):
195 residue_indexes=list(range(segment[0],
197 for p
in s.get_selected_particles():
199 print(
"MultipleStates: one particle was not destroied because it was a RigidMember.")
209 def add_residues_to_chains(
212 residue_type=IMP.atom.LYS):
216 for rc
in residuechainlist:
222 atom_type=IMP.atom.AT_CA)
224 print(s.get_selected_particles())
225 if len(s.get_selected_particles()) == 0:
226 for prot
in self.prot:
227 print(
"adding " + str(rc))
232 d.set_coordinates_are_optimized(
True)
241 print(tools.get_residue_index_and_chain_from_particle(a))
244 p = s.get_selected_particles()[0]
246 print(rc, s.get_selected_particles()[0])
253 atom_type=IMP.atom.AT_CA)
255 print(s.get_selected_particles())
257 def add_beads(self, segments, xyzs=None, radii=None, colors=None):
259 this method generate beads in missing portions.
260 The segments argument must be a list of selections
261 in the form [(firstres,lastres,chain)]
262 each selection will generate a bead
273 for n, s
in enumerate(segments):
278 for prot
in self.prot:
279 for prot
in self.prot:
283 if chain.get_id() == chainid:
286 rindexes = list(range(firstres, lasteres + 1))
287 f.set_residue_indexes(rindexes)
289 "Fragment_" +
'%i-%i' %
292 mass = len(rindexes) * 110.0
294 if n + 1 > len(radii):
295 mass = len(rindexes) * 110.0
297 radius = (3 * vol / math.pi) ** (1 / 3)
301 if n + 1 > len(xyzs):
310 if n + 1 <= len(colors):
314 d = IMP.atom.XYZR.setup_particle(
317 def renumber_residues(self, chainid, newfirstresiduenumber):
318 for prot
in self.prot:
322 ps = c.get_children()
325 offs = newfirstresiduenumber - ri
329 r.set_index(ri + offs)
331 def destroy_everything_but_the_residues(self, segments):
333 for prot
in self.prot:
335 for segment
in segments:
338 if (segment[0] == -1
or segment[1] == -1):
344 residue_indexes=list(range(segment[0],
346 pstokeep += s.get_selected_particles()
349 if p
not in pstokeep:
351 print(
"MultipleStates: one particle was not destroied because it was a RigidMember.")
360 def generate_linkers_restraint_and_floppy_bodies(self, segment):
362 this methods automatically links the particles consecutively
363 according to the sequence. The restraint applied is a harmonic upper bound,
364 with a distance that is proportional to the number of residues
369 linker_restraint_objects = []
370 for ncopy, prot
in enumerate(self.prot):
371 if (segment[0] == -1
or segment[1] == -1):
377 residue_indexes=list(range(segment[0],
380 for p
in s.get_selected_particles():
382 (r, c) = tools.get_residue_index_and_chain_from_particle(p)
387 (r, c) = tools.get_residue_index_and_chain_from_particle(p)
388 p.set_name(str(r) +
":" + str(c))
389 tools.set_floppy_body(p)
390 self.floppy_bodies[ncopy].append(p)
392 residue_indexes.append((r, Floppy, c, p))
394 residue_indexes.sort()
396 pruned_residue_list = []
397 r0 = residue_indexes[0]
398 pruned_residue_list.append(r0)
402 for i
in range(1, len(residue_indexes)):
403 r = residue_indexes[i]
407 pruned_residue_list.append(r0)
408 pruned_residue_list.append(r)
410 elif r[1] != r0[1]
and r0[1] ==
False:
411 pruned_residue_list.append(r0)
412 pruned_residue_list.append(r)
414 elif r[1] == r0[1]
and r0[1]:
415 pruned_residue_list.append(r)
417 elif r[1] != r0[1]
and r[1] ==
False:
418 pruned_residue_list.append(r)
421 r0 = pruned_residue_list[0]
424 for i
in range(1, len(pruned_residue_list)):
425 r = pruned_residue_list[i]
429 linkdomaindef.append((r0[0], r[0], r[2]))
432 print(
" creating linker between atoms defined by: " + str(linkdomaindef))
434 ld = restraints.LinkDomains(prot, linkdomaindef, 1.0, 3.0)
435 ld.set_label(str(ncopy))
437 linker_restraint_objects.append(ld)
440 return linker_restraint_objects
442 def get_ref_hierarchies(self):
445 def get_number_of_states(self):
448 def get_rigid_bodies(self):
450 for rbl
in self.rigid_bodies:
455 def get_floppy_bodies(self):
457 for fbl
in self.floppy_bodies:
462 def set_rigid_bodies(self, rigid_body_list):
463 if len(self.prot) == 0:
464 print(
"MultipleStates.set_rigid_bodies: hierarchy was not initialized")
466 for ncopy, prot
in enumerate(self.prot):
468 for element
in rigid_body_list:
470 for interval
in element:
474 if (interval[0] == -1
or interval[1] == -1):
480 residue_indexes=list(range(interval[0],
482 for p
in s.get_selected_particles():
486 for key
in self.prot_lowres:
487 if (interval[0] == -1
or interval[1] == -1):
489 self.prot_lowres[key][ncopy],
493 self.prot_lowres[key][
494 ncopy], chains=interval[2],
495 residue_indexes=list(range(interval[0], interval[1] + 1)))
496 for p
in s.get_selected_particles():
502 rb.set_name(str(element))
505 print(
"MultipleStates.set_rigid_bodies: selection " + str(interval) +
" has zero elements")
506 self.rigid_bodies[ncopy] += rbl
508 def set_floppy_bodies(self, floppy_body_list):
511 if len(self.prot) == 0:
512 print(
"MultipleStates: hierarchy was not initialized")
515 for ncopy, prot
in enumerate(self.prot):
517 for element
in floppy_body_list:
519 for interval
in element:
523 if (interval[0] == -1
or interval[1] == -1):
529 residue_indexes=list(range(interval[0],
531 for p
in s.get_selected_particles():
532 (r, c) = tools.get_residue_index_and_chain_from_particle(
534 tools.set_floppy_body(p)
535 p.set_name(str(r) +
":" + str(c))
537 self.floppy_bodies[ncopy] += atoms
539 def get_particles_to_sample(self):
544 rblist = self.get_rigid_bodies()
545 fblist = self.get_floppy_bodies()
546 if self.rigid_bodies_are_sampled:
547 ps[
"Rigid_Bodies_MultipleStates"] = (
551 if self.floppy_bodies_are_sampled:
552 ps[
"Floppy_Bodies_MultipleStates"] = (fblist, self.maxtrans_fb)
555 def set_hierarchy_from_pdb(self, pdblistoflist):
556 "the input is a list of list of pdbs"
557 "one list for each copy"
559 for copy
in range(0, self.nstates):
560 prot = self.read_pdbs(pdblistoflist[copy])
561 self.prot.append(prot)
563 self.xyzmodellist.append(xyz)
565 def set_ref_hierarchy_from_pdb(self, pdblistoflist):
566 "the input is a list of list of pdbs"
567 "one list for each copy"
569 for copy
in range(0, self.nstates):
570 prot = self.read_pdbs(pdblistoflist[copy])
571 self.refprot.append(prot)
573 self.xyzreflist.append(xyz)
575 def read_pdbs(self, list_pdb_file):
576 """read pdbs from an external list file
577 create a simplified representation
578 if the pdbs are given a individual strings, it will read the
579 pdbs and give the chain name as specified in the pdb
580 If it s a tuple like (filename,chainname) it will read
581 the pdb and assing a name chainname
586 for pdb
in list_pdb_file:
594 #destroy CA atoms, for the future
595 for p in IMP.atom.get_leaves(h):
596 coor=IMP.core.XYZ(p).get_coordinates()
597 r=IMP.atom.Hierarchy(p).get_parent()
598 IMP.core.XYZ.setup_particle(r,coor)
605 #consolidate the chains
608 s0=IMP.atom.Selection(hier, chains=cid)
610 p=s0.get_selected_particles()[0]
611 re=IMP.atom.Residue(IMP.atom.Atom(p).get_parent()
612 ch=IMP.atom.Chain(re).get_parent())
619 if type(pdb) == tuple:
626 #destroy CA atoms, for the future
627 for p in IMP.atom.get_leaves(h):
628 coor=IMP.core.XYZ(p).get_coordinates()
629 r=IMP.atom.Hierarchy(p).get_parent()
630 IMP.core.XYZ.setup_particle(r,coor)
641 def recenter(self, prot):
642 "recenter the hierarchy"
644 center = IMP.algebra.get_zero_vector_3d()
650 d.set_coordinates(d.get_coordinates() - center)
651 d.set_coordinates_are_optimized(
True)
654 # bug generating code: keeping it for history
656 rb=IMP.atom.create_rigid_body(prot)
657 rbcoord=rb.get_coordinates()
658 rot=IMP.algebra.get_identity_rotation_3d()
659 tmptrans=IMP.algebra.Transformation3D(rot,rbcoord)
660 trans=tmptrans.get_inverse()
661 IMP.core.transform(rb,trans)
662 IMP.core.RigidBody.teardown_particle(rb)
663 self.m.remove_particle(rb)
666 def shuffle_configuration(self, bounding_box_length):
667 "shuffle configuration, used to restart the optimization"
668 "it only works if rigid bodies were initialized"
669 if len(self.rigid_bodies) == 0:
670 print(
"MultipleStates: rigid bodies were not intialized")
671 hbbl = bounding_box_length / 2
672 for rbl
in self.rigid_bodies:
682 rb.set_reference_frame(
685 def generate_simplified_hierarchy(self, nres):
687 self.prot_lowres[nres] = []
688 for prot
in self.prot:
696 self.prot_lowres[nres].append(sh)
698 def get_simplified_hierarchy(self, nres):
699 return self.prot_lowres[nres]
701 def calculate_drms(self):
704 if len(self.xyzmodellist) == 0:
705 print(
"MultipleStates: hierarchies were not intialized")
707 if len(self.xyzreflist) == 0:
708 print(
"MultipleStates: reference hierarchies were not intialized")
711 for i
in range(len(self.xyzreflist)):
712 for j
in range(len(self.xyzmodellist)):
715 self.xyzmodellist[j],
718 drmsdval = tools.get_drmsd(
719 self.xyzmodellist[j],
721 drmsd[
"MultipleStates_DRMSD_" +
722 str(i) +
"-Model_" + str(j)] = drmsdval
726 for assign
in itertools.permutations(list(range(len(self.xyzreflist)))):
728 for i, j
in enumerate(assign):
729 s += drmsd[
"MultipleStates_DRMSD_" +
730 str(j) +
"-Model_" + str(i)]
733 drmsd[
"MultipleStates_Total_DRMSD"] = min(min_drmsd)
736 def get_output(self):
738 if len(self.refprot) != 0:
739 drms = self.calculate_drms()
741 output[
"MultipleStates_Total_Score_" +
742 self.label] = str(self.m.evaluate(
False))
748 class LinkDomains(object):
750 def __init__(self, prot, resrangelist, kappa, length=5.0):
759 self.resrangelist = resrangelist
763 self.m = self.prot.get_model()
766 for pair
in self.resrangelist:
776 atom_type=IMP.atom.AT_CA)
777 p0 = s0.get_selected_particles()[0]
786 atom_type=IMP.atom.AT_CA)
787 p1 = s1.get_selected_particles()[0]
793 dist0 = float(pair[1] - pair[0]) * self.length
798 "LinkDomains_" + str(pair[0]) +
"-" + str(pair[1]) +
"_" + str(pair[2]))
799 self.rs.add_restraint(pr)
800 self.pairs.append((p0, p1, r0, c0, r1, c1, pr))
802 def set_label(self, label):
805 def add_to_model(self):
806 self.m.add_restraint(self.rs)
811 def get_hierarchy(self):
817 def get_residue_ranges(self):
818 return self.resrangelist
820 def get_length(self):
823 def get_restraint(self):
828 for r
in self.rs.get_restraints():
829 rlist.append(IMP.core.PairRestraint.get_from(r))
832 def print_chimera_pseudobonds(self, filesuffix, model=0):
833 f = open(filesuffix +
".chimera",
"w")
836 s =
"#" + str(model) +
":" + str(p[2]) +
"." + p[3] +
"@" + atype + \
837 " #" + str(model) +
":" + str(p[4]) +
"." + p[5] +
"@" + atype
841 def get_output(self):
844 score = self.rs.unprotected_evaluate(
None)
845 output[
"_TotalScore"] = str(score)
846 output[
"LinkDomains_" + self.label] = str(score)
847 for rst
in self.rs.get_restraints():
851 output[
"LinkDomains_" + rst.get_name() +
852 "_" + self.label] = rst.unprotected_evaluate(
None)
854 for i
in range(len(self.pairs)):
856 p0 = self.pairs[i][0]
857 p1 = self.pairs[i][1]
858 r0 = self.pairs[i][2]
859 c0 = self.pairs[i][3]
860 r1 = self.pairs[i][4]
861 c1 = self.pairs[i][5]
863 label = str(r0) +
":" + c0 +
"_" + str(r1) +
":" + c1
867 output[
"LinkDomains_Distance_" + label +
"_" +
876 class UpperBound(object):
878 def __init__(self, prot, respairs, kappa, length=5.0):
888 self.respairs = respairs
892 self.m = self.prot.get_model()
894 for pair
in self.respairs:
899 residue_index=pair[0],
900 atom_type=IMP.atom.AT_CA)
901 p0 = s0.get_selected_particles()[0]
909 residue_index=pair[2],
910 atom_type=IMP.atom.AT_CA)
911 p1 = s1.get_selected_particles()[0]
922 "UpperBound_" + str(pair[0]) +
"-" + str(pair[1]) +
"_" + str(pair[2]))
923 self.rs.add_restraint(pr)
925 def set_label(self, label):
928 def add_to_model(self):
929 self.m.add_restraint(self.rs)
931 def get_hierarchy(self):
937 def get_residue_ranges(self):
940 def get_length(self):
943 def get_restraint(self):
946 def get_output(self):
949 score = self.rs.unprotected_evaluate(
None)
950 output[
"_TotalScore"] = str(score)
951 output[
"UpperBound_" + self.label] = str(score)
957 class ExcludedVolumeResidue(object):
959 def __init__(self, prot, kappa):
964 self.m = self.prot.get_model()
974 lsa.add_particles(atoms)
977 self.rs.add_restraint(evr)
979 def set_label(self, label):
982 def add_excluded_particle_pairs(self, excluded_particle_pairs):
985 lpc.add_particle_pairs(excluded_particle_pairs)
987 IMP.core.ExcludedVolumeRestraint.get_from(
988 self.rs.get_restraints()[0]).add_pair_filter(icpf)
990 def add_to_model(self):
991 self.m.add_restraint(self.rs)
993 def get_hierarchy(self):
999 def get_restraint(self):
1002 def get_output(self):
1005 score = self.rs.unprotected_evaluate(
None)
1006 output[
"_TotalScore"] = str(score)
1007 output[
"ExcludedVolumeResidue_" + self.label] = str(score)
1013 class BipartiteExcludedVolumeResidue(object):
1015 def __init__(self, prot1, prot2, kappa):
1021 self.m = self.prot.get_model()
1025 ls1.add_particles(atoms1)
1035 ls2.add_particles(atoms2)
1050 self.rs.add_restraint(evr3)
1051 self.m.add_restraint(rs)
1053 def set_label(self, label):
1056 def add_to_model(self):
1057 self.m.add_restraint(self.rs)
1059 def get_hierarchy(self):
1060 return self.prot1, self.prot2
1062 def get_kappa(self):
1065 def get_restraint(self):
1068 def get_output(self):
1071 score = self.rs.unprotected_evaluate(
None)
1072 output[
"_TotalScore"] = str(score)
1073 output[
"BipartiteExcludedVolumeResidue_" + self.label] = str(score)
1079 class TemplateRestraint(object):
1081 def __init__(self, ps1, ps2, cutoff=6.5, kappa=1.0, forcerb=False):
1082 self.m = ps1[0].get_model()
1084 self.cutoff = cutoff
1087 self.forcerb = forcerb
1098 if dist <= self.cutoff:
1102 self.rs.add_restraint(pr)
1104 def set_label(self, label):
1107 def add_to_model(self):
1108 self.m.add_restraint(self.rs)
1110 def get_cutoff(self):
1113 def get_kappa(self):
1116 def get_restraint(self):
1119 def get_output(self):
1122 score = self.rs.unprotected_evaluate(
None)
1123 output[
"_TotalScore"] = str(score)
1124 output[
"TemplateRestraint_" + self.label] = str(score)
1130 class MarginalChi3Restraint(object):
1132 def __init__(self, part1, part2):
1133 global impisd2, tools
1134 import IMP.isd2
as impisd2
1137 self.m = part1.get_model()
1140 self.sigmamaxtrans = 0.1
1144 self.sigma = tools.SetupNuisance(
1152 for i
in range(len(self.ps1)):
1153 mc = impisd2.MarginalChi3Restraint(
1157 self.rs.add_restraint(mc)
1159 def set_label(self, label):
1162 def add_to_model(self):
1163 self.m.add_restraint(self.rs)
1165 def get_restraint(self):
1168 def get_particles_to_sample(self):
1170 ps[
"Nuisances_MarginalChi3Restraint_Sigma_" +
1171 self.label] = ([self.sigma], self.sigmamaxtrans)
1174 def get_output(self):
1177 score = self.rs.unprotected_evaluate(
None)
1178 output[
"_TotalScore"] = str(score)
1179 output[
"MarginalChi3Restraint_" + self.label] = str(score)
1180 output[
"MarginalChi3Restraint_Sigma_" +
1181 self.label] = str(self.sigma.get_scale())
1190 this class initialize a CrossLinkMS restraint and contains
1191 all useful informations, such as the cross-link database, contained in self.pairs
1192 If restraint_file=None, it will proceed creating simulated data
1195 def __init__(self, prots,
1196 listofxlinkertypes=[
"BS3",
"BS2G",
"EGS"], map_between_protein_names_and_chains=
None,
1197 sigmamin=1.0, sigmamax=1.0, sigmagrid=1, sigmaissampled=
False, typeofprofile=
"gofr"):
1198 global impisd2, tools
1199 import IMP.isd2
as impisd2
1202 if map_between_protein_names_and_chains
is None:
1203 map_between_protein_names_and_chains = {}
1210 self.m = self.prots[0].get_model()
1211 self.sigmamin = sigmamin
1212 self.sigmamax = sigmamax
1213 self.sigmagrid = sigmagrid
1214 self.sigmaissampled = sigmaissampled
1216 self.sigmatrans = 0.1
1217 self.sigmaglobal = tools.SetupNuisance(self.m, self.sigmamin,
1218 self.sigmamin, self.sigmamax, self.sigmaissampled).get_particle()
1219 self.outputlevel =
"low"
1220 self.listofxlinkertypes = listofxlinkertypes
1222 self.reaction_rates =
None
1223 self.allpairs_database =
None
1224 self.residue_list =
None
1226 self.crosslinker_dict = self.get_crosslinker_dict(typeofprofile)
1229 self.mbpnc = map_between_protein_names_and_chains
1233 def get_crosslinker_dict(self, typeofprofile="gofr"):
1238 disttuple = (0.0, 200.0, 1000)
1239 omegatuple = (1.0, 1000.0, 30)
1240 sigmatuple = (self.sigmamin, self.sigmamax, self.sigmagrid)
1242 crosslinker_dict = {}
1243 if "BS3" in self.listofxlinkertypes:
1244 crosslinker_dict[
"BS3"] = tools.get_cross_link_data(
"bs3l",
1245 "pmf_bs3l_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1246 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1247 if "BS2G" in self.listofxlinkertypes:
1248 crosslinker_dict[
"BS2G"] = tools.get_cross_link_data(
"bs2gl",
1249 "pmf_bs2gl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1250 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1251 if "EGS" in self.listofxlinkertypes:
1252 crosslinker_dict[
"EGS"] = tools.get_cross_link_data(
"egl",
1253 "pmf_egl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1254 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1255 if "Short" in self.listofxlinkertypes:
1257 crosslinker_dict[
"Short"] = tools.get_cross_link_data_from_length(
1262 return crosslinker_dict
1268 if restraint_file
is None:
1270 restraint_list = self.allpairs_database
1274 f = open(restraint_file)
1275 restraint_list = f.readlines()
1279 self.added_pairs_list = []
1280 self.missing_residues = []
1281 for line
in restraint_list:
1284 force_restraint =
False
1286 if restraint_file
is None:
1287 if line[
"Is_Detected"]:
1288 crosslinker = line[
"Crosslinker"]
1289 (r1, c1) = line[
"Identified_Pair1"]
1290 (r2, c2) = line[
"Identified_Pair2"]
1296 tokens = line.split()
1298 if (tokens[0] ==
"#"):
1304 crosslinker = tokens[4]
1307 self.index = int(tokens[5])
1311 if (tokens[len(tokens) - 1] ==
"F"):
1312 force_restraint =
True
1316 totallist = eval(line)
1317 self.add_crosslink_according_to_new_file(totallist)
1321 print(
'''CrossLinkMS: attempting to add restraint between
1322 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2))
1332 atom_type=IMP.atom.AT_CA)
1333 p1 = (s1.get_selected_particles()[0])
1335 print(
"CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
1342 atom_type=IMP.atom.AT_CA)
1343 p2 = (s2.get_selected_particles()[0])
1345 print(
"CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
1348 for copy
in self.prots:
1353 atom_type=IMP.atom.AT_CA)
1354 p1s.append(s1.get_selected_particles()[0])
1359 atom_type=IMP.atom.AT_CA)
1360 p2s.append(s2.get_selected_particles()[0])
1367 print(
'''CrossLinkMS: WARNING> residue %d of chain %s and
1368 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2))
1373 if (p1s[0], p2s[0], crosslinker)
in self.added_pairs_list:
1374 print(
"CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
1376 if (p2s[0], p1s[0], crosslinker)
in self.added_pairs_list:
1377 print(
"CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
1380 print(
"CrossLinkMS: added pair %d %s %d %s" % (r1, c1, r2, c2))
1381 self.added_pairs_list.append((p1s[0], p2s[0], crosslinker))
1383 rs_name =
'restraint_' + str(index)
1385 ln = impisd2.CrossLinkMSRestraint(
1387 self.crosslinker_dict[crosslinker])
1388 for i
in range(len(p1s)):
1389 ln.add_contribution(p1s[i], p2s[i])
1391 for i
in range(len(self.prots)):
1392 self.pairs.append((p1s[i], p2s[i],
1393 crosslinker, rs_name,
1394 100, 100, (r1, c1, i), (r2, c2, i),
1395 crosslinker, i, ln))
1397 self.rs.add_restraint(ln)
1400 self.rs2.add_restraint(
1401 impisd2.UniformPrior(self.sigmaglobal,
1403 self.sigmaglobal.get_upper() - 1.0,
1404 self.sigmaglobal.get_lower() + 0.1))
1405 print(
"CrossLinkMS: missing residues")
1406 for ms
in self.missing_residues:
1407 print(
"CrossLinkMS:missing " + str(ms))
1410 def add_crosslink_according_to_new_file(self, totallist):
1411 force_restraint =
False
1412 ambiguous_list = totallist[0]
1413 crosslinker = totallist[1]
1414 if (totallist[2] ==
"F"):
1415 force_restraint =
True
1424 for pair
in ambiguous_list:
1428 c1 = self.mbpnc[pair[0][0]]
1430 "CrossLinkMS: WARNING> protein name " + \
1431 pair[0][0] +
" was not defined"
1434 c2 = self.mbpnc[pair[1][0]]
1436 "CrossLinkMS: WARNING> protein name " + \
1437 pair[1][0] +
" was not defined"
1439 r1 = int(pair[0][1])
1440 r2 = int(pair[1][1])
1442 print(
'''CrossLinkMS: attempting to add restraint between
1443 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2))
1450 atom_type=IMP.atom.AT_CA)
1451 p1 = (s1.get_selected_particles()[0])
1453 print(
"CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1))
1455 self.missing_residues.append((r1, c1))
1461 atom_type=IMP.atom.AT_CA)
1462 p2 = (s2.get_selected_particles()[0])
1464 print(
"CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2))
1466 self.missing_residues.append((r2, c2))
1474 atom_type=IMP.atom.AT_CA)
1475 p1 = s1.get_selected_particles()[0]
1480 atom_type=IMP.atom.AT_CA)
1481 p2 = s2.get_selected_particles()[0]
1484 if (p1, p2, crosslinker)
in self.added_pairs_list:
1485 print(
"CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
1487 if (p2, p1, crosslinker)
in self.added_pairs_list:
1488 print(
"CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
1496 print(
'''CrossLinkMS: WARNING> residue %d of chain %s and
1497 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2))
1507 print(
"CrossLinkMS: added pair %d %s %d %s" % (r1, c1, r2, c2))
1509 self.added_pairs_list.append((p1, p2, crosslinker))
1512 rs_name =
'{:05}'.format(self.index % 100000)
1514 ln = impisd2.CrossLinkMSRestraint(
1516 self.crosslinker_dict[crosslinker])
1517 for i
in range(len(p1s)):
1519 ln.add_contribution(p1s[i], p2s[i])
1520 self.pairs.append((p1s[i], p2s[i], crosslinker, rs_name,
1521 100, 100, (r1s[i], c1s[i], i), (r2s[i], c2s[i], i), crosslinker, i, ln))
1522 self.rs.add_restraint(ln)
1526 def simulate_data(self, crosslinker, weights, sensitivity_threshold=0.1,
1527 false_positive_half=0.02, elapsed_time=0.01,
1528 ratemin=100, ratemax=100):
1530 from random
import choice
1531 from random
import randrange
1532 from itertools
import combinations
1533 from numpy.random
import binomial
1535 self.weights = weights
1536 self.sensitivity_threshold = sensitivity_threshold
1537 self.false_positive_half = false_positive_half
1538 self.elapsed_time = elapsed_time
1539 self.ratemin = ratemin
1540 self.ratemax = ratemax
1544 if self.reaction_rates
is None:
1545 self.reaction_rates = {}
1550 atom_type=IMP.atom.AT_CA)
1551 self.residue_list = []
1553 for p1
in s0.get_selected_particles():
1554 (r1, c1) = tools.get_residue_index_and_chain_from_particle(p1)
1555 self.residue_list.append((r1, c1))
1556 if self.ratemin != self.ratemax:
1557 self.reaction_rates[(
1559 c1)] = randrange(self.ratemin,
1563 self.reaction_rates[(r1, c1)] = self.ratemax
1565 if self.allpairs_database
is None:
1566 self.allpairs_database = []
1569 allcomb = list(combinations(self.residue_list, 2))
1570 for ((r1, c1), (r2, c2))
in allcomb:
1575 for copy
in self.prots:
1577 chains=c1, atom_type=IMP.atom.AT_CA)
1578 p1s.append(s1.get_selected_particles()[0])
1580 chains=c2, atom_type=IMP.atom.AT_CA)
1581 p2s.append(s2.get_selected_particles()[0])
1583 ln = impisd2.CrossLinkMSRestraint(
1585 self.crosslinker_dict[crosslinker])
1586 for i
in range(len(p1s)):
1587 ln.add_contribution(p1s[i], p2s[i])
1591 reactionrate1 = self.reaction_rates[(r1, c1)]
1592 reactionrate2 = self.reaction_rates[(r2, c2)]
1593 prob = ln.get_marginal_probabilities()[i]
1594 effrate = float(reactionrate1 * reactionrate2) / \
1595 (reactionrate1 + reactionrate2)
1596 probt = self.weights[i] * \
1597 (1 - exp(-effrate * prob * elapsed_time))
1598 falsepositiveprob = exp(-probt / false_positive_half)
1599 falsepositivebool =
False
1600 falsepositive = binomial(n=1, p=falsepositiveprob)
1601 if (falsepositive == 1):
1602 falsepositivebool =
True
1603 randompair = choice(allcomb)
1604 randpair1 = randompair[0]
1605 randpair2 = randompair[1]
1607 randpair1 = (r1, c1)
1608 randpair2 = (r2, c2)
1609 if (probt > sensitivity_threshold):
1612 detectedbool =
False
1614 self.allpairs_database.append({})
1615 self.allpairs_database[-1][
"Particle1"] = p1s[i]
1616 self.allpairs_database[-1][
"Particle2"] = p2s[i]
1617 self.allpairs_database[-1][
"Distance"] = dist
1618 self.allpairs_database[-1][
"Crosslinker"] = crosslinker
1619 self.allpairs_database[-1][
"IMPRestraint"] = ln
1620 self.allpairs_database[-1][
"IMPRestraint_Probability"] = prob
1621 self.allpairs_database[-1][
"Reaction_Rate1"] = reactionrate1
1622 self.allpairs_database[-1][
"Reaction_Rate2"] = reactionrate2
1623 self.allpairs_database[-1][
"Effective_Rate"] = effrate
1624 self.allpairs_database[-1][
"CrossLink_Fraction"] = probt
1625 self.allpairs_database[
1626 -1][
"Resid1_Chainid1_Copy1"] = (r1, c1, i)
1627 self.allpairs_database[
1628 -1][
"Resid2_Chainid2_Copy2"] = (r2, c2, i)
1629 self.allpairs_database[
1630 -1][
"Is_False_Positive"] = falsepositivebool
1631 self.allpairs_database[-1][
"Identified_Pair1"] = randpair1
1632 self.allpairs_database[-1][
"Identified_Pair2"] = randpair2
1633 self.allpairs_database[-1][
"Is_Detected"] = detectedbool
1635 def set_hierarchy(self, prots):
1639 def initialize_simulated_database(self):
1641 self.allpairs_database =
None
1643 def get_number_detected_inter(self, xl_type):
1647 for el
in self.allpairs_database:
1648 if el[
"Is_Detected"]
and \
1649 ( el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1] )
and \
1650 el[
"Crosslinker"] == xl_type:
1654 def get_number_detected_inter_false_positive(self, xl_type):
1658 for el
in self.allpairs_database:
1659 if el[
"Is_Detected"]
and \
1660 ( el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1] )
and \
1661 el[
"Crosslinker"] == xl_type
and el[
"Is_False_Positive"]:
1665 def show_simulated_data(self, what="Inter"):
1667 if not self.allpairs_database
is None:
1669 for el
in self.allpairs_database:
1671 if el[
"Is_Detected"]:
1672 p1 = el[
"Identified_Pair1"]
1673 p2 = el[
"Identified_Pair2"]
1674 isf = el[
"Is_False_Positive"]
1676 el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1])
1677 cl = el[
"Crosslinker"]
1678 detectedlist.append((p1, p2, isf, cl, isinter))
1680 if el[
"Is_Detected"]
and what ==
"Detected":
1682 if el[
"Is_Detected"]
and el[
"Is_False_Positive"]
and what ==
"FalsePositive":
1684 if el[
"Is_Detected"]
and el[
"Is_False_Positive"] ==
False and what ==
"TruePositive":
1686 if el[
"Is_Detected"]
and what ==
"Intra" and \
1687 (el[
"Identified_Pair1"][1] == el[
"Identified_Pair2"][1]):
1689 if el[
"Is_Detected"]
and what ==
"Inter" and \
1690 (el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1]):
1696 print(
"Residue1: %6s, chainid1: %6s, copy1: %6d" % el[
"Resid1_Chainid1_Copy1"])
1697 print(
"Residue2: %6s, chainid2: %6s, copy2: %6d" % el[
"Resid2_Chainid2_Copy2"])
1698 keylist = list(el.keys())
1701 print(
"----", k, el[k])
1702 print(
"r1 c1 r2 c2 FP XL Inter")
1703 for d
in detectedlist:
1704 print(d[0][0], d[0][1], d[1][0], d[1][1], d[2], d[3], d[4])
1706 print(
"CrossLinkMS: Simulated data not initialized")
1709 def dump_simulated_data(self, filename="simulated_cross_link.dat"):
1711 sclf = open(filename,
"w")
1712 for el
in self.allpairs_database:
1717 def write_simulated_data(self, filename="detected_cross_link.dat"):
1719 sclf = open(filename,
"w")
1721 for el
in self.allpairs_database:
1722 if el[
"Is_Detected"]:
1724 p1 = el[
"Identified_Pair1"]
1725 p2 = el[
"Identified_Pair2"]
1726 isf = el[
"Is_False_Positive"]
1727 cl = el[
"Crosslinker"]
1741 def set_label(self, label):
1744 def add_to_model(self):
1745 self.m.add_restraint(self.rs)
1746 self.m.add_restraint(self.rs2)
1748 def get_hierarchies(self):
1752 return self.sigmaglobal
1754 def get_restraint_sets(self):
1755 return self.rs, self.rs2
1757 def get_restraint(self):
1759 tmprs.add_restraint(self.rs)
1760 tmprs.add_restraint(self.rs2)
1763 def set_output_level(self, level="low"):
1765 self.outputlevel = level
1767 def print_chimera_pseudobonds(self, filesuffix, model=0):
1768 f = open(filesuffix +
".chimera",
"w")
1770 for p
in self.pairs:
1771 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
1772 " #" + str(model) +
":" + \
1773 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
1777 def get_particles_to_sample(self):
1779 if self.sigmaissampled:
1780 ps[
"Nuisances_CrossLinkMS_Sigma_" +
1781 self.label] = ([self.sigmaglobal], self.sigmatrans)
1784 def get_output(self):
1789 score = self.rs.unprotected_evaluate(
None)
1790 score2 = self.rs2.unprotected_evaluate(
None)
1791 output[
"_TotalScore"] = str(score + score2)
1793 output[
"CrossLinkMS_Likelihood_" + self.label] = str(score)
1794 output[
"CrossLinkMS_Prior_" + self.label] = str(score2)
1795 output[
"CrossLinkMS_Sigma"] = str(self.sigmaglobal.get_scale())
1797 if self.outputlevel ==
"high":
1798 for i
in range(len(self.pairs)):
1800 p0 = self.pairs[i][0]
1801 p1 = self.pairs[i][1]
1802 crosslinker = self.pairs[i][2]
1803 ln = self.pairs[i][10]
1804 index = self.pairs[i][9]
1805 rsname = self.pairs[i][3]
1806 resid1 = self.pairs[i][6][0]
1807 chain1 = self.pairs[i][6][1]
1808 copy1 = self.pairs[i][6][2]
1809 resid2 = self.pairs[i][7][0]
1810 chain2 = self.pairs[i][7][1]
1811 copy2 = self.pairs[i][7][2]
1812 label_copy = str(rsname) +
":" + str(index) +
"-" + str(resid1) + \
1813 ":" + chain1 +
"_" +
"-" + \
1814 str(resid2) +
":" + chain2 +
"_" + crosslinker
1815 output[
"CrossLinkMS_Partial_Probability_" +
1816 label_copy] = str(ln.get_marginal_probabilities()[index])
1819 label = str(resid1) +
":" + chain1 + \
1820 "_" + str(resid2) +
":" + chain2
1822 output[
"CrossLinkMS_Score_" +
1823 str(rsname) +
"_" + crosslinker +
"_" + label] = str(ln.unprotected_evaluate(
None))
1827 output[
"CrossLinkMS_Distance_" +
1835 class BinomialXLMSRestraint(object):
1837 def __init__(self, m, prots,
1838 listofxlinkertypes=[
"BS3",
"BS2G",
"EGS"], map_between_protein_names_and_chains=
None, typeofprofile=
'pfes'):
1840 if map_between_protein_names_and_chains
is None:
1841 map_between_protein_names_and_chains = {}
1843 global impisd2, tools, exp
1844 import IMP.isd2
as impisd2
1856 self.weightmaxtrans = 0.05
1857 self.weightissampled =
False
1859 self.sigmainit = 5.0
1861 self.sigmaminnuis = 0.0
1862 self.sigmamax = 10.0
1863 self.sigmamaxnuis = 11.0
1865 self.sigmaissampled =
True
1866 self.sigmamaxtrans = 0.1
1872 self.betaissampled =
True
1873 print(
"BinomialXLMSRestraint: beta is sampled")
1875 self.betaissampled =
False
1876 print(
"BinomialXLMSRestraint: beta is NOT sampled")
1877 self.betamaxtrans = 0.01
1880 self.deltainit=0.001
1883 self.deltaissampled=False
1884 self.deltamaxtrans=0.001
1888 self.lamminnuis=0.00001
1890 self.lammaxnuis=100.0
1891 self.lamissampled=False
1892 self.lammaxtrans=0.1
1896 self.psi_dictionary = {}
1898 self.sigma = tools.SetupNuisance(self.m, self.sigmainit,
1899 self.sigmaminnuis, self.sigmamaxnuis, self.sigmaissampled).get_particle()
1901 self.beta = tools.SetupNuisance(self.m, self.betainit,
1902 self.betamin, self.betamax, self.betaissampled).get_particle()
1905 self.delta=tools.SetupNuisance(self.m,self.deltainit,
1906 self.deltamin,self.deltamax,self.deltaissampled).get_particle()
1908 self.lam=tools.SetupNuisance(self.m,self.laminit,
1909 self.lamminnuis,self.lammaxnuis,self.lamissampled).get_particle()
1911 self.weight=tools.SetupWeight(m,False).get_particle()
1913 for n in range(len(self.prots)):
1914 self.weight.add_weight()
1916 self.outputlevel =
"low"
1917 self.listofxlinkertypes = listofxlinkertypes
1919 self.reaction_rates =
None
1920 self.allpairs_database =
None
1921 self.residue_list =
None
1923 self.crosslinker_dict = self.get_crosslinker_dict(typeofprofile)
1926 self.mbpnc = map_between_protein_names_and_chains
1929 def create_psi(self, index, value):
1932 self.psiissampled =
True
1933 print(
"BinomialXLMSRestraint: psi " + str(index) +
" is sampled")
1935 self.psiinit = value
1936 self.psiissampled =
False
1937 print(
"BinomialXLMSRestraint: psi " + str(index) +
" is NOT sampled")
1938 self.psiminnuis = 0.0000001
1939 self.psimaxnuis = 0.4999999
1942 self.psitrans = 0.01
1943 self.psi = tools.SetupNuisance(self.m, self.psiinit,
1944 self.psiminnuis, self.psimaxnuis, self.psiissampled).get_particle()
1945 self.psi_dictionary[index] = (
1950 def get_psi(self, index, value):
1951 if not index
in self.psi_dictionary:
1952 self.create_psi(index, value)
1953 return self.psi_dictionary[index]
1955 def get_crosslinker_dict(self, typeofprofile):
1960 disttuple = (0.0, 200.0, 500)
1961 omegatuple = (0.01, 1000.0, 30)
1962 sigmatuple = (self.sigmamin, self.sigmamax, self.nsigma)
1964 crosslinker_dict = {}
1965 if "BS3" in self.listofxlinkertypes:
1966 crosslinker_dict[
"BS3"] = tools.get_cross_link_data(
"bs3l",
1967 "pmf_bs3l_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1968 if "BS2G" in self.listofxlinkertypes:
1969 crosslinker_dict[
"BS2G"] = tools.get_cross_link_data(
"bs2gl",
1970 "pmf_bs2gl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1971 if "EGS" in self.listofxlinkertypes:
1972 crosslinker_dict[
"EGS"] = tools.get_cross_link_data(
"egl",
1973 "pmf_egl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1974 if "Short" in self.listofxlinkertypes:
1976 crosslinker_dict[
"Short"] = tools.get_cross_link_data_from_length(
1981 return crosslinker_dict
1986 f = open(restraint_file)
1987 restraint_list = f.readlines()
1991 self.added_pairs_list = []
1992 self.missing_residues = []
1993 for line
in restraint_list:
1996 force_restraint =
False
1999 totallist = eval(line)
2000 self.add_crosslink_according_to_new_file(totallist)
2002 self.rs2.add_restraint(
2003 impisd2.UniformPrior(
2010 for psiindex
in self.psi_dictionary:
2011 if self.psi_dictionary[psiindex][2]:
2012 psip = self.psi_dictionary[psiindex][0]
2015 print(
"BinomialXLMSRestraint: setup 0, adding BinomialJeffreysPrior to psi particle " + str(psiindex))
2016 self.rs2.add_restraint(impisd2.BinomialJeffreysPrior(psip))
2019 self.rs2.add_restraint(
2020 impisd2.UniformPrior(
2026 def add_crosslink_according_to_new_file(self, totallist, constructor=0):
2030 force_restraint =
False
2031 ambiguous_list = totallist[0]
2032 crosslinker = totallist[1]
2033 if (totallist[2] ==
"F"):
2034 force_restraint =
True
2045 for pair
in ambiguous_list:
2049 c1 = self.mbpnc[pair[0][0]]
2051 print(
"BinomialXLMSRestraint: WARNING> protein name " + pair[0][0] +
" was not defined")
2054 c2 = self.mbpnc[pair[1][0]]
2056 print(
"BinomialXLMSRestraint: WARNING> protein name " + pair[1][0] +
" was not defined")
2059 r1 = int(pair[0][1])
2060 r2 = int(pair[1][1])
2061 psi = float(pair[2])
2063 psivalue = float(pair[3])
2067 print(
'''CrossLinkMS: attempting to add restraint between
2068 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2))
2075 atom_type=IMP.atom.AT_CA)
2076 p1 = (s1.get_selected_particles()[0])
2078 print(
"BinomialXLMSRestraint: WARNING> residue %d of chain %s is not there" % (r1, c1))
2080 self.missing_residues.append((r1, c1))
2086 atom_type=IMP.atom.AT_CA)
2087 p2 = (s2.get_selected_particles()[0])
2089 print(
"BinomialXLMSRestraint: WARNING> residue %d of chain %s is not there" % (r2, c2))
2091 self.missing_residues.append((r2, c2))
2099 atom_type=IMP.atom.AT_CA)
2100 p1 = s1.get_selected_particles()[0]
2105 atom_type=IMP.atom.AT_CA)
2106 p2 = s2.get_selected_particles()[0]
2109 if (p1, p2, crosslinker)
in self.added_pairs_list:
2110 print(
"BinomialXLMSRestraint: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
2112 if (p2, p1, crosslinker)
in self.added_pairs_list:
2113 print(
"BinomialXLMSRestraint: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
2121 print(
'''BinomialXLMSRestraint: WARNING> residue %d of chain %s and
2122 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2))
2132 psivalues.append(psivalue)
2134 print(
"BinomialXLMSRestraint: added pair %d %s %d %s" % (r1, c1, r2, c2))
2136 self.added_pairs_list.append((p1, p2, crosslinker))
2139 rs_name =
'{:05}'.format(self.index % 100000)
2142 print(
"BinomialXLMSRestraint: constructor 0")
2143 ln = impisd2.BinomialCrossLinkMSRestraint(
2147 self.crosslinker_dict[crosslinker])
2150 print(
"BinomialXLMSRestraint: constructor 1")
2151 ln = impisd2.BinomialCrossLinkMSRestraint(
2156 self.crosslinker_dict[crosslinker])
2158 for i
in range(len(p1s)):
2159 ln.add_contribution()
2161 psi = self.get_psi(psis[i], psivalues[i])
2163 ln.add_particle_pair(
2168 self.pairs.append((p1s[i], p2s[i], crosslinker, rs_name,
2169 self.index, 100, (r1s[i], c1s[i], i), (r2s[i], c2s[i], i), crosslinker, i, ln))
2175 self.rs2.add_restraint(pr)
2177 self.rs.add_restraint(ln)
2179 print(
"BinomialXLMSRestraint: missing residues")
2180 for ms
in self.missing_residues:
2181 print(
"BinomialXLMSRestraint:missing " + str(ms))
2187 def set_label(self, label):
2190 def add_to_model(self):
2191 self.m.add_restraint(self.rs)
2192 self.m.add_restraint(self.rs2)
2194 def get_hierarchies(self):
2198 return self.sigmaglobal
2200 def get_restraint_sets(self):
2201 return self.rs, self.rs2
2203 def get_restraint(self):
2205 tmprs.add_restraint(self.rs)
2206 tmprs.add_restraint(self.rs2)
2209 def set_output_level(self, level="low"):
2211 self.outputlevel = level
2213 def print_chimera_pseudobonds(self, filesuffix, model=0):
2214 f = open(filesuffix +
".chimera",
"w")
2216 for p
in self.pairs:
2217 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2218 " #" + str(model) +
":" + \
2219 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2223 def print_chimera_pseudobonds_with_psiindexes(self, filesuffix, model=0):
2225 f = open(filesuffix +
".chimera",
"w")
2227 for p
in self.pairs:
2228 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2229 " #" + str(model) +
":" + \
2230 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2234 def get_output(self):
2239 score = self.rs.unprotected_evaluate(
None)
2240 score2 = self.rs2.unprotected_evaluate(
None)
2241 output[
"_TotalScore"] = str(score + score2)
2242 output[
"CrossLinkMS_Likelihood_" + self.label] = str(score)
2243 output[
"CrossLinkMS_Prior_" + self.label] = str(score2)
2245 if self.outputlevel ==
"high":
2246 for i
in range(len(self.pairs)):
2248 p0 = self.pairs[i][0]
2249 p1 = self.pairs[i][1]
2250 crosslinker = self.pairs[i][2]
2251 psiindex = self.pairs[i][4]
2252 ln = self.pairs[i][10]
2253 index = self.pairs[i][9]
2254 rsname = self.pairs[i][3]
2255 resid1 = self.pairs[i][6][0]
2256 chain1 = self.pairs[i][6][1]
2257 copy1 = self.pairs[i][6][2]
2258 resid2 = self.pairs[i][7][0]
2259 chain2 = self.pairs[i][7][1]
2260 copy2 = self.pairs[i][7][2]
2261 label_copy = str(rsname) +
":" + str(index) +
"-" + str(resid1) + \
2262 ":" + chain1 +
"_" +
"-" + \
2263 str(resid2) +
":" + chain2 +
"_" + crosslinker
2266 label = str(resid1) +
":" + chain1 + \
2267 "_" + str(resid2) +
":" + chain2
2269 output[
"CrossLinkMS_Score_" + str(rsname) +
"_" + str(index) +
"_" +
2270 crosslinker +
"_" + label] = str(ln.unprotected_evaluate(
None))
2274 output[
"CrossLinkMS_Distance_" +
2277 output[
"CrossLinkMS_Sigma_" + self.label] = str(self.sigma.get_scale())
2279 output["CrossLinkMS_Delta_"+self.label]=str(self.delta.get_scale())
2280 output["CrossLinkMS_Lambda_"+self.label]=str(self.lam.get_scale())
2282 output[
"CrossLinkMS_Beta_" + self.label] = str(self.beta.get_scale())
2283 for psiindex
in self.psi_dictionary:
2284 output[
"CrossLinkMS_Psi_" +
2285 str(psiindex) +
"_" + self.label] = str(self.psi_dictionary[psiindex][0].get_scale())
2287 for n in range(self.weight.get_number_of_states()):
2288 output["CrossLinkMS_weights_"+str(n)+"_"+self.label]=str(self.weight.get_weight(n))
2292 def get_particles_to_sample(self):
2294 if self.sigmaissampled:
2295 ps[
"Nuisances_CrossLinkMS_Sigma_" +
2296 self.label] = ([self.sigma], self.sigmamaxtrans)
2298 if self.deltaissampled:
2299 ps["Nuisances_CrossLinkMS_Delta_"+self.label]=([self.delta],self.deltamaxtrans)
2300 if self.lamissampled:
2301 ps["Nuisances_CrossLinkMS_Lambda_"+self.label]=([self.lam],self.lammaxtrans)
2303 if self.betaissampled:
2304 ps[
"Nuisances_CrossLinkMS_Beta_" +
2305 self.label] = ([self.beta], self.betamaxtrans)
2307 for psiindex
in self.psi_dictionary:
2308 if self.psi_dictionary[psiindex][2]:
2309 ps[
"Nuisances_CrossLinkMS_Psi_" +
2310 str(psiindex) +
"_" + self.label] = ([self.psi_dictionary[psiindex][0]], self.psi_dictionary[psiindex][1])
2313 if self.weightissampled:
2314 ps["Weights_CrossLinkMS_"+self.label]=([self.weight],self.weightmaxtrans)
2321 class CrossLinkMSSimple(object):
2323 def __init__(self, prot, restraints_file, TruncatedHarmonic=True):
2324 """read crosslink restraints between two residue
2325 of different chains from an external text file
2326 syntax: part_name_1 part_name_2 distance error
2327 example: 0 1 1.0 0.1"""
2331 self.m = self.prot.get_model()
2337 if TruncatedHarmonic:
2350 addedd_pairs_list = []
2351 for line
in open(restraints_file):
2355 force_restraint =
True
2356 tokens = line.split()
2359 if (tokens[0] ==
"#"):
2365 crosslinker = tokens[4]
2368 index = int(tokens[5])
2372 if (tokens[len(tokens) - 1] ==
"F"):
2373 force_restraint =
True
2375 print(
"attempting to add restraint between residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2))
2386 atom_type=IMP.atom.AT_CA)
2387 p1 = (s1.get_selected_particles()[0])
2389 print(
"WARNING> residue %d of chain %s is not there" % (r1, c1))
2396 atom_type=IMP.atom.AT_CA)
2397 p2 = (s2.get_selected_particles()[0])
2399 print(
"WARNING> residue %d of chain %s is not there" % (r2, c2))
2411 print(
"attempting to add restraint between residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2))
2416 print(
"WARNING> residue %d of chain %s and residue %d of chain %s belong to the same rigid body" % (r1, c1, r2, c2))
2421 if (p1, p2, crosslinker)
in addedd_pairs_list:
2422 print(
"WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
2424 if (p2, p1, crosslinker)
in addedd_pairs_list:
2425 print(
"WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2))
2428 print(
"added pair %d %s %d %s" % (r1, c1, r2, c2))
2430 addedd_pairs_list.append((p1, p2, crosslinker))
2432 rs_name =
'restraint_' + str(index)
2435 ln.set_name(
"CrossLinkMSSimple_" + str(r1)
2436 +
":" + str(c1) +
"-" + str(r2) +
":" + str(c2))
2439 self.rs.add_restraint(ln)
2443 self.rs.add_restraint(pr)
2460 def set_label(self, label):
2463 def add_to_model(self):
2464 self.m.add_restraint(self.rs)
2466 def get_restraint(self):
2469 def print_chimera_pseudobonds(self, filesuffix, model=0):
2470 f = open(filesuffix +
".chimera",
"w")
2472 for p
in self.pairs:
2473 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2474 " #" + str(model) +
":" + \
2475 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2479 def get_output(self):
2484 score = self.rs.unprotected_evaluate(
None)
2485 output[
"_TotalScore"] = str(score)
2486 output[
"CrossLinkMSSimple_Score_" + self.label] = str(score)
2487 for i
in range(len(self.pairs)):
2489 p0 = self.pairs[i][0]
2490 p1 = self.pairs[i][1]
2491 crosslinker = self.pairs[i][2]
2492 ln = self.pairs[i][9]
2493 pr = self.pairs[i][10]
2494 resid1 = self.pairs[i][6][0]
2495 chain1 = self.pairs[i][6][1]
2496 resid2 = self.pairs[i][7][0]
2497 chain2 = self.pairs[i][7][1]
2499 label = str(resid1) +
":" + chain1 +
"_" + \
2500 str(resid2) +
":" + chain2
2501 output[
"CrossLinkMSSimple_Score_" + crosslinker +
2502 "_" + label] = str(ln.unprotected_evaluate(
None))
2503 output[
"CrossLinkMSSimple_Score_Linear_" + crosslinker +
2504 "_" + label] = str(pr.unprotected_evaluate(
None))
2507 output[
"CrossLinkMSSimple_Distance_" +
2513 def get_residue_index_and_chain_from_particle(p):
2520 def select_calpha_or_residue(
2525 SelectResidue=
False):
2529 residue_index=resid, atom_type=IMP.atom.AT_CA)
2531 ps = s.get_selected_particles()
2537 print(ObjectName +
" multiple residues selected for selection residue %s chain %s " % (resid, chain))
2541 residue_index=resid)
2542 ps = s.get_selected_particles()
2548 print(ObjectName +
" multiple residues selected for selection residue %s chain %s " % (resid, chain))
2551 print(ObjectName +
" residue %s chain %s does not exist" % (resid, chain))
static Residue setup_particle(kernel::Model *m, ParticleIndex pi, ResidueType t, int index, int insertion_code)
A filter which returns true if a container containers the Pair.
double get_volume_from_residue_type(ResidueType rt)
Return an estimate for the volume of a given residue.
A function that is harmonic over an interval.
void show_molecular_hierarchy(Hierarchy h)
Print out the molecular hierarchy.
static RigidBody setup_particle(kernel::Model *m, ParticleIndex pi, kernel::ParticleIndexesAdaptor ps)
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
static Atom setup_particle(kernel::Model *m, ParticleIndex pi, Atom other)
Upper bound harmonic function (non-zero when feature > mean)
Select atoms which are selected by both selectors.
double get_drmsd(const Vector3DsOrXYZs0 &m0, const Vector3DsOrXYZs1 &m1)
Calculate distance the root mean square deviation between two sets of 3D points.
Rotation3D get_random_rotation_3d(const Rotation3D ¢er, double distance)
Pick a rotation at random near the provided one.
void add_restraints(RMF::FileHandle fh, const kernel::Restraints &hs)
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
Color get_rgb_color(double f)
Return the color for f from the RGB color map.
Object used to hold a set of restraints.
double get_ball_radius_from_volume_3d(double volume)
Return the radius of a sphere with a given volume.
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
kernel::RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, kernel::RestraintSet *rs)
Return all close ordered pairs of particles taken from the two SingletonContainers.
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Vector3D get_random_vector_in(const Cylinder3D &c)
Generate a random vector in a cylinder with uniform density.
Classes to handle different kinds of restraints.
A class to store an fixed array of same-typed values.
Store a kernel::ParticleIndexPairs.
Select all non-alternative ATOM records.
static XYZR setup_particle(kernel::Model *m, ParticleIndex pi)
static Molecule setup_particle(kernel::Model *m, ParticleIndex pi)
double get_volume_from_mass(double m, ProteinDensityReference ref=ALBER)
Estimate the volume of a protein from its mass.
static Hierarchy setup_particle(kernel::Model *m, kernel::ParticleIndex pi, kernel::ParticleIndexesAdaptor children=kernel::ParticleIndexesAdaptor())
Store a kernel::ParticleIndexes.
A decorator for a particle representing an atom.
Hierarchies get_by_type(Hierarchy mhd, GetByType t)
static Colored setup_particle(kernel::Model *m, ParticleIndex pi, Color color)
A decorator for a particle with x,y,z coordinates.
static Chain setup_particle(kernel::Model *m, ParticleIndex pi, std::string id)
Class to handle individual model particles.
void destroy(Hierarchy d)
Delete the Hierarchy.
this class initialize a CrossLinkMS restraint and contains all useful informations, such as the cross-link database, contained in self.pairs If restraint_file=None, it will proceed creating simulated data
A decorator for a residue.
static bool get_is_setup(const IMP::kernel::ParticleAdaptor &p)
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
Prevent a set of particles and rigid bodies from inter-penetrating.
static Fragment setup_particle(kernel::Model *m, ParticleIndex pi)
Store info for a chain of a protein.
Applies a PairScore to a Pair.
Select all CA ATOM records.
void read_pdb(base::TextInput input, int model, Hierarchy h)
Hierarchies get_leaves(const Selection &h)
Select hierarchy particles identified by the biological name.
Applies a PairScore to each Pair in a list.
ResidueType get_residue_type(char c)
Get the residue type from the 1-letter amino acid code.
Harmonic function (symmetric about the mean)
A decorator for a particle with x,y,z coordinates and a radius.