コード例 #1
0
def run(args):
  log = sys.stdout
  if len(args) == 0:
    format_usage_message(log)
    return
  inputs = mmtbx.utils.process_command_line_args(args=args,
      master_params=master_params())
  work_params = inputs.params.extract()
  inputs.params.show(prefix=" ", out=log)
  pdb_file_names = list(inputs.pdb_file_names)
  if work_params.file_name is not None:
    pdb_file_names += work_params.file_name
  if len(pdb_file_names) == 0:
    raise Sorry("No PDB file specified")
  work_params.model_idealization.enabled=True
  # work_params.model_idealization.file_name_before_regularization="before.pdb"

  pdb_combined = iotbx.pdb.combine_unique_pdb_files(file_names=pdb_file_names)
  pdb_input = iotbx.pdb.input(source_info=None,
    lines=flex.std_string(pdb_combined.raw_records))
  pdb_h = pdb_input.construct_hierarchy()
  # couple checks if combined pdb_h is ok
  o_c = pdb_h.overall_counts()
  o_c.raise_duplicate_atom_labels_if_necessary()
  o_c.raise_residue_groups_with_multiple_resnames_using_same_altloc_if_necessary()
  o_c.raise_chains_with_mix_of_proper_and_improper_alt_conf_if_necessary()
  o_c.raise_improper_alt_conf_if_necessary()

  ann = ioss.annotation.from_phil(
      phil_helices=work_params.secondary_structure.protein.helix,
      phil_sheets=work_params.secondary_structure.protein.sheet,
      pdb_hierarchy=pdb_h)
  if ann.get_n_helices() + ann.get_n_sheets() == 0:
    ann = pdb_input.extract_secondary_structure()
  if ann is None or ann.get_n_helices() + ann.get_n_sheets() == 0:
    raise Sorry("No secondary structure annotations found.")
  ssb.substitute_ss(
      real_h=pdb_h,
      xray_structure=pdb_input.xray_structure_simple(),
      ss_annotation=ann,
      params=work_params.model_idealization,
      cif_objects=inputs.cif_objects,
      verbose=True,
      log=log,
      )
  # Write resulting pdb file.
  write_whole_pdb_file(
      file_name="%s_idealized.pdb" % os.path.basename(pdb_file_names[0]),
      pdb_hierarchy=pdb_h,
      crystal_symmetry=pdb_input.crystal_symmetry(),
      ss_annotation=ann)
  print >> log, "All done."
コード例 #2
0
ファイル: tst_3.py プロジェクト: cctbx/cctbx-playground
def exercise_some_atoms_are_absent():
  """ CD1, CD2 from 101 residue are absent"""
  tst_pdb_2 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    872  CA  TRP A 101    -127.455-144.601-103.619  1.00 25.83           C
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
"""
  pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_2)
  ann = pdb_inp.extract_secondary_structure()
  h = pdb_inp.construct_hierarchy()
  rm = ssb.substitute_ss(
      real_h=h,
      xray_structure=pdb_inp.xray_structure_simple(),
      ss_annotation=ann)
コード例 #3
0
ファイル: tst_3.py プロジェクト: cctbx/cctbx-playground
def exercise_presence_of_h():
  tst_pdb_1 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    870  H   GLY A 100    -129.862-139.777-104.337  1.00 36.09           H
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    872  CA  TRP A 101    -127.455-144.601-103.619  1.00 25.83           C
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    877  CD1 TRP A 101    -126.180-147.300-103.922  1.00 42.04           C
ATOM    878  CD2 TRP A 101    -125.677-147.528-101.760  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
ATOM    882  CZ2 TRP A 101    -124.799-149.820-101.767  1.00 42.04           C
ATOM    883  CZ3 TRP A 101    -124.899-148.528 -99.725  1.00 42.04           C
ATOM    884  CH2 TRP A 101    -124.581-149.703-100.415  1.00 42.04           C
ATOM    885  H   TRP A 101    -126.863-142.797-102.745  1.00 42.04           H
"""
  pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_1)
  ann = pdb_inp.extract_secondary_structure()
  h = pdb_inp.construct_hierarchy()
  rm = ssb.substitute_ss(
      real_h=h,
      xray_structure=pdb_inp.xray_structure_simple(),
      ss_annotation=ann)
