Exemplo n.º 1
0
 def minimum_covering_sphere(self, epsilon=None):
   if (epsilon is None): epsilon = 1.e-3
   points = flex.vec3_double()
   orth = self.unit_cell.orthogonalize
   for vertex in self.shape_vertices():
     points.append(orth([float(e) for e in vertex]))
   return minimum_covering_sphere(points=points, epsilon=epsilon)
Exemplo n.º 2
0
    def set_points_and_lines(self, simulation_factory_index, n_zigzag):
        if (simulation_factory_index == 0):
            self.sim = tst_molecules.simulation_zigzag(NB=n_zigzag)
        else:
            self.sim = tst_molecules.simulation_factories[
                simulation_factory_index]()
        self.points = flex.vec3_double()
        self.set_points()

        def add_line(i, j, color):
            line = (i, j)
            self.line_i_seqs.append(line)
            self.line_colors[line] = color

        self.labels = []
        B_off = []
        for B in self.sim.bodies:
            B_off.append(len(self.labels))
            self.labels.extend(B.labels)

            def add_off(i):
                if (i < 0): return B_off[B.parent + 1] + i
                else: return B_off[-1] + i

            for bond in B.bonds:
                i, j = [add_off(b) for b in bond]
                add_line(i, j, (1, 0, 0))
        mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
        self.minimum_covering_sphere = sphere_3d(center=mcs.center(),
                                                 radius=mcs.radius() * 1.3)
        self.flag_show_minimum_covering_sphere = False
        self.flag_show_rotation_center = False
        self.steps_per_tab = 1
        self.show_key_stroke_help()
Exemplo n.º 3
0
 def set_points_and_lines(self,
                          tardy_model,
                          velocity_scaling=False,
                          e_kin_per_dof=1,
                          minimum_covering_sphere_view_scale=1.3,
                          show_loop_edge_bendings=True,
                          long_labels=None):
     self.tardy_model = tardy_model
     temperature_dof = len(tardy_model.sites) * 3
     if (e_kin_per_dof is None):
         self.e_kin_target = tardy_model.e_kin() / max(1, temperature_dof)
     else:
         self.e_kin_target = e_kin_per_dof * temperature_dof
         tardy_model.assign_random_velocities(
             e_kin_target=self.e_kin_target)
     self.velocity_scaling = velocity_scaling
     self.long_labels = long_labels
     self.labels = self.tardy_model.labels
     self.set_points()
     for line, color in tardy_model.tardy_tree.viewer_lines_with_colors(
             include_loop_edge_bendings=show_loop_edge_bendings):
         self.line_i_seqs.append(line)
         self.line_colors[line] = color
     print("\n".join(
         tardy_model.tardy_tree.viewer_lines_with_colors_legend(
             include_loop_edge_bendings=show_loop_edge_bendings)))
     mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
     self.minimum_covering_sphere = sphere_3d(
         center=mcs.center(),
         radius=mcs.radius() * minimum_covering_sphere_view_scale)
     self.flag_show_minimum_covering_sphere = False
     self.flag_show_rotation_center = False
     self.steps_per_tab = 1
     self.show_key_stroke_help()
Exemplo n.º 4
0
 def __init__(self, *args, **kwds):
   super(MyGLWindow, self).__init__(*args, **kwds)
   self.points = flex.vec3_double([ (-5,-5,-5), (-4,0,0), (0,-8,0), (0,0,-11) ])
   self.line_i_seqs = [ (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) ]
   self.spheres = [ ((0,0,0), 1) ]
   self.flag_show_minimum_covering_sphere = False
   self.minimum_covering_sphere = minimum_covering_sphere(self.points)
Exemplo n.º 5
0
 def set_points_and_lines(self):
   self.sim_as = simulation()
   self.sim_ac = simulation()
   self.points = flex.vec3_double(self.sim_as.sites_cart_moved_F01)
   self.points.extend(flex.vec3_double(self.sim_ac.sites_cart_moved_F01))
   self.points.extend(flex.vec3_double(self.sim_as.sites_cart_wells_F01))
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   self.labels = []
   n = len(self.sim_as.sites_cart_F1)
   offs = 0
   for prefix,color in [("S",(1,0,0)),("C",(0,0,1)),("W",(0,1,0))]:
     for i in xrange(n):
       add_line(offs+i, offs+(i+1)%n, color)
       self.labels.append(prefix+str(i))
     offs += n
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=mcs.center(), radius=mcs.radius()*1.3)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
   self.steps_per_tab = 8
   print "Press and hold Tab key to run the simulation."
   print "Press Shift-Tab to increase speed."
   print "Press Ctrl-Tab  to decrease speed."
