def run(args):
    if len(args) == 0:
        show_usage()
        return
    inp_fn = args[0]
    import time
    t0 = time.time()
    pdb_input = iotbx.pdb.input(file_name=inp_fn,
                                source_info=None,
                                raise_sorry_if_format_error=True)
    t0 = time.time()
    model = mmtbx.model.manager(model_input=pdb_input)
    pdb_h = model.get_hierarchy()
    info = pdb_h.flip_symmetric_amino_acids()
    print(info)
    model.set_sites_cart_from_hierarchy()

    out_fn_prefix = inp_fn
    if inp_fn.endswith(".pdb") or inp_fn.endswith(".cif"):
        out_fn_prefix = inp_fn[:-4]
    out_fn = out_fn_prefix + "_iupac.pdb"

    if model.input_model_format_cif():
        out_fn = out_fn_prefix + "_iupac.cif"
        txt = model.model_as_mmcif()
    else:
        out_fn = out_fn_prefix + "_iupac.cif"
        txt = model.model_as_pdb()
    with open(out_fn, 'w') as f:
        f.write(txt)
Esempio n. 2
0
def run(args, out=sys.stdout):
  for file_name in args:
    try:
      assert os.path.exists(file_name)
      print >> out, "Converting %s to mmCIF format." %file_name
      pdb_input = iotbx.pdb.pdb_input(file_name=file_name)
      model = mmtbx.model.manager(
          model_input = pdb_input)
      # hierarchy = pdb_input.construct_hierarchy(sort_atoms=False)
      hierarchy = model.get_hierarchy()
      pdb_atoms = hierarchy.atoms()
      pdb_atoms.set_chemical_element_simple_if_necessary()
      elements = pdb_atoms.extract_element().strip()
      if (not elements.all_ne("")) :
        n_missing = elements.count("")
        raise RuntimeError("Missing element symbol for %d atoms." % n_missing)
      basename = os.path.splitext(os.path.basename(file_name))[0]
      txt = model.model_as_mmcif()
      with open(basename+".cif", 'w') as f:
        f.write(txt)
      print >> out, "  wrote %s.cif" % basename
    # except IOError, e: # debugging variant, to see traceback
    except Exception, e:
      print >> out, "Error converting %s to mmCIF format:" %file_name
      print >> out, " ", str(e)
      continue
Esempio n. 3
0
def run(args):
  if len(args) == 0:
    show_usage()
    return
  inp_fn = args[0]
  pdb_input = iotbx.pdb.input(
      file_name=inp_fn,
      source_info=None,
      raise_sorry_if_format_error=True)
  model = mmtbx.model.manager(
      model_input = pdb_input)

  out_fn_prefix = inp_fn
  if inp_fn.endswith(".pdb") or inp_fn.endswith(".cif"):
    out_fn_prefix = inp_fn[:-4]
  out_fn = out_fn_prefix + "_sorted"

  txt = ""
  if model.input_format_was_cif():
    out_fn += ".cif"
    txt = model.model_as_mmcif()
  else:
    out_fn += ".pdb"
    txt = model.model_as_pdb()
  with open(out_fn, 'w') as f:
    f.write(txt)
  def run(self):
    model = self.data_manager.get_model()
    self.cif_blocks = list()

    # sequence block
    print ('Creating mmCIF block for sequence', file=self.logger)
    sequence = self.data_manager.get_sequence()
    hierarchy = model._pdb_hierarchy
    seq_block = hierarchy.as_cif_block_with_sequence(
      sequence, crystal_symmetry=model.crystal_symmetry(),
      alignment_params=self.params.sequence_alignment)
    self.cif_blocks.append(seq_block)

    # create additional cif blocks?

    # add cif blocks together
    print ('Creating complete mmCIF', file=self.logger)
    self.cif_model = model.model_as_mmcif(additional_blocks=self.cif_blocks)

    # write output file
    self.output_file = os.path.splitext(
      self.data_manager.get_default_model_name())[0] + '.deposit.cif'
    print ('Writing mmCIF', file=self.logger)
    print ('  Output file = %s' % self.output_file, file=self.logger)
    with open(self.output_file, 'wb') as f:
      f.write(self.cif_model)

    # update data manager for any downstream applications
    pdb_input = iotbx.pdb.input(self.output_file)
    model = mmtbx.model.manager(model_input=pdb_input, log=self.logger)
    self.data_manager.add_model(self.output_file, model)
    self.data_manager.set_default_model(self.output_file)
