示例#1
0
def run(prefix):
    """
  Exercise gradients match:
    - small vs large box:
      -- using clustering vs not using clustering.
  Non-P1 case (P212121)
  """
    data_file_prefix = "2olx"
    common_args = ["restraints=cctbx", "mode=opt", "parallel.nproc=1"]
    r = run_tests.run_cmd(
        prefix,
        args=common_args +
        ["clustering=true", "dump_gradients=cluster_true.pkl"],
        pdb_name=os.path.join(qr_unit_tests_data, "%s.pdb" % data_file_prefix),
        mtz_name=os.path.join(qr_unit_tests_data, "%s.mtz" % data_file_prefix))
    r = run_tests.run_cmd(
        prefix,
        args=common_args +
        ["clustering=false", "dump_gradients=cluster_false.pkl"],
        pdb_name=os.path.join(qr_unit_tests_data, "%s.pdb" % data_file_prefix),
        mtz_name=os.path.join(qr_unit_tests_data, "%s.mtz" % data_file_prefix))
    #
    g1 = flex.vec3_double(easy_pickle.load("cluster_false.pkl"))
    g2 = flex.vec3_double(easy_pickle.load("cluster_true.pkl"))
    assert g1.size() == g2.size()
    diff = g1 - g2
    if (0):
        for i, diff_i in enumerate(diff):
            print i, diff_i  #, g1[i], g2[i]
        print
    assert approx_equal(diff.max(), [0, 0, 0])
示例#2
0
def run(prefix):
    """
  Exercise standard (cctbx-based restraints) refinement with all defaults.
  """
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example()
    run_tests.run_cmd(prefix, args=["restraints=cctbx"])
    # Check results
    xrs_refined = iotbx.pdb.input(file_name=os.path.join(
        prefix, "m00_poor_refined.pdb")).xray_structure_simple()
    d = flex.sqrt((xrs_good.sites_cart() - xrs_poor.sites_cart()).dot())
    assert flex.mean(d) > 0.10
    d = flex.sqrt((xrs_good.sites_cart() - xrs_refined.sites_cart()).dot())
    assert flex.mean(d) < 0.05
    # Check R-factors
    r_start, r_final = None, None
    ofo = open("%s.log" % prefix, "r")
    for l in ofo.readlines():
        if (l.strip().endswith("n_fev: 0")):
            r_start = float(l.split()[2])
        if (l.strip().startswith("Best r_work:")):
            r_final = float(l.split()[2])
    assert r_start > 0.1
    assert r_final < 0.04
    # Make sure output model actually corresponds to reported R-factor
    fmodel = mmtbx.f_model.manager(f_obs=f_obs,
                                   r_free_flags=r_free_flags,
                                   xray_structure=xrs_refined)
    fmodel.update_all_scales()
    assert fmodel.r_work() < 0.04
    assert abs(r_final - fmodel.r_work()) < 0.0005, abs(r_final -
                                                        fmodel.r_work())
示例#3
0
def run(prefix):
    """
  Exercise standard (cctbx-based restraints) optimization (no data required).
  """
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example()
    run_tests.run_cmd(
        prefix=prefix,
        args=["restraints=cctbx mode=opt use_convergence_test=False"],
        mtz_name="")
    # Check results
    pdb_inp = iotbx.pdb.input(
        file_name=os.path.join(prefix, "m00_poor_refined.pdb"))
    model_1 = mmtbx.model.manager(model_input=pdb_inp,
                                  build_grm=True,
                                  log=null_out())
    s1 = model_1.geometry_statistics().result()
    assert s1.bond.mean < 0.005
    ##########################
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example()
    run_tests.run_cmd(
        prefix=prefix,
        args=["restraints=cctbx mode=opt use_convergence_test=False"])
    # Check results
    pdb_inp = iotbx.pdb.input(
        file_name=os.path.join(prefix, "m00_poor_refined.pdb"))
    model_2 = mmtbx.model.manager(model_input=pdb_inp,
                                  build_grm=True,
                                  log=null_out())
    s2 = model_2.geometry_statistics().result()
    assert s2.bond.mean < 0.005
    ###########################
    assert approx_equal(s1.bond.mean, s2.bond.mean, 0.0001)
