Exemple #1
0
def atoms(xray_structure, short_sfac):
    if (short_sfac):
        celcon = calculate_cell_content(xray_structure).keys()
    lines = []
    l = lines.append
    i = 0
    for scatterer in xray_structure.scatterers():
        i += 1
        lbl = scatterer.scattering_type + str(i)
        if (short_sfac):
            sfac = celcon.index(scatterer.scattering_type) + 1
        else:
            sfac = i
        coor = []
        for x in scatterer.site:
            coor.append(NOFIX(x))
        coor = dot6fdot_list(coor)
        sof = NOFIX(scatterer.weight())
        if (not scatterer.flags.use_u_aniso()):
            l("%-4s %d %s %s %s" % (lbl, sfac, coor, dot6gdot(sof),
                                    dot6gdot(NOFIX(scatterer.u_iso))))
        else:
            u = adptbx.u_star_as_u_cif(xray_structure.unit_cell(),
                                       scatterer.u_star)
            u_fix = []
            for c in u:
                u_fix.append(NOFIX(c))
            u = u_fix
            l("%-4s %d %s %s %s =" %
              (lbl, sfac, coor, dot6gdot(sof), dot6gdot_list(u[:2])))
            l("    %s" % dot6gdot_list((u[2], u[5], u[4], u[3])))
    return lines
def atoms(xray_structure, short_sfac):
  if (short_sfac):
    celcon = calculate_cell_content(xray_structure).keys()
  lines = []
  l = lines.append
  i = 0
  for scatterer in xray_structure.scatterers():
    i += 1
    lbl = scatterer.scattering_type + str(i)
    if (short_sfac):
      sfac = celcon.index(scatterer.scattering_type) + 1
    else:
      sfac = i
    coor = []
    for x in scatterer.site: coor.append(NOFIX(x))
    coor = dot6fdot_list(coor)
    sof = NOFIX(scatterer.weight())
    if (not scatterer.flags.use_u_aniso()):
      l("%-4s %d %s %s %s" % (lbl, sfac, coor, dot6gdot(sof),
        dot6gdot(NOFIX(scatterer.u_iso))))
    else:
      u = adptbx.u_star_as_u_cif(xray_structure.unit_cell(), scatterer.u_star)
      u_fix = []
      for c in u: u_fix.append(NOFIX(c))
      u = u_fix
      l("%-4s %d %s %s %s =" % (lbl, sfac, coor, dot6gdot(sof),
        dot6gdot_list(u[:2])))
      l("    %s" % dot6gdot_list((u[2], u[5], u[4], u[3])))
  return lines
Exemple #3
0
def atoms(lapp, sfac_indices, xray_structure, encoded_sites):
  spis = xray_structure.special_position_indices()
  if (encoded_sites is None):
    enc_dict = {}
  else:
    assert len(encoded_sites) == spis.size()
    enc_dict = dict(zip(spis, encoded_sites))
  ss = xray_structure.space_group_info().structure_seminvariants()
  if (ss.number_of_continuous_allowed_origin_shifts() == 0):
    caosh_flags = None
    caosh_i_sc = None
  else:
    assert ss.continuous_shifts_are_principal()
    caosh_flags = ss.principal_continuous_shift_flags()
    reg = xray_structure.scattering_type_registry()
    w_max = None
    for i_sc,sc in enumerate(xray_structure.scatterers()):
      gaussian = reg.gaussian(sc.scattering_type)
      w = abs(sc.weight() * gaussian.at_stol(0))
      if (w_max is None or w_max < w):
        w_max = w
        caosh_i_sc = i_sc
    assert w_max is not None
  for i_sc,sc in enumerate(xray_structure.scatterers()):
    st = sc.scattering_type
    lbl = "%s%02d" % (st, i_sc+1)
    sfac = sfac_indices[st]
    enc_site = enc_dict.get(i_sc)
    coor = []
    if (caosh_i_sc is None or i_sc != caosh_i_sc):
      if (enc_site is None):
        for x in sc.site: coor.append(NOFIX(x))
      else:
        coor = enc_site
    else:
      if (enc_site is None):
        for x,f in zip(sc.site, caosh_flags):
          if (f): fix = FIX
          else:   fix = NOFIX
          coor.append(fix(x))
      else:
        for x,f in zip(enc_site, caosh_flags):
          if (f):
            coor.append(FIX(x))
          else:
            coor.append(x)
    coor = dot6fdot_list(coor)
    sof = FIX(sc.weight())
    if (not sc.flags.use_u_aniso()):
      lapp("%-4s %d %s %s %s" % (lbl, sfac, coor, dot6gdot(sof),
        dot6gdot(NOFIX(sc.u_iso))))
    else:
      u = adptbx.u_star_as_u_cif(xray_structure.unit_cell(), sc.u_star)
      u_fix = []
      for c in u: u_fix.append(NOFIX(c))
      u = u_fix
      lapp("%-4s %d %s %s %s =" % (lbl, sfac, coor, dot6gdot(sof),
        dot6gdot_list(u[:2])))
      lapp("    %s" % dot6gdot_list((u[2], u[5], u[4], u[3])))