def test_2():
  inp = iotbx.pdb.input(source_info=None, lines=pdb_str_0)
  model = mmtbx.model.manager(model_input=inp)
  model.expand_with_BIOMT_records()
  model = shift_and_box_model(model)
  model.search_for_ncs()
  model.setup_ncs_constraints_groups(filter_groups=True)
  assert model.ncs_constraints_present()
  assert not model.can_be_unique_with_biomt()
  assert "" == model.model_as_mmcif(try_unique_with_biomt=True)
def test_1():
  inp = iotbx.pdb.input(source_info=None, lines=pdb_str_0)
  model = mmtbx.model.manager(model_input=inp)
  model.expand_with_BIOMT_records()
  model = shift_and_box_model(model)

  sel = model.selection("chain '0' or chain 'C' or chain 'F' or chain 'I' or chain 'L' or chain 'O' or chain 'R' or chain 'U' or chain 'X'")
  model = model.select(sel)

  model.search_for_ncs()
  model.setup_ncs_constraints_groups(filter_groups=True)
  n1 = model.get_number_of_atoms()
  assert n1 == 648, n1
  assert model.ncs_constraints_present()
  nrgl = model.get_ncs_groups()
  assert len(nrgl[0].master_iselection) == 72
  assert len(nrgl[0].copies) == 8
  # nrgl._show()
  # print (model.can_be_unique_with_biomt())
  cif_txt = model.model_as_mmcif(try_unique_with_biomt=True)
  # print (cif_txt)
  assert_lines_in_text(cif_txt, """
loop_
  _pdbx_struct_assembly_gen.assembly_id
  _pdbx_struct_assembly_gen.oper_expression
  _pdbx_struct_assembly_gen.asym_id_list
   1 (1-9) A""")
  assert_lines_in_text(cif_txt, """
loop_
  _pdbx_struct_assembly.id
  _pdbx_struct_assembly.details
  _pdbx_struct_assembly.method_details
  _pdbx_struct_assembly.oligomeric_details
  _pdbx_struct_assembly.oligomeric_count
   1 'Symmetry assembly' ? ? ? """)
  assert_lines_in_text(cif_txt, """
  _pdbx_struct_oper_list.vector[1]
  _pdbx_struct_oper_list.vector[2]
  _pdbx_struct_oper_list.vector[3]
   1 'point symmetry operation' ? ? 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0""")


  inp = iotbx.pdb.input(source_info=None, lines=cif_txt)
  m2 = mmtbx.model.manager(model_input=inp)
  n2_1 = m2.get_number_of_atoms()
  assert n2_1 == 72
  m2.expand_with_BIOMT_records()
  n2_2 = m2.get_number_of_atoms()
  # print (n1, n2)
  assert n1 == n2_2, "%d, %d" % (n1, n2)
Esempio n. 7
0
def run(args):
    """
  Apply MTRIX records of PDB or equivalent records of mmCIF.
  Example:
    phenix.pdb.mtrix_reconstruction model.pdb
    phenix.pdb.mtrix_reconstruction model.cif
  """
    if (len(args) == 0 or "--help" in args or "-h" in args):
        print(run.__doc__)
        return
    file_name = args[0]
    pdb_inp = iotbx.pdb.input(file_name=file_name)
    model = mmtbx.model.manager(model_input=pdb_inp)
    if model.input_model_format_cif():
        out_text = model.model_as_mmcif()
        ext = ".cif"
    else:
        out_text = model.model_as_pdb()
        ext = ".pdb"
    ofn = "%s_MTRIX_expanded%s" % (os.path.splitext(
        os.path.basename(file_name))[0], ext)
    print("Writing result to %s file." % ofn)
    with open(ofn, 'w') as f:
        f.write(out_text)