def tst_adding_disulfur_hydrogen_atoms(switch):
    element = 'H'
    if switch.endswith('_D'): element = 'D'
    fn = 'tst_ready_hydrogens_%s.pdb' % (switch)
    f = file(fn, 'wb')
    f.write(pdb_strings[switch])
    del f
    pdb_inp = pdb_input(fn)
    hierarchy = pdb_inp.construct_hierarchy()
    from mmtbx.conformation_dependent_library.testing_utils import get_geometry_restraints_manager
    grm = get_geometry_restraints_manager(pdb_filename=fn)
    add_disulfur_hydrogen_atoms(grm, hierarchy, element=element)
    hierarchy.write_pdb_file(fn.replace('.pdb', '_updated.pdb'))
    if switch == 'CYS_1':
        f = file(fn.replace('.pdb', '_updated.pdb'), 'rb')
        lines = f.read()
        del f
        assert lines.find('HG') == -1
    else:
        cmd = 'phenix.pdb_interpretation %s write_geo=True' % fn.replace(
            '.pdb', '_updated.pdb')
        print(cmd)
        easy_run.go(cmd)
        assert_lines_in_file(file_name='%s.geo' %
                             fn.replace('.pdb', '_updated.pdb'),
                             lines=geo_strings[switch])
예제 #2
0
def run_bond(prefix):
  edits = """
refinement {
  geometry_restraints.edits {
    bond {
      action = %s
      atom_selection_1 = %s
      atom_selection_2 = %s
      distance_ideal = 2.0
      sigma = 1.0
    }
  }
}
"""
  sel_old_1 = "chain A and resseq 7 and name C"
  sel_old_2 = "chain A and resseq 7 and name O"
  sel_new_1 = "chain A and resseq 7 and name CA"
  sel_new_2 = "chain A and resseq 7 and name O"
  cntr=0
  for action in ["add","delete","change"]:
    for kind in ["new","old"]:
      prefix_ = "%s_bond_%s_%s"%(prefix, kind, action)
      with open("%s.eff"%prefix_, "w") as f:
        f.write(edits%(action, eval("sel_%s_1"%kind), eval("sel_%s_2"%kind)))
      cmd = cmd_base%(prefix, prefix_)
      print (cmd)
      r = easy_run.fully_buffered(cmd)
      if action == "delete":
        cntr+=1
        assert r.stderr_lines[0] == \
            'Sorry: geometry_restraints.edits.bond.action = delete not implemented.'
      else:
        if kind == "new":
          if action == 'add':
            cntr+=1
            assert_lines_in_file(
                file_name = "%s.pdb.geo"%prefix,
                lines     = """bond pdb=" CA  ILE A   7 "
                             pdb=" O   ILE A   7 "
                          ideal  model  delta    sigma   weight residual
                          2.000  2.394 -0.394 1.00e+00 1.00e+00 1.56e-01""")
          elif action == 'change':
            cntr += 1
            assert r.stderr_lines[0] == "Sorry: Bond below does not exists, use action=add instead."
        elif(kind == "old"):
          if action == 'add':
            cntr += 1
            assert r.stderr_lines[0] == "Sorry: Bond below exists, use action=change instead."
          elif action == 'change':
            cntr+=1
            assert_lines_in_file(
                file_name = "%s.pdb.geo"%prefix,
                lines     = """bond pdb=" C   ILE A   7 "
                                  pdb=" O   ILE A   7 "
                          ideal  model  delta    sigma   weight residual
                          2.000  1.229  0.771 1.00e+00 1.00e+00 5.94e-01""")
  assert cntr==6
예제 #3
0
def exercise_2(prefix="tst_pdb_link_records_2"):
    with open('%s_mcm.cif' % prefix, 'w') as f:
        f.write(restr_cif_txt)
    with open('%s.pdb' % prefix, 'w') as f:
        f.write(pdb_2c_id)
    cmd = "phenix.geometry_minimization %s.pdb %s_mcm.cif write_geo=False" % (
        prefix, prefix)
    assert not easy_run.call(cmd)
    assert_lines_in_file(
        '%s_minimized.pdb' % prefix,
        "LINK         C   ALYaC   5                 N   MCMaC   6 ",
        remove_white_spaces=False)
