def exercise(args, distance_cutoff=3.5, max_shell=5):
  command_line = (iotbx_option_parser()
    .option(None, "--tag",
      action="store",
      type="string")
    .option(None, "--full",
      action="store_true")
    .option(None, "--verbose",
      action="store_true")
  ).process(args=args)
  co = command_line.options
  atlas_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/misc/strudat_zeolite_atlas",
    test=os.path.isfile)
  if (atlas_file is None):
    print "Skipping exercise(): input file not available"
    return
  all_entries = strudat.read_all_entries(open(atlas_file))
  for i,entry in enumerate(all_entries.entries):
    structure = entry.as_xray_structure()
    if (co.tag is not None):
      if (co.tag != entry.tag):
        continue
    elif (not (co.full or i % 20 == 0)):
      continue
    if (co.verbose):
      print "strudat tag:", entry.tag
    exercise_simple(
      structure, distance_cutoff, max_shell, co.verbose)
    exercise_shell_asu_tables(structure, co.verbose)
예제 #2
0
def process_zeolite_atlas(args):
    command_line = (iotbx_option_parser().option(
        None, "--tag", action="store",
        type="string").option(None, "--verbose",
                              action="store_true")).process(args=args)
    atlas_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/misc/strudat_zeolite_atlas",
        test=os.path.isfile)
    if (atlas_file is None):
        print("Skipping process_zeolite_atlas(): input file not available")
        return
    if (command_line.options.verbose):
        out = sys.stdout
    else:
        out = StringIO()
    with open(atlas_file) as f:
        all_entries = strudat.read_all_entries(f)
    for i, entry in enumerate(all_entries.entries):
        structure = entry.as_xray_structure()
        if (command_line.options.tag is not None):
            if (command_line.options.tag != entry.tag):
                continue
        print("strudat tag:", entry.tag, file=out)
        exercise(structure=structure, out=out)
        exercise_shake_sites_in_place(structure=structure)
예제 #3
0
def get_emma_model_from_strudat(file_name):
  strudat_entries = strudat.read_all_entries(open(file_name))
  if (len(strudat_entries.entries) > 1):
    raise MultipleEntriesError(
      "strudat file %s may contain only one structure." % file_name)
  assert len(strudat_entries.entries) == 1
  return strudat_entries.entries[0].as_xray_structure().as_emma_model()
def process_zeolite_atlas(args):
  command_line = (iotbx_option_parser()
    .option(None, "--tag",
      action="store",
      type="string")
    .option(None, "--verbose",
      action="store_true")
  ).process(args=args)
  atlas_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/misc/strudat_zeolite_atlas",
    test=os.path.isfile)
  if (atlas_file is None):
    print "Skipping process_zeolite_atlas(): input file not available"
    return
  if (command_line.options.verbose):
    out = sys.stdout
  else:
    out = StringIO()
  all_entries = strudat.read_all_entries(open(atlas_file))
  for i,entry in enumerate(all_entries.entries):
    structure = entry.as_xray_structure()
    if (command_line.options.tag is not None):
      if (command_line.options.tag != entry.tag):
        continue
    print >> out, "strudat tag:", entry.tag
    exercise(structure=structure, out=out)
    exercise_shake_sites_in_place(structure=structure)
예제 #5
0
def exercise_zeolite_atlas(distance_cutoff=3.5):
    atlas_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/misc/strudat_zeolite_atlas",
        test=os.path.isfile)
    if (atlas_file is None):
        print("Skipping exercise_zeolite_atlas(): input file not available")
        return
    with open(atlas_file) as f:
        all_entries = strudat.read_all_entries(f)
    for i, entry in enumerate(all_entries.entries):
        structure = entry.as_xray_structure()
        if ("--full" in sys.argv[1:] or i % 20 == 0):
            tst_direct_space_asu.exercise_neighbors_pair_generators(
                structure=structure, verbose="--Verbose" in sys.argv[1:])
        asu_mappings = structure.asu_mappings(buffer_thickness=distance_cutoff)
        pair_generator = crystal.neighbors_fast_pair_generator(
            asu_mappings=asu_mappings, distance_cutoff=distance_cutoff)
        bond_counts = flex.size_t(structure.scatterers().size(), 0)
        for pair in pair_generator:
            bond_counts[pair.i_seq] += 1
            if (pair.j_sym == 0):
                bond_counts[pair.j_seq] += 1
        for atom, bond_count in zip(entry.atoms, bond_counts):
            assert atom.connectivity is not None
            assert atom.connectivity == bond_count
예제 #6
0
def get_emma_model_from_strudat(file_name):
    strudat_entries = strudat.read_all_entries(open(file_name))
    if (len(strudat_entries.entries) > 1):
        raise MultipleEntriesError(
            "strudat file %s may contain only one structure." % file_name)
    assert len(strudat_entries.entries) == 1
    return strudat_entries.entries[0].as_xray_structure().as_emma_model()
예제 #7
0
def exercise_zeolite_atlas(distance_cutoff=3.5):
  atlas_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/misc/strudat_zeolite_atlas",
    test=os.path.isfile)
  if (atlas_file is None):
    print "Skipping exercise_zeolite_atlas(): input file not available"
    return
  all_entries = strudat.read_all_entries(open(atlas_file))
  for i,entry in enumerate(all_entries.entries):
    structure = entry.as_xray_structure()
    if ("--full" in sys.argv[1:] or i % 20 == 0):
      tst_direct_space_asu.exercise_neighbors_pair_generators(
        structure=structure,
        verbose="--Verbose" in sys.argv[1:])
    asu_mappings = structure.asu_mappings(buffer_thickness=distance_cutoff)
    pair_generator = crystal.neighbors_fast_pair_generator(
      asu_mappings=asu_mappings,
      distance_cutoff=distance_cutoff)
    bond_counts = flex.size_t(structure.scatterers().size(), 0)
    for pair in pair_generator:
      bond_counts[pair.i_seq] += 1
      if (pair.j_sym == 0):
        bond_counts[pair.j_seq] += 1
    for atom,bond_count in zip(entry.atoms, bond_counts):
      assert atom.connectivity is not None
      assert atom.connectivity == bond_count
