Пример #1
0
def exercise_stl_set_unsigned():
  a = shared.stl_set_unsigned()
  assert a.size() == 0
  a = shared.stl_set_unsigned([(2,1)])
  assert a.size() == 1
  assert tuple(a[0]) == (1, 2)
  a = shared.stl_set_unsigned([(2,1),(3,5,2)])
  assert native(a) == [(1, 2), (2, 3, 5)]
  #
  from scitbx.array_family import flex
  b = shared.stl_vector_unsigned()
  s = flex.size_t()
  a.append_union_of_selected_arrays(arrays=b, selection=s)
  assert a.size() == 3
  assert a[2].size() == 0
  b.append([2,1])
  b.append([])
  b.append([4,3,2])
  s.append(2)
  s.append(1)
  a.append_union_of_selected_arrays(arrays=b, selection=s)
  assert tuple(a[3]) == (2,3,4)
  s[1] = 0
  a.append_union_of_selected_arrays(arrays=b, selection=s)
  assert tuple(a[4]) == (1,2,3,4)
  assert native(a) == [(1, 2), (2, 3, 5), (), (2, 3, 4), (1, 2, 3, 4)]
  #
  s = pickle.dumps(a, 1)
  l = pickle.loads(s)
  assert len(l) == len(a)
  for ae,le in zip(a,l):
    assert list(ae) == list(le)
Пример #2
0
def extract_trace (pdb_hierarchy, selection_cache=None) :
  from scitbx.array_family import shared
  if selection_cache is None :
    selection_cache = pdb_hierarchy.atom_selection_cache()
  last_atom     = None
  vertices = selection_cache.selection(
    "(name ' CA ' or name ' P  ') and (altloc 'A' or altloc ' ')")
  last_i_seq = None
  last_labels = None
  atoms = pdb_hierarchy.atoms()
  bonds = shared.stl_set_unsigned(atoms.size())
  for i_seq, atom in enumerate(atoms) :
    labels = atom.fetch_labels()
    if vertices[i_seq] :
      if last_i_seq is not None :
        if (labels.chain_id        == last_labels.chain_id and
            labels.model_id        == last_labels.model_id and
            labels.resseq_as_int() == (last_labels.resseq_as_int() + 1) and
            ((labels.altloc == last_labels.altloc) or
             (labels.altloc == "A" and last_labels.altloc == "") or
             (labels.altloc == ""  and last_labels.altloc == "A"))) :
          bonds[last_i_seq].append(i_seq)
          bonds[i_seq].append(last_i_seq)
      last_i_seq = i_seq
      last_labels = labels
  return bonds
Пример #3
0
 def set_noncovalent_bonds(self, model_id, bonded_atoms, auto_show=False):
     if isinstance(bonded_atoms, list):
         from scitbx.array_family import shared
         bonded_atoms = shared.stl_set_unsigned(bonded_atoms)
     model = self.get_model(model_id)
     if model is not None:
         model.set_noncovalent_bonds(bonded_atoms)
         if auto_show:
             model.flag_show_noncovalent_bonds = True
         self.update_scene = True
Пример #4
0
 def set_noncovalent_bonds (self, model_id, bonded_atoms, auto_show=False) :
   if isinstance(bonded_atoms, list) :
     from scitbx.array_family import shared
     bonded_atoms = shared.stl_set_unsigned(bonded_atoms)
   model = self.get_model(model_id)
   if model is not None :
     model.set_noncovalent_bonds(bonded_atoms)
     if auto_show :
       model.flag_show_noncovalent_bonds = True
     self.update_scene = True
Пример #5
0
def exercise():
    bonds = shared.stl_set_unsigned([[1, 2, 3, 5], [0, 4], [0], [0], [1],
                                     [0, 6, 7, 8], [5], [5], [5], []])

    atoms_drawable = flex.bool([True for i in xrange(0, 10)])
    atoms_drawable_non_h = flex.bool(
        [True, True, False, False, False, True, False, False, False, True])

    # all atoms drawable
    visibility = gltbx.viewer_utils.atom_visibility(
        bonds=bonds, atoms_drawable=atoms_drawable, flag_show_points=True)
    assert (list(visibility.bonds_visible) == [
        True, True, True, True, True, True, True, True, True, False
    ])
    assert (list(visibility.points_visible) == [
        False, False, False, False, False, False, False, False, False, True
    ])

    # hydrogens off, points on
    visibility = gltbx.viewer_utils.atom_visibility(
        bonds=bonds,
        atoms_drawable=atoms_drawable_non_h,
        flag_show_points=True)
    assert (list(visibility.bonds_visible) == [
        True, True, False, False, False, True, False, False, False, False
    ])
    assert (list(visibility.points_visible) == [
        False, False, False, False, False, False, False, False, False, True
    ])

    # equivalent to "not element H"
    atoms_selected_non_h = flex.bool(
        [True, True, False, False, False, True, False, False, False, True])

    visibility.get_selection_visibility(bonds=bonds,
                                        atoms_selected=atoms_selected_non_h)
    assert (list(visibility.selected_points_visible) == [
        False, False, False, False, False, False, False, False, False, True
    ])

    # no hydrogens, no points
    visibility = gltbx.viewer_utils.atom_visibility(
        bonds=bonds,
        atoms_drawable=atoms_drawable_non_h,
        flag_show_points=False)
    assert (list(visibility.bonds_visible) == [
        True, True, False, False, False, True, False, False, False, False
    ])
    assert (not True in list(visibility.points_visible))

    visibility.get_selection_visibility(bonds=bonds,
                                        atoms_selected=atoms_selected_non_h)
    assert (not True in list(visibility.selected_points_visible))
