Beispiel #1
0
    def test_calcall3(self):

        try:
            qcalc = os.path.join(os.environ["QBIN_DIR"], "Qcalc6")
        except KeyError:
            raise Exception("QBIN_DIR environment variable not defined.")

        dirs = [
            "data/qgroupcontrib/testrep1", "data/qgroupcontrib/testrep2",
            "data/qgroupcontrib/testrep3"
        ]

        pdb = "data/qgroupcontrib/dfpase_dfp_start.pdb"

        qgc = QGroupContrib(qcalc, dirs, pdb, "q_enfiles.list", [0.86, 0.14],
                            [0.46, 0.54], 15, 20, 1, 1,
                            [4841, 4842, 4843, 4844])
        try:
            qgc.calcall()
        except KeyboardInterrupt:
            qgc.kill_event.set()
            raise

        de1, de2, lras, reorgs = qgc.gcs_stats.get_columns([5, 9, 13, 17])
        assert is_close(de1[4], -0.475)
        assert is_close(de2[4], -0.84)
        assert is_close(lras[4], -0.6575)
        assert is_close(reorgs[4], 0.1825)
Beispiel #2
0
    def test_calcall(self):

        try:
            qcalc = os.path.join(os.environ["QBIN_DIR"], "Qcalc6")
        except KeyError:
            raise Exception("QBIN_DIR environment variable not defined.")

        dirs = [
            "data/qgroupcontrib/testrep1", "data/qgroupcontrib/testrep2",
            "data/qgroupcontrib/testrep3"
        ]

        pdb = "data/qgroupcontrib/dfpase_dfp_start.pdb"

        qgc = QGroupContrib(qcalc, dirs, pdb, "q_enfiles.list", [0.86, 0.14],
                            [0.46, 0.54], 15, 20, 1, 1, None)
        try:
            qgc.calcall()
        except KeyboardInterrupt:
            qgc.kill_event.set()
            raise

        de1, de2, lras, reorgs = qgc.gcs_stats.get_columns([5, 9, 13, 17])
        # Glu19
        # qcalc manual calculation + pen&paper
        # REP1:
        #    E1_1 = 79.51, E2_1 = 68.34, E1_2 = 79.42, E2_2 = 65.88
        #    de1 = -11.17, de2 = -13.54, lra = -12.355, reorg = 1.185
        # REP2:
        #    E1_1 = 76.02, E2_1 = 64.62, E1_2 = 79.88, E2_2 = 67.55
        #    de1 = -11.4, de2 = -12.33, lra = -11.865, reorg = 0.465
        # means:
        #    de1 = -11.285, de2 = -12.935, lra = -12.11, reorg = 0.825
        assert is_close(de1[4], -11.285)
        assert is_close(de2[4], -12.935)
        assert is_close(lras[4], -12.11)
        assert is_close(reorgs[4], 0.825)
Beispiel #3
0
    def test_calcall2(self):

        try:
            qcalc = os.path.join(os.environ["QBIN_DIR"], "Qcalc6")
        except KeyError:
            raise Exception("QBIN_DIR environment variable not defined.")

        dirs = [
            "data/qgroupcontrib/testrep1", "data/qgroupcontrib/testrep2",
            "data/qgroupcontrib/testrep3"
        ]

        pdb = "data/qgroupcontrib/dfpase_dfp_start.pdb"

        # set the iscale to 4.0
        qgc = QGroupContrib(qcalc, dirs, pdb, "q_enfiles.list", [0.86, 0.14],
                            [0.46, 0.54], 15, 20, 4.0, 1, None)
        try:
            qgc.calcall()
        except KeyboardInterrupt:
            qgc.kill_event.set()
            raise

        de1, de2, lras, reorgs = qgc.gcs_stats.get_columns([5, 9, 13, 17])
        try:
            qgc.calcall()
        except KeyboardInterrupt:
            qgc.kill_event.set()
            raise

        de1, de2, lras, reorgs = qgc.gcs_stats.get_columns([5, 9, 13, 17])
        # Glu19 scaled down by 4 (see above)
        assert is_close(de1[4], -2.82125)
        assert is_close(de2[4], -3.23375)
        assert is_close(lras[4], -3.0275)
        assert is_close(reorgs[4], 0.20625)