def exercise(args, distance_cutoff=3.5, max_shell=5):
    command_line = (iotbx_option_parser().option(
        None, "--tag", action="store",
        type="string").option(None, "--full", action="store_true").option(
            None, "--verbose", action="store_true")).process(args=args)
    co = command_line.options
    atlas_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/misc/strudat_zeolite_atlas",
        test=os.path.isfile)
    if (atlas_file is None):
        print "Skipping exercise(): input file not available"
        return
    all_entries = strudat.read_all_entries(open(atlas_file))
    for i, entry in enumerate(all_entries.entries):
        structure = entry.as_xray_structure()
        if (co.tag is not None):
            if (co.tag != entry.tag):
                continue
        elif (not (co.full or i % 20 == 0)):
            continue
        if (co.verbose):
            print "strudat tag:", entry.tag
        exercise_simple(structure, distance_cutoff, max_shell, co.verbose)
        exercise_shell_asu_tables(structure, co.verbose)
예제 #9
0
def exercise_all():
  verbose = "--verbose" in sys.argv[1:]
  exercise_icosahedron(verbose=verbose)
  default_distance_cutoff = 3.5
  regression_misc = libtbx.env.find_in_repositories("phenix_regression/misc")
  if (regression_misc is None):
    print "Skipping exercise_all(): phenix_regression/misc not available"
    return
  def get_reference_dict(file_name):
    path = os.path.join(regression_misc, file_name)
    if (not os.path.isfile(path)):
      print "Skipping some tests: reference file not available:", path
      return None
    result = {}
    for line in open(path).read().splitlines():
      tag, data = line.split()
      assert not tag in result
      result[tag] = data
    return result
  reference_apatanl_dict = get_reference_dict(
    "angle_pair_asu_tables_as_nested_lists")
  reference_cppc_dict = get_reference_dict(
    "conservative_pair_proxies_counts")
  file_names = []
  for file_name in ["strudat_zeolite_atlas", "strudat_special_bonds"]:
    path = os.path.join(regression_misc, file_name)
    if (not os.path.isfile(path)):
      print "Skipping %s test: input file not available" % file_name
    else:
      file_names.append(path)
  for file_name in file_names:
    strudat_entries = strudat.read_all_entries(open(file_name))
    for i_entry,entry in enumerate(strudat_entries.entries):
      if (    file_name.endswith("strudat_zeolite_atlas")
          and not ("--full" in sys.argv[1:] or i_entry % 20 == 0)):
        continue
      if (0 or verbose):
        print "strudat tag:", entry.tag
      structure = entry.as_xray_structure()
      if (0 or verbose):
        structure.show_summary().show_scatterers()
      if (entry.title.startswith("cutoff")):
        distance_cutoff = float(entry.title.split()[1])
      else:
        distance_cutoff = default_distance_cutoff
      weak_check_sym_equiv = (
        entry.reference.find("weak_check_sym_equiv") >= 0)
      connectivities = entry.connectivities(all_or_nothing=True)
      if (1):
        exercise(
          structure=structure,
          distance_cutoff=distance_cutoff,
          connectivities=connectivities,
          weak_check_sym_equiv=weak_check_sym_equiv,
          verbose=verbose)
      if (0 or verbose):
        print
      if (file_name.endswith("strudat_zeolite_atlas")):
        exercise_bond_sorted_asu_proxies(
          structure=structure,
          distance_cutoff=distance_cutoff)
      if (reference_apatanl_dict is None):
        reference_apatanl = None
      else:
        assert entry.tag in reference_apatanl_dict
        reference_apatanl = reference_apatanl_dict[entry.tag]
      if (reference_cppc_dict is None):
        reference_cppc = None
      else:
        assert entry.tag in reference_cppc_dict
        reference_cppc = reference_cppc_dict[entry.tag]
      exercise_angle_pair_asu_table(
        structure=structure,
        distance_cutoff=distance_cutoff,
        connectivities=connectivities,
        reference_apatanl=reference_apatanl,
        reference_cppc=reference_cppc)
def run(args, distance_cutoff=3.5):
    from iotbx.option_parser import option_parser
    command_line = (option_parser(
        usage="iotbx.distance_least_squares [options] studat_file [...]",
        description="Example: iotbx.distance_least_squares strudat --tag=SOD"
    ).option(
        None,
        "--tag",
        action="store",
        type="string",
        help="tag as it appears in the strudat file").option(
            None,
            "--repulsion_function",
            action="store",
            type="choice",
            choices=["gaussian", "cos", "prolsq"],
            default="gaussian",
            help="Nonbonded repulsion function type",
            metavar="gaussian|cos|prolsq").option(
                None,
                "--bond_stretch_factor",
                action="store",
                type="float",
                default=0.1,
                help="Bond stretch factor used in max residual calculation"
                " for nonbonded cos or gaussian repulsion function",
                metavar="FLOAT").option(
                    None,
                    "--n_trials",
                    action="store",
                    type="int",
                    default=1,
                    help="Number of trial per structure",
                    metavar="INT").option(
                        None,
                        "--n_macro_cycles",
                        action="store",
                        type="int",
                        default=1,
                        help="Number of macro cycles per trial",
                        metavar="INT").option(
                            None, "--dev", action="store_true",
                            default=False)).process(args=args)
    if (len(command_line.args) == 0):
        command_line.parser.show_help()
        return
    co = command_line.options
    from cctbx.geometry_restraints import distance_least_squares as dls
    from iotbx.kriber import strudat
    for file_name in command_line.args:
        strudat_entries = strudat.read_all_entries(open(file_name))
        for entry in strudat_entries.entries:
            if (co.tag is not None and co.tag != entry.tag):
                continue
            print("strudat tag:", entry.tag)
            print()
            dls.distance_and_repulsion_least_squares(
                si_structure=entry.as_xray_structure(),
                distance_cutoff=distance_cutoff,
                nonbonded_repulsion_function_type=co.repulsion_function,
                nonbonded_max_residual_bond_stretch_factor=co.
                bond_stretch_factor,
                n_trials=co.n_trials,
                n_macro_cycles=co.n_macro_cycles,
                connectivities=entry.connectivities(all_or_nothing=True),
                dev=co.dev)
