예제 #1
0
def exercise_clashscore():
    if (not libtbx.env.has_module(name="probe")):
        print "Skipping exercise_clashscore(): probe not configured"
        return

    pdb_io = pdb.input(source_info=None, lines=pdb_str_1)
    pdb_hierarchy = pdb_io.construct_hierarchy()
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               out=null_out())
    for unpickle in [False, True]:
        if unpickle:
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 35.29, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.048',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.768',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720'
        ]), [c.format_old() for c in bad_clashes_list]

    #test nuclear distances
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               nuclear=True)
    for unpickle in [False, True]:
        if (unpickle):
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 58.82, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.085',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.793',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720',
            ' A  72  ARG  HD3  A  72  ARG HH11 :0.669',
            ' A  72  ARG  HB3  A  72  ARG  HE  :0.647'
        ]), [c.format_old() for c in bad_clashes_list]

    #test B factor cutoff
    cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy,
                               fast=False,
                               condensed_probe=True,
                               b_factor_cutoff=40)
    for unpickle in [False, True]:
        if (unpickle):
            cs = loads(dumps(cs))
        c_score = cs.get_clashscore()
        assert approx_equal(c_score, 35.29, eps=0.01)
        c_score_b_cutoff = cs.get_clashscore_b_cutoff()
        assert approx_equal(c_score_b_cutoff, 39.47, eps=0.01)
        bad_clashes_list = cs.results
        assert ([c.format_old() for c in bad_clashes_list] == [
            ' A  72  ARG  HG2  A  72  ARG  O   :1.048',
            ' A  71  LEU  HA   A  71  LEU HD12 :0.768',
            ' A  72  ARG  CG   A  72  ARG  O   :0.720'
        ]), [c.format_old() for c in bad_clashes_list]
예제 #2
0
def exercise () :
  from mmtbx.regression.make_fake_anomalous_data import generate_calcium_inputs
  from mmtbx.command_line import find_peaks_holes
  mtz_file, pdb_file = generate_calcium_inputs(
    file_base = "tst_find_peaks_holes", anonymize = True)
  out = StringIO()
  peaks_holes = find_peaks_holes.run(
    args=[pdb_file, mtz_file],
    out=out)
  peaks_holes.save_pdb_file(file_name="tst_fph_peaks.pdb", log=null_out())
  p = easy_pickle.dumps(peaks_holes)
  s = peaks_holes.get_summary()
  sp = easy_pickle.dumps(s)
  out2 = StringIO()
  s.show(out=out2)
  lines = out2.getvalue().splitlines()
  assert ("""  anomalous H2O (anomalous > 3):      1""" in lines)
  assert ("""  anomalous non-water atoms:          0""" in lines)
  assert ("""  mFo-DFc >  9:                       0""" in lines)
  peaks_holes = find_peaks_holes.run(
    args=[pdb_file, mtz_file, "filter_peaks_by_2fofc=1.0"],
    out=null_out())
  out3 = StringIO()
  peaks_holes.get_summary().show(out=out3)
  lines = out3.getvalue().splitlines()
  assert ("""  anomalous > 3:                      0""" in lines)
  out3 = StringIO()
  peaks_holes = find_peaks_holes.run(
    args=[pdb_file, mtz_file, "include_peaks_near_model=True",],
    out=out3)
  lines = out3.getvalue().splitlines()
  assert ("""  mFo-DFc >  9:                       1""" in lines)
  os.remove(mtz_file)
  os.remove(pdb_file)
예제 #3
0
def exercise_clashscore ():
  if (not libtbx.env.has_module(name="probe")):
    print "Skipping exercise_clashscore(): probe not configured"
    return

  pdb_io = pdb.input(source_info=None, lines=pdb_str_1)
  pdb_hierarchy = pdb_io.construct_hierarchy()
  cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy, out=null_out())
  for unpickle in [False, True] :
    if (unpickle) :
      cs = loads(dumps(cs))
    c_score = cs.get_clashscore()
    assert approx_equal(c_score, 35.29, eps=0.01)
    bad_clashes_list = cs.results
    assert ([ c.format_old() for c in bad_clashes_list ] ==
      [' A  72  ARG  HG2  A  72  ARG  O   :-1.038',
       ' A  72  ARG  CG   A  72  ARG  O   :-0.465',
       ' A  71  LEU  HA   A  71  LEU HD12 :-0.446'])

  #test nuclear distances
  cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy, nuclear=True)
  for unpickle in [False, True] :
    if (unpickle) :
      cs = loads(dumps(cs))
    c_score = cs.get_clashscore()
    assert approx_equal(c_score, 58.82, eps=0.01)
    bad_clashes_list = cs.results
    assert ([ c.format_old() for c in bad_clashes_list ] ==
      [ ' A  72  ARG  HG2  A  72  ARG  O   :-1.082',
        ' A  72  ARG  CG   A  72  ARG  O   :-0.622',
        ' A  71  LEU  HA   A  71  LEU HD12 :-0.535',
        ' A  72  ARG  HB3  A  72  ARG  HE  :-0.475',
        ' A  72  ARG  HD3  A  72  ARG HH11 :-0.451'])

  #test B factor cutoff
  cs = clashscore.clashscore(pdb_hierarchy=pdb_hierarchy, b_factor_cutoff=40)
  for unpickle in [False, True] :
    if (unpickle) :
      cs = loads(dumps(cs))
    c_score = cs.get_clashscore()
    assert approx_equal(c_score, 35.29, eps=0.01)
    c_score_b_cutoff = cs.get_clashscore_b_cutoff()
    assert approx_equal(c_score_b_cutoff, 39.47, eps=0.01)
    bad_clashes_list = cs.results
    assert ([ c.format_old() for c in bad_clashes_list ] ==
      [' A  72  ARG  HG2  A  72  ARG  O   :-1.038',
       ' A  72  ARG  CG   A  72  ARG  O   :-0.465',
       ' A  71  LEU  HA   A  71  LEU HD12 :-0.446'])
예제 #4
0
def exercise_heavy () :
  from mmtbx.regression import make_fake_anomalous_data
  from mmtbx.command_line import validate_waters
  import mmtbx.ions.utils
  from iotbx.file_reader import any_file
  file_base = "tst_validate_waters_1"
  pdb_file = make_fake_anomalous_data.write_pdb_input_cd_cl(file_base=file_base)
  mtz_file = make_fake_anomalous_data.generate_mtz_file(
    file_base="tst_validate_waters_1",
    d_min=1.5,
    anomalous_scatterers=[
      group_args(selection="element CD", fp=-0.29, fdp=2.676),
      group_args(selection="element CL", fp=0.256, fdp=0.5),
    ])
  pdb_in = any_file(pdb_file)
  hierarchy = pdb_in.file_object.hierarchy
  hierarchy, n = mmtbx.ions.utils.anonymize_ions(hierarchy, log=null_out())
  hierarchy.write_pdb_file("%s_start.pdb" % file_base,
    crystal_symmetry=pdb_in.file_object.crystal_symmetry())
  args = ["tst_validate_waters_1_start.pdb", "tst_validate_waters_1.mtz",
    "skip_twin_detection=True"]
  results = validate_waters.run(args=args, out=null_out())
  out = StringIO()
  results.show(out=out)
  s = easy_pickle.dumps(results)
  r2 = easy_pickle.loads(s)
  out2 = StringIO()
  r2.show(out=out2)
  assert not show_diff(out.getvalue(), out2.getvalue())
  assert (results.n_bad >= 1) and (results.n_heavy == 2)
예제 #5
0
def exercise () :
  for module in ["reduce", "probe", "phenix_regression"] :
    if (not libtbx.env.has_module(module)) :
      print "%s not available, skipping" % module
      return
  from mmtbx.command_line import validation_summary
  from iotbx import file_reader
  import iotbx.pdb.hierarchy
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb1jxt.ent",
    test=os.path.isfile)
  out = StringIO()
  summary = validation_summary.run(args=[regression_pdb], out=out)
  assert approx_equal(summary.clashscore, 13.597, eps=0.001), "clashscore %s is not 13.597(0.0001)" % summary.clashscore
  ss = easy_pickle.dumps(summary)
  sss = easy_pickle.loads(ss)
  out_1 = StringIO()
  out_2 = StringIO()
  summary.show(out=out_1)
  sss.show(out=out_2)
  assert out_1.getvalue() == out_2.getvalue()
  pdb_in = file_reader.any_file(regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  new_hierarchy = iotbx.pdb.hierarchy.root()
  for i in range(5) :
    model = hierarchy.only_model().detached_copy()
    model.id = str(i+1)
    new_hierarchy.append_model(model)
  open("tst_validation_summary.pdb", "w").write(new_hierarchy.as_pdb_string())
  out2 = StringIO()
  summary = validation_summary.run(args=["tst_validation_summary.pdb"],
    out=out2)
  assert (type(summary).__name__ == 'ensemble')
  print "OK"
예제 #6
0
def exercise_heavy():
    from mmtbx.regression import make_fake_anomalous_data
    from mmtbx.command_line import validate_waters
    import mmtbx.ions.utils
    from iotbx.file_reader import any_file
    file_base = "tst_validate_waters_1"
    pdb_file = make_fake_anomalous_data.write_pdb_input_cd_cl(
        file_base=file_base)
    mtz_file = make_fake_anomalous_data.generate_mtz_file(
        file_base="tst_validate_waters_1",
        d_min=1.5,
        anomalous_scatterers=[
            group_args(selection="element CD", fp=-0.29, fdp=2.676),
            group_args(selection="element CL", fp=0.256, fdp=0.5),
        ])
    pdb_in = any_file(pdb_file)
    hierarchy = pdb_in.file_object.hierarchy
    hierarchy, n = mmtbx.ions.utils.anonymize_ions(hierarchy, log=null_out())
    hierarchy.write_pdb_file(
        "%s_start.pdb" % file_base,
        crystal_symmetry=pdb_in.file_object.crystal_symmetry())
    args = [
        "tst_validate_waters_1_start.pdb", "tst_validate_waters_1.mtz",
        "skip_twin_detection=True"
    ]
    results = validate_waters.run(args=args, out=null_out())
    out = StringIO()
    results.show(out=out)
    s = easy_pickle.dumps(results)
    r2 = easy_pickle.loads(s)
    out2 = StringIO()
    r2.show(out=out2)
    assert not show_diff(out.getvalue(), out2.getvalue())
    assert (results.n_bad >= 1) and (results.n_heavy == 2)
def exercise():
    for module in ["reduce", "probe", "phenix_regression"]:
        if not libtbx.env.has_module(module):
            print "%s not available, skipping" % module
            return
    from mmtbx.command_line import validation_summary
    from iotbx import file_reader
    import iotbx.pdb.hierarchy

    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile
    )
    out = StringIO()
    summary = validation_summary.run(args=[regression_pdb], out=out)
    assert approx_equal(summary.clashscore, 13.597, eps=0.0001)
    ss = easy_pickle.dumps(summary)
    sss = easy_pickle.loads(ss)
    out_1 = StringIO()
    out_2 = StringIO()
    summary.show(out=out_1)
    sss.show(out=out_2)
    assert out_1.getvalue() == out_2.getvalue()
    pdb_in = file_reader.any_file(regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    new_hierarchy = iotbx.pdb.hierarchy.root()
    for i in range(5):
        model = hierarchy.only_model().detached_copy()
        model.id = str(i + 1)
        new_hierarchy.append_model(model)
    open("tst_validation_summary.pdb", "w").write(new_hierarchy.as_pdb_string())
    out2 = StringIO()
    summary = validation_summary.run(args=["tst_validation_summary.pdb"], out=out2)
    assert type(summary).__name__ == "ensemble"
    print "OK"
예제 #8
0
def pickle_unpickle(result):
    result2 = loads(dumps(result))
    out1 = StringIO()
    out2 = StringIO()
    result.show(out=out1)
    result2.show(out=out2)
    assert (out1.getvalue() == out2.getvalue())
예제 #9
0
def pickle_unpickle (result) :
  result2 = loads(dumps(result))
  out1 = StringIO()
  out2 = StringIO()
  result.show(out=out1)
  result2.show(out=out2)
  assert (out1.getvalue() == out2.getvalue())
예제 #10
0
def test_pickle_consistency_and_size(result):
    all_out = StringIO()
    result.show(out=all_out)
    result_pkl_str = dumps(result)
    pkl_size = len(result_pkl_str)
    if (pkl_size >= 100000):
        print("Oversized pickle:", pkl_size)
        show_pickled_object_sizes(result)
        raise OverflowError()
    assert (pkl_size < 100000), pkl_size  # limit pickle size
    result_pkl = loads(result_pkl_str)
    all_out_pkl = StringIO()
    result_pkl.show(out=all_out_pkl)
    assert not show_diff(all_out.getvalue(), all_out_pkl.getvalue())
예제 #11
0
def test_pickle_consistency_and_size (result) :
  all_out = StringIO()
  result.show(out=all_out)
  result_pkl_str = dumps(result)
  pkl_size = len(result_pkl_str)
  if (pkl_size >= 100000) :
    print "Oversized pickle:", pkl_size
    show_pickled_object_sizes(result)
    raise OverflowError()
  assert (pkl_size < 100000), pkl_size # limit pickle size
  result_pkl = loads(result_pkl_str)
  all_out_pkl = StringIO()
  result_pkl.show(out=all_out_pkl)
  assert not show_diff(all_out.getvalue(), all_out_pkl.getvalue())
예제 #12
0
def exercise(n, use_dumps=False):
  from libtbx import easy_pickle
  import time
  obj = []
  for i in range(n):
    obj.append([i,i])
  for dgz in ["", ".gz"]:
    t0 = time.time()
    if (use_dumps):
      print("dumps/loads")
      pickle_string = easy_pickle.dumps(obj=obj)
    else:
      file_name = "test.dat"+dgz
      print(file_name)
      easy_pickle.dump(file_name=file_name, obj=obj)
    print("  dump: %.2f s" % (time.time()-t0))
    del obj
    t0 = time.time()
    if (use_dumps):
      obj = easy_pickle.loads(pickle_string)
    else:
      obj = easy_pickle.load(file_name=file_name)
    print("  load buffered: %.2f s" % (time.time()-t0))
    if (use_dumps):
      break
    else:
      del obj
      t0 = time.time()
      obj = easy_pickle.load(
        file_name=file_name, faster_but_using_more_memory=False)
      print("  load direct: %.2f s" % (time.time()-t0))
  # XXX pickling and unpickling of libtbx.Auto
  # couldn't think of a better place to test this...
  from libtbx import Auto
  a = easy_pickle.dumps(Auto)
  b = easy_pickle.loads(a)
  assert (b is Auto) and (b == Auto)
예제 #13
0
def exercise(n, use_dumps=False):
  from libtbx import easy_pickle
  import time
  obj = []
  for i in xrange(n):
    obj.append([i,i])
  for dgz in ["", ".gz"]:
    t0 = time.time()
    if (use_dumps):
      print "dumps/loads"
      pickle_string = easy_pickle.dumps(obj=obj)
    else:
      file_name = "test.dat"+dgz
      print file_name
      easy_pickle.dump(file_name=file_name, obj=obj)
    print "  dump: %.2f s" % (time.time()-t0)
    del obj
    t0 = time.time()
    if (use_dumps):
      obj = easy_pickle.loads(pickle_string)
    else:
      obj = easy_pickle.load(file_name=file_name)
    print "  load buffered: %.2f s" % (time.time()-t0)
    if (use_dumps):
      break
    else:
      del obj
      t0 = time.time()
      obj = easy_pickle.load(
        file_name=file_name, faster_but_using_more_memory=False)
      print "  load direct: %.2f s" % (time.time()-t0)
  # XXX pickling and unpickling of libtbx.Auto
  # couldn't think of a better place to test this...
  from libtbx import Auto
  a = easy_pickle.dumps(Auto)
  b = easy_pickle.loads(a)
  assert (b is Auto) and (b == Auto)
예제 #14
0
def exercise_rna () :
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb2goz_refmac_tls.ent",
    test=op.isfile)
  if (regression_pdb is None):
    print "Skipping exercise_regression(): input pdb (pdb2goz_refmac_tls.ent) not available"
    return
  result = molprobity.run(args=[regression_pdb], out=null_out()).validation
  assert (result.rna is not None)
  out = StringIO()
  result.show(out=out)
  assert ("2/58 pucker outliers present" in out.getvalue())
  result = loads(dumps(result))
  out2 = StringIO()
  result.show(out=out2)
  assert (out2.getvalue() == out.getvalue())
def exercise_rna():
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb2goz_refmac_tls.ent",
        test=op.isfile)
    if (regression_pdb is None):
        print "Skipping exercise_regression(): input pdb (pdb2goz_refmac_tls.ent) not available"
        return
    result = molprobity.run(args=[regression_pdb], out=null_out()).validation
    assert (result.rna is not None)
    out = StringIO()
    result.show(out=out)
    assert ("2/58 pucker outliers present" in out.getvalue())
    result = loads(dumps(result))
    out2 = StringIO()
    result.show(out=out2)
    assert (out2.getvalue() == out.getvalue())
