def run(server_info, inp, status):
    print("<pre>")
    special_position_settings = io_utils.special_position_settings_from_inp(
        inp)
    special_position_settings.show_summary()
    print("Minimum distance between symmetrically equivalent sites:", end=' ')
    print(special_position_settings.min_distance_sym_equiv())
    print()

    d_min = float(inp.d_min)
    print("Minimum d-spacing:", d_min)
    if (d_min <= 0.):
        raise ValueError("d-spacing must be greater than zero.")
    print()

    structure = io_utils.structure_from_inp(inp, status,
                                            special_position_settings)
    algorithm = inp.algorithm
    if (algorithm == "automatic"):
        if (structure.scatterers().size() <= 100):
            algorithm = "direct"
        else:
            algorithm = None
    elif (algorithm not in ["direct", "fft"]):
        algorithm = None
    f_calc_manager = structure.structure_factors(anomalous_flag=False,
                                                 d_min=d_min,
                                                 algorithm=algorithm)
    f_calc = f_calc_manager.f_calc()
    structure.scattering_type_registry().show()
    print()
    print("Number of Miller indices:", f_calc.indices().size())
    print()
    print("Structure factor algorithm:",
          f_calc_manager.algorithm(verbose=True))
    print()
    print("</pre><table border=2 cellpadding=2>")
    status.in_table = True
    print("<tr>")
    print("<th>hkl<th>Amplitude<th>Phase")
    for i, h in enumerate(f_calc.indices()):
        print("<tr>")
        print("<td>%3d %3d %3d<td>%.6g<td align=right>%.3f" %
              (h + complex_math.abs_arg(f_calc.data()[i], deg=True)))
    print("</table><pre>")
    status.in_table = False
    print()

    print("</pre>")
def run(server_info, inp, status):
  print "<pre>"
  special_position_settings = io_utils.special_position_settings_from_inp(inp)
  special_position_settings.show_summary()
  print "Minimum distance between symmetrically equivalent sites:",
  print special_position_settings.min_distance_sym_equiv()
  print

  d_min = float(inp.d_min)
  print "Minimum d-spacing:", d_min
  if (d_min <= 0.):
    raise ValueError, "d-spacing must be greater than zero."
  print

  structure = io_utils.structure_from_inp(
    inp, status, special_position_settings)
  algorithm = inp.algorithm
  if (algorithm == "automatic"):
    if (structure.scatterers().size() <= 100):
      algorithm = "direct"
    else:
      algorithm = None
  elif (algorithm not in ["direct", "fft"]):
    algorithm = None
  f_calc_manager = structure.structure_factors(
    anomalous_flag=False, d_min=d_min, algorithm=algorithm)
  f_calc = f_calc_manager.f_calc()
  structure.scattering_type_registry().show()
  print
  print "Number of Miller indices:", f_calc.indices().size()
  print
  print "Structure factor algorithm:", f_calc_manager.algorithm(verbose=True)
  print
  print "</pre><table border=2 cellpadding=2>"
  status.in_table = True
  print "<tr>"
  print "<th>hkl<th>Amplitude<th>Phase"
  for i,h in enumerate(f_calc.indices()):
    print "<tr>"
    print "<td>%3d %3d %3d<td>%.6g<td align=right>%.3f" % (
      h + complex_math.abs_arg(f_calc.data()[i], deg=True))
  print "</table><pre>"
  status.in_table = False
  print

  print "</pre>"