예제 #11
0
def run(args):
  command_line = (option_parser(
    usage="iotbx.show_distances [options] studat_file [...]",
    description="Example: iotbx.show_distances strudat --tag=SOD")
    .option(None, "--cif_data_block_name",
      action="store",
      type="string",
      default=None,
      help="data block name as it appears in the CIF file")
    .option(None, "--tag",
      action="store",
      type="string",
      help="tag as it appears in the strudat file")
    .option(None, "--distance_cutoff",
      action="store",
      type="float",
      default=5,
      help="Maximum distance to be considered",
      metavar="FLOAT")
    .option(None, "--min_distance_sym_equiv",
      action="store",
      type="float",
      default=0.5,
      help="Minimum distance between symmetry mates"
           " (for special position analysis)",
      metavar="FLOAT")
    .option(None, "--show_cartesian",
      action="store_true",
      help="Show Cartesian coordinates (instead of fractional)")
    .enable_symmetry_comprehensive()
    .option(None, "--cs",
      action="store",
      type="int",
      help="Compute N terms of the coordination sequences",
      metavar="N")
    .option(None, "--coseq",
      action="store",
      type="string",
      help="name of file with known coordination sequences",
      metavar="FILE")
  ).process(args=args)
  if (len(command_line.args) == 0):
    command_line.parser.show_help()
    return
  co = command_line.options
  max_shell = co.cs
  if (co.coseq is not None):
    coseq_dict = coordination_sequences.get_kriber_coseq_file(
      file_name=co.coseq)
    if (max_shell is None): max_shell = 10
  else:
    coseq_dict = None
  def call_display(xray_structure):
    display(
      distance_cutoff=co.distance_cutoff,
      show_cartesian=co.show_cartesian,
      max_shell=max_shell,
      coseq_dict=coseq_dict,
      xray_structure=xray_structure)
  cif_data_block_name_use_counter = 0
  for file_name in command_line.args:
    xray_structure = None
    if (iotbx.pdb.is_pdb_file(file_name=file_name)):
      xray_structure = iotbx.pdb.input(
        file_name=file_name).xray_structure_simple(
          crystal_symmetry=command_line.symmetry,
          cryst1_substitution_buffer_layer=max(5,
            co.distance_cutoff+1),
          min_distance_sym_equiv=co.min_distance_sym_equiv,
          enable_scattering_type_unknown=True)
      call_display(xray_structure)
      continue
    if (file_name.lower().endswith(".cif")):
      xray_structures = iotbx.cif.reader(
        file_path=file_name).build_crystal_structures()
      if (co.cif_data_block_name is not None):
        xray_structure = xray_structures.get(co.cif_data_block_name)
        if (xray_structure is None):
          continue
        cif_data_block_name_use_counter += 1
        xray_structures = [xray_structure]
      else:
        xray_structures = xray_structures.values()
      for xray_structure in xray_structures:
        call_display(xray_structure)
      continue
    if (   file_name.endswith(".ins")
        or file_name.endswith(".res")):
      xray_structure = xray.structure.from_shelx(
        filename=file_name, strictly_shelxl=False)
      call_display(xray_structure)
      continue
    if (command_line.symmetry is not None
        and (command_line.symmetry.unit_cell() is not None
          or command_line.symmetry.space_group_info() is not None)):
      raise Sorry(
        "Command-line symmetry options not supported for strudat files.")
    strudat_entries = strudat.read_all_entries(open(file_name))
    for entry in strudat_entries.entries:
      if (    co.tag is not None
          and co.tag != entry.tag):
        continue
      print "strudat tag:", entry.tag
      print
      xray_structure = entry.as_xray_structure(
        min_distance_sym_equiv=co.min_distance_sym_equiv)
      call_display(xray_structure)
  if (    co.cif_data_block_name is not None
      and cif_data_block_name_use_counter == 0):
    raise Sorry(
      "cif_data_block_name %s not found in any input files"
        % show_string(co.cif_data_block_name))