예제 #16
0
def exercise_cbetadev():
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile)
    if (regression_pdb is None):
        print "Skipping exercise_cbetadev(): input pdb (pdb1jxt.ent) not available"
        return
    from mmtbx.validation import cbetadev
    from iotbx import file_reader
    pdb_in = file_reader.any_file(file_name=regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    validation = cbetadev.cbetadev(pdb_hierarchy=hierarchy, outliers_only=True)
    assert approx_equal(validation.get_weighted_outlier_percent(),
                        4.40420846587)
    for unpickle in [False, True]:
        if unpickle:
            validation = loads(dumps(validation))
        assert (validation.n_outliers == len(validation.results) == 6)
        assert ([cb.id_str() for cb in validation.results] == [
            ' A   7 AILE', ' A   8 BVAL', ' A   8 CVAL', ' A  30 BTHR',
            ' A  39 BTHR', ' A  43 BASP'
        ])
        assert approx_equal([cb.deviation for cb in validation.results], [
            0.25977096732623106, 0.2577218834868609, 0.6405578498280606,
            0.81238828498566, 0.9239566035292618, 0.5001892640352836
        ])
        out = StringIO()
        validation.show_old_output(out=out, verbose=True)
        assert not show_diff(
            out.getvalue(), """\
pdb:alt:res:chainID:resnum:dev:dihedralNABB:Occ:ALT:
pdb :A:ile: A:   7 :  0.260: -46.47:   0.45:A:
pdb :B:val: A:   8 :  0.258:  80.92:   0.30:B:
pdb :C:val: A:   8 :  0.641: -53.98:   0.20:C:
pdb :B:thr: A:  30 :  0.812: -76.98:   0.30:B:
pdb :B:thr: A:  39 :  0.924:  56.41:   0.30:B:
pdb :B:asp: A:  43 :  0.500:   7.56:   0.25:B:
SUMMARY: 6 C-beta deviations >= 0.25 Angstrom (Goal: 0)
""")

    # Now with all residues
    validation = cbetadev.cbetadev(pdb_hierarchy=hierarchy,
                                   outliers_only=False)
    for unpickle in [False, True]:
        if unpickle:
            validation = loads(dumps(validation))
        for outlier in validation.results:
            assert (len(outlier.xyz) == 3)
        assert (validation.n_outliers == 6)
        assert (len(validation.results) == 51)
        out = StringIO()
        validation.show_old_output(out=out, verbose=True)
        assert not show_diff(
            out.getvalue(), """\
pdb:alt:res:chainID:resnum:dev:dihedralNABB:Occ:ALT:
pdb : :thr: A:   1 :  0.102:  11.27:   1.00: :
pdb :A:thr: A:   2 :  0.022: -49.31:   0.67:A:
pdb : :cys: A:   3 :  0.038: 103.68:   1.00: :
pdb : :cys: A:   4 :  0.047:-120.73:   1.00: :
pdb : :pro: A:   5 :  0.069:-121.41:   1.00: :
pdb : :ser: A:   6 :  0.052: 112.87:   1.00: :
pdb :A:ile: A:   7 :  0.260: -46.47:   0.45:A:
pdb :B:ile: A:   7 :  0.153: 122.97:   0.55:B:
pdb :A:val: A:   8 :  0.184:-155.36:   0.50:A:
pdb :B:val: A:   8 :  0.258:  80.92:   0.30:B:
pdb :C:val: A:   8 :  0.641: -53.98:   0.20:C:
pdb : :ala: A:   9 :  0.061: -82.84:   1.00: :
pdb :A:arg: A:  10 :  0.023: 172.25:   1.00:A:
pdb : :ser: A:  11 :  0.028:-129.11:   1.00: :
pdb :A:asn: A:  12 :  0.021: -80.80:   0.50:A:
pdb :B:asn: A:  12 :  0.199:  50.01:   0.50:B:
pdb :A:phe: A:  13 :  0.067: -37.32:   0.65:A:
pdb :B:phe: A:  13 :  0.138:  19.24:   0.35:B:
pdb : :asn: A:  14 :  0.065: -96.35:   1.00: :
pdb : :val: A:  15 :  0.138: -96.63:   1.00: :
pdb : :cys: A:  16 :  0.102: -28.64:   1.00: :
pdb : :arg: A:  17 :  0.053:-106.79:   1.00: :
pdb : :leu: A:  18 :  0.053:-141.51:   1.00: :
pdb : :pro: A:  19 :  0.065:-146.95:   1.00: :
pdb : :thr: A:  21 :  0.086:  53.80:   1.00: :
pdb :A:pro: A:  22 :  0.092: -83.39:   0.55:A:
pdb :A:glu: A:  23 :  0.014:-179.53:   0.50:A:
pdb :B:glu: A:  23 :  0.050:-179.78:   0.50:B:
pdb : :ala: A:  24 :  0.056: -88.96:   1.00: :
pdb : :leu: A:  25 :  0.084:-106.42:   1.00: :
pdb : :cys: A:  26 :  0.074: -94.70:   1.00: :
pdb : :ala: A:  27 :  0.056: -62.15:   1.00: :
pdb : :thr: A:  28 :  0.056:-114.82:   1.00: :
pdb :A:tyr: A:  29 :  0.068:   0.22:   0.65:A:
pdb :A:thr: A:  30 :  0.180: 103.27:   0.70:A:
pdb :B:thr: A:  30 :  0.812: -76.98:   0.30:B:
pdb : :cys: A:  32 :  0.029: -84.07:   1.00: :
pdb : :ile: A:  33 :  0.048:-119.17:   1.00: :
pdb : :ile: A:  34 :  0.045:  99.02:   1.00: :
pdb : :ile: A:  35 :  0.052:-128.24:   1.00: :
pdb : :pro: A:  36 :  0.084:-142.29:   1.00: :
pdb : :ala: A:  38 :  0.039:  50.01:   1.00: :
pdb :A:thr: A:  39 :  0.093: -96.63:   0.70:A:
pdb :B:thr: A:  39 :  0.924:  56.41:   0.30:B:
pdb : :cys: A:  40 :  0.013:-144.11:   1.00: :
pdb : :pro: A:  41 :  0.039: -97.09:   1.00: :
pdb :A:asp: A:  43 :  0.130:-146.91:   0.75:A:
pdb :B:asp: A:  43 :  0.500:   7.56:   0.25:B:
pdb : :tyr: A:  44 :  0.085:-143.63:   1.00: :
pdb : :ala: A:  45 :  0.055:  33.32:   1.00: :
pdb : :asn: A:  46 :  0.066: -50.46:   1.00: :
SUMMARY: 6 C-beta deviations >= 0.25 Angstrom (Goal: 0)
""")

    # Auxilary function: extract_atoms_from_residue_group
    from mmtbx.validation.cbetadev import extract_atoms_from_residue_group
    from iotbx import pdb
    pdb_1 = pdb.input(source_info=None,
                      lines="""\
ATOM   1185  N  ASER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1186  N  BSER A 146      24.758  37.100  16.337  0.50 16.79           N
ATOM   1187  CA ASER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1188  CA BSER A 146      24.237  37.427  17.662  0.50 16.87           C
ATOM   1189  C  ASER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1190  C  BSER A 146      22.792  36.945  17.783  0.50 15.94           C
ATOM   1191  O  ASER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1192  O  BSER A 146      22.091  36.741  16.779  0.50 15.17           O
ATOM   1193  CB ASER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1194  CB BSER A 146      24.321  38.940  17.904  0.50 17.48           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """
                      ).construct_hierarchy()
    pdb_2 = pdb.input(source_info=None,
                      lines="""\
ATOM   1185  N   SER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1187  CA  SER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1189  C   SER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1191  O   SER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1193  CB ASER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1194  CB BSER A 146      24.321  38.940  17.904  0.50 17.48           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """
                      ).construct_hierarchy()
    pdb_3 = pdb.input(source_info=None,
                      lines="""\
ATOM   1185  N   SER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1187  CA  SER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1189  C   SER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1191  O   SER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1193  CB  SER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """
                      ).construct_hierarchy()
    rg1 = pdb_1.only_model().only_chain().only_residue_group()
    rg2 = pdb_2.only_model().only_chain().only_residue_group()
    rg3 = pdb_3.only_model().only_chain().only_residue_group()
    all_relevant_atoms_1 = extract_atoms_from_residue_group(rg1)
    all_relevant_atoms_2 = extract_atoms_from_residue_group(rg2)
    all_relevant_atoms_3 = extract_atoms_from_residue_group(rg3)
    keys_1 = [sorted([k for k in a.keys()]) for a in all_relevant_atoms_1]
    keys_2 = [sorted([k for k in a.keys()]) for a in all_relevant_atoms_2]
    keys_3 = [sorted([k for k in a.keys()]) for a in all_relevant_atoms_3]
    assert keys_1 == [[' C  ', ' CA ', ' CB ', ' N  '],
                      [' C  ', ' CA ', ' CB ', ' N  ']]
    assert keys_2 == [[' C  ', ' CA ', ' CB ', ' N  '],
                      [' C  ', ' CA ', ' CB ', ' N  ']]
    assert keys_3 == [[' C  ', ' CA ', ' CB ', ' N  ']]
    print "OK"
예제 #17
0
def exercise_ramalyze():
    from mmtbx.rotamer.rotamer_eval import find_rotarama_data_dir
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/jcm.pdb", test=os.path.isfile)
    if (regression_pdb is None):
        print "Skipping exercise_ramalyze(): input pdb (jcm.pdb) not available"
        return
    if (find_rotarama_data_dir(optional=True) is None):
        print "Skipping exercise_ramalyze(): rotarama_data directory not available"
        return
    from iotbx import file_reader
    # Exercise 1
    pdb_in = file_reader.any_file(file_name=regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    pdb_io = pdb.input(file_name=regression_pdb)
    hierarchy.atoms().reset_i_seq()
    r = ramalyze.ramalyze(pdb_hierarchy=hierarchy, outliers_only=True)
    out = StringIO()
    r.show_old_output(out=out)
    output = out.getvalue()
    assert output.count("OUTLIER") == 100
    assert output.count("Favored") == 0
    assert output.count("Allowed") == 0
    assert output.count("General") == 64
    assert output.count("Glycine") == 6
    assert output.count("Trans-proline") == 1
    assert output.count("Cis-proline") == 0
    assert output.count("Pre-proline") == 4
    assert output.count("Isoleucine or valine") == 25
    assert (len(r.outlier_selection()) == 494)
    outlier_ids = set([])
    atoms = hierarchy.atoms()
    for i_seq in r.outlier_selection():
        atom = atoms[i_seq]
        atom_group = atoms[i_seq].parent()
        outlier_ids.add(atom_group.id_str())
    outliers1 = sorted([o.atom_group_id_str() for o in r.results])
    outliers2 = sorted(list(outlier_ids))
    assert (outliers1 == outliers2)

    r = ramalyze.ramalyze(pdb_hierarchy=hierarchy, outliers_only=False)
    for unpickle in [False, True]:
        if unpickle:
            r = loads(dumps(r))
        for outlier in r.results:
            assert (len(outlier.xyz) == 3)
        out = StringIO()
        r.show_old_output(out=out, verbose=False)
        output = out.getvalue()
        assert output.count("OUTLIER") == 100
        assert output.count("Favored") == 463
        assert output.count("Allowed") == 162
        assert output.count("General") == 514
        assert output.count("Glycine") == 39
        assert output.count("Trans-proline") == 23
        assert output.count("Cis-proline") == 0
        assert output.count("Pre-proline") == 21
        assert output.count("Isoleucine or valine") == 128
        numtotal = r.get_phi_psi_residues_count()
        assert r.get_outliers_count_and_fraction() == (100, 100. / numtotal)
        assert r.get_allowed_count_and_fraction() == (162, 162. / numtotal)
        assert r.get_favored_count_and_fraction() == (463, 463. / numtotal)
        assert r.get_general_count_and_fraction() == (514, 514. / numtotal)
        assert r.get_gly_count_and_fraction() == (39, 39. / numtotal)
        assert r.get_trans_pro_count_and_fraction() == (23, 23. / numtotal)
        assert r.get_cis_pro_count_and_fraction() == (0, 0. / numtotal)
        assert r.get_prepro_count_and_fraction() == (21, 21. / numtotal)
        assert r.get_ileval_count_and_fraction() == (128, 128. / numtotal)
        #assert numtotal == 75+154+494 #reasons for this math unclear
        assert numtotal == 725
        output_lines = output.splitlines()
        assert len(output_lines) == 725
        selected_lines = []
        for x in [
                0, 1, 168, 169, 715, 716, 717, 718, 719, 720, 721, 722, 723,
                724
        ]:
            selected_lines.append(output_lines[x])
        assert not show_diff(
            "\n".join(selected_lines), """\
 A  15  SER:35.07:-83.26:131.88:Favored:General
 A  16  SER:0.74:-111.53:71.36:Allowed:General
 A 191  ASP:2.66:-42.39:121.87:Favored:Pre-proline
 A 192  PRO:0.31:-39.12:-31.84:Allowed:Trans-proline
 B 368  LYS:56.44:-62.97:-53.28:Favored:General
 B 369  GLU:8.89:-44.36:-45.50:Favored:General
 B 370  LYS:40.00:-50.00:-39.06:Favored:General
 B 371  VAL:68.24:-60.38:-51.85:Favored:Isoleucine or valine
 B 372  LEU:0.02:-61.13:-170.23:OUTLIER:General
 B 373  ARG:0.02:60.09:-80.26:OUTLIER:General
 B 374  ALA:0.13:-37.21:-36.12:Allowed:General
 B 375  LEU:11.84:-89.81:-41.45:Favored:General
 B 376  ASN:84.33:-58.30:-41.39:Favored:General
 B 377  GLU:30.88:-56.79:-21.74:Favored:General""")
        assert (len(r.outlier_selection()) == 494)

    # Exercise 2
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile)
    pdb_in = file_reader.any_file(file_name=regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    hierarchy.atoms().reset_i_seq()
    r = ramalyze.ramalyze(pdb_hierarchy=hierarchy, outliers_only=True)
    out = StringIO()
    r.show_old_output(out=out)
    output = out.getvalue()
    assert output.count("Favored") == 0
    assert output.count("Allowed") == 0
    assert output.count("OUTLIER") == 0
    r = ramalyze.ramalyze(pdb_hierarchy=hierarchy, outliers_only=False)
    for unpickle in [False, True]:
        if unpickle:
            r = loads(dumps(r))
        out = StringIO()
        r.show_old_output(out=out, verbose=False)
        output = out.getvalue()
        assert output.count("Favored") == 50
        assert output.count("Allowed") == 1
        assert output.count("OUTLIER") == 0
        assert output.count("General") == 29
        assert output.count("Glycine") == 4
        assert output.count("Trans-proline") == 5
        assert output.count("Cis-proline") == 0
        assert output.count("Pre-proline") == 5
        assert output.count("Isoleucine or valine") == 8
        numtotal = r.get_phi_psi_residues_count()
        assert r.get_outliers_count_and_fraction() == (0, 0. / numtotal)
        assert r.get_allowed_count_and_fraction() == (1, 1. / numtotal)
        assert r.get_favored_count_and_fraction() == (43, 43. / numtotal)
        #print r.get_general_count_and_fraction()
        assert r.get_general_count_and_fraction() == (25, 25. / numtotal)
        assert r.get_gly_count_and_fraction() == (4, 4. / numtotal)
        assert r.get_trans_pro_count_and_fraction() == (5, 5. / numtotal)
        assert r.get_cis_pro_count_and_fraction() == (0, 0. / numtotal)
        assert r.get_prepro_count_and_fraction() == (5, 5. / numtotal)
        assert r.get_ileval_count_and_fraction() == (5, 5. / numtotal)
        output_lines = output.splitlines()
        assert len(output_lines) == 51
        selected_lines = []
        for x in [0, 1, 5, 6, 7, 8, 9, 47, 48, 49, 50]:
            selected_lines.append(output_lines[x])
        assert not show_diff(
            "\n".join(selected_lines), """\
 A   2 ATHR:33.85:-106.92:144.23:Favored:General
 A   3 ACYS:47.07:-132.54:137.26:Favored:General
 A   7 AILE:98.76:-61.91:-44.35:Favored:Isoleucine or valine
 A   7 BILE:61.50:-56.21:-51.56:Favored:Isoleucine or valine
 A   8 AVAL:23.11:-50.35:-49.64:Favored:Isoleucine or valine
 A   8 BVAL:12.01:-83.20:-12.14:Favored:Isoleucine or valine
 A   8 CVAL:73.11:-61.22:-36.49:Favored:Isoleucine or valine
 A  43 AASP:51.81:-94.64:5.45:Favored:General
 A  43 BASP:56.98:-88.69:-0.12:Favored:General
 A  44  TYR:1.76:-133.10:58.75:Allowed:General
 A  45  ALA:57.37:-86.61:-8.57:Favored:General""")

    # Exercise 3: 2plx excerpt (unusual icode usage)
    import iotbx.pdb.hierarchy
    pdb_io = iotbx.pdb.hierarchy.input(pdb_string="""\
ATOM   1468  N   GLY A 219       3.721  21.322  10.752  1.00 14.12           N
ATOM   1469  CA  GLY A 219       3.586  21.486  12.188  1.00 14.85           C
ATOM   1470  C   GLY A 219       4.462  20.538  12.995  1.00 15.63           C
ATOM   1471  O   GLY A 219       5.513  20.090  12.512  1.00 14.55           O
ATOM   1472  N   CYS A 220       4.036  20.213  14.235  1.00 15.02           N
ATOM   1473  CA  CYS A 220       4.776  19.228  15.068  1.00 15.56           C
ATOM   1474  C   CYS A 220       3.773  18.322  15.741  1.00 14.69           C
ATOM   1475  O   CYS A 220       2.799  18.828  16.338  1.00 15.54           O
ATOM   1476  CB  CYS A 220       5.620  19.906  16.174  1.00 15.72           C
ATOM   1477  SG  CYS A 220       6.762  21.133  15.448  1.00 15.45           S
ATOM   1478  N   ALA A 221A      4.054  17.017  15.707  1.00 14.77           N
ATOM   1479  CA  ALA A 221A      3.274  16.015  16.507  1.00 14.01           C
ATOM   1480  C   ALA A 221A      1.774  15.992  16.099  1.00 14.50           C
ATOM   1481  O   ALA A 221A      0.875  15.575  16.881  1.00 14.46           O
ATOM   1482  CB  ALA A 221A      3.440  16.318  17.935  1.00 12.28           C
ATOM   1483  N   GLN A 221       1.523  16.390  14.848  1.00 14.52           N
ATOM   1484  CA  GLN A 221       0.159  16.391  14.325  1.00 15.19           C
ATOM   1485  C   GLN A 221      -0.229  15.044  13.717  1.00 14.43           C
ATOM   1486  O   GLN A 221       0.641  14.280  13.307  1.00 16.88           O
ATOM   1487  CB  GLN A 221       0.002  17.491  13.272  1.00 16.41           C
ATOM   1488  CG  GLN A 221       0.253  18.906  13.805  1.00 16.52           C
ATOM   1489  CD  GLN A 221      -0.640  19.181  14.995  1.00 17.87           C
ATOM   1490  OE1 GLN A 221      -1.857  19.399  14.826  1.00 13.54           O
ATOM   1491  NE2 GLN A 221      -0.050  19.149  16.228  1.00 16.18           N
ATOM   1492  N   LYS A 222      -1.537  14.773  13.694  1.00 14.34           N
ATOM   1493  CA  LYS A 222      -2.053  13.536  13.125  1.00 15.07           C
ATOM   1494  C   LYS A 222      -1.679  13.455  11.655  1.00 14.88           C
ATOM   1495  O   LYS A 222      -1.856  14.424  10.883  1.00 14.32           O
""")
    r = ramalyze.ramalyze(pdb_hierarchy=pdb_io.hierarchy, outliers_only=False)
    assert (len(r.results) == 3)
예제 #18
0
def test_multi_axis_goniometer():
    from libtbx.test_utils import approx_equal
    from scitbx.array_family import flex

    alpha = 50
    omega = -10
    kappa = 30
    phi = 20
    direction = "-y"

    from dxtbx.model.goniometer import KappaGoniometer

    kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                       "omega")
    axes = (
        kappa_omega_scan.get_phi_axis(),
        kappa_omega_scan.get_kappa_axis(),
        kappa_omega_scan.get_omega_axis(),
    )
    angles = (
        kappa_omega_scan.get_phi_angle(),
        kappa_omega_scan.get_kappa_angle(),
        kappa_omega_scan.get_omega_angle(),
    )

    # First test a kappa goniometer with omega as the scan axis
    axes = flex.vec3_double(axes)
    angles = flex.double(angles)
    names = flex.std_string(("phi", "kappa", "omega"))
    scan_axis = 2

    multi_axis_omega_scan = GoniometerFactory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(
        multi_axis_omega_scan.get_fixed_rotation(),
        kappa_omega_scan.get_fixed_rotation(),
    )
    assert approx_equal(multi_axis_omega_scan.get_rotation_axis(),
                        kappa_omega_scan.get_rotation_axis())

    recycle_omega = MultiAxisGoniometer.from_dict(
        multi_axis_omega_scan.to_dict())
    assert approx_equal(recycle_omega.get_axes(),
                        multi_axis_omega_scan.get_axes())
    assert approx_equal(recycle_omega.get_angles(),
                        multi_axis_omega_scan.get_angles())
    assert recycle_omega.get_scan_axis(
    ) == multi_axis_omega_scan.get_scan_axis()

    # Now test a kappa goniometer with phi as the scan axis
    kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                     "phi")

    scan_axis = 0
    multi_axis_phi_scan = GoniometerFactory.multi_axis(axes, angles, names,
                                                       scan_axis)
    assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(),
                        kappa_phi_scan.get_fixed_rotation())
    assert approx_equal(
        matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) *
        multi_axis_phi_scan.get_rotation_axis_datum(),
        kappa_phi_scan.get_rotation_axis(),
    )
    assert approx_equal(multi_axis_phi_scan.get_rotation_axis(),
                        kappa_phi_scan.get_rotation_axis())

    recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
    assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle_phi.get_angles(),
                        multi_axis_phi_scan.get_angles())
    assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

    s = easy_pickle.dumps(multi_axis_phi_scan)
    recycle = easy_pickle.loads(s)
    assert recycle == multi_axis_phi_scan

    assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
    assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
    recycle.set_angles((0, 90, 180))
    assert approx_equal(recycle.get_angles(), (0, 90, 180))
    new_axes = flex.vec3_double((
        (0.99996, -0.00647, -0.00659),
        (0.91314, 0.27949, -0.29674),
        (1.00000, -0.00013, -0.00064),
    ))
    recycle.set_axes(new_axes)
    assert approx_equal(recycle.get_axes(), new_axes)

    # Check exception is raised if scan axis is out range
    try:
        GoniometerFactory.multi_axis(axes, angles, names, 3)
    except RuntimeError:
        pass
    else:
        raise Exception_expected

    # Single axis is just a special case of a multi axis goniometer
    single_axis = GoniometerFactory.multi_axis(flex.vec3_double(((1, 0, 0), )),
                                               flex.double((0, )),
                                               flex.std_string(("PHI", )), 0)
    assert single_axis.get_fixed_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert single_axis.get_setting_rotation() == (1, 0, 0, 0, 1, 0, 0, 0, 1)
    assert single_axis.get_rotation_axis() == (1, 0, 0)
예제 #19
0
def exercise_ramalyze():
  from mmtbx.rotamer.rotamer_eval import find_rotarama_data_dir
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/jcm.pdb",
    test=os.path.isfile)
  if (regression_pdb is None):
    print "Skipping exercise_ramalyze(): input pdb (jcm.pdb) not available"
    return
  if (find_rotarama_data_dir(optional=True) is None):
    print "Skipping exercise_ramalyze(): rotarama_data directory not available"
    return
  from iotbx import file_reader
  # Exercise 1
  pdb_in = file_reader.any_file(file_name=regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  pdb_io = pdb.input(file_name=regression_pdb)
  hierarchy.atoms().reset_i_seq()
  r = ramalyze.ramalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=True)
  out = StringIO()
  r.show_old_output(out=out)
  output = out.getvalue()
  assert output.count("OUTLIER") == 100
  assert output.count("Favored") == 0
  assert output.count("Allowed") == 0
  assert output.count("General") == 64
  assert output.count("Glycine") == 6
  assert output.count("Trans-proline") == 1
  assert output.count("Cis-proline") == 0
  assert output.count("Pre-proline") == 4
  assert output.count("Isoleucine or valine") == 25
  assert (len(r.outlier_selection()) == 788)
  outlier_ids = set([])
  atoms = hierarchy.atoms()
  for i_seq in r.outlier_selection() :
    atom = atoms[i_seq]
    atom_group = atoms[i_seq].parent()
    outlier_ids.add(atom_group.id_str())
  outliers1 = sorted([ o.atom_group_id_str() for o in r.results ])
  outliers2 = sorted(list(outlier_ids))
  assert (outliers1 == outliers2)

  r = ramalyze.ramalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=False)
  for unpickle in [False, True] :
    if unpickle :
      r = loads(dumps(r))
    for outlier in r.results :
      assert (len(outlier.xyz) == 3)
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    output = out.getvalue()
    assert output.count("OUTLIER") == 100
    assert output.count("Favored") == 461
    assert output.count("Allowed") == 162
    assert output.count("General") == 513
    assert output.count("Glycine") == 39
    assert output.count("Trans-proline") == 23
    assert output.count("Cis-proline") == 0
    assert output.count("Pre-proline") == 21
    assert output.count("Isoleucine or valine") == 127
    numtotal = r.get_phi_psi_residues_count()
    assert r.get_outliers_count_and_fraction()  == (100, 100./numtotal)
    assert r.get_allowed_count_and_fraction()   == (162, 162./numtotal)
    assert r.get_favored_count_and_fraction()   == (461, 461./numtotal)
    assert r.get_general_count_and_fraction()   == (513, 513./numtotal)
    assert r.get_gly_count_and_fraction()       == (39, 39./numtotal)
    assert r.get_trans_pro_count_and_fraction() == (23, 23./numtotal)
    assert r.get_cis_pro_count_and_fraction()   == (0, 0./numtotal)
    assert r.get_prepro_count_and_fraction()    == (21, 21./numtotal)
    assert r.get_ileval_count_and_fraction()    == (127, 127./numtotal)
    assert numtotal == 75+154+494
    output_lines = output.splitlines()
    assert len(output_lines) == 723
    selected_lines = []
    for x in [0, 1, 168, 169, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722]:
      selected_lines.append(output_lines[x])
    assert not show_diff("\n".join(selected_lines), """\
 A  15  SER:35.07:-83.26:131.88:Favored:General
 A  16  SER:0.74:-111.53:71.36:Allowed:General
 A 191  ASP:2.66:-42.39:121.87:Favored:Pre-proline
 A 192  PRO:0.31:-39.12:-31.84:Allowed:Trans-proline
 B 368  LYS:56.44:-62.97:-53.28:Favored:General
 B 369  GLU:8.89:-44.36:-45.50:Favored:General
 B 370  LYS:40.00:-50.00:-39.06:Favored:General
 B 371  VAL:68.24:-60.38:-51.85:Favored:Isoleucine or valine
 B 372  LEU:0.02:-61.13:-170.23:OUTLIER:General
 B 373  ARG:0.02:60.09:-80.26:OUTLIER:General
 B 374  ALA:0.13:-37.21:-36.12:Allowed:General
 B 375  LEU:11.84:-89.81:-41.45:Favored:General
 B 376  ASN:84.33:-58.30:-41.39:Favored:General
 B 377  GLU:30.88:-56.79:-21.74:Favored:General""")
    assert (len(r.outlier_selection()) == 788)

  # Exercise 2
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb1jxt.ent",
    test=os.path.isfile)
  pdb_in = file_reader.any_file(file_name=regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  hierarchy.atoms().reset_i_seq()
  r = ramalyze.ramalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=True)
  out = StringIO()
  r.show_old_output(out=out)
  output = out.getvalue()
  assert output.count("Favored") == 0
  assert output.count("Allowed") == 0
  assert output.count("OUTLIER") == 0
  r = ramalyze.ramalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=False)
  for unpickle in [False, True] :
    if unpickle :
      r = loads(dumps(r))
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    output = out.getvalue()
    assert output.count("Favored") == 47
    assert output.count("Allowed") == 1
    assert output.count("OUTLIER") == 0
    assert output.count("General") == 27
    assert output.count("Glycine") == 4
    assert output.count("Trans-proline") == 4
    assert output.count("Cis-proline") == 0
    assert output.count("Pre-proline") == 5
    assert output.count("Isoleucine or valine") == 8
    numtotal = r.get_phi_psi_residues_count()
    assert r.get_outliers_count_and_fraction()  == (0, 0./numtotal)
    assert r.get_allowed_count_and_fraction()   == (1, 1./numtotal)
    assert r.get_favored_count_and_fraction()   == (47, 47./numtotal)
    assert r.get_general_count_and_fraction()   == (27, 27./numtotal)
    assert r.get_gly_count_and_fraction()       == (4, 4./numtotal)
    assert r.get_trans_pro_count_and_fraction() == (4, 4./numtotal)
    assert r.get_cis_pro_count_and_fraction()   == (0, 0./numtotal)
    assert r.get_prepro_count_and_fraction()    == (5, 5./numtotal)
    assert r.get_ileval_count_and_fraction()    == (8, 8./numtotal)
    output_lines = output.splitlines()
    assert len(output_lines) == 48
    selected_lines = []
    for x in [0, 1, 6, 7, 8, 9, 10, 44, 45, 46, 47]:
      selected_lines.append(output_lines[x])
    assert not show_diff("\n".join(selected_lines), """\
 A   2 ATHR:33.85:-106.92:144.23:Favored:General
 A   2 BTHR:37.07:-97.44:137.00:Favored:General
 A   7 AILE:98.76:-61.91:-44.35:Favored:Isoleucine or valine
 A   7 BILE:61.50:-56.21:-51.56:Favored:Isoleucine or valine
 A   8 AVAL:23.11:-50.35:-49.64:Favored:Isoleucine or valine
 A   8 BVAL:12.01:-83.20:-12.14:Favored:Isoleucine or valine
 A   8 CVAL:73.11:-61.22:-36.49:Favored:Isoleucine or valine
 A  43 AASP:51.81:-94.64:5.45:Favored:General
 A  43 BASP:56.98:-88.69:-0.12:Favored:General
 A  44  TYR:1.76:-133.10:58.75:Allowed:General
 A  45  ALA:57.37:-86.61:-8.57:Favored:General""")

  # Exercise 3: 2plx excerpt (unusual icode usage)
  import iotbx.pdb.hierarchy
  pdb_io = iotbx.pdb.hierarchy.input(pdb_string="""\
ATOM   1468  N   GLY A 219       3.721  21.322  10.752  1.00 14.12           N
ATOM   1469  CA  GLY A 219       3.586  21.486  12.188  1.00 14.85           C
ATOM   1470  C   GLY A 219       4.462  20.538  12.995  1.00 15.63           C
ATOM   1471  O   GLY A 219       5.513  20.090  12.512  1.00 14.55           O
ATOM   1472  N   CYS A 220       4.036  20.213  14.235  1.00 15.02           N
ATOM   1473  CA  CYS A 220       4.776  19.228  15.068  1.00 15.56           C
ATOM   1474  C   CYS A 220       3.773  18.322  15.741  1.00 14.69           C
ATOM   1475  O   CYS A 220       2.799  18.828  16.338  1.00 15.54           O
ATOM   1476  CB  CYS A 220       5.620  19.906  16.174  1.00 15.72           C
ATOM   1477  SG  CYS A 220       6.762  21.133  15.448  1.00 15.45           S
ATOM   1478  N   ALA A 221A      4.054  17.017  15.707  1.00 14.77           N
ATOM   1479  CA  ALA A 221A      3.274  16.015  16.507  1.00 14.01           C
ATOM   1480  C   ALA A 221A      1.774  15.992  16.099  1.00 14.50           C
ATOM   1481  O   ALA A 221A      0.875  15.575  16.881  1.00 14.46           O
ATOM   1482  CB  ALA A 221A      3.440  16.318  17.935  1.00 12.28           C
ATOM   1483  N   GLN A 221       1.523  16.390  14.848  1.00 14.52           N
ATOM   1484  CA  GLN A 221       0.159  16.391  14.325  1.00 15.19           C
ATOM   1485  C   GLN A 221      -0.229  15.044  13.717  1.00 14.43           C
ATOM   1486  O   GLN A 221       0.641  14.280  13.307  1.00 16.88           O
ATOM   1487  CB  GLN A 221       0.002  17.491  13.272  1.00 16.41           C
ATOM   1488  CG  GLN A 221       0.253  18.906  13.805  1.00 16.52           C
ATOM   1489  CD  GLN A 221      -0.640  19.181  14.995  1.00 17.87           C
ATOM   1490  OE1 GLN A 221      -1.857  19.399  14.826  1.00 13.54           O
ATOM   1491  NE2 GLN A 221      -0.050  19.149  16.228  1.00 16.18           N
ATOM   1492  N   LYS A 222      -1.537  14.773  13.694  1.00 14.34           N
ATOM   1493  CA  LYS A 222      -2.053  13.536  13.125  1.00 15.07           C
ATOM   1494  C   LYS A 222      -1.679  13.455  11.655  1.00 14.88           C
ATOM   1495  O   LYS A 222      -1.856  14.424  10.883  1.00 14.32           O
""")
  r = ramalyze.ramalyze(
    pdb_hierarchy=pdb_io.hierarchy,
    outliers_only=False)
  assert (len(r.results) == 3)