Exemplo n.º 6
0
 def __init__(self, *args, **kwds):
     wxGLWindow.__init__(self, *args, **kwds)
     self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
     self.Bind(wx.EVT_ERASE_BACKGROUND, lambda evt: None)
     # FIXME orthographic is definitely best for this application, but it isn't
     # working properly right now
     #self.orthographic = True
     parent = self.GetParent()
     if (parent is None):
         parent = kwds.get("parent")
     assert (parent is not None)
     self.settings = parent.settings
     self.buffer_factor = 2.0
     self.min_slab = 4
     self.min_viewport_use_fraction = 0.1
     self.min_dist = 4.0
     self.flag_show_fog = True
     self.flag_use_lights = True
     self.flag_use_quadrics = False
     self.minimum_covering_sphere = None
     self.spheres_display_list = None
     self.points_display_list = None
     self.labels_display_list = None
     self.miller_array = None
     self.d_min = None
     self.scene = None
     self.animation_time = 0
     #self.fps = gltbx.viewer_utils.fps_monitor()
     # XXX prevent exception when no data are loaded
     from scitbx.math import minimum_covering_sphere
     from scitbx.array_family import flex
     points = flex.vec3_double([(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)])
     mcs = minimum_covering_sphere(points=points, epsilon=0.1)
     self.minimum_covering_sphere = mcs
Exemplo n.º 7
0
 def set_points_and_lines(self, simulation_factory_index, n_zigzag):
   if (simulation_factory_index == 0):
     self.sim = tst_molecules.simulation_zigzag(NB=n_zigzag)
   else:
     self.sim = tst_molecules.simulation_factories[simulation_factory_index]()
   self.points = flex.vec3_double()
   self.set_points()
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   self.labels = []
   B_off = []
   for B in self.sim.bodies:
     B_off.append(len(self.labels))
     self.labels.extend(B.labels)
     def add_off(i):
       if (i < 0): return B_off[B.parent+1] + i
       else:       return B_off[-1] + i
     for bond in B.bonds:
       i,j = [add_off(b) for b in bond]
       add_line(i, j, (1,0,0))
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=mcs.center(), radius=mcs.radius()*1.3)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
   self.steps_per_tab = 1
   self.show_key_stroke_help()
Exemplo n.º 8
0
 def __init__ (self, *args, **kwds) :
   wxGLWindow.__init__(self, *args, **kwds)
   self.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick)
   self.Bind(wx.EVT_ERASE_BACKGROUND, lambda evt: None)
   # FIXME orthographic is definitely best for this application, but it isn't
   # working properly right now
   #self.orthographic = True
   parent = self.GetParent()
   if (parent is None) :
     parent = kwds.get("parent")
   assert (parent is not None)
   self.settings = parent.settings
   self.buffer_factor = 2.0
   self.min_slab = 4
   self.min_viewport_use_fraction = 0.1
   self.min_dist = 4.0
   self.flag_show_fog = True
   self.flag_use_lights = True
   self.flag_use_quadrics = False
   self.minimum_covering_sphere = None
   self.spheres_display_list = None
   self.points_display_list = None
   self.labels_display_list = None
   self.miller_array = None
   self.d_min = None
   self.scene = None
   self.animation_time = 0
   #self.fps = gltbx.viewer_utils.fps_monitor()
   # XXX prevent exception when no data are loaded
   from scitbx.math import minimum_covering_sphere
   from scitbx.array_family import flex
   points = flex.vec3_double([(0.0,0.0,0.0),(1.0,1.0,1.0)])
   mcs = minimum_covering_sphere(points=points, epsilon=0.1)
   self.minimum_covering_sphere = mcs
Exemplo n.º 9
0
    def set_points_and_lines(self):
        NB = 3
        self.sim = revolute_simulation(mersenne_twister=None,
                                       NB=NB,
                                       config="zigzag")
        self.points = flex.vec3_double()
        self.set_points()
        assert self.points.size() == NB * 3

        def add_line(i, j, color):
            line = (i, j)
            self.line_i_seqs.append(line)
            self.line_colors[line] = color

        self.labels = []
        p, n, s = 0, 1, 2
        for ib in range(NB):
            self.labels.extend(["p%d" % ib, "n%d" % ib, "s%d" % ib])
            add_line(p, n, (1, 0, 0))
            add_line(p, s, (0, 1, 0))
            add_line(n, s, (0, 0, 1))
            p, n, s = p + 3, n + 3, s + 3
        mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
        self.minimum_covering_sphere = sphere_3d(center=mcs.center(),
                                                 radius=mcs.radius() * 1.3)
        self.flag_show_minimum_covering_sphere = False
        self.flag_show_rotation_center = False
        self.steps_per_tab = 8
        print("Press and hold Tab key to run the simulation.")
        print("Press Shift-Tab to increase speed.")
        print("Press Ctrl-Tab  to decrease speed.")