def exercise_with_zeolite(verbose):
  if (not libtbx.env.has_module("iotbx")):
    print "Skipping exercise_with_zeolite(): iotbx not available"
    return
  from iotbx.kriber import strudat
  atlas_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/misc/strudat_zeolite_atlas",
    test=os.path.isfile)
  if (atlas_file is None):
    print "Skipping exercise_with_zeolite(): input file not available"
    return
  strudat_contents = strudat.read_all_entries(open(atlas_file))
  strudat_entry = strudat_contents.get("YUG")
  si_structure = strudat_entry.as_xray_structure()
  if (verbose):
    out = sys.stdout
  else:
    out = StringIO()
  drls = distance_and_repulsion_least_squares(
    si_structure=si_structure,
    distance_cutoff=3.5,
    nonbonded_repulsion_function_type="prolsq",
    n_macro_cycles=2,
    out=out)
  #
  nbp = drls.geometry_restraints_manager.pair_proxies().nonbonded_proxies
  assert nbp.n_total() > 50
    # expected is 60, but the exact number depends on the minimizer
  #
  site_labels = drls.minimized_structure.scatterers().extract_labels()
  sites_cart = drls.start_structure.sites_cart()
  pair_proxies = drls.geometry_restraints_manager.pair_proxies()
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    site_labels=site_labels,
    f=out)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert len(out.getvalue().splitlines()) == 48*4+2
  assert out.getvalue().splitlines()[-1].find("remaining") < 0
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    site_labels=site_labels,
    f=out,
    prefix="0^",
    max_items=28)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue().replace("e-00", "e-0"), """\
0^Bond restraints: 48
0^Sorted by residual:
0^bond O3
0^     O4
0^  ideal  model  delta    sigma   weight residual
0^  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
0^bond SI1
0^     SI1
0^  ideal  model  delta    sigma   weight residual sym.op.
0^  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
0^... (remaining 20 not shown)
""",
    selections=[range(6), range(-5,0)])
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="delta",
    sites_cart=sites_cart,
    site_labels=site_labels,
    f=out,
    prefix="0^",
    max_items=28)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue().replace("e-00", "e-0"), """\
0^Bond restraints: 48
0^Sorted by delta:
0^bond O3
0^     O4
0^  ideal  model  delta    sigma   weight residual
0^  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
0^... (remaining 20 not shown)
""",
    selections=[range(6), [-1]])
  site_labels_long = ["abc"+label+"def" for label in site_labels]
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    site_labels=site_labels_long,
    f=out,
    prefix="^0",
    max_items=28)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue().replace("e-00", "e-0"), """\
^0Bond restraints: 48
^0Sorted by residual:
^0bond abcO3def
^0     abcO4def
^0  ideal  model  delta    sigma   weight residual
^0  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
^0bond abcSI1def
^0     abcSI1def
^0  ideal  model  delta    sigma   weight residual sym.op.
^0  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
^0... (remaining 20 not shown)
""",
    selections=[range(6), range(-5,0)])
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    f=out,
    prefix=".=",
    max_items=28)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue().replace("e-00", "e-0"), """\
.=Bond restraints: 48
.=Sorted by residual:
.=bond 4
.=     5
.=  ideal  model  delta    sigma   weight residual
.=  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
.=bond 0
.=     0
.=  ideal  model  delta    sigma   weight residual sym.op.
.=  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
.=... (remaining 20 not shown)
""",
    selections=[range(6), range(-5,0)])
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    f=out,
    prefix="-+",
    max_items=1)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue().replace("e-00", "e-0"), """\
-+Bond restraints: 48
-+Sorted by residual:
-+bond 4
-+     5
-+  ideal  model  delta    sigma   weight residual
-+  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
-+... (remaining 47 not shown)
""")
  out = StringIO()
  pair_proxies.bond_proxies.show_sorted(
    by_value="residual",
    sites_cart=sites_cart,
    f=out,
    prefix="=+",
    max_items=0)
  if (verbose):
    sys.stdout.write(out.getvalue())
  assert not show_diff(out.getvalue(), """\
=+Bond restraints: 48
=+Sorted by residual:
=+... (remaining 48 not shown)
""")
  #
  sites_cart = si_structure.sites_cart()
  site_labels = [sc.label for sc in si_structure.scatterers()]
  asu_mappings = si_structure.asu_mappings(buffer_thickness=3.5)
  for min_cubicle_edge in [0, 5]:
    pair_generator = crystal.neighbors_fast_pair_generator(
      asu_mappings=asu_mappings,
      distance_cutoff=asu_mappings.buffer_thickness(),
      minimal=False,
      min_cubicle_edge=min_cubicle_edge)
    sorted_asu_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
      asu_mappings=asu_mappings)
    while (not pair_generator.at_end()):
      p = geometry_restraints.nonbonded_asu_proxy(
        pair=pair_generator.next(),
        vdw_distance=3)
      sorted_asu_proxies.process(p)
    out = StringIO()
    sorted_asu_proxies.show_sorted(
      by_value="delta",
      sites_cart=sites_cart,
      site_labels=site_labels,
      f=out,
      prefix="d%")
    if (verbose):
      sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue(), """\
d%Nonbonded interactions: 7
d%Sorted by model distance:
...
d%nonbonded SI2
d%          SI2
d%   model   vdw sym.op.
d%   3.092 3.000 -x+1,y,-z
...
d%nonbonded SI1
d%          SI1
d%   model   vdw sym.op.
d%   3.216 3.000 -x+1/2,-y+1/2,-z+1
""",
      selections=[range(2), range(10,14), range(26,30)])
    out = StringIO()
    sorted_asu_proxies.show_sorted(
      by_value="delta",
      sites_cart=sites_cart,
      f=out,
      prefix="*j",
      max_items=5)
    if (verbose):
      sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue(), """\
*jNonbonded interactions: 7
*jSorted by model distance:
...
*jnonbonded 0
*j          1
*j   model   vdw
*j   3.107 3.000
*jnonbonded 0
*j          0
*j   model   vdw sym.op.
*j   3.130 3.000 -x+1,y,-z+1
*j... (remaining 2 not shown)
""",
      selections=[range(2), range(-9,0)])
    out = StringIO()
    sorted_asu_proxies.show_sorted(
      by_value="delta",
      sites_cart=sites_cart,
      f=out,
      prefix="@r",
      max_items=0)
    if (verbose):
      sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue(), """\
@rNonbonded interactions: 7
""")
예제 #13
0
def exercise_basic():
    test_file = StringIO("""
*tric
Title
Reference
P 1
 11 12 13 100 110 120
Si 0.1 0.2 0.3
---------------------------------
*mono_b
Title
Reference
P 1 2 1
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*mono_c
Title
Reference
P 1 1 2
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*mono_a
Title
Reference
P 2 1 1
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*orth
Title
Reference
P 2 2 2
 11 12 13
Si 0.1 0.2 0.3 # remark
---------------------------------
*tetr
Title
Reference
P 4
 11 13
Si 0.1 0.2 0.3 4
---------------------------------
*trig
Title
Reference
R 3
 11 13
Si 0.1 0.2 0.3
---------------------------------
*rhom
Title
Reference
R 3 R
 11 100
Si 0.1 0.2 0.3
---------------------------------
*hexa
Title
Reference
P 6
 11 13
Si 0.1 0.2 0.3
---------------------------------
*cubi
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3
O  0.0 0.0 0.0
---------------------------------
*mixcon1
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3 4
O  0.0 0.0 0.0
---------------------------------
*mixcon2
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3 4
O  0.0 0.0 0.0
O  0.0 0.0 0.0
---------------------------------
""")
    all_entries = strudat.read_all_entries(test_file)
    for tag, cell in (("tric", (11, 12, 13, 100, 110,
                                120)), ("mono_b", (11, 12, 13, 90, 100, 90)),
                      ("mono_c", (11, 12, 13, 90, 90,
                                  100)), ("mono_a", (11, 12, 13, 100, 90, 90)),
                      ("orth", (11, 12, 13, 90, 90,
                                90)), ("tetr", (11, 11, 13, 90, 90, 90)),
                      ("trig", (11, 11, 13, 90, 90,
                                120)), ("rhom", (11, 11, 11, 100, 100, 100)),
                      ("hexa", (11, 11, 13, 90, 90,
                                120)), ("cubi", (11, 11, 11, 90, 90, 90))):
        assert all_entries.get(tag).unit_cell().is_similar_to(
            uctbx.unit_cell(cell))
    assert all_entries.get("orth").atoms[0].connectivity is None
    assert all_entries.get("tetr").atoms[0].connectivity == 4
    assert all_entries.get("mixcon1").connectivities() == [4, None]
    assert all_entries.get("mixcon2").connectivities() == [4, None, None]
    try:
        all_entries.get("mixcon1").connectivities(all_or_nothing=True)
    except AssertionError as e:
        assert str(e) == "Tag mixcon1: 1 atom is missing the bond count."
    else:
        raise Exception_expected
    try:
        all_entries.get("mixcon2").connectivities(all_or_nothing=True)
    except AssertionError as e:
        assert str(e) == "Tag mixcon2: 2 atoms are missing the bond count."
    else:
        raise Exception_expected
    assert all_entries.get("cubi").as_xray_structure().scatterers().size() == 2
