1 """@namespace IMP.pmi.nonmaintained
11 self.rigid_bodies = []
12 self.floppy_bodies = []
13 self.maxtrans_rb = 2.0
14 self.maxtrans_fb = 2.0
17 def add_protein(self, name, (firstres, lastres)):
18 from math
import pi, cos, sin
21 nres = lastres - firstres
22 radius = (nres) * 5 / 2 / pi
24 for res
in range(firstres, lastres):
25 alpha = 2 * pi / nres * (res - firstres)
26 x = radius * cos(alpha)
27 y = radius * sin(alpha)
32 d.set_coordinates_are_optimized(
True)
34 self.hier.add_child(h)
36 def get_hierarchy(self):
39 def set_rod(self, chainname, (firstres, lastres)):
44 residue_indexes=range(
47 ps = sel.get_selected_particles()
49 self.rigid_bodies.append(rb)
51 def get_particles_to_sample(self):
56 ps[
"Floppy_Bodies_Rods"] = (self.floppy_bodies, self.maxtrans_fb)
57 ps[
"Rigid_Bodies_Rods"] = (
66 def __init__(self, m):
71 self.floppy_bodies = []
72 self.maxtrans_fb = 0.2
73 self.particle_database = {}
75 def add_bead(self, radius, label="None", color=None):
79 self.particle_database[label] = p
80 self.floppy_bodies.append(p)
84 d.set_coordinates_are_optimized(
True)
91 self.hier.add_child(p)
93 self.set_color(label, color)
94 return self.particle_database[label]
96 def set_color(self, label, value):
97 p = self.particle_database[label]
101 def set_floppy_bodies_max_trans(self, maxtrans):
102 self.maxtrans_fb = maxtrans
104 def get_hierarchy(self):
107 def get_bead(self, label):
108 return self.particle_database[label]
110 def set_maxtrans_fb(self, maxtrans_fb):
111 self.maxtrans_fb = maxtrans_fb
113 def get_particles_to_sample(self):
118 ps[
"Floppy_Bodies_Beads"] = (self.floppy_bodies, self.maxtrans_fb)
122 class MultipleStates(object):
124 def __init__(self, nstates, m):
125 global itertools, tools, restraints
129 import IMP.pmi.restraints
as restraints
131 self.floppy_bodies = []
132 self.rigid_bodies = []
133 for ncopy
in range(nstates):
134 self.floppy_bodies.append([])
135 self.rigid_bodies.append([])
137 self.rigid_bodies_are_sampled =
True
138 self.floppy_bodies_are_sampled =
True
141 self.prot_lowres = {}
142 self.nstates = nstates
146 self.xyzmodellist = []
148 self.maxtrans_rb = 0.15
149 self.maxrot_rb = 0.03
150 self.maxtrans_fb = 0.15
156 def set_label(self, label):
159 def set_rigid_bodies_are_sampled(self, input=True):
160 self.rigid_bodies_are_sampled = input
162 def set_floppy_bodies_are_sampled(self, input=True):
163 self.floppy_bodies_are_sampled = input
165 def get_rigid_bodies(self):
166 return self.rigid_bodies
168 def set_rigid_bodies_max_trans(self, maxtrans):
169 self.maxtrans_rb = maxtrans
171 def set_rigid_bodies_max_rot(self, maxrot):
172 self.maxrot_rb = maxrot
174 def set_floppy_bodies_max_trans(self, maxtrans):
175 self.maxtrans_fb = maxtrans
177 def get_hierarchies(self):
180 def destroy_residues(self, segments):
183 for prot
in self.prot:
184 for segment
in segments:
186 if (segment[0] == -1
or segment[1] == -1):
192 residue_indexes=range(segment[0],
194 for p
in s.get_selected_particles():
196 print "MultipleStates: one particle was not destroied because it was a RigidMember."
206 def add_residues_to_chains(
209 residue_type=IMP.atom.LYS):
213 for rc
in residuechainlist:
219 atom_type=IMP.atom.AT_CA)
221 print s.get_selected_particles()
222 if len(s.get_selected_particles()) == 0:
223 for prot
in self.prot:
224 print "adding " + str(rc)
229 d.set_coordinates_are_optimized(
True)
238 print tools.get_residue_index_and_chain_from_particle(a)
241 p = s.get_selected_particles()[0]
243 print rc, s.get_selected_particles()[0]
250 atom_type=IMP.atom.AT_CA)
252 print s.get_selected_particles()
254 def add_beads(self, segments, xyzs=None, radii=None, colors=None):
256 this method generate beads in missing portions.
257 The segments argument must be a list of selections
258 in the form [(firstres,lastres,chain)]
259 each selection will generate a bead
270 for n, s
in enumerate(segments):
275 for prot
in self.prot:
276 for prot
in self.prot:
280 if chain.get_id() == chainid:
283 rindexes = range(firstres, lasteres + 1)
284 f.set_residue_indexes(rindexes)
286 "Fragment_" +
'%i-%i' %
289 mass = len(rindexes) * 110.0
291 if n + 1 > len(radii):
292 mass = len(rindexes) * 110.0
294 radius = (3 * vol / math.pi) ** (1 / 3)
298 if n + 1 > len(xyzs):
307 if n + 1 <= len(colors):
311 d = IMP.atom.XYZR.setup_particle(
314 def renumber_residues(self, chainid, newfirstresiduenumber):
315 for prot
in self.prot:
319 ps = c.get_children()
322 offs = newfirstresiduenumber - ri
326 r.set_index(ri + offs)
328 def destroy_everything_but_the_residues(self, segments):
330 for prot
in self.prot:
332 for segment
in segments:
335 if (segment[0] == -1
or segment[1] == -1):
341 residue_indexes=range(segment[0],
343 pstokeep += s.get_selected_particles()
346 if p
not in pstokeep:
348 print "MultipleStates: one particle was not destroied because it was a RigidMember."
357 def generate_linkers_restraint_and_floppy_bodies(self, segment):
359 this methods automatically links the particles consecutively
360 according to the sequence. The restraint applied is a harmonic upper bound,
361 with a distance that is proportional to the number of residues
366 linker_restraint_objects = []
367 for ncopy, prot
in enumerate(self.prot):
368 if (segment[0] == -1
or segment[1] == -1):
374 residue_indexes=range(segment[0],
377 for p
in s.get_selected_particles():
379 (r, c) = tools.get_residue_index_and_chain_from_particle(p)
384 (r, c) = tools.get_residue_index_and_chain_from_particle(p)
385 p.set_name(str(r) +
":" + str(c))
386 tools.set_floppy_body(p)
387 self.floppy_bodies[ncopy].append(p)
389 residue_indexes.append((r, Floppy, c, p))
391 residue_indexes.sort()
393 pruned_residue_list = []
394 r0 = residue_indexes[0]
395 pruned_residue_list.append(r0)
399 for i
in range(1, len(residue_indexes)):
400 r = residue_indexes[i]
404 pruned_residue_list.append(r0)
405 pruned_residue_list.append(r)
407 elif r[1] != r0[1]
and r0[1] ==
False:
408 pruned_residue_list.append(r0)
409 pruned_residue_list.append(r)
411 elif r[1] == r0[1]
and r0[1]:
412 pruned_residue_list.append(r)
414 elif r[1] != r0[1]
and r[1] ==
False:
415 pruned_residue_list.append(r)
418 r0 = pruned_residue_list[0]
421 for i
in range(1, len(pruned_residue_list)):
422 r = pruned_residue_list[i]
426 linkdomaindef.append((r0[0], r[0], r[2]))
429 print " creating linker between atoms defined by: " + str(linkdomaindef)
431 ld = restraints.LinkDomains(prot, linkdomaindef, 1.0, 3.0)
432 ld.set_label(str(ncopy))
434 linker_restraint_objects.append(ld)
437 return linker_restraint_objects
439 def get_ref_hierarchies(self):
442 def get_number_of_states(self):
445 def get_rigid_bodies(self):
447 for rbl
in self.rigid_bodies:
452 def get_floppy_bodies(self):
454 for fbl
in self.floppy_bodies:
459 def set_rigid_bodies(self, rigid_body_list):
460 if len(self.prot) == 0:
461 print "MultipleStates.set_rigid_bodies: hierarchy was not initialized"
463 for ncopy, prot
in enumerate(self.prot):
465 for element
in rigid_body_list:
467 for interval
in element:
471 if (interval[0] == -1
or interval[1] == -1):
477 residue_indexes=range(interval[0],
479 for p
in s.get_selected_particles():
483 for key
in self.prot_lowres:
484 if (interval[0] == -1
or interval[1] == -1):
486 self.prot_lowres[key][ncopy],
490 self.prot_lowres[key][
491 ncopy], chains=interval[2],
492 residue_indexes=range(interval[0], interval[1] + 1))
493 for p
in s.get_selected_particles():
499 rb.set_name(str(element))
502 print "MultipleStates.set_rigid_bodies: selection " + str(interval) +
" has zero elements"
503 self.rigid_bodies[ncopy] += rbl
505 def set_floppy_bodies(self, floppy_body_list):
508 if len(self.prot) == 0:
509 print "MultipleStates: hierarchy was not initialized"
512 for ncopy, prot
in enumerate(self.prot):
514 for element
in floppy_body_list:
516 for interval
in element:
520 if (interval[0] == -1
or interval[1] == -1):
526 residue_indexes=range(interval[0],
528 for p
in s.get_selected_particles():
529 (r, c) = tools.get_residue_index_and_chain_from_particle(
531 tools.set_floppy_body(p)
532 p.set_name(str(r) +
":" + str(c))
534 self.floppy_bodies[ncopy] += atoms
536 def get_particles_to_sample(self):
541 rblist = self.get_rigid_bodies()
542 fblist = self.get_floppy_bodies()
543 if self.rigid_bodies_are_sampled:
544 ps[
"Rigid_Bodies_MultipleStates"] = (
548 if self.floppy_bodies_are_sampled:
549 ps[
"Floppy_Bodies_MultipleStates"] = (fblist, self.maxtrans_fb)
552 def set_hierarchy_from_pdb(self, pdblistoflist):
553 "the input is a list of list of pdbs"
554 "one list for each copy"
556 for copy
in range(0, self.nstates):
557 prot = self.read_pdbs(pdblistoflist[copy])
558 self.prot.append(prot)
560 self.xyzmodellist.append(xyz)
562 def set_ref_hierarchy_from_pdb(self, pdblistoflist):
563 "the input is a list of list of pdbs"
564 "one list for each copy"
566 for copy
in range(0, self.nstates):
567 prot = self.read_pdbs(pdblistoflist[copy])
568 self.refprot.append(prot)
570 self.xyzreflist.append(xyz)
572 def read_pdbs(self, list_pdb_file):
573 """read pdbs from an external list file
574 create a simplified representation
575 if the pdbs are given a individual strings, it will read the
576 pdbs and give the chain name as specified in the pdb
577 If it s a tuple like (filename,chainname) it will read
578 the pdb and assing a name chainname
583 for pdb
in list_pdb_file:
591 #destroy CA atoms, for the future
592 for p in IMP.atom.get_leaves(h):
593 coor=IMP.core.XYZ(p).get_coordinates()
594 r=IMP.atom.Hierarchy(p).get_parent()
595 IMP.core.XYZ.setup_particle(r,coor)
602 #consolidate the chains
605 s0=IMP.atom.Selection(hier, chains=cid)
607 p=s0.get_selected_particles()[0]
608 re=IMP.atom.Residue(IMP.atom.Atom(p).get_parent()
609 ch=IMP.atom.Chain(re).get_parent())
616 if type(pdb) == tuple:
623 #destroy CA atoms, for the future
624 for p in IMP.atom.get_leaves(h):
625 coor=IMP.core.XYZ(p).get_coordinates()
626 r=IMP.atom.Hierarchy(p).get_parent()
627 IMP.core.XYZ.setup_particle(r,coor)
638 def recenter(self, prot):
639 "recenter the hierarchy"
641 center = IMP.algebra.get_zero_vector_3d()
647 d.set_coordinates(d.get_coordinates() - center)
648 d.set_coordinates_are_optimized(
True)
651 # bug generating code: keeping it for history
653 rb=IMP.atom.create_rigid_body(prot)
654 rbcoord=rb.get_coordinates()
655 rot=IMP.algebra.get_identity_rotation_3d()
656 tmptrans=IMP.algebra.Transformation3D(rot,rbcoord)
657 trans=tmptrans.get_inverse()
658 IMP.core.transform(rb,trans)
659 IMP.core.RigidBody.teardown_particle(rb)
660 self.m.remove_particle(rb)
663 def shuffle_configuration(self, bounding_box_length):
664 "shuffle configuration, used to restart the optimization"
665 "it only works if rigid bodies were initialized"
666 if len(self.rigid_bodies) == 0:
667 print "MultipleStates: rigid bodies were not intialized"
668 hbbl = bounding_box_length / 2
669 for rbl
in self.rigid_bodies:
679 rb.set_reference_frame(
682 def generate_simplified_hierarchy(self, nres):
684 self.prot_lowres[nres] = []
685 for prot
in self.prot:
693 self.prot_lowres[nres].append(sh)
695 def get_simplified_hierarchy(self, nres):
696 return self.prot_lowres[nres]
698 def calculate_drms(self):
701 if len(self.xyzmodellist) == 0:
702 print "MultipleStates: hierarchies were not intialized"
704 if len(self.xyzreflist) == 0:
705 print "MultipleStates: reference hierarchies were not intialized"
708 for i
in range(len(self.xyzreflist)):
709 for j
in range(len(self.xyzmodellist)):
712 self.xyzmodellist[j],
715 drmsdval = tools.get_drmsd(
716 self.xyzmodellist[j],
718 drmsd[
"MultipleStates_DRMSD_" +
719 str(i) +
"-Model_" + str(j)] = drmsdval
723 for assign
in itertools.permutations(range(len(self.xyzreflist))):
725 for i, j
in enumerate(assign):
726 s += drmsd[
"MultipleStates_DRMSD_" +
727 str(j) +
"-Model_" + str(i)]
730 drmsd[
"MultipleStates_Total_DRMSD"] = min(min_drmsd)
733 def get_output(self):
735 if len(self.refprot) != 0:
736 drms = self.calculate_drms()
738 output[
"MultipleStates_Total_Score_" +
739 self.label] = str(self.m.evaluate(
False))
745 class LinkDomains(object):
747 def __init__(self, prot, resrangelist, kappa, length=5.0):
756 self.resrangelist = resrangelist
760 self.m = self.prot.get_model()
763 for pair
in self.resrangelist:
773 atom_type=IMP.atom.AT_CA)
774 p0 = s0.get_selected_particles()[0]
783 atom_type=IMP.atom.AT_CA)
784 p1 = s1.get_selected_particles()[0]
790 dist0 = float(pair[1] - pair[0]) * self.length
795 "LinkDomains_" + str(pair[0]) +
"-" + str(pair[1]) +
"_" + str(pair[2]))
796 self.rs.add_restraint(pr)
797 self.pairs.append((p0, p1, r0, c0, r1, c1, pr))
799 def set_label(self, label):
802 def add_to_model(self):
803 self.m.add_restraint(self.rs)
808 def get_hierarchy(self):
814 def get_residue_ranges(self):
815 return self.resrangelist
817 def get_length(self):
820 def get_restraint(self):
825 for r
in self.rs.get_restraints():
826 rlist.append(IMP.core.PairRestraint.get_from(r))
829 def print_chimera_pseudobonds(self, filesuffix, model=0):
830 f = open(filesuffix +
".chimera",
"w")
833 s =
"#" + str(model) +
":" + str(p[2]) +
"." + p[3] +
"@" + atype + \
834 " #" + str(model) +
":" + str(p[4]) +
"." + p[5] +
"@" + atype
838 def get_output(self):
841 score = self.rs.unprotected_evaluate(
None)
842 output[
"_TotalScore"] = str(score)
843 output[
"LinkDomains_" + self.label] = str(score)
844 for rst
in self.rs.get_restraints():
848 output[
"LinkDomains_" + rst.get_name() +
849 "_" + self.label] = rst.unprotected_evaluate(
None)
851 for i
in range(len(self.pairs)):
853 p0 = self.pairs[i][0]
854 p1 = self.pairs[i][1]
855 r0 = self.pairs[i][2]
856 c0 = self.pairs[i][3]
857 r1 = self.pairs[i][4]
858 c1 = self.pairs[i][5]
860 label = str(r0) +
":" + c0 +
"_" + str(r1) +
":" + c1
864 output[
"LinkDomains_Distance_" + label +
"_" +
873 class UpperBound(object):
875 def __init__(self, prot, respairs, kappa, length=5.0):
885 self.respairs = respairs
889 self.m = self.prot.get_model()
891 for pair
in self.respairs:
896 residue_index=pair[0],
897 atom_type=IMP.atom.AT_CA)
898 p0 = s0.get_selected_particles()[0]
906 residue_index=pair[2],
907 atom_type=IMP.atom.AT_CA)
908 p1 = s1.get_selected_particles()[0]
919 "UpperBound_" + str(pair[0]) +
"-" + str(pair[1]) +
"_" + str(pair[2]))
920 self.rs.add_restraint(pr)
922 def set_label(self, label):
925 def add_to_model(self):
926 self.m.add_restraint(self.rs)
928 def get_hierarchy(self):
934 def get_residue_ranges(self):
937 def get_length(self):
940 def get_restraint(self):
943 def get_output(self):
946 score = self.rs.unprotected_evaluate(
None)
947 output[
"_TotalScore"] = str(score)
948 output[
"UpperBound_" + self.label] = str(score)
954 class ExcludedVolumeResidue(object):
956 def __init__(self, prot, kappa):
961 self.m = self.prot.get_model()
971 lsa.add_particles(atoms)
974 self.rs.add_restraint(evr)
976 def set_label(self, label):
979 def add_excluded_particle_pairs(self, excluded_particle_pairs):
982 lpc.add_particle_pairs(excluded_particle_pairs)
984 IMP.core.ExcludedVolumeRestraint.get_from(
985 self.rs.get_restraints()[0]).add_pair_filter(icpf)
987 def add_to_model(self):
988 self.m.add_restraint(self.rs)
990 def get_hierarchy(self):
996 def get_restraint(self):
999 def get_output(self):
1002 score = self.rs.unprotected_evaluate(
None)
1003 output[
"_TotalScore"] = str(score)
1004 output[
"ExcludedVolumeResidue_" + self.label] = str(score)
1010 class BipartiteExcludedVolumeResidue(object):
1012 def __init__(self, prot1, prot2, kappa):
1018 self.m = self.prot.get_model()
1022 ls1.add_particles(atoms1)
1032 ls2.add_particles(atoms2)
1047 self.rs.add_restraint(evr3)
1048 self.m.add_restraint(rs)
1050 def set_label(self, label):
1053 def add_to_model(self):
1054 self.m.add_restraint(self.rs)
1056 def get_hierarchy(self):
1057 return self.prot1, self.prot2
1059 def get_kappa(self):
1062 def get_restraint(self):
1065 def get_output(self):
1068 score = self.rs.unprotected_evaluate(
None)
1069 output[
"_TotalScore"] = str(score)
1070 output[
"BipartiteExcludedVolumeResidue_" + self.label] = str(score)
1076 class TemplateRestraint(object):
1078 def __init__(self, ps1, ps2, cutoff=6.5, kappa=1.0, forcerb=False):
1079 self.m = ps1[0].get_model()
1081 self.cutoff = cutoff
1084 self.forcerb = forcerb
1095 if dist <= self.cutoff:
1099 self.rs.add_restraint(pr)
1101 def set_label(self, label):
1104 def add_to_model(self):
1105 self.m.add_restraint(self.rs)
1107 def get_cutoff(self):
1110 def get_kappa(self):
1113 def get_restraint(self):
1116 def get_output(self):
1119 score = self.rs.unprotected_evaluate(
None)
1120 output[
"_TotalScore"] = str(score)
1121 output[
"TemplateRestraint_" + self.label] = str(score)
1127 class MarginalChi3Restraint(object):
1129 def __init__(self, part1, part2):
1130 global impisd2, tools
1131 import IMP.isd2
as impisd2
1134 self.m = part1.get_model()
1137 self.sigmamaxtrans = 0.1
1141 self.sigma = tools.SetupNuisance(
1149 for i
in range(len(self.ps1)):
1150 mc = impisd2.MarginalChi3Restraint(
1154 self.rs.add_restraint(mc)
1156 def set_label(self, label):
1159 def add_to_model(self):
1160 self.m.add_restraint(self.rs)
1162 def get_restraint(self):
1165 def get_particles_to_sample(self):
1167 ps[
"Nuisances_MarginalChi3Restraint_Sigma_" +
1168 self.label] = ([self.sigma], self.sigmamaxtrans)
1171 def get_output(self):
1174 score = self.rs.unprotected_evaluate(
None)
1175 output[
"_TotalScore"] = str(score)
1176 output[
"MarginalChi3Restraint_" + self.label] = str(score)
1177 output[
"MarginalChi3Restraint_Sigma_" +
1178 self.label] = str(self.sigma.get_scale())
1187 this class initialize a CrossLinkMS restraint and contains
1188 all useful informations, such as the cross-link database, contained in self.pairs
1189 If restraint_file=None, it will proceed creating simulated data
1192 def __init__(self, prots,
1193 listofxlinkertypes=[
"BS3",
"BS2G",
"EGS"], map_between_protein_names_and_chains=
None,
1194 sigmamin=1.0, sigmamax=1.0, sigmagrid=1, sigmaissampled=
False, typeofprofile=
"gofr"):
1195 global impisd2, tools
1196 import IMP.isd2
as impisd2
1199 if map_between_protein_names_and_chains
is None:
1200 map_between_protein_names_and_chains = {}
1207 self.m = self.prots[0].get_model()
1208 self.sigmamin = sigmamin
1209 self.sigmamax = sigmamax
1210 self.sigmagrid = sigmagrid
1211 self.sigmaissampled = sigmaissampled
1213 self.sigmatrans = 0.1
1214 self.sigmaglobal = tools.SetupNuisance(self.m, self.sigmamin,
1215 self.sigmamin, self.sigmamax, self.sigmaissampled).get_particle()
1216 self.outputlevel =
"low"
1217 self.listofxlinkertypes = listofxlinkertypes
1219 self.reaction_rates =
None
1220 self.allpairs_database =
None
1221 self.residue_list =
None
1223 self.crosslinker_dict = self.get_crosslinker_dict(typeofprofile)
1226 self.mbpnc = map_between_protein_names_and_chains
1230 def get_crosslinker_dict(self, typeofprofile="gofr"):
1235 disttuple = (0.0, 200.0, 1000)
1236 omegatuple = (1.0, 1000.0, 30)
1237 sigmatuple = (self.sigmamin, self.sigmamax, self.sigmagrid)
1239 crosslinker_dict = {}
1240 if "BS3" in self.listofxlinkertypes:
1241 crosslinker_dict[
"BS3"] = tools.get_cross_link_data(
"bs3l",
1242 "pmf_bs3l_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1243 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1244 if "BS2G" in self.listofxlinkertypes:
1245 crosslinker_dict[
"BS2G"] = tools.get_cross_link_data(
"bs2gl",
1246 "pmf_bs2gl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1247 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1248 if "EGS" in self.listofxlinkertypes:
1249 crosslinker_dict[
"EGS"] = tools.get_cross_link_data(
"egl",
1250 "pmf_egl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple,
1251 don=
None, doff=
None, prior=0, type_of_profile=typeofprofile)
1252 if "Short" in self.listofxlinkertypes:
1254 crosslinker_dict[
"Short"] = tools.get_cross_link_data_from_length(
1259 return crosslinker_dict
1265 if restraint_file
is None:
1267 restraint_list = self.allpairs_database
1271 f = open(restraint_file)
1272 restraint_list = f.readlines()
1276 self.added_pairs_list = []
1277 self.missing_residues = []
1278 for line
in restraint_list:
1281 force_restraint =
False
1283 if restraint_file
is None:
1284 if line[
"Is_Detected"]:
1285 crosslinker = line[
"Crosslinker"]
1286 (r1, c1) = line[
"Identified_Pair1"]
1287 (r2, c2) = line[
"Identified_Pair2"]
1293 tokens = line.split()
1295 if (tokens[0] ==
"#"):
1301 crosslinker = tokens[4]
1304 self.index = int(tokens[5])
1308 if (tokens[len(tokens) - 1] ==
"F"):
1309 force_restraint =
True
1313 totallist = eval(line)
1314 self.add_crosslink_according_to_new_file(totallist)
1318 print '''CrossLinkMS: attempting to add restraint between
1319 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2)
1329 atom_type=IMP.atom.AT_CA)
1330 p1 = (s1.get_selected_particles()[0])
1332 print "CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1)
1339 atom_type=IMP.atom.AT_CA)
1340 p2 = (s2.get_selected_particles()[0])
1342 print "CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2)
1345 for copy
in self.prots:
1350 atom_type=IMP.atom.AT_CA)
1351 p1s.append(s1.get_selected_particles()[0])
1356 atom_type=IMP.atom.AT_CA)
1357 p2s.append(s2.get_selected_particles()[0])
1364 print '''CrossLinkMS: WARNING> residue %d of chain %s and
1365 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2)
1370 if (p1s[0], p2s[0], crosslinker)
in self.added_pairs_list:
1371 print "CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
1373 if (p2s[0], p1s[0], crosslinker)
in self.added_pairs_list:
1374 print "CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
1377 print "CrossLinkMS: added pair %d %s %d %s" % (r1, c1, r2, c2)
1378 self.added_pairs_list.append((p1s[0], p2s[0], crosslinker))
1380 rs_name =
'restraint_' + str(index)
1382 ln = impisd2.CrossLinkMSRestraint(
1384 self.crosslinker_dict[crosslinker])
1385 for i
in range(len(p1s)):
1386 ln.add_contribution(p1s[i], p2s[i])
1388 for i
in range(len(self.prots)):
1389 self.pairs.append((p1s[i], p2s[i],
1390 crosslinker, rs_name,
1391 100, 100, (r1, c1, i), (r2, c2, i),
1392 crosslinker, i, ln))
1394 self.rs.add_restraint(ln)
1397 self.rs2.add_restraint(
1398 impisd2.UniformPrior(self.sigmaglobal,
1400 self.sigmaglobal.get_upper() - 1.0,
1401 self.sigmaglobal.get_lower() + 0.1))
1402 print "CrossLinkMS: missing residues"
1403 for ms
in self.missing_residues:
1404 print "CrossLinkMS:missing " + str(ms)
1407 def add_crosslink_according_to_new_file(self, totallist):
1408 force_restraint =
False
1409 ambiguous_list = totallist[0]
1410 crosslinker = totallist[1]
1411 if (totallist[2] ==
"F"):
1412 force_restraint =
True
1421 for pair
in ambiguous_list:
1425 c1 = self.mbpnc[pair[0][0]]
1427 "CrossLinkMS: WARNING> protein name " + \
1428 pair[0][0] +
" was not defined"
1431 c2 = self.mbpnc[pair[1][0]]
1433 "CrossLinkMS: WARNING> protein name " + \
1434 pair[1][0] +
" was not defined"
1436 r1 = int(pair[0][1])
1437 r2 = int(pair[1][1])
1439 print '''CrossLinkMS: attempting to add restraint between
1440 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2)
1447 atom_type=IMP.atom.AT_CA)
1448 p1 = (s1.get_selected_particles()[0])
1450 print "CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r1, c1)
1452 self.missing_residues.append((r1, c1))
1458 atom_type=IMP.atom.AT_CA)
1459 p2 = (s2.get_selected_particles()[0])
1461 print "CrossLinkMS: WARNING> residue %d of chain %s is not there" % (r2, c2)
1463 self.missing_residues.append((r2, c2))
1471 atom_type=IMP.atom.AT_CA)
1472 p1 = s1.get_selected_particles()[0]
1477 atom_type=IMP.atom.AT_CA)
1478 p2 = s2.get_selected_particles()[0]
1481 if (p1, p2, crosslinker)
in self.added_pairs_list:
1482 print "CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
1484 if (p2, p1, crosslinker)
in self.added_pairs_list:
1485 print "CrossLinkMS: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
1493 print '''CrossLinkMS: WARNING> residue %d of chain %s and
1494 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2)
1504 print "CrossLinkMS: added pair %d %s %d %s" % (r1, c1, r2, c2)
1506 self.added_pairs_list.append((p1, p2, crosslinker))
1509 rs_name =
'{:05}'.format(self.index % 100000)
1511 ln = impisd2.CrossLinkMSRestraint(
1513 self.crosslinker_dict[crosslinker])
1514 for i
in range(len(p1s)):
1516 ln.add_contribution(p1s[i], p2s[i])
1517 self.pairs.append((p1s[i], p2s[i], crosslinker, rs_name,
1518 100, 100, (r1s[i], c1s[i], i), (r2s[i], c2s[i], i), crosslinker, i, ln))
1519 self.rs.add_restraint(ln)
1523 def simulate_data(self, crosslinker, weights, sensitivity_threshold=0.1,
1524 false_positive_half=0.02, elapsed_time=0.01,
1525 ratemin=100, ratemax=100):
1527 from random
import choice
1528 from random
import randrange
1529 from itertools
import combinations
1530 from numpy.random
import binomial
1532 self.weights = weights
1533 self.sensitivity_threshold = sensitivity_threshold
1534 self.false_positive_half = false_positive_half
1535 self.elapsed_time = elapsed_time
1536 self.ratemin = ratemin
1537 self.ratemax = ratemax
1541 if self.reaction_rates
is None:
1542 self.reaction_rates = {}
1547 atom_type=IMP.atom.AT_CA)
1548 self.residue_list = []
1550 for p1
in s0.get_selected_particles():
1551 (r1, c1) = tools.get_residue_index_and_chain_from_particle(p1)
1552 self.residue_list.append((r1, c1))
1553 if self.ratemin != self.ratemax:
1554 self.reaction_rates[(
1556 c1)] = randrange(self.ratemin,
1560 self.reaction_rates[(r1, c1)] = self.ratemax
1562 if self.allpairs_database
is None:
1563 self.allpairs_database = []
1566 allcomb = list(combinations(self.residue_list, 2))
1567 for ((r1, c1), (r2, c2))
in allcomb:
1572 for copy
in self.prots:
1574 chains=c1, atom_type=IMP.atom.AT_CA)
1575 p1s.append(s1.get_selected_particles()[0])
1577 chains=c2, atom_type=IMP.atom.AT_CA)
1578 p2s.append(s2.get_selected_particles()[0])
1580 ln = impisd2.CrossLinkMSRestraint(
1582 self.crosslinker_dict[crosslinker])
1583 for i
in range(len(p1s)):
1584 ln.add_contribution(p1s[i], p2s[i])
1588 reactionrate1 = self.reaction_rates[(r1, c1)]
1589 reactionrate2 = self.reaction_rates[(r2, c2)]
1590 prob = ln.get_marginal_probabilities()[i]
1591 effrate = float(reactionrate1 * reactionrate2) / \
1592 (reactionrate1 + reactionrate2)
1593 probt = self.weights[i] * \
1594 (1 - exp(-effrate * prob * elapsed_time))
1595 falsepositiveprob = exp(-probt / false_positive_half)
1596 falsepositivebool =
False
1597 falsepositive = binomial(n=1, p=falsepositiveprob)
1598 if (falsepositive == 1):
1599 falsepositivebool =
True
1600 randompair = choice(allcomb)
1601 randpair1 = randompair[0]
1602 randpair2 = randompair[1]
1604 randpair1 = (r1, c1)
1605 randpair2 = (r2, c2)
1606 if (probt > sensitivity_threshold):
1609 detectedbool =
False
1611 self.allpairs_database.append({})
1612 self.allpairs_database[-1][
"Particle1"] = p1s[i]
1613 self.allpairs_database[-1][
"Particle2"] = p2s[i]
1614 self.allpairs_database[-1][
"Distance"] = dist
1615 self.allpairs_database[-1][
"Crosslinker"] = crosslinker
1616 self.allpairs_database[-1][
"IMPRestraint"] = ln
1617 self.allpairs_database[-1][
"IMPRestraint_Probability"] = prob
1618 self.allpairs_database[-1][
"Reaction_Rate1"] = reactionrate1
1619 self.allpairs_database[-1][
"Reaction_Rate2"] = reactionrate2
1620 self.allpairs_database[-1][
"Effective_Rate"] = effrate
1621 self.allpairs_database[-1][
"CrossLink_Fraction"] = probt
1622 self.allpairs_database[
1623 -1][
"Resid1_Chainid1_Copy1"] = (r1, c1, i)
1624 self.allpairs_database[
1625 -1][
"Resid2_Chainid2_Copy2"] = (r2, c2, i)
1626 self.allpairs_database[
1627 -1][
"Is_False_Positive"] = falsepositivebool
1628 self.allpairs_database[-1][
"Identified_Pair1"] = randpair1
1629 self.allpairs_database[-1][
"Identified_Pair2"] = randpair2
1630 self.allpairs_database[-1][
"Is_Detected"] = detectedbool
1632 def set_hierarchy(self, prots):
1636 def initialize_simulated_database(self):
1638 self.allpairs_database =
None
1640 def get_number_detected_inter(self, xl_type):
1644 for el
in self.allpairs_database:
1645 if el[
"Is_Detected"]
and \
1646 ( el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1] )
and \
1647 el[
"Crosslinker"] == xl_type:
1651 def get_number_detected_inter_false_positive(self, xl_type):
1655 for el
in self.allpairs_database:
1656 if el[
"Is_Detected"]
and \
1657 ( el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1] )
and \
1658 el[
"Crosslinker"] == xl_type
and el[
"Is_False_Positive"]:
1662 def show_simulated_data(self, what="Inter"):
1664 if not self.allpairs_database
is None:
1666 for el
in self.allpairs_database:
1668 if el[
"Is_Detected"]:
1669 p1 = el[
"Identified_Pair1"]
1670 p2 = el[
"Identified_Pair2"]
1671 isf = el[
"Is_False_Positive"]
1673 el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1])
1674 cl = el[
"Crosslinker"]
1675 detectedlist.append((p1, p2, isf, cl, isinter))
1677 if el[
"Is_Detected"]
and what ==
"Detected":
1679 if el[
"Is_Detected"]
and el[
"Is_False_Positive"]
and what ==
"FalsePositive":
1681 if el[
"Is_Detected"]
and el[
"Is_False_Positive"] ==
False and what ==
"TruePositive":
1683 if el[
"Is_Detected"]
and what ==
"Intra" and \
1684 (el[
"Identified_Pair1"][1] == el[
"Identified_Pair2"][1]):
1686 if el[
"Is_Detected"]
and what ==
"Inter" and \
1687 (el[
"Identified_Pair1"][1] != el[
"Identified_Pair2"][1]):
1693 print "Residue1: %6s, chainid1: %6s, copy1: %6d" % el[
"Resid1_Chainid1_Copy1"]
1694 print "Residue2: %6s, chainid2: %6s, copy2: %6d" % el[
"Resid2_Chainid2_Copy2"]
1698 print "----", k, el[k]
1699 print "r1 c1 r2 c2 FP XL Inter"
1700 for d
in detectedlist:
1701 print d[0][0], d[0][1], d[1][0], d[1][1], d[2], d[3], d[4]
1703 print "CrossLinkMS: Simulated data not initialized"
1706 def dump_simulated_data(self, filename="simulated_cross_link.dat"):
1708 sclf = open(filename,
"w")
1709 for el
in self.allpairs_database:
1714 def write_simulated_data(self, filename="detected_cross_link.dat"):
1716 sclf = open(filename,
"w")
1718 for el
in self.allpairs_database:
1719 if el[
"Is_Detected"]:
1721 p1 = el[
"Identified_Pair1"]
1722 p2 = el[
"Identified_Pair2"]
1723 isf = el[
"Is_False_Positive"]
1724 cl = el[
"Crosslinker"]
1738 def set_label(self, label):
1741 def add_to_model(self):
1742 self.m.add_restraint(self.rs)
1743 self.m.add_restraint(self.rs2)
1745 def get_hierarchies(self):
1749 return self.sigmaglobal
1751 def get_restraint_sets(self):
1752 return self.rs, self.rs2
1754 def get_restraint(self):
1756 tmprs.add_restraint(self.rs)
1757 tmprs.add_restraint(self.rs2)
1760 def set_output_level(self, level="low"):
1762 self.outputlevel = level
1764 def print_chimera_pseudobonds(self, filesuffix, model=0):
1765 f = open(filesuffix +
".chimera",
"w")
1767 for p
in self.pairs:
1768 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
1769 " #" + str(model) +
":" + \
1770 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
1774 def get_particles_to_sample(self):
1776 if self.sigmaissampled:
1777 ps[
"Nuisances_CrossLinkMS_Sigma_" +
1778 self.label] = ([self.sigmaglobal], self.sigmatrans)
1781 def get_output(self):
1786 score = self.rs.unprotected_evaluate(
None)
1787 score2 = self.rs2.unprotected_evaluate(
None)
1788 output[
"_TotalScore"] = str(score + score2)
1790 output[
"CrossLinkMS_Likelihood_" + self.label] = str(score)
1791 output[
"CrossLinkMS_Prior_" + self.label] = str(score2)
1792 output[
"CrossLinkMS_Sigma"] = str(self.sigmaglobal.get_scale())
1794 if self.outputlevel ==
"high":
1795 for i
in range(len(self.pairs)):
1797 p0 = self.pairs[i][0]
1798 p1 = self.pairs[i][1]
1799 crosslinker = self.pairs[i][2]
1800 ln = self.pairs[i][10]
1801 index = self.pairs[i][9]
1802 rsname = self.pairs[i][3]
1803 resid1 = self.pairs[i][6][0]
1804 chain1 = self.pairs[i][6][1]
1805 copy1 = self.pairs[i][6][2]
1806 resid2 = self.pairs[i][7][0]
1807 chain2 = self.pairs[i][7][1]
1808 copy2 = self.pairs[i][7][2]
1809 label_copy = str(rsname) +
":" + str(index) +
"-" + str(resid1) + \
1810 ":" + chain1 +
"_" +
"-" + \
1811 str(resid2) +
":" + chain2 +
"_" + crosslinker
1812 output[
"CrossLinkMS_Partial_Probability_" +
1813 label_copy] = str(ln.get_marginal_probabilities()[index])
1816 label = str(resid1) +
":" + chain1 + \
1817 "_" + str(resid2) +
":" + chain2
1819 output[
"CrossLinkMS_Score_" +
1820 str(rsname) +
"_" + crosslinker +
"_" + label] = str(ln.unprotected_evaluate(
None))
1824 output[
"CrossLinkMS_Distance_" +
1832 class BinomialXLMSRestraint(object):
1834 def __init__(self, m, prots,
1835 listofxlinkertypes=[
"BS3",
"BS2G",
"EGS"], map_between_protein_names_and_chains=
None, typeofprofile=
'pfes'):
1837 if map_between_protein_names_and_chains
is None:
1838 map_between_protein_names_and_chains = {}
1840 global impisd2, tools, exp
1841 import IMP.isd2
as impisd2
1853 self.weightmaxtrans = 0.05
1854 self.weightissampled =
False
1856 self.sigmainit = 5.0
1858 self.sigmaminnuis = 0.0
1859 self.sigmamax = 10.0
1860 self.sigmamaxnuis = 11.0
1862 self.sigmaissampled =
True
1863 self.sigmamaxtrans = 0.1
1869 self.betaissampled =
True
1870 print "BinomialXLMSRestraint: beta is sampled"
1872 self.betaissampled =
False
1873 print "BinomialXLMSRestraint: beta is NOT sampled"
1874 self.betamaxtrans = 0.01
1877 self.deltainit=0.001
1880 self.deltaissampled=False
1881 self.deltamaxtrans=0.001
1885 self.lamminnuis=0.00001
1887 self.lammaxnuis=100.0
1888 self.lamissampled=False
1889 self.lammaxtrans=0.1
1893 self.psi_dictionary = {}
1895 self.sigma = tools.SetupNuisance(self.m, self.sigmainit,
1896 self.sigmaminnuis, self.sigmamaxnuis, self.sigmaissampled).get_particle()
1898 self.beta = tools.SetupNuisance(self.m, self.betainit,
1899 self.betamin, self.betamax, self.betaissampled).get_particle()
1902 self.delta=tools.SetupNuisance(self.m,self.deltainit,
1903 self.deltamin,self.deltamax,self.deltaissampled).get_particle()
1905 self.lam=tools.SetupNuisance(self.m,self.laminit,
1906 self.lamminnuis,self.lammaxnuis,self.lamissampled).get_particle()
1908 self.weight=tools.SetupWeight(m,False).get_particle()
1910 for n in range(len(self.prots)):
1911 self.weight.add_weight()
1913 self.outputlevel =
"low"
1914 self.listofxlinkertypes = listofxlinkertypes
1916 self.reaction_rates =
None
1917 self.allpairs_database =
None
1918 self.residue_list =
None
1920 self.crosslinker_dict = self.get_crosslinker_dict(typeofprofile)
1923 self.mbpnc = map_between_protein_names_and_chains
1926 def create_psi(self, index, value):
1929 self.psiissampled =
True
1930 print "BinomialXLMSRestraint: psi " + str(index) +
" is sampled"
1932 self.psiinit = value
1933 self.psiissampled =
False
1934 print "BinomialXLMSRestraint: psi " + str(index) +
" is NOT sampled"
1935 self.psiminnuis = 0.0000001
1936 self.psimaxnuis = 0.4999999
1939 self.psitrans = 0.01
1940 self.psi = tools.SetupNuisance(self.m, self.psiinit,
1941 self.psiminnuis, self.psimaxnuis, self.psiissampled).get_particle()
1942 self.psi_dictionary[index] = (
1947 def get_psi(self, index, value):
1948 if not index
in self.psi_dictionary:
1949 self.create_psi(index, value)
1950 return self.psi_dictionary[index]
1952 def get_crosslinker_dict(self, typeofprofile):
1957 disttuple = (0.0, 200.0, 500)
1958 omegatuple = (0.01, 1000.0, 30)
1959 sigmatuple = (self.sigmamin, self.sigmamax, self.nsigma)
1961 crosslinker_dict = {}
1962 if "BS3" in self.listofxlinkertypes:
1963 crosslinker_dict[
"BS3"] = tools.get_cross_link_data(
"bs3l",
1964 "pmf_bs3l_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1965 if "BS2G" in self.listofxlinkertypes:
1966 crosslinker_dict[
"BS2G"] = tools.get_cross_link_data(
"bs2gl",
1967 "pmf_bs2gl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1968 if "EGS" in self.listofxlinkertypes:
1969 crosslinker_dict[
"EGS"] = tools.get_cross_link_data(
"egl",
1970 "pmf_egl_tip3p.txt.standard", disttuple, omegatuple, sigmatuple, don=
None, doff=
None, prior=1, type_of_profile=typeofprofile)
1971 if "Short" in self.listofxlinkertypes:
1973 crosslinker_dict[
"Short"] = tools.get_cross_link_data_from_length(
1978 return crosslinker_dict
1983 f = open(restraint_file)
1984 restraint_list = f.readlines()
1988 self.added_pairs_list = []
1989 self.missing_residues = []
1990 for line
in restraint_list:
1993 force_restraint =
False
1996 totallist = eval(line)
1997 self.add_crosslink_according_to_new_file(totallist)
1999 self.rs2.add_restraint(
2000 impisd2.UniformPrior(
2007 for psiindex
in self.psi_dictionary:
2008 if self.psi_dictionary[psiindex][2]:
2009 psip = self.psi_dictionary[psiindex][0]
2012 print "BinomialXLMSRestraint: setup 0, adding BinomialJeffreysPrior to psi particle " + str(psiindex)
2013 self.rs2.add_restraint(impisd2.BinomialJeffreysPrior(psip))
2016 self.rs2.add_restraint(
2017 impisd2.UniformPrior(
2023 def add_crosslink_according_to_new_file(self, totallist, constructor=0):
2027 force_restraint =
False
2028 ambiguous_list = totallist[0]
2029 crosslinker = totallist[1]
2030 if (totallist[2] ==
"F"):
2031 force_restraint =
True
2042 for pair
in ambiguous_list:
2046 c1 = self.mbpnc[pair[0][0]]
2048 print "BinomialXLMSRestraint: WARNING> protein name " + pair[0][0] +
" was not defined"
2051 c2 = self.mbpnc[pair[1][0]]
2053 print "BinomialXLMSRestraint: WARNING> protein name " + pair[1][0] +
" was not defined"
2056 r1 = int(pair[0][1])
2057 r2 = int(pair[1][1])
2058 psi = float(pair[2])
2060 psivalue = float(pair[3])
2064 print '''CrossLinkMS: attempting to add restraint between
2065 residue %d of chain %s and residue %d of chain %s''' % (r1, c1, r2, c2)
2072 atom_type=IMP.atom.AT_CA)
2073 p1 = (s1.get_selected_particles()[0])
2075 print "BinomialXLMSRestraint: WARNING> residue %d of chain %s is not there" % (r1, c1)
2077 self.missing_residues.append((r1, c1))
2083 atom_type=IMP.atom.AT_CA)
2084 p2 = (s2.get_selected_particles()[0])
2086 print "BinomialXLMSRestraint: WARNING> residue %d of chain %s is not there" % (r2, c2)
2088 self.missing_residues.append((r2, c2))
2096 atom_type=IMP.atom.AT_CA)
2097 p1 = s1.get_selected_particles()[0]
2102 atom_type=IMP.atom.AT_CA)
2103 p2 = s2.get_selected_particles()[0]
2106 if (p1, p2, crosslinker)
in self.added_pairs_list:
2107 print "BinomialXLMSRestraint: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
2109 if (p2, p1, crosslinker)
in self.added_pairs_list:
2110 print "BinomialXLMSRestraint: WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
2118 print '''BinomialXLMSRestraint: WARNING> residue %d of chain %s and
2119 residue %d of chain %s belong to the same rigid body''' % (r1, c1, r2, c2)
2129 psivalues.append(psivalue)
2131 print "BinomialXLMSRestraint: added pair %d %s %d %s" % (r1, c1, r2, c2)
2133 self.added_pairs_list.append((p1, p2, crosslinker))
2136 rs_name =
'{:05}'.format(self.index % 100000)
2139 print "BinomialXLMSRestraint: constructor 0"
2140 ln = impisd2.BinomialCrossLinkMSRestraint(
2144 self.crosslinker_dict[crosslinker])
2147 print "BinomialXLMSRestraint: constructor 1"
2148 ln = impisd2.BinomialCrossLinkMSRestraint(
2153 self.crosslinker_dict[crosslinker])
2155 for i
in range(len(p1s)):
2156 ln.add_contribution()
2158 psi = self.get_psi(psis[i], psivalues[i])
2160 ln.add_particle_pair(
2165 self.pairs.append((p1s[i], p2s[i], crosslinker, rs_name,
2166 self.index, 100, (r1s[i], c1s[i], i), (r2s[i], c2s[i], i), crosslinker, i, ln))
2172 self.rs2.add_restraint(pr)
2174 self.rs.add_restraint(ln)
2176 print "BinomialXLMSRestraint: missing residues"
2177 for ms
in self.missing_residues:
2178 print "BinomialXLMSRestraint:missing " + str(ms)
2184 def set_label(self, label):
2187 def add_to_model(self):
2188 self.m.add_restraint(self.rs)
2189 self.m.add_restraint(self.rs2)
2191 def get_hierarchies(self):
2195 return self.sigmaglobal
2197 def get_restraint_sets(self):
2198 return self.rs, self.rs2
2200 def get_restraint(self):
2202 tmprs.add_restraint(self.rs)
2203 tmprs.add_restraint(self.rs2)
2206 def set_output_level(self, level="low"):
2208 self.outputlevel = level
2210 def print_chimera_pseudobonds(self, filesuffix, model=0):
2211 f = open(filesuffix +
".chimera",
"w")
2213 for p
in self.pairs:
2214 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2215 " #" + str(model) +
":" + \
2216 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2220 def print_chimera_pseudobonds_with_psiindexes(self, filesuffix, model=0):
2222 f = open(filesuffix +
".chimera",
"w")
2224 for p
in self.pairs:
2225 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2226 " #" + str(model) +
":" + \
2227 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2231 def get_output(self):
2236 score = self.rs.unprotected_evaluate(
None)
2237 score2 = self.rs2.unprotected_evaluate(
None)
2238 output[
"_TotalScore"] = str(score + score2)
2239 output[
"CrossLinkMS_Likelihood_" + self.label] = str(score)
2240 output[
"CrossLinkMS_Prior_" + self.label] = str(score2)
2242 if self.outputlevel ==
"high":
2243 for i
in range(len(self.pairs)):
2245 p0 = self.pairs[i][0]
2246 p1 = self.pairs[i][1]
2247 crosslinker = self.pairs[i][2]
2248 psiindex = self.pairs[i][4]
2249 ln = self.pairs[i][10]
2250 index = self.pairs[i][9]
2251 rsname = self.pairs[i][3]
2252 resid1 = self.pairs[i][6][0]
2253 chain1 = self.pairs[i][6][1]
2254 copy1 = self.pairs[i][6][2]
2255 resid2 = self.pairs[i][7][0]
2256 chain2 = self.pairs[i][7][1]
2257 copy2 = self.pairs[i][7][2]
2258 label_copy = str(rsname) +
":" + str(index) +
"-" + str(resid1) + \
2259 ":" + chain1 +
"_" +
"-" + \
2260 str(resid2) +
":" + chain2 +
"_" + crosslinker
2263 label = str(resid1) +
":" + chain1 + \
2264 "_" + str(resid2) +
":" + chain2
2266 output[
"CrossLinkMS_Score_" + str(rsname) +
"_" + str(index) +
"_" +
2267 crosslinker +
"_" + label] = str(ln.unprotected_evaluate(
None))
2271 output[
"CrossLinkMS_Distance_" +
2274 output[
"CrossLinkMS_Sigma_" + self.label] = str(self.sigma.get_scale())
2276 output["CrossLinkMS_Delta_"+self.label]=str(self.delta.get_scale())
2277 output["CrossLinkMS_Lambda_"+self.label]=str(self.lam.get_scale())
2279 output[
"CrossLinkMS_Beta_" + self.label] = str(self.beta.get_scale())
2280 for psiindex
in self.psi_dictionary:
2281 output[
"CrossLinkMS_Psi_" +
2282 str(psiindex) +
"_" + self.label] = str(self.psi_dictionary[psiindex][0].get_scale())
2284 for n in range(self.weight.get_number_of_states()):
2285 output["CrossLinkMS_weights_"+str(n)+"_"+self.label]=str(self.weight.get_weight(n))
2289 def get_particles_to_sample(self):
2291 if self.sigmaissampled:
2292 ps[
"Nuisances_CrossLinkMS_Sigma_" +
2293 self.label] = ([self.sigma], self.sigmamaxtrans)
2295 if self.deltaissampled:
2296 ps["Nuisances_CrossLinkMS_Delta_"+self.label]=([self.delta],self.deltamaxtrans)
2297 if self.lamissampled:
2298 ps["Nuisances_CrossLinkMS_Lambda_"+self.label]=([self.lam],self.lammaxtrans)
2300 if self.betaissampled:
2301 ps[
"Nuisances_CrossLinkMS_Beta_" +
2302 self.label] = ([self.beta], self.betamaxtrans)
2304 for psiindex
in self.psi_dictionary:
2305 if self.psi_dictionary[psiindex][2]:
2306 ps[
"Nuisances_CrossLinkMS_Psi_" +
2307 str(psiindex) +
"_" + self.label] = ([self.psi_dictionary[psiindex][0]], self.psi_dictionary[psiindex][1])
2310 if self.weightissampled:
2311 ps["Weights_CrossLinkMS_"+self.label]=([self.weight],self.weightmaxtrans)
2318 class CrossLinkMSSimple(object):
2320 def __init__(self, prot, restraints_file, TruncatedHarmonic=True):
2321 """read crosslink restraints between two residue
2322 of different chains from an external text file
2323 syntax: part_name_1 part_name_2 distance error
2324 example: 0 1 1.0 0.1"""
2328 self.m = self.prot.get_model()
2334 if TruncatedHarmonic:
2347 addedd_pairs_list = []
2348 for line
in open(restraints_file):
2352 force_restraint =
True
2353 tokens = line.split()
2356 if (tokens[0] ==
"#"):
2362 crosslinker = tokens[4]
2365 index = int(tokens[5])
2369 if (tokens[len(tokens) - 1] ==
"F"):
2370 force_restraint =
True
2372 print "attempting to add restraint between residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2)
2383 atom_type=IMP.atom.AT_CA)
2384 p1 = (s1.get_selected_particles()[0])
2386 print "WARNING> residue %d of chain %s is not there" % (r1, c1)
2393 atom_type=IMP.atom.AT_CA)
2394 p2 = (s2.get_selected_particles()[0])
2396 print "WARNING> residue %d of chain %s is not there" % (r2, c2)
2408 print "attempting to add restraint between residue %d of chain %s and residue %d of chain %s" % (r1, c1, r2, c2)
2413 print "WARNING> residue %d of chain %s and residue %d of chain %s belong to the same rigid body" % (r1, c1, r2, c2)
2418 if (p1, p2, crosslinker)
in addedd_pairs_list:
2419 print "WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
2421 if (p2, p1, crosslinker)
in addedd_pairs_list:
2422 print "WARNING> pair %d %s %d %s already there" % (r1, c1, r2, c2)
2425 print "added pair %d %s %d %s" % (r1, c1, r2, c2)
2427 addedd_pairs_list.append((p1, p2, crosslinker))
2429 rs_name =
'restraint_' + str(index)
2432 ln.set_name(
"CrossLinkMSSimple_" + str(r1)
2433 +
":" + str(c1) +
"-" + str(r2) +
":" + str(c2))
2436 self.rs.add_restraint(ln)
2440 self.rs.add_restraint(pr)
2457 def set_label(self, label):
2460 def add_to_model(self):
2461 self.m.add_restraint(self.rs)
2463 def get_restraint(self):
2466 def print_chimera_pseudobonds(self, filesuffix, model=0):
2467 f = open(filesuffix +
".chimera",
"w")
2469 for p
in self.pairs:
2470 s =
"#" + str(model) +
":" + str(p[6][0]) +
"." + p[6][1] +
"@" + atype + \
2471 " #" + str(model) +
":" + \
2472 str(p[7][0]) +
"." + p[7][1] +
"@" + atype
2476 def get_output(self):
2481 score = self.rs.unprotected_evaluate(
None)
2482 output[
"_TotalScore"] = str(score)
2483 output[
"CrossLinkMSSimple_Score_" + self.label] = str(score)
2484 for i
in range(len(self.pairs)):
2486 p0 = self.pairs[i][0]
2487 p1 = self.pairs[i][1]
2488 crosslinker = self.pairs[i][2]
2489 ln = self.pairs[i][9]
2490 pr = self.pairs[i][10]
2491 resid1 = self.pairs[i][6][0]
2492 chain1 = self.pairs[i][6][1]
2493 resid2 = self.pairs[i][7][0]
2494 chain2 = self.pairs[i][7][1]
2496 label = str(resid1) +
":" + chain1 +
"_" + \
2497 str(resid2) +
":" + chain2
2498 output[
"CrossLinkMSSimple_Score_" + crosslinker +
2499 "_" + label] = str(ln.unprotected_evaluate(
None))
2500 output[
"CrossLinkMSSimple_Score_Linear_" + crosslinker +
2501 "_" + label] = str(pr.unprotected_evaluate(
None))
2504 output[
"CrossLinkMSSimple_Distance_" +
2510 def get_residue_index_and_chain_from_particle(p):
2517 def select_calpha_or_residue(
2522 SelectResidue=
False):
2526 residue_index=resid, atom_type=IMP.atom.AT_CA)
2528 ps = s.get_selected_particles()
2534 print ObjectName +
" multiple residues selected for selection residue %s chain %s " % (resid, chain)
2538 residue_index=resid)
2539 ps = s.get_selected_particles()
2545 print ObjectName +
" multiple residues selected for selection residue %s chain %s " % (resid, chain)
2548 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.
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.