Esempio n. 1
0
def run(file_name,
        d_min=0.8,
        maxnum_residues_in_cluster=3,
        filter_non_protein_and_hd=True):
    prefix = os.path.basename(file_name)[3:7]
    print file_name, prefix
    pdb_inp = iotbx.pdb.input(file_name=file_name)
    resolution = pdb_inp.resolution()
    data_type = pdb_inp.get_experiment_type()
    if (resolution is not None and resolution <= d_min):
        if (data_type in ["X-RAY DIFFRACTION", "NEUTRON DIFFRACTION"]):
            pdb_hierarchy = pdb_inp.construct_hierarchy()
            xray_structure = pdb_hierarchy.extract_xray_structure()
            xray_structure.convert_to_isotropic()
            pdb_hierarchy.adopt_xray_structure(xray_structure)
            if (filter_non_protein_and_hd):
                pdb_hierarchy = keep_protein_only(pdb_hierarchy=pdb_hierarchy)
            if (pdb_hierarchy is not None):
                if (have_conformers(pdb_hierarchy=pdb_hierarchy)):
                    pdb_hierarchy.remove_alt_confs(
                        always_keep_one_conformer=True)
                pdb_hierarchy = add_hydrogens_using_ReadySet(
                    pdb_hierarchy=pdb_hierarchy)
                box = box_pdb(pdb_hierarchy=pdb_hierarchy)
                fq = fragments(
                    pdb_hierarchy=box.pdb_hierarchy,
                    maxnum_residues_in_cluster=maxnum_residues_in_cluster,
                    debug=True,
                    crystal_symmetry=box.cs)
                print "clusters:", fq.clusters
                os.mkdir(prefix)
                cntr = 0
                for fname in os.listdir(os.getcwd()):
                    if fname.endswith("_cluster.pdb"):
                        if check_missing_atom(pdb_filename=fname):
                            os.remove(fname)
                        else:
                            cl_fn = "%s_%d.pdb" % (prefix, cntr)
                            fo = open(cl_fn, "w")
                            ph_i = iotbx.pdb.input(
                                file_name=fname).construct_hierarchy()
                            ph_i = completion.run(pdb_hierarchy=ph_i,
                                                  crystal_symmetry=box.cs,
                                                  model_completion=False)
                            pdb_str = ph_i.as_pdb_string(
                                crystal_symmetry=box.cs, append_end=True)
                            pdb_str = validate(pdb_str=pdb_str)
                            if (pdb_str is None): continue
                            charge = charges_class(
                                raw_records=pdb_str).get_total_charge()
                            fo.write("REMARK charge= %s \n" % str(charge))
                            fo.write(pdb_str)
                            fo.close()
                            cntr += 1
                            libtbx.easy_run.fully_buffered("mv %s %s" %
                                                           (cl_fn, prefix))
                libtbx.easy_run.fully_buffered("rm -rf *.pdb ase/")
    if not os.listdir(prefix):
        os.rmdir(prefix)
        print "Empty dir"
Esempio n. 2
0
def run(maxnum_residues_in_cluster):
  result = []
  for clustering in [True, False]:
    if 0: print("  clustering", clustering, "-"*30)
    model = get_model()
    fq = from_cctbx(restraints_manager = model.get_restraints_manager())
    if(clustering):
      fm = fragments(
       working_folder             = os.path.split("./ase/tmp_ase.pdb")[0]+ "/",
       clustering_method          = betweenness_centrality_clustering,
       maxnum_residues_in_cluster = maxnum_residues_in_cluster,
       altloc_method              = "subtract",
       charge_embedding           = False,
       two_buffers                = False,
       clustering                 = clustering,
       pdb_hierarchy              = model.get_hierarchy().deep_copy(),
       qm_engine_name             = "mopac",
       fast_interaction           = True,
       crystal_symmetry           = model.crystal_symmetry())
    else:
      fc = fq
    fc = from_cluster(
      restraints_manager = fq,
      fragment_manager   = fm,
      parallel_params    = get_master_phil().extract())
    energy, gradients = fc.target_and_gradients(sites_cart=model.get_sites_cart())
    gradients = gradients.as_double()
    result.append(gradients.deep_copy())
  diff = flex.abs(result[0] - result[1])
  max_diff = flex.max(diff)
  #print "  max(diff_grad):", max_diff
  assert max_diff < 1.e-9