예제 #14
0
def exercise_basic():
  test_file = StringIO("""
*tric
Title
Reference
P 1
 11 12 13 100 110 120
Si 0.1 0.2 0.3
---------------------------------
*mono_b
Title
Reference
P 1 2 1
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*mono_c
Title
Reference
P 1 1 2
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*mono_a
Title
Reference
P 2 1 1
 11 12 13 100
Si 0.1 0.2 0.3
---------------------------------
*orth
Title
Reference
P 2 2 2
 11 12 13
Si 0.1 0.2 0.3 # remark
---------------------------------
*tetr
Title
Reference
P 4
 11 13
Si 0.1 0.2 0.3 4
---------------------------------
*trig
Title
Reference
R 3
 11 13
Si 0.1 0.2 0.3
---------------------------------
*rhom
Title
Reference
R 3 R
 11 100
Si 0.1 0.2 0.3
---------------------------------
*hexa
Title
Reference
P 6
 11 13
Si 0.1 0.2 0.3
---------------------------------
*cubi
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3
O  0.0 0.0 0.0
---------------------------------
*mixcon1
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3 4
O  0.0 0.0 0.0
---------------------------------
*mixcon2
Title
Reference
P 2 3
 11
Si 0.1 0.2 0.3 4
O  0.0 0.0 0.0
O  0.0 0.0 0.0
---------------------------------
""")
  all_entries = strudat.read_all_entries(test_file)
  for tag,cell in (("tric", (11,12,13,100,110,120)),
                   ("mono_b", (11,12,13,90,100,90)),
                   ("mono_c", (11,12,13,90,90,100)),
                   ("mono_a", (11,12,13,100,90,90)),
                   ("orth", (11,12,13,90,90,90)),
                   ("tetr", (11,11,13,90,90,90)),
                   ("trig", (11,11,13,90,90,120)),
                   ("rhom", (11,11,11,100,100,100)),
                   ("hexa", (11,11,13,90,90,120)),
                   ("cubi", (11,11,11,90,90,90))):
    assert all_entries.get(tag).unit_cell().is_similar_to(
      uctbx.unit_cell(cell))
  assert all_entries.get("orth").atoms[0].connectivity is None
  assert all_entries.get("tetr").atoms[0].connectivity == 4
  assert all_entries.get("mixcon1").connectivities() == [4, None]
  assert all_entries.get("mixcon2").connectivities() == [4, None, None]
  try:
    all_entries.get("mixcon1").connectivities(all_or_nothing=True)
  except AssertionError, e:
    assert str(e) == "Tag mixcon1: 1 atom is missing the bond count."
def run_call_back(flags,
      space_group_info,
      max_n_indices=5,
      anomalous_flag=True):
  if (not flags.Verbose):
    out = StringIO()
  else:
    out = sys.stdout
  if (flags.chunk):
    chunk_n,chunk_i = [int(i) for i in flags.chunk.split(",")]
  else:
    chunk_n = 1
    chunk_i = 0
  if (flags.tag):
    if (flags.tag == "internal"):
      strudat_contents = strudat.read_all_entries(StringIO(zeolite_edi))
      strudat_entries = strudat_contents.entries
    else:
      atlas_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/misc/strudat_zeolite_atlas",
        test=os.path.isfile)
      assert atlas_file is not None
      strudat_contents = strudat.read_all_entries(open(atlas_file))
      if (not isinstance(flags.tag, str)):
        strudat_entries = strudat_contents.entries
      else:
        strudat_entries = [strudat_contents.get(tag=flags.tag)]
        assert strudat_entries[0] is not None
  if (flags.isotropic):
    use_u_aniso_flags = [False]
  elif (flags.anisotropic):
    use_u_aniso_flags = [True]
  else:
    use_u_aniso_flags = [False, True]
  if (not flags.tag):
    for n_scatterers in xrange(2,3+1):
      for use_u_aniso in use_u_aniso_flags:
        xray_structure = random_structure.xray_structure(
          space_group_info=space_group_info,
          n_scatterers=n_scatterers,
          elements="random",
          volume_per_atom=100,
          general_positions_only=False,
          random_f_prime_d_min=1,
          random_f_double_prime=anomalous_flag,
          use_u_aniso = use_u_aniso,
          use_u_iso = not(use_u_aniso),
          random_u_iso=True,
          random_u_iso_scale=0.3,
          random_occupancy=True)
        exercise(
          xray_structure=xray_structure,
          anomalous_flag=anomalous_flag,
          max_n_indices=max_n_indices,
          out=out)
        out.flush()
  else:
    i_structure = count()
    for entry in strudat_entries:
      if (i_structure.next() % chunk_n != chunk_i): continue
      print >> sys.stderr, "strudat tag:", entry.tag
      sys.stderr.flush()
      print >> out, "strudat tag:", entry.tag
      out.flush()
      for use_u_aniso in use_u_aniso_flags:
        xray_structure = entry.as_xray_structure()
        xray_structure = random_structure.xray_structure(
          space_group_info=xray_structure.space_group_info(),
          unit_cell=xray_structure.unit_cell(),
          sites_frac=xray_structure.sites_frac(),
          elements="random",
          random_f_prime_d_min=1,
          random_f_double_prime=anomalous_flag,
          use_u_aniso = use_u_aniso,
          use_u_iso = not(use_u_aniso),
          random_u_iso=True,
          random_u_iso_scale=0.3,
          random_occupancy=True)
        exercise(
          xray_structure=xray_structure,
          anomalous_flag=anomalous_flag,
          max_n_indices=max_n_indices,
          out=out)
        out.flush()
  if (flags.tag):
    return False