Example #3
0
def run(server_info, inp, status):
    print("<pre>")

    if (inp.format == "cns_sdb"):
        print("Minimum distance between symmetrically equivalent sites:",
              end=' ')
        print(float(inp.min_distance_sym_equiv))
        print()
        structures = inp_as_xray_structures(inp)
        if (len(structures) == 0):
            print("No CNS sdb files found!")
            print()
            print(
                "Note that each file must start with {+ file: some_file_name +}"
            )
            print("in order to be recognized.")
            print()
    else:
        if (inp.ucparams is None): inp.ucparams = ""
        if (inp.sgsymbol is None): inp.sgsymbol = "P1"
        special_position_settings = io_utils.special_position_settings_from_inp(
            inp)
        special_position_settings.show_summary()
        print("Minimum distance between symmetrically equivalent sites:",
              end=' ')
        print(special_position_settings.min_distance_sym_equiv())
        print()
        structures = [
            io_utils.structure_from_inp(inp, status, special_position_settings)
        ]

    d_min = float(inp.d_min)
    print("Minimum d-spacing:", d_min)
    if (d_min <= 0.):
        raise ValueError("d-spacing must be greater than zero.")
    print()

    min_peak_distance = float(inp.min_peak_distance)
    print("Minimum peak distance:", min_peak_distance)
    if (min_peak_distance <= 0.):
        raise ValueError("min_peak_distance must be greater than zero.")
    print()

    max_reduced_peaks = int(inp.max_reduced_peaks)
    print("Maximum number of peaks:", max_reduced_peaks)
    if (max_reduced_peaks <= 0):
        raise ValueError("max_reduced_peaks must be greater than zero.")
    print()

    for structure in structures:
        if (inp.format == "cns_sdb"):
            structure.show_summary().show_scatterers()
            print()
        if (structure.scatterers().size() == 0): continue
        reduced_peaks = phase_o_phrenia.calculate_exp_i_two_phi_peaks(
            xray_structure=structure,
            d_min=d_min,
            min_peak_distance=min_peak_distance,
            max_reduced_peaks=max_reduced_peaks)

        print("Actual number of peaks:", len(reduced_peaks))
        print()

        plot_nx = min(len(reduced_peaks), 60)
        if (plot_nx > 0):
            plot_ny = max(10, plot_nx // 3)
            if (plot_nx != max_reduced_peaks):
                print("Number of peaks used for plot:", plot_nx)
                print()
            print("Plot of relative peak heights:")
            print()
            plot = flex.bool(flex.grid(plot_nx, plot_ny))
            for i in range(plot_nx):
                height = reduced_peaks[i].height
                h = int(round(height * plot_ny))
                h = max(0, min(plot_ny, h))
                for j in range(h):
                    plot[(i, j)] = True
            for j in range(plot_ny - 1, -1, -1):
                line = ""
                for i in range(plot_nx):
                    if (plot[(i, j)]): line += "*"
                    else: line += " "
                print("    |" + line.rstrip())
            print("    -" + "-" * plot_nx)
            print()

            print("Peak list:")
            print("  Relative")
            print("   height   Fractional coordinates")
            for peak in reduced_peaks:
                print("    %5.1f" % (peak.height * 100),
                      " %8.5f %8.5f %8.5f" % peak.site)
            print()

    print("</pre>")
def run(server_info, inp, status):
  print "<pre>"

  if (inp.format == "cns_sdb"):
    print "Minimum distance between symmetrically equivalent sites:",
    print float(inp.min_distance_sym_equiv)
    print
    structures = inp_as_xray_structures(inp)
    if (len(structures) == 0):
      print "No CNS sdb files found!"
      print
      print "Note that each file must start with {+ file: some_file_name +}"
      print "in order to be recognized."
      print
  else:
    if (inp.ucparams is None): inp.ucparams = ""
    if (inp.sgsymbol is None): inp.sgsymbol = "P1"
    special_position_settings = io_utils.special_position_settings_from_inp(inp)
    special_position_settings.show_summary()
    print "Minimum distance between symmetrically equivalent sites:",
    print special_position_settings.min_distance_sym_equiv()
    print
    structures = [io_utils.structure_from_inp(inp, status, special_position_settings)]

  d_min = float(inp.d_min)
  print "Minimum d-spacing:", d_min
  if (d_min <= 0.):
    raise ValueError, "d-spacing must be greater than zero."
  print

  min_peak_distance = float(inp.min_peak_distance)
  print "Minimum peak distance:", min_peak_distance
  if (min_peak_distance <= 0.):
    raise ValueError, "min_peak_distance must be greater than zero."
  print

  max_reduced_peaks = int(inp.max_reduced_peaks)
  print "Maximum number of peaks:", max_reduced_peaks
  if (max_reduced_peaks <= 0):
    raise ValueError, "max_reduced_peaks must be greater than zero."
  print

  for structure in structures:
    if (inp.format == "cns_sdb"):
      structure.show_summary().show_scatterers()
      print
    if (structure.scatterers().size() == 0): continue
    reduced_peaks = phase_o_phrenia.calculate_exp_i_two_phi_peaks(
      xray_structure=structure,
      d_min=d_min,
      min_peak_distance=min_peak_distance,
      max_reduced_peaks=max_reduced_peaks)

    print "Actual number of peaks:", len(reduced_peaks)
    print

    plot_nx = min(len(reduced_peaks), 60)
    if (plot_nx > 0):
      plot_ny = max(10, plot_nx//3)
      if (plot_nx != max_reduced_peaks):
        print "Number of peaks used for plot:", plot_nx
        print
      print "Plot of relative peak heights:"
      print
      plot = flex.bool(flex.grid(plot_nx, plot_ny))
      for i in xrange(plot_nx):
        height = reduced_peaks[i].height
        h = int(round(height * plot_ny))
        h = max(0, min(plot_ny, h))
        for j in xrange(h): plot[(i,j)] = True
      for j in xrange(plot_ny-1,-1,-1):
        line = ""
        for i in xrange(plot_nx):
          if (plot[(i,j)]): line += "*"
          else:                  line += " "
        print "    |" + line.rstrip()
      print   "    -" + "-" * plot_nx
      print

      print "Peak list:"
      print "  Relative"
      print "   height   Fractional coordinates"
      for peak in reduced_peaks:
        print "    %5.1f" % (peak.height*100), " %8.5f %8.5f %8.5f" % peak.site
      print

  print "</pre>"