コード例 #4
0
ファイル: tst_3.py プロジェクト: hainm/cctbx_project
def exercise_presence_of_h():
    tst_pdb_1 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    870  H   GLY A 100    -129.862-139.777-104.337  1.00 36.09           H
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    872  CA  TRP A 101    -127.455-144.601-103.619  1.00 25.83           C
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    877  CD1 TRP A 101    -126.180-147.300-103.922  1.00 42.04           C
ATOM    878  CD2 TRP A 101    -125.677-147.528-101.760  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
ATOM    882  CZ2 TRP A 101    -124.799-149.820-101.767  1.00 42.04           C
ATOM    883  CZ3 TRP A 101    -124.899-148.528 -99.725  1.00 42.04           C
ATOM    884  CH2 TRP A 101    -124.581-149.703-100.415  1.00 42.04           C
ATOM    885  H   TRP A 101    -126.863-142.797-102.745  1.00 42.04           H
"""
    pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_1)
    ann = pdb_inp.extract_secondary_structure()
    h = pdb_inp.construct_hierarchy()
    rm = ssb.substitute_ss(real_h=h,
                           xray_structure=pdb_inp.xray_structure_simple(),
                           ss_annotation=ann)
コード例 #5
0
def run(args):
  pdb_inp = iotbx.pdb.input(source_info=None,
    file_name=args[0])
  ss_ann = pdb_inp.extract_secondary_structure()
  pdb_h = pdb_inp.construct_hierarchy()
  params = ssb.master_phil.extract()
  params.ss_idealization.file_name_before_regularization="before_reg.pdb"
  params.ss_idealization.enabled=True
  rm = ssb.substitute_ss(
    real_h=pdb_h,
    xray_structure=pdb_inp.xray_structure_simple(),
    use_plane_peptide_bond_restr=True,
    log=sys.stdout,
    ss_annotation=ss_ann,
    params=params)
  out_fname = "%s_ss_ideal.pdb" % os.path.basename(args[0])
  iotbx.pdb.write_whole_pdb_file(
    file_name=out_fname,
    output_file=None,
    processed_pdb_file=None,
    pdb_hierarchy=pdb_h,
    crystal_symmetry=None,
    ss_annotation=ss_ann,
    append_end=True,
    atoms_reset_serial_first_value=None,
    link_records=None)
  print "File saved: %s" % out_fname
  print "All done."
コード例 #6
0
def exercise_some_atoms_are_absent():
  """ CD1, CD2 from 101 residue are absent"""
  tst_pdb_2 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    872  CA  TRP A 101    -127.455-144.601-103.619  1.00 25.83           C
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
"""
  pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_2)
  ann = pdb_inp.extract_secondary_structure()
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    build_grm = True)
  model.set_ss_annotation(ann)
  rm = ssb.substitute_ss(
      model)
コード例 #7
0
def run(args):
  pdb_inp = iotbx.pdb.input(source_info=None,
    file_name=args[0])
  model = mmtbx.model.manager(
      model_input=pdb_inp)
  params = ssb.master_phil.extract()
  params.ss_idealization.file_name_before_regularization="before_reg.pdb"
  params.ss_idealization.enabled=True
  rm = ssb.substitute_ss(
    model = model,
    params = params,
    log=sys.stdout)
  out_fname = "%s_ss_ideal.pdb" % os.path.basename(args[0])
  txt = model.model_as_pdb()
  with open(out_fname, 'w') as f:
    f.write(txt)
  print("File saved: %s" % out_fname)
  print("All done.")
コード例 #8
0
def exercise_ca_absent():
  # should raise Sorry
  """ CA from 101 residue are absent. We don't handle it at the moment."""
  tst_pdb_1 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    870  H   GLY A 100    -129.862-139.777-104.337  1.00 36.09           H
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    877  CD1 TRP A 101    -126.180-147.300-103.922  1.00 42.04           C
ATOM    878  CD2 TRP A 101    -125.677-147.528-101.760  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
ATOM    882  CZ2 TRP A 101    -124.799-149.820-101.767  1.00 42.04           C
ATOM    883  CZ3 TRP A 101    -124.899-148.528 -99.725  1.00 42.04           C
ATOM    884  CH2 TRP A 101    -124.581-149.703-100.415  1.00 42.04           C
ATOM    885  H   TRP A 101    -126.863-142.797-102.745  1.00 42.04           H
"""
  pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_1)
  ann = pdb_inp.extract_secondary_structure()
  model = mmtbx.model.manager(
    model_input = pdb_inp,
    build_grm = True)
  model.set_ss_annotation(ann)
  try:
    rm = ssb.substitute_ss(
        model)
  except Sorry as e:
    assert e.args[0].startswith("C, CA or N")
  except Exception:
    assert 0, "Error: This test failed"
  else:
    assert 0, "Error: This test failed"
コード例 #9
0
ファイル: tst_3.py プロジェクト: cctbx/cctbx-playground
def exercise_ca_absent():
  # should raise Sorry
  """ CA from 101 residue are absent. We don't handle it at the moment."""
  tst_pdb_1 = """\
HELIX    2   2 GLY A  100  TRP A  101  1                                   2
ATOM    866  N   GLY A 100    -128.903-139.939-104.460  1.00 27.58           N
ATOM    867  CA  GLY A 100    -128.223-140.890-103.603  1.00 27.58           C
ATOM    868  C   GLY A 100    -128.381-142.356-103.959  1.00 27.58           C
ATOM    869  O   GLY A 100    -129.283-142.755-104.686  1.00 27.58           O
ATOM    870  H   GLY A 100    -129.862-139.777-104.337  1.00 36.09           H
ATOM    871  N   TRP A 101    -127.491-143.163-103.397  1.00 25.83           N
ATOM    873  C   TRP A 101    -128.824-145.274-103.752  1.00 25.83           C
ATOM    874  O   TRP A 101    -129.091-145.962-104.734  1.00 25.83           O
ATOM    875  CB  TRP A 101    -126.659-145.240-102.480  1.00 42.04           C
ATOM    876  CG  TRP A 101    -126.207-146.635-102.729  1.00 42.04           C
ATOM    877  CD1 TRP A 101    -126.180-147.300-103.922  1.00 42.04           C
ATOM    878  CD2 TRP A 101    -125.677-147.528-101.760  1.00 42.04           C
ATOM    879  NE1 TRP A 101    -125.663-148.557-103.751  1.00 42.04           N
ATOM    880  CE2 TRP A 101    -125.347-148.723-102.429  1.00 42.04           C
ATOM    881  CE3 TRP A 101    -125.446-147.437-100.384  1.00 42.04           C
ATOM    882  CZ2 TRP A 101    -124.799-149.820-101.767  1.00 42.04           C
ATOM    883  CZ3 TRP A 101    -124.899-148.528 -99.725  1.00 42.04           C
ATOM    884  CH2 TRP A 101    -124.581-149.703-100.415  1.00 42.04           C
ATOM    885  H   TRP A 101    -126.863-142.797-102.745  1.00 42.04           H
"""
  pdb_inp = iotbx.pdb.input(source_info=None, lines=tst_pdb_1)
  ann = pdb_inp.extract_secondary_structure()
  h = pdb_inp.construct_hierarchy()
  try:
    rm = ssb.substitute_ss(
        real_h=h,
        xray_structure=pdb_inp.xray_structure_simple(),
        ss_annotation=ann)
  except Sorry as e:
    assert e.args[0].startswith("C, CA or N")
  except Exception:
    assert 0, "Error: This test failed"
  else:
    assert 0, "Error: This test failed"