Esempio n. 3
0
def run(pdb_file, log, maxnum_residues_in_cluster=15):
    print >> log, "max number of residues in each cluster:\n", maxnum_residues_in_cluster
    pdb_inp = iotbx.pdb.input(pdb_file)
    ph = pdb_inp.construct_hierarchy()
    cs = pdb_inp.crystal_symmetry()
    fq = fragments(
        pdb_hierarchy=ph,
        crystal_symmetry=cs,
        maxnum_residues_in_cluster=int(maxnum_residues_in_cluster),
        qm_run=False)  # not run qm_calculation, just the clustering result
    print >> log, "Residue indices for each cluster:\n", fq.clusters
Esempio n. 4
0
def run(file_name,
        d_min=0.9,
        maxnum_residues_in_cluster=5,
        filter_non_protein=True):
    pdb_inp = iotbx.pdb.input(file_name=file_name)
    pdb_hierarchy = pdb_inp.construct_hierarchy()
    fq = fragments(pdb_hierarchy=pdb_hierarchy,
                   maxnum_residues_in_cluster=maxnum_residues_in_cluster,
                   debug=True,
                   crystal_symmetry=pdb_inp.crystal_symmetry())
    print "clusters:", fq.clusters
Esempio n. 5
0
def run(file_name,
        d_min=0.9,
        maxnum_residues_in_cluster=5,
        filter_non_protein=True):
    pdb_inp = iotbx.pdb.input(file_name=file_name)
    pdb_hierarchy = pdb_inp.construct_hierarchy()
    pdb_hierarchy = keep_protein_only(pdb_hierarchy=pdb_hierarchy)
    pdb_hierarchy.remove_alt_confs(always_keep_one_conformer=True)
    fq = fragments(pdb_hierarchy=pdb_hierarchy,
                   maxnum_residues_in_cluster=maxnum_residues_in_cluster,
                   debug=True,
                   crystal_symmetry=pdb_inp.crystal_symmetry())
    print "clusters:", fq.clusters
Esempio n. 6
0
def run(prefix):
    """
  Exercise combined energy and gradients from cluster qm.
  """
    for restraints in ["cctbx", "qm"]:
        if 0:
            print("Using restraints:", restraints)
        result = []
        for clustering in [True, False]:
            if 0:
                print("  clustering", clustering, "-" * 30)
            model = get_model()
            if (restraints == "qm"):
                fq = from_qm(pdb_hierarchy=model.get_hierarchy(),
                             qm_engine_name="mopac",
                             method="PM3",
                             crystal_symmetry=model.crystal_symmetry(),
                             clustering=clustering)
            else:
                fq = from_cctbx(
                    restraints_manager=model.get_restraints_manager())
            if (clustering):
                fm = fragments(
                    working_folder=os.path.split("./ase/tmp_ase.pdb")[0] + "/",
                    clustering_method=betweenness_centrality_clustering,
                    maxnum_residues_in_cluster=8,
                    charge_embedding=False,
                    two_buffers=False,
                    fast_interaction=True,
                    pdb_hierarchy=model.get_hierarchy().deep_copy(
                    ),  # deep copy just in case
                    qm_engine_name="mopac",
                    crystal_symmetry=model.crystal_symmetry())
                fc = from_cluster(restraints_manager=fq,
                                  fragment_manager=fm,
                                  parallel_params=get_master_phil().extract())
            else:
                fc = fq
            energy, gradients = fc.target_and_gradients(
                sites_cart=model.get_sites_cart())
            if (restraints == "qm"):
                energy = energy * (kcal / mol) * (kcal / mol) / Hartree
                gradients = gradients * (kcal / mol) * (kcal / mol) * (Bohr /
                                                                       Hartree)
            gradients = gradients.as_double()
            result.append(gradients.deep_copy())
        #
        diff = flex.abs(result[0] - result[1])
        max_diff = flex.max(diff)
