Exemplo n.º 1
0
def check_adp_set_b_iso(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,        xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart,tolerance)
  assert approx_equal(xrsp.use_u_iso,  xrsp_init.use_u_iso,tolerance)
  assert approx_equal(xrsp.use_u_aniso,xrsp_init.use_u_aniso,tolerance)
  assert approx_equal(xrsp.u_iso_not_used,  xrsp_init.u_iso_not_used,tolerance)
  assert approx_equal(xrsp.u_cart_not_used,xrsp_init.u_cart_not_used,tolerance)
  if(selection_str is None):
    assert not_approx_equal(xrsp.u_iso_used,  xrsp_init.u_iso_used,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
  else:
    arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
    arg2 = xrsp_init.u_iso_used.select(selection.select(xrsp_init.use_u_iso))
    if(arg1.size() > 0): assert not_approx_equal(arg1, arg2,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
Exemplo n.º 2
0
def check_adp_set_b_iso(cmd,
                        xrsp_init,
                        output,
                        selection,
                        selection_str,
                        verbose,
                        tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert approx_equal(xrsp.u_iso_not_used, xrsp_init.u_iso_not_used,
                        tolerance)
    assert approx_equal(xrsp.u_cart_not_used, xrsp_init.u_cart_not_used,
                        tolerance)
    if (selection_str is None):
        assert not_approx_equal(xrsp.u_iso_used, xrsp_init.u_iso_used,
                                tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
    else:
        arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
        arg2 = xrsp_init.u_iso_used.select(
            selection.select(xrsp_init.use_u_iso))
        if (arg1.size() > 0): assert not_approx_equal(arg1, arg2, tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
Exemplo n.º 3
0
def show_scatterer(self, f=None, unit_cell=None):

  if (f is None): f = sys.stdout
  from cctbx import adptbx
  print >> f, "%-4s" % self.label[5:15],
  print >> f, "%-4s" % self.scattering_type,
  #print >> f, "%3d" % self.multiplicity(),
  print >> f, "%6.3f" % (self.fdp),
  print >> f, "(%7.4f %7.4f %7.4f)" % self.site,
  print >> f, "%4.2f" % self.occupancy,
  if self.flags.use_u_iso():
    print >> f, "%6.4f" % self.u_iso,
  else:
    print >> f, '[ - ]',
  if self.flags.use_u_aniso():
    assert unit_cell is not None
    u_cart = adptbx.u_star_as_u_cart(unit_cell, self.u_star)
    print >> f, "%6.4f" % adptbx.u_cart_as_u_iso(u_cart)
    print >> f, "     u_cart =", ("%6.3f " * 5 + "%6.3f") % u_cart,
  else:
    print >> f, '[ - ]',
  if False and (self.fp != 0 or self.fdp != 0):
    print >> f, "\n     fp,fdp = %6.4f,%6.4f" % (
      self.fp,
      self.fdp),
  print >> f
Exemplo n.º 4
0
def show_scatterer(self, f=None, unit_cell=None):

    if (f is None): f = sys.stdout
    from cctbx import adptbx
    print("%-4s" % self.label[5:15], end=' ', file=f)
    print("%-4s" % self.scattering_type, end=' ', file=f)
    #print >> f, "%3d" % self.multiplicity(),
    print("%6.3f" % (self.fdp), end=' ', file=f)
    print("(%7.4f %7.4f %7.4f)" % self.site, end=' ', file=f)
    print("%4.2f" % self.occupancy, end=' ', file=f)
    if self.flags.use_u_iso():
        print("%6.4f" % self.u_iso, end=' ', file=f)
    else:
        print('[ - ]', end=' ', file=f)
    if self.flags.use_u_aniso():
        assert unit_cell is not None
        u_cart = adptbx.u_star_as_u_cart(unit_cell, self.u_star)
        print("%6.4f" % adptbx.u_cart_as_u_iso(u_cart), file=f)
        print("     u_cart =", ("%6.3f " * 5 + "%6.3f") % u_cart,
              end=' ',
              file=f)
    else:
        print('[ - ]', end=' ', file=f)
    if False and (self.fp != 0 or self.fdp != 0):
        print("\n     fp,fdp = %6.4f,%6.4f" % (self.fp, self.fdp),
              end=' ',
              file=f)
    print(file=f)
Exemplo n.º 5
0
def as_pdb_file(self,
      remark,
      remarks,
      fractional_coordinates,
      resname,
      connect):
  if (remark is not None):
    remarks.insert(0, remark)
  s = StringIO()
  for remark in remarks:
    print >> s, "REMARK", remark
  print >> s, "REMARK Number of scatterers:", self.scatterers().size()
  print >> s, "REMARK At special positions:", \
    self.special_position_indices().size()
  if (fractional_coordinates):
    print >> s, "REMARK Fractional coordinates"
  else:
    print >> s, "REMARK Cartesian coordinates"
  print >> s, iotbx.pdb.format_cryst1_record(crystal_symmetry=self)
  print >> s, iotbx.pdb.format_scale_records(unit_cell=self.unit_cell())
  atom = iotbx.pdb.hierarchy.atom_with_labels()
  if (resname is not None):
    atom.resname = resname.upper()
  serial = 0
  for scatterer in self.scatterers():
    serial += 1
    atom.serial = iotbx.pdb.hy36encode(width=5, value=serial)
    if (scatterer.flags.use_u_aniso_only()):
      atom.uij = adptbx.u_star_as_u_cart(self.unit_cell(), scatterer.u_star)
      atom.b = adptbx.u_as_b(adptbx.u_cart_as_u_iso(atom.uij))
    else:
      atom.uij_erase()
      atom.b = adptbx.u_as_b(scatterer.u_iso)
    if (fractional_coordinates):
      atom.xyz = scatterer.site
    else:
      atom.xyz = self.unit_cell().orthogonalize(scatterer.site)
    atom.occ = scatterer.occupancy
    label = scatterer.label.upper()
    atom.name = label[:4]
    if (resname is None):
      atom.resname = label[:3]
    element_symbol = scatterer.element_symbol()
    if (element_symbol is None): element_symbol = "Q"
    assert len(element_symbol) in (1,2)
    atom.element = element_symbol.upper()
    atom.resseq = iotbx.pdb.hy36encode(width=4, value=serial)
    print >> s, atom.format_atom_record_group()
  if (connect is not None):
    assert len(connect) == self.scatterers().size()
    i = 0
    for bonds in connect:
      i += 1
      l = "CONNECT%5d" % i
      for bond in bonds:
        l += "%5d" % (bond+1)
      print >> s, l
  print >> s, "END"
  return s.getvalue()
Exemplo n.º 6
0
def as_pdb_file(self, remark, remarks, fractional_coordinates, resname,
                connect):
    if (remark is not None):
        remarks.insert(0, remark)
    s = StringIO()
    for remark in remarks:
        print >> s, "REMARK", remark
    print >> s, "REMARK Number of scatterers:", self.scatterers().size()
    print >> s, "REMARK At special positions:", \
      self.special_position_indices().size()
    if (fractional_coordinates):
        print >> s, "REMARK Fractional coordinates"
    else:
        print >> s, "REMARK Cartesian coordinates"
    print >> s, iotbx.pdb.format_cryst1_record(crystal_symmetry=self)
    print >> s, iotbx.pdb.format_scale_records(unit_cell=self.unit_cell())
    atom = iotbx.pdb.hierarchy.atom_with_labels()
    if (resname is not None):
        atom.resname = resname.upper()
    serial = 0
    for scatterer in self.scatterers():
        serial += 1
        atom.serial = iotbx.pdb.hy36encode(width=5, value=serial)
        if (scatterer.flags.use_u_aniso_only()):
            atom.uij = adptbx.u_star_as_u_cart(self.unit_cell(),
                                               scatterer.u_star)
            atom.b = adptbx.u_as_b(adptbx.u_cart_as_u_iso(atom.uij))
        else:
            atom.uij_erase()
            atom.b = adptbx.u_as_b(scatterer.u_iso)
        if (fractional_coordinates):
            atom.xyz = scatterer.site
        else:
            atom.xyz = self.unit_cell().orthogonalize(scatterer.site)
        atom.occ = scatterer.occupancy
        label = scatterer.label.upper()
        atom.name = label[:4]
        if (resname is None):
            atom.resname = label[:3]
        element_symbol = scatterer.element_symbol()
        if (element_symbol is None): element_symbol = "Q"
        assert len(element_symbol) in (1, 2)
        atom.element = element_symbol.upper()
        atom.resseq = iotbx.pdb.hy36encode(width=4, value=serial)
        print >> s, atom.format_atom_record_group()
    if (connect is not None):
        assert len(connect) == self.scatterers().size()
        i = 0
        for bonds in connect:
            i += 1
            l = "CONNECT%5d" % i
            for bond in bonds:
                l += "%5d" % (bond + 1)
            print >> s, l
    print >> s, "END"
    return s.getvalue()
Exemplo n.º 7
0
def exercise_factor_u_star_u_iso():
  for i_trial in xrange(100):
    a = flex.random_double(size=9, factor=3)
    a.resize(flex.grid(3,3))
    u = a.matrix_transpose().matrix_multiply(a) # always positive-definite
    u_cart = [u[0],u[4],u[8],u[1],u[2],u[5]]
    unit_cell = uctbx.unit_cell((3,5,7,80,100,110))
    u_star = adptbx.u_cart_as_u_star(unit_cell, u_cart)
    airlie = u_star_minus_u_iso_airlie(unit_cell, u_star)
    ralf = u_star_minus_u_iso_ralf(unit_cell, u_star)
    assert approx_equal(ralf, airlie, 1.e-10)
    f = adptbx.factor_u_star_u_iso(unit_cell=unit_cell, u_star=u_star)
    assert approx_equal(f.u_iso, adptbx.u_cart_as_u_iso(u_cart))
    assert approx_equal(f.u_star_minus_u_iso, airlie, 1.e-10)
Exemplo n.º 8
0
def exercise_factor_u_star_u_iso():
    for i_trial in xrange(100):
        a = flex.random_double(size=9, factor=3)
        a.resize(flex.grid(3, 3))
        u = a.matrix_transpose().matrix_multiply(a)  # always positive-definite
        u_cart = [u[0], u[4], u[8], u[1], u[2], u[5]]
        unit_cell = uctbx.unit_cell((3, 5, 7, 80, 100, 110))
        u_star = adptbx.u_cart_as_u_star(unit_cell, u_cart)
        airlie = u_star_minus_u_iso_airlie(unit_cell, u_star)
        ralf = u_star_minus_u_iso_ralf(unit_cell, u_star)
        assert approx_equal(ralf, airlie, 1.0e-10)
        f = adptbx.factor_u_star_u_iso(unit_cell=unit_cell, u_star=u_star)
        assert approx_equal(f.u_iso, adptbx.u_cart_as_u_iso(u_cart))
        assert approx_equal(f.u_star_minus_u_iso, airlie, 1.0e-10)
Exemplo n.º 9
0
 def show(self, f=None, unit_cell=None):
     if (f is None): f = sys.stdout
     print >> f, "%-4s" % self.label,
     print >> f, "%-4s" % self.scattering_type,
     print >> f, "%3d" % self.multiplicity(),
     print >> f, "(%7.4f %7.4f %7.4f)" % self.site,
     print >> f, "%4.2f" % self.occupancy,
     if self.flags.use_u_iso():
         print >> f, "%6.4f" % self.u_iso,
     else:
         print >> f, '[ - ]',
     if self.flags.use_u_aniso():
         assert unit_cell is not None
         u_cart = adptbx.u_star_as_u_cart(unit_cell, self.u_star)
         print >> f, "%6.4f" % adptbx.u_cart_as_u_iso(u_cart)
         print >> f, "     u_cart =", ("%6.3f " * 5 + "%6.3f") % u_cart,
     else:
         print >> f, '[ - ]',
     if (self.fp != 0 or self.fdp != 0):
         print >> f, "\n     fp,fdp = %6.4f,%6.4f" % (self.fp, self.fdp),
     print >> f
Exemplo n.º 10
0
 def show(self, f=None, unit_cell=None):
     if f is None:
         f = sys.stdout
     print >> f, "%-4s" % self.label,
     print >> f, "%-4s" % self.scattering_type,
     print >> f, "%3d" % self.multiplicity(),
     print >> f, "(%7.4f %7.4f %7.4f)" % self.site,
     print >> f, "%4.2f" % self.occupancy,
     if self.flags.use_u_iso():
         print >> f, "%6.4f" % self.u_iso,
     else:
         print >> f, "[ - ]",
     if self.flags.use_u_aniso():
         assert unit_cell is not None
         u_cart = adptbx.u_star_as_u_cart(unit_cell, self.u_star)
         print >> f, "%6.4f" % adptbx.u_cart_as_u_iso(u_cart)
         print >> f, "     u_cart =", ("%6.3f " * 5 + "%6.3f") % u_cart,
     else:
         print >> f, "[ - ]",
     if self.fp != 0 or self.fdp != 0:
         print >> f, "\n     fp,fdp = %6.4f,%6.4f" % (self.fp, self.fdp),
     print >> f
Exemplo n.º 11
0
def exercise_interface():
  episq = 8*(math.pi**2)
  assert approx_equal(adptbx.u_as_b(2.3), 2.3*episq)
  assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
  u = (3,4,9, 2,1,7)
  assert approx_equal(adptbx.u_as_b(u), [x*episq for x in u])
  assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
  uc = uctbx.unit_cell((5,4,7,80,110,100))
  for fw,bw in ((adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
                (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
                (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
                (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
                (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif)):
    assert approx_equal(bw(uc, fw(uc, u)), u)
  assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
  assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)), 2.3)
  for fw,bw in ((adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
                (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
                (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso)):
    assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
  fc = adptbx.factor_u_cart_u_iso(u_cart=u)
  assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
  assert approx_equal(
    fc.u_cart_minus_u_iso,
    [uii-fc.u_iso for uii in u[:3]]+list(u[3:]))
  f = adptbx.factor_u_star_u_iso(
    unit_cell=uc, u_star=adptbx.u_cart_as_u_star(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.u_star_minus_u_iso,
    adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
  f = adptbx.factor_u_cif_u_iso(
    unit_cell=uc, u_cif=adptbx.u_cart_as_u_cif(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.u_cif_minus_u_iso,
    adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
  f = adptbx.factor_beta_u_iso(
    unit_cell=uc, beta=adptbx.u_cart_as_beta(uc, u))
  assert approx_equal(f.u_iso, fc.u_iso)
  assert approx_equal(
    f.beta_minus_u_iso,
    adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
  assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25,2.3),
                      math.exp(-2.3*0.25))
  assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25,2.3),
                      math.exp(-2.3*episq*0.25))
  assert approx_equal(adptbx.debye_waller_factor_b_iso(uc, (1,2,3), 2.3),
                      adptbx.debye_waller_factor_u_iso(uc, (1,2,3), 2.3/episq))
  u_star = adptbx.u_cart_as_u_star(uc, u)
  dw = adptbx.debye_waller_factor_u_star((1,2,3), u_star)
  assert approx_equal(dw, adptbx.debye_waller_factor_beta((1,2,3),
                            adptbx.u_star_as_beta(u_star)))
  assert approx_equal(dw, adptbx.debye_waller_factor_u_cif(uc, (1,2,3),
                            adptbx.u_star_as_u_cif(uc, u_star)))
  assert approx_equal(dw, adptbx.debye_waller_factor_u_cart(uc, (1,2,3),
                            adptbx.u_star_as_u_cart(uc, u_star)))
  for e in adptbx.eigenvalues(u):
    check_eigenvalue(u, e)
  assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
  assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
  assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
  assert not adptbx.is_positive_definite(u)
  assert not adptbx.is_positive_definite(u, 0)
  assert adptbx.is_positive_definite(u, 1.22)
  up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
  s = adptbx.eigensystem(up)
  assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
  for i in xrange(3):
    check_eigenvector(up, s.values()[i], s.vectors(i))
  c = (1,2,3, 3,-4,5, 4,5,6)
  v = (198,18,1020,116,447,269)
  assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
  assert approx_equal(adptbx.eigensystem(u).values(),
    (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
  s = adptbx.eigensystem(up)
  try: s.vectors(4)
  except RuntimeError, e: assert str(e).endswith("Index out of range.")
  else: raise Exception_expected
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0)
  assert approx_equal(uf, (3.0810418, 4.7950710, 9.3400030,
                           1.7461615, 1.1659954, 6.4800706))
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0, u_max=3)
  assert approx_equal(uf, (2.7430890, 1.0378360, 2.1559895,
                           0.6193215, -0.3921632, 1.2846854))
  uf = adptbx.eigenvalue_filtering(u_cart=u, u_min=0, u_max=3)
  assert approx_equal(scitbx.linalg.eigensystem.real_symmetric(u).values(),
                      (14.2792015, 2.9369144, -1.2161159))
  assert approx_equal(scitbx.linalg.eigensystem.real_symmetric(uf).values(),
                      (3, 2.9369144, 0))
  uf = adptbx.eigenvalue_filtering(up)
  assert approx_equal(uf, up)
Exemplo n.º 12
0
def u_star_minus_u_iso_ralf(unit_cell, u_star):
  u_cart = adptbx.u_star_as_u_cart(unit_cell, u_star)
  u_iso = adptbx.u_cart_as_u_iso(u_cart)
  u_cart_minus_u_iso = [a-u_iso for a in u_cart[:3]] + list(u_cart[3:])
  return adptbx.u_cart_as_u_star(unit_cell, u_cart_minus_u_iso)
Exemplo n.º 13
0
def exercise_interface():
    episq = 8 * (math.pi**2)
    assert approx_equal(adptbx.u_as_b(2.3), 2.3 * episq)
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
    u = (3, 4, 9, 2, 1, 7)
    assert approx_equal(adptbx.u_as_b(u), [x * episq for x in u])
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
    uc = uctbx.unit_cell((5, 4, 7, 80, 110, 100))
    for fw, bw in ((adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
                   (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
                   (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
                   (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
                   (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif)):
        assert approx_equal(bw(uc, fw(uc, u)), u)
    assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
    assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)),
                        2.3)
    for fw, bw in ((adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
                   (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
                   (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso)):
        assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
    fc = adptbx.factor_u_cart_u_iso(u_cart=u)
    assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
    assert approx_equal(fc.u_cart_minus_u_iso,
                        [uii - fc.u_iso for uii in u[:3]] + list(u[3:]))
    f = adptbx.factor_u_star_u_iso(unit_cell=uc,
                                   u_star=adptbx.u_cart_as_u_star(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_star_minus_u_iso,
                        adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_u_cif_u_iso(unit_cell=uc,
                                  u_cif=adptbx.u_cart_as_u_cif(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_cif_minus_u_iso,
                        adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_beta_u_iso(unit_cell=uc,
                                 beta=adptbx.u_cart_as_beta(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.beta_minus_u_iso,
                        adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
    assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25, 2.3),
                        math.exp(-2.3 * 0.25))
    assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25, 2.3),
                        math.exp(-2.3 * episq * 0.25))
    assert approx_equal(
        adptbx.debye_waller_factor_b_iso(uc, (1, 2, 3), 2.3),
        adptbx.debye_waller_factor_u_iso(uc, (1, 2, 3), 2.3 / episq))
    u_star = adptbx.u_cart_as_u_star(uc, u)
    dw = adptbx.debye_waller_factor_u_star((1, 2, 3), u_star)
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_beta((1, 2, 3),
                                        adptbx.u_star_as_beta(u_star)))
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_u_cif(uc, (1, 2, 3),
                                         adptbx.u_star_as_u_cif(uc, u_star)))
    assert approx_equal(
        dw,
        adptbx.debye_waller_factor_u_cart(uc, (1, 2, 3),
                                          adptbx.u_star_as_u_cart(uc, u_star)))
    for e in adptbx.eigenvalues(u):
        check_eigenvalue(u, e)
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
    assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
    assert not adptbx.is_positive_definite(u)
    assert not adptbx.is_positive_definite(u, 0)
    assert adptbx.is_positive_definite(u, 1.22)
    up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
    s = adptbx.eigensystem(up)
    assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
    for i in xrange(3):
        check_eigenvector(up, s.values()[i], s.vectors(i))
    c = (1, 2, 3, 3, -4, 5, 4, 5, 6)
    v = (198, 18, 1020, 116, 447, 269)
    assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
    assert approx_equal(
        adptbx.eigensystem(u).values(),
        (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
    s = adptbx.eigensystem(up)
    try:
        s.vectors(4)
    except RuntimeError, e:
        assert str(e).endswith("Index out of range.")
Exemplo n.º 14
0
def exercise_interface():
    episq = 8 * (math.pi ** 2)
    assert approx_equal(adptbx.u_as_b(2.3), 2.3 * episq)
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(2.3)), 2.3)
    u = (3, 4, 9, 2, 1, 7)
    assert approx_equal(adptbx.u_as_b(u), [x * episq for x in u])
    assert approx_equal(adptbx.b_as_u(adptbx.u_as_b(u)), u)
    uc = uctbx.unit_cell((5, 4, 7, 80, 110, 100))
    for fw, bw in (
        (adptbx.u_cif_as_u_star, adptbx.u_star_as_u_cif),
        (adptbx.u_cart_as_u_star, adptbx.u_star_as_u_cart),
        (adptbx.u_cart_as_u_cif, adptbx.u_cif_as_u_cart),
        (adptbx.u_cart_as_beta, adptbx.beta_as_u_cart),
        (adptbx.u_cif_as_beta, adptbx.beta_as_u_cif),
    ):
        assert approx_equal(bw(uc, fw(uc, u)), u)
    assert approx_equal(adptbx.beta_as_u_star(adptbx.u_star_as_beta(u)), u)
    assert approx_equal(adptbx.u_cart_as_u_iso(adptbx.u_iso_as_u_cart(2.3)), 2.3)
    for fw, bw in (
        (adptbx.u_iso_as_u_star, adptbx.u_star_as_u_iso),
        (adptbx.u_iso_as_u_cif, adptbx.u_cif_as_u_iso),
        (adptbx.u_iso_as_beta, adptbx.beta_as_u_iso),
    ):
        assert approx_equal(bw(uc, fw(uc, 2.3)), 2.3)
    fc = adptbx.factor_u_cart_u_iso(u_cart=u)
    assert approx_equal(fc.u_iso, adptbx.u_cart_as_u_iso(u))
    assert approx_equal(fc.u_cart_minus_u_iso, [uii - fc.u_iso for uii in u[:3]] + list(u[3:]))
    f = adptbx.factor_u_star_u_iso(unit_cell=uc, u_star=adptbx.u_cart_as_u_star(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_star_minus_u_iso, adptbx.u_cart_as_u_star(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_u_cif_u_iso(unit_cell=uc, u_cif=adptbx.u_cart_as_u_cif(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.u_cif_minus_u_iso, adptbx.u_cart_as_u_cif(uc, fc.u_cart_minus_u_iso))
    f = adptbx.factor_beta_u_iso(unit_cell=uc, beta=adptbx.u_cart_as_beta(uc, u))
    assert approx_equal(f.u_iso, fc.u_iso)
    assert approx_equal(f.beta_minus_u_iso, adptbx.u_cart_as_beta(uc, fc.u_cart_minus_u_iso))
    assert approx_equal(adptbx.debye_waller_factor_b_iso(0.25, 2.3), math.exp(-2.3 * 0.25))
    assert approx_equal(adptbx.debye_waller_factor_u_iso(0.25, 2.3), math.exp(-2.3 * episq * 0.25))
    assert approx_equal(
        adptbx.debye_waller_factor_b_iso(uc, (1, 2, 3), 2.3),
        adptbx.debye_waller_factor_u_iso(uc, (1, 2, 3), 2.3 / episq),
    )
    u_star = adptbx.u_cart_as_u_star(uc, u)
    dw = adptbx.debye_waller_factor_u_star((1, 2, 3), u_star)
    assert approx_equal(dw, adptbx.debye_waller_factor_beta((1, 2, 3), adptbx.u_star_as_beta(u_star)))
    assert approx_equal(dw, adptbx.debye_waller_factor_u_cif(uc, (1, 2, 3), adptbx.u_star_as_u_cif(uc, u_star)))
    assert approx_equal(dw, adptbx.debye_waller_factor_u_cart(uc, (1, 2, 3), adptbx.u_star_as_u_cart(uc, u_star)))
    for e in adptbx.eigenvalues(u):
        check_eigenvalue(u, e)
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u))
    assert not adptbx.is_positive_definite(adptbx.eigenvalues(u), 0)
    assert adptbx.is_positive_definite(adptbx.eigenvalues(u), 1.22)
    assert not adptbx.is_positive_definite(u)
    assert not adptbx.is_positive_definite(u, 0)
    assert adptbx.is_positive_definite(u, 1.22)
    up = (0.534, 0.812, 0.613, 0.0166, 0.134, -0.0124)
    s = adptbx.eigensystem(up)
    assert approx_equal(s.values(), (0.813132, 0.713201, 0.432668))
    for i in xrange(3):
        check_eigenvector(up, s.values()[i], s.vectors(i))
    c = (1, 2, 3, 3, -4, 5, 4, 5, 6)
    v = (198, 18, 1020, 116, 447, 269)
    assert approx_equal(adptbx.c_u_c_transpose(c, u), v)
    assert approx_equal(adptbx.eigensystem(u).values(), (14.279201519086316, 2.9369143826320214, -1.2161159017183376))
    s = adptbx.eigensystem(up)
    try:
        s.vectors(4)
    except RuntimeError, e:
        assert str(e).endswith("Index out of range.")
Exemplo n.º 15
0
def u_star_minus_u_iso_ralf(unit_cell, u_star):
    u_cart = adptbx.u_star_as_u_cart(unit_cell, u_star)
    u_iso = adptbx.u_cart_as_u_iso(u_cart)
    u_cart_minus_u_iso = [a - u_iso for a in u_cart[:3]] + list(u_cart[3:])
    return adptbx.u_cart_as_u_star(unit_cell, u_cart_minus_u_iso)