Beispiel #4
0
def gc(args):

    if not os.path.lexists(args.pdb):
        print "This file went missing: {}".format(args.pdb)
        sys.exit(1)

    if args.qmaskfile:
        try:
            qmask = open(args.qmaskfile, "r").read().split()
            if not qmask:
                raise IOError
        except IOError:
            print "Can't read '{}' or file empty".format(args.qmaskfile)
            sys.exit(1)
    else:
        qmask = None

    lambdas = []
    for lamb in args.lra_l:
        try:
            lamb = float(lamb)
            if lamb < 0 or lamb > 1:
                raise ValueError
        except ValueError:
            print "FATAL! Lambda values make no sense. 0 <= lambda <= 1 please."
            sys.exit(1)
        lambdas.append((lamb, 1 - lamb))

    calcdirs = args.dirs
    if not calcdirs:
        lsdir = os.listdir(os.getcwd())
        calcdirs = [f for f in lsdir if os.path.isdir(f)]
    if not calcdirs:
        calcdirs = [
            os.getcwd(),
        ]
        print "No subdirectories. Calculating in current directory only.\n"
    else:
        print "Will use these directories for calculating GCs (use --dirs to "\
              "change this): {}\n".format(", ".join(calcdirs))

    qgc = QGroupContrib(args.qcalc_exec, calcdirs, args.pdb,
                        QScfg.get("files", "en_list_fn"), lambdas[0],
                        lambdas[1], args.resid_first, args.resid_last,
                        args.scale_ionized, args.nthreads, qmask)

    try:
        qgc.calcall()
    except QGroupContribError as error_msg:
        print "\nMassive fail:\n{}\n".format(error_msg)
        sys.exit(1)
    except KeyboardInterrupt:
        qgc.kill_event.set()
        raise

    # writeout QCalc inputs and outputs
    if args.writeout:
        for calcdir, (qcinps, qcouts) in qgc._qcalc_io.iteritems():
            for i, qci in enumerate(qcinps):
                fn = os.path.join(calcdir, "q_calc.gc.{}.inp".format(i + 1))
                try:
                    open(fn, 'w').write(qci)
                except OSError as err:
                    print "Error when writing to {}: {}".format(fn, err)
                else:
                    print "Wrote {}".format(fn)
            for i, qco in enumerate(qcouts):
                fn = os.path.join(calcdir, "q_calc.gc.{}.out".format(i + 1))
                try:
                    open(fn, 'w').write(qco)
                except OSError as err:
                    print "Error when writing to {}: {}".format(fn, err)
                else:
                    print "Wrote {}".format(fn)

    # write out details and top 10 GCs to stdout and outfile
    if not qgc.gcs:
        top_gcs = "None, all directories failed..."
        top_gcs_reorg = "None, all directories failed..."
    else:
        top_rows = sorted(qgc.gcs_stats.get_rows(),
                          key=lambda x: -abs(x[13]))[:10]

        out_l = ["{:<10} {:>10} {:>10}".format("# Residue", "Mean", "Stdev")]

        for row in top_rows:
            rid, rn, el, elstd = row[0], row[1], row[13], row[14]

            tmp = "{}_{}".format(rn.capitalize(), rid)
            tmp2 = "{:<10} {:10.2f} {:10.2f}".format(tmp, el, elstd)
            out_l.append(tmp2)

        top_gcs = "\n".join(out_l)

        top_rows = sorted(qgc.gcs_stats.get_rows(),
                          key=lambda x: -abs(x[17]))[:10]

        out_l = ["{:<10} {:>10} {:>10}".format("# Residue", "Mean", "Stdev")]

        for row in top_rows:
            rid, rn, el, elstd = row[0], row[1], row[17], row[18]

            tmp = "{}_{}".format(rn.capitalize(), rid)
            tmp2 = "{:<10} {:10.2f} {:10.2f}".format(tmp, el, elstd)
            out_l.append(tmp2)

        top_gcs_reorg = "\n".join(out_l)

    outstr = """
{gc_details}
Top LRA (el) contributions:
{top_gcs}

Top REORG (el) contributions:
{top_gcs_reorg}
""".format(gc_details=qgc.details,
           top_gcs=top_gcs,
           top_gcs_reorg=top_gcs_reorg)

    print outstr
    fn_out = args.output_fn
    backup = backup_file(fn_out)
    if backup:
        print "# Backed up '{}' to '{}'".format(fn_out, backup)
    open(fn_out, "w").write(outstr)
    print "Wrote '{}'...".format(fn_out)

    # convert plots to json and write them out
    fn_out = args.plots_out
    plots = qgc.plotdata
    jsonenc = plotdata.PlotDataJSONEncoder(indent=2)
    backup = backup_file(fn_out)
    if backup:
        print "# Backed up '{}' to '{}'".format(fn_out, backup)
    open(fn_out, 'w').write(jsonenc.encode(plots))
    print "Wrote '{}'... (q_plot.py is your "\
          "friend)".format(fn_out)

    # writeout the pdbgc if requested
    if args.pdbgc_out:
        backup = backup_file(args.pdbgc_out)
        if backup:
            print "# Backed up '{}' to '{}'".format(args.pdbgc_out, backup)
        open(args.pdbgc_out, 'w').write(qgc.get_pdbgc())
        print "Wrote '{}'... (use Pymol/Chimera/VMD and color by occupancy "\
              "(LRA) or B-factor (reorg))".format(args.pdbgc_out)