def exercise():
  t = covalent_radii.table("sI")
  assert t.label() == "Si"
  assert approx_equal(t.radius(), 1.11)
  assert approx_equal(t.esd(), 0.02)
  n = 0
  for t in covalent_radii.table_iterator():
    n += 1
    if (n == 1):
      assert t.label() == "H"
    elif (n == 97):
      assert t.label() == "Cm"
    u = covalent_radii.table(t.label())
    assert u.label() == t.label()
  assert n == 97
Exemple #2
0
def exercise():
    t = covalent_radii.table("sI")
    assert t.label() == "Si"
    assert approx_equal(t.radius(), 1.11)
    assert approx_equal(t.esd(), 0.02)
    n = 0
    for t in covalent_radii.table_iterator():
        n += 1
        if (n == 1):
            assert t.label() == "H"
        elif (n == 97):
            assert t.label() == "Cm"
        u = covalent_radii.table(t.label())
        assert u.label() == t.label()
    assert n == 97
Exemple #3
0
 def __init__(self,
              structure,
              **kwds):
   from cctbx.eltbx import covalent_radii
   self.structure = structure
   libtbx.adopt_optional_init_args(self, kwds)
   max_r = 0
   for st in structure.scattering_type_registry().type_index_pairs_as_dict():
     r = 0
     if self.radii:
       r = self.radii.get(st, 0)
     if r == 0:
       r = covalent_radii.table(st).radius()
     if r > max_r: max_r = r
   self.structure = structure
   self.buffer_thickness = 2*max_r + self.covalent_bond_tolerance
   asu_mappings = structure.asu_mappings(
     buffer_thickness=self.buffer_thickness)
   self._pair_asu_table = crystal.pair_asu_table(asu_mappings)
   self._pair_asu_table_needs_updating = False
   if self.radii is None:
     self.radii = {}
   self._pair_asu_table.add_covalent_pairs(
     structure.scattering_types(),
     conformer_indices=self.conformer_indices,
     sym_excl_indices=self.sym_excl_indices,
     tolerance=self.covalent_bond_tolerance,
     radii=self.radii
   )
   self.pair_sym_table = self.pair_asu_table.extract_pair_sym_table()
Exemple #4
0
 def __init__(self, structure, **kwds):
     from cctbx.eltbx import covalent_radii
     self.structure = structure
     libtbx.adopt_optional_init_args(self, kwds)
     max_r = 0
     for st in structure.scattering_type_registry(
     ).type_index_pairs_as_dict():
         r = 0
         if self.radii:
             r = self.radii.get(st, 0)
         if r == 0:
             r = covalent_radii.table(st).radius()
         if r > max_r: max_r = r
     self.structure = structure
     self.buffer_thickness = 2 * max_r + self.covalent_bond_tolerance
     asu_mappings = structure.asu_mappings(
         buffer_thickness=self.buffer_thickness)
     self._pair_asu_table = crystal.pair_asu_table(asu_mappings)
     self._pair_asu_table_needs_updating = False
     if self.radii is None:
         self.radii = {}
     self._pair_asu_table.add_covalent_pairs(
         structure.scattering_types(),
         conformer_indices=self.conformer_indices,
         sym_excl_indices=self.sym_excl_indices,
         tolerance=self.covalent_bond_tolerance,
         radii=self.radii)
     self.pair_sym_table = self.pair_asu_table.extract_pair_sym_table()