def build_simple_two_way_bond_sets(sites_cart,
                                   elements,
                                   conformer_indices=None,
                                   search_max_distance=None,
                                   tolerance_factor_expected_bond_length=1.3,
                                   fallback_expected_bond_length=2.0,
                                   fallback_search_max_distance=3.0):
    assert sites_cart.size() == elements.size()
    assert (isinstance(tolerance_factor_expected_bond_length, float)
            or isinstance(tolerance_factor_expected_bond_length, int))
    assert (isinstance(fallback_expected_bond_length, float)
            or isinstance(fallback_expected_bond_length, int))
    assert (isinstance(fallback_search_max_distance, float)
            or isinstance(fallback_search_max_distance, int))
    if (conformer_indices is None):
        conformer_indices = flex.size_t(sites_cart.size(), 0)
    stripped_elements = elements.strip().upper()
    if (search_max_distance is None):
        search_max_distance = 2 * max(
            [vdw_radii.get(e, 0.0) for e in stripped_elements])
        if (search_max_distance == 0.0):
            search_max_distance = fallback_search_max_distance
        else:
            search_max_distance *= tolerance_factor_expected_bond_length
    else:
        assert isinstance(search_max_distance, float)
    box_symmetry = cctbx.crystal.symmetry(
        unit_cell=cctbx.uctbx.non_crystallographic_unit_cell(
            sites_cart=sites_cart,
            buffer_layer=search_max_distance *
            (1 + 1.e-4)),  # uncritical tolerance
        space_group_symbol="P1").special_position_settings()
    asu_mappings = box_symmetry.asu_mappings(
        buffer_thickness=search_max_distance, sites_cart=sites_cart)
    pair_generator = cctbx.crystal.neighbors_fast_pair_generator(
        asu_mappings=asu_mappings,
        distance_cutoff=search_max_distance,
        minimal=True)
    result = shared.stl_set_unsigned(sites_cart.size())
    return pair_generator.distance_based_simple_two_way_bond_sets(
        elements=stripped_elements,
        conformer_indices=conformer_indices,
        expected_bond_lengths=expected_bond_lengths,
        vdw_radii=vdw_radii,
        fallback_expected_bond_length=fallback_expected_bond_length,
        tolerance_factor_expected_bond_length=
        tolerance_factor_expected_bond_length)
def build_simple_two_way_bond_sets(
    sites_cart,
    elements,
    conformer_indices=None,
    search_max_distance=None,
    tolerance_factor_expected_bond_length=1.3,
    fallback_expected_bond_length=2.0,
    fallback_search_max_distance=3.0,
):
    assert sites_cart.size() == elements.size()
    assert isinstance(tolerance_factor_expected_bond_length, float) or isinstance(
        tolerance_factor_expected_bond_length, int
    )
    assert isinstance(fallback_expected_bond_length, float) or isinstance(fallback_expected_bond_length, int)
    assert isinstance(fallback_search_max_distance, float) or isinstance(fallback_search_max_distance, int)
    if conformer_indices is None:
        conformer_indices = flex.size_t(sites_cart.size(), 0)
    stripped_elements = elements.strip().upper()
    if search_max_distance is None:
        search_max_distance = 2 * max([vdw_radii.get(e, 0.0) for e in stripped_elements])
        if search_max_distance == 0.0:
            search_max_distance = fallback_search_max_distance
        else:
            search_max_distance *= tolerance_factor_expected_bond_length
    else:
        assert isinstance(search_max_distance, float)
    box_symmetry = cctbx.crystal.symmetry(
        unit_cell=cctbx.uctbx.non_crystallographic_unit_cell(
            sites_cart=sites_cart, buffer_layer=search_max_distance * (1 + 1.0e-4)
        ),  # uncritical tolerance
        space_group_symbol="P1",
    ).special_position_settings()
    asu_mappings = box_symmetry.asu_mappings(buffer_thickness=search_max_distance, sites_cart=sites_cart)
    pair_generator = cctbx.crystal.neighbors_fast_pair_generator(
        asu_mappings=asu_mappings, distance_cutoff=search_max_distance, minimal=True
    )
    result = shared.stl_set_unsigned(sites_cart.size())
    return pair_generator.distance_based_simple_two_way_bond_sets(
        elements=stripped_elements,
        conformer_indices=conformer_indices,
        expected_bond_lengths=expected_bond_lengths,
        vdw_radii=vdw_radii,
        fallback_expected_bond_length=fallback_expected_bond_length,
        tolerance_factor_expected_bond_length=tolerance_factor_expected_bond_length,
    )
