def process_file(traj, top_file, resname, report, outputFilename, format_out,
                 new_report, epoch):
    start = time.time()
    sasa_values = calculateSASA(traj, top_file, resname)
    header = ""
    if not new_report:
        try:
            reportFilename = glob.glob(report)[0]
        except IndexError:
            raise IndexError("File %s not found" % report)
        if outputFilename != reportFilename:
            reportFilename = outputFilename

        with open(reportFilename) as f:
            header = f.readline().rstrip()
            if not header.startswith("#"):
                header = ""
            reportFile = utilities.loadtxtfile(f)

        fixedReport = analysis_utils.extendReportWithRmsd(
            reportFile, sasa_values)
    else:
        indexes = np.array(range(sasa_values.shape[0]))
        fixedReport = np.concatenate((indexes[:, None], sasa_values[:, None]),
                                     axis=1)

    with open(outputFilename, "w") as fw:
        if header:
            fw.write("%s\tSASA\n" % header)
        else:
            fw.write("# Step\tSASA\n")
        np.savetxt(fw, fixedReport, fmt=format_out, delimiter="\t")
    end = time.time()
    print("Took %.2fs to process" % (end - start), traj)
def calculate_rmsd_traj(nativePDB, resname, symmetries, rmsdColInReport, traj, reportName, top, epoch, outputFilename, fmt_str, new_report):
    top_proc = None
    if top is not None:
        top_proc = utilities.getTopologyFile(top)
    rmsds = utilities.getRMSD(traj, nativePDB, resname, symmetries, topology=top_proc)

    if new_report:
        fixedReport = np.zeros((rmsds.size, 2))
        fixedReport[:, 0] = range(rmsds.size)
        fixedReport[:, 1] = rmsds
        header = ""
    else:
        with open(reportName) as f:
            header = f.readline().rstrip()
            if not header.startswith("#"):
                header = ""
            reportFile = utilities.loadtxtfile(reportName)
        if rmsdColInReport > 0 and rmsdColInReport < reportFile.shape[1]:
            reportFile[:, rmsdColInReport] = rmsds
            fixedReport = reportFile
        else:
            fixedReport = analysis_utils.extendReportWithRmsd(reportFile, rmsds)

    with open(outputFilename, "w") as fw:
        if header:
            fw.write("%s\tRMSD\n" % header)
        else:
            fw.write("# Step\tRMSD\n")
        np.savetxt(fw, fixedReport, fmt=fmt_str)
def process_file(report, outputFilename, format_out, new_report, epoch,
                 energy_column):
    try:
        reportFilename = glob.glob(report)[0]
    except IndexError:
        raise IndexError("File %s not found" % report)

    with open(reportFilename) as f:
        header = f.readline().rstrip()
        if not header.startswith("#"):
            header = ""
        reportFile = utilities.loadtxtfile(f)
    energy_values = reportFile[:, energy_column]
    energy_values = preprocessing.scale(energy_values)

    if not new_report:
        if outputFilename != reportFilename:
            reportFile = utilities.loadtxtfile(outputFilename)
        fixedReport = analysis_utils.extendReportWithRmsd(
            reportFile, energy_values)
    else:
        header = ""
        indexes = np.array(range(energy_values.shape[0]))
        fixedReport = np.concatenate(
            (indexes[:, None], energy_values[:, None]), axis=1)

    with open(outputFilename, "w") as fw:
        if header:
            fw.write("%s\tEnergy\n" % header)
        else:
            fw.write("# Step\tEnergy\n")
        np.savetxt(fw, fixedReport, fmt=format_out, delimiter="\t")