예제 #16
0
def run(args):
  command_line = (option_parser(
    usage="iotbx.python strudat_as_fis.py [options] studat_file [...]")
    .option(None, "--tag",
      action="store",
      type="string",
      help="tag as it appears in the strudat file")
    .option(None, "--coseq",
      action="store",
      type="string",
      help="name of file with known coordination sequences",
      metavar="FILE")
  ).process(args=args)
  if (len(command_line.args) == 0):
    command_line.parser.show_help()
    return
  if (command_line.options.coseq is not None):
    coseq_dict = coordination_sequences.get_kriber_coseq_file(
      file_name=command_line.options.coseq)
  else:
    coseq_dict = None
  n_fis = 0
  n_errors = 0
  for file_name in command_line.args:
    strudat_entries = strudat.read_all_entries(open(file_name))
    for entry in strudat_entries.entries:
      if (    command_line.options.tag is not None
          and command_line.options.tag != entry.tag):
        continue
      print "strudat tag:", entry.tag
      print
      xray_structure = entry.as_xray_structure()
      pairs, term_table = display(
        distance_cutoff=3.4,
        show_cartesian=False,
        max_shell=10,
        coseq_dict=coseq_dict,
        xray_structure=xray_structure)
      fis = format_focus_input(
        tag=entry.tag,
        xray_structure=xray_structure,
        term_table=term_table)
      open("tmp.fis", "w").write(fis)
      open("%s.fis" % entry.tag, "w").write(fis)
      n_fis += 1
      if (os.path.isfile("tmp.fo")):
        os.remove("tmp.fo")
      assert not os.path.isfile("tmp.fo")
      focus_run = easy_run.fully_buffered(
        command="focus -siteframe -sitelabel -coseq=10 tmp.fis > tmp.fo")
      focus_run.raise_if_errors_or_output()
      lines = open("tmp.fo").read().splitlines()
      focus_coseq = extract_coseq(lines=lines)
      for scatterer,terms in zip(xray_structure.scatterers(), term_table):
        focus_terms = focus_coseq[scatterer.label]
        if (list(terms) != focus_terms):
          print "ERROR:", entry.tag
          print "  cctbx", list(terms)
          print "  focus", focus_terms
          n_errors += 1
  print "Number of .fis files written:", n_fis
  print "Number of errors:", n_errors
  for file_name in ["tmp.fis", "tmp.fo"]:
    if (os.path.isfile(file_name)):
      os.remove(file_name)
예제 #17
0
def run(args):
    command_line = (option_parser(
        usage="iotbx.show_distances [options] studat_file [...]",
        description="Example: iotbx.show_distances strudat --tag=SOD").option(
            None,
            "--cif_data_block_name",
            action="store",
            type="string",
            default=None,
            help="data block name as it appears in the CIF file").option(
                None,
                "--tag",
                action="store",
                type="string",
                help="tag as it appears in the strudat file").option(
                    None,
                    "--distance_cutoff",
                    action="store",
                    type="float",
                    default=5,
                    help="Maximum distance to be considered",
                    metavar="FLOAT"
                ).option(
                    None,
                    "--min_distance_sym_equiv",
                    action="store",
                    type="float",
                    default=0.5,
                    help="Minimum distance between symmetry mates"
                    " (for special position analysis)",
                    metavar="FLOAT"
                ).option(
                    None,
                    "--show_cartesian",
                    action="store_true",
                    help="Show Cartesian coordinates (instead of fractional)"
                ).enable_symmetry_comprehensive().option(
                    None,
                    "--cs",
                    action="store",
                    type="int",
                    help="Compute N terms of the coordination sequences",
                    metavar="N").option(
                        None,
                        "--coseq",
                        action="store",
                        type="string",
                        help="name of file with known coordination sequences",
                        metavar="FILE")).process(args=args)
    if (len(command_line.args) == 0):
        command_line.parser.show_help()
        return
    co = command_line.options
    max_shell = co.cs
    if (co.coseq is not None):
        coseq_dict = coordination_sequences.get_kriber_coseq_file(
            file_name=co.coseq)
        if (max_shell is None): max_shell = 10
    else:
        coseq_dict = None

    def call_display(xray_structure):
        display(distance_cutoff=co.distance_cutoff,
                show_cartesian=co.show_cartesian,
                max_shell=max_shell,
                coseq_dict=coseq_dict,
                xray_structure=xray_structure)

    cif_data_block_name_use_counter = 0
    for file_name in command_line.args:
        xray_structure = None
        if (iotbx.pdb.is_pdb_file(file_name=file_name)):
            xray_structure = iotbx.pdb.input(
                file_name=file_name).xray_structure_simple(
                    crystal_symmetry=command_line.symmetry,
                    cryst1_substitution_buffer_layer=max(
                        5, co.distance_cutoff + 1),
                    min_distance_sym_equiv=co.min_distance_sym_equiv,
                    enable_scattering_type_unknown=True)
            call_display(xray_structure)
            continue
        if (file_name.lower().endswith(".cif")):
            xray_structures = iotbx.cif.reader(
                file_path=file_name).build_crystal_structures()
            if (co.cif_data_block_name is not None):
                xray_structure = xray_structures.get(co.cif_data_block_name)
                if (xray_structure is None):
                    continue
                cif_data_block_name_use_counter += 1
                xray_structures = [xray_structure]
            else:
                xray_structures = xray_structures.values()
            for xray_structure in xray_structures:
                call_display(xray_structure)
            continue
        if (file_name.endswith(".ins") or file_name.endswith(".res")):
            xray_structure = xray.structure.from_shelx(filename=file_name,
                                                       strictly_shelxl=False)
            call_display(xray_structure)
            continue
        if (command_line.symmetry is not None
                and (command_line.symmetry.unit_cell() is not None
                     or command_line.symmetry.space_group_info() is not None)):
            raise Sorry(
                "Command-line symmetry options not supported for strudat files."
            )
        strudat_entries = strudat.read_all_entries(open(file_name))
        for entry in strudat_entries.entries:
            if (co.tag is not None and co.tag != entry.tag):
                continue
            print "strudat tag:", entry.tag
            print
            xray_structure = entry.as_xray_structure(
                min_distance_sym_equiv=co.min_distance_sym_equiv)
            call_display(xray_structure)
    if (co.cif_data_block_name is not None
            and cif_data_block_name_use_counter == 0):
        raise Sorry("cif_data_block_name %s not found in any input files" %
                    show_string(co.cif_data_block_name))
