예제 #1
0
def check_adp_set_b_iso(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,        xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart,tolerance)
  assert approx_equal(xrsp.use_u_iso,  xrsp_init.use_u_iso,tolerance)
  assert approx_equal(xrsp.use_u_aniso,xrsp_init.use_u_aniso,tolerance)
  assert approx_equal(xrsp.u_iso_not_used,  xrsp_init.u_iso_not_used,tolerance)
  assert approx_equal(xrsp.u_cart_not_used,xrsp_init.u_cart_not_used,tolerance)
  if(selection_str is None):
    assert not_approx_equal(xrsp.u_iso_used,  xrsp_init.u_iso_used,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
  else:
    arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
    arg2 = xrsp_init.u_iso_used.select(selection.select(xrsp_init.use_u_iso))
    if(arg1.size() > 0): assert not_approx_equal(arg1, arg2,tolerance)
    for ucart in xrsp.u_cart:
      b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
      if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
      else: assert approx_equal(b_iso, -78.956, 0.005)
예제 #2
0
def check_keep_selection(cmd,
                         xrsp_init,
                         output,
                         selection,
                         selection_str,
                         keep_selection_str,
                         verbose,
                         tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    keep_selection = xrsp_init.selection(selection_strings=keep_selection_str)
    assert approx_equal(xrsp.sites_cart,
                        xrsp_init.sites_cart.select(keep_selection), tolerance)
    assert approx_equal(xrsp.occ, xrsp_init.occ.select(keep_selection),
                        tolerance)
    assert approx_equal(xrsp.u_iso, xrsp_init.u_iso.select(keep_selection),
                        tolerance)
    assert approx_equal(xrsp.u_cart, xrsp_init.u_cart.select(keep_selection),
                        tolerance)
    sct1 = xrsp_init.xray_structure.scatterers().extract_scattering_types()
    assert sct1.count("C") > 0 and sct1.size() > sct1.count("C")
    sct2 = xrsp.xray_structure.scatterers().extract_scattering_types()
    assert sct2.count("C") == sct2.size()
    assert sct1.size() > keep_selection.count(True)
    assert sct1.size() > sct2.size()
예제 #3
0
def check_adp_set_b_iso(cmd,
                        xrsp_init,
                        output,
                        selection,
                        selection_str,
                        verbose,
                        tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert approx_equal(xrsp.u_iso_not_used, xrsp_init.u_iso_not_used,
                        tolerance)
    assert approx_equal(xrsp.u_cart_not_used, xrsp_init.u_cart_not_used,
                        tolerance)
    if (selection_str is None):
        assert not_approx_equal(xrsp.u_iso_used, xrsp_init.u_iso_used,
                                tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
    else:
        arg1 = xrsp.u_iso_used.select(selection.select(xrsp.use_u_iso))
        arg2 = xrsp_init.u_iso_used.select(
            selection.select(xrsp_init.use_u_iso))
        if (arg1.size() > 0): assert not_approx_equal(arg1, arg2, tolerance)
        for ucart in xrsp.u_cart:
            b_iso = adptbx.u_as_b(adptbx.u_cart_as_u_iso(ucart))
            if b_iso > 0: assert approx_equal(b_iso, 10, 0.005)
            else: assert approx_equal(b_iso, -78.956, 0.005)
예제 #4
0
def exercise_convert_met_to_semet():
    pdb_str_met = """
ATOM      1  N   MET B  37       7.525   5.296   6.399  1.00 10.00           N
ATOM      2  CA  MET B  37       6.533   6.338   6.634  1.00 10.00           C
ATOM      3  C   MET B  37       6.175   7.044   5.330  1.00 10.00           C
ATOM      4  O   MET B  37       5.000   7.200   5.000  1.00 10.00           O
ATOM      5  CB  MET B  37       7.051   7.351   7.655  1.00 10.00           C
ATOM      6  CG  MET B  37       7.377   6.750   9.013  1.00 10.00           C
ATOM      7  SD  MET B  37       8.647   5.473   8.922  1.00 10.00           S
ATOM      8  CE  MET B  37       8.775   5.000  10.645  1.00 10.00           C
TER
END
  """
    pi = iotbx.pdb.input(source_info=None, lines=pdb_str_met)
    ph_met_in = pi.construct_hierarchy()
    pi.write_pdb_file(file_name="exercise_convert_met_to_semet.pdb")
    cmd = " ".join([
        "phenix.pdbtools", "exercise_convert_met_to_semet.pdb",
        "convert_met_to_semet=true"
    ])
    run_command(command=cmd, verbose=False)
    cmd = " ".join([
        "phenix.pdbtools", "exercise_convert_met_to_semet.pdb_modified.pdb",
        "convert_semet_to_met=true"
    ])
    run_command(command=cmd, verbose=False)
    pi_met_out = iotbx.pdb.input(
        file_name="exercise_convert_met_to_semet.pdb_modified.pdb_modified.pdb"
    ).construct_hierarchy()
    assert pi_met_out.is_similar_hierarchy(ph_met_in)
예제 #5
0
def exercise_normalize_occupancies():
    pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.41 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O  AHOH B   3       1.132   5.963   7.065  0.80 15.00           O
ATOM     18  O  BHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM     19  O  AHOH B   4       4.132   9.963   7.800  0.50 15.00           O
ATOM     20  O  BHOH B   4       4.132   9.963   7.800  0.40 15.00           O
ATOM     21 ZN   ZN  C   5       8.000  12.124  11.900  0.75 20.00          ZN
"""
    open("tst_pdbtools_norm_occ.pdb", "w").write(pdb_in)
    cmd = 'phenix.pdbtools tst_pdbtools_norm_occ.pdb occupancies.normalize=True modify.selection="not element ZN"'
    run_command(command=cmd, verbose=False)
    pdb_new = open("tst_pdbtools_norm_occ.pdb_modified.pdb").read()
    assert (pdb_new == """\
ATOM      1  O  AHOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB ALYS A  32       9.197   8.686  12.246  0.59 14.71           C
ATOM      4  CB BLYS A  32       9.193   8.732  12.170  0.41 12.23           C
ATOM      5  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      6  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
TER
ATOM      7  O  AHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM      8  O  BHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM      9  O  AHOH B   4       4.132   9.963   7.800  0.60 15.00           O
ATOM     10  O  BHOH B   4       4.132   9.963   7.800  0.40 15.00           O
TER
ATOM     11 ZN   ZN  C   5       8.000  12.124  11.900  0.75 20.00          Zn
TER
END
""")
예제 #6
0
def exercise_normalize_occupancies () :
  pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.41 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O  AHOH B   3       1.132   5.963   7.065  0.80 15.00           O
ATOM     18  O  BHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM     19  O  AHOH B   4       4.132   9.963   7.800  0.50 15.00           O
ATOM     20  O  BHOH B   4       4.132   9.963   7.800  0.40 15.00           O
ATOM     21 ZN   ZN  C   5       8.000  12.124  11.900  0.75 20.00          ZN
"""
  open("tst_pdbtools_norm_occ.pdb", "w").write(pdb_in)
  cmd = 'phenix.pdbtools tst_pdbtools_norm_occ.pdb occupancies.normalize=True modify.selection="not element ZN"'
  run_command(command=cmd, verbose=False)
  pdb_new = open("tst_pdbtools_norm_occ.pdb_modified.pdb").read()
  assert (pdb_new == """\
ATOM      1  O  AHOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB ALYS A  32       9.197   8.686  12.246  0.59 14.71           C
ATOM      4  CB BLYS A  32       9.193   8.732  12.170  0.41 12.23           C
ATOM      5  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      6  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
TER
ATOM      7  O  AHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM      8  O  BHOH B   3       1.132   5.963   7.065  0.50 15.00           O
ATOM      9  O  AHOH B   4       4.132   9.963   7.800  0.60 15.00           O
ATOM     10  O  BHOH B   4       4.132   9.963   7.800  0.40 15.00           O
TER
ATOM     11 ZN   ZN  C   5       8.000  12.124  11.900  0.75 20.00          Zn
TER
END
""")
예제 #7
0
def exercise_convert_met_to_semet():
  pdb_str_met = """
ATOM      1  N   MET B  37       7.525   5.296   6.399  1.00 10.00           N
ATOM      2  CA  MET B  37       6.533   6.338   6.634  1.00 10.00           C
ATOM      3  C   MET B  37       6.175   7.044   5.330  1.00 10.00           C
ATOM      4  O   MET B  37       5.000   7.200   5.000  1.00 10.00           O
ATOM      5  CB  MET B  37       7.051   7.351   7.655  1.00 10.00           C
ATOM      6  CG  MET B  37       7.377   6.750   9.013  1.00 10.00           C
ATOM      7  SD  MET B  37       8.647   5.473   8.922  1.00 10.00           S
ATOM      8  CE  MET B  37       8.775   5.000  10.645  1.00 10.00           C
TER
END
  """
  pi = iotbx.pdb.input(source_info=None, lines=pdb_str_met)
  ph_met_in = pi.construct_hierarchy()
  pi.write_pdb_file(file_name="exercise_convert_met_to_semet.pdb")
  cmd = " ".join([
    "phenix.pdbtools",
    "exercise_convert_met_to_semet.pdb",
    "convert_met_to_semet=true"])
  run_command(command=cmd, verbose=False)
  cmd = " ".join([
    "phenix.pdbtools",
    "exercise_convert_met_to_semet.pdb_modified.pdb",
    "convert_semet_to_met=true"])
  run_command(command=cmd, verbose=False)
  pi_met_out = iotbx.pdb.input(
    file_name="exercise_convert_met_to_semet.pdb_modified.pdb_modified.pdb"
    ).construct_hierarchy()
  assert pi_met_out.is_similar_hierarchy(ph_met_in)
예제 #8
0
def exercise_move_waters():
    pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     19  H1  HOH A   3       1.160   5.211   6.437  1.00 15.00           H
ATOM     20  H2  HOH A   3       1.122   5.579   7.967  1.00 15.00           H
HETATM 2397  P   PO4     1      -7.520  25.376  38.369  1.00 39.37           P
HETATM 2398  O1  PO4     1      -6.610  24.262  38.967  1.00 40.00           O
HETATM 2399  O2  PO4     1      -6.901  25.919  37.049  1.00 41.07           O
HETATM 2400  O3  PO4     1      -8.894  24.741  38.097  1.00 45.09           O
HETATM 2401  O4  PO4     1      -7.722  26.556  39.350  1.00 42.48           O
ATOM     23 CL   CL  B   1       6.302   6.419   1.560  0.50 10.00          CL
HETATM 6362  O   HOH B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM 6363  O  AHOH B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM 6364  O   HOH B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM 6365  O  BHOH B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM 6366  O   HOH B   6      35.068  19.167 155.349  1.00 15.97       B   O
"""
    pdb_out = """\
ATOM      1  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      2  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM      3  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
TER
HETATM    6  O1  PO4     1      -6.610  24.262  38.967  1.00 40.00           O
HETATM    7  O2  PO4     1      -6.901  25.919  37.049  1.00 41.07           O
HETATM    8  O3  PO4     1      -8.894  24.741  38.097  1.00 45.09           O
HETATM    9  O4  PO4     1      -7.722  26.556  39.350  1.00 42.48           O
HETATM   10  P   PO4     1      -7.520  25.376  38.369  1.00 39.37           P
TER
ATOM     11 CL   CL  B   1       6.302   6.419   1.560  0.50 10.00          Cl
TER
ATOM     12  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     13  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     14  H1  HOH A   3       1.160   5.211   6.437  1.00 15.00           H
ATOM     15  H2  HOH A   3       1.122   5.579   7.967  1.00 15.00           H
TER
HETATM   16  O   HOH B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM   17  O  AHOH B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM   18  O   HOH B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM   19  O  BHOH B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM   20  O   HOH B   6      35.068  19.167 155.349  1.00 15.97       B   O
TER
END
"""
    open("tst_pdbtools_move_waters.pdb", "w").write(pdb_in)
    cmd = "phenix.pdbtools tst_pdbtools_move_waters.pdb move_waters_last=True"
    run_command(command=cmd, verbose=False)
    pdb_new = open("tst_pdbtools_move_waters.pdb_modified.pdb").read()
    assert pdb_new == pdb_out, pdb_new
예제 #9
0
def exercise_move_waters () :
  pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     19  H1  HOH A   3       1.160   5.211   6.437  1.00 15.00           H
ATOM     20  H2  HOH A   3       1.122   5.579   7.967  1.00 15.00           H
HETATM 2397  P   PO4     1      -7.520  25.376  38.369  1.00 39.37           P
HETATM 2398  O1  PO4     1      -6.610  24.262  38.967  1.00 40.00           O
HETATM 2399  O2  PO4     1      -6.901  25.919  37.049  1.00 41.07           O
HETATM 2400  O3  PO4     1      -8.894  24.741  38.097  1.00 45.09           O
HETATM 2401  O4  PO4     1      -7.722  26.556  39.350  1.00 42.48           O
ATOM     23 CL   CL  B   1       6.302   6.419   1.560  0.50 10.00          CL
HETATM 6362  O   HOH B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM 6363  O  AHOH B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM 6364  O   HOH B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM 6365  O  BHOH B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM 6366  O   HOH B   6      35.068  19.167 155.349  1.00 15.97       B   O
"""
  pdb_out = """\
ATOM      1  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      2  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM      3  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
TER
HETATM    6  O1  PO4     1      -6.610  24.262  38.967  1.00 40.00           O
HETATM    7  O2  PO4     1      -6.901  25.919  37.049  1.00 41.07           O
HETATM    8  O3  PO4     1      -8.894  24.741  38.097  1.00 45.09           O
HETATM    9  O4  PO4     1      -7.722  26.556  39.350  1.00 42.48           O
HETATM   10  P   PO4     1      -7.520  25.376  38.369  1.00 39.37           P
TER
ATOM     11 CL   CL  B   1       6.302   6.419   1.560  0.50 10.00          Cl
TER
ATOM     12  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     13  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     14  H1  HOH A   3       1.160   5.211   6.437  1.00 15.00           H
ATOM     15  H2  HOH A   3       1.122   5.579   7.967  1.00 15.00           H
TER
HETATM   16  O   HOH B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM   17  O  AHOH B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM   18  O   HOH B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM   19  O  BHOH B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM   20  O   HOH B   6      35.068  19.167 155.349  1.00 15.97       B   O
TER
END
"""
  open("tst_pdbtools_move_waters.pdb", "w").write(pdb_in)
  cmd = "phenix.pdbtools tst_pdbtools_move_waters.pdb move_waters_last=True"
  run_command(command=cmd, verbose=False)
  pdb_new = open("tst_pdbtools_move_waters.pdb_modified.pdb").read()
  assert pdb_new == pdb_out, pdb_new
예제 #10
0
def test_quiet(file_name, verbose):
  output_file_name = "shifted.pdb"
  remove_files("log")
  remove_files(output_file_name)
  assert file_name.find('"') < 0
  cmd= 'phenix.pdbtools "%s" output.file_name=%s shake=0.1 --quiet > log'%(
    file_name, output_file_name)
  run_command(command=cmd, verbose=verbose)
  lines = open("log","r").readlines()
  assert len(lines) == 0
예제 #11
0
def check_all_none(cmd, xrsp_init, output, verbose, tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert approx_equal(xrsp.u_iso, xrsp_init.u_iso, tolerance)
    assert approx_equal(xrsp.u_cart, xrsp_init.u_cart, tolerance)
예제 #12
0
def check_all_none(cmd, xrsp_init, output, verbose, tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,         xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart,  xrsp_init.sites_cart,tolerance)
  assert approx_equal(xrsp.use_u_iso,   xrsp_init.use_u_iso,tolerance)
  assert approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso,tolerance)
  assert approx_equal(xrsp.u_iso,       xrsp_init.u_iso,tolerance)
  assert approx_equal(xrsp.u_cart,      xrsp_init.u_cart,tolerance)
예제 #13
0
def test_quiet(file_name, verbose):
    output_file_name = "shifted.pdb"
    remove_files("log")
    remove_files(output_file_name)
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" output.file_name=%s shake=0.1 --quiet > log' % (
        file_name, output_file_name)
    run_command(command=cmd, verbose=verbose)
    lines = open("log", "r").readlines()
    assert len(lines) == 0
예제 #14
0
def exercise_remove_first_n_atoms_fraction(pdb_dir, verbose):
  file_name = os.path.join(pdb_dir, "enk_gbr.pdb")
  n_atoms_start = iotbx.pdb.hierarchy.input(
    file_name=file_name).xray_structure_simple().scatterers().size()
  assert file_name.find('"') < 0
  cmd = 'phenix.pdbtools "%s" remove_first_n_atoms_fraction=0.6'%file_name
  run_command(command=cmd, verbose=verbose)
  pdb_inp = iotbx.pdb.hierarchy.input(file_name="enk_gbr.pdb_modified.pdb")
  n_atoms_final = iotbx.pdb.hierarchy.input(
    file_name="enk_gbr.pdb_modified.pdb").xray_structure_simple().scatterers().size()
  assert n_atoms_final*1./n_atoms_start == 0.4
예제 #15
0
def exercise_truncate_to_polyala(pdb_dir, verbose):
    file_name = os.path.join(pdb_dir, "enk_gbr.pdb")
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" truncate_to_polyala=true' % file_name
    run_command(command=cmd, verbose=verbose)
    ala_atom_names = [" N  ", " CA ", " C  ", " O  ", " CB "]
    pdb_inp = iotbx.pdb.hierarchy.input(file_name="enk_gbr.pdb_modified.pdb")
    counter = 0
    for a in pdb_inp.hierarchy.atoms_with_labels():
        assert a.name in ala_atom_names
        counter += 1
    assert counter == 23
예제 #16
0
def exercise_remove_first_n_atoms_fraction(pdb_dir, verbose):
    file_name = os.path.join(pdb_dir, "enk_gbr.pdb")
    n_atoms_start = iotbx.pdb.hierarchy.input(
        file_name=file_name).xray_structure_simple().scatterers().size()
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" remove_first_n_atoms_fraction=0.6' % file_name
    run_command(command=cmd, verbose=verbose)
    pdb_inp = iotbx.pdb.hierarchy.input(file_name="enk_gbr.pdb_modified.pdb")
    n_atoms_final = iotbx.pdb.hierarchy.input(
        file_name="enk_gbr.pdb_modified.pdb").xray_structure_simple(
        ).scatterers().size()
    assert n_atoms_final * 1. / n_atoms_start == 0.4
예제 #17
0
def exercise_truncate_to_polyala(pdb_dir, verbose):
  file_name = os.path.join(pdb_dir, "enk_gbr.pdb")
  assert file_name.find('"') < 0
  cmd = 'phenix.pdbtools "%s" truncate_to_polyala=true'%file_name
  run_command(command=cmd, verbose=verbose)
  ala_atom_names = [" N  ", " CA ", " C  ", " O  ", " CB "]
  pdb_inp = iotbx.pdb.hierarchy.input(file_name="enk_gbr.pdb_modified.pdb")
  counter = 0
  for a in pdb_inp.hierarchy.atoms_with_labels():
    assert a.name in ala_atom_names
    counter += 1
  assert counter == 23
예제 #18
0
def exercise_show_number_of_removed(pdb_dir, verbose):
    file_name = os.path.join(pdb_dir, "phe_h.pdb")
    log = "exercise_show_number_of_removed.log"
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" remove="element H" > %s' % (file_name, log)
    remove_files(log)
    run_command(command=cmd, verbose=verbose)
    assert os.path.isfile(log)
    n_found = 0
    for line in open(log).read().splitlines():
        if (line == "Atoms to be kept: 13 of 24"):
            n_found += 1
    assert n_found == 1
예제 #19
0
 def run_concoord(self, nstruct, prefix='prefix'):
   env = libtbx.env_config.unpickle()
   self.dist= env.find_dist_path('sastbx')+'/concoord/mydist.csh'
   self.disco= env.find_dist_path('sastbx')+'/concoord/mydisco.csh'
   # initialize distance constraints
   op_file = prefix+".pdb"
   og_file = prefix+".gro"
   od_file = prefix+".dat"
   run_command(self.dist+" -p %s -op %s -og %s -od %s >& %s.log0"%(self.pdb_file, op_file, og_file, od_file, prefix ) )
   # run disco to generate nstruct conformations
   #print "running:\n", self.disco+" -p %s -n %d -op %s>%s.log &"%(self.pdb_file,nstruct,prefix,prefix)
   random_number = random.randint(1,741265)
   run_command(self.disco+" -p %s -d %s -n %d -op %s -s %d >& %s.log &"%(op_file,od_file,nstruct,prefix,random_number,prefix) )
예제 #20
0
def exercise_show_number_of_removed(pdb_dir, verbose):
  file_name = os.path.join(pdb_dir, "phe_h.pdb")
  log = "exercise_show_number_of_removed.log"
  assert file_name.find('"') < 0
  cmd = 'phenix.pdbtools "%s" remove="element H" > %s' % (file_name, log)
  remove_files(log)
  run_command(command=cmd, verbose=verbose)
  assert os.path.isfile(log)
  n_found = 0
  for line in open(log).read().splitlines():
    if (line == "Atoms to be kept: 13 of 24"):
      n_found += 1
  assert n_found == 1
예제 #21
0
def exercise_stop_for_unknowns () :
  pdb_in = """\
HETATM   16  O   UNK B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM   17  O   UNK B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM   18  O   UNK B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM   19  O   UNK B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM   20  O   UNK B   6      35.068  19.167 155.349  1.00 15.97       B   O
"""
  open("tst_pdbtools_unknown.pdb", "w").write(pdb_in)
  cmd = "phenix.pdbtools tst_pdbtools_unknown.pdb set_b_iso=20"
  run_command(command=cmd, sorry_expected=True)
  cmd2 = cmd + " stop_for_unknowns=False"
  run_command(command=cmd)
예제 #22
0
def check_adp_to_iso(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,        xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart,tolerance)
  assert not_approx_equal(xrsp.use_u_iso,  xrsp_init.use_u_iso,tolerance)
  assert not_approx_equal(xrsp.use_u_aniso,xrsp_init.use_u_aniso,tolerance)
  assert xrsp.u_iso_not_used.size() == 0
  assert xrsp_init.u_iso_not_used.size() > 0
  assert xrsp.u_cart_used.size() == 0
  assert xrsp_init.u_cart_used.size() > 0
예제 #23
0
def exercise_change_of_basis () :
  open("tmp_pdbtools_cb_op.pdb", "w").write("""\
CRYST1   21.937    4.866   23.477  90.00 107.08  90.00 P 1 21 1      2
ATOM      1  N   GLY A   1      -9.009   4.612   6.102  1.00 16.77           N
ATOM      2  CA  GLY A   1      -9.052   4.207   4.651  1.00 16.57           C
ATOM      3  C   GLY A   1      -8.015   3.140   4.419  1.00 16.16           C
ATOM      4  O   GLY A   1      -7.523   2.521   5.381  1.00 16.78           O  """)
  cmd = "phenix.pdbtools tmp_pdbtools_cb_op.pdb change_of_basis='a,c,b'"
  run_command(command=cmd, verbose=False)
  lines = open("tmp_pdbtools_cb_op.pdb_modified.pdb").readlines()
  for line in lines :
    if line.startswith("CRYST1") :
      assert (line.strip() ==
        """CRYST1   21.937   23.477    4.866  90.00  90.00 107.08 P 1 1 21""")
      break
예제 #24
0
def exercise_stop_for_unknowns():
    pdb_in = """\
HETATM   16  O   UNK B   2      47.616  10.724 150.212  1.00 46.48       B   O
HETATM   17  O   UNK B   3      46.408  16.672 146.066  0.50 12.81       B   O
HETATM   18  O   UNK B   4      29.343  12.806 185.898  1.00 35.57       B   O
HETATM   19  O   UNK B   5      43.786  12.615 147.734  0.50 28.43       B   O
HETATM   20  O   UNK B   6      35.068  19.167 155.349  1.00 15.97       B   O
"""
    open("tst_pdbtools_unknown.pdb", "w").write(pdb_in)
    cmd = "phenix.pdbtools tst_pdbtools_unknown.pdb set_b_iso=20"
    print cmd
    run_command(command=cmd, sorry_expected=True)
    cmd2 = cmd + " stop_for_unknowns=False"
    print cmd2
    run_command(command=cmd2)
예제 #25
0
def check_sites_rt(
      cmd, xrsp_init, output, selection, selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.occ,    xrsp_init.occ,tolerance)
  assert approx_equal(xrsp.u_iso,  xrsp_init.u_iso,tolerance)
  assert approx_equal(xrsp.u_cart, xrsp_init.u_cart,tolerance)
  if(selection_str is None):
    diff = xrsp.sites_cart - xrsp_init.sites_cart
    assert math.sqrt(flex.mean(diff.dot())) > 1.0
  else:
    diff = xrsp.sites_cart - xrsp_init.sites_cart
    assert math.sqrt(flex.mean(diff.select(selection).dot())) > 1.0
    assert approx_equal(
              math.sqrt(flex.mean(diff.select(~selection).dot())),0.,tolerance)
예제 #26
0
def exercise_change_of_basis():
    open("tmp_pdbtools_cb_op.pdb", "w").write("""\
CRYST1   21.937    4.866   23.477  90.00 107.08  90.00 P 1 21 1      2
ATOM      1  N   GLY A   1      -9.009   4.612   6.102  1.00 16.77           N
ATOM      2  CA  GLY A   1      -9.052   4.207   4.651  1.00 16.57           C
ATOM      3  C   GLY A   1      -8.015   3.140   4.419  1.00 16.16           C
ATOM      4  O   GLY A   1      -7.523   2.521   5.381  1.00 16.78           O  """
                                              )
    cmd = "phenix.pdbtools tmp_pdbtools_cb_op.pdb change_of_basis='a,c,b'"
    run_command(command=cmd, verbose=False)
    lines = open("tmp_pdbtools_cb_op.pdb_modified.pdb").readlines()
    for line in lines:
        if line.startswith("CRYST1"):
            assert (
                line.strip() ==
                """CRYST1   21.937   23.477    4.866  90.00  90.00 107.08 P 1 1 21"""
            )
            break
예제 #27
0
def check_keep_remove_conflict(cmd, output, verbose):
    cmd += " keep=all remove=all "
    cmd_result = run_command(command=cmd, verbose=verbose, sorry_expected=True)
    sorry_lines = search_for(
        pattern="Sorry: Ambiguous selection:"
        " 'keep' and 'remove' keywords cannot be used simultaneously:",
        mode="==",
        lines=cmd_result.stdout_lines)
    assert len(sorry_lines) == 1
예제 #28
0
def check_keep_remove_conflict(cmd, output, verbose):
  cmd += " keep=all remove=all "
  cmd_result = run_command(command=cmd, verbose=verbose, sorry_expected=True)
  sorry_lines = search_for(
    pattern="Sorry: Ambiguous selection:"
            " 'keep' and 'remove' keywords cannot be used simultaneously:",
    mode="==",
    lines=cmd_result.stdout_lines)
  assert len(sorry_lines) == 1
예제 #29
0
def check_adp_to_iso(cmd,
                     xrsp_init,
                     output,
                     selection,
                     selection_str,
                     verbose,
                     tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert not_approx_equal(xrsp.use_u_iso, xrsp_init.use_u_iso, tolerance)
    assert not_approx_equal(xrsp.use_u_aniso, xrsp_init.use_u_aniso, tolerance)
    assert xrsp.u_iso_not_used.size() == 0
    assert xrsp_init.u_iso_not_used.size() > 0
    assert xrsp.u_cart_used.size() == 0
    assert xrsp_init.u_cart_used.size() > 0
예제 #30
0
def check_occ_randomize(
      cmd, xrsp_init, output, selection,selection_str, verbose,
      tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  assert approx_equal(xrsp.sites_cart,xrsp_init.sites_cart,tolerance)
  assert approx_equal(xrsp.u_iso,     xrsp_init.u_iso,tolerance)
  assert approx_equal(xrsp.u_cart,    xrsp_init.u_cart,tolerance)
  if(selection_str is None):
    diff = flex.abs(xrsp.occ - xrsp_init.occ)
    assert flex.mean(diff) > 0.0
    assert flex.max(diff) > 0.0
  else:
    diff = flex.abs(xrsp.occ - xrsp_init.occ)
    assert flex.mean(diff) > 0.0
    assert flex.max(diff) > 0.0
    assert approx_equal(flex.mean(diff.select(~selection)),0.,tolerance)
예제 #31
0
def check_keep_selection(
      cmd, xrsp_init, output, selection, selection_str,
      keep_selection_str, verbose, tolerance=1.e-3):
  remove_files(output)
  run_command(command=cmd, verbose=verbose)
  xrsp = xray_structure_plus(file_name = output)
  keep_selection = xrsp_init.selection(selection_strings = keep_selection_str)
  assert approx_equal(xrsp.sites_cart,
                      xrsp_init.sites_cart.select(keep_selection),tolerance)
  assert approx_equal(xrsp.occ, xrsp_init.occ.select(keep_selection),tolerance)
  assert approx_equal(
    xrsp.u_iso, xrsp_init.u_iso.select(keep_selection),tolerance)
  assert approx_equal(
    xrsp.u_cart, xrsp_init.u_cart.select(keep_selection),tolerance)
  sct1 = xrsp_init.xray_structure.scatterers().extract_scattering_types()
  assert sct1.count("C") > 0 and sct1.size() > sct1.count("C")
  sct2 = xrsp.xray_structure.scatterers().extract_scattering_types()
  assert sct2.count("C") == sct2.size()
  assert sct1.size() > keep_selection.count(True)
  assert sct1.size() > sct2.size()
예제 #32
0
def exercise_multiple(pdb_dir, verbose):
    params = """\
modify{
adp {
  atom_selection = chain A
  randomize = True
}
adp {
  atom_selection = chain B
  shift_b_iso = 10
}
sites {
  atom_selection = chain B
  shake = 1.5
}
sites {
  atom_selection = chain A or chain C
  translate = 1 2 3
  rotate = 4 5 6
}
occupancies
{
  atom_selection = chain A
  randomize = True
}
occupancies
{
  atom_selection = chain C
  set = 0.1
}
}
"""
    open("params", "w").write(params)
    file_name = os.path.join(pdb_dir, "phe_e.pdb")
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" modify.output.file_name=modified.pdb params' % (
        file_name)
    result = run_command(command=cmd, verbose=verbose)
    lines = result.stdout_lines
    for i, line in enumerate(lines):
        if (line.find("Performing requested model manipulations") >= 0):
            break
    else:
        raise RuntimeError("Expected output not found.")
    assert lines[i + 1] == ""
    assert lines[i + 8] == ""
    assert not show_diff(
        "\n".join(lines[i + 2:i + 8]), """\
Randomizing ADP: selected atoms: 12 of 36
Adding shift = 10.00 to all ADP: selected atoms: 12 of 36
Shaking sites (RMS = 1.500): selected atoms: 12 of 36
Rigid body shift: selected atoms: 24 of 36
Randomizing occupancies: selected atoms: 12 of 36
Setting occupancies to:    0.100: selected atoms: 12 of 36""")
예제 #33
0
def check_sites_rt(cmd,
                   xrsp_init,
                   output,
                   selection,
                   selection_str,
                   verbose,
                   tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.occ, xrsp_init.occ, tolerance)
    assert approx_equal(xrsp.u_iso, xrsp_init.u_iso, tolerance)
    assert approx_equal(xrsp.u_cart, xrsp_init.u_cart, tolerance)
    if (selection_str is None):
        diff = xrsp.sites_cart - xrsp_init.sites_cart
        assert math.sqrt(flex.mean(diff.dot())) > 1.0
    else:
        diff = xrsp.sites_cart - xrsp_init.sites_cart
        assert math.sqrt(flex.mean(diff.select(selection).dot())) > 1.0
        assert approx_equal(
            math.sqrt(flex.mean(diff.select(~selection).dot())), 0., tolerance)
예제 #34
0
def exercise_multiple(pdb_dir, verbose):
  params = """\
modify{
adp {
  atom_selection = chain A
  randomize = True
}
adp {
  atom_selection = chain B
  shift_b_iso = 10
}
sites {
  atom_selection = chain B
  shake = 1.5
}
sites {
  atom_selection = chain A or chain C
  translate = 1 2 3
  rotate = 4 5 6
}
occupancies
{
  atom_selection = chain A
  randomize = True
}
occupancies
{
  atom_selection = chain C
  set = 0.1
}
}
"""
  open("params", "w").write(params)
  file_name = os.path.join(pdb_dir, "phe_e.pdb")
  assert file_name.find('"') < 0
  cmd = 'phenix.pdbtools "%s" modify.output.file_name=modified.pdb params' % (
    file_name)
  result = run_command(command=cmd, verbose=verbose)
  lines = result.stdout_lines
  for i,line in enumerate(lines):
    if (line.find("Performing requested model manipulations") >= 0):
      break
  else:
    raise RuntimeError("Expected output not found.")
  assert lines[i+1] == ""
  assert lines[i+8] == ""
  assert not show_diff("\n".join(lines[i+2:i+8]), """\
Randomizing ADP: selected atoms: 12 of 36
Adding shift = 10.00 to all ADP: selected atoms: 12 of 36
Shaking sites (RMS = 1.500): selected atoms: 12 of 36
Rigid body shift: selected atoms: 24 of 36
Randomizing occupancies: selected atoms: 12 of 36
Setting occupancies to:    0.100: selected atoms: 12 of 36""")
예제 #35
0
def exercise_remove_alt_confs () :
  pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     19  O  BHOH A   4       4.132   9.963   7.800  0.50 15.00           O
"""
  open("tst_pdbtools_alt_confs.pdb", "w").write(pdb_in)
  cmd = "phenix.pdbtools tst_pdbtools_alt_confs.pdb remove_alt_confs=True"
  run_command(command=cmd, verbose=False)
  pdb_new = open("tst_pdbtools_alt_confs.pdb_modified.pdb").read()
  assert (pdb_new == """\
ATOM      1  O   HOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB  LYS A  32       9.197   8.686  12.246  1.00 14.71           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM      6  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
TER
END
""")
  cmd = "phenix.pdbtools tst_pdbtools_alt_confs.pdb remove_alt_confs=True " +\
    "always_keep_one_conformer=True"
  run_command(command=cmd, verbose=False)
  pdb_new = open("tst_pdbtools_alt_confs.pdb_modified.pdb").read()
  assert (pdb_new == """\
ATOM      1  O   HOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB  LYS A  32       9.193   8.732  12.170  1.00 12.23           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM      6  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM      7  O   HOH A   4       4.132   9.963   7.800  1.00 15.00           O
TER
END
""")
예제 #36
0
def exercise_remove_alt_confs():
    pdb_in = """\
ATOM     16  O  AHOH A   2       5.131   5.251   5.823  0.60 10.00           O
ATOM     60  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM     63  CB ALYS A  32       9.197   8.686  12.246  0.29 14.71           C
ATOM     64  CB BLYS A  32       9.193   8.732  12.170  0.71 12.23           C
ATOM     74  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM     77  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM     18  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM     19  O  BHOH A   4       4.132   9.963   7.800  0.50 15.00           O
"""
    open("tst_pdbtools_alt_confs.pdb", "w").write(pdb_in)
    cmd = "phenix.pdbtools tst_pdbtools_alt_confs.pdb remove_alt_confs=True"
    run_command(command=cmd, verbose=False)
    pdb_new = open("tst_pdbtools_alt_confs.pdb_modified.pdb").read()
    assert (pdb_new == """\
ATOM      1  O   HOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB  LYS A  32       9.197   8.686  12.246  1.00 14.71           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM      6  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
TER
END
""")
    cmd = "phenix.pdbtools tst_pdbtools_alt_confs.pdb remove_alt_confs=True " +\
      "always_keep_one_conformer=True"
    run_command(command=cmd, verbose=False)
    pdb_new = open("tst_pdbtools_alt_confs.pdb_modified.pdb").read()
    assert (pdb_new == """\
ATOM      1  O   HOH A   2       5.131   5.251   5.823  1.00 10.00           O
ATOM      2  CA  LYS A  32      10.574   8.177  11.768  1.00 11.49           C
ATOM      3  CB  LYS A  32       9.193   8.732  12.170  1.00 12.23           C
ATOM      4  CA  VAL A  33      11.708   5.617  14.332  1.00 11.42           C
ATOM      5  CB  VAL A  33      11.101   4.227  14.591  1.00 11.47           C
ATOM      6  O   HOH A   3       1.132   5.963   7.065  1.00 15.00           O
ATOM      7  O   HOH A   4       4.132   9.963   7.800  1.00 15.00           O
TER
END
""")
예제 #37
0
def check_occ_randomize(cmd,
                        xrsp_init,
                        output,
                        selection,
                        selection_str,
                        verbose,
                        tolerance=1.e-3):
    remove_files(output)
    run_command(command=cmd, verbose=verbose)
    xrsp = xray_structure_plus(file_name=output)
    assert approx_equal(xrsp.sites_cart, xrsp_init.sites_cart, tolerance)
    assert approx_equal(xrsp.u_iso, xrsp_init.u_iso, tolerance)
    assert approx_equal(xrsp.u_cart, xrsp_init.u_cart, tolerance)
    if (selection_str is None):
        diff = flex.abs(xrsp.occ - xrsp_init.occ)
        assert flex.mean(diff) > 0.0
        assert flex.max(diff) > 0.0
    else:
        diff = flex.abs(xrsp.occ - xrsp_init.occ)
        assert flex.mean(diff) > 0.0
        assert flex.max(diff) > 0.0
        assert approx_equal(flex.mean(diff.select(~selection)), 0., tolerance)
예제 #38
0
def exercise_no_cryst1(pdb_dir, verbose):
  file_name = os.path.join(pdb_dir, "t.pdb")
  output = "modified.pdb"
  assert file_name.find('"') < 0
  base = 'phenix.pdbtools "%s" modify.output.file_name=%s '%(file_name, output)
  cmd = base+'sites.rotate="0 0 0" sites.translate="0 0 0"'
  run_command(command=cmd, verbose=verbose)
  lines1 = []
  for line in open(file_name,"r").readlines():
    line = line.strip()
    assert line.count("CRYST1") == 0
    if(line.startswith("ATOM") or line.startswith("HETATM")):
      lines1.append(line)
  lines2 = []
  for line in open(output,"r").readlines():
    line = line.strip()
    assert line.count("CRYST1") == 0
    if(line.startswith("ATOM") or line.startswith("HETATM")):
      lines2.append(line)
  assert len(lines1) == len(lines2)
  for l1,l2 in zip(lines1, lines2):
    assert l1[11:70].strip() == l2[11:70].strip()
예제 #39
0
def exercise_no_cryst1(pdb_dir, verbose):
    file_name = os.path.join(pdb_dir, "t.pdb")
    output = "modified.pdb"
    assert file_name.find('"') < 0
    base = 'phenix.pdbtools "%s" modify.output.file_name=%s ' % (file_name,
                                                                 output)
    cmd = base + 'sites.rotate="0 0 0" sites.translate="0 0 0"'
    run_command(command=cmd, verbose=verbose)
    lines1 = []
    for line in open(file_name, "r").readlines():
        line = line.strip()
        assert line.count("CRYST1") == 0
        if (line.startswith("ATOM") or line.startswith("HETATM")):
            lines1.append(line)
    lines2 = []
    for line in open(output, "r").readlines():
        line = line.strip()
        assert line.count("CRYST1") == 0
        if (line.startswith("ATOM") or line.startswith("HETATM")):
            lines2.append(line)
    assert len(lines1) == len(lines2)
    for l1, l2 in zip(lines1, lines2):
        assert l1[11:70].strip() == l2[11:70].strip()
예제 #40
0
def exercise_convert_semet_to_met () :
  open("tmp_semet.pdb", "w").write("""\
HETATM  507  N   MSE A 106      53.211  45.681  34.889  1.00  1.05           N
HETATM  508  CA  MSE A 106      51.827  45.381  35.207  1.00  1.35           C
HETATM  509  C   MSE A 106      50.937  45.462  33.968  1.00  3.57           C
HETATM  510  O   MSE A 106      49.956  44.737  33.860  1.00  4.67           O
HETATM  511  CB  MSE A 106      51.318  46.310  36.304  1.00  1.07           C
HETATM  512  CG  MSE A 106      49.833  46.180  36.603  1.00  1.06           C
HETATM  513 SE   MSE A 106      49.249  47.284  38.129  0.82 10.02          Se
HETATM  514  CE  MSE A 106      50.851  47.140  39.206  1.00  1.19           C
""")
  cmd = "phenix.pdbtools tmp_semet.pdb convert_semet_to_met=True"
  run_command(command=cmd, verbose=False)
  assert (not "HETATM" in open("tmp_semet.pdb_modified.pdb").read())
  pdb_inp = iotbx.pdb.hierarchy.input(file_name="tmp_semet.pdb_modified.pdb")
  found_sd = False
  for atom in pdb_inp.hierarchy.atoms() :
    labels = atom.fetch_labels()
    assert (labels.resname == "MET")
    if (atom.name == " SD ") :
      found_sd = True
      assert (atom.element == ' S')
      break
  assert (found_sd)
예제 #41
0
def exercise_convert_semet_to_met():
    open("tmp_semet.pdb", "w").write("""\
HETATM  507  N   MSE A 106      53.211  45.681  34.889  1.00  1.05           N
HETATM  508  CA  MSE A 106      51.827  45.381  35.207  1.00  1.35           C
HETATM  509  C   MSE A 106      50.937  45.462  33.968  1.00  3.57           C
HETATM  510  O   MSE A 106      49.956  44.737  33.860  1.00  4.67           O
HETATM  511  CB  MSE A 106      51.318  46.310  36.304  1.00  1.07           C
HETATM  512  CG  MSE A 106      49.833  46.180  36.603  1.00  1.06           C
HETATM  513 SE   MSE A 106      49.249  47.284  38.129  0.82 10.02          Se
HETATM  514  CE  MSE A 106      50.851  47.140  39.206  1.00  1.19           C
""")
    cmd = "phenix.pdbtools tmp_semet.pdb convert_semet_to_met=True"
    run_command(command=cmd, verbose=False)
    assert (not "HETATM" in open("tmp_semet.pdb_modified.pdb").read())
    pdb_inp = iotbx.pdb.hierarchy.input(file_name="tmp_semet.pdb_modified.pdb")
    found_sd = False
    for atom in pdb_inp.hierarchy.atoms():
        labels = atom.fetch_labels()
        assert (labels.resname == "MET")
        if (atom.name == " SD "):
            found_sd = True
            assert (atom.element == ' S')
            break
    assert (found_sd)
예제 #42
0
def exercise_show_geometry_statistics(pdb_dir, verbose):
    file_name = os.path.join(pdb_dir, "phe_e.pdb")
    assert file_name.find('"') < 0
    cmd = 'phenix.pdbtools "%s" --show-geometry-statistics' % file_name
    run_command(command=cmd, verbose=verbose)
예제 #43
0
    def iterate(self):
        self.n1 = self.nmodes
        if (self.Niter > 0):  # need to build PDB object from the last PDB file
            iter_name = self.root + str(self.Niter) + ".pdb"
            self.pdb = PDB(iter_name, method=self.method)
            self.pdb.Hessian(self.cutoff, self.nmode_init, self.scale_factor)

# Generate random normal modes
        self.modes = flex.int(range(self.nmodes - 1)) + 7
        self.modes.append(
            int(random.random() * (self.nmode_init - self.nmodes)) + 7 +
            self.nmodes)
        self.scale = 0

        candidates = []
        score = []
        for kk in range(self.topn * 10):
            if (kk == 0):
                vec = flex.random_double(self.nmodes) * 0
            else:
                vec = (flex.random_double(self.nmodes) -
                       0.5) * 2 * self.step_size
            result = self.target(vec)
            insert = 0
            for ii in range(len(score)):
                if (score[ii] > result):
                    score.insert(ii, result)
                    candidates.insert(ii, vec)
                    insert = 1
                    break
            if (insert == 0):
                score.append(result)
                candidates.append(vec)

        for kk in range(self.topn):
            self.starting_simplex = []
            cand = candidates[kk]
            for ii in range(self.n1):
                self.starting_simplex.append(
                    flex.double(self.orth(ii, self.n1)) * self.step_size +
                    cand)
            self.starting_simplex.append(cand)

            self.optimizer = simplex.simplex_opt(dimension=self.n1,
                                                 matrix=self.starting_simplex,
                                                 evaluator=self,
                                                 monitor_cycle=5,
                                                 tolerance=1e-2)
            self.x = self.optimizer.get_solution()
            candidates[kk] = self.x.deep_copy()
            score[kk] = self.optimizer.get_score()

        minscore = min(score[0:self.topn])
        print self.Niter, minscore, self.counter
        print >> self.chi, self.Niter, minscore

        if ((self.Niter % self.optNum) > 1):
            self.stopCheck(minscore)
        self.updateScore(minscore)
        minvec = candidates[score.index(minscore)]
        new_coord = self.pdb.NMPerturb(self.modes, minvec)
        print list(minvec)
        self.Niter = self.Niter + 1
        iter_base = self.root + str(self.Niter)
        iter_name = iter_base + ".pdb"
        self.pdb.writePDB(new_coord, iter_name)
        if (self.Niter % self.optNum == 0):
            print self.pulchra
            run_command(command=self.pulchra + ' ' + iter_name)
            run_command(command='mv ' + iter_base + '.rebuilt.pdb ' +
                        iter_name)

            #processed_pdb, pdb_inp = self.pdb_processor.process_pdb_files( pdb_file_names=[iter_name] )
            #new_coord = geo_opt(processed_pdb, self.log)
            #self.pdb.writePDB(new_coord,iter_name)
#    if(not self.stop):
        if (self.Niter < 40):
            self.iterate()
예제 #44
0
def exercise_mmcif_support():
    from libtbx.test_utils import open_tmp_file
    f = open_tmp_file(suffix="pdbtools.cif")
    f.write("""\
data_phenix
_space_group.name_H-M_alt         'C 1 2 1'
_space_group.name_Hall            ' C 2y'
_cell.length_a                    46.053
_cell.length_b                    9.561
_cell.length_c                    20.871
_cell.angle_alpha                 90.0
_cell.angle_beta                  97.43
_cell.angle_gamma                 90.0
_cell.volume                      9112.60599144
loop_
  _atom_site.group_PDB
  _atom_site.id
  _atom_site.label_atom_id
  _atom_site.label_alt_id
  _atom_site.label_comp_id
  _atom_site.auth_asym_id
  _atom_site.auth_seq_id
  _atom_site.pdbx_PDB_ins_code
  _atom_site.Cartn_x
  _atom_site.Cartn_y
  _atom_site.Cartn_z
  _atom_site.occupancy
  _atom_site.B_iso_or_equiv
  _atom_site.type_symbol
  _atom_site.pdbx_formal_charge
  _atom_site.label_asym_id
  _atom_site.label_entity_id
  _atom_site.label_seq_id
  _atom_site.pdbx_PDB_model_num
  ATOM      2  CA  .  LYS  A  1  ?    7.49733  -0.62028   4.35289  1.000  10.25989  C  ?  A  ?   1  1
  ATOM     11  CA  .  LEU  A  2  ?    3.72032  -0.19320   3.89326  1.000   7.80433  C  ?  A  ?   2  1
  ATOM     19  CA  .  VAL  A  3  ?    0.78668  -0.39555   6.35234  1.000   5.03864  C  ?  A  ?   3  1
  ATOM     26  CA  .  PHE  A  4  ?   -2.75438  -0.21383   5.02429  1.000   8.93080  C  ?  A  ?   4  1
  ATOM     37  CA  .  PHE  A  5  ?   -6.05155  -0.46197   6.85390  1.000   9.57417  C  ?  A  ?   5  1
  ATOM     48  CA  .  ALA  A  6  ?   -9.57646  -0.10942   5.55847  1.000  17.73488  C  ?  A  ?   6  1
  ATOM     54  CA  .  LYS  B  1  ?   -8.86604  -5.20044   5.46515  1.000  16.15297  C  ?  B  ?   7  1
""")
    f.close()
    cmd = " ".join([
        "phenix.pdbtools",
        "\"%s\"" % f.name, "rename_chain_id.old_id=A",
        "rename_chain_id.new_id=C"
    ])
    run_command(command=cmd, verbose=False)
    assert os.path.isfile(f.name + "_modified.pdb")
    pdb_inp = iotbx.pdb.input(file_name=f.name + "_modified.pdb")
    assert pdb_inp.file_type() == "pdb"
    hierarchy = pdb_inp.construct_hierarchy()
    assert [chain.id for chain in hierarchy.chains()] == ['C', 'B']
    cmd = " ".join([
        "phenix.pdbtools",
        "\"%s\"" % f.name, "adp.convert_to_anisotropic=True",
        "output.format=mmcif"
    ])
    run_command(command=cmd, verbose=False)
    assert os.path.isfile(f.name + "_modified.cif")
    pdb_inp = iotbx.pdb.input(file_name=f.name + "_modified.cif")
    assert pdb_inp.file_type() == "mmcif"
    xs = pdb_inp.xray_structure_simple()
    assert xs.use_u_aniso().all_eq(True)
예제 #45
0
def run_pulchra(input, output):
    cmd = 'pulchra %s' % (input)
    run_command(command=cmd)
예제 #46
0
def exercise_mmcif_support():
  from libtbx.test_utils import open_tmp_file
  f = open_tmp_file(suffix="pdbtools.cif")
  f.write("""\
data_phenix
_space_group.name_H-M_alt         'C 1 2 1'
_space_group.name_Hall            ' C 2y'
_cell.length_a                    46.053
_cell.length_b                    9.561
_cell.length_c                    20.871
_cell.angle_alpha                 90.0
_cell.angle_beta                  97.43
_cell.angle_gamma                 90.0
_cell.volume                      9112.60599144
loop_
  _atom_site.group_PDB
  _atom_site.id
  _atom_site.label_atom_id
  _atom_site.label_alt_id
  _atom_site.label_comp_id
  _atom_site.auth_asym_id
  _atom_site.auth_seq_id
  _atom_site.pdbx_PDB_ins_code
  _atom_site.Cartn_x
  _atom_site.Cartn_y
  _atom_site.Cartn_z
  _atom_site.occupancy
  _atom_site.B_iso_or_equiv
  _atom_site.type_symbol
  _atom_site.pdbx_formal_charge
  _atom_site.label_asym_id
  _atom_site.label_entity_id
  _atom_site.label_seq_id
  _atom_site.pdbx_PDB_model_num
  ATOM      2  CA  .  LYS  A  1  ?    7.49733  -0.62028   4.35289  1.000  10.25989  C  ?  A  ?   1  1
  ATOM     11  CA  .  LEU  A  2  ?    3.72032  -0.19320   3.89326  1.000   7.80433  C  ?  A  ?   2  1
  ATOM     19  CA  .  VAL  A  3  ?    0.78668  -0.39555   6.35234  1.000   5.03864  C  ?  A  ?   3  1
  ATOM     26  CA  .  PHE  A  4  ?   -2.75438  -0.21383   5.02429  1.000   8.93080  C  ?  A  ?   4  1
  ATOM     37  CA  .  PHE  A  5  ?   -6.05155  -0.46197   6.85390  1.000   9.57417  C  ?  A  ?   5  1
  ATOM     48  CA  .  ALA  A  6  ?   -9.57646  -0.10942   5.55847  1.000  17.73488  C  ?  A  ?   6  1
  ATOM     54  CA  .  LYS  B  1  ?   -8.86604  -5.20044   5.46515  1.000  16.15297  C  ?  B  ?   7  1
""")
  f.close()
  cmd = " ".join(["phenix.pdbtools", "\"%s\"" % f.name,
    "rename_chain_id.old_id=A",
    "rename_chain_id.new_id=C"])
  run_command(command=cmd, verbose=False)
  assert os.path.isfile(f.name+"_modified.pdb")
  pdb_inp = iotbx.pdb.input(file_name=f.name+"_modified.pdb")
  assert pdb_inp.file_type() == "pdb"
  hierarchy = pdb_inp.construct_hierarchy()
  assert [chain.id for chain in hierarchy.chains()] == ['C', 'B']
  cmd = " ".join(["phenix.pdbtools", "\"%s\"" % f.name,
    "adp.convert_to_anisotropic=True",
    "output.format=mmcif"])
  run_command(command=cmd, verbose=False)
  assert os.path.isfile(f.name+"_modified.cif")
  pdb_inp = iotbx.pdb.input(file_name=f.name+"_modified.cif")
  assert pdb_inp.file_type() == "mmcif"
  xs = pdb_inp.xray_structure_simple()
  assert xs.use_u_aniso().all_eq(True)
예제 #47
0
def geo_opt(input, output):
    log = "tmp.log"
    cmd = 'phenix.pdbtools %s --geometry-regularization modify.output.file_name=%s > %s' % (
        input, output, log)
    run_command(command=cmd)
예제 #48
0
def exercise_show_geometry_statistics(pdb_dir, verbose):
  file_name = os.path.join(pdb_dir, "phe_e.pdb")
  assert file_name.find('"') < 0
  cmd = 'phenix.pdbtools "%s" --show-geometry-statistics'%file_name
  run_command(command=cmd, verbose=verbose)