示例#4
0
def run(prefix):
  """
  Exercise refinement  match:
  -- pdbs with altlocs
      -- using subtract vs using average
  """
  import multiprocessing
  nproc = str(multiprocessing.cpu_count())
  for data_file_prefix in ["h_altconf_complete", "h_altconf_2_complete"]:
    for maxnum in ["15"]:
      common_args = ["restraints=cctbx", "mode=refine", "parallel.nproc="+nproc, "clustering=true"] +\
        ["gradient_only=true", "maxnum_residues_in_cluster="+maxnum]
      r = run_tests.run_cmd(prefix,
        args     = common_args+["altloc_method=subtract", "output_file_name_prefix=subtract-"+data_file_prefix],
        pdb_name = os.path.join(qr_unit_tests_data,"%s.pdb"%data_file_prefix),
        mtz_name = os.path.join(qr_unit_tests_data,"%s.mtz"%data_file_prefix))
      r = run_tests.run_cmd(prefix,
        args     = common_args+["altloc_method=average", "output_file_name_prefix=average-"+data_file_prefix],
        pdb_name = os.path.join(qr_unit_tests_data,"%s.pdb"%data_file_prefix),
        mtz_name = os.path.join(qr_unit_tests_data,"%s.mtz"%data_file_prefix))
      sites_cart_average = iotbx.pdb.input("%s/average-%s_refined.pdb"%(prefix,data_file_prefix)).\
                       construct_hierarchy().extract_xray_structure().sites_cart()
      sites_cart_subtract = iotbx.pdb.input("%s/subtract-%s_refined.pdb"%(prefix,data_file_prefix)).\
                       construct_hierarchy().extract_xray_structure().sites_cart()
      rmsd_diff = sites_cart_average.rms_difference(sites_cart_subtract)
      assert approx_equal(rmsd_diff, 0, 0.2), 'rmsd diff between subtract and average is too large %0.3f' % rmsd_diff
示例#5
0
def run(prefix):
    """
  Exercise refine_sites=False.
  """
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example()
    run_tests.run_cmd(prefix, args=["restraints=cctbx", "refine_sites=False"])
    xrs_start = iotbx.pdb.input(file_name=os.path.join(
        qr_unit_tests, "data_files", "m00_poor.pdb")).xray_structure_simple()
    xrs_refined = iotbx.pdb.input(file_name=os.path.join(
        prefix, "m00_poor_refined.pdb")).xray_structure_simple()
    d = flex.sqrt((xrs_start.sites_cart() - xrs_refined.sites_cart()).dot())
    assert approx_equal(d.min_max_mean().as_tuple(), [0, 0, 0])
示例#6
0
def run(prefix):
    """
  Exercise standard (cctbx-based restraints) optimization.
  Assert mode=opt is approximately equivalent to data_weight=0.
  """
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example()
    # Run optimization
    run_tests.run_cmd(prefix, args=["restraints=cctbx", "mode=opt"])
    assert get_bond_rmsd(file_name=os.path.join(qr_unit_tests, "data_files",
                                                "m00_poor.pdb")) > 0.1
    assert get_bond_rmsd(
        file_name=os.path.join(prefix, "m00_poor_refined.pdb")) < 0.0009
    #Run refinement without data term
    run_tests.run_cmd(prefix, args=["restraints=cctbx", "data_weight=0"])
    assert get_bond_rmsd(
        file_name=os.path.join(prefix, "m00_poor_refined.pdb")) < 0.0009
示例#7
0
def run(prefix="tst_18"):
    """
  Exercise gradients match:
  -- pdbs with altlocs
      -- using clustering with less clusters vs not using clustering.
      -- using clustering with more clusters vs not using clustering.
  """
    import multiprocessing
    nproc = str(multiprocessing.cpu_count())
    for data_file_prefix in ["h_altconf_complete", "h_altconf_2_complete"]:
        for maxnum in ["15", "2"]:
            common_args = ["restraints=cctbx", "mode=opt", "parallel.nproc="+nproc] +\
                      ["altloc_method=subtract","maxnum_residues_in_cluster="+maxnum]
            r = run_tests.run_cmd(
                prefix,
                args=common_args +
                ["clustering=true", "dump_gradients=cluster_true.pkl"],
                pdb_name=os.path.join(qr_unit_tests_data,
                                      "%s.pdb" % data_file_prefix),
                mtz_name=os.path.join(qr_unit_tests_data,
                                      "%s.mtz" % data_file_prefix))
            r = run_tests.run_cmd(
                prefix,
                args=common_args +
                ["clustering=false", "dump_gradients=cluster_false.pkl"],
                pdb_name=os.path.join(qr_unit_tests_data,
                                      "%s.pdb" % data_file_prefix),
                mtz_name=os.path.join(qr_unit_tests_data,
                                      "%s.mtz" % data_file_prefix))
            #
            g1 = flex.vec3_double(easy_pickle.load("cluster_false.pkl"))
            g2 = flex.vec3_double(easy_pickle.load("cluster_true.pkl"))
            assert g1.size() == g2.size()
            diff = g1 - g2
            if (0):
                for i, diff_i in enumerate(diff):
                    print i, diff_i  #, g1[i], g2[i]
            assert approx_equal(diff.max(), [0, 0, 0],
                                [1.0E-3, 1.0E-3, 1.0E-3])