Exemple #4
0
def write_shelx76_ls(
      f_obs,
      xray_structure,
      titl=None,
      l_s_parameters="0",
      fvars=None,
      encoded_sites=None):
  assert xray_structure.scatterers().size() > 0
  assert (fvars is None) == (encoded_sites is None)
  lines = []
  lapp = lines.append
  if (titl is None):
    titl = str(xray_structure.space_group_info())
  lapp("TITL " + titl)
  lapp("CELL 0.7 " + dot6gdot_list(xray_structure.unit_cell().parameters()))
  s = StringIO()
  LATT_SYMM(s, xray_structure.space_group(), decimal=True)
  lapp(s.getvalue()[:-1])
  sfac_indices = sfac_unit(lapp, xray_structure)
  if (fvars is None):
    lapp("FVAR 1.0")
  else:
    for fv in fvars:
      lapp("FVAR %.6f" % fv)
  lapp("L.S. %s" % l_s_parameters)
  atoms(lapp, sfac_indices, xray_structure, encoded_sites)
  HKLF(lapp, f_obs, skip_zeros=True)
  lapp("END")
  print >> open("tmp.ins", "w"), "\n".join(lines)
Exemple #5
0
def run_shelx(shelx_titl, structure_factors, short_sfac=False, verbose=0):
    run_shelx.counter += 1
    xray_structure = structure_factors.xray_structure()
    assert xray_structure.scatterers().size() > 0
    pre_check(xray_structure)
    f_calc = structure_factors.f_calc()
    lines = []
    l = lines.append
    l("TITL " + shelx_titl)
    l("CELL 1.0 " + dot6gdot_list(xray_structure.unit_cell().parameters()))
    l("ZERR 1 0.01 0.01 0.01 0 0 0")
    s = StringIO()
    LATT_SYMM(s, xray_structure.space_group())
    l(s.getvalue()[:-1])
    lines += SFAC_DISP_UNIT(xray_structure, short_sfac)
    l("FVAR 1.")
    l("L.S. 1")
    l("BLOC 0")
    l("SPEC -0.1")
    l("WPDB 2")
    lines += atoms(xray_structure, short_sfac)
    HKLF(l, f_calc)
    with open("tmp%02d.ins" % run_shelx.counter, "w") as f:
        for l in lines:
            if (0 or verbose): print l
            f.write(l + "\n")
    sys.stdout.flush()
    sys.stderr.flush()
    try:
        os.unlink("tmp%02d.lst" % run_shelx.counter)
    except KeyboardInterrupt:
        raise
    except Exception:
        pass
    shelxl_out = easy_run.fully_buffered(command="shelxl tmp%02d" % run_shelx.counter) \
      .raise_if_errors() \
      .stdout_lines
    if (0 or verbose):
        for l in shelxl_out:
            print l
    sys.stderr.flush()
    with open("tmp%02d.lst" % run_shelx.counter, "r") as f:
        shelx_lst = f.readlines()
    with open("tmp%02d.pdb" % run_shelx.counter, "r") as f:
        shelx_pdb = f.readlines()
    if (0 or verbose):
        for l in shelx_lst:
            print l[:-1]
    sys.stdout.flush()
    check_r1(f_calc, shelx_lst, verbose)
    check_anisou(shelx_titl, xray_structure, shelx_pdb, verbose)
def run_shelx(shelx_titl, structure_factors, short_sfac=False, verbose=0):
  xray_structure = structure_factors.xray_structure()
  assert xray_structure.scatterers().size() > 0
  pre_check(xray_structure)
  f_calc = structure_factors.f_calc()
  lines = []
  l = lines.append
  l("TITL " + shelx_titl)
  l("CELL 1.0 " + dot6gdot_list(xray_structure.unit_cell().parameters()))
  l("ZERR 1 0.01 0.01 0.01 0 0 0")
  s = StringIO()
  LATT_SYMM(s, xray_structure.space_group())
  l(s.getvalue()[:-1])
  lines += SFAC_DISP_UNIT(xray_structure, short_sfac)
  l("FVAR 1.")
  l("L.S. 1")
  l("BLOC 0")
  l("SPEC -0.1")
  l("WPDB 2")
  lines += atoms(xray_structure, short_sfac)
  HKLF(l, f_calc)
  f = open("tmp.ins", "w")
  for l in lines:
    if (0 or verbose): print l
    f.write(l + "\n")
  f.close()
  sys.stdout.flush()
  sys.stderr.flush()
  try: os.unlink("tmp.lst")
  except KeyboardInterrupt: raise
  except Exception: pass
  shelxl_out = easy_run.fully_buffered(command="shelxl tmp") \
    .raise_if_errors() \
    .stdout_lines
  if (0 or verbose):
    for l in shelxl_out: print l
  f = open("tmp.lst", "r")
  shelx_lst = f.readlines()
  f.close()
  sys.stderr.flush()
  f = open("tmp.pdb", "r")
  shelx_pdb = f.readlines()
  f.close()
  sys.stderr.flush()
  if (0 or verbose):
    for l in shelx_lst: print l[:-1]
  sys.stdout.flush()
  check_r1(f_calc, shelx_lst, verbose)
  check_anisou(shelx_titl, xray_structure, shelx_pdb, verbose)