예제 #4
0
def main():
    for code, item in pdbs.items():
        print(code)
        pf = 'tst_fe_s_%s.pdb' % code
        with open(pf, 'w') as f:
            f.write(item[0])
        cmd = 'phenix.pdb_interpretation %(pf)s > %(pf)s.log' % locals()
        print(cmd)
        easy_run.go(cmd)
        print(item[1])
        for line in item[1].split('\n'):
            print(line)
            assert_lines_in_file(file_name='%s.log' % pf, lines=line)
def test_3():
  """ test for command-line tool iotbx.unique_with_biomt"""
  inp = iotbx.pdb.input(source_info=None, lines=pdb_str_0)
  model = mmtbx.model.manager(model_input=inp)
  model.expand_with_BIOMT_records()
  model = shift_and_box_model(model)

  sel = model.selection("chain '0' or chain 'C' or chain 'F' or chain 'I' or chain 'L' or chain 'O' or chain 'R' or chain 'U' or chain 'X'")
  model = model.select(sel)
  pdb_str = model.model_as_pdb()
  fname = 'tst_reduce_model_with_biomt_test3.pdb'
  with open(fname, 'w') as f:
    f.write(pdb_str)
  assert os.path.isfile(fname)

  cmd = "iotbx.unique_with_biomt %s" % fname
  print(cmd)
  easy_run.call(cmd)
  res_fname = 'tst_reduce_model_with_biomt_test3_unique_biomt_000.cif'
  assert_lines_in_file(res_fname, """
      ATOM 1 N . LYS 0 151 ? 72.74200 43.65400 193.22800 14.010 14.01000 N ? A ? 1 1""")
  assert_lines_in_file(res_fname, """
      _pdbx_struct_assembly_gen.asym_id_list
       1 (1-9) A""")

  cmd = "iotbx.unique_with_biomt %s chain_id_to_leave='C' output.serial=1" % fname
  print(cmd)
  easy_run.call(cmd)
  res_fname = 'tst_reduce_model_with_biomt_test3_unique_biomt_001.cif'
  assert_lines_in_file(res_fname, """
      ATOM 1 N . LYS C 151 ? 186.74500 185.38200 236.77300 14.010 14.01000 N ? A ? 1 1""")
  assert_lines_in_file(res_fname, """
      _pdbx_struct_assembly_gen.asym_id_list
       1 (1-9) A""")
def exercise(prefix="tst_pdb_box_around_mol"):
  # test pdb format
  with open("%s.pdb" % prefix, 'w') as f:
    f.write(pdb_str)
  assert not easy_run.call("iotbx.pdb.box_around_molecule %s.pdb" % (
      prefix))
  assert_lines_in_file(file_name="%s_box_000.pdb" % prefix,
    lines="""\
CRYST1   10.847   12.316   12.145  90.00  90.00  90.00 P 1
SCALE1      0.092191  0.000000  0.000000        0.00000
SCALE2      0.000000  0.081195  0.000000        0.00000
SCALE3      0.000000  0.000000  0.082338        0.00000
ATOM      1  N   SER 1  71       5.439   5.000   5.057  1.00300.00           N
ATOM      2  CA  SER 1  71       5.000   6.424   5.000  1.00300.00           C
ATOM      3  C   SER 1  71       5.847   7.316   5.915  1.00300.00           C
ATOM      4  O   SER 1  71       5.736   7.242   7.145  1.00300.00           O
TER""")
  # test mmcif format
  if libtbx.env.find_in_repositories(relative_path='chem_data') is not None:
    with open("%s.cif" % prefix, 'w') as f:
      f.write(cif_str)
    assert not easy_run.call("iotbx.pdb.box_around_molecule %s.cif" % (
        prefix))
    assert_lines_in_file(file_name="%s_box_000.cif" % prefix,
      lines="""\
data_default
_cell.angle_beta                  90.000
_cell.angle_gamma                 90.000
_cell.length_b                    11.563
_cell.length_c                    11.512
_cell.angle_alpha                 90.000
_cell.volume                      1650.205
_cell.length_a                    12.397
_space_group.crystal_system       triclinic
_space_group.name_H-M_alt         'P 1'
_space_group.IT_number            1
_space_group.name_Hall            ' P 1'
_symmetry.space_group_name_H-M    'P 1'
_symmetry.Int_Tables_number       1
_symmetry.space_group_name_Hall   ' P 1'
loop_
  _space_group_symop.id
  _space_group_symop.operation_xyz
   1 x,y,z""")
  else:
    print('chem_data is not available, skipping')

  print("OK")