Exemplo n.º 10
0
 def __init__(self, *args, **kwds):
   super(MyGLWindow, self).__init__(*args, **kwds)
   self.points = flex.vec3_double([ (-5,-5,-5), (-4,0,0), (0,-8,0), (0,0,-11) ])
   self.line_i_seqs = [ (0,1), (0,2), (0,3), (1,2), (1,3), (2,3) ]
   self.spheres = [ ((0,0,0), 1) ]
   self.flag_show_minimum_covering_sphere = False
   self.minimum_covering_sphere = minimum_covering_sphere(self.points)
Exemplo n.º 11
0
 def set_points_and_lines(self):
   self.sim_as = simulation()
   self.sim_ac = simulation()
   self.points = flex.vec3_double(self.sim_as.sites_cart_moved_F01)
   self.points.extend(flex.vec3_double(self.sim_ac.sites_cart_moved_F01))
   self.points.extend(flex.vec3_double(self.sim_as.sites_cart_wells_F01))
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   self.labels = []
   n = len(self.sim_as.sites_cart_F1)
   offs = 0
   for prefix,color in [("S",(1,0,0)),("C",(0,0,1)),("W",(0,1,0))]:
     for i in range(n):
       add_line(offs+i, offs+(i+1)%n, color)
       self.labels.append(prefix+str(i))
     offs += n
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=mcs.center(), radius=mcs.radius()*1.3)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
   self.steps_per_tab = 8
   print("Press and hold Tab key to run the simulation.")
   print("Press Shift-Tab to increase speed.")
   print("Press Ctrl-Tab  to decrease speed.")
Exemplo n.º 12
0
 def set_points_and_lines(O, app, minimum_covering_sphere_view_scale=1.3):
     pdb_atoms = app.pdb_atoms
     pdb_atoms.set_chemical_element_simple_if_necessary()
     atom_tmp_sentinel = pdb_atoms.reset_tmp(first_value=0, increment=0)
     for i, rg in enumerate(app.pdb_hierarchy.residue_groups()):
         for atom in rg.atoms():
             atom.tmp = i
     O.points = pdb_atoms.extract_xyz()
     if (app.co.serial_labels):
         m = ""
         need_m = (app.pdb_hierarchy.models_size() != 1)
         for mdl in app.pdb_hierarchy.models():
             if (need_m): m = mdl.id.strip() + ":"
             for i in range(mdl.atoms_size()):
                 O.labels.append(m + str(i))
         assert len(O.labels) == O.points.size()
     else:
         rg_done = set()
         for atom in pdb_atoms:
             i = atom.tmp
             if (i not in rg_done):
                 rg_done.add(i)
                 l = atom.id_str()
             else:
                 l = atom.name
             O.labels.append(l)
     from cctbx.crystal.distance_based_connectivity import \
       build_simple_two_way_bond_sets
     bond_sets = build_simple_two_way_bond_sets(
         sites_cart=O.points, elements=pdb_atoms.extract_element())
     for i, bond_set in enumerate(bond_sets):
         for j in bond_set:
             if (i < j):
                 line = (i, j)
                 ai, aj = [pdb_atoms[_] for _ in line]
                 if (ai.is_in_same_conformer_as(aj)):
                     O.line_i_seqs.append(line)
                     if (ai.tmp == aj.tmp):
                         if (ai.tmp % 2 == 0):
                             color = (0, 0, 1)
                         else:
                             color = (0, 1, 0)
                     else:
                         color = (1, 0, 0)
                     O.line_colors[line] = color
     del atom_tmp_sentinel
     from scitbx.math import minimum_covering_sphere, sphere_3d
     mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
     O.minimum_covering_sphere = sphere_3d(
         center=mcs.center(),
         radius=mcs.radius() * minimum_covering_sphere_view_scale)
     O.flag_show_minimum_covering_sphere = False
     O.flag_show_rotation_center = False
     _ = app.co.labels_threshold
     O.flag_show_labels = (_ == 0 or len(O.points) <= _)
     O.labels_display_list = None
     O.lines_display_list = None
     O.points_display_list = None