예제 #20
0
def test_goniometer():
    '''A test class for the goniometer class.'''

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert (len(xg.get_rotation_axis()) == 3)
    assert (len(xg.get_fixed_rotation()) == 9)

    assert (compare_tuples(xg.get_rotation_axis(), axis))
    assert (compare_tuples(xg.get_fixed_rotation(), fixed))

    single = goniometer_factory.single_axis()

    assert (len(single.get_rotation_axis()) == 3)
    assert (len(single.get_fixed_rotation()) == 9)

    assert (compare_tuples(single.get_rotation_axis(), axis))
    assert (compare_tuples(single.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)
    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'phi')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (compare_tuples(kappa.get_fixed_rotation(), fixed))

    kappa = goniometer_factory.kappa(50.0, 0.0, 30.0, 0.0, '-y', 'omega')

    assert (len(kappa.get_rotation_axis()) == 3)
    assert (len(kappa.get_fixed_rotation()) == 9)

    assert (compare_tuples(kappa.get_rotation_axis(), axis))
    assert (not compare_tuples(kappa.get_fixed_rotation(), fixed))

    import libtbx.load_env
    import os

    dxtbx_dir = libtbx.env.dist_path('dxtbx')

    image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf')
    cbf = goniometer_factory.imgCIF(image)

    kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 0.0, '-y', 'phi')

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = os.path.join(dxtbx_dir, 'tests', 'omega_scan.cbf')
    cbf = goniometer_factory.imgCIF(image)

    kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 20.0, '-y', 'omega')

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    print 'OK'
예제 #21
0
def show_pickled_object_sizes(result):
    result_pkl = dumps(result)
    print("result", len(result_pkl))
    show_pickle_sizes(result, "  ")
예제 #22
0
def exercise_cbetadev():
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb1jxt.ent",
    test=os.path.isfile)
  if (regression_pdb is None):
    print "Skipping exercise_cbetadev(): input pdb (pdb1jxt.ent) not available"
    return
  from mmtbx.validation import cbetadev
  from iotbx import file_reader
  pdb_in = file_reader.any_file(file_name=regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  validation = cbetadev.cbetadev(
    pdb_hierarchy=hierarchy,
    outliers_only=True)
  for unpickle in [False, True] :
    if unpickle :
      validation = loads(dumps(validation))
    assert (validation.n_outliers == len(validation.results) == 6)
    assert ([ cb.id_str() for cb in validation.results ] ==
      [' A   7 AILE', ' A   8 BVAL', ' A   8 CVAL', ' A  30 BTHR',
       ' A  39 BTHR', ' A  43 BASP'])
    assert approx_equal([ cb.deviation for cb in validation.results ],
      [0.25977096732623106, 0.2577218834868609, 0.6405578498280606,
       0.81238828498566, 0.9239566035292618, 0.5001892640352836])
    out = StringIO()
    validation.show_old_output(out=out, verbose=True)
    assert not show_diff(out.getvalue(),
"""\
pdb:alt:res:chainID:resnum:dev:dihedralNABB:Occ:ALT:
pdb :A:ile: A:   7 :  0.260: -46.47:   0.45:A:
pdb :B:val: A:   8 :  0.258:  80.92:   0.30:B:
pdb :C:val: A:   8 :  0.641: -53.98:   0.20:C:
pdb :B:thr: A:  30 :  0.812: -76.98:   0.30:B:
pdb :B:thr: A:  39 :  0.924:  56.41:   0.30:B:
pdb :B:asp: A:  43 :  0.500:   7.56:   0.25:B:
SUMMARY: 6 C-beta deviations >= 0.25 Angstrom (Goal: 0)
""")

  # Now with all residues
  validation = cbetadev.cbetadev(
    pdb_hierarchy=hierarchy,
    outliers_only=False)
  for unpickle in [False, True] :
    if unpickle :
      validation = loads(dumps(validation))
    for outlier in validation.results :
      assert (len(outlier.xyz) == 3)
    assert (validation.n_outliers == 6)
    assert (len(validation.results) == 51)
    out = StringIO()
    validation.show_old_output(out=out, verbose=True)
    assert not show_diff(out.getvalue(), """\
pdb:alt:res:chainID:resnum:dev:dihedralNABB:Occ:ALT:
pdb : :thr: A:   1 :  0.102:  11.27:   1.00: :
pdb :A:thr: A:   2 :  0.022: -49.31:   0.67:A:
pdb : :cys: A:   3 :  0.038: 103.68:   1.00: :
pdb : :cys: A:   4 :  0.047:-120.73:   1.00: :
pdb : :pro: A:   5 :  0.069:-121.41:   1.00: :
pdb : :ser: A:   6 :  0.052: 112.87:   1.00: :
pdb :A:ile: A:   7 :  0.260: -46.47:   0.45:A:
pdb :B:ile: A:   7 :  0.153: 122.97:   0.55:B:
pdb :A:val: A:   8 :  0.184:-155.36:   0.50:A:
pdb :B:val: A:   8 :  0.258:  80.92:   0.30:B:
pdb :C:val: A:   8 :  0.641: -53.98:   0.20:C:
pdb : :ala: A:   9 :  0.061: -82.84:   1.00: :
pdb :A:arg: A:  10 :  0.023: 172.25:   1.00:A:
pdb : :ser: A:  11 :  0.028:-129.11:   1.00: :
pdb :A:asn: A:  12 :  0.021: -80.80:   0.50:A:
pdb :B:asn: A:  12 :  0.199:  50.01:   0.50:B:
pdb :A:phe: A:  13 :  0.067: -37.32:   0.65:A:
pdb :B:phe: A:  13 :  0.138:  19.24:   0.35:B:
pdb : :asn: A:  14 :  0.065: -96.35:   1.00: :
pdb : :val: A:  15 :  0.138: -96.63:   1.00: :
pdb : :cys: A:  16 :  0.102: -28.64:   1.00: :
pdb : :arg: A:  17 :  0.053:-106.79:   1.00: :
pdb : :leu: A:  18 :  0.053:-141.51:   1.00: :
pdb : :pro: A:  19 :  0.065:-146.95:   1.00: :
pdb : :thr: A:  21 :  0.086:  53.80:   1.00: :
pdb :A:pro: A:  22 :  0.092: -83.39:   0.55:A:
pdb :A:glu: A:  23 :  0.014:-179.53:   0.50:A:
pdb :B:glu: A:  23 :  0.050:-179.78:   0.50:B:
pdb : :ala: A:  24 :  0.056: -88.96:   1.00: :
pdb : :leu: A:  25 :  0.084:-106.42:   1.00: :
pdb : :cys: A:  26 :  0.074: -94.70:   1.00: :
pdb : :ala: A:  27 :  0.056: -62.15:   1.00: :
pdb : :thr: A:  28 :  0.056:-114.82:   1.00: :
pdb :A:tyr: A:  29 :  0.068:   0.22:   0.65:A:
pdb :A:thr: A:  30 :  0.180: 103.27:   0.70:A:
pdb :B:thr: A:  30 :  0.812: -76.98:   0.30:B:
pdb : :cys: A:  32 :  0.029: -84.07:   1.00: :
pdb : :ile: A:  33 :  0.048:-119.17:   1.00: :
pdb : :ile: A:  34 :  0.045:  99.02:   1.00: :
pdb : :ile: A:  35 :  0.052:-128.24:   1.00: :
pdb : :pro: A:  36 :  0.084:-142.29:   1.00: :
pdb : :ala: A:  38 :  0.039:  50.01:   1.00: :
pdb :A:thr: A:  39 :  0.093: -96.63:   0.70:A:
pdb :B:thr: A:  39 :  0.924:  56.41:   0.30:B:
pdb : :cys: A:  40 :  0.013:-144.11:   1.00: :
pdb : :pro: A:  41 :  0.039: -97.09:   1.00: :
pdb :A:asp: A:  43 :  0.130:-146.91:   0.75:A:
pdb :B:asp: A:  43 :  0.500:   7.56:   0.25:B:
pdb : :tyr: A:  44 :  0.085:-143.63:   1.00: :
pdb : :ala: A:  45 :  0.055:  33.32:   1.00: :
pdb : :asn: A:  46 :  0.066: -50.46:   1.00: :
SUMMARY: 6 C-beta deviations >= 0.25 Angstrom (Goal: 0)
""")

  # Auxilary function: extract_atoms_from_residue_group
  from mmtbx.validation.cbetadev import extract_atoms_from_residue_group
  from iotbx import pdb
  pdb_1 = pdb.input(source_info=None, lines="""\
ATOM   1185  N  ASER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1186  N  BSER A 146      24.758  37.100  16.337  0.50 16.79           N
ATOM   1187  CA ASER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1188  CA BSER A 146      24.237  37.427  17.662  0.50 16.87           C
ATOM   1189  C  ASER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1190  C  BSER A 146      22.792  36.945  17.783  0.50 15.94           C
ATOM   1191  O  ASER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1192  O  BSER A 146      22.091  36.741  16.779  0.50 15.17           O
ATOM   1193  CB ASER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1194  CB BSER A 146      24.321  38.940  17.904  0.50 17.48           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """).construct_hierarchy()
  pdb_2 = pdb.input(source_info=None, lines="""\
ATOM   1185  N   SER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1187  CA  SER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1189  C   SER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1191  O   SER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1193  CB ASER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1194  CB BSER A 146      24.321  38.940  17.904  0.50 17.48           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """).construct_hierarchy()
  pdb_3 = pdb.input(source_info=None, lines="""\
ATOM   1185  N   SER A 146      24.734  37.097  16.303  0.50 16.64           N
ATOM   1187  CA  SER A 146      24.173  37.500  17.591  0.50 16.63           C
ATOM   1189  C   SER A 146      22.765  36.938  17.768  0.50 15.77           C
ATOM   1191  O   SER A 146      22.052  36.688  16.781  0.50 14.91           O
ATOM   1193  CB  SER A 146      24.118  39.035  17.649  0.50 16.93           C
ATOM   1195  OG ASER A 146      23.183  39.485  18.611  0.50 17.56           O
ATOM   1196  OG BSER A 146      23.468  39.645  17.028  0.50 18.32           O  """).construct_hierarchy()
  rg1 = pdb_1.only_model().only_chain().only_residue_group()
  rg2 = pdb_2.only_model().only_chain().only_residue_group()
  rg3 = pdb_3.only_model().only_chain().only_residue_group()
  all_relevant_atoms_1 = extract_atoms_from_residue_group(rg1)
  all_relevant_atoms_2 = extract_atoms_from_residue_group(rg2)
  all_relevant_atoms_3 = extract_atoms_from_residue_group(rg3)
  keys_1 = [ sorted([ k for k in a.keys() ]) for a in all_relevant_atoms_1 ]
  keys_2 = [ sorted([ k for k in a.keys() ]) for a in all_relevant_atoms_2 ]
  keys_3 = [ sorted([ k for k in a.keys() ]) for a in all_relevant_atoms_3 ]
  assert keys_1 == [[' C  ',' CA ',' CB ',' N  '],[' C  ',' CA ',' CB ',' N  ']]
  assert keys_2 == [[' C  ',' CA ',' CB ',' N  '],[' C  ',' CA ',' CB ',' N  ']]
  assert keys_3 == [[' C  ', ' CA ', ' CB ', ' N  ']]
  print "OK"
예제 #23
0
def exercise_protein () :
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/3ifk.pdb",
    test=op.isfile)
  hkl_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/reflection_files/3ifk.mtz",
    test=op.isfile)
  if (pdb_file is None) :
    print "phenix_regression not available, skipping."
    return
  args1 = [
    pdb_file,
    "outliers_only=True",
    "output.prefix=tst_molprobity",
    "--pickle",
    "flags.xtriage=True",
  ]
  result = molprobity.run(args=args1, out=null_out()).validation
  out1 = StringIO()
  result.show(out=out1)
  result = loads(dumps(result))
  out2 = StringIO()
  result.show(out=out2)
  assert (result.nqh_flips.n_outliers == 1)
  assert (not "RNA validation" in out2.getvalue())
  assert (out2.getvalue() == out1.getvalue())
  dump("tst_molprobity.pkl", result)
  mc = result.as_multi_criterion_view()
  assert (result.neutron_stats is None)
  mpscore = result.molprobity_score()
  # percentiles
  out4 = StringIO()
  result.show_summary(out=out4, show_percentiles=True)
  assert ("""  Clashscore            =  49.96 (percentile: 0.2)""" in
    out4.getvalue())
  # misc
  assert approx_equal(result.r_work(), 0.237) # from PDB header
  assert approx_equal(result.r_free(), 0.293) # from PDB header
  assert approx_equal(result.d_min(), 2.03)   # from PDB header
  assert (result.d_max_min() is None)
  assert approx_equal(result.rms_bonds(), 0.02585)
  assert approx_equal(result.rms_angles(), 2.356740)
  assert approx_equal(result.rama_favored(), 96.47059)
  assert (result.cbeta_outliers() == 10)
  assert approx_equal(result.molprobity_score(), 3.40, eps=0.01)
  summary = result.summarize()
  gui_fields = list(summary.iter_molprobity_gui_fields())
  assert (len(gui_fields) == 6)
  #result.show()
  assert (str(mc.data()[2]) == ' A   5  THR  rota,cb,clash')
  import mmtbx.validation.molprobity
  from iotbx import file_reader
  pdb_in = file_reader.any_file(pdb_file)
  hierarchy = pdb_in.file_object.hierarchy
  flags = mmtbx.validation.molprobity.molprobity_flags()
  flags.clashscore = False
  flags.model_stats = False
  flags.cbetadev = False
  result = mmtbx.validation.molprobity.molprobity(
    pdb_hierarchy=hierarchy,
    flags=flags)
  out3 = StringIO()
  result.show_summary(out=out3)
  assert not show_diff(out3.getvalue(), """\
  Ramachandran outliers =   1.76 %
                favored =  96.47 %
  Rotamer outliers      =  20.00 %
""")
  # now with data
  args2 = args1 + [ hkl_file, "--maps" ]
  result, cmdline = molprobity.run(args=args2,
    out=null_out(),
    return_input_objects=True)
  out = StringIO()
  result.show(out=out)
  stats = result.get_statistics_for_phenix_gui()
  #print stats
  stats = result.get_polygon_statistics(["r_work","r_free","adp_mean_all",
    "angle_rmsd", "bond_rmsd", "clashscore"])
  #print stats
  assert approx_equal(result.r_work(), 0.2276, eps=0.001)
  assert approx_equal(result.r_free(), 0.2805, eps=0.001)
  assert approx_equal(result.d_min(), 2.0302, eps=0.0001)
  assert approx_equal(result.d_max_min(), [34.546125, 2.0302], eps=0.0001)
  assert approx_equal(result.rms_bonds(), 0.02585)
  assert approx_equal(result.rms_angles(), 2.356740)
  assert approx_equal(result.rama_favored(), 96.47059)
  assert (result.cbeta_outliers() == 10)
  assert approx_equal(result.unit_cell().parameters(),
          (55.285, 58.851, 67.115,90,90,90))
  assert (str(result.space_group_info()) == "P 21 21 21")
  bins = result.fmodel_statistics_by_resolution()
  assert (len(bins) == 10)
  assert approx_equal(result.atoms_to_observations_ratio(), 0.09755,
    eps=0.0001)
  assert approx_equal(result.b_iso_mean(), 31.11739)
  assert op.isfile("tst_molprobity_maps.mtz")
  assert approx_equal(result.atoms_to_observations_ratio(), 0.0975493)
  bins = result.fmodel_statistics_by_resolution()
  #bins.show()
  bin_plot = result.fmodel_statistics_graph_data()
  lg = bin_plot.format_loggraph()
  # fake fmodel_neutron
  fmodel_neutron = cmdline.fmodel.deep_copy()
  result2 = mmtbx.validation.molprobity.molprobity(
    pdb_hierarchy=cmdline.pdb_hierarchy,
    fmodel=cmdline.fmodel,
    fmodel_neutron=fmodel_neutron,
    geometry_restraints_manager=cmdline.geometry,
    nuclear=True,
    keep_hydrogens=True)
  stats = result2.get_statistics_for_phenix_gui()
  assert ('R-work (neutron)' in [ label for (label, stat) in stats ])