コード例 #10
0
ファイル: tst_ss_id_ncs.py プロジェクト: TheApacheCats/cctbx
def exercise():
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    ann = pdb_inp.extract_secondary_structure()
    pdb_int_params = mmtbx.model.manager.get_default_pdb_interpretation_params(
    )
    pdb_int_params.pdb_interpretation.ncs_search.enabled = True
    model = mmtbx.model.manager(model_input=pdb_inp,
                                pdb_interpretation_params=pdb_int_params,
                                build_grm=True)
    model.setup_ncs_constraints_groups()
    log = StringIO()
    rm = ssb.substitute_ss(model, log=log)
    # with open("res.pdb", 'w') as f:
    # f.write(model.model_as_pdb())

    # check that strict NCS was implemented throughout
    dif = get_difference_chainsAB(strings=model.model_as_pdb())
    for d in dif:
        assert approx_equal(d, (0, 0, 0), eps=0.005)
    log_cont = log.getvalue()
    assert log_cont.find("skipping, not in NCS master") > 0
    # print log_cont
    print("OK")
コード例 #11
0
    def run(self):
        t_0 = time()
        self.ann = self.model.get_ss_annotation()
        self._setup_model_h()
        self.model.set_restraint_objects(self.model_h.get_restraint_objects())

        self.model.get_restraints_manager()
        # set SS restratins
        self.set_ss_restraints(self.ann)

        self.model.setup_ncs_constraints_groups()

        self.init_model_statistics = self.get_statistics(self.model)

        #
        # Cablam idealization
        #
        if self.params.debug:
            self.shift_and_write_result(model=self.model, fname_suffix="start")
            self.shift_and_write_result(model=self.model_h,
                                        fname_suffix="start_h")
        self.params.cablam_idealization.find_ss_after_fixes = False
        ci_results = cablam_idealization(
            model=self.model,
            params=self.params.cablam_idealization,
            log=self.log).get_results()
        self.model = ci_results.model
        self.after_cablam_statistics = self.get_statistics(self.model)
        if self.params.debug:
            self.shift_and_write_result(model=self.model,
                                        fname_suffix="cablam_id")

        # Here we are preparing maps if needed.
        if self.user_supplied_map is not None:
            self.prepare_user_map()

        if self.reference_map is None and self.params.use_map_for_reference:
            self.prepare_reference_map_3()

        if self.params.run_minimization_first:
            # running simple minimization and updating all
            # self.master, self.working, etc...
            # self.whole_pdb_h.reset_atom_i_seqs()
            if self.init_ref_map is None:
                self.prepare_init_reference_map()
            print >> self.log, "Minimization first"
            self.minimize(
                model=self.model,
                original_pdb_h=self.original_hierarchy,
                excl_string_selection=None,  # don't need if we have map
                reference_map=self.init_ref_map,
            )
            self.init_gm_model_statistics = self.get_statistics(self.model)
            if self.params.debug:
                self.shift_and_write_result(model=self.model,
                                            fname_suffix="init_gm")

        if (self.init_gm_model_statistics is not None
                and self.init_gm_model_statistics.ramachandran.outliers == 0
                and self.init_gm_model_statistics.omega.twisted_general <= 0.01
                and self.init_gm_model_statistics.omega.twisted_proline <= 0.01
                and self.init_gm_model_statistics.omega.cis_general <= 0.01
                and self.init_gm_model_statistics.omega.cis_proline <= 0.01
                and self.init_gm_model_statistics.rotamer.outliers <= 0.01):
            print >> self.log, "Simple minimization was enough"
            # Early exit!!!
            self.shift_and_write_result(model=self.model,
                                        fname_suffix="all_idealized")
            self.final_model_statistics = self.get_statistics(self.model)
            # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_end.pdb")
            self.time_for_run = time() - t_0
            if self.params.output_pkl:
                easy_pickle.dump(file_name="%s.pkl" %
                                 self.params.output_prefix,
                                 obj=self.get_stats_obj())
            return

        self.filtered_whole_ann = None
        if self.ann is not None:
            self.filtered_whole_ann = self.ann.deep_copy()
            print >> self.log, "Original SS annotation"
            print >> self.log, self.ann.as_pdb_str()
            if self.params.filter_input_ss:
                self.filtered_whole_ann = self.ann.filter_annotation(
                    hierarchy=self.model.get_hierarchy(),
                    asc=self.model.get_atom_selection_cache())
            print >> self.log, "Filtered SS annotation"
            print >> self.log, self.filtered_whole_ann.as_pdb_str()
            self.model.set_ss_annotation(self.filtered_whole_ann)

        # getting grm with SS restraints
        self.update_ss_in_grm(self.filtered_whole_ann)

        if (self.ann is None
                or self.ann.get_n_helices() + self.ann.get_n_sheets() == 0
                or not self.params.ss_idealization.enabled):
            print >> self.log, "No secondary structure annotations found or SS idealization is disabled."
            print >> self.log, "Secondary structure substitution step will be skipped"
            self.log.flush()
            # here we want to do geometry minimization anyway!
            negate_selection = None
            if self.reference_map is None:
                outlier_selection_txt = mmtbx.building.loop_closure.utils. \
                  rama_score_selection(self.model, self.model.get_ramachandran_manager(), "outlier",1)
                print >> self.log, "outlier_selection_txt", outlier_selection_txt
                negate_selection = "all"
                if outlier_selection_txt != "" and outlier_selection_txt is not None:
                    negate_selection = "not (%s)" % outlier_selection_txt
            # if self.params.run_minimization_first:
            # self.minimize(
            #     model=self.model,
            #     original_pdb_h=self.whole_pdb_h,
            #     ncs_restraints_group_list=self.filtered_ncs_restr_group_list,
            #     excl_string_selection=negate_selection,
            #     reference_map=self.reference_map)
            # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_h_1.pdb")
        else:
            if self.params.debug:
                self.params.ss_idealization.file_name_before_regularization = \
                    "%s_ss_before_reg.pdb" % self.params.output_prefix
            self.params.ss_idealization.skip_good_ss_elements = True
            ssb.substitute_ss(model=self.model,
                              params=self.params.ss_idealization,
                              verbose=self.params.verbose,
                              reference_map=self.master_map,
                              log=self.log)
            self.log.flush()

        self.after_ss_idealization = self.get_statistics(self.model)
        self.shift_and_write_result(model=self.model,
                                    fname_suffix="ss_ideal_stat")

        # Write resulting pdb file.
        if self.params.debug:
            self.shift_and_write_result(
                model=self.model,
                fname_suffix="ss_ideal",
            )
        # self.params.loop_idealization.minimize_whole = not self.model.ncs_constraints_present() and self.params.loop_idealization.minimize_whole
        self.params.loop_idealization.debug = self.params.debug or self.params.loop_idealization.debug
        # self.params.loop_idealization.enabled = False
        # self.params.loop_idealization.variant_search_level = 0
        print >> self.log, "Starting loop idealization"
        loop_ideal = loop_idealization(self.model,
                                       params=self.params.loop_idealization,
                                       reference_map=self.master_map,
                                       log=self.log,
                                       verbose=True)
        self.log.flush()
        if self.params.debug:
            self.shift_and_write_result(model=self.model,
                                        fname_suffix="rama_ideal")
        self.after_loop_idealization = self.get_statistics(self.model)

        # fixing remaining rotamer outliers
        if (self.params.additionally_fix_rotamer_outliers
                and self.after_loop_idealization.rotamer.outliers > 0.004):
            self.idealize_rotamers()

        self.after_rotamer_fixing = self.get_statistics(self.model)
        ref_hierarchy_for_final_gm = self.original_boxed_hierarchy
        if not self.params.use_starting_model_for_final_gm:
            ref_hierarchy_for_final_gm = self.model.get_hierarchy().deep_copy()
        ref_hierarchy_for_final_gm.reset_atom_i_seqs()

        if self.model.ncs_constraints_present():
            print >> self.log, "Using ncs"
            # assert 0
        else:
            print >> self.log, "Not using ncs"
            # assert 0

        # need to update SS manager for the whole model here.
        if self.params.use_ss_restraints:
            ss_params = sec_str_master_phil.fetch().extract()
            ss_params.secondary_structure.protein.remove_outliers = not self.params.ss_idealization.enabled
            self.set_ss_restraints(ss_annotation=self.filtered_whole_ann,
                                   params=ss_params.secondary_structure)
        if self.params.run_minimization_last:
            print >> self.log, "loop_ideal.ref_exclusion_selection", loop_ideal.ref_exclusion_selection
            print >> self.log, "Minimizing whole model"
            self.minimize(
                model=self.model,
                original_pdb_h=ref_hierarchy_for_final_gm,
                excl_string_selection=loop_ideal.ref_exclusion_selection,
                reference_map=self.reference_map)
        self.shift_and_write_result(model=self.model,
                                    fname_suffix="all_idealized")
        self.final_model_statistics = self.get_statistics(self.model)
        self.time_for_run = time() - t_0
        if self.params.output_pkl or self.params.debug:
            easy_pickle.dump(file_name="%s.pkl" % self.params.output_prefix,
                             obj=self.get_stats_obj())