def exercise_with_zeolite(verbose):
    if (not libtbx.env.has_module("iotbx")):
        print("Skipping exercise_with_zeolite(): iotbx not available")
        return
    from iotbx.kriber import strudat
    atlas_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/misc/strudat_zeolite_atlas",
        test=os.path.isfile)
    if (atlas_file is None):
        print("Skipping exercise_with_zeolite(): input file not available")
        return
    strudat_contents = strudat.read_all_entries(open(atlas_file))
    strudat_entry = strudat_contents.get("YUG")
    si_structure = strudat_entry.as_xray_structure()
    if (verbose):
        out = sys.stdout
    else:
        out = StringIO()
    drls = distance_and_repulsion_least_squares(
        si_structure=si_structure,
        distance_cutoff=3.5,
        nonbonded_repulsion_function_type="prolsq",
        n_macro_cycles=2,
        out=out)
    #
    nbp = drls.geometry_restraints_manager.pair_proxies().nonbonded_proxies
    assert nbp.n_total() > 50
    # expected is 60, but the exact number depends on the minimizer
    #
    site_labels = drls.minimized_structure.scatterers().extract_labels()
    sites_cart = drls.start_structure.sites_cart()
    pair_proxies = drls.geometry_restraints_manager.pair_proxies()
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          site_labels=site_labels,
                                          f=out)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert len(out.getvalue().splitlines()) == 48 * 4 + 2
    assert out.getvalue().splitlines()[-1].find("remaining") < 0
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          site_labels=site_labels,
                                          f=out,
                                          prefix="0^",
                                          max_items=28)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue().replace("e-00", "e-0"),
                         """\
0^Bond restraints: 48
0^Sorted by residual:
0^bond O3
0^     O4
0^  ideal  model  delta    sigma   weight residual
0^  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
0^bond SI1
0^     SI1
0^  ideal  model  delta    sigma   weight residual sym.op.
0^  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
0^... (remaining 20 not shown)
""",
                         selections=[range(6), range(-5, 0)])
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="delta",
                                          sites_cart=sites_cart,
                                          site_labels=site_labels,
                                          f=out,
                                          prefix="0^",
                                          max_items=28)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue().replace("e-00", "e-0"),
                         """\
0^Bond restraints: 48
0^Sorted by delta:
0^bond O3
0^     O4
0^  ideal  model  delta    sigma   weight residual
0^  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
0^... (remaining 20 not shown)
""",
                         selections=[range(6), [-1]])
    site_labels_long = ["abc" + label + "def" for label in site_labels]
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          site_labels=site_labels_long,
                                          f=out,
                                          prefix="^0",
                                          max_items=28)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue().replace("e-00", "e-0"),
                         """\
^0Bond restraints: 48
^0Sorted by residual:
^0bond abcO3def
^0     abcO4def
^0  ideal  model  delta    sigma   weight residual
^0  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
^0bond abcSI1def
^0     abcSI1def
^0  ideal  model  delta    sigma   weight residual sym.op.
^0  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
^0... (remaining 20 not shown)
""",
                         selections=[range(6), range(-5, 0)])
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          f=out,
                                          prefix=".=",
                                          max_items=28)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(out.getvalue().replace("e-00", "e-0"),
                         """\
.=Bond restraints: 48
.=Sorted by residual:
.=bond 4
.=     5
.=  ideal  model  delta    sigma   weight residual
.=  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
...
.=bond 0
.=     0
.=  ideal  model  delta    sigma   weight residual sym.op.
.=  3.071  3.216 -0.145 2.08e+00 2.31e-01 4.83e-03 -x+1/2,-y+1/2,-z+1
.=... (remaining 20 not shown)
""",
                         selections=[range(6), range(-5, 0)])
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          f=out,
                                          prefix="-+",
                                          max_items=1)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(
        out.getvalue().replace("e-00", "e-0"), """\
-+Bond restraints: 48
-+Sorted by residual:
-+bond 4
-+     5
-+  ideal  model  delta    sigma   weight residual
-+  2.629  2.120  0.509 1.56e+00 4.10e-01 1.06e-01
-+... (remaining 47 not shown)
""")
    out = StringIO()
    pair_proxies.bond_proxies.show_sorted(by_value="residual",
                                          sites_cart=sites_cart,
                                          f=out,
                                          prefix="=+",
                                          max_items=0)
    if (verbose):
        sys.stdout.write(out.getvalue())
    assert not show_diff(
        out.getvalue(), """\
=+Bond restraints: 48
=+Sorted by residual:
=+... (remaining 48 not shown)
""")
    #
    sites_cart = si_structure.sites_cart()
    site_labels = [sc.label for sc in si_structure.scatterers()]
    asu_mappings = si_structure.asu_mappings(buffer_thickness=3.5)
    for min_cubicle_edge in [0, 5]:
        pair_generator = crystal.neighbors_fast_pair_generator(
            asu_mappings=asu_mappings,
            distance_cutoff=asu_mappings.buffer_thickness(),
            minimal=False,
            min_cubicle_edge=min_cubicle_edge)
        sorted_asu_proxies = geometry_restraints.nonbonded_sorted_asu_proxies(
            asu_mappings=asu_mappings)
        while (not pair_generator.at_end()):
            p = geometry_restraints.nonbonded_asu_proxy(
                pair=next(pair_generator), vdw_distance=3)
            sorted_asu_proxies.process(p)
        out = StringIO()
        sorted_asu_proxies.show_sorted(by_value="delta",
                                       sites_cart=sites_cart,
                                       site_labels=site_labels,
                                       f=out,
                                       prefix="d%")
        if (verbose):
            sys.stdout.write(out.getvalue())
        assert not show_diff(
            out.getvalue(),
            """\
d%Nonbonded interactions: 7
d%Sorted by model distance:
...
d%nonbonded SI2
d%          SI2
d%   model   vdw sym.op.
d%   3.092 3.000 -x+1,y,-z
...
d%nonbonded SI1
d%          SI1
d%   model   vdw sym.op.
d%   3.216 3.000 -x+1/2,-y+1/2,-z+1
""",
            selections=[range(2), range(10, 14),
                        range(26, 30)])
        out = StringIO()
        sorted_asu_proxies.show_sorted(by_value="delta",
                                       sites_cart=sites_cart,
                                       f=out,
                                       prefix="*j",
                                       max_items=5)
        if (verbose):
            sys.stdout.write(out.getvalue())
        assert not show_diff(out.getvalue(),
                             """\
*jNonbonded interactions: 7
*jSorted by model distance:
...
*jnonbonded 0
*j          1
*j   model   vdw
*j   3.107 3.000
*jnonbonded 0
*j          0
*j   model   vdw sym.op.
*j   3.130 3.000 -x+1,y,-z+1
*j... (remaining 2 not shown)
""",
                             selections=[range(2), range(-9, 0)])
        out = StringIO()
        sorted_asu_proxies.show_sorted(by_value="delta",
                                       sites_cart=sites_cart,
                                       f=out,
                                       prefix="@r",
                                       max_items=0)
        if (verbose):
            sys.stdout.write(out.getvalue())
        assert not show_diff(out.getvalue(), """\
@rNonbonded interactions: 7
""")
예제 #19
0
def exercise_all():
    verbose = "--verbose" in sys.argv[1:]
    exercise_icosahedron(verbose=verbose)
    default_distance_cutoff = 3.5
    regression_misc = libtbx.env.find_in_repositories("phenix_regression/misc")
    if (regression_misc is None):
        print("Skipping exercise_all(): phenix_regression/misc not available")
        return

    def get_reference_dict(file_name):
        path = os.path.join(regression_misc, file_name)
        if (not os.path.isfile(path)):
            print("Skipping some tests: reference file not available:", path)
            return None
        result = {}
        for line in open(path).read().splitlines():
            tag, data = line.split()
            assert not tag in result
            result[tag] = data
        return result

    reference_apatanl_dict = get_reference_dict(
        "angle_pair_asu_tables_as_nested_lists")
    reference_cppc_dict = get_reference_dict(
        "conservative_pair_proxies_counts")
    file_names = []
    for file_name in ["strudat_zeolite_atlas", "strudat_special_bonds"]:
        path = os.path.join(regression_misc, file_name)
        if (not os.path.isfile(path)):
            print("Skipping %s test: input file not available" % file_name)
        else:
            file_names.append(path)
    for file_name in file_names:
        strudat_entries = strudat.read_all_entries(open(file_name))
        for i_entry, entry in enumerate(strudat_entries.entries):
            if (file_name.endswith("strudat_zeolite_atlas")
                    and not ("--full" in sys.argv[1:] or i_entry % 20 == 0)):
                continue
            if (0 or verbose):
                print("strudat tag:", entry.tag)
            structure = entry.as_xray_structure()
            if (0 or verbose):
                structure.show_summary().show_scatterers()
            if (entry.title.startswith("cutoff")):
                distance_cutoff = float(entry.title.split()[1])
            else:
                distance_cutoff = default_distance_cutoff
            weak_check_sym_equiv = (
                entry.reference.find("weak_check_sym_equiv") >= 0)
            connectivities = entry.connectivities(all_or_nothing=True)
            if (1):
                exercise(structure=structure,
                         distance_cutoff=distance_cutoff,
                         connectivities=connectivities,
                         weak_check_sym_equiv=weak_check_sym_equiv,
                         verbose=verbose)
            if (0 or verbose):
                print()
            if (file_name.endswith("strudat_zeolite_atlas")):
                exercise_bond_sorted_asu_proxies(
                    structure=structure, distance_cutoff=distance_cutoff)
            if (reference_apatanl_dict is None):
                reference_apatanl = None
            else:
                assert entry.tag in reference_apatanl_dict
                reference_apatanl = reference_apatanl_dict[entry.tag]
            if (reference_cppc_dict is None):
                reference_cppc = None
            else:
                assert entry.tag in reference_cppc_dict
                reference_cppc = reference_cppc_dict[entry.tag]
            exercise_angle_pair_asu_table(structure=structure,
                                          distance_cutoff=distance_cutoff,
                                          connectivities=connectivities,
                                          reference_apatanl=reference_apatanl,
                                          reference_cppc=reference_cppc)
