Exemplo n.º 1
0
def split_models (hierarchy,
                  crystal_symmetry,
                  output_base,
                  original_file=None,
                  log=None) :
  if (log is None) : log = null_out()
  import iotbx.pdb.hierarchy
  n_models = len(hierarchy.models())
  file_names = []
  for k, model in enumerate(hierarchy.models()) :
    k += 1
    new_hierarchy = iotbx.pdb.hierarchy.root()
    new_hierarchy.append_model(model.detached_copy())
    if (model.id == "") :
      model_id = str(k)
    else :
      model_id = model.id.strip()
    output_file = "%s_%s.pdb" % (output_base, model_id)
    f = open(output_file, "w")
    if (crystal_symmetry is not None) :
      print >> f, iotbx.pdb.format_cryst1_and_scale_records(
        crystal_symmetry=crystal_symmetry,
        write_scale_records=True)
    print >> f, "REMARK Model %d of %d" % (k, n_models)
    if (original_file is not None) :
      print >> f, "REMARK Original file:"
      print >> f, "REMARK   %s" % original_file
    f.write(new_hierarchy.as_pdb_string())
    f.close()
    file_names.append(output_file)
    print >> log, "Wrote %s" % output_file
  return file_names
Exemplo n.º 2
0
def split_models(hierarchy,
                 crystal_symmetry,
                 output_base,
                 original_file=None,
                 log=None):
    if (log is None): log = null_out()
    import iotbx.pdb.hierarchy
    n_models = len(hierarchy.models())
    file_names = []
    for k, model in enumerate(hierarchy.models()):
        k += 1
        new_hierarchy = iotbx.pdb.hierarchy.root()
        new_hierarchy.append_model(model.detached_copy())
        if (model.id == ""):
            model_id = str(k)
        else:
            model_id = model.id.strip()
        output_file = "%s_%s.pdb" % (output_base, model_id)
        f = open(output_file, "w")
        if (crystal_symmetry is not None):
            print >> f, iotbx.pdb.format_cryst1_and_scale_records(
                crystal_symmetry=crystal_symmetry, write_scale_records=True)
        print >> f, "REMARK Model %d of %d" % (k, n_models)
        if (original_file is not None):
            print >> f, "REMARK Original file:"
            print >> f, "REMARK   %s" % original_file
        f.write(new_hierarchy.as_pdb_string())
        f.close()
        file_names.append(output_file)
        print >> log, "Wrote %s" % output_file
    return file_names
Exemplo n.º 3
0
 def add_structure(self, filename):
   pdb = iotbx.pdb.hierarchy.input(file_name=filename)
   hierarchy = pdb.hierarchy
   structure_name = os.path.basename(filename).strip(".pdb").strip()
   # We're using the "third view" of the PDB hierarchy here; 
   # see cctbx_project/iotbx/examples/pdb_hierarchy.py for what that means.
   # We're doing this basically because we want a complete conformation for 
   # every residue, which most pressingly means we want e.g. ' '+'A' for cases 
   # where the backbone is alt ' ' but the sidechain has alts 'A' and 'B'.
   # The "first view" is bad here because it gives separate pieces 
   # of each residue in ' ', 'A', and 'B'.
   # The "second view" is bad because it gives an entire structure for each 
   # alt conf, so even single-conformer residues get multiple appearances.
   for m, model in enumerate(hierarchy.models()):
     for chain in model.chains():
       for residue_group in chain.residue_groups():
         resseq = residue_group.resseq_as_int()
         icode = residue_group.icode
         for residue_conformer in residue_group.conformers():
           residue = residue_conformer.only_residue()
           resname = residue.resname
           if resname not in aa_resnames: continue
           cnit = (chain.id, resseq, icode, resname)
           if cnit in self.conf_ensems:
             conf_ensem = self.conf_ensems[cnit]
           else:
             conf_ensem = ConformerEnsemble(chain.id, resseq, icode, resname)
             self.conf_ensems[cnit] = conf_ensem
           assert conf_ensem is not None
           if resname in ["GLY", "ALA"]:
             chis = None
             value = None
             rotamer = "n/a"
           else:
             chis = sc_angles_measurer.measureChiAngles(residue)
             if None in chis: # probably some missing atoms because disordered
               continue # go to next atom_group
             else:
               value = rotamer_scorer.evaluate(resname, chis)
               rotamer = rotamer_scorer.evaluate_residue(residue)
           if rotamer is None:
             rotamer = "(disordered?)"
           altloc = None
           if len(residue_group.conformers()) > 1:
             altloc = residue_conformer.altloc
           modelnum=None
           if len(hierarchy.models()) > 1:
             modelnum = m+1
           conformer = Conformer(structure_name, chain.id, resseq, icode, 
             resname, chis, value, rotamer, a=altloc, m=modelnum)
           conf_ensem.add(conformer)