예제 #24
0
def exercise_1():
    pdb_raw = """\
ATOM   1134  N   LYS A  82       5.933  36.285  21.572  1.00 70.94           N
ATOM   1135  CA  LYS A  82       6.564  37.423  20.931  1.00 76.69           C
ATOM   1136  C   LYS A  82       5.553  38.547  20.756  1.00 78.75           C
ATOM   1137  O   LYS A  82       5.325  39.038  19.654  1.00 86.47           O
ATOM   1138  CB  LYS A  82       7.179  37.024  19.583  1.00 82.32           C
ATOM   1139  CG  LYS A  82       8.190  38.035  19.048  0.00 70.34           C
ATOM   1140  CD  LYS A  82       9.429  38.129  19.944  0.00 67.69           C
ATOM   1141  CE  LYS A  82       9.983  39.545  20.014  0.00 64.44           C
ATOM   1142  NZ  LYS A  82      10.933  39.832  18.908  0.00 61.45           N
ATOM   1143  H   LYS A  82       5.139  36.115  21.291  1.00 85.12           H
ATOM   1144  HA  LYS A  82       7.279  37.749  21.501  1.00 92.03           H
ATOM   1145  HB2 LYS A  82       6.469  36.939  18.928  1.00 98.78           H
ATOM   1146  HB3 LYS A  82       7.636  36.175  19.687  1.00 98.78           H
ATOM   1147  HG2 LYS A  82       8.476  37.762  18.163  0.00 84.41           H
ATOM   1148  HG3 LYS A  82       7.775  38.912  19.011  0.00 84.41           H
ATOM   1149  HD2 LYS A  82       9.193  37.853  20.843  0.00 81.23           H
ATOM   1150  HD3 LYS A  82      10.122  37.551  19.589  0.00 81.23           H
ATOM   1151  HE2 LYS A  82       9.249  40.177  19.952  0.00 77.33           H
ATOM   1152  HE3 LYS A  82      10.453  39.662  20.854  0.00 77.33           H
ATOM   1153  HZ1 LYS A  82      11.237  40.666  18.977  0.00 73.75           H
ATOM   1154  HZ2 LYS A  82      10.523  39.738  18.123  0.00 73.75           H
ATOM   1155  HZ3 LYS A  82      11.621  39.269  18.944  0.00 73.75           H
ATOM   1156  N   LYS A  83       4.936  38.927  21.866  1.00 75.79           N
ATOM   1157  CA  LYS A  83       4.177  40.172  21.966  1.00 82.80           C
ATOM   1158  C   LYS A  83       4.081  40.508  23.460  1.00 86.23           C
ATOM   1159  O   LYS A  83       2.978  40.521  24.017  1.00 79.81           O
ATOM   1160  CB  LYS A  83       2.790  40.044  21.332  1.00 79.16           C
ATOM   1161  CG  LYS A  83       2.038  41.342  21.175  0.00 70.42           C
ATOM   1162  CD  LYS A  83       2.072  41.803  19.735  0.00 66.90           C
ATOM   1163  CE  LYS A  83       1.295  43.089  19.552  0.00 62.46           C
ATOM   1164  NZ  LYS A  83       1.004  43.350  18.118  0.00 60.73           N
ATOM   1165  H   LYS A  83       4.940  38.470  22.594  1.00 90.95           H
ATOM   1166  HA  LYS A  83       4.658  40.885  21.518  1.00 99.36           H
ATOM   1167  HB2 LYS A  83       2.251  39.459  21.887  1.00 95.00           H
ATOM   1168  HB3 LYS A  83       2.890  39.655  20.449  1.00 95.00           H
ATOM   1169  HG2 LYS A  83       1.113  41.213  21.435  0.00 84.51           H
ATOM   1170  HG3 LYS A  83       2.453  42.024  21.726  0.00 84.51           H
ATOM   1171  HD2 LYS A  83       2.992  41.962  19.471  0.00 80.28           H
ATOM   1172  HD3 LYS A  83       1.672  41.123  19.171  0.00 80.28           H
ATOM   1173  HE2 LYS A  83       0.452  43.024  20.027  0.00 74.95           H
ATOM   1174  HE3 LYS A  83       1.818  43.830  19.896  0.00 74.95           H
ATOM   1175  HZ1 LYS A  83       0.521  42.683  17.780  0.00 72.87           H
ATOM   1176  HZ2 LYS A  83       1.764  43.417  17.661  0.00 72.87           H
ATOM   1177  HZ3 LYS A  83       0.548  44.109  18.034  0.00 72.87           H
ATOM   3630  N   ASN A 242      -5.454  -3.027   1.145  0.00 67.69           N
ATOM   3631  CA  ASN A 242      -4.759  -2.535  -0.037  0.00 65.44           C
ATOM   3632  C   ASN A 242      -5.734  -2.397  -1.208  0.00 63.57           C
ATOM   3633  O   ASN A 242      -6.425  -3.357  -1.552  0.00 63.94           O
ATOM   3634  CB  ASN A 242      -3.626  -3.503  -0.392  0.00 63.13           C
ATOM   3635  CG  ASN A 242      -2.802  -3.044  -1.576  0.00 63.58           C
ATOM   3636  OD1 ASN A 242      -2.524  -1.862  -1.731  0.00 65.52           O
ATOM   3637  ND2 ASN A 242      -2.399  -3.988  -2.416  0.00 62.17           N
ATOM   3638  H   ASN A 242      -5.562  -3.880   1.129  0.00 81.22           H
ATOM   3639  HA  ASN A 242      -4.375  -1.665   0.151  0.00 78.53           H
ATOM   3640  HB2 ASN A 242      -3.032  -3.587   0.370  0.00 75.76           H
ATOM   3641  HB3 ASN A 242      -4.007  -4.368  -0.611  0.00 75.76           H
ATOM   3642 HD21 ASN A 242      -1.929  -3.779  -3.104  0.00 74.60           H
ATOM   3643 HD22 ASN A 242      -2.609  -4.810  -2.272  0.00 74.60           H
ATOM      2  CA ALYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB ALYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      2  CA BLYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB BLYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      5  CA AVAL A  33      11.708   5.617  14.332  0.50 71.42           C
ATOM      6  CB AVAL A  33      11.101   4.227  14.591  0.50 71.47           C
ATOM      5  CA BVAL A  33      11.708   5.617  14.332  0.40 71.42           C
ATOM      6  CB BVAL A  33      11.101   4.227  14.591  0.40 71.47           C
TER
ATOM      1  N   GLU X  18     -13.959  12.159  -6.598  1.00260.08           N
ATOM      2  CA  GLU X  18     -13.297  13.465  -6.628  1.00269.83           C
ATOM      3  C   GLU X  18     -11.946  13.282  -7.309  1.00269.18           C
ATOM      4  CB  GLU X  18     -13.128  14.035  -5.210  1.00261.96           C
ATOM      5  CG  GLU X  18     -14.455  14.401  -4.522  1.00263.56           C
ATOM      6  CD  GLU X  18     -14.291  15.239  -3.242  1.00264.89           C
ATOM      7  OE1 GLU X  18     -14.172  14.646  -2.143  1.00264.24           O
ATOM      8  OE2 GLU X  18     -14.309  16.498  -3.306  1.00264.37           O1-
HETATM  614  S   SO4 B 101      14.994  20.601  10.862  0.00  7.02           S
HETATM  615  O1  SO4 B 101      14.234  20.194  12.077  0.00  7.69           O
HETATM  616  O2  SO4 B 101      14.048  21.062   9.850  0.00  9.28           O
HETATM  617  O3  SO4 B 101      15.905  21.686  11.261  0.00  8.01           O
HETATM  618  O4  SO4 B 101      15.772  19.454  10.371  0.00  8.18           O
TER
HETATM  122  O   HOH S   1       5.334   8.357   8.032  1.00  0.00           O
HETATM  123  O   HOH S   2       5.396  15.243  10.734  1.00202.95           O
HETATM  124  O   HOH S   3     -25.334  18.357  18.032  0.00 20.00           O
"""
    mon_lib_srv = server.server()
    ener_lib = server.ener_lib()
    pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
    xrs = pdb_in.input.xray_structure_simple()
    processed_pdb_file = pdb_interpretation.process(
        mon_lib_srv=mon_lib_srv,
        ener_lib=ener_lib,
        raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
        crystal_symmetry=xrs,
        log=null_out())
    pdb_in.hierarchy.atoms().reset_i_seq()
    mstats = model_properties.model_statistics(
        pdb_hierarchy=pdb_in.hierarchy,
        xray_structure=xrs,
        all_chain_proxies=processed_pdb_file.all_chain_proxies,
        ignore_hd=True)
    out = StringIO()
    mstats.show(out=out)
    #print out.getvalue()
    assert not show_diff(
        out.getvalue(), """\
Overall:
  Number of atoms = 50  (anisotropic = 0)
  B_iso: mean =  96.0  max = 269.8  min =   0.0
  Occupancy: mean = 0.47  max = 1.00  min = 0.00
    warning: 22 atoms with zero occupancy
  69 total B-factor or occupancy problem(s) detected
  Atoms or residues with zero occupancy:
   LYS A  82   CG    occ=0.00
   LYS A  82   CD    occ=0.00
   LYS A  82   CE    occ=0.00
   LYS A  82   NZ    occ=0.00
   LYS A  83   CG    occ=0.00
   LYS A  83   CD    occ=0.00
   LYS A  83   CE    occ=0.00
   LYS A  83   NZ    occ=0.00
   ASN A 242  (all)  occ=0.00
   SO4 B 101  (all)  occ=0.00
   HOH S   3   O     occ=0.00
Macromolecules:
  Number of atoms = 42  (anisotropic = 0)
  B_iso: mean = 108.0  max = 269.8  min =  60.7
  Occupancy: mean = 0.51  max = 1.00  min = 0.00
    warning: 16 atoms with zero occupancy
  59 total B-factor or occupancy problem(s) detected
Ligands:
  Number of atoms = 5  (anisotropic = 0)
  B_iso: mean =   8.0  max =   9.3  min =   7.0
  Occupancy: mean = 0.00  max = 0.00  min = 0.00
    warning: 5 atoms with zero occupancy
  6 total B-factor or occupancy problem(s) detected
Waters:
  Number of atoms = 3  (anisotropic = 0)
  B_iso: mean =  74.3  max = 202.9  min =   0.0
  Occupancy: mean = 0.67  max = 1.00  min = 0.00
    warning: 1 atoms with zero occupancy
  4 total B-factor or occupancy problem(s) detected
(Hydrogen atoms not included in overall counts.)
""")
    assert (len(mstats.all.bad_adps) == 1)
    assert (mstats.all.n_zero_b == 1)
    mstats2 = loads(dumps(mstats))
    out1 = StringIO()
    out2 = StringIO()
    mstats.show(out=out1)
    mstats2.show(out=out2)
    assert (out1.getvalue() == out2.getvalue())
    # now with ignore_hd=False
    mstats3 = model_properties.model_statistics(
        pdb_hierarchy=pdb_in.hierarchy,
        xray_structure=xrs,
        all_chain_proxies=processed_pdb_file.all_chain_proxies,
        ignore_hd=False)
    out2 = StringIO()
    mstats3.show(out=out2)
    assert (out2.getvalue() != out.getvalue())
    assert ("""   LYS A  83   HZ3   occ=0.00""" in out2.getvalue())
    outliers = mstats3.all.as_gui_table_data(include_zoom=True)
    assert (len(outliers) == 86)
    # test with all_chain_proxies undefined
    mstats4 = model_properties.model_statistics(pdb_hierarchy=pdb_in.hierarchy,
                                                xray_structure=xrs,
                                                all_chain_proxies=None,
                                                ignore_hd=False)
    outliers = mstats4.all.as_gui_table_data(include_zoom=True)
    assert (len(outliers) == 86)
예제 #25
0
def exercise_rotalyze():
  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/jcm.pdb",
    test=os.path.isfile)
  if (regression_pdb is None):
    print "Skipping exercise_rotalyze(): input pdb (jcm.pdb) not available"
    return
  if (find_rotarama_data_dir(optional=True) is None):
    print "Skipping exercise_rotalyze(): rotarama_data directory not available"
    return
  pdb_in = file_reader.any_file(file_name=regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  pdb_io = pdb.input(file_name=regression_pdb)
  r = rotalyze.rotalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=True)
  out = StringIO()
  r.show_old_output(out=out, verbose=False)
  output = out.getvalue()
  assert output.count("OUTLIER") == 246, output.count("OUTLIER")
  assert output.count(":") == 984, output.count(":")
  output_lines = output.splitlines()
  assert len(output_lines) == 123
  for lines in output_lines:
    assert float(lines[12:15]) <= 1.0

  r = rotalyze.rotalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=False)
  for unpickle in [False, True] :
    if unpickle :
      r = loads(dumps(r))
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    for outlier in r.results :
      assert (len(outlier.xyz) == 3)
    output = out.getvalue()
    assert output.count("OUTLIER") == 246
    assert output.count(":") == 5144, output.count(":")
    assert output.count("p") == 120
    assert output.count("m") == 324
    assert output.count("t") == 486
    output_lines = output.splitlines()
    #for line in output_lines:
    #  print line
    #STOP()
    assert len(output_lines) == 643
    line_indices = [0,1,2,42,43,168,169,450,587,394,641,642]

#    top500 version
    line_values = [
     " A  14  MET:1.00:3.3:29.2:173.3:287.9::Favored:ptm",
     " A  15  SER:1.00:0.1:229.0::::OUTLIER:OUTLIER",
     " A  16  SER:1.00:4.2:277.9::::Favored:m",
     " A  58  ASN:1.00:2.0:252.4:343.6:::Favored:m-20",
     " A  59  ILE:1.00:2.0:84.2:186.7:::Allowed:pt",
     " A 202  GLU:1.00:0.4:272.7:65.9:287.8::OUTLIER:OUTLIER",
     " A 203  ILE:1.00:5.0:292.9:199.6:::Favored:mt",
     " B 154  THR:1.00:0.1:356.0::::OUTLIER:OUTLIER",
     " B 316  TYR:1.00:5.4:153.7:68.6:::Favored:t80",
     " B  86  ASP:1.00:2.2:321.4:145.1:::Favored:m-20",
     " B 377  GLU:1.00:45.3:311.7:166.2:160.1::Favored:mt-10",
     " B 378  THR:1.00:23.5:309.4::::Favored:m"]
#    top8000 version
    line_values = [
     " A  14  MET:1.00:1.3:29.2:173.3:287.9::Allowed:ptm",
     " A  15  SER:1.00:0.1:229.0::::OUTLIER:OUTLIER",
     " A  16  SER:1.00:3.0:277.9::::Favored:m",
     " A  58  ASN:1.00:1.0:252.4:343.6:::Allowed:m-40",
     " A  59  ILE:1.00:0.5:84.2:186.7:::Allowed:pt",
     " A 202  GLU:1.00:0.0:272.7:65.9:287.8::OUTLIER:OUTLIER",
     " A 203  ILE:1.00:1.0:292.9:199.6:::Allowed:mt",
     " B 154  THR:1.00:0.0:356.0::::OUTLIER:OUTLIER",
     " B 316  TYR:1.00:4.1:153.7:68.6:::Favored:t80",
     " B  86  ASP:1.00:0.4:321.4:145.1:::Allowed:m-30",
     " B 377  GLU:1.00:15.0:311.7:166.2:160.1::Favored:mt-10",
     " B 378  THR:1.00:17.0:309.4::::Favored:m",
    ]
    for idx, val in zip(line_indices, line_values) :
      assert (output_lines[idx] == val), (idx, output_lines[idx])

  regression_pdb = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/pdb1jxt.ent",
    test=os.path.isfile)
  if (regression_pdb is None):
    print "Skipping exercise_ramalyze(): input pdb (pdb1jxt.ent) not available"
    return
  pdb_in = file_reader.any_file(file_name=regression_pdb)
  hierarchy = pdb_in.file_object.hierarchy
  pdb_io = pdb.input(file_name=regression_pdb)
  r = rotalyze.rotalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=True)
  out = StringIO()
  r.show_old_output(out=out, verbose=False)
  output = out.getvalue().strip()
  assert output == ""

  r = rotalyze.rotalyze(
    pdb_hierarchy=hierarchy,
    outliers_only=False)
  for unpickle in [False, True] :
    if unpickle :
      r = loads(dumps(r))
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    output = out.getvalue()
    assert not show_diff(output,"""\
 A   1  THR:1.00:95.4:299.5::::Favored:m
 A   2 ATHR:0.67:49.5:56.1::::Favored:p
 A   2 BTHR:0.33:90.4:298.1::::Favored:m
 A   3  CYS:1.00:12.9:310.5::::Favored:m
 A   4  CYS:1.00:91.6:293.1::::Favored:m
 A   5  PRO:1.00:78.8:30.2:319.7:33.8::Favored:Cg_endo
 A   6  SER:1.00:90.1:68.4::::Favored:p
 A   7 AILE:0.45:49.6:290.8:178.2:::Favored:mt
 A   7 BILE:0.55:6.5:284.4:298.4:::Favored:mm
 A   8 AVAL:0.50:1.1:156.7::::Allowed:t
 A   8 BVAL:0.30:5.1:71.3::::Favored:p
 A   8 CVAL:0.20:69.8:172.1::::Favored:t
 A  10 AARG:0.65:24.7:176.8:66.5:63.9:180.0:Favored:tpp-160
 A  10 BARG:0.35:17.5:176.8:72.8:66.4:171.9:Favored:tpp-160
 A  11  SER:1.00:51.6:300.9::::Favored:m
 A  12 AASN:0.50:93.9:286.1:343.8:::Favored:m-40
 A  12 BASN:0.50:98.9:288.4:337.6:::Favored:m-40
 A  13 APHE:0.65:45.1:187.2:276.4:::Favored:t80
 A  13 BPHE:0.35:86.1:179.6:263.1:::Favored:t80
 A  14  ASN:1.00:95.2:289.6:333.0:::Favored:m-40
 A  15  VAL:1.00:42.3:168.2::::Favored:t
 A  16  CYS:1.00:40.8:176.5::::Favored:t
 A  17  ARG:1.00:21.4:289.7:282.8:288.6:158.7:Favored:mmm160
 A  18  LEU:1.00:65.0:287.2:173.3:::Favored:mt
 A  19  PRO:1.00:43.6:24.4:324.8:31.6::Favored:Cg_endo
 A  21  THR:1.00:5.7:314.0::::Favored:m
 A  22 APRO:0.55:87.5:333.5:34.0:333.8::Favored:Cg_exo
 A  23 AGLU:0.50:86.9:290.9:187.1:341.8::Favored:mt-10
 A  23 BGLU:0.50:91.7:292.0:183.8:339.2::Favored:mt-10
 A  25 ALEU:0.50:95.7:294.4:173.6:::Favored:mt
 A  26  CYS:1.00:83.0:295.0::::Favored:m
 A  28  THR:1.00:29.6:52.9::::Favored:p
 A  29 ATYR:0.65:18.5:161.8:67.8:::Favored:t80
 A  29 BTYR:0.35:0.4:191.3:322.7:::Allowed:t80
 A  30 ATHR:0.70:60.8:57.4::::Favored:p
 A  30 BTHR:0.30:6.6:78.1::::Favored:p
 A  32  CYS:1.00:61.4:301.7::::Favored:m
 A  33  ILE:1.00:36.6:66.5:173.4:::Favored:pt
 A  34 AILE:0.70:60.9:303.6:167.6:::Favored:mt
 A  34 BILE:0.30:31.4:308.5:296.8:::Favored:mm
 A  35  ILE:1.00:45.6:62.4:170.0:::Favored:pt
 A  36  PRO:1.00:36.2:22.5:330.5:24.8::Favored:Cg_endo
 A  39 ATHR:0.70:14.0:311.0::::Favored:m
 A  39 BTHR:0.30:13.1:288.8::::Favored:m
 A  40  CYS:1.00:81.4:294.4::::Favored:m
 A  41  PRO:1.00:35.4:34.4:317.5:33.1::Favored:Cg_endo
 A  43 AASP:0.75:24.8:56.5:340.3:::Favored:p0
 A  43 BASP:0.25:43.2:59.6:349.3:::Favored:p0
 A  44  TYR:1.00:85.3:290.9:85.1:::Favored:m-80
 A  46  ASN:1.00:38.7:301.6:117.9:::Favored:m110
""")
예제 #26
0
def test_goniometer():
    """A test class for the goniometer class."""

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert len(xg.get_rotation_axis()) == 3
    assert len(xg.get_fixed_rotation()) == 9

    _compare_tuples(xg.get_rotation_axis(), axis)
    _compare_tuples(xg.get_fixed_rotation(), fixed)

    single = GoniometerFactory.single_axis()

    assert len(single.get_rotation_axis()) == 3
    assert len(single.get_fixed_rotation()) == 9

    _compare_tuples(single.get_rotation_axis(), axis)
    _compare_tuples(single.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9
    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    with pytest.raises(AssertionError):
        _compare_tuples(kappa.get_fixed_rotation(), fixed)

    import libtbx.load_env

    dxtbx_dir = libtbx.env.dist_path("dxtbx")

    image = os.path.join(dxtbx_dir, "tests", "phi_scan_001.cbf")
    assert GoniometerFactory.imgCIF(image)

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = os.path.join(dxtbx_dir, "tests", "omega_scan.cbf")
    assert GoniometerFactory.imgCIF(image)

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2
예제 #27
0
 def copy (self, preserve_changes=True) :
   if preserve_changes :
     return easy_pickle.loads(easy_pickle.dumps(self))
   else :
     return self.copy_master()
def exercise_protein():
    pdb_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/3ifk.pdb", test=op.isfile)
    hkl_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/reflection_files/3ifk.mtz",
        test=op.isfile)
    if (pdb_file is None):
        print "phenix_regression not available, skipping."
        return
    args1 = [
        pdb_file,
        "outliers_only=True",
        "output.prefix=tst_molprobity",
        "--pickle",
        "flags.xtriage=True",
    ]
    result = molprobity.run(args=args1, out=null_out()).validation
    out1 = StringIO()
    result.show(out=out1)
    result = loads(dumps(result))
    out2 = StringIO()
    result.show(out=out2)
    assert (result.nqh_flips.n_outliers == 6)
    assert (not "RNA validation" in out2.getvalue())
    assert (out2.getvalue() == out1.getvalue())
    dump("tst_molprobity.pkl", result)
    mc = result.as_multi_criterion_view()
    assert (result.neutron_stats is None)
    mpscore = result.molprobity_score()
    # percentiles
    out4 = StringIO()
    result.show_summary(out=out4, show_percentiles=True)
    assert ("""  Clashscore            =  49.59"""
            in out4.getvalue()), out4.getvalue()
    # misc
    assert approx_equal(result.r_work(), 0.237)  # from PDB header
    assert approx_equal(result.r_free(), 0.293)  # from PDB header
    assert approx_equal(result.d_min(), 2.03)  # from PDB header
    assert (result.d_max_min() is None)
    assert approx_equal(result.rms_bonds(), 0.02585)
    assert approx_equal(result.rms_angles(), 2.356740)
    assert approx_equal(result.rama_favored(), 96.47059)
    assert (result.cbeta_outliers() == 10)
    assert approx_equal(result.molprobity_score(), 3.39, eps=0.01)
    summary = result.summarize()
    gui_fields = list(summary.iter_molprobity_gui_fields())
    assert (len(gui_fields) == 6)
    #result.show()
    assert (str(mc.data()[2]) == ' A   5  THR  rota,cb,clash')
    import mmtbx.validation.molprobity
    from iotbx import file_reader
    pdb_in = file_reader.any_file(pdb_file)
    model = mmtbx.model.manager(pdb_in.file_object.input)
    result = mmtbx.validation.molprobity.molprobity(model)
    out3 = StringIO()
    result.show_summary(out=out3)
    assert """\
  Ramachandran outliers =   1.76 %
                favored =  96.47 %
  Rotamer outliers      =  20.00 %
""" in out3.getvalue()
    # now with data
    args2 = args1 + [hkl_file, "--maps"]
    result, cmdline = molprobity.run(args=args2,
                                     out=null_out(),
                                     return_input_objects=True)
    out = StringIO()
    result.show(out=out)
    stats = result.get_statistics_for_phenix_gui()
    #print stats
    stats = result.get_polygon_statistics([
        "r_work", "r_free", "adp_mean_all", "angle_rmsd", "bond_rmsd",
        "clashscore"
    ])
    #print stats
    assert approx_equal(result.r_work(), 0.2276, eps=0.001)
    assert approx_equal(result.r_free(), 0.2805, eps=0.001)
    assert approx_equal(result.d_min(), 2.0302, eps=0.0001)
    assert approx_equal(result.d_max_min(), [34.546125, 2.0302], eps=0.0001)
    assert approx_equal(result.rms_bonds(), 0.02585)
    assert approx_equal(result.rms_angles(), 2.356740)
    assert approx_equal(result.rama_favored(), 96.47059)
    assert (result.cbeta_outliers() == 10)
    assert approx_equal(result.unit_cell().parameters(),
                        (55.285, 58.851, 67.115, 90, 90, 90))
    assert (str(result.space_group_info()) == "P 21 21 21")
    bins = result.fmodel_statistics_by_resolution()
    assert (len(bins) == 10)
    assert approx_equal(result.atoms_to_observations_ratio(),
                        0.09755,
                        eps=0.0001)
    assert approx_equal(result.b_iso_mean(), 31.11739)
    assert op.isfile("tst_molprobity_maps.mtz")
    bins = result.fmodel_statistics_by_resolution()
    #bins.show()
    bin_plot = result.fmodel_statistics_graph_data()
    lg = bin_plot.format_loggraph()
    # fake fmodel_neutron
    fmodel_neutron = cmdline.fmodel.deep_copy()
    result2 = mmtbx.validation.molprobity.molprobity(
        cmdline.model,
        fmodel=cmdline.fmodel,
        fmodel_neutron=fmodel_neutron,
        nuclear=True,
        keep_hydrogens=True)
    stats = result2.get_statistics_for_phenix_gui()
    assert ('R-work (neutron)' in [label for (label, stat) in stats])
def exercise () :
  import libtbx.utils
  if (libtbx.utils.detect_multiprocessing_problem() is not None) :
    print "multiprocessing not available, skipping this test"
    return
  if (os.name == "nt"):
    print "easy_mp fixed_func not supported under Windows, skipping this test"
    return
  from mmtbx.validation.sequence import validation, get_sequence_n_copies, \
    get_sequence_n_copies_from_files
  import iotbx.bioinformatics
  import iotbx.pdb
  from iotbx import file_reader
  import libtbx.load_env # import dependency
  from libtbx.test_utils import Exception_expected, contains_lines, approx_equal
  from cStringIO import StringIO
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM      2  CA  ARG A  10      -6.299  36.344   7.806  1.00 55.20           C
ATOM     25  CA  TYR A  11      -3.391  33.962   7.211  1.00 40.56           C
ATOM     46  CA  ALA A  12      -0.693  34.802   4.693  1.00 67.95           C
ATOM     56  CA  ALA A  13       0.811  31.422   3.858  1.00 57.97           C
ATOM     66  CA  GLY A  14       4.466  31.094   2.905  1.00 49.24           C
ATOM     73  CA  ALA A  15       7.163  28.421   2.671  1.00 54.70           C
ATOM     83  CA  ILE A  16       6.554  24.685   2.957  1.00 51.79           C
ATOM    102  CA  LEU A  17       7.691  23.612   6.406  1.00 42.30           C
ATOM    121  CA  PTY A  18       7.292  19.882   5.861  1.00 36.68           C
ATOM    128  CA  PHE A  19       5.417  16.968   4.327  1.00 44.99           C
ATOM    148  CA  GLY A  20       3.466  14.289   6.150  1.00 41.99           C
ATOM    155  CA  GLY A  21       1.756  11.130   4.965  1.00 35.77           C
ATOM    190  CA  ALA A  24       1.294  19.658   3.683  1.00 47.02           C
ATOM    200  CA  VAL A  24A      2.361  22.009   6.464  1.00 37.13           C
ATOM    216  CA  HIS A  25       2.980  25.633   5.535  1.00 42.52           C
ATOM    234  CA  LEU A  26       4.518  28.425   7.577  1.00 47.63           C
ATOM    253  CA  ALA A  27       2.095  31.320   7.634  1.00 38.61           C
ATOM    263  CA  ARG A  28       1.589  34.719   9.165  1.00 37.04           C
END""")
  seq1 = iotbx.bioinformatics.sequence("MTTPSHLSDRYELGEILGFGGMSEVHLARD".lower())
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq1],
    log=null_out(),
    nproc=1)
  out = StringIO()
  v.show(out=out)
  assert contains_lines(out.getvalue(), """\
  sequence identity: 76.47%
  13 residue(s) missing from PDB chain (9 at start, 1 at end)
  2 gap(s) in chain
  4 mismatches to sequence
    residue IDs:  12 13 15 24""")
  cif_block = v.as_cif_block()
  assert list(cif_block['_struct_ref.pdbx_seq_one_letter_code']) == [
    'MTTPSHLSDRYELGEILGFGGMSEVHLARD']
  assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg'],
                      ['10', '14', '16', '19', '24'])
  assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                      ['11', '14', '17', '21', '28'])
  assert approx_equal(cif_block['_struct_ref_seq.db_align_beg'],
                      ['10', '14', '16', '19', '25'])
  assert approx_equal(cif_block['_struct_ref_seq.db_align_end'],
                      ['11', '14', '17', '21', '29'])
  assert cif_block['_struct_ref_seq.pdbx_seq_align_beg_ins_code'][4] == 'A'
  seq2 = iotbx.bioinformatics.sequence("MTTPSHLSDRYELGEILGFGGMSEVHLA")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq2],
    log=null_out(),
    nproc=1)
  out = StringIO()
  v.show(out=out)
  assert contains_lines(out.getvalue(), """\
  1 residues not found in sequence
    residue IDs:  28""")
  try :
    v = validation(
      pdb_hierarchy=pdb_in.construct_hierarchy(),
      sequences=[],
      log=null_out(),
      nproc=1)
  except AssertionError :
    pass
  else :
    raise Exception_expected
  cif_block = v.as_cif_block()
  assert list(cif_block['_struct_ref.pdbx_seq_one_letter_code']) == [
    'MTTPSHLSDRYELGEILGFGGMSEVHLA-']
  assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                      ['11', '14', '17', '21', '27'])
  assert approx_equal(cif_block['_struct_ref_seq.db_align_end'],
                      ['11', '14', '17', '21', '28'])
  #
  pdb_in2 = iotbx.pdb.input(source_info=None, lines="""\