Esempio n. 7
0
def run(pdb_file, log):
    pdb_inp = iotbx.pdb.input(pdb_file)
    ph = pdb_inp.construct_hierarchy()
    cs = pdb_inp.crystal_symmetry()
    fq = fragments(pdb_hierarchy=ph,
                   crystal_symmetry=cs,
                   charge_embedding=True,
                   debug=True,
                   qm_engine_name="terachem")
    print >> log, "Residue indices for each cluster:\n", fq.clusters
    fq_ext = fragment_extracts(fq)
    for i in xrange(len(fq.clusters)):
        # add capping for the cluster and buffer
        print >> log, "capping frag:", i
        get_qm_file_name_and_pdb_hierarchy(fragment_extracts=fq_ext, index=i)
        print >> log, "point charge file:", i
        #write mm point charge file
        write_mm_charge_file(fragment_extracts=fq_ext, index=i)
Esempio n. 8
0
def generate_restraints(cs, ph, clustering=False):
    fq = from_qm(pdb_hierarchy=ph,
                 qm_engine_name="mopac",
                 crystal_symmetry=cs,
                 clustering=clustering)
    if (clustering):
        fm = fragments(working_folder=os.path.split("./ase/tmp_ase.pdb")[0] +
                       "/",
                       clustering_method=betweenness_centrality_clustering,
                       maxnum_residues_in_cluster=8,
                       charge_embedding=False,
                       two_buffers=True,
                       pdb_hierarchy=ph,
                       qm_engine_name="mopac",
                       fast_interaction=True,
                       crystal_symmetry=cs)
        restraints = from_cluster(restraints_manager=fq,
                                  fragment_manager=fm,
                                  parallel_params=get_master_phil().extract())
    else:
        restraints = fq
    return restraints
Esempio n. 9
0
def run(pdb_file, log):
    pdb_inp = iotbx.pdb.input(pdb_file)
    ph = pdb_inp.construct_hierarchy()
    cs = pdb_inp.crystal_symmetry()
    print >> log, '\n\tfragmenting "%s"' % pdb_file
    t0 = time.time()
    #
    # use a pickle file of fragments so testing of parallel is snappy
    #
    fq_fn = '%s_fq.pickle' % pdb_file.replace('.pdb', '')
    if not os.path.exists(fq_fn):
        fq = fragments(pdb_hierarchy=ph,
                       crystal_symmetry=cs,
                       charge_embedding=True,
                       debug=False,
                       qm_engine_name="orca")
        print >> log, '\n\tfragmenting took %0.1f\n' % (time.time() - t0)
        print >> log, "Residue indices for each cluster:\n", fq.clusters
        fq_ext = fragment_extracts(fq)
        f = file(fq_fn, 'wb')
        pickle.dump(fq_ext, f)
        f.close()
    else:
        f = file(fq_fn, 'rb')
        fq_ext = pickle.load(f)
        f.close()
    #
    # get QM engine
    #
    qm_engine = Orca()
    if 0:
        #
        # use parallel_map
        #
        #indices = range(len(fq.clusters))
        indices = range(len(fq_ext.fragment_selections))
        rc = run_all(
            qm_engine,
            fq_ext,
            indices,
            processes=6,
        )
        print rc
    elif 0:
        #
        # use multi_core_run
        #
        from libtbx import easy_mp
        nproc = 6
        argss = []
        results = []
        #for i in xrange(len(fq.clusters)):
        for i in range(len(fq_ext.fragment_selections)):
            argss.append([qm_engine, fq_ext, i])
        for args, res, err_str in easy_mp.multi_core_run(
                get_qm_energy,
                argss,
                nproc,
        ):
            print '%sTotal time: %6.2f (s)' % (' ' * 7, time.time() - t0)
            print args[-1], res
            if err_str:
                print 'Error output from %s' % args
                print err_str
                print '_' * 80
            results.append([args, res, err_str])
        print '-' * 80
        for args, res, err_str in results:
            print args[-1], res
    else:
        #
        # serial
        #
        #for i in xrange(len(fq.clusters)):
        for i in range(len(fq_ext.fragment_selections)):
            # add capping for the cluster and buffer
            print >> log, "capping frag:", i
            energy = get_qm_energy(qm_engine, fq_ext, i)
            print >> log, " frag:", i, "  energy:", energy, ' time:', print_time(
                time.time() - t0)
            time.sleep(10)