Exemplo n.º 4
0
def print_hier_atoms(hierarchy):
    """
    Basic printing of an iotbx.pdb.hierarchy

    :param hierarchy: 
    :return: 
    """

    for model in hierarchy.models():
        print("Model: {}".format(model.id))

        for chain in model.chains():
            print("Chain: {}".format(chain.id))

            for residue_group in chain.residue_groups():
                print("Residue: {}".format(residue_group.resseq))

                for atom_group in residue_group.atom_groups():
                    print("Altloc: {}".format(atom_group.altloc))

                    for atom in atom_group.atoms():
                        print("Atom Name: {}".format(atom.name))

    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Exemplo n.º 5
0
def exercise_synthetic () :
  from mmtbx.regression import tst_build_alt_confs
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=tst_build_alt_confs.pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  fc = abs(xrs.structure_factors(d_min=1.5).f_calc())
  flags = fc.resolution_filter(d_min=1.6).generate_r_free_flags()
  ls = fc.lone_set(other=flags)
  # case 1: no work set in high-res shell
  flags2 = ls.array(data=flex.bool(ls.size(), True))
  flags_all = flags.concatenate(other=flags2)
  mtz_out = fc.as_mtz_dataset(column_root_label="F")
  mtz_out.add_miller_array(flags_all, column_root_label="FreeR_flag")
  mtz_out.mtz_object().write("tst_molprobity_1.mtz")
  open("tst_molprobity_1.pdb", "w").write(tst_build_alt_confs.pdb_raw)
  args = [
    "tst_molprobity_1.pdb",
    "tst_molprobity_1.mtz",
    "--kinemage",
    "--maps",
    "flags.clashscore=False",
    "flags.xtriage=True",
  ]
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # case 2: no test set in high-res shell
  flags2 = ls.array(data=flex.bool(ls.size(), False))
  flags_all = flags.concatenate(other=flags2)
  mtz_out = fc.as_mtz_dataset(column_root_label="F")
  mtz_out.add_miller_array(flags_all, column_root_label="FreeR_flag")
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # case 3: multi-MODEL structure
  # XXX This is not a very sophisticated test - it only ensures that the
  # program does not crash.  We need a test for expected output...
  hierarchy = pdb_in.hierarchy
  model2 = hierarchy.only_model().detached_copy()
  hierarchy.append_model(model2)
  hierarchy.models()[0].id = "1"
  hierarchy.models()[1].id = "2"
  open("tst_molprobity_multi_model.pdb", "w").write(hierarchy.as_pdb_string())
  args = [
    "tst_molprobity_multi_model.pdb",
    "tst_molprobity_1.mtz",
    "--kinemage",
    "--maps",
    "flags.clashscore=False",
  ]
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # test rotamer distributions
  open("tst_molprobity_misc1.pdb", "w").write(tst_build_alt_confs.pdb_raw)
  args = [
    "tst_molprobity_1.pdb",
    "rotamer_library=8000",
    "outliers_only=False",
    "flags.clashscore=False",
  ]
  out = StringIO()
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  result.show(outliers_only=False, out=out)
  assert ("""   A   7  TYR              m-80  93.10   299.6,92.0""" in
    out.getvalue()), out.getvalue()