ATOM      2  CA  ARG A  10      -6.299  36.344   7.806  1.00 55.20           C
ATOM     25  CA  TYR A  11      -3.391  33.962   7.211  1.00 40.56           C
ATOM     46  CA  ALA A  12      -0.693  34.802   4.693  1.00 67.95           C
ATOM     56  CA  ALA A  13       0.811  31.422   3.858  1.00 57.97           C
ATOM     66  CA  GLY A  14       4.466  31.094   2.905  1.00 49.24           C
ATOM     73  CA  ALA A  15       7.163  28.421   2.671  1.00 54.70           C
ATOM     83  CA  ILE A  16       6.554  24.685   2.957  1.00 51.79           C
ATOM    102  CA  LEU A  17       7.691  23.612   6.406  1.00 42.30           C
TER
ATOM   1936  P     G B   2     -22.947 -23.615  15.323  1.00123.20           P
ATOM   1959  P     C B   3     -26.398 -26.111  19.062  1.00110.06           P
ATOM   1979  P     U B   4     -29.512 -30.638  21.164  1.00101.06           P
ATOM   1999  P     C B   5     -30.524 -36.109  21.527  1.00 92.76           P
ATOM   2019  P     U B   6     -28.684 -41.458  21.223  1.00 87.42           P
ATOM   2062  P     G B   8     -18.396 -45.415  21.903  1.00 80.35           P
ATOM   2085  P     A B   9     -13.852 -43.272  24.156  1.00 77.76           P
ATOM   2107  P     G B  10      -8.285 -44.242  26.815  1.00 79.86           P
END
""")
  seq3 = iotbx.bioinformatics.sequence("AGCUUUGGAG")
  v = validation(
    pdb_hierarchy=pdb_in2.construct_hierarchy(),
    sequences=[seq2,seq3],
    log=null_out(),
    nproc=1,
    extract_coordinates=True)
  out = StringIO()
  v.show(out=out)
  cif_block = v.as_cif_block()
  assert approx_equal(cif_block['_struct_ref.pdbx_seq_one_letter_code'],
                      ['MTTPSHLSDRYELGEILGFGGMSEVHLA', 'AGCUUUGGAG'])
  assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg'],
                      ['10', '14', '16', '2', '6', '8'])
  assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                      ['11', '14', '17', '4', '6', '10'])
  assert (len(v.chains[0].get_outliers_table()) == 3)
  assert (len(v.get_table_data()) == 4)
  assert approx_equal(
    v.chains[0].get_mean_coordinate_for_alignment_range(11,11),
    (-0.693, 34.802, 4.693))
  assert approx_equal(
    v.chains[0].get_mean_coordinate_for_alignment_range(11,14),
    (2.93675, 31.43475, 3.53175))
  assert (v.chains[0].get_highlighted_residues() == [11,12,14])
  assert contains_lines(out.getvalue(), """\
  3 mismatches to sequence
    residue IDs:  12 13 15""")
  assert contains_lines(out.getvalue(), """\
  sequence identity: 87.50%
  2 residue(s) missing from PDB chain (1 at start, 0 at end)
  1 gap(s) in chain
  1 mismatches to sequence
    residue IDs:  5""")
  s = easy_pickle.dumps(v)
  seq4 = iotbx.bioinformatics.sequence("")
  try :
    v = validation(
      pdb_hierarchy=pdb_in2.construct_hierarchy(),
      sequences=[seq4],
      log=null_out(),
      nproc=1,
      extract_coordinates=True)
  except AssertionError :
    pass
  else :
    raise Exception_expected
  # check that nucleic acid chain doesn't get aligned against protein sequence
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM  18932  P  B DG D   1     -12.183  60.531  25.090  0.50364.79           P
ATOM  18963  P  B DG D   2      -9.738  55.258  20.689  0.50278.77           P
ATOM  18994  P  B DA D   3     -10.119  47.855  19.481  0.50355.17           P
ATOM  19025  P  B DT D   4     -13.664  42.707  21.119  0.50237.06           P
ATOM  19056  P  B DG D   5     -19.510  39.821  21.770  0.50255.45           P
ATOM  19088  P  B DA D   6     -26.096  40.001  21.038  0.50437.49           P
ATOM  19120  P  B DC D   7     -31.790  41.189  18.413  0.50210.00           P
ATOM  19149  P  B DG D   8     -34.639  41.306  12.582  0.50313.99           P
ATOM  19179  P  B DA D   9     -34.987  38.244   6.813  0.50158.92           P
ATOM  19210  P  B DT D  10     -32.560  35.160   1.082  0.50181.38           P
HETATM19241  P  BTSP D  11     -27.614  30.137   0.455  0.50508.17           P
""")
  sequences, _ = iotbx.bioinformatics.fasta_sequence_parse.parse(
    """>4GFH:A|PDBID|CHAIN|SEQUENCE
MSTEPVSASDKYQKISQLEHILKRPDTYIGSVETQEQLQWIYDEETDCMIEKNVTIVPGLFKIFDEILVNAADNKVRDPS
MKRIDVNIHAEEHTIEVKNDGKGIPIEIHNKENIYIPEMIFGHLLTSSNYDDDEKKVTGGRNGYGAKLCNIFSTEFILET
ADLNVGQKYVQKWENNMSICHPPKITSYKKGPSYTKVTFKPDLTRFGMKELDNDILGVMRRRVYDINGSVRDINVYLNGK
SLKIRNFKNYVELYLKSLEKKRQLDNGEDGAAKSDIPTILYERINNRWEVAFAVSDISFQQISFVNSIATTMGGTHVNYI
TDQIVKKISEILKKKKKKSVKSFQIKNNMFIFINCLIENPAFTSQTKEQLTTRVKDFGSRCEIPLEYINKIMKTDLATRM
FEIADANEENALKKSDGTRKSRITNYPKLEDANKAGTKEGYKCTLVLTEGDSALSLAVAGLAVVGRDYYGCYPLRGKMLN
VREASADQILKNAEIQAIKKIMGLQHRKKYEDTKSLRYGHLMIMTDQDHDGSHIKGLIINFLESSFPGLLDIQGFLLEFI
TPIIKVSITKPTKNTIAFYNMPDYEKWREEESHKFTWKQKYYKGLGTSLAQEVREYFSNLDRHLKIFHSLQGNDKDYIDL
AFSKKKADDRKEWLRQYEPGTVLDPTLKEIPISDFINKELILFSLADNIRSIPNVLDGFKPGQRKVLYGCFKKNLKSELK
VAQLAPYVSECTAYHHGEQSLAQTIIGLAQNFVGSNNIYLLLPNGAFGTRATGGKDAAAARYIYTELNKLTRKIFHPADD
PLYKYIQEDEKTVEPEWYLPILPMILVNGAEGIGTGWSTYIPPFNPLEIIKNIRHLMNDEELEQMHPWFRGWTGTIEEIE
PLRYRMYGRIEQIGDNVLEITELPARTWTSTIKEYLLLGLSGNDKIKPWIKDMEEQHDDNIKFIITLSPEEMAKTRKIGF
YERFKLISPISLMNMVAFDPHGKIKKYNSVNEILSEFYYVRLEYYQKRKDHMSERLQWEVEKYSFQVKFIKMIIEKELTV
TNKPRNAIIQELENLGFPRFNKEGKPYYGSPNDEIAEQINDVKGATSDEEDEESSHEDTENVINGPEELYGTYEYLLGMR
IWSLTKERYQKLLKQKQEKETELENLLKLSAKDIWNTDLKAFEVGYQEFLQRDAEAR
>4GFH:D|PDBID|CHAIN|SEQUENCE
GGATGACGATX
""")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=sequences,
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].n_missing == 0
  assert v.chains[0].n_missing_end == 0
  assert v.chains[0].n_missing_start == 0
  assert len(v.chains[0].alignment.matches()) == 11
  #
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM      2  CA  GLY A   1       1.367   0.551   0.300  1.00  7.71           C
ATOM      6  CA  CYS A   2       2.782   3.785   1.683  1.00  5.18           C
ATOM     12  CA  CYS A   3      -0.375   5.128   3.282  1.00  5.21           C
ATOM     18  CA  SER A   4      -0.870   2.048   5.492  1.00  7.19           C
ATOM     25  CA  LEU A   5       2.786   2.056   6.642  1.00  6.78           C
ATOM     33  CA  PRO A   6       3.212   4.746   9.312  1.00  7.03           C
ATOM     40  CA  PRO A   7       6.870   5.690   8.552  1.00  7.97           C
ATOM     47  CA  CYS A   8       6.021   6.070   4.855  1.00  6.48           C
ATOM     53  CA  ALA A   9       2.812   8.041   5.452  1.00  7.15           C
ATOM     58  CA  LEU A  10       4.739  10.382   7.748  1.00  8.36           C
ATOM     66  CA  SER A  11       7.292  11.200   5.016  1.00  7.00           C
ATOM     73  CA  ASN A  12       4.649  11.435   2.264  1.00  5.40           C
ATOM     81  CA  PRO A  13       1.879  13.433   3.968  1.00  5.97           C
ATOM     88  CA  ASP A  14       0.485  15.371   0.986  1.00  7.70           C
ATOM     96  CA  TYR A  15       0.565  12.245  -1.180  1.00  6.55           C
ATOM    108  CA  CYS A  16      -1.466  10.260   1.363  1.00  7.32           C
ATOM    113  N   NH2 A  17      -2.612  12.308   2.058  1.00  8.11           N
""")
  seq = iotbx.bioinformatics.sequence("GCCSLPPCALSNPDYCX")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq],
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].n_missing == 0
  assert v.chains[0].n_missing_end == 0
  assert v.chains[0].n_missing_start == 0
  assert len(v.chains[0].alignment.matches()) == 17
  #
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM   2518  CA  PRO C   3      23.450  -5.848  45.723  1.00 85.24           C
ATOM   2525  CA  GLY C   4      20.066  -4.416  44.815  1.00 79.25           C
ATOM   2529  CA  PHE C   5      19.408  -0.913  46.032  1.00 77.13           C
ATOM   2540  CA  GLY C   6      17.384  -1.466  49.208  1.00 83.44           C
ATOM   2544  CA  GLN C   7      17.316  -5.259  49.606  1.00 89.25           C
ATOM   2553  CA  GLY C   8      19.061  -6.829  52.657  1.00 90.67           C
""")
  sequences, _ = iotbx.bioinformatics.fasta_sequence_parse.parse(
    """>1JN5:A|PDBID|CHAIN|SEQUENCE
MASVDFKTYVDQACRAAEEFVNVYYTTMDKRRRLLSRLYMGTATLVWNGNAVSGQESLSEFFEMLPSSEFQISVVDCQPV
HDEATPSQTTVLVVICGSVKFEGNKQRDFNQNFILTAQASPSNTVWKIASDCFRFQDWAS
>1JN5:B|PDBID|CHAIN|SEQUENCE
APPCKGSYFGTENLKSLVLHFLQQYYAIYDSGDRQGLLDAYHDGACCSLSIPFIPQNPARSSLAEYFKDSRNVKKLKDPT
LRFRLLKHTRLNVVAFLNELPKTQHDVNSFVVDISAQTSTLLCFSVNGVFKEVDGKSRDSLRAFTRTFIAVPASNSGLCI
VNDELFVRNASSEEIQRAFAMPAPTPSSSPVPTLSPEQQEMLQAFSTQSGMNLEWSQKCLQDNNWDYTRSAQAFTHLKAK
GEIPEVAFMK
>1JN5:C|PDBID|CHAIN|SEQUENCE
GQSPGFGQGGSV
""")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=sequences,
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].n_missing_start == 3
  assert v.chains[0].n_missing_end == 3
  assert v.chains[0].identity == 1.0
  assert v.chains[0].alignment.match_codes == 'iiimmmmmmiii'
  #
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM      2  CA  ALA A   2      -8.453  57.214 -12.754  1.00 52.95           C
ATOM      7  CA  LEU A   3      -8.574  59.274  -9.471  1.00 24.33           C
ATOM     15  CA  ARG A   4     -12.178  60.092  -8.575  1.00 28.40           C
ATOM     26  CA  GLY A   5     -14.170  61.485  -5.667  1.00 26.54           C
ATOM     30  CA  THR A   6     -17.784  60.743  -4.783  1.00 31.78           C
ATOM     37  CA  VAL A   7     -19.080  64.405  -4.464  1.00 21.31           C
""")
  seq = iotbx.bioinformatics.sequence("XALRGTV")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq],
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].n_missing_start == 1
  assert v.chains[0].n_missing_end == 0
  assert v.chains[0].identity == 1.0
  assert v.chains[0].alignment.match_codes == 'immmmmm'
  #
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM   2171  CA  ASP I 355       5.591 -11.903   1.133  1.00 41.60           C
ATOM   2175  CA  PHE I 356       7.082  -8.454   0.828  1.00 39.82           C
ATOM   2186  CA  GLU I 357       5.814  -6.112  -1.877  1.00 41.12           C
ATOM   2195  CA  GLU I 358       8.623  -5.111  -4.219  1.00 42.70           C
ATOM   2199  CA  ILE I 359      10.346  -1.867  -3.363  1.00 43.32           C
ATOM   2207  CA  PRO I 360      11.658   0.659  -5.880  1.00 44.86           C
ATOM   2214  CA  GLU I 361      14.921  -0.125  -7.592  1.00 44.32           C
ATOM   2219  CA  GLU I 362      15.848   3.489  -6.866  1.00 44.27           C
HETATM 2224  CA  TYS I 363      16.482   2.005  -3.448  1.00 44.52           C
""")
  seq = iotbx.bioinformatics.sequence("NGDFEEIPEEYL")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq],
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].n_missing_start == 2
  assert v.chains[0].n_missing_end == 1
  assert v.chains[0].identity == 1.0
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM    450  CA  ASN A   1      37.242  41.665  44.160  1.00 35.89           C
ATOM    458  CA  GLY A   2      37.796  38.269  42.523  1.00 30.13           C
HETATM  463  CA AMSE A   3      35.878  39.005  39.326  0.54 22.83           C
HETATM  464  CA BMSE A   3      35.892  39.018  39.323  0.46 22.96           C
ATOM    478  CA  ILE A   4      37.580  38.048  36.061  1.00 22.00           C
ATOM    486  CA  SER A   5      37.593  40.843  33.476  1.00 18.73           C
ATOM    819  CA  ALA A   8      25.982  34.781  27.220  1.00 18.43           C
ATOM    824  CA  ALA A   9      23.292  32.475  28.614  1.00 19.60           C
HETATM  830  CA BMSE A  10      22.793  30.814  25.223  0.41 22.60           C
HETATM  831  CA CMSE A  10      22.801  30.850  25.208  0.59 22.54           C
ATOM    845  CA  GLU A  11      26.504  30.054  24.966  1.00 25.19           C
ATOM    854  CA  GLY A  12      25.907  28.394  28.320  1.00 38.88           C
""")
  seq = iotbx.bioinformatics.sequence("NGMISAAAAMEG")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq],
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  assert v.chains[0].alignment.a == 'NGMISXXAAMEG'
  assert v.chains[0].alignment.b == 'NGMISAAAAMEG'
  pdb_in = iotbx.pdb.input(source_info=None, lines="""\
ATOM   4615  CA  ALA C   1       1.000   1.000   1.000  1.00 10.00
ATOM   4622  CA  ALA C   2       1.000   1.000   1.000  1.00 10.00
ATOM   4627  CA  ALA C   3       1.000   1.000   1.000  1.00 10.00
ATOM   4634  CA  ALA C   4       1.000   1.000   1.000  1.00 10.00
ATOM   4646  CA  ALA C   5       1.000   1.000   1.000  1.00 10.00
ATOM   4658  CA  ALA C   6       1.000   1.000   1.000  1.00 10.00
ATOM   4664  CA  ALA C   7       1.000   1.000   1.000  1.00 10.00
ATOM   4669  CA  ALA C   8       1.000   1.000   1.000  1.00 10.00
ATOM   4680  CA  ARG C   9       1.000   1.000   1.000  1.00 10.00
ATOM   4690  CA  GLY C  10       1.000   1.000   1.000  1.00 10.00
ATOM   4698  CA  PRO C  11       1.000   1.000   1.000  1.00 10.00
ATOM   4705  CA  LYS C  12       1.000   1.000   1.000  1.00 10.00
ATOM   4712  CA  TRP C  13       1.000   1.000   1.000  1.00 10.00
ATOM   4726  CA  GLU C  14       1.000   1.000   1.000  1.00 10.00
ATOM   4738  CA  SER C  15       1.000   1.000   1.000  1.00 10.00
ATOM   4744  CA  THR C  16       1.000   1.000   1.000  1.00 10.00
ATOM   4751  CA  GLY C  17       1.000   1.000   1.000  1.00 10.00
ATOM   4755  CA  TYR C  18       1.000   1.000   1.000  1.00 10.00
ATOM   4767  CA  PHE C  19       1.000   1.000   1.000  1.00 10.00
ATOM   4778  CA  ALA C  20       1.000   1.000   1.000  1.00 10.00
ATOM   4786  CA  ALA C  21       1.000   1.000   1.000  1.00 10.00
ATOM   4798  CA  TRP C  22       1.000   1.000   1.000  1.00 10.00
ATOM   4812  CA  GLY C  23       1.000   1.000   1.000  1.00 10.00
ATOM   4816  CA  GLN C  24       1.000   1.000   1.000  1.00 10.00
ATOM   4822  CA  GLY C  25       1.000   1.000   1.000  1.00 10.00
ATOM   4826  CA  THR C  26       1.000   1.000   1.000  1.00 10.00
ATOM   4833  CA  LEU C  27       1.000   1.000   1.000  1.00 10.00
ATOM   4841  CA  VAL C  28       1.000   1.000   1.000  1.00 10.00
ATOM   4848  CA  THR C  29       1.000   1.000   1.000  1.00 10.00
ATOM   4855  CA  VAL C  30       1.000   1.000   1.000  1.00 10.00
ATOM   4862  CA  SER C  31       1.000   1.000   1.000  1.00 10.00
ATOM   4868  CA  SER C  32       1.000   1.000   1.000  1.00 10.00
END
""")
  seq = iotbx.bioinformatics.sequence(
    "AAAAAAAARGKWESPAALLKKAAWCSGTLVTVSSASAPKWKSTSGCYFAAPWNKRALRVTVLQSS")
  v = validation(
    pdb_hierarchy=pdb_in.construct_hierarchy(),
    sequences=[seq],
    log=null_out(),
    nproc=1,)
  out = StringIO()
  v.show(out=out)
  # all tests below here have additional dependencies
  if (not libtbx.env.has_module("ksdssp")) :
    print "Skipping advanced tests (require ksdssp module)"
    return
  pdb_file = libtbx.env.find_in_repositories(
    relative_path="phenix_regression/pdb/1ywf.pdb",
    test=os.path.isfile)
  if (pdb_file is not None) :
    seq = iotbx.bioinformatics.sequence("MGSSHHHHHHSSGLVPRGSHMAVRELPGAWNFRDVADTATALRPGRLFRSSELSRLDDAGRATLRRLGITDVADLRSSREVARRGPGRVPDGIDVHLLPFPDLADDDADDSAPHETAFKRLLTNDGSNGESGESSQSINDAATRYMTDEYRQFPTRNGAQRALHRVVTLLAAGRPVLTHCFAGKDRTGFVVALVLEAVGLDRDVIVADYLRSNDSVPQLRARISEMIQQRFDTELAPEVVTFTKARLSDGVLGVRAEYLAAARQTIDETYGSLGGYLRDAGISQATVNRMRGVLLG")
    pdb_in = file_reader.any_file(pdb_file, force_type="pdb")
    hierarchy = pdb_in.file_object.hierarchy
    v = validation(
      pdb_hierarchy=hierarchy,
      sequences=[seq],
      log=null_out(),
      nproc=1,
      include_secondary_structure=True,
      extract_coordinates=True)
    out = StringIO()
    v.show(out=out)
    aln1, aln2, ss = v.chains[0].get_alignment(include_sec_str=True)
    assert ("HHH" in ss) and ("LLL" in ss) and ("---" in ss)
    cif_block = v.as_cif_block()
    assert cif_block['_struct_ref.pdbx_seq_one_letter_code'] == seq.sequence
    assert list(
      cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg']) == ['4', '117']
    assert list(
      cif_block['_struct_ref_seq.pdbx_auth_seq_align_end']) == ['85', '275']
    assert list(cif_block['_struct_ref_seq.seq_align_beg']) == ['1', '114']
    assert list(cif_block['_struct_ref_seq.seq_align_end']) == ['82', '272']
    # determine relative counts of sequences and chains
    n_seq = get_sequence_n_copies(
      pdb_hierarchy=hierarchy,
      sequences=[seq] * 4,
      copies_from_xtriage=4,
      out=null_out())
    assert (n_seq == 1)
    hierarchy = hierarchy.deep_copy()
    chain2 = hierarchy.only_model().chains()[0].detached_copy()
    hierarchy.only_model().append_chain(chain2)
    n_seq = get_sequence_n_copies(
      pdb_hierarchy=hierarchy,
      sequences=[seq] * 4,
      copies_from_xtriage=2,
      out=null_out())
    assert (n_seq == 1)
    n_seq = get_sequence_n_copies(
      pdb_hierarchy=hierarchy,
      sequences=[seq],
      copies_from_xtriage=2,
      out=null_out())
    assert (n_seq == 4)
    try :
      n_seq = get_sequence_n_copies(
        pdb_hierarchy=hierarchy,
        sequences=[seq] * 3,
        copies_from_xtriage=2,
        out=null_out())
    except Sorry, s :
      assert ("round number" in str(s))
    else :
      raise Exception_expected
    n_seq = get_sequence_n_copies(
      pdb_hierarchy=hierarchy,
      sequences=[seq] * 3,
      copies_from_xtriage=2,
      force_accept_composition=True,
      out=null_out())
    assert (n_seq == 1)
    try :
      n_seq = get_sequence_n_copies(
        pdb_hierarchy=hierarchy,
        sequences=[seq] * 4,
        copies_from_xtriage=1,
        out=null_out())
    except Sorry, s :
      assert ("less than" in str(s))
예제 #30
0
def show_pickled_object_sizes (result) :
  result_pkl = dumps(result)
  print "result", len(result_pkl)
  show_pickle_sizes(result, "  ")
예제 #31
0
def exercise_simple():
    # extracted from 1lyz, with hydrogens from reduce
    pdb_in = """