Exemplo n.º 13
0
 def construct_reciprocal_space(self, merge=None):
     self.scene = hklview.scene(miller_array=self.miller_array,
                                merge=merge,
                                settings=self.settings)
     from scitbx.math import minimum_covering_sphere
     mcs = minimum_covering_sphere(points=self.scene.points, epsilon=0.1)
     self.minimum_covering_sphere = mcs
     self.spheres_display_list = None
     self.points_display_list = None
     self.labels_display_list = None
     self.rotation_center = (0, 0, 0)
Exemplo n.º 14
0
 def update_mcs(self, points, recenter_and_zoom=True, buffer=0):
     from scitbx.math import minimum_covering_sphere, sphere_3d
     mcs = minimum_covering_sphere(points=points, epsilon=0.1)
     if buffer > 0:
         self.minimum_covering_sphere = sphere_3d(center=mcs.center(),
                                                  radius=mcs.radius() +
                                                  buffer)
     else:
         self.minimum_covering_sphere = mcs
     if (recenter_and_zoom) and (not self.GL_uninitialised):
         self.move_rotation_center_to_mcs_center()
         self.fit_into_viewport()
Exemplo n.º 15
0
 def construct_reciprocal_space (self, merge=None) :
   self.scene = hklview.scene(miller_array=self.miller_array,
     merge=merge,
     settings=self.settings)
   from scitbx.math import minimum_covering_sphere
   mcs = minimum_covering_sphere(points=self.scene.points,
                                 epsilon=0.1)
   self.minimum_covering_sphere = mcs
   self.spheres_display_list = None
   self.points_display_list = None
   self.labels_display_list = None
   self.rotation_center = (0,0,0)
Exemplo n.º 16
0
 def update_mcs (self, points, recenter_and_zoom=True, buffer=0) :
   from scitbx.math import minimum_covering_sphere, sphere_3d
   mcs = minimum_covering_sphere(points=points,
                                 epsilon=0.1)
   if buffer > 0 :
     self.minimum_covering_sphere = sphere_3d(
       center=mcs.center(),
       radius=mcs.radius() + buffer)
   else :
     self.minimum_covering_sphere = mcs
   if (recenter_and_zoom) and (not self.GL_uninitialised) :
     self.move_rotation_center_to_mcs_center()
     self.fit_into_viewport()
Exemplo n.º 17
0
 def __init__ (self, *args, **kwds) :
   wx_viewer.wxGLWindow.__init__(self, *args, **kwds)
   self.SetSize((400,400))
   self.SetMinSize((400,400))
   self.flag_draw_boxes = False
   self.flag_log_scale = False
   self._img = None
   self.x_center = None
   self.y_center = None
   self.buffer_factor = 2.0
   self.scale_factor = 100
   self.rotation_center = (20,-20,0)
   self.minimum_covering_sphere = minimum_covering_sphere(
     flex.vec3_double([[0,0,0],[40,-40,40],[40,0,0],[0,-40,40]]))
   self.zoom_level = 16
Exemplo n.º 18
0
 def __init__(self, *args, **kwds):
   wx_viewer.wxGLWindow.__init__(self, *args, **kwds)
   self.SetSize((400,400))
   self.SetMinSize((400,400))
   self.flag_draw_boxes = False
   self.flag_log_scale = False
   self._img = None
   self.x_center = None
   self.y_center = None
   self.buffer_factor = 2.0
   self.scale_factor = 100
   self.rotation_center = (20,-20,0)
   self.minimum_covering_sphere = minimum_covering_sphere(
     flex.vec3_double([[0,0,0],[40,-40,40],[40,0,0],[0,-40,40]]))
   self.zoom_level = 16
Exemplo n.º 19
0
 def first_motion_callback(self, points):
   self.points = flex.vec3_double(points)
   self.labels = ["A", "B", "C"]
   def add_line(i, j, color):
     line = (i,j)
     self.line_i_seqs.append(line)
     self.line_colors[line] = color
   add_line(0, 1, (1,0,0))
   add_line(1, 2, (0,1,0))
   add_line(2, 0, (0,0,1))
   mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
   self.minimum_covering_sphere = sphere_3d(
     center=matrix.col(mcs.center())+matrix.col((0.5,0.5,0.5)),
     radius=mcs.radius()*2.0)
   self.flag_show_minimum_covering_sphere = False
   self.flag_show_rotation_center = False