Esempio n. 10
0
def run(prefix):
    """
  Exercise combined energy and gradients from cluster qm.
  """
    #e = -4770.51146839
    e = -0.0188567309879
    g = [
        -0.08456615549999999, 0.10127334349999997, -0.10242523249999999,
        0.005342293499999999, -0.11995874419999995, -0.07123394619999997,
        -0.0181705993, 0.10454728429999999, -0.04413921959999999,
        0.009679603399999999, -0.009121438199999998, 0.017765005099999998,
        -0.10292599449999999, -0.021032337599999992, 0.19227364749999998,
        0.20080026099999998, 0.07756343689999999, 0.04037623699999999,
        0.022457268599999993, -0.19447525149999997, -0.08313646499999999,
        0.08618981049999999, 0.11223422999999998, -0.03263333429999998,
        -0.12023754289999997, 0.04570431589999999, 0.07184392599999999,
        -0.09959662779999998, 0.05599450589999998, -0.18692389119999994,
        0.14166337219999994, 0.10928884749999995, -0.00010803089999999996,
        -0.09286083449999998, 0.0070887217999999995, -0.042819663499999994,
        0.011747478199999996, 0.0020709142999999998, 0.0155718881,
        0.09978134159999996, -0.16828699659999996, 0.20112003719999993,
        -0.13691679659999995, 0.04693286069999999, -0.020098479499999995,
        0.006421124799999999, -0.14228682679999996, 0.03074080909999999,
        -0.06345386689999997, 0.0540718306, -0.2192631818999999,
        -0.09424992719999997, 0.0876742437, 0.08769038159999999,
        -0.017843138899999996, -0.020051329499999992, -0.10296862299999995,
        0.0036765932, -0.0011355988999999997, 0.0336712045,
        0.14390991449999999, -0.058120583499999996, 0.23378543549999994,
        -0.04526928529999999, -0.09279928339999997, -0.10211093629999997,
        0.13913907279999996, -0.021608406899999995, 0.03163317669999999,
        -0.046078754099999994, 0.08021273509999997, -0.2133580607,
        -0.09506438349999997, -0.11225534059999999, 0.002175395599999999,
        0.02810503409999999, 0.034700818599999995, -0.04577220239999999,
        -0.0031643896, 0.006103702599999998, -0.013420845099999999,
        0.04734791989999999, -0.04087237219999999, 0.27310615299999996,
        0.09222950209999997, 0.030048884899999996, -0.10796715279999998,
        0.024249821599999992, 0.08609433989999997, 0.11100423779999997,
        -0.0908682388, 0.11657135879999994, -0.18054697989999993, 0.1363704825,
        -0.0612450326, -0.06956100439999999, -0.05383942109999999,
        0.07699810309999998, -0.03252626399999999, 0.014023944299999999,
        -0.007865846099999999, 0.013593557999999999, 0.03773802329999999,
        -0.1629163042, 0.22817627809999996, -0.038193966499999996,
        0.13891371279999998, -0.010524218799999997, -0.08517528979999998,
        -0.07180391979999999, 0.08937603319999998, -0.08876329529999998,
        0.06411278599999999, -0.20456718929999995, 0.06752903599999999,
        0.14215725829999998, 0.047365303699999986, -0.07095322129999998,
        -0.015525017399999997, -0.0555983734, 0.010615422799999996,
        0.0017179213999999993, 0.0119133477, 0.13235639709999997,
        -0.13802391619999999, 0.21295888619999995, -0.13386174689999994,
        -0.012668172499999998, -0.05137007749999999, 0.0643506372,
        -0.12679474069999994, 0.013655725699999996, -0.042072087299999984,
        0.0728243264, -0.22654012409999996, -0.14573698399999999,
        0.025316557999999992, 0.06546370409999999, 0.03143893629999999,
        -0.0021188467, -0.08296277749999997, -0.008833872099999996,
        -0.004236358899999999, 0.019423341599999998, 0.10096460029999998,
        -0.04916252659999999, 0.2626485158, 0.02541927949999999,
        -0.06881671389999998, -0.12597456279999997, 0.12323139989999995,
        0.02877757349999999, 0.06864828369999999, -0.013625003799999995,
        0.11928656539999999, -0.21394597359999995, -0.007209919599999998,
        -0.15212524499999996, -0.051973657499999985, 0.021747500799999993,
        0.04431474299999998, -0.023677993699999997, -0.002670129099999999,
        0.0019006115999999997, -0.007955863099999998, -0.024645625899999992,
        -0.09768972109999997, 0.26912261289999995, 0.08742696429999998,
        0.10077918939999997, -0.05481312519999999, -0.06490659249999998,
        0.045055832199999986, 0.11830992419999996, -0.04679164979999999,
        0.10801289749999997, -0.20996703789999993, 0.1619887609, 0.0189571961,
        -0.014714428099999996, -0.0779905827, 0.052030067499999985,
        -0.04978193019999999, 0.013969698299999996, -0.008418040199999999,
        0.022545170099999994, 0.027116685899999996, -0.16116820019999997,
        0.23463616229999995, -0.09975993879999998, 0.10186490829999997,
        -0.0291957566, -0.060009407699999996, -0.12147408619999997,
        0.04644019639999999, -0.03950867969999999, 0.06864468099999999,
        -0.21645581219999993, -0.04352159619999999, 0.13685605209999996,
        0.06394913949999997, -0.029060687099999993, -0.035780113999999995,
        -0.07880487589999997, 0.0012057329999999998, -0.003457790599999999,
        0.008208808999999997, 0.10429058969999998, -0.10613049529999999,
        0.24350930369999996, -0.0803707538, -0.0717863952,
        -0.09746923109999997, 0.11602792729999999, -0.07391092899999997,
        0.037259427599999985, -0.0015554781999999997, 0.08293186139999999,
        -0.20200613059999997, -0.14833666199999998, -0.05584847209999998,
        -0.0069063241, 0.04999217049999999, 0.011683344699999997,
        -0.07303952619999997, 0.004491002799999999, 0.0008760120999999998,
        0.010574099399999997, 0.02846439539999999, -0.040399862999999994,
        0.2780464814, 0.09680116969999997, -0.017292296299999996,
        -0.10586559739999998, 0.05384248459999999, 0.0748885907,
        0.10969722139999996, -0.03653972, 0.11935011549999996,
        -0.19070836209999995, 0.08581903909999998, -0.12018963119999997,
        -0.04881325499999999, -0.017609414599999998, 0.06085935429999999,
        -0.06904357269999999, 0.002511758599999999, 0.007746915999999999,
        0.0158303274, -0.025517339699999995, -0.13106877169999998,
        0.25135694819999993, 0.030080269599999994, 0.13709668719999998,
        -0.033244503599999996, -0.09850133139999998, -0.007615988199999999,
        0.10309588899999998, -0.08454689749999997, 0.08028340959999998,
        -0.17584256699999995, 0.11473156629999999, 0.0690920467,
        0.0035207403999999998, 0.1530698161, 0.06053849989999999,
        0.004663570399999998, -0.05215193699999999, -0.03866576739999999,
        -0.050896319599999996, -0.07301203669999999, -0.0208231669,
        0.017359334199999993, 0.09495519929999997, -0.15792162779999994,
        0.21719830599999995, -0.12020762609999999, 0.06283927129999999,
        -0.044325136599999995, -0.02876324339999999, -0.12972709869999993,
        0.04722357629999999
    ]
    pdb_inp = iotbx.pdb.input(
        os.path.join(qr_unit_tests, "data_files", "helix.pdb"))
    ph = pdb_inp.construct_hierarchy()
    cs = pdb_inp.crystal_symmetry()
    sites_cart = ph.atoms().extract_xyz()

    fq = from_qm(
        pdb_hierarchy=ph,
        qm_engine_name="mopac",
        crystal_symmetry=cs,
        clustering=True,
    )

    fm = fragments(working_folder=os.path.split("./ase/tmp_ase.pdb")[0] + "/",
                   clustering_method=betweenness_centrality_clustering,
                   maxnum_residues_in_cluster=8,
                   charge_embedding=False,
                   pdb_hierarchy=ph,
                   qm_engine_name="mopac",
                   crystal_symmetry=cs)

    fc = from_cluster(
        restraints_manager=fq,
        fragment_manager=fm,
        parallel_params=get_master_phil().extract(),
    )

    energy, gradients = fc.target_and_gradients(sites_cart=sites_cart)
    energy = energy * (kcal / mol) * (kcal / mol) / Hartree
    gradients = gradients * (kcal / mol) * (kcal / mol) * (Bohr / Hartree)
    gradients = list(gradients.as_double())
    os.system("rm -rf ase")
    assert approx_equal(energy, e, 1.0E-4)