ATOM      1  N   LYS A   1       3.296   9.888  10.739  1.00  7.00           N
ATOM      2  CA  LYS A   1       2.439  10.217   9.791  1.00  6.00           C
ATOM      3  C   LYS A   1       2.439  11.997   9.160  1.00  6.00           C
ATOM      4  O   LYS A   1       2.637  12.656  10.107  1.00  8.00           O
ATOM      5  CB  LYS A   1       0.659  10.086   8.844  1.00  6.00           C
ATOM      6  CG  LYS A   1       0.198  10.415   8.086  1.00  6.00           C
ATOM      7  CD  LYS A   1      -1.187  10.086   8.212  1.00  6.00           C
ATOM      8  CE  LYS A   1      -2.175  10.086   7.264  1.00  6.00           C
ATOM      9  NZ  LYS A   1      -3.527   9.869   7.288  1.00  7.00           N
ATOM      0  H1  LYS A   1       3.156   9.045  10.986  1.00  7.00           H
ATOM      0  H2  LYS A   1       4.127   9.972  10.431  1.00  7.00           H
ATOM      0  H3  LYS A   1       3.184  10.425  11.440  1.00  7.00           H
ATOM      0  HA  LYS A   1       2.772   9.314   9.912  1.00  6.00           H
ATOM      0  HB2 LYS A   1       0.584   9.128   8.712  1.00  6.00           H
ATOM      0  HB3 LYS A   1       0.046  10.323   9.557  1.00  6.00           H
ATOM      0  HG2 LYS A   1       0.310  11.376   8.015  1.00  6.00           H
ATOM      0  HG3 LYS A   1       0.563  10.027   7.276  1.00  6.00           H
ATOM      0  HD2 LYS A   1      -1.193   9.186   8.573  1.00  6.00           H
ATOM      0  HD3 LYS A   1      -1.516  10.674   8.910  1.00  6.00           H
ATOM      0  HE2 LYS A   1      -2.097  10.964   6.860  1.00  6.00           H
ATOM      0  HE3 LYS A   1      -1.857   9.444   6.610  1.00  6.00           H
ATOM      0  HZ1 LYS A   1      -3.725   9.170   6.774  1.00  7.00           H
ATOM      0  HZ2 LYS A   1      -3.787   9.706   8.123  1.00  7.00           H
ATOM      0  HZ3 LYS A   1      -3.949  10.590   6.982  1.00  7.00           H
ATOM     10  N   VAL A   2       2.637  12.722   7.707  1.00  7.00           N
ATOM     11  CA  VAL A   2       2.307  14.172   7.580  1.00  6.00           C
ATOM     12  C   VAL A   2       0.857  14.041   6.949  1.00  6.00           C
ATOM     13  O   VAL A   2       0.659  13.843   5.875  1.00  8.00           O
ATOM     14  CB  VAL A   2       3.625  14.172   6.759  1.00  6.00           C
ATOM     15  CG1 VAL A   2       3.494  15.491   6.317  1.00  6.00           C
ATOM     16  CG2 VAL A   2       4.746  13.843   7.580  1.00  6.00           C
ATOM      0  H   VAL A   2       2.920  12.338   6.992  1.00  7.00           H
ATOM      0  HA  VAL A   2       2.195  14.925   8.181  1.00  6.00           H
ATOM      0  HB  VAL A   2       3.767  13.528   6.048  1.00  6.00           H
ATOM      0 HG11 VAL A   2       4.250  15.721   5.755  1.00  6.00           H
ATOM      0 HG12 VAL A   2       2.674  15.582   5.808  1.00  6.00           H
ATOM      0 HG13 VAL A   2       3.467  16.087   7.081  1.00  6.00           H
ATOM      0 HG21 VAL A   2       5.554  13.850   7.043  1.00  6.00           H
ATOM      0 HG22 VAL A   2       4.827  14.495   8.294  1.00  6.00           H
ATOM      0 HG23 VAL A   2       4.620  12.960   7.962  1.00  6.00           H
END
"""
    pdb_file = "tst_validate_restraints_simple.pdb"
    open(pdb_file, "w").write(pdb_in)
    v1 = run_validation(pdb_file, ignore_hd=True)
    out1 = StringIO()
    v1.show(out=out1)
    assert ("""
                       ----------Chiral volumes----------

atoms                   ideal    model    delta   sigma  residual   deviation
 A   1  LYS  CA
 A   1  LYS  N
 A   1  LYS  C
 A   1  LYS  CB          2.57     1.12     1.45  2.00e-01  5.25e+01   7.2*sigma
""" in "\n".join([l.rstrip() for l in out1.getvalue().splitlines()]))
    s = easy_pickle.dumps(v1)
    v1p = easy_pickle.loads(s)
    out1p = StringIO()
    v1p.show(out=out1p)
    assert (out1.getvalue() == out1p.getvalue())
    v2 = run_validation(pdb_file, ignore_hd=False)
    out2 = StringIO()
    v2.show(out=out2)
    assert (out2.getvalue() != out1.getvalue())
    assert ("""\
 A   1  LYS  HA        110.00    57.00    53.00  3.00e+00  3.12e+02  17.7*sigma
 A   1  LYS  N
 A   1  LYS  CA
""" in "\n".join([l.rstrip() for l in out2.getvalue().splitlines()]))
    #
    # C-alpha-only model (from 3b5d)
    pdb_raw = """\
CRYST1  115.100   43.700   76.400  90.00 108.10  90.00 C 1 2 1       8
ATOM      1  CA  TYR A   6      -7.551 -11.355 -17.946  1.00148.04           C
ATOM      2  CA  LEU A   7      -8.052  -8.804 -20.730  1.00310.75           C
ATOM      3  CA  GLY A   8     -10.874  -6.691 -19.353  1.00158.95           C
ATOM      4  CA  GLY A   9      -9.359  -7.332 -15.966  1.00217.68           C
ATOM      5  CA  ALA A  10      -5.806  -6.508 -16.946  1.00239.12           C
ATOM      6  CA  ILE A  11      -7.024  -3.514 -18.905  1.00103.16           C
ATOM      7  CA  LEU A  12     -10.023  -2.071 -17.056  1.00230.80           C
ATOM      8  CA  ALA A  13      -7.313  -1.820 -14.420  1.00141.04           C
"""
    pdb_file = "tst_validate_restraints_calpha.pdb"
    open(pdb_file, "w").write(pdb_raw)
    v1 = run_validation(pdb_file, ignore_hd=True)
예제 #32
0
 def copy(self, preserve_changes=True):
     if preserve_changes:
         return easy_pickle.loads(easy_pickle.dumps(self))
     else:
         return self.copy_master()
예제 #33
0
def test_multi_axis_goniometer():
  from libtbx.test_utils import approx_equal
  from scitbx.array_family import flex

  alpha = 50
  omega = -10
  kappa = 30
  phi = 20
  direction = '-y'

  from dxtbx.model.goniometer import KappaGoniometer
  kappa_omega_scan = KappaGoniometer(
    alpha, omega, kappa, phi, direction, 'omega')
  axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(),
          kappa_omega_scan.get_omega_axis())
  angles = (kappa_omega_scan.get_phi_angle(), kappa_omega_scan.get_kappa_angle(),
            kappa_omega_scan.get_omega_angle())

  # First test a kappa goniometer with omega as the scan axis
  axes = flex.vec3_double(axes)
  angles = flex.double(angles)
  names = flex.std_string(('phi', 'kappa', 'omega'))
  scan_axis = 2

  multi_axis_omega_scan = goniometer_factory.multi_axis(
    axes, angles, names, scan_axis)
  assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(), kappa_omega_scan.get_fixed_rotation())
  assert approx_equal(multi_axis_omega_scan.get_rotation_axis(), kappa_omega_scan.get_rotation_axis())

  recycle_omega = MultiAxisGoniometer.from_dict(multi_axis_omega_scan.to_dict())
  assert approx_equal(recycle_omega.get_axes(), multi_axis_omega_scan.get_axes())
  assert approx_equal(recycle_omega.get_angles(), multi_axis_omega_scan.get_angles())
  assert recycle_omega.get_scan_axis() == multi_axis_omega_scan.get_scan_axis()

  # Now test a kappa goniometer with phi as the scan axis
  kappa_phi_scan = KappaGoniometer(
    alpha, omega, kappa, phi, direction, 'phi')

  scan_axis = 0
  multi_axis_phi_scan = goniometer_factory.multi_axis(
    axes, angles, names, scan_axis)
  assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(), kappa_phi_scan.get_fixed_rotation())
  from scitbx import matrix
  assert approx_equal(matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) * multi_axis_phi_scan.get_rotation_axis(), kappa_phi_scan.get_rotation_axis())

  recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
  assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle_phi.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

  s = easy_pickle.dumps(multi_axis_phi_scan)
  recycle = easy_pickle.loads(s)
  assert recycle == multi_axis_phi_scan

  assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
  recycle.set_angles((0,90,180))
  assert approx_equal(recycle.get_angles(), (0, 90, 180))
  new_axes = (0.9, 0.1, 0.0), (0.6427876096865394, -0.766044443118978, 0.0), (1.0, 0.0, 0.0)
  new_axes = flex.vec3_double(
    ((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674),
     (1.00000, -0.00013, -0.00064)))
  recycle.set_axes(new_axes)
  assert approx_equal(recycle.get_axes(), new_axes)

  # Check exception is raised if scan axis is out range
  try: goniometer_factory.multi_axis(axes, angles, names, 3)
  except RuntimeError, e: pass
  else: raise Exception_expected

  # Single axis is just a special case of a multi axis goniometer
  single_axis = goniometer_factory.multi_axis(
    flex.vec3_double(((1,0,0),)), flex.double((0,)), flex.std_string(('PHI',)), 0)
  assert single_axis.get_fixed_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_setting_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_rotation_axis() == (1,0,0)

  print 'OK'
예제 #34
0
def test_multi_axis_goniometer():
    from libtbx.test_utils import approx_equal
    from scitbx.array_family import flex

    alpha = 50
    omega = -10
    kappa = 30
    phi = 20
    direction = '-y'

    from dxtbx.model.goniometer import KappaGoniometer
    kappa_omega_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                       'omega')
    axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(),
            kappa_omega_scan.get_omega_axis())
    angles = (kappa_omega_scan.get_phi_angle(),
              kappa_omega_scan.get_kappa_angle(),
              kappa_omega_scan.get_omega_angle())

    # First test a kappa goniometer with omega as the scan axis
    axes = flex.vec3_double(axes)
    angles = flex.double(angles)
    names = flex.std_string(('phi', 'kappa', 'omega'))
    scan_axis = 2

    multi_axis_omega_scan = goniometer_factory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(),
                        kappa_omega_scan.get_fixed_rotation())
    assert approx_equal(multi_axis_omega_scan.get_rotation_axis(),
                        kappa_omega_scan.get_rotation_axis())

    recycle_omega = MultiAxisGoniometer.from_dict(
        multi_axis_omega_scan.to_dict())
    assert approx_equal(recycle_omega.get_axes(),
                        multi_axis_omega_scan.get_axes())
    assert approx_equal(recycle_omega.get_angles(),
                        multi_axis_omega_scan.get_angles())
    assert recycle_omega.get_scan_axis(
    ) == multi_axis_omega_scan.get_scan_axis()

    # Now test a kappa goniometer with phi as the scan axis
    kappa_phi_scan = KappaGoniometer(alpha, omega, kappa, phi, direction,
                                     'phi')

    scan_axis = 0
    multi_axis_phi_scan = goniometer_factory.multi_axis(
        axes, angles, names, scan_axis)
    assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(),
                        kappa_phi_scan.get_fixed_rotation())
    from scitbx import matrix
    assert approx_equal(
        matrix.sqr(multi_axis_phi_scan.get_setting_rotation()) *
        multi_axis_phi_scan.get_rotation_axis_datum(),
        kappa_phi_scan.get_rotation_axis())
    assert approx_equal(multi_axis_phi_scan.get_rotation_axis(),
                        kappa_phi_scan.get_rotation_axis())

    recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
    assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle_phi.get_angles(),
                        multi_axis_phi_scan.get_angles())
    assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

    s = easy_pickle.dumps(multi_axis_phi_scan)
    recycle = easy_pickle.loads(s)
    assert recycle == multi_axis_phi_scan

    assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
    assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
    assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()
    recycle.set_angles((0, 90, 180))
    assert approx_equal(recycle.get_angles(), (0, 90, 180))
    new_axes = (0.9, 0.1, 0.0), (0.6427876096865394, -0.766044443118978,
                                 0.0), (1.0, 0.0, 0.0)
    new_axes = flex.vec3_double(
        ((0.99996, -0.00647, -0.00659), (0.91314, 0.27949, -0.29674),
         (1.00000, -0.00013, -0.00064)))
    recycle.set_axes(new_axes)
    assert approx_equal(recycle.get_axes(), new_axes)

    # Check exception is raised if scan axis is out range
    try:
        goniometer_factory.multi_axis(axes, angles, names, 3)
    except RuntimeError, e:
        pass
예제 #35
0
def test_goniometer():
  '''A test class for the goniometer class.'''


  axis = (1, 0, 0)
  fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

  xg = Goniometer(axis, fixed)

  assert(len(xg.get_rotation_axis()) == 3)
  assert(len(xg.get_fixed_rotation()) == 9)

  assert(compare_tuples(xg.get_rotation_axis(), axis))
  assert(compare_tuples(xg.get_fixed_rotation(), fixed))

  single = goniometer_factory.single_axis()

  assert(len(single.get_rotation_axis()) == 3)
  assert(len(single.get_fixed_rotation()) == 9)

  assert(compare_tuples(single.get_rotation_axis(), axis))
  assert(compare_tuples(single.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)
  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 0.0, 0.0, '-y', 'phi')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(compare_tuples(kappa.get_fixed_rotation(), fixed))

  kappa = goniometer_factory.kappa(50.0, 0.0, 30.0, 0.0, '-y', 'omega')

  assert(len(kappa.get_rotation_axis()) == 3)
  assert(len(kappa.get_fixed_rotation()) == 9)

  assert(compare_tuples(kappa.get_rotation_axis(), axis))
  assert(not compare_tuples(kappa.get_fixed_rotation(), fixed))

  import libtbx.load_env
  import os

  dxtbx_dir = libtbx.env.dist_path('dxtbx')

  image = os.path.join(dxtbx_dir, 'tests', 'phi_scan_001.cbf')
  cbf = goniometer_factory.imgCIF(image)

  kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 0.0, '-y', 'phi')

  s = easy_pickle.dumps(kappa)
  kappa2 = easy_pickle.loads(s)
  assert kappa == kappa2

  image = os.path.join(dxtbx_dir, 'tests', 'omega_scan.cbf')
  cbf = goniometer_factory.imgCIF(image)

  kappa = goniometer_factory.kappa(50.0, -10.0, 30.0, 20.0, '-y', 'omega')

  s = easy_pickle.dumps(kappa)
  kappa2 = easy_pickle.loads(s)
  assert kappa == kappa2

  print 'OK'
예제 #36
0
def exercise():
    import libtbx.utils
    if (libtbx.utils.detect_multiprocessing_problem() is not None):
        print "multiprocessing not available, skipping this test"
        return
    if (os.name == "nt"):
        print "easy_mp fixed_func not supported under Windows, skipping this test"
        return
    from mmtbx.validation.sequence import validation, get_sequence_n_copies, \
      get_sequence_n_copies_from_files
    import iotbx.bioinformatics
    import iotbx.pdb
    from iotbx import file_reader
    import libtbx.load_env  # import dependency
    from libtbx.test_utils import Exception_expected, contains_lines, approx_equal
    from cStringIO import StringIO
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM      2  CA  ARG A  10      -6.299  36.344   7.806  1.00 55.20           C
ATOM     25  CA  TYR A  11      -3.391  33.962   7.211  1.00 40.56           C
ATOM     46  CA  ALA A  12      -0.693  34.802   4.693  1.00 67.95           C
ATOM     56  CA  ALA A  13       0.811  31.422   3.858  1.00 57.97           C
ATOM     66  CA  GLY A  14       4.466  31.094   2.905  1.00 49.24           C
ATOM     73  CA  ALA A  15       7.163  28.421   2.671  1.00 54.70           C
ATOM     83  CA  ILE A  16       6.554  24.685   2.957  1.00 51.79           C
ATOM    102  CA  LEU A  17       7.691  23.612   6.406  1.00 42.30           C
ATOM    121  CA  PTY A  18       7.292  19.882   5.861  1.00 36.68           C
ATOM    128  CA  PHE A  19       5.417  16.968   4.327  1.00 44.99           C
ATOM    148  CA  GLY A  20       3.466  14.289   6.150  1.00 41.99           C
ATOM    155  CA  GLY A  21       1.756  11.130   4.965  1.00 35.77           C
ATOM    190  CA  ALA A  24       1.294  19.658   3.683  1.00 47.02           C
ATOM    200  CA  VAL A  24A      2.361  22.009   6.464  1.00 37.13           C
ATOM    216  CA  HIS A  25       2.980  25.633   5.535  1.00 42.52           C
ATOM    234  CA  LEU A  26       4.518  28.425   7.577  1.00 47.63           C
ATOM    253  CA  ALA A  27       2.095  31.320   7.634  1.00 38.61           C
ATOM    263  CA  ARG A  28       1.589  34.719   9.165  1.00 37.04           C
END""")
    seq1 = iotbx.bioinformatics.sequence(
        "MTTPSHLSDRYELGEILGFGGMSEVHLARD".lower())
    v = validation(pdb_hierarchy=pdb_in.construct_hierarchy(),
                   sequences=[seq1],
                   log=null_out(),
                   nproc=1)
    out = StringIO()
    v.show(out=out)
    assert contains_lines(
        out.getvalue(), """\
  sequence identity: 76.47%
  13 residue(s) missing from PDB chain (9 at start, 1 at end)
  2 gap(s) in chain
  4 mismatches to sequence
    residue IDs:  12 13 15 24""")
    cif_block = v.as_cif_block()
    assert list(cif_block['_struct_ref.pdbx_seq_one_letter_code']) == [
        'MTTPSHLSDRYELGEILGFGGMSEVHLARD'
    ]
    assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg'],
                        ['10', '14', '16', '19', '24'])
    assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                        ['11', '14', '17', '21', '28'])
    assert approx_equal(cif_block['_struct_ref_seq.db_align_beg'],
                        ['10', '14', '16', '19', '25'])
    assert approx_equal(cif_block['_struct_ref_seq.db_align_end'],
                        ['11', '14', '17', '21', '29'])
    assert cif_block['_struct_ref_seq.pdbx_seq_align_beg_ins_code'][4] == 'A'
    seq2 = iotbx.bioinformatics.sequence("MTTPSHLSDRYELGEILGFGGMSEVHLA")
    v = validation(pdb_hierarchy=pdb_in.construct_hierarchy(),
                   sequences=[seq2],
                   log=null_out(),
                   nproc=1)
    out = StringIO()
    v.show(out=out)
    assert contains_lines(
        out.getvalue(), """\
  1 residues not found in sequence
    residue IDs:  28""")
    try:
        v = validation(pdb_hierarchy=pdb_in.construct_hierarchy(),
                       sequences=[],
                       log=null_out(),
                       nproc=1)
    except AssertionError:
        pass
    else:
        raise Exception_expected
    cif_block = v.as_cif_block()
    assert list(cif_block['_struct_ref.pdbx_seq_one_letter_code']) == [
        'MTTPSHLSDRYELGEILGFGGMSEVHLA-'
    ]
    assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                        ['11', '14', '17', '21', '27'])
    assert approx_equal(cif_block['_struct_ref_seq.db_align_end'],
                        ['11', '14', '17', '21', '28'])
    #
    pdb_in2 = iotbx.pdb.input(source_info=None,
                              lines="""\
ATOM      2  CA  ARG A  10      -6.299  36.344   7.806  1.00 55.20           C
ATOM     25  CA  TYR A  11      -3.391  33.962   7.211  1.00 40.56           C
ATOM     46  CA  ALA A  12      -0.693  34.802   4.693  1.00 67.95           C
ATOM     56  CA  ALA A  13       0.811  31.422   3.858  1.00 57.97           C
ATOM     66  CA  GLY A  14       4.466  31.094   2.905  1.00 49.24           C
ATOM     73  CA  ALA A  15       7.163  28.421   2.671  1.00 54.70           C
ATOM     83  CA  ILE A  16       6.554  24.685   2.957  1.00 51.79           C
ATOM    102  CA  LEU A  17       7.691  23.612   6.406  1.00 42.30           C
TER
ATOM   1936  P     G B   2     -22.947 -23.615  15.323  1.00123.20           P
ATOM   1959  P     C B   3     -26.398 -26.111  19.062  1.00110.06           P
ATOM   1979  P     U B   4     -29.512 -30.638  21.164  1.00101.06           P
ATOM   1999  P     C B   5     -30.524 -36.109  21.527  1.00 92.76           P
ATOM   2019  P     U B   6     -28.684 -41.458  21.223  1.00 87.42           P
ATOM   2062  P     G B   8     -18.396 -45.415  21.903  1.00 80.35           P
ATOM   2085  P     A B   9     -13.852 -43.272  24.156  1.00 77.76           P
ATOM   2107  P     G B  10      -8.285 -44.242  26.815  1.00 79.86           P
END
""")
    seq3 = iotbx.bioinformatics.sequence("AGCUUUGGAG")
    v = validation(pdb_hierarchy=pdb_in2.construct_hierarchy(),
                   sequences=[seq2, seq3],
                   log=null_out(),
                   nproc=1,
                   extract_coordinates=True)
    out = StringIO()
    v.show(out=out)
    cif_block = v.as_cif_block()
    assert approx_equal(cif_block['_struct_ref.pdbx_seq_one_letter_code'],
                        ['MTTPSHLSDRYELGEILGFGGMSEVHLA', 'AGCUUUGGAG'])
    assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg'],
                        ['10', '14', '16', '2', '6', '8'])
    assert approx_equal(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end'],
                        ['11', '14', '17', '4', '6', '10'])
    assert (len(v.chains[0].get_outliers_table()) == 3)
    assert (len(v.get_table_data()) == 4)
    assert approx_equal(
        v.chains[0].get_mean_coordinate_for_alignment_range(11, 11),
        (-0.693, 34.802, 4.693))
    assert approx_equal(
        v.chains[0].get_mean_coordinate_for_alignment_range(11, 14),
        (2.93675, 31.43475, 3.53175))
    assert (v.chains[0].get_highlighted_residues() == [11, 12, 14])
    assert contains_lines(
        out.getvalue(), """\
  3 mismatches to sequence
    residue IDs:  12 13 15""")
    assert contains_lines(
        out.getvalue(), """\
  sequence identity: 87.50%
  2 residue(s) missing from PDB chain (1 at start, 0 at end)
  1 gap(s) in chain
  1 mismatches to sequence
    residue IDs:  5""")
    s = easy_pickle.dumps(v)
    seq4 = iotbx.bioinformatics.sequence("")
    try:
        v = validation(pdb_hierarchy=pdb_in2.construct_hierarchy(),
                       sequences=[seq4],
                       log=null_out(),
                       nproc=1,
                       extract_coordinates=True)
    except AssertionError:
        pass
    else:
        raise Exception_expected
    # check that nucleic acid chain doesn't get aligned against protein sequence
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM  18932  P  B DG D   1     -12.183  60.531  25.090  0.50364.79           P
ATOM  18963  P  B DG D   2      -9.738  55.258  20.689  0.50278.77           P
ATOM  18994  P  B DA D   3     -10.119  47.855  19.481  0.50355.17           P
ATOM  19025  P  B DT D   4     -13.664  42.707  21.119  0.50237.06           P
ATOM  19056  P  B DG D   5     -19.510  39.821  21.770  0.50255.45           P
ATOM  19088  P  B DA D   6     -26.096  40.001  21.038  0.50437.49           P
ATOM  19120  P  B DC D   7     -31.790  41.189  18.413  0.50210.00           P
ATOM  19149  P  B DG D   8     -34.639  41.306  12.582  0.50313.99           P
ATOM  19179  P  B DA D   9     -34.987  38.244   6.813  0.50158.92           P
ATOM  19210  P  B DT D  10     -32.560  35.160   1.082  0.50181.38           P
HETATM19241  P  BTSP D  11     -27.614  30.137   0.455  0.50508.17           P
""")
    sequences, _ = iotbx.bioinformatics.fasta_sequence_parse.parse(
        """>4GFH:A|PDBID|CHAIN|SEQUENCE