def exercise_hbond_as_cif_loop():
  xs = sucrose()
  for sc in xs.scatterers():
    sc.flags.set_grad_site(True)
  radii = [
    covalent_radii.table(elt).radius() for elt in
    xs.scattering_type_registry().type_index_pairs_as_dict() ]
  asu_mappings = xs.asu_mappings(
    buffer_thickness=2*max(radii) + 0.5)
  pair_asu_table = crystal.pair_asu_table(asu_mappings)
  pair_asu_table.add_covalent_pairs(
    xs.scattering_types(),
    tolerance=0.5)
  hbonds = [
    geometry.hbond(1,5, sgtbx.rt_mx('-X,0.5+Y,2-Z')),
    geometry.hbond(5,14, sgtbx.rt_mx('-X,-0.5+Y,1-Z')),
    geometry.hbond(7,10, sgtbx.rt_mx('1+X,+Y,+Z')),
    geometry.hbond(10,0),
    geometry.hbond(12,14, sgtbx.rt_mx('-1-X,0.5+Y,1-Z')),
    geometry.hbond(14,12, sgtbx.rt_mx('-1-X,-0.5+Y,1-Z')),
    geometry.hbond(16,7)
  ]
  loop = geometry.hbonds_as_cif_loop(
    hbonds, pair_asu_table, xs.scatterers().extract_labels(),
    sites_frac=xs.sites_frac()).loop
  s = StringIO()
  print >> s, loop
  assert not show_diff(s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.8200  2.0636  2.8635  165.0  2_557
  O4   H4   O9  0.8200  2.0559  2.8736  174.9  2_546
  O5   H5   O7  0.8200  2.0496  2.8589  169.0  1_655
  O7   H7   O1  0.8200  2.0573  2.8617  166.8  .
  O8   H8   O9  0.8200  2.1407  2.8943  152.8  2_456
  O9   H9   O8  0.8200  2.1031  2.8943  162.1  2_446
  O10  H10  O5  0.8200  2.0167  2.7979  159.1  .

""")
  # with a covariance matrix
  flex.set_random_seed(1)
  vcv_matrix = matrix.diag(
    flex.random_double(size=xs.n_parameters(), factor=1e-5))\
             .as_flex_double_matrix().matrix_symmetric_as_packed_u()
  loop = geometry.hbonds_as_cif_loop(
    hbonds, pair_asu_table, xs.scatterers().extract_labels(),
    sites_frac=xs.sites_frac(),
    covariance_matrix=vcv_matrix,
    parameter_map=xs.parameter_map()).loop
  s = StringIO()
  print >> s, loop
  assert not show_diff(s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.82(3)  2.06(3)    2.86(3)  165.0(18)  2_557
  O4   H4   O9  0.82(4)  2.06(4)    2.87(4)     175(2)  2_546
  O5   H5   O7  0.82(2)  2.05(2)  2.859(19)  169.0(18)  1_655
  O7   H7   O1  0.82(2)  2.06(2)    2.86(2)     167(2)  .
  O8   H8   O9  0.82(3)  2.14(3)    2.89(3)     153(3)  2_456
  O9   H9   O8  0.82(3)  2.10(3)    2.89(3)     162(2)  2_446
  O10  H10  O5  0.82(3)  2.02(3)    2.80(3)     159(3)  .

""")
  cell_vcv = flex.pow2(matrix.diag(flex.random_double(size=6,factor=1e-1))\
                       .as_flex_double_matrix().matrix_symmetric_as_packed_u())
  loop = geometry.hbonds_as_cif_loop(
    hbonds, pair_asu_table, xs.scatterers().extract_labels(),
    sites_frac=xs.sites_frac(),
    covariance_matrix=vcv_matrix,
    cell_covariance_matrix=cell_vcv,
    parameter_map=xs.parameter_map()).loop
  s = StringIO()
  print >> s, loop
  assert not show_diff(s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.82(3)  2.06(4)  2.86(4)  165.0(18)  2_557
  O4   H4   O9  0.82(4)  2.06(4)  2.87(4)     175(2)  2_546
  O5   H5   O7  0.82(2)  2.05(2)  2.86(2)  169.0(18)  1_655
  O7   H7   O1  0.82(2)  2.06(3)  2.86(3)     167(2)  .
  O8   H8   O9  0.82(3)  2.14(4)  2.89(4)     153(3)  2_456
  O9   H9   O8  0.82(3)  2.10(3)  2.89(4)     162(2)  2_446
  O10  H10  O5  0.82(3)  2.02(3)  2.80(3)     159(3)  .

""")
  def __init__(self, xray_structure, name='??',
               **kwds):
    super(xray_structure_viewer, self).__init__(
      unit_cell=xray_structure.unit_cell(),
      orthographic=True,
      light_position=(-1, 1, 1, 0),
      **kwds)
    assert self.bonding in ("covalent", "all")
    assert self.bonding != "all" or self.distance_cutoff is not None
    self.xray_structure = xs = xray_structure
    self.setWindowTitle("%s in %s" % (name,
                                      xs.space_group().type().hall_symbol()))
    sites_frac = xs.sites_frac()
    self.set_extent(sites_frac.min(), sites_frac.max())
    self.is_unit_cell_shown = False

    sites_cart = self.sites_cart = xs.sites_cart()
    thermal_tensors = xs.extract_u_cart_plus_u_iso()
    self.ellipsoid_to_sphere_transforms = {}
    self.scatterer_indices = flex.std_string()
    self.scatterer_labels = flex.std_string()
    for i, (sc, site, u_cart) in enumerate(itertools.izip(xs.scatterers(),
                                                          sites_cart,
                                                          thermal_tensors)):
      t = quadrics.ellipsoid_to_sphere_transform(site, u_cart)
      self.ellipsoid_to_sphere_transforms.setdefault(
        sc.element_symbol(),
        quadrics.shared_ellipsoid_to_sphere_transforms()).append(t)
      self.scatterer_indices.append("# %i" % i)
      self.scatterer_labels.append(sc.label)
    self.labels = None
    self.label_font = QtGui.QFont("Arial Black", pointSize=18)

    if self.bonding == "covalent":
      radii = [
        covalent_radii.table(elt).radius()
        for elt in xs.scattering_type_registry().type_index_pairs_as_dict() ]
      buffer_thickness = 2*max(radii) + self.covalent_bond_tolerance
      asu_mappings = xs.asu_mappings(buffer_thickness=buffer_thickness)
      bond_table = crystal.pair_asu_table(asu_mappings)
      bond_table.add_covalent_pairs(xs.scattering_types(),
                                    tolerance=self.covalent_bond_tolerance)
    elif self.bonding == "all":
      asu_mappings = xs.asu_mappings(buffer_thickness=self.distance_cutoff)
      bond_table = crystal.pair_asu_table(asu_mappings)
      bond_table.add_all_pairs(self.distance_cutoff)

    pair_sym_table = bond_table.extract_pair_sym_table(
      all_interactions_from_inside_asu=True)
    self.bonds = flex.vec3_double()
    self.bonds.reserve(len(xs.scatterers()))
    uc = self.xray_structure.unit_cell()
    frac = mat.rec(uc.fractionalization_matrix(), (3,3))
    inv_frac = frac.inverse()
    site_symms = xs.site_symmetry_table()
    scatt = self.xray_structure.scatterers()
    for i, neighbours in enumerate(pair_sym_table):
      x0 = sites_cart[i]
      sc0 = scatt[i]
      for j, ops in neighbours.items():
        sc1 = scatt[j]
        if sc0.scattering_type == 'H' and sc1.scattering_type == 'H':
          continue
        for op in ops:
          if op.is_unit_mx():
            x1 = sites_cart[j]
          else:
            x1 = uc.orthogonalize(op*sites_frac[j])
            op_cart = inv_frac*mat.rec(op.r().as_double(), (3,3))*frac
            u1 = (op_cart
                  *mat.sym(sym_mat3=thermal_tensors[j])
                  *op_cart.transpose())
            t = quadrics.ellipsoid_to_sphere_transform(x1, u1.as_sym_mat3())
            self.ellipsoid_to_sphere_transforms[sc1.element_symbol()].append(t)
            self.sites_cart.append(x1)
            op_lbl = (" [%s]" % op).lower()
            self.scatterer_indices.append("# %i%s" % (j, op_lbl))
            self.scatterer_labels.append("%s%s" % (sc1.label, op_lbl))
          self.bonds.append(x0)
          self.bonds.append(x1)
def exercise_hbond_as_cif_loop():
    xs = sucrose()
    for sc in xs.scatterers():
        sc.flags.set_grad_site(True)
    radii = [
        covalent_radii.table(elt).radius()
        for elt in xs.scattering_type_registry().type_index_pairs_as_dict()
    ]
    asu_mappings = xs.asu_mappings(buffer_thickness=2 * max(radii) + 0.5)
    pair_asu_table = crystal.pair_asu_table(asu_mappings)
    pair_asu_table.add_covalent_pairs(xs.scattering_types(), tolerance=0.5)
    hbonds = [
        geometry.hbond(1, 5, sgtbx.rt_mx('-X,0.5+Y,2-Z')),
        geometry.hbond(5, 14, sgtbx.rt_mx('-X,-0.5+Y,1-Z')),
        geometry.hbond(7, 10, sgtbx.rt_mx('1+X,+Y,+Z')),
        geometry.hbond(10, 0),
        geometry.hbond(12, 14, sgtbx.rt_mx('-1-X,0.5+Y,1-Z')),
        geometry.hbond(14, 12, sgtbx.rt_mx('-1-X,-0.5+Y,1-Z')),
        geometry.hbond(16, 7)
    ]
    loop = geometry.hbonds_as_cif_loop(hbonds,
                                       pair_asu_table,
                                       xs.scatterers().extract_labels(),
                                       sites_frac=xs.sites_frac()).loop
    s = StringIO()
    print >> s, loop
    assert not show_diff(
        s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.8200  2.0636  2.8635  165.0  2_557
  O4   H4   O9  0.8200  2.0559  2.8736  174.9  2_546
  O5   H5   O7  0.8200  2.0496  2.8589  169.0  1_655
  O7   H7   O1  0.8200  2.0573  2.8617  166.8  .
  O8   H8   O9  0.8200  2.1407  2.8943  152.8  2_456
  O9   H9   O8  0.8200  2.1031  2.8943  162.1  2_446
  O10  H10  O5  0.8200  2.0167  2.7979  159.1  .

""")
    # with a covariance matrix
    flex.set_random_seed(1)
    vcv_matrix = matrix.diag(
      flex.random_double(size=xs.n_parameters(), factor=1e-5))\
               .as_flex_double_matrix().matrix_symmetric_as_packed_u()
    loop = geometry.hbonds_as_cif_loop(hbonds,
                                       pair_asu_table,
                                       xs.scatterers().extract_labels(),
                                       sites_frac=xs.sites_frac(),
                                       covariance_matrix=vcv_matrix,
                                       parameter_map=xs.parameter_map()).loop
    s = StringIO()
    print >> s, loop
    assert not show_diff(
        s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.82(3)  2.06(3)    2.86(3)  165.0(18)  2_557
  O4   H4   O9  0.82(4)  2.06(4)    2.87(4)     175(2)  2_546
  O5   H5   O7  0.82(2)  2.05(2)  2.859(19)  169.0(18)  1_655
  O7   H7   O1  0.82(2)  2.06(2)    2.86(2)     167(2)  .
  O8   H8   O9  0.82(3)  2.14(3)    2.89(3)     153(3)  2_456
  O9   H9   O8  0.82(3)  2.10(3)    2.89(3)     162(2)  2_446
  O10  H10  O5  0.82(3)  2.02(3)    2.80(3)     159(3)  .

""")
    cell_vcv = flex.pow2(matrix.diag(flex.random_double(size=6,factor=1e-1))\
                         .as_flex_double_matrix().matrix_symmetric_as_packed_u())
    loop = geometry.hbonds_as_cif_loop(hbonds,
                                       pair_asu_table,
                                       xs.scatterers().extract_labels(),
                                       sites_frac=xs.sites_frac(),
                                       covariance_matrix=vcv_matrix,
                                       cell_covariance_matrix=cell_vcv,
                                       parameter_map=xs.parameter_map()).loop
    s = StringIO()
    print >> s, loop
    assert not show_diff(
        s.getvalue(), """\
loop_
  _geom_hbond_atom_site_label_D
  _geom_hbond_atom_site_label_H
  _geom_hbond_atom_site_label_A
  _geom_hbond_distance_DH
  _geom_hbond_distance_HA
  _geom_hbond_distance_DA
  _geom_hbond_angle_DHA
  _geom_hbond_site_symmetry_A
  O2   H2   O4  0.82(3)  2.06(4)  2.86(4)  165.0(18)  2_557
  O4   H4   O9  0.82(4)  2.06(4)  2.87(4)     175(2)  2_546
  O5   H5   O7  0.82(2)  2.05(2)  2.86(2)  169.0(18)  1_655
  O7   H7   O1  0.82(2)  2.06(3)  2.86(3)     167(2)  .
  O8   H8   O9  0.82(3)  2.14(4)  2.89(4)     153(3)  2_456
  O9   H9   O8  0.82(3)  2.10(3)  2.89(4)     162(2)  2_446
  O10  H10  O5  0.82(3)  2.02(3)  2.80(3)     159(3)  .

""")
    def __init__(self, xray_structure, name='??', **kwds):
        super(xray_structure_viewer,
              self).__init__(unit_cell=xray_structure.unit_cell(),
                             orthographic=True,
                             light_position=(-1, 1, 1, 0),
                             **kwds)
        assert self.bonding in ("covalent", "all")
        assert self.bonding != "all" or self.distance_cutoff is not None
        self.xray_structure = xs = xray_structure
        self.setWindowTitle("%s in %s" %
                            (name, xs.space_group().type().hall_symbol()))
        sites_frac = xs.sites_frac()
        self.set_extent(sites_frac.min(), sites_frac.max())
        self.is_unit_cell_shown = False

        sites_cart = self.sites_cart = xs.sites_cart()
        thermal_tensors = xs.extract_u_cart_plus_u_iso()
        self.ellipsoid_to_sphere_transforms = {}
        self.scatterer_indices = flex.std_string()
        self.scatterer_labels = flex.std_string()
        for i, (sc, site, u_cart) in enumerate(
                zip(xs.scatterers(), sites_cart, thermal_tensors)):
            t = quadrics.ellipsoid_to_sphere_transform(site, u_cart)
            self.ellipsoid_to_sphere_transforms.setdefault(
                sc.element_symbol(),
                quadrics.shared_ellipsoid_to_sphere_transforms()).append(t)
            self.scatterer_indices.append("# %i" % i)
            self.scatterer_labels.append(sc.label)
        self.labels = None
        self.label_font = QtGui.QFont("Arial Black", pointSize=18)

        if self.bonding == "covalent":
            radii = [
                covalent_radii.table(elt).radius() for elt in
                xs.scattering_type_registry().type_index_pairs_as_dict()
            ]
            buffer_thickness = 2 * max(radii) + self.covalent_bond_tolerance
            asu_mappings = xs.asu_mappings(buffer_thickness=buffer_thickness)
            bond_table = crystal.pair_asu_table(asu_mappings)
            bond_table.add_covalent_pairs(
                xs.scattering_types(), tolerance=self.covalent_bond_tolerance)
        elif self.bonding == "all":
            asu_mappings = xs.asu_mappings(
                buffer_thickness=self.distance_cutoff)
            bond_table = crystal.pair_asu_table(asu_mappings)
            bond_table.add_all_pairs(self.distance_cutoff)

        pair_sym_table = bond_table.extract_pair_sym_table(
            all_interactions_from_inside_asu=True)
        self.bonds = flex.vec3_double()
        self.bonds.reserve(len(xs.scatterers()))
        uc = self.xray_structure.unit_cell()
        frac = mat.rec(uc.fractionalization_matrix(), (3, 3))
        inv_frac = frac.inverse()
        site_symms = xs.site_symmetry_table()
        scatt = self.xray_structure.scatterers()
        for i, neighbours in enumerate(pair_sym_table):
            x0 = sites_cart[i]
            sc0 = scatt[i]
            for j, ops in neighbours.items():
                sc1 = scatt[j]
                if sc0.scattering_type == 'H' and sc1.scattering_type == 'H':
                    continue
                for op in ops:
                    if op.is_unit_mx():
                        x1 = sites_cart[j]
                    else:
                        x1 = uc.orthogonalize(op * sites_frac[j])
                        op_cart = inv_frac * mat.rec(op.r().as_double(),
                                                     (3, 3)) * frac
                        u1 = (op_cart * mat.sym(sym_mat3=thermal_tensors[j]) *
                              op_cart.transpose())
                        t = quadrics.ellipsoid_to_sphere_transform(
                            x1, u1.as_sym_mat3())
                        self.ellipsoid_to_sphere_transforms[
                            sc1.element_symbol()].append(t)
                        self.sites_cart.append(x1)
                        op_lbl = (" [%s]" % op).lower()
                        self.scatterer_indices.append("# %i%s" % (j, op_lbl))
                        self.scatterer_labels.append("%s%s" %
                                                     (sc1.label, op_lbl))
                    self.bonds.append(x0)
                    self.bonds.append(x1)