Exemplo n.º 6
0
def exercise():
    pdb_str = """\
MODEL        1
ATOM      1  CA  ALA A  73      40.400   8.490  10.792  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.672   7.864  11.359  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.406   4.181  10.841  0.01 13.28           C
ENDMDL
MODEL        2
ATOM      1  CA  ALA A  73      40.320   8.758  11.103  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.630   7.923  11.568  0.01 13.55           C
ATOM      3  CA  LYS A  75      36.856   4.141  11.040  0.01 13.28           C
ENDMDL
MODEL        3
ATOM      1  CA  ALA A  73      40.192   9.182  11.213  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.644   7.871  11.649  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.564   4.235  11.057  0.01 13.28           C
ENDMDL
MODEL        4
ATOM      1  CA  ALA A  73      39.924   9.073  10.840  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.434   7.623  11.282  0.01 13.55           C
ATOM      3  CA  LYS A  75      38.120   4.233  11.095  0.01 13.28           C
ENDMDL
MODEL        5
ATOM      1  CA  ALA A  73      39.870   8.700  11.195  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.328   7.379  11.083  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.543   3.760  10.681  0.01 13.28           C
ENDMDL
MODEL        6
ATOM      1  CA  ALA A  73      40.236   9.111  11.122  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.653   7.850  11.378  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.252   4.117  10.669  0.01 13.28           C
ENDMDL
MODEL        7
ATOM      1  CA  ALA A  73      40.532   8.599  10.939  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.830   7.868  11.208  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.397   4.094  11.107  0.01 13.28           C
ENDMDL
MODEL        8
ATOM      1  CA  ALA A  73      40.340   9.520  11.303  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.701   8.474  11.515  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.522   4.781  11.633  0.01 13.28           C
ENDMDL
MODEL        9
ATOM      1  CA  ALA A  73      40.296   8.642  10.668  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.832   7.269  11.324  0.01 13.55           C
ATOM      3  CA  LYS A  75      38.541   3.900  11.400  0.01 13.28           C
ENDMDL
MODEL       10
ATOM      1  CA  ALA A  73      39.396   8.850  11.064  0.01 13.69           C
ATOM      2  CA  ARG A  74      35.915   7.291  10.970  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.173   3.719  10.662  0.01 13.28           C
ENDMDL
"""
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_str)
    hierarchy = pdb_in.hierarchy
    disorder.set_ensemble_b_factors_to_xyz_displacement(
        pdb_hierarchy=hierarchy, method="rmsf", log=null_out())
    model = hierarchy.models()[0]
    assert approx_equal(list(model.atoms().extract_b()),
                        [0.480574, 0.478505, 0.616683])
    disorder.set_ensemble_b_factors_to_xyz_displacement(
        pdb_hierarchy=hierarchy, method="mcs", log=null_out())
    model = hierarchy.models()[0]
    assert approx_equal(list(model.atoms().extract_b()),
                        [0.684434, 0.779022, 0.881886])
Exemplo n.º 7
0
def exercise_synthetic () :
  from mmtbx.regression import tst_build_alt_confs
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=tst_build_alt_confs.pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  fc = abs(xrs.structure_factors(d_min=1.5).f_calc())
  flags = fc.resolution_filter(d_min=1.6).generate_r_free_flags()
  ls = fc.lone_set(other=flags)
  # case 1: no work set in high-res shell
  flags2 = ls.array(data=flex.bool(ls.size(), True))
  flags_all = flags.concatenate(other=flags2)
  mtz_out = fc.as_mtz_dataset(column_root_label="F")
  mtz_out.add_miller_array(flags_all, column_root_label="FreeR_flag")
  mtz_out.mtz_object().write("tst_molprobity_1.mtz")
  open("tst_molprobity_1.pdb", "w").write(tst_build_alt_confs.pdb_raw)
  args = [
    "tst_molprobity_1.pdb",
    "tst_molprobity_1.mtz",
    "--kinemage",
    "--maps",
    "flags.clashscore=False",
    "flags.xtriage=True",
  ]
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # case 2: no test set in high-res shell
  flags2 = ls.array(data=flex.bool(ls.size(), False))
  flags_all = flags.concatenate(other=flags2)
  mtz_out = fc.as_mtz_dataset(column_root_label="F")
  mtz_out.add_miller_array(flags_all, column_root_label="FreeR_flag")
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # case 3: multi-MODEL structure
  # XXX This is not a very sophisticated test - it only ensures that the
  # program does not crash.  We need a test for expected output...
  hierarchy = pdb_in.hierarchy
  model2 = hierarchy.only_model().detached_copy()
  hierarchy.append_model(model2)
  hierarchy.models()[0].id = "1"
  hierarchy.models()[1].id = "2"
  open("tst_molprobity_multi_model.pdb", "w").write(hierarchy.as_pdb_string())
  args = [
    "tst_molprobity_multi_model.pdb",
    "tst_molprobity_1.mtz",
    "--kinemage",
    "--maps",
  ]
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  out = StringIO()
  result.show(out=out)
  # test rotamer distributions
  open("tst_molprobity_misc1.pdb", "w").write(tst_build_alt_confs.pdb_raw)
  args = [
    "tst_molprobity_1.pdb",
    "rotamer_library=8000",
  ]
  out = StringIO()
  result = molprobity.run(args=args,
    ignore_missing_modules=True,
    out=null_out()).validation
  result.show(outliers_only=False, out=out)