コード例 #12
0
  def run(self):
    t_0 = time()

    ncs_obj = iotbx.ncs.input(
        hierarchy=self.whole_pdb_h,
        chain_max_rmsd=4.0,
        chain_similarity_threshold=0.99,
        residue_match_radius=999.0)
    print >> self.log, "Found NCS groups:"
    ncs_obj.show(format='phil', log=self.log)
    ncs_restr_group_list = ncs_obj.get_ncs_restraints_group_list(
        raise_sorry=False)
    self.using_ncs = False
    total_ncs_selected_atoms = 0
    master_sel = flex.size_t([])
    filtered_ncs_restr_group_list = self.filter_ncs_restraints_group_list(
        self.whole_pdb_h, ncs_restr_group_list)
    if len(filtered_ncs_restr_group_list) > 0:
      self.using_ncs = True
      master_sel = flex.bool(self.whole_pdb_h.atoms_size(), True)
      for ncs_gr in filtered_ncs_restr_group_list:
        for copy in ncs_gr.copies:
          master_sel.set_selected(copy.iselection, False)
      self.master_pdb_h = self.whole_pdb_h.select(master_sel)
      self.master_sel=master_sel
      self.master_pdb_h.reset_atom_i_seqs()

    if self.using_ncs:
      self.master_pdb_h.write_pdb_file("%s_master_h.pdb" % self.params.output_prefix)
      self.working_pdb_h = self.master_pdb_h
    else:
      self.working_pdb_h = self.whole_pdb_h
    self.working_pdb_h.reset_atom_i_seqs()

    self.ann = ioss.annotation.from_phil(
        phil_helices=self.params.secondary_structure.protein.helix,
        phil_sheets=self.params.secondary_structure.protein.sheet,
        pdb_hierarchy=self.whole_pdb_h)

    self.working_xrs = self.working_pdb_h.extract_xray_structure(crystal_symmetry=self.cs)
    if self.using_ncs:
      self.whole_xrs = self.whole_pdb_h.extract_xray_structure(crystal_symmetry=self.cs)
    else:
      self.whole_xrs = self.working_xrs

    if self.params.use_map_for_reference:
      # self.prepare_reference_map(xrs=self.whole_xrs, pdb_h=self.whole_pdb_h)
      # self.prepare_reference_map_2(xrs=self.whole_xrs, pdb_h=self.whole_pdb_h)
      self.prepare_reference_map_3(xrs=self.whole_xrs, pdb_h=self.whole_pdb_h)
    # STOP()

    if self.ann.get_n_helices() + self.ann.get_n_sheets() == 0:
      self.ann = self.pdb_input.extract_secondary_structure()
    self.original_ann = None
    self.filtered_whole_ann = None
    if self.ann is not None:
      self.original_ann = self.ann.deep_copy()
      print >> self.log, "Original SS annotation"
      print >> self.log, self.original_ann.as_pdb_str()
      self.ann.remove_short_annotations()
      self.filtered_whole_ann = self.ann.deep_copy()
      self.ann.remove_empty_annotations(
          hierarchy=self.working_pdb_h)
      self.filtered_whole_ann.remove_empty_annotations(
          hierarchy=self.whole_pdb_h)
      # self.ann.concatenate_consecutive_helices()
      self.ann.split_helices_with_prolines(
          hierarchy=self.working_pdb_h,
          asc=None)
      self.filtered_whole_ann.split_helices_with_prolines(
          hierarchy=self.whole_pdb_h,
          asc=None)
      # print >> self.log, "Splitted SS annotation"
      # print >> self.log, ann.as_pdb_str()
      print >> self.log, "Filtered SS annotation"
      print >> self.log, self.ann.as_pdb_str()

    # getting grm with SS restraints
    self.get_grm()

    if (self.ann is None or
        self.ann.get_n_helices() + self.ann.get_n_sheets() == 0 or
        not self.params.ss_idealization.enabled):
      print >> self.log, "No secondary structure annotations found or SS idealization is disabled."
      print >> self.log, "Secondary structure substitution step will be skipped"
      self.log.flush()
      # here we want to do geometry minimization anyway!
      negate_selection = None
      if self.reference_map is None:
        outlier_selection_txt = mmtbx.building.loop_closure.utils. \
          rama_outliers_selection(self.working_pdb_h, self.rama_manager, 1)
        print >> self.log, "outlier_selection_txt", outlier_selection_txt
        negate_selection = "all"
        if outlier_selection_txt != "" and outlier_selection_txt is not None:
          negate_selection = "not (%s)" % outlier_selection_txt
      self.minimize(
          hierarchy=self.whole_pdb_h,
          xrs=self.whole_xrs,
          original_pdb_h=self.whole_pdb_h,
          grm=self.whole_grm,
          ncs_restraints_group_list=filtered_ncs_restr_group_list,
          excl_string_selection=negate_selection,
          ss_annotation=self.ann,
          reference_map=self.reference_map)
      # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_h_1.pdb")
    else:
      self.params.ss_idealization.file_name_before_regularization = \
          "%s_ss_before_reg.pdb" % self.params.output_prefix
      ssb.substitute_ss(
          real_h=self.working_pdb_h,
          xray_structure=self.working_xrs,
          ss_annotation=self.ann,
          params=self.params.ss_idealization,
          grm=self.working_grm,
          fix_rotamer_outliers=True,
          cif_objects=self.cif_objects,
          verbose=True,
          reference_map=self.reference_map,
          rotamer_manager=self.rotamer_manager,
          log=self.log)
      self.log.flush()

    self.after_ss_idealization = geometry_no_grm(
        pdb_hierarchy=iotbx.pdb.input(
          source_info=None,
          lines=self.working_pdb_h.as_pdb_string()).construct_hierarchy(),
        molprobity_scores=True)

    # Write resulting pdb file.
    self.shift_and_write_result(
        hierarchy=self.working_pdb_h,
        fname_suffix="ss_ideal",
        grm=self.working_grm)
    # STOP()
    self.params.loop_idealization.minimize_whole = not self.using_ncs
    # self.params.loop_idealization.enabled = False
    # self.params.loop_idealization.variant_search_level = 0
    loop_ideal = loop_idealization(
        pdb_hierarchy=self.working_pdb_h,
        params=self.params.loop_idealization,
        secondary_structure_annotation=self.ann,
        reference_map=self.reference_map,
        crystal_symmetry=self.working_xrs.crystal_symmetry(),
        grm=self.working_grm,
        rama_manager=self.rama_manager,
        rotamer_manager=self.rotamer_manager,
        log=self.log,
        verbose=True)
    self.log.flush()
    # STOP()
    self.shift_and_write_result(
        hierarchy=loop_ideal.resulting_pdb_h,
        fname_suffix="rama_ideal",
        grm=self.working_grm)
    self.after_loop_idealization = geometry_no_grm(
        pdb_hierarchy=iotbx.pdb.input(
          source_info=None,
          lines=loop_ideal.resulting_pdb_h.as_pdb_string()).construct_hierarchy(),
        molprobity_scores=True)

    # fixing remaining rotamer outliers
    fixed_rot_pdb_h = loop_ideal.resulting_pdb_h.deep_copy()
    fixed_rot_pdb_h.reset_atom_i_seqs()
    if (self.params.additionally_fix_rotamer_outliers and
        self.after_loop_idealization.rotamer_outliers > 0.004):
      print >> self.log, "Processing pdb file again for fixing rotamers..."
      self.log.flush()
      print >> self.log, "Fixing rotamers..."
      self.log.flush()
      self.shift_and_write_result(
        hierarchy=fixed_rot_pdb_h,
        fname_suffix="just_before_rota")
      fixed_rot_pdb_h = fix_rotamer_outliers(
          pdb_hierarchy=fixed_rot_pdb_h,
          grm=self.working_grm.geometry,
          xrs=self.working_xrs,
          map_data=self.reference_map,
          mon_lib_srv=self.mon_lib_srv,
          rotamer_manager=self.rotamer_manager,
          verbose=True)

    self.shift_and_write_result(
        hierarchy=fixed_rot_pdb_h,
        fname_suffix="rota_ideal",
        grm=self.working_grm)
    cs_to_write = self.cs if self.shift_vector is None else None
    self.after_rotamer_fixing = geometry_no_grm(
        pdb_hierarchy=iotbx.pdb.input(
          source_info=None,
          lines=fixed_rot_pdb_h.as_pdb_string()).construct_hierarchy(),
        molprobity_scores=True)

    ref_hierarchy_for_final_gm = self.original_boxed_hierarchy
    if not self.params.use_starting_model_for_final_gm:
      ref_hierarchy_for_final_gm = self.whole_pdb_h
    ref_hierarchy_for_final_gm.reset_atom_i_seqs()
    if self.params.additionally_fix_rotamer_outliers:
      ssb.set_xyz_smart(self.working_pdb_h, fixed_rot_pdb_h)
    if self.using_ncs:
      print >> self.log, "Using ncs"
      # multiply back and do geometry_minimization for the whole molecule
      for ncs_gr in ncs_restr_group_list:
        master_h = self.whole_pdb_h.select(ncs_gr.master_iselection)
        for c in ncs_gr.copies:
          new_sites = master_h.atoms().extract_xyz()
          new_c_sites = c.r.elems * new_sites + c.t
          self.whole_pdb_h.select(c.iselection).atoms().set_xyz(new_c_sites)
      self.log.flush()
    else:
      # still need to run gm if rotamers were fixed
      print >> self.log, "Not using ncs"

    # need to update SS manager for the whole model here.
    if self.params.use_ss_restraints:
      ss_manager = manager(
          pdb_hierarchy=self.whole_pdb_h,
          geometry_restraints_manager=self.whole_grm.geometry,
          sec_str_from_pdb_file=self.filtered_whole_ann,
          params=None,
          mon_lib_srv=self.mon_lib_srv,
          verbose=-1,
          log=self.log)
      self.whole_grm.geometry.set_secondary_structure_restraints(
          ss_manager=ss_manager,
          hierarchy=self.whole_pdb_h,
          log=self.log)
    print >> self.log, "loop_ideal.ref_exclusion_selection", loop_ideal.ref_exclusion_selection
    print >> self.log, "Minimizing whole model"
    self.minimize(
        hierarchy=self.whole_pdb_h,
        xrs=self.whole_xrs,
        grm=self.whole_grm,
        ncs_restraints_group_list=filtered_ncs_restr_group_list,
        original_pdb_h=ref_hierarchy_for_final_gm,
        excl_string_selection=loop_ideal.ref_exclusion_selection,
        ss_annotation=self.ann,
        reference_map = self.reference_map)
    self.shift_and_write_result(
        hierarchy=self.whole_pdb_h,
        fname_suffix="all_idealized",
        grm=self.whole_grm)
    self.final_model_statistics = geometry_no_grm(
        pdb_hierarchy=iotbx.pdb.input(
          source_info=None,
          lines=self.whole_pdb_h.as_pdb_string()).construct_hierarchy(),
        molprobity_scores=True)
    # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_end.pdb")
    self.time_for_run = time() - t_0