예제 #7
0
def exercise(prefix="tst_pdb_box_around_mol"):
    with open("%s.pdb" % prefix, 'w') as f:
        f.write(pdb_str)
    assert not easy_run.call(
        "iotbx.pdb.box_around_molecule %s.pdb > %s_boxed.pdb" %
        (prefix, prefix))
    assert_lines_in_file(file_name="%s_boxed.pdb" % prefix,
                         lines="""\
CRYST1   10.847   12.316   12.145  90.00  90.00  90.00 P 1
SCALE1      0.092191  0.000000  0.000000        0.00000
SCALE2      0.000000  0.081195  0.000000        0.00000
SCALE3      0.000000  0.000000  0.082338        0.00000
ATOM      1  N   SER 1  71       5.439   5.000   5.057  1.00300.00           N
ATOM      2  CA  SER 1  71       5.000   6.424   5.000  1.00300.00           C
ATOM      3  C   SER 1  71       5.847   7.316   5.915  1.00300.00           C
ATOM      4  O   SER 1  71       5.736   7.242   7.145  1.00300.00           O
TER""")
    print "OK"
예제 #8
0
def tst_adding_side_chain_acid_hydrogen_atoms(switch):
    element = 'H'
    if switch.endswith('_D'): element = 'D'
    for i in range(4):
        fn = 'tst_ready_hydrogens_%s_%d.pdb' % (switch, i)
        with open(fn, 'w') as f:
            f.write(pdb_strings[switch])
        pdb_inp = pdb_input(fn)
        hierarchy = pdb_inp.construct_hierarchy()
        add_side_chain_acid_hydrogens(hierarchy,
                                      configuration_index=i,
                                      element=element)
        hierarchy.write_pdb_file(fn.replace('.pdb', '_updated.pdb'))
        cmd = 'phenix.pdb_interpretation %s flip_sym=0 write_geo=True' % fn.replace(
            '.pdb', '_updated.pdb')
        print(cmd)
        easy_run.go(cmd)
        assert_lines_in_file(file_name='%s.geo' %
                             fn.replace('.pdb', '_updated.pdb'),
                             lines=geo_strings[switch][i])
def tst_1(prefix="tst_ref_model_ligands_1"):
  with open("%s.pdb" % prefix, 'w') as f:
    f.write(pdb_str)
  with open("%s.cif" % prefix, 'w') as f:
    f.write(restr_string)
  cmd = " ".join([
      "phenix.geometry_minimization",
      "%s.pdb" % prefix,
      "%s.cif" % prefix,
      "reference_model.enabled=True",
      "reference_model.file=%s.pdb" % prefix,
      ">%s.log" % prefix])
  print(cmd)
  assert not easy_run.call(cmd)
  assert_lines_in_file(
      file_name="%s.log" % prefix,
      lines=
          """Model:              Reference:
          LIG A   1  <=====>  LIG A   1
          Total # of matched residue pairs: 1
          Total # of reference model restraints: 1""")