Exemplo n.º 20
0
    def first_action_callback(O, tardy_model, rmsd_calculator):
        O.tardy_model = tardy_model
        tpo = tardy_model.potential_obj
        O.draw_map.set_unit_cell_and_density_map(
            unit_cell=tpo.geo_manager.crystal_symmetry.unit_cell(),
            density_map=tpo.density_map)
        O.points = tardy_model.sites_moved().deep_copy()
        if (tpo.ideal_sites_cart is not None):
            O.points.extend(tpo.ideal_sites_cart)
        if (O.points.size() < 20):
            if (tpo.ideal_sites_cart is None):
                O.labels = tardy_model.labels
            else:
                O.labels = tardy_model.labels + [""] * len(tardy_model.labels)

        def draw_ideal_line():
            if (tpo.ideal_sites_cart is None): return
            n = tardy_model.tardy_tree.n_vertices
            ideal_line = tuple([i + n for i in line])
            O.line_i_seqs.append(ideal_line)
            O.line_colors[ideal_line] = [0.6] * 3

        if (tardy_model.potential_obj.reduced_geo_manager is not None):
            for line, color in tardy_model.tardy_tree.viewer_lines_with_colors(
                    include_loop_edge_bendings=False):
                draw_ideal_line()
                O.line_i_seqs.append(line)
                O.line_colors[line] = color
            print "\n".join(
                tardy_model.tardy_tree.viewer_lines_with_colors_legend(
                    include_loop_edge_bendings=False))
        else:
            for line in tardy_model.potential_obj.geo_manager.simple_edge_list(
            ):
                draw_ideal_line()
                O.line_i_seqs.append(line)
                O.line_colors[line] = (1, 0, 0)
        mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
        O.minimum_covering_sphere = sphere_3d(center=mcs.center(),
                                              radius=mcs.radius() * 2.0)
        O.flag_show_minimum_covering_sphere = False
        O.flag_show_rotation_center = False
        O.show_key_stroke_help()
        if (O.first_first): O.first_first = False
        else: O.action_callback()
Exemplo n.º 21
0
    def first_motion_callback(self, points):
        self.points = flex.vec3_double(points)
        self.labels = ["A", "B", "C"]

        def add_line(i, j, color):
            line = (i, j)
            self.line_i_seqs.append(line)
            self.line_colors[line] = color

        add_line(0, 1, (1, 0, 0))
        add_line(1, 2, (0, 1, 0))
        add_line(2, 0, (0, 0, 1))
        mcs = minimum_covering_sphere(self.points, epsilon=1.e-2)
        self.minimum_covering_sphere = sphere_3d(
            center=matrix.col(mcs.center()) + matrix.col((0.5, 0.5, 0.5)),
            radius=mcs.radius() * 2.0)
        self.flag_show_minimum_covering_sphere = False
        self.flag_show_rotation_center = False
Exemplo n.º 22
0
 def __init__ (self, *args, **kwds) :
   if self.initialize_map_viewer_super :
     wxGLWindow.__init__(self, *args, **kwds)
   # various data objects
   self.map_ids     = []
   self.map_objects = []
   self.map_scenes  = {}
   self.show_object = {}
   self.map_panel = None
   # user settings
   self.mesh_line_width = 0.25 # very buggy on OS X + NVidia (and ???)
   self.selected_map_id = None
   self.update_maps = False
   self.flag_show_maps = True
   self.flag_smooth_lines = True
   self.flag_use_materials = False
   self.flag_show_rotation_center = True
   self.minimum_covering_sphere = minimum_covering_sphere(
     flex.vec3_double([[0,0,0],[100,100,100],[100,0,0],[0,100,100]]))
Exemplo n.º 23
0
    def load_residue(self, *args, **kwargs):
        self.points = flex.vec3_double(kwargs['atoms'])
        self.colours = kwargs['colours']
        self.line_i_seqs = kwargs['bonds']
        self.labels = kwargs['labels']
        self.blabels = kwargs['blabels']
        self.uij = kwargs['uij']

        self.minimum_covering_sphere = minimum_covering_sphere(points=self.points)
        self.spheres_display_list = None
        self.points_display_list = None
        self.lines_display_list = None
        self.labels_display_list = None
        self.ellipsoid_display_list = None
        self.blabels_display_list = None
    
        if not self.GL_uninitialised:
            self.move_rotation_center_to_mcs_center()
            self.fit_into_viewport()
