def convert(file_object):
    """ Examplify the direct use of the tool from shelx.lexer

  In practice, one is strongly encouraged to make use of the tools
  from shelx.parsers: that is to say, for the task handled here,
  crystal_symmetry_parser (the code to follow just parrots
  the implementation of crystal_symmetry_parser).
  """
    space_group = None
    for command, line in shelx.command_stream(file=file_object):
        cmd, args = command[0], command[-1]
        if cmd == "LATT":
            assert space_group is None
            assert len(args) == 1
            space_group = sgtbx.space_group()
            n = int(args[0])
            if n > 0:
                space_group.expand_inv(sgtbx.tr_vec((0, 0, 0)))
            z = "*PIRFABC"[abs(n)]
            space_group.expand_conventional_centring_type(z)
        elif cmd == "SYMM":
            assert space_group is not None
            assert len(args) == 1
            s = sgtbx.rt_mx(args[0])
            space_group.expand_smx(s)
        elif cmd == "SFAC":
            return sgtbx.space_group_info(group=space_group)
def convert(file_object):
  """ Examplify the direct use of the tool from shelx.lexer

  In practice, one is strongly encouraged to make use of the tools
  from shelx.parsers: that is to say, for the task handled here,
  crystal_symmetry_parser (the code to follow just parrots
  the implementation of crystal_symmetry_parser).
  """
  space_group = None
  for command, line in shelx.command_stream(file=file_object):
    cmd, args = command[0], command[-1]
    if cmd == "LATT":
      assert space_group is None
      assert len(args) == 1
      space_group = sgtbx.space_group()
      n = int(args[0])
      if n > 0:
        space_group.expand_inv(sgtbx.tr_vec((0,0,0)))
      z = "*PIRFABC"[abs(n)]
      space_group.expand_conventional_centring_type(z)
    elif cmd == "SYMM":
      assert space_group is not None
      assert len(args) == 1
      s = sgtbx.rt_mx(args[0])
      space_group.expand_smx(s)
    elif cmd == "SFAC":
      return sgtbx.space_group_info(group=space_group)
def extract_from(file_name=None, file=None, max_characters=100000):
  # XXX backward compatibility 2009-09-17 - keep max_characters keyword
  assert [file_name, file].count(None) == 1
  stream = shelx.command_stream(file=file, filename=file_name)
  parser = shelx.crystal_symmetry_parser(
    stream, builder=builders.crystal_symmetry_builder())
  parser.parse()
  return parser.builder.crystal_symmetry
def extract_from(file_name=None, file=None, max_characters=100000):
    # XXX backward compatibility 2009-09-17 - keep max_characters keyword
    assert [file_name, file].count(None) == 1
    stream = shelx.command_stream(file=file, filename=file_name)
    parser = shelx.crystal_symmetry_parser(
        stream, builder=builders.crystal_symmetry_builder())
    parser.parse()
    return parser.builder.crystal_symmetry