Пример #8
0
 def get_simple_bonds(self, selection_phil=None):
     # assert 0 # used in GUI to draw bonds
     # this function wants
     # shared.stl_set_unsigned([(i_seq, j_seq),(i_seq, j_seq)])
     desired_annotation = None
     if (selection_phil is not None):
         if isinstance(selection_phil, str):
             selection_phil = iotbx.phil.parse(selection_phil)
         params = sec_str_master_phil.fetch(source=selection_phil).extract()
         desired_annotation = iotbx.pdb.secondary_structure.annotation.from_phil(
             phil_helices=params.secondary_structure.protein.helix,
             phil_sheets=params.secondary_structure.protein.sheet,
             pdb_hierarchy=self.pdb_hierarchy)
     else:
         desired_annotation = self.actual_sec_str
     hb_proxies, hb_angles = self.create_protein_hbond_proxies(
         annotation=desired_annotation, log=sys.stdout)
     from scitbx.array_family import shared
     simple_bonds = []
     for p in hb_proxies:
         simple_bonds.append(p.i_seqs)
     return shared.stl_set_unsigned(simple_bonds)
Пример #9
0
 def get_simple_bonds (self, selection_phil=None) :
   # assert 0 # used in GUI to draw bonds
   # this function wants
   # shared.stl_set_unsigned([(i_seq, j_seq),(i_seq, j_seq)])
   desired_annotation = None
   if (selection_phil is not None) :
     if isinstance(selection_phil, str) :
       selection_phil = iotbx.phil.parse(selection_phil)
     params = sec_str_master_phil.fetch(source=selection_phil).extract()
     desired_annotation = iotbx.pdb.secondary_structure.annotation.from_phil(
         phil_helices=params.secondary_structure.protein.helix,
         phil_sheets=params.secondary_structure.protein.sheet,
         pdb_hierarchy=self.pdb_hierarchy)
   else :
     desired_annotation = self.actual_sec_str
   hb_proxies = self.create_protein_hbond_proxies(
       annotation=desired_annotation,
       log=sys.stdout)
   from scitbx.array_family import shared
   simple_bonds = []
   for p in hb_proxies:
     simple_bonds.append(p.i_seqs)
   return shared.stl_set_unsigned(simple_bonds)
Пример #10
0
def exercise () :
  bonds = shared.stl_set_unsigned([
    [1, 2, 3, 5],
    [0, 4],
    [0],
    [0],
    [1],
    [0, 6, 7, 8],
    [5],
    [5],
    [5],
    []
  ])

  atoms_drawable = flex.bool([True for i in xrange(0, 10) ])
  atoms_drawable_non_h = flex.bool(
    [True, True, False, False, False, True, False, False, False, True]
  )

  # all atoms drawable
  visibility = gltbx.viewer_utils.atom_visibility(
    bonds            = bonds,
    atoms_drawable   = atoms_drawable,
    flag_show_points = True
  )
  assert (list(visibility.bonds_visible) ==
    [True, True, True, True, True, True, True, True, True, False]
  )
  assert (list(visibility.points_visible) ==
    [False, False, False, False, False, False, False, False, False, True]
  )

  # hydrogens off, points on
  visibility = gltbx.viewer_utils.atom_visibility(
    bonds            = bonds,
    atoms_drawable   = atoms_drawable_non_h,
    flag_show_points = True
  )
  assert (list(visibility.bonds_visible) ==
    [True, True, False, False, False, True, False, False, False, False]
  )
  assert (list(visibility.points_visible) ==
    [False, False, False, False, False, False, False, False, False, True]
  )

  # equivalent to "not element H"
  atoms_selected_non_h = flex.bool(
    [True, True, False, False, False, True, False, False, False, True]
  )

  visibility.get_selection_visibility(
    bonds          = bonds,
    atoms_selected = atoms_selected_non_h
  )
  assert (list(visibility.selected_points_visible) ==
    [False, False, False, False, False, False, False, False, False, True]
  )

  # no hydrogens, no points
  visibility = gltbx.viewer_utils.atom_visibility(
    bonds            = bonds,
    atoms_drawable   = atoms_drawable_non_h,
    flag_show_points = False
  )
  assert (list(visibility.bonds_visible) ==
    [True, True, False, False, False, True, False, False, False, False]
  )
  assert (not True in list(visibility.points_visible))

  visibility.get_selection_visibility(
    bonds          = bonds,
    atoms_selected = atoms_selected_non_h
  )
  assert (not True in list(visibility.selected_points_visible))