示例#8
0
def run(prefix="tst_06"):
    """
  Exercise altlocs.
  """
    run_tests.assert_folder_is_empty(prefix=prefix)
    xrs_good, xrs_poor, f_obs, r_free_flags = run_tests.setup_helix_example(
        pdb_name="altlocs.pdb", mtz_name="altlocs.mtz")
    r = run_tests.run_cmd(prefix,
                          args=["restraints=cctbx"],
                          pdb_name="altlocs.pdb",
                          mtz_name="altlocs.mtz")
    #assert r.stdout_lines == \
    #   ['Sorry: Alternative conformations are not supported.']
    run_tests.clean_up(prefix, mtz_name="altlocs.mtz")
示例#9
0
def run(prefix):
    """
  Exercise gradients match:
    - small vs large box:
      -- using clustering vs not using clustering.
  """
    for restraints in ["cctbx", "qm"]:
        #for restraints in ["cctbx",]:
        # XXX qm option is not supposed to work fulfull the test with 2ona_box_S
        # XXX qm option is currently suspected to be broken for 2ona_box_L
        for data_file_prefix in ["2ona_box_L", "2ona_box_S"]:
            if (restraints is "qm" and data_file_prefix is "2ona_box_S"):
                continue
            common_args = [
                "restraints=%s" % restraints, "mode=opt", "parallel.nproc=1",
                "quantum.engine_name=mopac", "two_buffers=true"
            ]
            args = common_args + [
                "clustering=false", "dump_gradients=cluster_false.pkl"
            ]
            r = run_tests.run_cmd(
                prefix,
                args=args,
                pdb_name=os.path.join(qr_unit_tests_data,
                                      "%s.pdb" % data_file_prefix),
                mtz_name=os.path.join(qr_unit_tests_data,
                                      "%s.mtz" % data_file_prefix))

            args = common_args + [
                "clustering=true", "dump_gradients=cluster_true.pkl"
            ]
            r = run_tests.run_cmd(
                prefix,
                args=args,
                pdb_name=os.path.join(qr_unit_tests_data,
                                      "%s.pdb" % data_file_prefix),
                mtz_name=os.path.join(qr_unit_tests_data,
                                      "%s.mtz" % data_file_prefix))

            #
            g1 = easy_pickle.load("cluster_false.pkl")
            g2 = easy_pickle.load("cluster_true.pkl")
            if (restraints is "cctbx"):
                ##tight comparison
                ## clustering cctbx should match the atomic gradients
                ## at x,y,z directions
                g1 = g1.as_double()
                g2 = g2.as_double()
                assert g1.size() == g2.size()
                diff = g1 - g2
                if (0):
                    for i, diff_i in enumerate(diff):
                        print i + 1, diff_i, g1[i], g2[i]
                    print
                assert approx_equal(g1, g2, 1.0E-4)
            else:
                ## loose comparison
                ## clustering qm just checks the norm of gradients from
                ## x, y, z directions
                assert approx_equal(g1.norm(), g2.norm(), g1.norm() * 0.05)
                g1_norms = flex.sqrt(g1.dot())
                g2_norms = flex.sqrt(g2.dot())
                for i in range(g1_norms.size()):
                    #print i+1, g1_norms[i], g2_norms[i], g1_norms[i]*0.2
                    assert approx_equal(g1_norms[i], g2_norms[i],
                                        g1_norms[i] * 0.2)