def run(args, distance_cutoff=3.5):
  from iotbx.option_parser import option_parser
  command_line = (option_parser(
    usage="iotbx.distance_least_squares [options] studat_file [...]",
    description="Example: iotbx.distance_least_squares strudat --tag=SOD")
    .option(None, "--tag",
      action="store",
      type="string",
      help="tag as it appears in the strudat file")
    .option(None, "--repulsion_function",
      action="store",
      type="choice",
      choices=["gaussian", "cos", "prolsq"],
      default="gaussian",
      help="Nonbonded repulsion function type",
      metavar="gaussian|cos|prolsq")
    .option(None, "--bond_stretch_factor",
      action="store",
      type="float",
      default=0.1,
      help="Bond stretch factor used in max residual calculation"
           " for nonbonded cos or gaussian repulsion function",
      metavar="FLOAT")
    .option(None, "--n_trials",
      action="store",
      type="int",
      default=1,
      help="Number of trial per structure",
      metavar="INT")
    .option(None, "--n_macro_cycles",
      action="store",
      type="int",
      default=1,
      help="Number of macro cycles per trial",
      metavar="INT")
    .option(None, "--dev",
      action="store_true",
      default=False)
  ).process(args=args)
  if (len(command_line.args) == 0):
    command_line.parser.show_help()
    return
  co = command_line.options
  from cctbx.geometry_restraints import distance_least_squares as dls
  from iotbx.kriber import strudat
  for file_name in command_line.args:
    strudat_entries = strudat.read_all_entries(open(file_name))
    for entry in strudat_entries.entries:
      if (co.tag is not None and co.tag != entry.tag):
        continue
      print "strudat tag:", entry.tag
      print
      dls.distance_and_repulsion_least_squares(
        si_structure=entry.as_xray_structure(),
        distance_cutoff=distance_cutoff,
        nonbonded_repulsion_function_type=co.repulsion_function,
        nonbonded_max_residual_bond_stretch_factor=co.bond_stretch_factor,
        n_trials=co.n_trials,
        n_macro_cycles=co.n_macro_cycles,
        connectivities=entry.connectivities(all_or_nothing=True),
        dev=co.dev)