예제 #10
0
def exercise(prefix="tst_pdb_box_around_mol"):
    # test pdb format
    with open("%s.pdb" % prefix, 'w') as f:
        f.write(pdb_str)
    assert not easy_run.call("iotbx.pdb.box_around_molecule %s.pdb" % (prefix))
    assert_lines_in_file(file_name="%s_box_000.pdb" % prefix,
                         lines="""\
CRYST1   10.847   12.316   12.145  90.00  90.00  90.00 P 1
SCALE1      0.092191  0.000000  0.000000        0.00000
SCALE2      0.000000  0.081195  0.000000        0.00000
SCALE3      0.000000  0.000000  0.082338        0.00000
ATOM      1  N   SER 1  71       5.439   5.000   5.057  1.00300.00           N
ATOM      2  CA  SER 1  71       5.000   6.424   5.000  1.00300.00           C
ATOM      3  C   SER 1  71       5.847   7.316   5.915  1.00300.00           C
ATOM      4  O   SER 1  71       5.736   7.242   7.145  1.00300.00           O
TER""")
    # test mmcif format
    if libtbx.env.find_in_repositories(relative_path='chem_data') is not None:
        with open("%s.cif" % prefix, 'w') as f:
            f.write(cif_str)
        assert not easy_run.call("iotbx.pdb.box_around_molecule %s.cif" %
                                 (prefix))
        # XXX temp fix for python3 failure
        # XXX changes in python 3 because _cell.length_a and other order differs

        # Python 3 behavior looks better.
        # Reason for this discrepancy is that starting from Python 3.7
        # "the insertion-order preservation nature of dict objects has been
        # declared to be an official part of the Python language spec."
        # https://docs.python.org/3/whatsnew/3.7.html
        # Basically, dict.keys() in Py3 preserves the order in which keys were added
        # to the dict.
        #
        # Sorting of mmCIF keys here
        # cctbx_project/iotbx/cif/__init__.py, def category_sort_function()
        # should be improved to address such issues universally (sorting within
        # category), note the diference in _space_group and _symmetry categories
        # as well.

        import sys
        if sys.version.startswith("3.8"):
            assert_lines_in_file(file_name="%s_box_000.cif" % prefix,
                                 lines="""\
data_default
_cell.length_a                    12.397
_cell.length_b                    11.563
_cell.length_c                    11.512
_cell.angle_alpha                 90.000
_cell.angle_beta                  90.000
_cell.angle_gamma                 90.000
_cell.volume                      1650.205
_space_group.crystal_system       triclinic
_space_group.IT_number            1
_space_group.name_H-M_alt         'P 1'
_space_group.name_Hall            ' P 1'
_symmetry.space_group_name_H-M    'P 1'
_symmetry.space_group_name_Hall   ' P 1'
_symmetry.Int_Tables_number       1
loop_
  _space_group_symop.id
  _space_group_symop.operation_xyz
   1 x,y,z""")
        else:  # version 2.7
            assert_lines_in_file(file_name="%s_box_000.cif" % prefix,
                                 lines="""\
data_default
_cell.angle_beta                  90.000
_cell.angle_gamma                 90.000
_cell.length_b                    11.563
_cell.length_c                    11.512
_cell.angle_alpha                 90.000
_cell.volume                      1650.205
_cell.length_a                    12.397
_space_group.crystal_system       triclinic
_space_group.name_H-M_alt         'P 1'
_space_group.IT_number            1
_space_group.name_Hall            ' P 1'
_symmetry.space_group_name_H-M    'P 1'
_symmetry.Int_Tables_number       1
_symmetry.space_group_name_Hall   ' P 1'
loop_
  _space_group_symop.id
  _space_group_symop.operation_xyz
   1 x,y,z""")

    else:
        print('chem_data is not available, skipping')

    print("OK")