Exemplo n.º 24
0
 def first_action_callback(O, tardy_model, rmsd_calculator):
   O.tardy_model = tardy_model
   tpo = tardy_model.potential_obj
   O.draw_map.set_unit_cell_and_density_map(
     unit_cell=tpo.geo_manager.crystal_symmetry.unit_cell(),
     density_map=tpo.density_map)
   O.points = tardy_model.sites_moved().deep_copy()
   if (tpo.ideal_sites_cart is not None):
     O.points.extend(tpo.ideal_sites_cart)
   if (O.points.size() < 20):
     if (tpo.ideal_sites_cart is None):
       O.labels = tardy_model.labels
     else:
       O.labels = tardy_model.labels + [""] * len(tardy_model.labels)
   def draw_ideal_line():
     if (tpo.ideal_sites_cart is None): return
     n = tardy_model.tardy_tree.n_vertices
     ideal_line = tuple([i+n for i in line])
     O.line_i_seqs.append(ideal_line)
     O.line_colors[ideal_line] = [0.6]*3
   if (tardy_model.potential_obj.reduced_geo_manager is not None):
     for line,color in tardy_model.tardy_tree.viewer_lines_with_colors(
           include_loop_edge_bendings=False):
       draw_ideal_line()
       O.line_i_seqs.append(line)
       O.line_colors[line] = color
     print "\n".join(tardy_model.tardy_tree.viewer_lines_with_colors_legend(
       include_loop_edge_bendings=False))
   else:
     for line in tardy_model.potential_obj.geo_manager.simple_edge_list():
       draw_ideal_line()
       O.line_i_seqs.append(line)
       O.line_colors[line] = (1,0,0)
   mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
   O.minimum_covering_sphere = sphere_3d(
     center=mcs.center(),
     radius=mcs.radius()*2.0)
   O.flag_show_minimum_covering_sphere = False
   O.flag_show_rotation_center = False
   O.show_key_stroke_help()
   if (O.first_first): O.first_first = False
   else:               O.action_callback()
Exemplo n.º 25
0
 def set_points_and_lines(
     self,
     tardy_model,
     velocity_scaling=False,
     e_kin_per_dof=1,
     minimum_covering_sphere_view_scale=1.3,
     show_loop_edge_bendings=True,
     long_labels=None,
 ):
     self.tardy_model = tardy_model
     temperature_dof = len(tardy_model.sites) * 3
     if e_kin_per_dof is None:
         self.e_kin_target = tardy_model.e_kin() / max(1, temperature_dof)
     else:
         self.e_kin_target = e_kin_per_dof * temperature_dof
         tardy_model.assign_random_velocities(e_kin_target=self.e_kin_target)
     self.velocity_scaling = velocity_scaling
     self.long_labels = long_labels
     self.labels = self.tardy_model.labels
     self.set_points()
     for line, color in tardy_model.tardy_tree.viewer_lines_with_colors(
         include_loop_edge_bendings=show_loop_edge_bendings
     ):
         self.line_i_seqs.append(line)
         self.line_colors[line] = color
     print "\n".join(
         tardy_model.tardy_tree.viewer_lines_with_colors_legend(include_loop_edge_bendings=show_loop_edge_bendings)
     )
     mcs = minimum_covering_sphere(self.points, epsilon=1.0e-2)
     self.minimum_covering_sphere = sphere_3d(
         center=mcs.center(), radius=mcs.radius() * minimum_covering_sphere_view_scale
     )
     self.flag_show_minimum_covering_sphere = False
     self.flag_show_rotation_center = False
     self.steps_per_tab = 1
     self.show_key_stroke_help()
Exemplo n.º 26
0
 def update_minimum_covering_sphere(self):
   n_points = min(1000, self.points.size())
   isel = flex.random_permutation(self.points.size())[:n_points]
   self.minimum_covering_sphere = minimum_covering_sphere(
     self.points.select(isel))