MSTEPVSASDKYQKISQLEHILKRPDTYIGSVETQEQLQWIYDEETDCMIEKNVTIVPGLFKIFDEILVNAADNKVRDPS
MKRIDVNIHAEEHTIEVKNDGKGIPIEIHNKENIYIPEMIFGHLLTSSNYDDDEKKVTGGRNGYGAKLCNIFSTEFILET
ADLNVGQKYVQKWENNMSICHPPKITSYKKGPSYTKVTFKPDLTRFGMKELDNDILGVMRRRVYDINGSVRDINVYLNGK
SLKIRNFKNYVELYLKSLEKKRQLDNGEDGAAKSDIPTILYERINNRWEVAFAVSDISFQQISFVNSIATTMGGTHVNYI
TDQIVKKISEILKKKKKKSVKSFQIKNNMFIFINCLIENPAFTSQTKEQLTTRVKDFGSRCEIPLEYINKIMKTDLATRM
FEIADANEENALKKSDGTRKSRITNYPKLEDANKAGTKEGYKCTLVLTEGDSALSLAVAGLAVVGRDYYGCYPLRGKMLN
VREASADQILKNAEIQAIKKIMGLQHRKKYEDTKSLRYGHLMIMTDQDHDGSHIKGLIINFLESSFPGLLDIQGFLLEFI
TPIIKVSITKPTKNTIAFYNMPDYEKWREEESHKFTWKQKYYKGLGTSLAQEVREYFSNLDRHLKIFHSLQGNDKDYIDL
AFSKKKADDRKEWLRQYEPGTVLDPTLKEIPISDFINKELILFSLADNIRSIPNVLDGFKPGQRKVLYGCFKKNLKSELK
VAQLAPYVSECTAYHHGEQSLAQTIIGLAQNFVGSNNIYLLLPNGAFGTRATGGKDAAAARYIYTELNKLTRKIFHPADD
PLYKYIQEDEKTVEPEWYLPILPMILVNGAEGIGTGWSTYIPPFNPLEIIKNIRHLMNDEELEQMHPWFRGWTGTIEEIE
PLRYRMYGRIEQIGDNVLEITELPARTWTSTIKEYLLLGLSGNDKIKPWIKDMEEQHDDNIKFIITLSPEEMAKTRKIGF
YERFKLISPISLMNMVAFDPHGKIKKYNSVNEILSEFYYVRLEYYQKRKDHMSERLQWEVEKYSFQVKFIKMIIEKELTV
TNKPRNAIIQELENLGFPRFNKEGKPYYGSPNDEIAEQINDVKGATSDEEDEESSHEDTENVINGPEELYGTYEYLLGMR
IWSLTKERYQKLLKQKQEKETELENLLKLSAKDIWNTDLKAFEVGYQEFLQRDAEAR
>4GFH:D|PDBID|CHAIN|SEQUENCE
GGATGACGATX
""")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=sequences,
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].n_missing == 0
    assert v.chains[0].n_missing_end == 0
    assert v.chains[0].n_missing_start == 0
    assert len(v.chains[0].alignment.matches()) == 11
    #
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM      2  CA  GLY A   1       1.367   0.551   0.300  1.00  7.71           C
ATOM      6  CA  CYS A   2       2.782   3.785   1.683  1.00  5.18           C
ATOM     12  CA  CYS A   3      -0.375   5.128   3.282  1.00  5.21           C
ATOM     18  CA  SER A   4      -0.870   2.048   5.492  1.00  7.19           C
ATOM     25  CA  LEU A   5       2.786   2.056   6.642  1.00  6.78           C
ATOM     33  CA  PRO A   6       3.212   4.746   9.312  1.00  7.03           C
ATOM     40  CA  PRO A   7       6.870   5.690   8.552  1.00  7.97           C
ATOM     47  CA  CYS A   8       6.021   6.070   4.855  1.00  6.48           C
ATOM     53  CA  ALA A   9       2.812   8.041   5.452  1.00  7.15           C
ATOM     58  CA  LEU A  10       4.739  10.382   7.748  1.00  8.36           C
ATOM     66  CA  SER A  11       7.292  11.200   5.016  1.00  7.00           C
ATOM     73  CA  ASN A  12       4.649  11.435   2.264  1.00  5.40           C
ATOM     81  CA  PRO A  13       1.879  13.433   3.968  1.00  5.97           C
ATOM     88  CA  ASP A  14       0.485  15.371   0.986  1.00  7.70           C
ATOM     96  CA  TYR A  15       0.565  12.245  -1.180  1.00  6.55           C
ATOM    108  CA  CYS A  16      -1.466  10.260   1.363  1.00  7.32           C
ATOM    113  N   NH2 A  17      -2.612  12.308   2.058  1.00  8.11           N
""")
    seq = iotbx.bioinformatics.sequence("GCCSLPPCALSNPDYCX")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=[seq],
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].n_missing == 0
    assert v.chains[0].n_missing_end == 0
    assert v.chains[0].n_missing_start == 0
    assert len(v.chains[0].alignment.matches()) == 17
    #
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM   2518  CA  PRO C   3      23.450  -5.848  45.723  1.00 85.24           C
ATOM   2525  CA  GLY C   4      20.066  -4.416  44.815  1.00 79.25           C
ATOM   2529  CA  PHE C   5      19.408  -0.913  46.032  1.00 77.13           C
ATOM   2540  CA  GLY C   6      17.384  -1.466  49.208  1.00 83.44           C
ATOM   2544  CA  GLN C   7      17.316  -5.259  49.606  1.00 89.25           C
ATOM   2553  CA  GLY C   8      19.061  -6.829  52.657  1.00 90.67           C
""")
    sequences, _ = iotbx.bioinformatics.fasta_sequence_parse.parse(
        """>1JN5:A|PDBID|CHAIN|SEQUENCE
MASVDFKTYVDQACRAAEEFVNVYYTTMDKRRRLLSRLYMGTATLVWNGNAVSGQESLSEFFEMLPSSEFQISVVDCQPV
HDEATPSQTTVLVVICGSVKFEGNKQRDFNQNFILTAQASPSNTVWKIASDCFRFQDWAS
>1JN5:B|PDBID|CHAIN|SEQUENCE
APPCKGSYFGTENLKSLVLHFLQQYYAIYDSGDRQGLLDAYHDGACCSLSIPFIPQNPARSSLAEYFKDSRNVKKLKDPT
LRFRLLKHTRLNVVAFLNELPKTQHDVNSFVVDISAQTSTLLCFSVNGVFKEVDGKSRDSLRAFTRTFIAVPASNSGLCI
VNDELFVRNASSEEIQRAFAMPAPTPSSSPVPTLSPEQQEMLQAFSTQSGMNLEWSQKCLQDNNWDYTRSAQAFTHLKAK
GEIPEVAFMK
>1JN5:C|PDBID|CHAIN|SEQUENCE
GQSPGFGQGGSV
""")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=sequences,
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].n_missing_start == 3
    assert v.chains[0].n_missing_end == 3
    assert v.chains[0].identity == 1.0
    assert v.chains[0].alignment.match_codes == 'iiimmmmmmiii'
    #
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM      2  CA  ALA A   2      -8.453  57.214 -12.754  1.00 52.95           C
ATOM      7  CA  LEU A   3      -8.574  59.274  -9.471  1.00 24.33           C
ATOM     15  CA  ARG A   4     -12.178  60.092  -8.575  1.00 28.40           C
ATOM     26  CA  GLY A   5     -14.170  61.485  -5.667  1.00 26.54           C
ATOM     30  CA  THR A   6     -17.784  60.743  -4.783  1.00 31.78           C
ATOM     37  CA  VAL A   7     -19.080  64.405  -4.464  1.00 21.31           C
""")
    seq = iotbx.bioinformatics.sequence("XALRGTV")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=[seq],
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].n_missing_start == 1
    assert v.chains[0].n_missing_end == 0
    assert v.chains[0].identity == 1.0
    assert v.chains[0].alignment.match_codes == 'immmmmm'
    #
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM   2171  CA  ASP I 355       5.591 -11.903   1.133  1.00 41.60           C
ATOM   2175  CA  PHE I 356       7.082  -8.454   0.828  1.00 39.82           C
ATOM   2186  CA  GLU I 357       5.814  -6.112  -1.877  1.00 41.12           C
ATOM   2195  CA  GLU I 358       8.623  -5.111  -4.219  1.00 42.70           C
ATOM   2199  CA  ILE I 359      10.346  -1.867  -3.363  1.00 43.32           C
ATOM   2207  CA  PRO I 360      11.658   0.659  -5.880  1.00 44.86           C
ATOM   2214  CA  GLU I 361      14.921  -0.125  -7.592  1.00 44.32           C
ATOM   2219  CA  GLU I 362      15.848   3.489  -6.866  1.00 44.27           C
HETATM 2224  CA  TYS I 363      16.482   2.005  -3.448  1.00 44.52           C
""")
    seq = iotbx.bioinformatics.sequence("NGDFEEIPEEYL")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=[seq],
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].n_missing_start == 2
    assert v.chains[0].n_missing_end == 1
    assert v.chains[0].identity == 1.0
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM    450  CA  ASN A   1      37.242  41.665  44.160  1.00 35.89           C
ATOM    458  CA  GLY A   2      37.796  38.269  42.523  1.00 30.13           C
HETATM  463  CA AMSE A   3      35.878  39.005  39.326  0.54 22.83           C
HETATM  464  CA BMSE A   3      35.892  39.018  39.323  0.46 22.96           C
ATOM    478  CA  ILE A   4      37.580  38.048  36.061  1.00 22.00           C
ATOM    486  CA  SER A   5      37.593  40.843  33.476  1.00 18.73           C
ATOM    819  CA  ALA A   8      25.982  34.781  27.220  1.00 18.43           C
ATOM    824  CA  ALA A   9      23.292  32.475  28.614  1.00 19.60           C
HETATM  830  CA BMSE A  10      22.793  30.814  25.223  0.41 22.60           C
HETATM  831  CA CMSE A  10      22.801  30.850  25.208  0.59 22.54           C
ATOM    845  CA  GLU A  11      26.504  30.054  24.966  1.00 25.19           C
ATOM    854  CA  GLY A  12      25.907  28.394  28.320  1.00 38.88           C
""")
    seq = iotbx.bioinformatics.sequence("NGMISAAAAMEG")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=[seq],
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    assert v.chains[0].alignment.a == 'NGMISXXAAMEG'
    assert v.chains[0].alignment.b == 'NGMISAAAAMEG'
    pdb_in = iotbx.pdb.input(source_info=None,
                             lines="""\
ATOM   4615  CA  ALA C   1       1.000   1.000   1.000  1.00 10.00
ATOM   4622  CA  ALA C   2       1.000   1.000   1.000  1.00 10.00
ATOM   4627  CA  ALA C   3       1.000   1.000   1.000  1.00 10.00
ATOM   4634  CA  ALA C   4       1.000   1.000   1.000  1.00 10.00
ATOM   4646  CA  ALA C   5       1.000   1.000   1.000  1.00 10.00
ATOM   4658  CA  ALA C   6       1.000   1.000   1.000  1.00 10.00
ATOM   4664  CA  ALA C   7       1.000   1.000   1.000  1.00 10.00
ATOM   4669  CA  ALA C   8       1.000   1.000   1.000  1.00 10.00
ATOM   4680  CA  ARG C   9       1.000   1.000   1.000  1.00 10.00
ATOM   4690  CA  GLY C  10       1.000   1.000   1.000  1.00 10.00
ATOM   4698  CA  PRO C  11       1.000   1.000   1.000  1.00 10.00
ATOM   4705  CA  LYS C  12       1.000   1.000   1.000  1.00 10.00
ATOM   4712  CA  TRP C  13       1.000   1.000   1.000  1.00 10.00
ATOM   4726  CA  GLU C  14       1.000   1.000   1.000  1.00 10.00
ATOM   4738  CA  SER C  15       1.000   1.000   1.000  1.00 10.00
ATOM   4744  CA  THR C  16       1.000   1.000   1.000  1.00 10.00
ATOM   4751  CA  GLY C  17       1.000   1.000   1.000  1.00 10.00
ATOM   4755  CA  TYR C  18       1.000   1.000   1.000  1.00 10.00
ATOM   4767  CA  PHE C  19       1.000   1.000   1.000  1.00 10.00
ATOM   4778  CA  ALA C  20       1.000   1.000   1.000  1.00 10.00
ATOM   4786  CA  ALA C  21       1.000   1.000   1.000  1.00 10.00
ATOM   4798  CA  TRP C  22       1.000   1.000   1.000  1.00 10.00
ATOM   4812  CA  GLY C  23       1.000   1.000   1.000  1.00 10.00
ATOM   4816  CA  GLN C  24       1.000   1.000   1.000  1.00 10.00
ATOM   4822  CA  GLY C  25       1.000   1.000   1.000  1.00 10.00
ATOM   4826  CA  THR C  26       1.000   1.000   1.000  1.00 10.00
ATOM   4833  CA  LEU C  27       1.000   1.000   1.000  1.00 10.00
ATOM   4841  CA  VAL C  28       1.000   1.000   1.000  1.00 10.00
ATOM   4848  CA  THR C  29       1.000   1.000   1.000  1.00 10.00
ATOM   4855  CA  VAL C  30       1.000   1.000   1.000  1.00 10.00
ATOM   4862  CA  SER C  31       1.000   1.000   1.000  1.00 10.00
ATOM   4868  CA  SER C  32       1.000   1.000   1.000  1.00 10.00
END
""")
    seq = iotbx.bioinformatics.sequence(
        "AAAAAAAARGKWESPAALLKKAAWCSGTLVTVSSASAPKWKSTSGCYFAAPWNKRALRVTVLQSS")
    v = validation(
        pdb_hierarchy=pdb_in.construct_hierarchy(),
        sequences=[seq],
        log=null_out(),
        nproc=1,
    )
    out = StringIO()
    v.show(out=out)
    # all tests below here have additional dependencies
    if (not libtbx.env.has_module("ksdssp")):
        print "Skipping advanced tests (require ksdssp module)"
        return
    pdb_file = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/1ywf.pdb", test=os.path.isfile)
    if (pdb_file is not None):
        seq = iotbx.bioinformatics.sequence(
            "MGSSHHHHHHSSGLVPRGSHMAVRELPGAWNFRDVADTATALRPGRLFRSSELSRLDDAGRATLRRLGITDVADLRSSREVARRGPGRVPDGIDVHLLPFPDLADDDADDSAPHETAFKRLLTNDGSNGESGESSQSINDAATRYMTDEYRQFPTRNGAQRALHRVVTLLAAGRPVLTHCFAGKDRTGFVVALVLEAVGLDRDVIVADYLRSNDSVPQLRARISEMIQQRFDTELAPEVVTFTKARLSDGVLGVRAEYLAAARQTIDETYGSLGGYLRDAGISQATVNRMRGVLLG"
        )
        pdb_in = file_reader.any_file(pdb_file, force_type="pdb")
        hierarchy = pdb_in.file_object.hierarchy
        v = validation(pdb_hierarchy=hierarchy,
                       sequences=[seq],
                       log=null_out(),
                       nproc=1,
                       include_secondary_structure=True,
                       extract_coordinates=True)
        out = StringIO()
        v.show(out=out)
        aln1, aln2, ss = v.chains[0].get_alignment(include_sec_str=True)
        assert ("HHH" in ss) and ("LLL" in ss) and ("---" in ss)
        cif_block = v.as_cif_block()
        assert cif_block[
            '_struct_ref.pdbx_seq_one_letter_code'] == seq.sequence
        assert list(cif_block['_struct_ref_seq.pdbx_auth_seq_align_beg']) == [
            '4', '117'
        ]
        assert list(cif_block['_struct_ref_seq.pdbx_auth_seq_align_end']) == [
            '85', '275'
        ]
        assert list(cif_block['_struct_ref_seq.seq_align_beg']) == ['1', '114']
        assert list(
            cif_block['_struct_ref_seq.seq_align_end']) == ['82', '272']
        # determine relative counts of sequences and chains
        n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                      sequences=[seq] * 4,
                                      copies_from_xtriage=4,
                                      out=null_out())
        assert (n_seq == 1)
        hierarchy = hierarchy.deep_copy()
        chain2 = hierarchy.only_model().chains()[0].detached_copy()
        hierarchy.only_model().append_chain(chain2)
        n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                      sequences=[seq] * 4,
                                      copies_from_xtriage=2,
                                      out=null_out())
        assert (n_seq == 1)
        n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                      sequences=[seq],
                                      copies_from_xtriage=2,
                                      out=null_out())
        assert (n_seq == 4)
        try:
            n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                          sequences=[seq] * 3,
                                          copies_from_xtriage=2,
                                          out=null_out())
        except Sorry, s:
            assert ("round number" in str(s))
        else:
            raise Exception_expected
        n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                      sequences=[seq] * 3,
                                      copies_from_xtriage=2,
                                      force_accept_composition=True,
                                      out=null_out())
        assert (n_seq == 1)
        try:
            n_seq = get_sequence_n_copies(pdb_hierarchy=hierarchy,
                                          sequences=[seq] * 4,
                                          copies_from_xtriage=1,
                                          out=null_out())
        except Sorry, s:
            assert ("less than" in str(s))
예제 #37
0
def test_goniometer():
    """A test class for the goniometer class."""

    axis = (1, 0, 0)
    fixed = (1, 0, 0, 0, 1, 0, 0, 0, 1)

    xg = Goniometer(axis, fixed)

    assert len(xg.get_rotation_axis()) == 3
    assert len(xg.get_fixed_rotation()) == 9

    _compare_tuples(xg.get_rotation_axis(), axis)
    _compare_tuples(xg.get_fixed_rotation(), fixed)

    single = GoniometerFactory.single_axis()

    assert len(single.get_rotation_axis()) == 3
    assert len(single.get_fixed_rotation()) == 9

    _compare_tuples(single.get_rotation_axis(), axis)
    _compare_tuples(single.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9
    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 0.0, 0.0, "-y", "phi")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    _compare_tuples(kappa.get_fixed_rotation(), fixed)

    kappa = GoniometerFactory.kappa(50.0, 0.0, 30.0, 0.0, "-y", "omega")

    assert len(kappa.get_rotation_axis()) == 3
    assert len(kappa.get_fixed_rotation()) == 9

    _compare_tuples(kappa.get_rotation_axis(), axis)
    with pytest.raises(AssertionError):
        _compare_tuples(kappa.get_fixed_rotation(), fixed)

    image = Path(__file__).parent / "phi_scan_001.cbf"
    assert GoniometerFactory.imgCIF(str(image))

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 0.0, "-y", "phi")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2

    image = Path(__file__).parent / "omega_scan.cbf"
    assert GoniometerFactory.imgCIF(str(image))

    kappa = GoniometerFactory.kappa(50.0, -10.0, 30.0, 20.0, "-y", "omega")

    s = easy_pickle.dumps(kappa)
    kappa2 = easy_pickle.loads(s)
    assert kappa == kappa2
예제 #38
0
def exercise_simple () :
  # extracted from 1lyz, with hydrogens from reduce
  pdb_in = """
ATOM      1  N   LYS A   1       3.296   9.888  10.739  1.00  7.00           N
ATOM      2  CA  LYS A   1       2.439  10.217   9.791  1.00  6.00           C
ATOM      3  C   LYS A   1       2.439  11.997   9.160  1.00  6.00           C
ATOM      4  O   LYS A   1       2.637  12.656  10.107  1.00  8.00           O
ATOM      5  CB  LYS A   1       0.659  10.086   8.844  1.00  6.00           C
ATOM      6  CG  LYS A   1       0.198  10.415   8.086  1.00  6.00           C
ATOM      7  CD  LYS A   1      -1.187  10.086   8.212  1.00  6.00           C
ATOM      8  CE  LYS A   1      -2.175  10.086   7.264  1.00  6.00           C
ATOM      9  NZ  LYS A   1      -3.527   9.869   7.288  1.00  7.00           N
ATOM      0  H1  LYS A   1       3.156   9.045  10.986  1.00  7.00           H
ATOM      0  H2  LYS A   1       4.127   9.972  10.431  1.00  7.00           H
ATOM      0  H3  LYS A   1       3.184  10.425  11.440  1.00  7.00           H
ATOM      0  HA  LYS A   1       2.772   9.314   9.912  1.00  6.00           H
ATOM      0  HB2 LYS A   1       0.584   9.128   8.712  1.00  6.00           H
ATOM      0  HB3 LYS A   1       0.046  10.323   9.557  1.00  6.00           H
ATOM      0  HG2 LYS A   1       0.310  11.376   8.015  1.00  6.00           H
ATOM      0  HG3 LYS A   1       0.563  10.027   7.276  1.00  6.00           H
ATOM      0  HD2 LYS A   1      -1.193   9.186   8.573  1.00  6.00           H
ATOM      0  HD3 LYS A   1      -1.516  10.674   8.910  1.00  6.00           H
ATOM      0  HE2 LYS A   1      -2.097  10.964   6.860  1.00  6.00           H
ATOM      0  HE3 LYS A   1      -1.857   9.444   6.610  1.00  6.00           H
ATOM      0  HZ1 LYS A   1      -3.725   9.170   6.774  1.00  7.00           H
ATOM      0  HZ2 LYS A   1      -3.787   9.706   8.123  1.00  7.00           H
ATOM      0  HZ3 LYS A   1      -3.949  10.590   6.982  1.00  7.00           H
ATOM     10  N   VAL A   2       2.637  12.722   7.707  1.00  7.00           N
ATOM     11  CA  VAL A   2       2.307  14.172   7.580  1.00  6.00           C
ATOM     12  C   VAL A   2       0.857  14.041   6.949  1.00  6.00           C
ATOM     13  O   VAL A   2       0.659  13.843   5.875  1.00  8.00           O
ATOM     14  CB  VAL A   2       3.625  14.172   6.759  1.00  6.00           C
ATOM     15  CG1 VAL A   2       3.494  15.491   6.317  1.00  6.00           C
ATOM     16  CG2 VAL A   2       4.746  13.843   7.580  1.00  6.00           C
ATOM      0  H   VAL A   2       2.920  12.338   6.992  1.00  7.00           H
ATOM      0  HA  VAL A   2       2.195  14.925   8.181  1.00  6.00           H
ATOM      0  HB  VAL A   2       3.767  13.528   6.048  1.00  6.00           H
ATOM      0 HG11 VAL A   2       4.250  15.721   5.755  1.00  6.00           H
ATOM      0 HG12 VAL A   2       2.674  15.582   5.808  1.00  6.00           H
ATOM      0 HG13 VAL A   2       3.467  16.087   7.081  1.00  6.00           H
ATOM      0 HG21 VAL A   2       5.554  13.850   7.043  1.00  6.00           H
ATOM      0 HG22 VAL A   2       4.827  14.495   8.294  1.00  6.00           H
ATOM      0 HG23 VAL A   2       4.620  12.960   7.962  1.00  6.00           H
END
"""
  pdb_file = "tst_validate_restraints_simple.pdb"
  open(pdb_file, "w").write(pdb_in)
  v1 = run_validation(pdb_file, ignore_hd=True)
  out1 = StringIO()
  v1.show(out=out1)
  assert ("""
                       ----------Chiral volumes----------

atoms                   ideal    model    delta   sigma  residual   deviation
 A   1  LYS  CA
 A   1  LYS  N
 A   1  LYS  C
 A   1  LYS  CB          2.57     1.12     1.45  2.00e-01  5.25e+01   7.2*sigma
""" in "\n".join([ l.rstrip() for l in out1.getvalue().splitlines() ]))
  s = easy_pickle.dumps(v1)
  v1p = easy_pickle.loads(s)
  out1p = StringIO()
  v1p.show(out=out1p)
  assert (out1.getvalue() == out1p.getvalue())
  v2 = run_validation(pdb_file, ignore_hd=False)
  out2 = StringIO()
  v2.show(out=out2)
  assert (out2.getvalue() != out1.getvalue())
  assert ("""\
 A   1  LYS  HA        110.00    57.00    53.00  3.00e+00  3.12e+02  17.7*sigma
 A   2  VAL  N
 A   2  VAL  CA
""" in "\n".join([ l.rstrip() for l in out2.getvalue().splitlines() ]))
  #
  # C-alpha-only model (from 3b5d)
  pdb_raw = """\
CRYST1  115.100   43.700   76.400  90.00 108.10  90.00 C 1 2 1       8
ATOM      1  CA  TYR A   6      -7.551 -11.355 -17.946  1.00148.04           C
ATOM      2  CA  LEU A   7      -8.052  -8.804 -20.730  1.00310.75           C
ATOM      3  CA  GLY A   8     -10.874  -6.691 -19.353  1.00158.95           C
ATOM      4  CA  GLY A   9      -9.359  -7.332 -15.966  1.00217.68           C
ATOM      5  CA  ALA A  10      -5.806  -6.508 -16.946  1.00239.12           C
ATOM      6  CA  ILE A  11      -7.024  -3.514 -18.905  1.00103.16           C
ATOM      7  CA  LEU A  12     -10.023  -2.071 -17.056  1.00230.80           C
ATOM      8  CA  ALA A  13      -7.313  -1.820 -14.420  1.00141.04           C
"""
  pdb_file = "tst_validate_restraints_calpha.pdb"
  open(pdb_file, "w").write(pdb_raw)
  v1 = run_validation(pdb_file, ignore_hd=True)