예제 #11
0
def run():
    fn = '4udx_sf4.pdb'
    f = file(fn, 'wb')
    f.write(pdbs[fn])
    f.close()
    for i, superpose in enumerate(['None', 'all']):
        cmd = 'phenix.geometry_minimization %s superpose_ideal=%s' % (
            fn,
            superpose,
        )
        print cmd
        rc = easy_run.go(cmd)
        for line in rc.stdout_lines:
            #print line
            if line.find('bond_residual_sum') > -1:
                bond_value = round(float(line.split()[-1]))
            if line.find('angle_residual_sum') > -1:
                angle_value = round(float(line.split()[-1]))
        # in the second iteration bond_value and angle_value are expected to be 0!
        # assert bond_value, "%f %f" % (bond_value, results[fn][i][0])
        # assert angle_value, angle_value
        assert bond_value == results[fn][i][0], 'not matching %s to %s' % (
            bond_value,
            results[fn][i][0],
        )
        assert angle_value == results[fn][i][1], 'not matching %s to %s' % (
            angle_value,
            results[fn][i][1],
        )

    for i, superpose in enumerate(['None', 'all']):
        cmd = 'phenix.pdb_interpretation %s superpose_ideal=%s' % (
            fn,
            superpose,
        )
        print cmd
        rc = easy_run.go(cmd)
        for line in rc.stdout_lines:
            #print line
            if line.find('bond_residual_sum') > -1:
                value = round(float(line.split()[-1]))
                print 'value', value
                assert value == results[fn][i][2], 'not matching %s to %s' % (
                    value,
                    results[fn][i][2],
                )
            if line.find('angle_residual_sum') > -1:
                value = round(float(line.split()[-1]))
                print 'value', value
                assert value == results[fn][i][3], 'not matching %s to %s' % (
                    value,
                    results[fn][i][3],
                )

    fn = '4udx_sf4_cys.pdb'
    f = file(fn, 'wb')
    f.write(pdbs[fn])
    f.close()
    # lines = '''
    # SF4/F3S coordination
    #    SF4 X1001
    #      pdb="FE1  SF4 X1001 " - pdb=" SG  CYS X  51 "
    #      pdb="FE2  SF4 X1001 " - pdb=" SG  CYS X  48 "
    #      pdb="FE3  SF4 X1001 " - pdb=" SG  CYS X  56 "
    #      pdb="FE4  SF4 X1001 " - pdb=" SG  CYS X  70 "'''

    from libtbx.test_utils import assert_lines_in_file
    lines = [
        'SF4/F3S coordination',
        'SF4 X1001',
        'pdb="FE1  SF4 X1001 " - pdb=" SG  CYS X  51 "',
        'pdb="FE4  SF4 X1001 " - pdb=" SG  CYS X  70 "',
        'pdb="FE3  SF4 X1001 " - pdb=" SG  CYS X  56 "',
        'pdb="FE2  SF4 X1001 " - pdb=" SG  CYS X  48 "',
    ]
    cmd = 'phenix.pdb_interpretation %s link_all=True > %s.log' % (fn, fn)
    print cmd
    assert not easy_run.call(cmd)
    for line in lines:
        print line
        assert_lines_in_file(file_name='%s.log' % fn, lines=line)
    return 0
예제 #12
0
def run_angle(prefix):
    edits = """
refinement {
  geometry_restraints.edits {
    angle {
      action = %s
      atom_selection_1 = %s
      atom_selection_2 = %s
      atom_selection_3 = %s
      angle_ideal = 10
      sigma = 1
    }
  }
}
"""
    sel_old_1 = "chain A and resseq 7 and name N"
    sel_old_2 = "chain A and resseq 7 and name CA"
    sel_old_3 = "chain A and resseq 7 and name CB"
    sel_new_1 = "chain A and resseq 7 and name N"
    sel_new_2 = "chain A and resseq 7 and name CA"
    sel_new_3 = "chain A and resseq 7 and name CG2"
    cntr = 0
    for action in ["add", "delete", "change"]:
        for kind in ["new", "old"]:
            prefix_ = "%s_angle_%s_%s" % (prefix, kind, action)
            with open("%s.eff" % prefix_, "w") as f:
                f.write(edits %
                        (action, eval("sel_%s_1" % kind),
                         eval("sel_%s_2" % kind), eval("sel_%s_3" % kind)))
            cmd = cmd_base % (prefix, prefix_)
            print(cmd)
            r = easy_run.fully_buffered(cmd)
            if action == "add":
                if kind == "new":
                    cntr += 1
                    assert_lines_in_file(file_name="%s.pdb.geo" % prefix,
                                         lines="""
angle pdb=" N   ILE A   7 "
      pdb=" CA  ILE A   7 "
      pdb=" CG2 ILE A   7 "
    ideal   model   delta    sigma   weight residual
    10.00  143.31 -133.31 1.00e+00 1.00e+00 1.78e+04""")
                elif kind == "old":
                    cntr += 1
                    assert r.stderr_lines[0] == \
                        "Sorry: Some restraints were not added because they are already present."
            if action == "delete":
                cntr += 1
                assert r.stderr_lines[0] == \
                    'Sorry: geometry_restraints.edits.angle.action = delete not implemented.'
            if action == "change":
                if kind == "new":
                    cntr += 1
                    assert r.stderr_lines[0] == \
                        'Sorry: Angle below is not restrained, nothing to change.'
                elif kind == "old":
                    cntr += 1
                    assert_lines_in_file(file_name="%s.pdb.geo" % prefix,
                                         lines="""
angle pdb=" N   ILE A   7 "
      pdb=" CA  ILE A   7 "
      pdb=" CB  ILE A   7 "
    ideal   model   delta    sigma   weight residual
    10.00  109.54  -99.54 1.00e+00 1.00e+00 9.91e+03""")
    assert cntr == 6