コード例 #13
0
  def run(self):
    t_0 = time()
    self.ann = self.model.get_ss_annotation()

    self.get_grm()
    self.model.setup_ncs_constraints_groups()

    self.init_model_statistics = self.get_statistics(self.model)

    #
    # Cablam idealization
    #
    self.params.cablam_idealization.find_ss_after_fixes = False
    ci_results = cablam_idealization(
        model=self.model,
        params=self.params.cablam_idealization,
        log=self.log).get_results()
    self.model = ci_results.model
    self.after_cablam_statistics = self.get_statistics(self.model)
    if self.params.debug:
      self.shift_and_write_result(
          model = self.model,
          fname_suffix="cablam_id")


    # Here we are preparing maps if needed.
    if self.user_supplied_map is not None:
      self.prepare_user_map()

    if self.reference_map is None and self.params.use_map_for_reference:
      self.prepare_reference_map_3()

    if self.params.run_minimization_first:
      # running simple minimization and updating all
      # self.master, self.working, etc...
      # self.whole_pdb_h.reset_atom_i_seqs()
      if self.init_ref_map is None:
        self.prepare_init_reference_map()
      print >> self.log, "Minimization first"
      self.minimize(
          model=self.model,
          original_pdb_h=self.original_hierarchy,
          excl_string_selection=None, # don't need if we have map
          reference_map=self.init_ref_map,
          )
      self.init_gm_model_statistics = self.get_statistics(self.model)
      if self.params.debug:
        self.shift_and_write_result(
            model = self.model,
            fname_suffix="init_gm")

    if (self.init_gm_model_statistics is not None
        and self.init_gm_model_statistics.ramachandran.outliers == 0
        and self.init_gm_model_statistics.omega.twisted_general <= 0.01
        and self.init_gm_model_statistics.omega.twisted_proline <= 0.01
        and self.init_gm_model_statistics.omega.cis_general <= 0.01
        and self.init_gm_model_statistics.omega.cis_proline <= 0.01
        and self.init_gm_model_statistics.rotamer.outliers <= 0.01):
      print >> self.log, "Simple minimization was enough"
      # Early exit!!!
      self.shift_and_write_result(
          model=self.model,
          fname_suffix="all_idealized")
      self.final_model_statistics = self.get_statistics(self.model)
      # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_end.pdb")
      self.time_for_run = time() - t_0
      if self.params.output_pkl:
        easy_pickle.dump(
            file_name="%s.pkl" % self.params.output_prefix,
            obj = self.get_stats_obj())
      return

    self.filtered_whole_ann = None
    if self.ann is not None:
      self.filtered_whole_ann = self.ann.deep_copy()
      print >> self.log, "Original SS annotation"
      print >> self.log, self.ann.as_pdb_str()
      if self.params.filter_input_ss:
        self.filtered_whole_ann = self.ann.filter_annotation(
            hierarchy=self.model.get_hierarchy(),
            asc=self.model.get_atom_selection_cache())
      print >> self.log, "Filtered SS annotation"
      print >> self.log, self.filtered_whole_ann.as_pdb_str()
      self.model.set_ss_annotation(self.filtered_whole_ann)

    # getting grm with SS restraints
    self.update_ss_in_grm(self.filtered_whole_ann)

    if (self.ann is None or
        self.ann.get_n_helices() + self.ann.get_n_sheets() == 0 or
        not self.params.ss_idealization.enabled):
      print >> self.log, "No secondary structure annotations found or SS idealization is disabled."
      print >> self.log, "Secondary structure substitution step will be skipped"
      self.log.flush()
      # here we want to do geometry minimization anyway!
      negate_selection = None
      if self.reference_map is None:
        outlier_selection_txt = mmtbx.building.loop_closure.utils. \
          rama_score_selection(self.model, self.model.get_ramachandran_manager(), "outlier",1)
        print >> self.log, "outlier_selection_txt", outlier_selection_txt
        negate_selection = "all"
        if outlier_selection_txt != "" and outlier_selection_txt is not None:
          negate_selection = "not (%s)" % outlier_selection_txt
      # if self.params.run_minimization_first:
      # self.minimize(
      #     model=self.model,
      #     original_pdb_h=self.whole_pdb_h,
      #     ncs_restraints_group_list=self.filtered_ncs_restr_group_list,
      #     excl_string_selection=negate_selection,
      #     reference_map=self.reference_map)
      # self.original_boxed_hierarchy.write_pdb_file(file_name="original_boxed_h_1.pdb")
    else:
      if self.params.debug:
        self.params.ss_idealization.file_name_before_regularization = \
            "%s_ss_before_reg.pdb" % self.params.output_prefix
      self.params.ss_idealization.skip_good_ss_elements = True
      ssb.substitute_ss(
          model = self.model,
          params=self.params.ss_idealization,
          verbose=self.params.verbose,
          reference_map=self.master_map,
          log=self.log)
      self.log.flush()

    self.after_ss_idealization = self.get_statistics(self.model)
    self.shift_and_write_result(
          model=self.model,
          fname_suffix="ss_ideal_stat")

    # Write resulting pdb file.
    if self.params.debug:
      self.shift_and_write_result(
          model=self.model,
          fname_suffix="ss_ideal",
          )
    # self.params.loop_idealization.minimize_whole = not self.model.ncs_constraints_present() and self.params.loop_idealization.minimize_whole
    self.params.loop_idealization.debug = self.params.debug or self.params.loop_idealization.debug
    # self.params.loop_idealization.enabled = False
    # self.params.loop_idealization.variant_search_level = 0
    print >> self.log, "Starting loop idealization"
    loop_ideal = loop_idealization(
        self.model,
        params=self.params.loop_idealization,
        reference_map=self.master_map,
        log=self.log,
        verbose=True)
    self.log.flush()
    if self.params.debug:
      self.shift_and_write_result(
          model = self.model,
          fname_suffix="rama_ideal")
    self.after_loop_idealization = self.get_statistics(self.model)

    # fixing remaining rotamer outliers
    if (self.params.additionally_fix_rotamer_outliers and
        self.after_loop_idealization.rotamer.outliers > 0.004):

      print >> self.log, "Fixing rotamers..."
      self.log.flush()
      if self.params.debug:
        self.shift_and_write_result(
          model = self.model,
          fname_suffix="just_before_rota")
      # run reduce
      assert (libtbx.env.has_module(name="reduce"))

      input_str = self.model.model_as_pdb(do_not_shift_back=True)
      build = "phenix.reduce" + " -quiet -build -allalt -NUC -"
      output = easy_run.fully_buffered(build,
                                   stdin_lines=input_str)
      p = mmtbx.model.manager.get_default_pdb_interpretation_params()
      p.pdb_interpretation.use_neutron_distances=True
      p.pdb_interpretation.ncs_search = self.params_for_model.pdb_interpretation.ncs_search
      p.pdb_interpretation.ncs_search.exclude_selection="water"
      h_input = iotbx.pdb.input(lines=output.stdout_lines, source_info=None)
      h_model = mmtbx.model.manager(model_input = h_input,
          process_input=True,
          restraint_objects=self.model._restraint_objects,
          pdb_interpretation_params=p)
      sel = h_model.get_hd_selection()
      h_model.setup_ncs_constraints_groups(filter_groups=True)
      h_model._update_master_sel()

      result = mmtbx.refinement.real_space.fit_residues.run(
          vdw_radii         = h_model.get_vdw_radii(),
          bselection        = h_model.get_master_selection(),
          pdb_hierarchy     = h_model.get_hierarchy(),
          crystal_symmetry  = self.model.crystal_symmetry(),
          map_data          = self.master_map,
          rotamer_manager   = mmtbx.idealized_aa_residues.rotamer_manager.load(),
          sin_cos_table     = scitbx.math.sin_cos_table(n=10000),
          backbone_sample   = False,
          mon_lib_srv       = h_model.get_mon_lib_srv(),
          log               = self.log)
      self.model.set_sites_cart(
          sites_cart = result.pdb_hierarchy.select(~sel).atoms().extract_xyz(),
          update_grm = True)
      self.model.set_sites_cart_from_hierarchy(multiply_ncs=True)
    if self.params.debug:
      self.shift_and_write_result(
          model = self.model,
          fname_suffix="rota_ideal")

    self.after_rotamer_fixing = self.get_statistics(self.model)
    ref_hierarchy_for_final_gm = self.original_boxed_hierarchy
    if not self.params.use_starting_model_for_final_gm:
      ref_hierarchy_for_final_gm = self.model.get_hierarchy().deep_copy()
    ref_hierarchy_for_final_gm.reset_atom_i_seqs()

    if self.model.ncs_constraints_present():
      print >> self.log, "Using ncs"
      # assert 0
    else:
      print >> self.log, "Not using ncs"
      # assert 0

    # need to update SS manager for the whole model here.
    if self.params.use_ss_restraints:
      ss_params = sec_str_master_phil.fetch().extract()
      ss_params.secondary_structure.protein.remove_outliers = not self.params.ss_idealization.enabled
      self.set_ss_restraints(
          ss_annotation=self.filtered_whole_ann,
          params=ss_params.secondary_structure)
    if self.params.run_minimization_last:
      print >> self.log, "loop_ideal.ref_exclusion_selection", loop_ideal.ref_exclusion_selection
      print >> self.log, "Minimizing whole model"
      self.minimize(
          model = self.model,
          original_pdb_h=ref_hierarchy_for_final_gm,
          excl_string_selection=loop_ideal.ref_exclusion_selection,
          reference_map = self.reference_map)
    self.shift_and_write_result(
        model = self.model,
        fname_suffix="all_idealized")
    self.final_model_statistics = self.get_statistics(self.model)
    self.time_for_run = time() - t_0
    if self.params.output_pkl or self.params.debug:
      easy_pickle.dump(
          file_name="%s.pkl" % self.params.output_prefix,
          obj = self.get_stats_obj())