Exemplo n.º 27
0
 def set_points_and_lines(
       O,
       app,
       minimum_covering_sphere_view_scale=1.3):
   pdb_atoms = app.pdb_atoms
   pdb_atoms.set_chemical_element_simple_if_necessary()
   atom_tmp_sentinel = pdb_atoms.reset_tmp(first_value=0, increment=0)
   for i,rg in enumerate(app.pdb_hierarchy.residue_groups()):
     for atom in rg.atoms():
       atom.tmp = i
   O.points = pdb_atoms.extract_xyz()
   if (app.co.serial_labels):
     m = ""
     need_m = (app.pdb_hierarchy.models_size() != 1)
     for mdl in app.pdb_hierarchy.models():
       if (need_m): m = mdl.id.strip() + ":"
       for i in xrange(mdl.atoms_size()):
         O.labels.append(m+str(i))
     assert len(O.labels) == O.points.size()
   else:
     rg_done = set()
     for atom in pdb_atoms:
       i = atom.tmp
       if (i not in rg_done):
         rg_done.add(i)
         l = atom.id_str()
       else:
         l = atom.name
       O.labels.append(l)
   from cctbx.crystal.distance_based_connectivity import \
     build_simple_two_way_bond_sets
   bond_sets = build_simple_two_way_bond_sets(
     sites_cart=O.points,
     elements=pdb_atoms.extract_element())
   for i,bond_set in enumerate(bond_sets):
     for j in bond_set:
       if (i < j):
         line = (i,j)
         ai, aj = [pdb_atoms[_] for _ in line]
         if (ai.is_in_same_conformer_as(aj)):
           O.line_i_seqs.append(line)
           if (ai.tmp == aj.tmp):
             if (ai.tmp % 2 == 0):
               color = (0,0,1)
             else:
               color = (0,1,0)
           else:
             color = (1,0,0)
           O.line_colors[line] = color
   del atom_tmp_sentinel
   from scitbx.math import minimum_covering_sphere, sphere_3d
   mcs = minimum_covering_sphere(O.points, epsilon=1.e-2)
   O.minimum_covering_sphere = sphere_3d(
     center=mcs.center(),
     radius=mcs.radius()*minimum_covering_sphere_view_scale)
   O.flag_show_minimum_covering_sphere = False
   O.flag_show_rotation_center = False
   _ = app.co.labels_threshold
   O.flag_show_labels = (_ == 0 or len(O.points) <= _)
   O.labels_display_list = None
   O.lines_display_list = None
   O.points_display_list = None
Exemplo n.º 28
0
def set_ensemble_b_factors_to_xyz_displacement(
    pdb_hierarchy,
    include_hydrogens=False,
    include_waters=False,
    use_c_alpha_values=False,
    method="rmsf",
    selection=None,
    substitute_b_value=-1.0,
    logarithmic=False,
    log=None,
):
    """
  Given an ensemble (multi-MODEL PDB hierarchy), calculate the deviation
  between copies of each atom (defined here as either the root-mean-square
  fluctuation, or the radius of the minimum covering sphere) and set the
  isotropic B-factors to this value.
  """
    if log is None:
        log = null_out()
    assert method in ["rmsf", "mcs"]
    from scitbx.math import minimum_covering_sphere
    from scitbx.array_family import flex

    pdb_atoms = pdb_hierarchy.atoms()
    pdb_atoms.reset_i_seq()
    xyz_by_atom = {}

    def get_key(atom):
        labels = atom.fetch_labels()
        return (labels.chain_id, labels.resid(), labels.altloc, atom.name)

    def get_c_alpha(atom):
        if (atom.name.strip() == "CA") and (atom.element.strip() == "C"):
            return atom
        for other in atom.parent().atoms():
            if (other.name.strip() == "CA") and (other.element.strip() == "C"):
                return other
        return None

    for model in pdb_hierarchy.models():
        for atom in model.atoms():
            if selection is not None:
                if not selection[atom.i_seq]:
                    continue
            elif (not include_hydrogens) and (atom.element.strip() in ["H", "D"]):
                continue
            elif (not include_waters) and (atom.parent().resname in ["HOH"]):
                continue
            if (use_c_alpha_values) and (atom.name.strip() != "CA"):
                continue
            atom_key = get_key(atom)
            if atom_key in xyz_by_atom:
                xyz_by_atom[atom_key].append(atom.xyz)
            else:
                xyz_by_atom[atom_key] = flex.vec3_double([atom.xyz])
    dev_by_atom = {}
    for atom_key, xyz in xyz_by_atom.iteritems():
        if method == "mcs":
            mcs = minimum_covering_sphere(points=xyz, epsilon=0.1)
            radius = mcs.radius()
            if logarithmic:
                radius = math.log(radius + 1.0)
            dev_by_atom[atom_key] = radius
        else:
            mean_array = flex.vec3_double(xyz.size(), xyz.mean())
            rmsf = xyz.rms_difference(mean_array)
            dev_by_atom[atom_key] = rmsf
    all_dev = flex.double(dev_by_atom.values())
    if method == "mcs":
        print >> log, "Distribution of sphere radii:"
    else:
        print >> log, "Distribution of root-mean-square fluctuation values:"
    flex.histogram(all_dev, n_slots=20).show(f=log, prefix="  ", format_cutoffs="%.2f")
    for model in pdb_hierarchy.models():
        for atom in model.atoms():
            if use_c_alpha_values:
                c_alpha = get_c_alpha(atom)
                if c_alpha is None:
                    atom.b = substitute_b_value
                else:
                    atom_key = get_key(c_alpha)
                    atom.b = dev_by_atom.get(atom_key, substitute_b_value)
            else:
                atom_key = get_key(atom)
                atom.b = dev_by_atom.get(atom_key, substitute_b_value)
