1 """@namespace IMP.EMageFit.domino_model
2 Classes to manage a model using DOMINO.
27 log = logging.getLogger(
"DominoModel")
37 Management of a model using DOMINO
40 def __init__(self, name="my model"):
42 self.model.set_name(name)
43 self.configuration_sampling_done =
False
44 self.assignments_sampling_done =
False
46 self.merge_tree =
None
48 self.measure_models =
False
51 self.create_coarse =
True
52 self.restraints = dict()
57 Adds a restraint to the model
58 @param r An IMP.Restraint object
59 @param name Name for the restraint
60 @param weight Weight for the restraint
61 @param max_score Maximum score allowed for the restraint. If
62 max_score is False, there is no limit for the value of
65 log.info(
"Adding restraint %s weight %s max_score %s",
66 name, weight, max_score)
68 raise ValueError(
"SQL database does not accept restraint names "
71 if max_score
is not None and max_score:
72 r.set_maximum_score(max_score)
74 self.restraints[name] = r
78 Aligns the set of structures considered for DOMINO sampling.
80 1) reads the possible reference frames that the
81 rb_states_table stores for each rigid body. This table
82 must be filled before using this function. Usually it is
83 filled with the results from a previous Monte Carlo
84 sampling. If the solutions from Monte Carlo seem to have
85 the same structure but they are not aligned to each other,
86 this function can help setting better starting positions
88 2) Gets the first state for each of the rigid bodies and sets
89 a reference structure using such states.
90 3) Aligns all the rest of the structures respect to the
92 4) Replaces the values of the reference frames stored in the
93 rb_states_table with the new values obtained from the
94 alignments. It does it for all states of a rigid body.
95 @note: If this function is applied, the parameters "anchor"
96 and "fixed" are ignored, as they are superseded by the use
97 of the alignments calculated here.
99 log.debug(
"Align the configurations read from the database before "
103 for rb
in self.components_rbs:
104 ps = self.rb_states_table.get_particle_states(rb)
105 n = ps.get_number_of_particle_states()
108 "There are no particle states for %s" %
114 for rb, states
in zip(self.components_rbs, rb_states):
115 states.load_particle_state(0, rb)
117 aligned_transformations = [[]
for rb
in self.components_rbs]
118 for i
in range(1, max(n_states)):
119 log.debug(
"Aligning rigid bodies configuration %s" % i)
121 for j
in range(len(self.components_rbs)):
124 state_index = min(i, n_states[j] - 1)
125 rb_states[j].load_particle_state(
127 self.components_rbs[j])
129 T = alg.get_transformation_aligning_first_to_second(
130 coords, reference_coords)
131 for j, rb
in enumerate(self.components_rbs):
132 t = rb.get_reference_frame().get_transformation_to()
133 new_t = alg.compose(T, t)
134 aligned_transformations[j].append(new_t)
136 for i, rb
in enumerate(self.components_rbs):
140 distance, weight, stddev, max_score=
False):
142 Set a restraint on the maximum distance between 2 residues
143 @param id1 Name of the first component
145 @param residue1 Residue number for the aminoacid in the first
146 component.The number is the number in the PDB file, not the
147 number relative to the beginning of the chain
148 @param id2 Name of the second component
150 @param residue2 Residue number for the aminoacid in the second
152 @param distance Maximum distance tolerated
153 @param weight Weight of the restraint
154 @param stddev Standard deviation used to approximate the
155 HarmonicUpperBound function to a Gaussian
156 @param max_score See help for add_restraint(). If none is given,
157 the maximum score is set to allow a maximum distance of 10 Angstrom
158 greater than the parameter "distance".
168 log.info(
"Setting cross-linking restraint ")
169 log.info(
"%s", xlink.show())
170 self.xlinks_dict.add(xlink)
172 A = representation.get_component(self.assembly, xlink.first_id)
174 residue_index=xlink.first_residue)
175 p1 = s1.get_selected_particles()[0]
176 B = representation.get_component(self.assembly, xlink.second_id)
178 residue_index=xlink.second_residue)
179 p2 = s2.get_selected_particles()[0]
180 k = core.Harmonic.get_k_from_standard_deviation(stddev)
185 error_distance_allowed = 100
186 max_score = weight * \
187 score.evaluate(distance + error_distance_allowed)
188 log.info(
"%s, max_score %s", xlink.show(), max_score)
192 max_sep_distance, max_penetration,
193 weight, max_score=1e10):
195 Set a restraint for geometric complementarity between 2 components
197 @param name2 - The restraint is applied to this components
198 @param rname - The name given to the restraint
199 @param max_sep_distance - maximum distance between molecules
200 tolerated by the restraint
201 @param max_penetration - Maximum penetration allowed (angstrom)
205 log.info(
"Setting geometric complementarity restraint %s: %s - %s",
207 A = representation.get_component(self.assembly, name1)
208 B = representation.get_component(self.assembly, name2)
210 atom.get_leaves(A), atom.get_leaves(B), rname)
211 restraint.set_maximum_separation(max_sep_distance)
212 restraint.set_maximum_penetration(max_penetration)
213 log.debug(
"Maximum separation: %s Maximum penetration score: %s",
214 max_sep_distance, max_penetration)
219 Simplify the assembly with a coarse representation
220 @param n_residues Number of residues used for a coarse particle
222 if self.create_coarse:
223 log.info(
"Creating simplified assembly")
224 self.coarse_assembly = representation.create_simplified_assembly(
225 self.assembly, self.components_rbs, n_residues)
226 self.create_coarse =
False
228 def do_sampling(self, mode="assignments_heap_container", params=None):
231 @param mode The mode used to recover solutions from domino.
233 the value "configuration", "assignments", or
234 "assignments_heap_container". The mode
235 "configuration" recovers all possible configurations
236 (takes a while to generate them).
237 The mode "assignments" only provides the assignments
238 (state numbers) of the solutions. It is faster but requires
239 generating the solutions afterwards
240 The mode "assignments_heap_container" selects the best solutions
241 after each merging in DOMINO, discarding the rest.
242 In practice I used the mode "assignments_heap_container"
246 if mode ==
"configuration":
247 self.configuration_set = self.sampler.create_sample()
249 log.info(
"found %s configurations. Time %s",
250 self.configuration_set.get_number_of_configurations(),
252 self.configuration_sampling_done =
True
253 elif mode ==
"assignments":
254 subset = self.rb_states_table.get_subset()
256 "Do sampling with assignments. Subset has %s elements: %s",
258 self.solution_assignments = \
259 self.sampler.get_sample_assignments(subset)
261 log.info(
"found %s assignments. Time %s",
262 len(self.solution_assignments), tf - t0)
263 self.assignments_sampling_done =
True
264 elif mode ==
"assignments_heap_container":
265 subset = self.rb_states_table.get_subset()
266 log.info(
"DOMINO sampling an assignments_heap_container. "
267 "Subset has %s elements: %s", len(subset), subset)
269 root = self.merge_tree.get_vertices()[-1]
271 params.heap_solutions)
272 self.solution_assignments = container.get_assignments()
274 log.info(
"found %s assignments. Time %s",
275 len(self.solution_assignments), tf - t0)
276 self.assignments_sampling_done =
True
278 raise ValueError(
"Requested wrong mode for the DOMINO sampling")
282 Get the formatted text for an assignment
283 @param subset Subset of components of the assembly
284 @param assignment Assignment class with the states for the subset
285 @note: The order in assignment and subset is not always the order
286 of the rigid bodies in self.components_rbs. The function reorders
287 the terms in the assignment so there is correspondence.
289 ordered_assignment = []
290 for rb
in self.components_rbs:
291 for i, particle
in enumerate(subset):
292 if rb.get_particle() == particle:
293 ordered_assignment.append(assignment[i])
294 text =
"|".join([str(i)
for i
in ordered_assignment])
299 Return a line with texts for an assignment and the
300 the reference frames of the RigidBodies in the subset.
301 @param subset Subset of components of the assembly
302 @param assignment Assignment class with the states for the subset
303 @note: see the get_assignment_assignment_text() note.
305 ordered_assignment = []
307 for rb
in self.components_rbs:
308 for i, particle
in enumerate(subset):
309 if rb.get_particle() == particle:
311 ordered_assignment.append(j)
312 pstates = self.rb_states_table.get_particle_states(rb)
313 pstates.load_particle_state(j, rb.get_particle())
314 RFs.append(rb.get_reference_frame())
315 RFs_text = unit_delim.join(
316 [io.ReferenceFrameToText(ref).get_text()
for ref
in RFs])
317 assignment_numbers =
"|".join([str(i)
for i
in ordered_assignment])
318 return [assignment_numbers, RFs_text]
322 Info related to an assignment. Returns a list with text for the
323 assignment and all the scores for the restraints
324 @param subset Subset of components of the assembly
325 @param assignment Assignment class with the states for the subset
329 info = text + [total_score] + scores
334 Returns a list with the values for the restraints on a subset of
335 the components of the assembly
336 @param subset Subset of components of the assembly
337 @param assignment Assignment class with the states for the subset
339 restraints_to_evaluate = \
340 self.restraint_cache.get_restraints(subset, [])
341 scores = [self.restraint_cache.get_score(r, subset, assignment)
342 for r
in restraints_to_evaluate]
343 total_score = sum(scores)
344 return scores, total_score
348 Load the positions of the components given by the assignment
349 @param assignment Assignment class
351 subset = self.rb_states_table.get_subset()
352 domino.load_particle_states(subset, assignment, self.rb_states_table)
356 Domino sampling that recovers the assignments for the root of the
358 conserving only the best k scores for each vertex of the tree.
359 @param[in] vertex Vertex with the root of the current
360 merge tree. This function is recursive.
363 if(self.sampler.get_number_of_subset_filter_tables() == 0):
364 raise ValueError(
"No subset filter tables")
365 if(self.merge_tree
is None):
366 raise ValueError(
"No merge tree")
369 subset = self.merge_tree.get_vertex_name(vertex)
370 log.info(
"computing assignments for vertex %s", subset)
373 subset, k, self.restraint_cache,
"my_heap_assignments_container")
374 neighbors = self.merge_tree.get_out_neighbors(vertex)
375 if len(neighbors) == 0:
377 self.sampler.load_vertex_assignments(vertex, assignments_container)
379 if neighbors[0] > neighbors[1]:
382 neighbors = [neighbors[1], neighbors[0]]
386 self.sampler.load_vertex_assignments(vertex,
389 assignments_container)
390 tf = time.time() - t0
391 log.info(
"Merge tree vertex: %s assignments: %s Time %s sec.", subset,
392 assignments_container.get_number_of_assignments(), tf)
393 return assignments_container
397 Recover the value of a restraint
398 @param name of the restraint
399 @param assignment Assignment class containing the assignment for
402 if not self.assignments_sampling_done:
403 raise ValueError(
"DominoModel: sampling not done")
404 log.debug(
"Computing restraint value for assignment %s", assignment)
406 for rb
in self.components_rbs:
408 rb.get_reference_frame().get_transformation_to())
409 val = self.restraints[name].evaluate(
False)
410 log.debug(
"restraint %s = %s", name, val)
415 Sets the native model for benchmark, by reading the native
416 structure and set the rigid bodies.
418 self.measure_models =
True
420 if hasattr(params.benchmark,
"fn_pdb_native"):
421 self.native_assembly = representation.create_assembly_from_pdb(
422 self.native_model, params.benchmark.fn_pdb_native,
424 elif hasattr(params.benchmark,
"fn_pdbs_native"):
425 self.native_assembly = representation.create_assembly(
426 self.native_model, params.benchmark.fn_pdbs_native,
430 "set_native_assembly_for_benchmark: Requested "
431 "to set a native assembly for benchmark but did not provide "
432 "its pdb, or the pdbs of the components")
433 self.native_rbs = representation.create_rigid_bodies(
434 self.native_assembly)
439 Add a set of reference frames as possible states for a rigid body
440 @param rb The rigid body
441 @param transformations Transformations are used to build the
442 reference frames for the rigid body.
444 log.info(
"Set rigid body states for %s", rb.get_name())
445 RFs = [alg.ReferenceFrame3D(T)
for T
in transformations]
449 self.rb_states_table.set_particle_states(rb, rb_states)
450 st = self.rb_states_table.get_particle_states(rb)
451 log.info(
"RigidBodyStates created %s",
452 st.get_number_of_particle_states())
456 Add a RestraintScoreSubsetFilterTable to DOMINO that allows to
457 reject assignments that have score worse than the thresholds for
460 log.info(
"Adding RestraintScoreSubsetFilterTable")
464 self.restraint_cache.add_restraints(list(self.restraints.values()))
466 rssft.set_name(
'myRestraintScoreSubsetFilterTable')
467 self.sampler.add_subset_filter_table(rssft)
471 Sets the components of an assembly, each one given as a separate
473 @param fn_pdbs List with the names of the pdb files
474 @param names List with the names of the components of the assembly.
476 if len(fn_pdbs) != len(names):
477 raise ValueError(
"Each PDB file needs a name")
479 self.assembly = representation.create_assembly(self.model, fn_pdbs,
481 self.components_rbs = representation.create_rigid_bodies(self.assembly)
482 self.not_optimized_rbs = []
486 Sets an assembly from a single PDB file. The function assumes that
487 the components of the assembly are the chains of the PDB file.
488 @param fn_pdb PDB with the file for the assembly
489 @param names Names for each of the components (chains)
492 self.assembly = representation.create_assembly_from_pdb(self.model,
495 self.components_rbs = representation.create_rigid_bodies(self.assembly)
496 self.not_optimized_rbs = []
500 BranchAndBoundAssignmentsTable enumerate states based on provided
501 filtered using the provided the subset filter tables
503 log.info(
"Setting BranchAndBoundAssignmentsTable")
505 for i
in range(self.sampler.get_number_of_subset_filter_tables()):
506 ft = self.sampler.get_subset_filter_table(i)
509 self.sampler.set_assignments_table(at)
510 self.assignments_table = at
514 ExclusionSubsetFilterTable ensures that two particles are not given
515 the same state at the same time
517 log.info(
"Setting ExclusionSubsetFilterTable")
519 self.sampler.add_subset_filter_table(ft)
523 Creates a DOMINO sampler and adds the required filter tables
525 if self.merge_tree
is None:
526 raise ValueError(
"Merge tree for DOMINO not set. It is required "
527 "to setup the sampler")
528 log.info(
"Domino sampler")
530 self.sampler.set_restraints(list(self.restraints.values()))
531 self.sampler.set_log_level(IMP.TERSE)
532 self.sampler.set_merge_tree(self.merge_tree)
539 Read and create a merge tree from a file.
540 The format of the file is the format written by write merge_tree()
541 It does not matter the order of the indices in the file, as
542 they are sorted by this function.
543 The only condition is that the index for the vertex that is the
544 root of the tree MUST be the largest. This is guaranteed when
545 creating a merge tree with create_merge_tree()
546 @param fn File containing the merge tree
548 log.info(
"Reading merge tree from %s", fn)
549 ps = self.rb_states_table.get_particles()
550 log.debug(
"particles")
552 log.debug(
"%s", p.get_name())
553 rows = csv_related.read_csv(fn, delimiter=field_delim)
554 for i
in range(len(rows)):
556 rows[i] = [int(row[0]), int(row[1]), int(row[2]), row[3]]
562 names = row[3].split(unit_delim)
563 log.debug(
"row %s names %s", row, names)
567 lp = [p
for p
in ps
if p.get_name() == name]
569 ValueError(
"More than one particle with same name" % names)
572 subset_names = [p.get_name()
for p
in particles]
573 log.debug(
"Merge tree Subset %s. Particles %s ", s, subset_names)
577 jt = domino.SubsetGraph()
578 jt.add_vertex(subsets[0])
579 mt = domino.get_merge_tree(jt)
581 for i
in range(1, len(subsets)):
582 mt.add_vertex(subsets[i])
589 mt.add_edge(vid, child_left)
590 if child_right != -1:
591 mt.add_edge(vid, child_right)
593 log.info(
"%s", self.merge_tree.show_graphviz())
597 Creates a merge tree from the restraints that are set already
599 rs = list(self.restraints.values())
600 ig = domino.get_interaction_graph(rs, self.rb_states_table)
604 jt = domino.get_junction_tree(ig)
606 self.merge_tree = domino.get_balanced_merge_tree(jt)
608 log.info(
"Balanced merge tree created")
609 log.info(
"%s", self.merge_tree.show_graphviz())
613 Writes the current merge tree to file. The format is:
614 parent | child_left | child_right | labels
615 @param fn File for storing the merge tree
617 log.info(
"Writing merge to %s", fn)
618 if self.merge_tree
is None:
619 raise ValueError(
"No merge tree")
622 "# Vertex index | Child0 | Child1 | label "
623 "(names of the particles)\n")
624 w = csv.writer(f, delimiter=field_delim)
625 root = self.merge_tree.get_vertices()[-1]
631 Writes lines describing a subset (vertex of a merge tree)
632 @param w A csv.writer
633 @param v Vertex index
636 subset = self.merge_tree.get_vertex_name(v)
637 names = [p.get_name()
for p
in subset]
638 reps = [x
for x
in names
if names.count(x) > 1]
641 "The names of the particles in the subset %s are not unique"
643 names = unit_delim.join(names)
644 neighbors = self.merge_tree.get_out_neighbors(v)
645 if len(neighbors) == 0:
647 w.writerow([v, no_child_index, no_child_index, names])
649 if neighbors[0] > neighbors[1]:
650 neighbors = [neighbors[1], neighbors[0]]
651 w.writerow([v, neighbors[0], neighbors[1], names])
657 weight=1.0, max_score=
None, n_pairs=1,
660 Set a connectivity restraint between the elements of the assembly
661 @param names List with all the elements to be connected
662 @param distance Maximum distance tolerated by the restraint
663 @param rname Name for the restraint
664 @param weight Weight for the restraint
665 @param max_score Maximum score for the restraint
666 @param n_pairs Number of pairs of particles used in the
667 KClosePairScore of the connectivity restraint
668 @param stddev Standard deviation used to approximate the
669 HarmonicUpperBound function to a Gaussian
673 c = representation.get_component(self.coarse_assembly, name)
675 log.info(
"Connectivity restraint for %s", components)
676 spring_constant = core.Harmonic.get_k_from_standard_deviation(stddev)
677 if max_score
is None:
678 max_score = weight * spring_constant * n_pairs * (stddev) ** 2
679 r = restraints.get_connectivity_restraint(
680 components, distance, n_pairs,
685 n_projections, weight, max_score=
False,
686 mode=
"fast", n_optimized=1):
688 Set a Restraint computing the em2d score.
689 @param name Name for the restraint
690 @param fn_images_sel Selection file with the names of the images
691 used for the restraint
692 @param pixel_size - pixel size in the images
693 @param resolution - resolution used to downsample the projections
694 of the model when projecting
695 @param weight Weight of the restraint
696 @param max_score - Maximum value tolerated for the restraint
697 @param n_projections - Number of projections to generate
698 when projecting the model to do the coarse alignments
699 @param mode - Mode used for computing the restraints.
700 @param n_optimized - number of results from the coarse
701 alignment that are refined with the Simplex algorithm
702 to get a more accurate value for the restraint
704 log.info(
"Adding a em2D restraint: %s", fn_images_sel)
708 r = restraints.get_em2d_restraint(self.assembly,
716 Set a part of the model as not optimized (it does not move during
717 the model optimization)
718 @param name of the component to optimized
720 if name
not in self.names:
721 raise ValueError(
"DominoModel: There is not component "
722 "in the assembly with this name")
723 rb_name = representation.get_rb_name(name)
724 self.not_optimized_rbs.append(rb_name)
727 self, distance=10, weight=1.0, ratio=0.05, stddev=2, max_score=
False):
729 Creates an excluded volume restraint between all the components
730 of the coarse assembly.See help for
731 @param distance Maximum distance tolerated between particles
732 @param weight Weight for the restraint
734 @param max_score Maximum value for the restraint. If the parameter
735 is None, an automatic value is computed (using the ratio).
736 @param ratio Fraction of the number of possible pairs of
737 particles that are tolerated to overlap. The maximum
738 score is modified according to this ratio.
739 I have found that ratios of 0.05-0.1 work well allowing for
740 some interpenetration
741 @param stddev Standard deviation used to approximate the
742 HarmonicUpperBound function to a Gaussian
744 k = core.Harmonic.get_k_from_standard_deviation(stddev)
745 for i, c1
in enumerate(self.coarse_assembly.get_children()):
746 for j, c2
in enumerate(self.coarse_assembly.get_children()):
748 name =
"exc_vol_%s_%s" % (c1.get_name(), c2.get_name())
750 ls1 = atom.get_leaves(c1)
751 ls2 = atom.get_leaves(c2)
752 possible_pairs = len(ls1) * len(ls2)
753 n_pairs = possible_pairs * ratio
756 self.model,
"marker1 " + name)
758 self.model,
"marker2 " + name)
760 table_refiner.add_particle(marker1, ls1)
761 table_refiner.add_particle(marker2, ls2)
771 minimum_distance_allowed = 0
772 max_score = weight * n_pairs * \
773 score.evaluate(minimum_distance_allowed)
775 "Setting close_pairs_excluded_volume_restraint(), "
776 "max_score %s", max_score)
780 restraint_name, distance=10,
781 weight=1.0, n_pairs=1, stddev=2, max_score=
None):
783 Set a pair_score restraint between the coarse representation
785 @param name1 Name of the first component
786 @param name2 Name of the second component
787 @param restraint_name Name for the restraint
788 @param distance Maximum distance tolerated between particles
789 @param weight Weight of the restraint
791 @param max_score Maximum value tolerated for the restraint
792 @param stddev Standard deviation used to approximate the
793 HarmonicUpperBound function to a Gaussian
800 A = representation.get_component(self.coarse_assembly, name1)
801 marker1 =
IMP.Particle(self.model,
"marker1 " + restraint_name)
802 table_refiner.add_particle(marker1, atom.get_leaves(A))
804 B = representation.get_component(self.coarse_assembly, name2)
805 marker2 =
IMP.Particle(self.model,
"marker2 " + restraint_name)
806 table_refiner.add_particle(marker2, atom.get_leaves(B))
808 k = core.Harmonic.get_k_from_standard_deviation(stddev)
818 error_distance_allowed = 10
819 max_score = weight * n_pairs * \
820 temp_score.evaluate(distance + error_distance_allowed)
822 log.info(
"Setting pair score restraint for %s %s. k = %s, max_score "
823 "= %s, stddev %s", name1, name2, k, max_score, stddev)
829 Write the results of the DOMINO sampling to a SQLite database.
831 @param max_number Maximum number of results to write
833 log.info(
"Creating the database of solutions")
834 if self.measure_models
and not hasattr(self,
"native_model"):
835 raise ValueError(
"The native model has not been set")
837 db.create(fn_database, overwrite=
True)
838 db.connect(fn_database)
839 subset = self.rb_states_table.get_subset()
841 db.add_results_table(restraints_names, self.measure_models)
842 n = len(self.solution_assignments)
843 if max_number
is not None:
844 n = min(n, max_number)
845 for sol_id, assignment
in enumerate(self.solution_assignments[0:n]):
849 RFs = [rb.get_reference_frame()
for rb
in self.components_rbs]
853 if(self.measure_models):
854 measures =
measure_model(self.assembly, self.native_assembly,
855 self.components_rbs, self.native_rbs)
856 db.add_record(sol_id, txt, RFs, total_score, scores, measures)
858 if self.measure_models:
859 assignment =
"native"
860 RFs = [rb.get_reference_frame()
for rb
in self.native_rbs]
863 db.add_native_record(assignment, RFs, total_score, scores)
868 """ Get the names of the restraints used for a subset
869 @param subset Subset of components of the assembly
871 return [r.get_name()
for r
872 in self.restraint_cache.get_restraints(subset, [])]
876 Get values of the restraints for the native structure
877 @param restraints_names Names of the restraints requested
878 @return a list with the values of all scores, and the total score
880 saved = [rb.get_reference_frame()
for rb
in self.components_rbs]
882 for rb, rn
in zip(self.components_rbs, self.native_rbs):
884 rb_members = [m
for m
in rb.get_members()
885 if not core.RigidBody.get_is_setup(m.get_particle())]
886 rn_members = [m
for m
in rn.get_members()
887 if not core.RigidBody.get_is_setup(m.get_particle())]
888 rb_coords = [m.get_coordinates()
for m
in rb_members]
889 rn_coords = [m.get_coordinates()
for m
in rn_members]
892 if len(rn_coords) != len(rb_coords):
893 raise ValueError(
"Mismatch in the number of members. "
894 "Reference %d Aligned %d "
895 % (len(rn_coords), len(rb_coords)))
896 T = alg.get_transformation_aligning_first_to_second(rb_coords,
898 t = rb.get_reference_frame().get_transformation_to()
899 new_t = alg.compose(T, t)
900 rb.set_reference_frame(alg.ReferenceFrame3D(new_t))
902 for name
in restraints_names:
903 scores.append(self.restraints[name].evaluate(
False))
904 total_score = sum(scores)
905 representation.set_reference_frames(self.components_rbs, saved)
906 return scores, total_score
910 Write the solution in the assignment
911 @param assignment Assignment class with the states for the subset
912 @param fn_pdb File to write the model
914 if not self.assignments_sampling_done:
915 raise ValueError(
"DominoModel: sampling not done")
916 log.info(
"Writting PDB %s for assignment %s", fn_pdb, assignment)
918 atom.write_pdb(self.assembly, fn_pdb)
922 Write a file with a configuration for the model (configuration
923 here means a configuration in DOMINO)
924 @param n Index of the configuration desired.
927 if not self.configuration_sampling_done:
928 raise ValueError(
"DominoModel: sampling not done")
929 log.debug(
"Writting PDB %s for configuration %s", fn_pdb, n)
930 configuration_set.load_configuration(n)
931 atom.write_pdb(self.assembly, fn_pdb)
935 Write a PDB file with a solution given by a set of reference frames
936 @param RFs Reference frames for the elements of the complex
937 @param fn_pdb File to write the solution
939 log.debug(
"Writting PDB %s for reference frames %s", fn_pdb, RFs)
940 representation.set_reference_frames(self.components_rbs, RFs)
941 atom.write_pdb(self.assembly, fn_pdb)
945 Write a separate PDB for each of the elements
946 @param RFs Reference frames for the elements of the complex
947 @param fn_base base string to build the names of the PDBs files
949 log.debug(
"Writting PDBs with basename %s", fn_base)
950 representation.set_reference_frames(self.components_rbs, RFs)
951 for i, ch
in enumerate(self.assembly.get_children()):
952 atom.write_pdb(ch, fn_base +
"component-%02d.pdb" % i)
956 Write one component of the assembly
957 @param component_index Position of the component in the assembly
958 @param ref Reference frame of the component
959 @param fn_pdb Output PDB
961 (
"Writting PDB %s for component %s", fn_pdb, component_index)
962 self.components_rbs[component_index].set_reference_frame(ref)
963 hierarchy_component = self.assembly.get_child(component_index)
964 atom.write_pdb(hierarchy_component, fn_pdb)
967 """Get a ScoringFunction that includes all restraints."""
969 list(self.restraints.values()))
973 Write the solution of a MonteCarlo run
974 @param fn_database Database file with the solution.
975 The database will contain only one record
980 for r
in self.restraints.values():
981 score = r.evaluate(
False)
982 rnames.append(r.get_name())
986 db.create(fn_database, overwrite=
True)
987 db.connect(fn_database)
988 db.add_results_table(rnames, self.measure_models)
989 RFs = [rb.get_reference_frame()
for rb
in self.components_rbs]
991 if(self.measure_models):
992 measures =
measure_model(self.assembly, self.native_assembly,
993 self.components_rbs, self.native_rbs)
995 db.add_record(solution_id,
"", RFs, total_score, scores, measures)
999 def print_restraints_values(self):
1000 print(
"Restraints: Name, weight, value, maximum_value")
1002 for r
in self.restraints.values():
1003 score = r.evaluate(
False)
1006 print(
"%20s %18f %18f" % (r.get_name(), r.get_weight(), score))
1007 total_score += score
1008 print(
"total_score:", total_score)
1013 "Anchor" a set of rigid bodies, by setting the position of one of them
1014 at the origin (0,0,0).
1015 @param components_rbs Rigid bodies of the components
1016 @param anchored - List of True/False values indicating if the components
1017 of the assembly are anchored. The function sets the FIRST anchored
1018 component in the (0,0,0) coordinate and moves the other
1019 components with the same translation. If all the values are False, the
1020 function does not do anything
1022 if True in anchored:
1024 for a, rb
in zip(anchored, components_rbs):
1028 center = anchored_rb.get_coordinates()
1029 log.info(
"Anchoring assembly at (0,0,0)")
1030 for rb
in components_rbs:
1031 T = rb.get_reference_frame().get_transformation_to()
1032 t = T.get_translation()
1033 R = T.get_rotation()
1034 log.debug(
"%s: Rerefence frame BEFORE %s",
1035 rb.get_name(), rb.get_reference_frame())
1036 T2 = alg.Transformation3D(R, t - center)
1037 rb.set_reference_frame(alg.ReferenceFrame3D(T2))
1038 log.debug(
"%s Rerefence frame AFTER %s",
1039 rb.get_name(), rb.get_reference_frame())
1044 Get the drms, cdrms and crmsd for a model
1045 @param assembly Hierarchy for an assembly
1046 @param native_assembly Hierarchy of the native structure
1047 @param rbs Rigid bodies for the components of the assembly
1048 @param native_rbs Rigid bodies for the components of the native
1050 @return cdrms, cdrms, crmsd
1051 - drms - typical drms measure
1052 - cdrms - drms for the centroids of the rigid bodies of the components
1054 - crmsd - rmsd for the centroids
1056 log.debug(
"Measure model")
1057 drms = comparisons.get_drms_for_backbone(assembly, native_assembly)
1058 RFs = [rb.get_reference_frame()
for rb
in rbs]
1059 vs = [r.get_transformation_to().get_translation()
for r
in RFs]
1060 nRFs = [rb.get_reference_frame()
for rb
in native_rbs]
1061 nvs = [r.get_transformation_to().get_translation()
for r
in nRFs]
1062 cdrms = atom.get_drms(vs, nvs)
1063 crmsd, RFs = alignments.align_centroids_using_pca(RFs, nRFs)
1064 log.debug(
"drms %s cdrms %s crmsd %s", drms, cdrms, crmsd)
1065 return [drms, cdrms, crmsd]
1070 Return a list of the coordinates of all the members
1073 if len(rigid_bodies) == 0:
1075 "get_coordinates: There are no rigid bodies to get "
1078 for rb
in rigid_bodies:
1080 rb_members = [m
for m
in rb.get_members()
1081 if not core.RigidBody.get_is_setup(m.get_particle())]
1082 coords.extend([m.get_coordinates()
for m
in rb_members])
def write_pdb_for_component
Write one component of the assembly.
def get_assignment_and_RFs
Return a line with texts for an assignment and the the reference frames of the RigidBodies in the sub...
Utility functions to handle restraints.
A harmonic upper bound on the distance between two spheres.
Lower bound harmonic function (non-zero when feature < mean)
Compute the complementarity between two molecules.
def set_rb_states
Add a set of reference frames as possible states for a rigid body.
Apply a score to a fixed number of close pairs from the two sets.
def add_exclusion_filter_table
ExclusionSubsetFilterTable ensures that two particles are not given the same state at the same time...
Restraints using electron microscopy 2D images (class averages).
def get_restraints_names_used
Get the names of the restraints used for a subset.
def write_solutions_database
Write the results of the DOMINO sampling to a SQLite database.
Upper bound harmonic function (non-zero when feature > mean)
Apply the score to all pairs whose spheres are within a distance threshold.
def get_assignment_scores
Returns a list with the values for the restraints on a subset of the components of the assembly...
Utility functions to handle representation.
def anchor_assembly
"Anchor" a set of rigid bodies, by setting the position of one of them at the origin (0...
Utility functions to handle alignments.
Sample best solutions using Domino.
def set_close_pairs_excluded_volume_restraint
Creates an excluded volume restraint between all the components of the coarse assembly.See help for.
def set_xlink_restraint
Set a restraint on the maximum distance between 2 residues.
def get_assignment_text
Get the formatted text for an assignment.
def load_state
Load the positions of the components given by the assignment.
Filter a configuration of the subset using the Model thresholds.
Represent a subset of the particles being optimized.
def get_coordinates
Return a list of the coordinates of all the members of the rigid bodies.
Utility functions to handle IO.
Create a scoring function on a list of restraints.
A score on the distance between the surfaces of two spheres.
def create_merge_tree
Creates a merge tree from the restraints that are set already.
Management of a model using DOMINO.
Class defining a cross-link.
def get_restraint_value_for_assignment
Recover the value of a restraint.
def write_merge_tree
Writes the current merge tree to file.
def set_connectivity_restraint
Set a connectivity restraint between the elements of the assembly.
def write_pdbs_for_reference_frames
Write a separate PDB for each of the elements.
Class for storing model, its restraints, constraints, and particles.
def write_pdb_for_reference_frames
Write a PDB file with a solution given by a set of reference frames.
Do not allow two particles to be in the same state.
def create_coarse_assembly
Simplify the assembly with a coarse representation.
def write_subset
Writes lines describing a subset (vertex of a merge tree)
def get_restraints_for_native
Get values of the restraints for the native structure.
Utility functions to store and retrieve solution information.
A lookup based particle refiner.
def set_native_assembly_for_benchmark
Sets the native model for benchmark, by reading the native structure and set the rigid bodies...
def get_scoring_function
Get a ScoringFunction that includes all restraints.
def do_sampling
Do Domino sampling.
def write_pdb_for_configuration
Write a file with a configuration for the model (configuration here means a configuration in DOMINO) ...
def set_complementarity_restraint
Set a restraint for geometric complementarity between 2 components.
def measure_model
Get the drms, cdrms and crmsd for a model.
Fitting atomic structures into a cryo-electron microscopy density map.
Class for managing the results of the experiments.
def set_assembly
Sets an assembly from a single PDB file.
def get_assignment_info
Info related to an assignment.
def read_merge_tree
Read and create a merge tree from a file.
def setup_domino_sampler
Creates a DOMINO sampler and adds the required filter tables.
Description of crosslinking restraints as a python dictionary.
def align_rigid_bodies_states
Aligns the set of structures considered for DOMINO sampling.
Basic functionality that is expected to be used by a wide variety of IMP users.
General purpose algebraic and geometric methods that are expected to be used by a wide variety of IMP...
Parameters used by Em2DRestraint and ProjectionFinder.
def get_assignments_with_heap
Domino sampling that recovers the assignments for the root of the merge tree, but conserving only the...
def set_pair_score_restraint
Set a pair_score restraint between the coarse representation of two components.
Utility functions for comparisons.
Class to handle individual particles of a Model object.
def set_em2d_restraint
Set a Restraint computing the em2d score.
def add_branch_and_bound_assignments_table
BranchAndBoundAssignmentsTable enumerate states based on provided filtered using the provided the sub...
def set_not_optimized
Set a part of the model as not optimized (it does not move during the model optimization) ...
Store a set of k top scoring assignments.
def add_restraint
Adds a restraint to the model.
Applies a PairScore to a Pair.
Functionality for loading, creating, manipulating and scoring atomic structures.
Utility functions to handle cross links.
Select hierarchy particles identified by the biological name.
def write_pdb_for_assignment
Write the solution in the assignment.
Divide-and-conquer inferential optimization in discrete space.
def set_assembly_components
Sets the components of an assembly, each one given as a separate PDB file.
def add_restraint_score_filter_table
Add a RestraintScoreSubsetFilterTable to DOMINO that allows to reject assignments that have score wor...
def write_monte_carlo_solution
Write the solution of a MonteCarlo run.