Exemplo n.º 8
0
def exercise () :
  pdb_str = """\
MODEL        1
ATOM      1  CA  ALA A  73      40.400   8.490  10.792  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.672   7.864  11.359  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.406   4.181  10.841  0.01 13.28           C
ENDMDL
MODEL        2
ATOM      1  CA  ALA A  73      40.320   8.758  11.103  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.630   7.923  11.568  0.01 13.55           C
ATOM      3  CA  LYS A  75      36.856   4.141  11.040  0.01 13.28           C
ENDMDL
MODEL        3
ATOM      1  CA  ALA A  73      40.192   9.182  11.213  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.644   7.871  11.649  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.564   4.235  11.057  0.01 13.28           C
ENDMDL
MODEL        4
ATOM      1  CA  ALA A  73      39.924   9.073  10.840  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.434   7.623  11.282  0.01 13.55           C
ATOM      3  CA  LYS A  75      38.120   4.233  11.095  0.01 13.28           C
ENDMDL
MODEL        5
ATOM      1  CA  ALA A  73      39.870   8.700  11.195  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.328   7.379  11.083  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.543   3.760  10.681  0.01 13.28           C
ENDMDL
MODEL        6
ATOM      1  CA  ALA A  73      40.236   9.111  11.122  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.653   7.850  11.378  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.252   4.117  10.669  0.01 13.28           C
ENDMDL
MODEL        7
ATOM      1  CA  ALA A  73      40.532   8.599  10.939  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.830   7.868  11.208  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.397   4.094  11.107  0.01 13.28           C
ENDMDL
MODEL        8
ATOM      1  CA  ALA A  73      40.340   9.520  11.303  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.701   8.474  11.515  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.522   4.781  11.633  0.01 13.28           C
ENDMDL
MODEL        9
ATOM      1  CA  ALA A  73      40.296   8.642  10.668  0.01 13.69           C
ATOM      2  CA  ARG A  74      36.832   7.269  11.324  0.01 13.55           C
ATOM      3  CA  LYS A  75      38.541   3.900  11.400  0.01 13.28           C
ENDMDL
MODEL       10
ATOM      1  CA  ALA A  73      39.396   8.850  11.064  0.01 13.69           C
ATOM      2  CA  ARG A  74      35.915   7.291  10.970  0.01 13.55           C
ATOM      3  CA  LYS A  75      37.173   3.719  10.662  0.01 13.28           C
ENDMDL
"""
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_str)
  hierarchy = pdb_in.hierarchy
  disorder.set_ensemble_b_factors_to_xyz_displacement(
    pdb_hierarchy=hierarchy,
    method="rmsf",
    log=null_out())
  model = hierarchy.models()[0]
  assert approx_equal(list(model.atoms().extract_b()),
    [0.480574, 0.478505, 0.616683])
  disorder.set_ensemble_b_factors_to_xyz_displacement(
    pdb_hierarchy=hierarchy,
    method="mcs",
    log=null_out())
  model = hierarchy.models()[0]
  assert approx_equal(list(model.atoms().extract_b()),
    [0.684434, 0.779022, 0.881886])