Exemplo n.º 29
0
 def update_minimum_covering_sphere(self):
     n_points = min(1000, self.points.size())
     isel = flex.random_permutation(self.points.size())[:n_points]
     self.minimum_covering_sphere = minimum_covering_sphere(
         self.points.select(isel))
Exemplo n.º 30
0
def set_ensemble_b_factors_to_xyz_displacement(pdb_hierarchy,
                                               include_hydrogens=False,
                                               include_waters=False,
                                               use_c_alpha_values=False,
                                               method="rmsf",
                                               selection=None,
                                               substitute_b_value=-1.0,
                                               logarithmic=False,
                                               log=None):
    """
  Given an ensemble (multi-MODEL PDB hierarchy), calculate the deviation
  between copies of each atom (defined here as either the root-mean-square
  fluctuation, or the radius of the minimum covering sphere) and set the
  isotropic B-factors to this value.
  """
    if (log is None): log = null_out()
    assert (method in ["rmsf", "mcs"])
    from scitbx.math import minimum_covering_sphere
    from scitbx.array_family import flex
    pdb_atoms = pdb_hierarchy.atoms()
    pdb_atoms.reset_i_seq()
    xyz_by_atom = {}

    def get_key(atom):
        labels = atom.fetch_labels()
        return (labels.chain_id, labels.resid(), labels.altloc, atom.name)

    def get_c_alpha(atom):
        if (atom.name.strip() == "CA") and (atom.element.strip() == "C"):
            return atom
        for other in atom.parent().atoms():
            if (other.name.strip() == "CA") and (other.element.strip() == "C"):
                return other
        return None

    for model in pdb_hierarchy.models():
        for atom in model.atoms():
            if (selection is not None):
                if (not selection[atom.i_seq]): continue
            elif (not include_hydrogens) and (atom.element.strip()
                                              in ["H", "D"]):
                continue
            elif (not include_waters) and (atom.parent().resname in ["HOH"]):
                continue
            if (use_c_alpha_values) and (atom.name.strip() != "CA"):
                continue
            atom_key = get_key(atom)
            if (atom_key in xyz_by_atom):
                xyz_by_atom[atom_key].append(atom.xyz)
            else:
                xyz_by_atom[atom_key] = flex.vec3_double([atom.xyz])
    dev_by_atom = {}
    for atom_key, xyz in six.iteritems(xyz_by_atom):
        if (method == "mcs"):
            mcs = minimum_covering_sphere(points=xyz, epsilon=0.1)
            radius = mcs.radius()
            if (logarithmic):
                radius = math.log(radius + 1.0)
            dev_by_atom[atom_key] = radius
        else:
            mean_array = flex.vec3_double(xyz.size(), xyz.mean())
            rmsf = xyz.rms_difference(mean_array)
            dev_by_atom[atom_key] = rmsf
    # NOTE it seems flex.double handles list generators, not sure about funky python3 dict.values() though
    all_dev = flex.double(list(dev_by_atom.values()))
    if (method == "mcs"):
        print("Distribution of sphere radii:", file=log)
    else:
        print("Distribution of root-mean-square fluctuation values:", file=log)
    flex.histogram(all_dev, n_slots=20).show(f=log,
                                             prefix="  ",
                                             format_cutoffs="%.2f")
    for model in pdb_hierarchy.models():
        for atom in model.atoms():
            if (use_c_alpha_values):
                c_alpha = get_c_alpha(atom)
                if (c_alpha is None):
                    atom.b = substitute_b_value
                else:
                    atom_key = get_key(c_alpha)
                    atom.b = dev_by_atom.get(atom_key, substitute_b_value)
            else:
                atom_key = get_key(atom)
                atom.b = dev_by_atom.get(atom_key, substitute_b_value)
Exemplo n.º 31
0
 def update_minimum_covering_sphere(self):
   self.minimum_covering_sphere = minimum_covering_sphere(
     self.points, epsilon=1e-3)
Exemplo n.º 32
0
 def update_minimum_covering_sphere(self):
   self.minimum_covering_sphere = minimum_covering_sphere(
     self.points, epsilon=1e-3)