def test_multi_axis_goniometer():
  from libtbx.test_utils import approx_equal
  from scitbx.array_family import flex

  alpha = 50
  omega = -10
  kappa = 30
  phi = 20
  direction = '-y'

  kappa_omega_scan = goniometer_factory.kappa(
    alpha, omega, kappa, phi, direction, 'omega')
  axes = (kappa_omega_scan.get_phi_axis(), kappa_omega_scan.get_kappa_axis(),
          kappa_omega_scan.get_omega_axis())
  angles = (kappa_omega_scan.get_phi_angle(), kappa_omega_scan.get_kappa_angle(),
            kappa_omega_scan.get_omega_angle())

  # First test a kappa goniometer with omega as the scan axis
  axes = flex.vec3_double(axes)
  angles = flex.double(angles)
  scan_axis = 2

  multi_axis_omega_scan = goniometer_factory.multi_axis(axes, angles, scan_axis)
  assert approx_equal(multi_axis_omega_scan.get_fixed_rotation(), kappa_omega_scan.get_fixed_rotation())
  assert approx_equal(multi_axis_omega_scan.get_rotation_axis(), kappa_omega_scan.get_rotation_axis())

  recycle_omega = MultiAxisGoniometer.from_dict(multi_axis_omega_scan.to_dict())
  assert approx_equal(recycle_omega.get_axes(), multi_axis_omega_scan.get_axes())
  assert approx_equal(recycle_omega.get_angles(), multi_axis_omega_scan.get_angles())
  assert recycle_omega.get_scan_axis() == multi_axis_omega_scan.get_scan_axis()

  # Now test a kappa goniometer with phi as the scan axis
  kappa_phi_scan = goniometer_factory.kappa(
    alpha, omega, kappa, phi, direction, 'phi')

  scan_axis = 0
  multi_axis_phi_scan = goniometer_factory.multi_axis(axes, angles, scan_axis)
  assert approx_equal(multi_axis_phi_scan.get_fixed_rotation(), kappa_phi_scan.get_fixed_rotation())
  assert approx_equal(multi_axis_phi_scan.get_rotation_axis(), kappa_phi_scan.get_rotation_axis())

  recycle_phi = MultiAxisGoniometer.from_dict(multi_axis_phi_scan.to_dict())
  assert approx_equal(recycle_phi.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle_phi.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle_phi.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

  s = easy_pickle.dumps(multi_axis_phi_scan)
  recycle = easy_pickle.loads(s)
  assert recycle == multi_axis_phi_scan

  assert approx_equal(recycle.get_axes(), multi_axis_phi_scan.get_axes())
  assert approx_equal(recycle.get_angles(), multi_axis_phi_scan.get_angles())
  assert recycle.get_scan_axis() == multi_axis_phi_scan.get_scan_axis()

  # Check exception is raised if scan axis is out range
  try: goniometer_factory.multi_axis(axes, angles, 3)
  except RuntimeError, e: pass
  else: raise Exception_expected

  # Single axis is just a special case of a multi axis goniometer
  single_axis = goniometer_factory.multi_axis(
    flex.vec3_double(((1,0,0),)), flex.double((0,)), 0)
  assert single_axis.get_fixed_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_setting_rotation() == (1,0,0,0,1,0,0,0,1)
  assert single_axis.get_rotation_axis() == (1,0,0)

  print 'OK'
예제 #40
0
def exercise_rotalyze():
    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/jcm.pdb", test=os.path.isfile)
    if (regression_pdb is None):
        print "Skipping exercise_rotalyze(): input pdb (jcm.pdb) not available"
        return
    if (find_rotarama_data_dir(optional=True) is None):
        print "Skipping exercise_rotalyze(): rotarama_data directory not available"
        return
    pdb_in = file_reader.any_file(file_name=regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    pdb_io = pdb.input(file_name=regression_pdb)
    r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=True)
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    output = out.getvalue()
    assert output.count("OUTLIER") == 246, output.count("OUTLIER")
    assert output.count(":") == 984, output.count(":")
    output_lines = output.splitlines()
    assert len(output_lines) == 123
    for lines in output_lines:
        assert float(lines[12:15]) <= 1.0

    r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False)
    for unpickle in [False, True]:
        if unpickle:
            r = loads(dumps(r))
        out = StringIO()
        r.show_old_output(out=out, verbose=False)
        for outlier in r.results:
            assert (len(outlier.xyz) == 3)
        output = out.getvalue()
        assert output.count("OUTLIER") == 246
        assert output.count(":") == 5144, output.count(":")
        assert output.count("p") == 120
        assert output.count("m") == 324
        assert output.count("t") == 486
        output_lines = output.splitlines()
        #for line in output_lines:
        #  print line
        #STOP()
        assert len(output_lines) == 643
        line_indices = [0, 1, 2, 42, 43, 168, 169, 450, 587, 394, 641, 642]

        #    top500 version
        line_values = [
            " A  14  MET:1.00:3.3:29.2:173.3:287.9::Favored:ptm",
            " A  15  SER:1.00:0.1:229.0::::OUTLIER:OUTLIER",
            " A  16  SER:1.00:4.2:277.9::::Favored:m",
            " A  58  ASN:1.00:2.0:252.4:343.6:::Favored:m-20",
            " A  59  ILE:1.00:2.0:84.2:186.7:::Allowed:pt",
            " A 202  GLU:1.00:0.4:272.7:65.9:287.8::OUTLIER:OUTLIER",
            " A 203  ILE:1.00:5.0:292.9:199.6:::Favored:mt",
            " B 154  THR:1.00:0.1:356.0::::OUTLIER:OUTLIER",
            " B 316  TYR:1.00:5.4:153.7:68.6:::Favored:t80",
            " B  86  ASP:1.00:2.2:321.4:145.1:::Favored:m-20",
            " B 377  GLU:1.00:45.3:311.7:166.2:160.1::Favored:mt-10",
            " B 378  THR:1.00:23.5:309.4::::Favored:m"
        ]
        #    top8000 version
        line_values = [
            " A  14  MET:1.00:1.3:29.2:173.3:287.9::Allowed:ptm",
            " A  15  SER:1.00:0.1:229.0::::OUTLIER:OUTLIER",
            " A  16  SER:1.00:3.0:277.9::::Favored:m",
            " A  58  ASN:1.00:1.0:252.4:343.6:::Allowed:m-40",
            " A  59  ILE:1.00:0.5:84.2:186.7:::Allowed:pt",
            " A 202  GLU:1.00:0.0:272.7:65.9:287.8::OUTLIER:OUTLIER",
            " A 203  ILE:1.00:1.0:292.9:199.6:::Allowed:mt",
            " B 154  THR:1.00:0.0:356.0::::OUTLIER:OUTLIER",
            " B 316  TYR:1.00:4.1:153.7:68.6:::Favored:t80",
            " B  86  ASP:1.00:0.4:321.4:145.1:::Allowed:m-30",
            " B 377  GLU:1.00:15.0:311.7:166.2:160.1::Favored:mt-10",
            " B 378  THR:1.00:17.0:309.4::::Favored:m",
        ]
        for idx, val in zip(line_indices, line_values):
            assert (output_lines[idx] == val), (idx, output_lines[idx])

    regression_pdb = libtbx.env.find_in_repositories(
        relative_path="phenix_regression/pdb/pdb1jxt.ent", test=os.path.isfile)
    if (regression_pdb is None):
        print "Skipping exercise_ramalyze(): input pdb (pdb1jxt.ent) not available"
        return
    pdb_in = file_reader.any_file(file_name=regression_pdb)
    hierarchy = pdb_in.file_object.hierarchy
    pdb_io = pdb.input(file_name=regression_pdb)
    r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=True)
    out = StringIO()
    r.show_old_output(out=out, verbose=False)
    output = out.getvalue().strip()
    assert output == ""

    r = rotalyze.rotalyze(pdb_hierarchy=hierarchy, outliers_only=False)
    for unpickle in [False, True]:
        if unpickle:
            r = loads(dumps(r))
        out = StringIO()
        r.show_old_output(out=out, verbose=False)
        output = out.getvalue()
        assert not show_diff(
            output, """\
 A   1  THR:1.00:95.4:299.5::::Favored:m
 A   2 ATHR:0.67:49.5:56.1::::Favored:p
 A   2 BTHR:0.33:90.4:298.1::::Favored:m
 A   3  CYS:1.00:12.9:310.5::::Favored:m
 A   4  CYS:1.00:91.6:293.1::::Favored:m
 A   5  PRO:1.00:78.8:30.2:319.7:33.8::Favored:Cg_endo
 A   6  SER:1.00:90.1:68.4::::Favored:p
 A   7 AILE:0.45:49.6:290.8:178.2:::Favored:mt
 A   7 BILE:0.55:6.5:284.4:298.4:::Favored:mm
 A   8 AVAL:0.50:1.1:156.7::::Allowed:t
 A   8 BVAL:0.30:5.1:71.3::::Favored:p
 A   8 CVAL:0.20:69.8:172.1::::Favored:t
 A  10 AARG:0.65:24.7:176.8:66.5:63.9:180.0:Favored:tpp-160
 A  10 BARG:0.35:17.5:176.8:72.8:66.4:171.9:Favored:tpp-160
 A  11  SER:1.00:51.6:300.9::::Favored:m
 A  12 AASN:0.50:93.9:286.1:343.8:::Favored:m-40
 A  12 BASN:0.50:98.9:288.4:337.6:::Favored:m-40
 A  13 APHE:0.65:45.1:187.2:276.4:::Favored:t80
 A  13 BPHE:0.35:86.1:179.6:263.1:::Favored:t80
 A  14  ASN:1.00:95.2:289.6:333.0:::Favored:m-40
 A  15  VAL:1.00:42.3:168.2::::Favored:t
 A  16  CYS:1.00:40.8:176.5::::Favored:t
 A  17  ARG:1.00:21.4:289.7:282.8:288.6:158.7:Favored:mmm160
 A  18  LEU:1.00:65.0:287.2:173.3:::Favored:mt
 A  19  PRO:1.00:43.6:24.4:324.8:31.6::Favored:Cg_endo
 A  21  THR:1.00:5.7:314.0::::Favored:m
 A  22 APRO:0.55:87.5:333.5:34.0:333.8::Favored:Cg_exo
 A  23 AGLU:0.50:86.9:290.9:187.1:341.8::Favored:mt-10
 A  23 BGLU:0.50:91.7:292.0:183.8:339.2::Favored:mt-10
 A  25 ALEU:0.50:95.7:294.4:173.6:::Favored:mt
 A  26  CYS:1.00:83.0:295.0::::Favored:m
 A  28  THR:1.00:29.6:52.9::::Favored:p
 A  29 ATYR:0.65:18.5:161.8:67.8:::Favored:t80
 A  29 BTYR:0.35:0.4:191.3:322.7:::Allowed:t80
 A  30 ATHR:0.70:60.8:57.4::::Favored:p
 A  30 BTHR:0.30:6.6:78.1::::Favored:p
 A  32  CYS:1.00:61.4:301.7::::Favored:m
 A  33  ILE:1.00:36.6:66.5:173.4:::Favored:pt
 A  34 AILE:0.70:60.9:303.6:167.6:::Favored:mt
 A  34 BILE:0.30:31.4:308.5:296.8:::Favored:mm
 A  35  ILE:1.00:45.6:62.4:170.0:::Favored:pt
 A  36  PRO:1.00:36.2:22.5:330.5:24.8::Favored:Cg_endo
 A  39 ATHR:0.70:14.0:311.0::::Favored:m
 A  39 BTHR:0.30:13.1:288.8::::Favored:m
 A  40  CYS:1.00:81.4:294.4::::Favored:m
 A  41  PRO:1.00:35.4:34.4:317.5:33.1::Favored:Cg_endo
 A  43 AASP:0.75:24.8:56.5:340.3:::Favored:p0
 A  43 BASP:0.25:43.2:59.6:349.3:::Favored:p0
 A  44  TYR:1.00:85.3:290.9:85.1:::Favored:m-80
 A  46  ASN:1.00:38.7:301.6:117.9:::Favored:m110
""")
예제 #41
0
def exercise_1 () :
  pdb_raw = """\
ATOM   1134  N   LYS A  82       5.933  36.285  21.572  1.00 70.94           N
ATOM   1135  CA  LYS A  82       6.564  37.423  20.931  1.00 76.69           C
ATOM   1136  C   LYS A  82       5.553  38.547  20.756  1.00 78.75           C
ATOM   1137  O   LYS A  82       5.325  39.038  19.654  1.00 86.47           O
ATOM   1138  CB  LYS A  82       7.179  37.024  19.583  1.00 82.32           C
ATOM   1139  CG  LYS A  82       8.190  38.035  19.048  0.00 70.34           C
ATOM   1140  CD  LYS A  82       9.429  38.129  19.944  0.00 67.69           C
ATOM   1141  CE  LYS A  82       9.983  39.545  20.014  0.00 64.44           C
ATOM   1142  NZ  LYS A  82      10.933  39.832  18.908  0.00 61.45           N
ATOM   1143  H   LYS A  82       5.139  36.115  21.291  1.00 85.12           H
ATOM   1144  HA  LYS A  82       7.279  37.749  21.501  1.00 92.03           H
ATOM   1145  HB2 LYS A  82       6.469  36.939  18.928  1.00 98.78           H
ATOM   1146  HB3 LYS A  82       7.636  36.175  19.687  1.00 98.78           H
ATOM   1147  HG2 LYS A  82       8.476  37.762  18.163  0.00 84.41           H
ATOM   1148  HG3 LYS A  82       7.775  38.912  19.011  0.00 84.41           H
ATOM   1149  HD2 LYS A  82       9.193  37.853  20.843  0.00 81.23           H
ATOM   1150  HD3 LYS A  82      10.122  37.551  19.589  0.00 81.23           H
ATOM   1151  HE2 LYS A  82       9.249  40.177  19.952  0.00 77.33           H
ATOM   1152  HE3 LYS A  82      10.453  39.662  20.854  0.00 77.33           H
ATOM   1153  HZ1 LYS A  82      11.237  40.666  18.977  0.00 73.75           H
ATOM   1154  HZ2 LYS A  82      10.523  39.738  18.123  0.00 73.75           H
ATOM   1155  HZ3 LYS A  82      11.621  39.269  18.944  0.00 73.75           H
ATOM   1156  N   LYS A  83       4.936  38.927  21.866  1.00 75.79           N
ATOM   1157  CA  LYS A  83       4.177  40.172  21.966  1.00 82.80           C
ATOM   1158  C   LYS A  83       4.081  40.508  23.460  1.00 86.23           C
ATOM   1159  O   LYS A  83       2.978  40.521  24.017  1.00 79.81           O
ATOM   1160  CB  LYS A  83       2.790  40.044  21.332  1.00 79.16           C
ATOM   1161  CG  LYS A  83       2.038  41.342  21.175  0.00 70.42           C
ATOM   1162  CD  LYS A  83       2.072  41.803  19.735  0.00 66.90           C
ATOM   1163  CE  LYS A  83       1.295  43.089  19.552  0.00 62.46           C
ATOM   1164  NZ  LYS A  83       1.004  43.350  18.118  0.00 60.73           N
ATOM   1165  H   LYS A  83       4.940  38.470  22.594  1.00 90.95           H
ATOM   1166  HA  LYS A  83       4.658  40.885  21.518  1.00 99.36           H
ATOM   1167  HB2 LYS A  83       2.251  39.459  21.887  1.00 95.00           H
ATOM   1168  HB3 LYS A  83       2.890  39.655  20.449  1.00 95.00           H
ATOM   1169  HG2 LYS A  83       1.113  41.213  21.435  0.00 84.51           H
ATOM   1170  HG3 LYS A  83       2.453  42.024  21.726  0.00 84.51           H
ATOM   1171  HD2 LYS A  83       2.992  41.962  19.471  0.00 80.28           H
ATOM   1172  HD3 LYS A  83       1.672  41.123  19.171  0.00 80.28           H
ATOM   1173  HE2 LYS A  83       0.452  43.024  20.027  0.00 74.95           H
ATOM   1174  HE3 LYS A  83       1.818  43.830  19.896  0.00 74.95           H
ATOM   1175  HZ1 LYS A  83       0.521  42.683  17.780  0.00 72.87           H
ATOM   1176  HZ2 LYS A  83       1.764  43.417  17.661  0.00 72.87           H
ATOM   1177  HZ3 LYS A  83       0.548  44.109  18.034  0.00 72.87           H
ATOM   3630  N   ASN A 242      -5.454  -3.027   1.145  0.00 67.69           N
ATOM   3631  CA  ASN A 242      -4.759  -2.535  -0.037  0.00 65.44           C
ATOM   3632  C   ASN A 242      -5.734  -2.397  -1.208  0.00 63.57           C
ATOM   3633  O   ASN A 242      -6.425  -3.357  -1.552  0.00 63.94           O
ATOM   3634  CB  ASN A 242      -3.626  -3.503  -0.392  0.00 63.13           C
ATOM   3635  CG  ASN A 242      -2.802  -3.044  -1.576  0.00 63.58           C
ATOM   3636  OD1 ASN A 242      -2.524  -1.862  -1.731  0.00 65.52           O
ATOM   3637  ND2 ASN A 242      -2.399  -3.988  -2.416  0.00 62.17           N
ATOM   3638  H   ASN A 242      -5.562  -3.880   1.129  0.00 81.22           H
ATOM   3639  HA  ASN A 242      -4.375  -1.665   0.151  0.00 78.53           H
ATOM   3640  HB2 ASN A 242      -3.032  -3.587   0.370  0.00 75.76           H
ATOM   3641  HB3 ASN A 242      -4.007  -4.368  -0.611  0.00 75.76           H
ATOM   3642 HD21 ASN A 242      -1.929  -3.779  -3.104  0.00 74.60           H
ATOM   3643 HD22 ASN A 242      -2.609  -4.810  -2.272  0.00 74.60           H
ATOM      2  CA ALYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB ALYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      2  CA BLYS A  32      10.574   8.177  11.768  0.40 71.49           C
ATOM      3  CB BLYS A  32       9.197   8.686  12.246  0.40 74.71           C
ATOM      5  CA AVAL A  33      11.708   5.617  14.332  0.50 71.42           C
ATOM      6  CB AVAL A  33      11.101   4.227  14.591  0.50 71.47           C
ATOM      5  CA BVAL A  33      11.708   5.617  14.332  0.40 71.42           C
ATOM      6  CB BVAL A  33      11.101   4.227  14.591  0.40 71.47           C
TER
ATOM      1  N   GLU X  18     -13.959  12.159  -6.598  1.00260.08           N
ATOM      2  CA  GLU X  18     -13.297  13.465  -6.628  1.00269.83           C
ATOM      3  C   GLU X  18     -11.946  13.282  -7.309  1.00269.18           C
ATOM      4  CB  GLU X  18     -13.128  14.035  -5.210  1.00261.96           C
ATOM      5  CG  GLU X  18     -14.455  14.401  -4.522  1.00263.56           C
ATOM      6  CD  GLU X  18     -14.291  15.239  -3.242  1.00264.89           C
ATOM      7  OE1 GLU X  18     -14.172  14.646  -2.143  1.00264.24           O
ATOM      8  OE2 GLU X  18     -14.309  16.498  -3.306  1.00264.37           O1-
HETATM  614  S   SO4 B 101      14.994  20.601  10.862  0.00  7.02           S
HETATM  615  O1  SO4 B 101      14.234  20.194  12.077  0.00  7.69           O
HETATM  616  O2  SO4 B 101      14.048  21.062   9.850  0.00  9.28           O
HETATM  617  O3  SO4 B 101      15.905  21.686  11.261  0.00  8.01           O
HETATM  618  O4  SO4 B 101      15.772  19.454  10.371  0.00  8.18           O
TER
HETATM  122  O   HOH S   1       5.334   8.357   8.032  1.00  0.00           O
HETATM  123  O   HOH S   2       5.396  15.243  10.734  1.00202.95           O
HETATM  124  O   HOH S   3     -25.334  18.357  18.032  0.00 20.00           O
"""
  mon_lib_srv = server.server()
  ener_lib = server.ener_lib()
  pdb_in = iotbx.pdb.hierarchy.input(pdb_string=pdb_raw)
  xrs = pdb_in.input.xray_structure_simple()
  processed_pdb_file = pdb_interpretation.process(
    mon_lib_srv=mon_lib_srv,
    ener_lib=ener_lib,
    raw_records=pdb_in.hierarchy.as_pdb_string(crystal_symmetry=xrs),
    crystal_symmetry=xrs,
    log=null_out())
  pdb_in.hierarchy.atoms().reset_i_seq()
  mstats = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ignore_hd=True)
  out = StringIO()
  mstats.show(out=out)
  #print out.getvalue()
  assert not show_diff(out.getvalue(), """\
Overall:
  Number of atoms = 50  (anisotropic = 0)
  B_iso: mean =  96.0  max = 269.8  min =   0.0
  Occupancy: mean = 0.47  max = 1.00  min = 0.00
    warning: 22 atoms with zero occupancy
  67 total B-factor or occupancy problem(s) detected
  Atoms or residues with zero occupancy:
   LYS A  82   CG    occ=0.00
   LYS A  82   CD    occ=0.00
   LYS A  82   CE    occ=0.00
   LYS A  82   NZ    occ=0.00
   LYS A  83   CG    occ=0.00
   LYS A  83   CD    occ=0.00
   LYS A  83   CE    occ=0.00
   LYS A  83   NZ    occ=0.00
   ASN A 242  (all)  occ=0.00
   SO4 B 101  (all)  occ=0.00
   HOH S   3   O     occ=0.00
Macromolecules:
  Number of atoms = 42  (anisotropic = 0)
  B_iso: mean = 108.0  max = 269.8  min =  60.7
  Occupancy: mean = 0.51  max = 1.00  min = 0.00
    warning: 16 atoms with zero occupancy
  57 total B-factor or occupancy problem(s) detected
Ligands:
  Number of atoms = 5  (anisotropic = 0)
  B_iso: mean =   8.0  max =   9.3  min =   7.0
  Occupancy: mean = 0.00  max = 0.00  min = 0.00
    warning: 5 atoms with zero occupancy
  6 total B-factor or occupancy problem(s) detected
Waters:
  Number of atoms = 3  (anisotropic = 0)
  B_iso: mean =  74.3  max = 202.9  min =   0.0
  Occupancy: mean = 0.67  max = 1.00  min = 0.00
    warning: 1 atoms with zero occupancy
  4 total B-factor or occupancy problem(s) detected
(Hydrogen atoms not included in overall counts.)
""")
  assert (len(mstats.all.bad_adps) == 1)
  assert (mstats.all.n_zero_b == 1)
  mstats2 = loads(dumps(mstats))
  out1 = StringIO()
  out2 = StringIO()
  mstats.show(out=out1)
  mstats2.show(out=out2)
  assert (out1.getvalue() == out2.getvalue())
  # now with ignore_hd=False
  mstats3 = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=processed_pdb_file.all_chain_proxies,
    ignore_hd=False)
  out2 = StringIO()
  mstats3.show(out=out2)
  assert (out2.getvalue() != out.getvalue())
  assert ("""   LYS A  83   HZ3   occ=0.00""" in out2.getvalue())
  outliers = mstats3.all.as_gui_table_data(include_zoom=True)
  assert (len(outliers) == 84)
  # test with all_chain_proxies undefined
  mstats4 = model_properties.model_statistics(
    pdb_hierarchy=pdb_in.hierarchy,
    xray_structure=xrs,
    all_chain_proxies=None,
    ignore_hd=False)
  outliers = mstats4.all.as_gui_table_data(include_zoom=True)
  assert (len(outliers) == 84)