Exemplo n.º 1
0
def main(argv=None):
    """ Runs the main program.

    @param argv: The command line arguments.
    :return: The return code for the program's termination.
    """
    args, ret = parse_cmdline(argv)
    if ret != 0:
        return ret

    if args.src_file is not None:
        proc_data = calc_for_wham(args.src_file)
        write_csv(proc_data, create_out_fname(args.src_file, prefix=OUT_PFX), COLVAR_WHAM_KEY_SEQ)
    else:
        found_files = find_files_by_dir(args.base_dir, args.pattern)
        logger.debug("Found '%d' dirs with files to process", len(found_files))
        # noinspection PyCompatibility
        for f_dir, files in found_files.iteritems():
            if not files:
                logger.warn("No files found for dir '%s'", f_dir)
                continue
            for colvar_path in ([os.path.join(f_dir, tgt) for tgt in files]):
                proc_data = calc_for_wham(colvar_path)
                f_name = create_out_fname(colvar_path, prefix=OUT_PFX)
                if allow_write(f_name, overwrite=args.overwrite):
                    list_to_file([str(d['r']) for d in proc_data if 'r' in d], f_name)
                    # write_csv(proc_data, f_name, COLVAR_WHAM_KEY_SEQ, extrasaction="ignore")
    return 0  # success
Exemplo n.º 2
0
def main(argv=None):
    """ Runs the main program.

    @param argv: The command line arguments.
    :return: The return code for the program's termination.
    """
    args, ret = parse_cmdline(argv)
    if ret != 0:
        return ret

    if args.src_file is not None:
        proc_data = calc_for_wham(args.src_file)
        write_csv(proc_data, create_out_fname(args.src_file, prefix=OUT_PFX),
                  COLVAR_WHAM_KEY_SEQ)
    else:
        found_files = find_files_by_dir(args.base_dir, args.pattern)
        logger.debug("Found '%d' dirs with files to process", len(found_files))
        # noinspection PyCompatibility
        for f_dir, files in found_files.iteritems():
            if not files:
                logger.warn("No files found for dir '%s'", f_dir)
                continue
            for colvar_path in ([os.path.join(f_dir, tgt) for tgt in files]):
                proc_data = calc_for_wham(colvar_path)
                f_name = create_out_fname(colvar_path, prefix=OUT_PFX)
                if allow_write(f_name, overwrite=args.overwrite):
                    list_to_file([str(d['r']) for d in proc_data if 'r' in d],
                                 f_name)
                    # write_csv(proc_data, f_name, COLVAR_WHAM_KEY_SEQ, extrasaction="ignore")
    return 0  # success
Exemplo n.º 3
0
def main(argv=None):
    """ Runs the main program.

    :param argv: The command line arguments.
    :return: The return code for the program's termination.
    """
    args, ret = parse_cmdline(argv)
    if ret != GOOD_RET or args is None:
        return ret

    kbt = calc_kbt(args.temp)

    if args.src_file is not None:
        proc_data = to_zero_point(calc_rad(args.src_file, kbt))
        write_csv(proc_data, create_out_fname(args.src_file, prefix=OUT_PFX),
                  RAD_KEY_SEQ)
    else:
        found_files = find_files_by_dir(args.base_dir, args.pattern)
        logger.debug("Found '{}' dirs with files to process".format(
            len(found_files)))
        # noinspection PyCompatibility
        for f_dir, files in found_files.items():
            if not files:
                logger.warn("No files found for dir '{}'".format(f_dir))
                continue
            for pmf_path in ([os.path.join(f_dir, tgt) for tgt in files]):
                proc_data = to_zero_point(calc_rad(pmf_path, kbt))
                f_name = create_out_fname(pmf_path, prefix=OUT_PFX)
                if allow_write(f_name, overwrite=args.overwrite):
                    write_csv(proc_data, f_name, RAD_KEY_SEQ)
    return GOOD_RET  # success
Exemplo n.º 4
0
def main(argv=None):
    """ Runs the main program.

    :param argv: The command line arguments.
    :return: The return code for the program's termination.
    """
    args, ret = parse_cmdline(argv)
    if ret != GOOD_RET or args is None:
        return ret

    kbt = calc_kbt(args.temp)

    if args.src_file is not None:
        proc_data = to_zero_point(calc_rad(args.src_file, kbt))
        write_csv(proc_data, create_out_fname(args.src_file, prefix=OUT_PFX), RAD_KEY_SEQ)
    else:
        found_files = find_files_by_dir(args.base_dir, args.pattern)
        logger.debug("Found '{}' dirs with files to process".format(len(found_files)))
        # noinspection PyCompatibility
        for f_dir, files in found_files.iteritems():
            if not files:
                logger.warn("No files found for dir '{}'".format(f_dir))
                continue
            for pmf_path in ([os.path.join(f_dir, tgt) for tgt in files]):
                proc_data = to_zero_point(calc_rad(pmf_path, kbt))
                f_name = create_out_fname(pmf_path, prefix=OUT_PFX)
                if allow_write(f_name, overwrite=args.overwrite):
                    write_csv(proc_data, f_name, RAD_KEY_SEQ)
    return GOOD_RET  # success
Exemplo n.º 5
0
def write_avg_rmsd(tgt_dir, rmsd, overwrite=False):
    """
    Writes out all of the described RMSD files into the given target directory.

    :param tgt_dir: The data where the files will go.
    :param rmsd: A dict of an array of floats keyed by file name.
    :param overwrite: Whether to overwrite existing files.
    """
    for rmsd_fname, data in rmsd.items():
        f_name = os.path.join(tgt_dir, rmsd_fname)
        if allow_write(f_name, overwrite=overwrite):
            write_rmsd(data, f_name)
Exemplo n.º 6
0
def write_avg_rmsd(tgt_dir, rmsd, overwrite=False):
    """
    Writes out all of the described RMSD files into the given target directory.

    :param tgt_dir: The data where the files will go.
    :param rmsd: A dict of an array of floats keyed by file name.
    :param overwrite: Whether to overwrite existing files.
    """
    for rmsd_fname, data in rmsd.items():
        f_name = os.path.join(tgt_dir, rmsd_fname)
        if allow_write(f_name, overwrite=overwrite):
            write_rmsd(data, f_name)
Exemplo n.º 7
0
def write_result(result, src_file, overwrite=False, basedir=None):
    """Writes the result to a file named for the given source file.

    :param result: The result to write.
    :param src_file: The original source file name.
    :param overwrite: Whether to overwrite an existing file name.
    :param basedir: The base directory to target (uses the source file's base directory
        if not specified)
    """
    f_name = create_out_fname(src_file, prefix=OUT_PFX, base_dir=basedir)
    if allow_write(f_name, overwrite=overwrite):
        write_csv(result, f_name, OUT_KEY_SEQ)
Exemplo n.º 8
0
def write_submit(tgt_dir, sub_tpl_base, sub_tpl_line, step, overwrite=False):
    """
    Uses the given templates and step number to write a submit script to the given target file location.

    :param sub_tpl_base: The base template.
    :param sub_tpl_line: The line template.
    :param step: The step number.
    :param tgt_dir: The target directory.
    :param overwrite: Whether to allow overwrites.
    """
    sub_file = os.path.join(tgt_dir, STEP_SUBMIT_FNAME.format(step))
    if allow_write(sub_file, overwrite):
        wham_fill = fill_submit_wham(sub_tpl_base, sub_tpl_line, step, use_part=False)
        str_to_file(wham_fill, sub_file)
Exemplo n.º 9
0
def write_submit(tgt_dir, sub_tpl_base, sub_tpl_line, step, overwrite=False):
    """
    Uses the given templates and step number to write a submit script to the given target file location.

    :param sub_tpl_base: The base template.
    :param sub_tpl_line: The line template.
    :param step: The step number.
    :param tgt_dir: The target directory.
    :param overwrite: Whether to allow overwrites.
    """
    sub_file = os.path.join(tgt_dir, STEP_SUBMIT_FNAME.format(step))
    if allow_write(sub_file, overwrite):
        wham_fill = fill_submit_wham(sub_tpl_base, sub_tpl_line, step, use_part=False)
        str_to_file(wham_fill, sub_file)
Exemplo n.º 10
0
def rmsd_split(meta_file,
               steps,
               tpl_dir=DEF_TPL_DIR,
               overwrite=False,
               base_dir=None):
    """
    Reads the given meta file, fetches the RMSD files in the inventory, and creates a succession
    of directories that split the original RMSD files into a larger number of chunks for each step
    such that step 1 will create a split of 2 in 01_01 and 01_02, etc.

    :param meta_file: The initial meta file.
    :param steps: The number of averaging steps to perform.
    :param tpl_dir: The directory that contains the submit templates.
    :param overwrite: Whether to overwrite existing files.
    :param base_dir: The base directory to write to (defaults to the meta file's dir)
    """
    meta = read_meta(meta_file)
    rmsd = read_meta_rmsd(meta)
    sub_tpl_base = read_tpl(os.path.join(tpl_dir, DEF_BASE_SUBMIT_TPL))
    sub_tpl_line = read_tpl(os.path.join(tpl_dir, DEF_PART_LINE_SUBMIT_TPL))

    if not base_dir:
        base_dir = meta[DIR_KEY]
    for step in range(1, steps + 1):
        for rmsd_fname, data in rmsd.items():
            data_len = len(data)
            chunk_num = step + 1
            chunk_size = math.floor(data_len / chunk_num)
            logger.debug(STEP_DBG_MSG, step, data_len, rmsd_fname, chunk_num,
                         chunk_size)

            rmsd_chunks = [ch for ch in chunk(data, chunk_size, list)]
            for step_part in range(1, chunk_num + 1):
                rmsd_tgt_dir = os.path.join(
                    base_dir, SPLIT_DIR_FMT.format(step, step_part))
                if not os.path.exists(rmsd_tgt_dir):
                    os.makedirs(rmsd_tgt_dir)
                f_name = os.path.join(rmsd_tgt_dir, rmsd_fname)
                if allow_write(f_name, overwrite=overwrite):
                    write_rmsd(rmsd_chunks[step_part - 1], f_name)

        write_meta(base_dir, meta, step, overwrite)
        write_submit(base_dir, sub_tpl_base, sub_tpl_line, step, overwrite)
Exemplo n.º 11
0
def write_avg_stdev(result, out_fname, overwrite=False, basedir=None):
    """Writes the result to a file named for the given source file.

    :param result: The result to write.
    :param out_fname: The target out file.
    :param overwrite: Whether to overwrite an existing file name.
    :param basedir: The base directory to target (uses the source file's base directory
        if not specified)
    """
    if basedir:
        tgt_file = os.path.join(basedir, out_fname)
    else:
        tgt_file = out_fname

    if allow_write(tgt_file, overwrite=overwrite):
        with open(tgt_file, 'w') as csv_file:
            res_writer = csv.writer(csv_file)
            res_writer.writerow(OUT_KEY_SEQ)
            for res_row in sorted(result):
                res_writer.writerow(res_row)
        print("Wrote file: {}".format(tgt_file))
Exemplo n.º 12
0
def write_meta(tgt_dir, meta, step, overwrite=False):
    """
    Writes out the meta file using the original meta data structure as a beginning.

    :param tgt_dir: The target directory for the meta file.
    :param meta: The parsed data from the original meta file.
    :param step: The step number being processed.
    :param overwrite: Whether to overwrite an existing meta file.
    """
    step_meta = STEP_META_FNAME.format(step)
    f_name = os.path.join(tgt_dir, step_meta)
    if allow_write(f_name, overwrite=overwrite):
        with open(f_name, 'w') as m_file:
            for m_line in meta[LINES_KEY]:
                rmsd_loc = os.path.join("{:02d}".format(step),
                                        os.path.basename(m_line[0]))
                m_file.write(rmsd_loc)
                m_file.write('\t')
                m_file.write('\t'.join(m_line[1:]))
                m_file.write('\n')
        print("Wrote file: {}".format(f_name))
Exemplo n.º 13
0
def write_meta(tgt_dir, meta, step, overwrite=False):
    """
    Writes out the meta file using the original meta data structure as a beginning.

    :param tgt_dir: The target directory for the meta file.
    :param meta: The parsed data from the original meta file.
    :param step: The step number being processed.
    :param overwrite: Whether to overwrite an existing meta file.
    """
    step_meta = STEP_META_FNAME.format(step)
    f_name = os.path.join(tgt_dir, step_meta)
    if allow_write(f_name, overwrite=overwrite):
        with open(f_name, 'w') as m_file:
            for m_line in meta[LINES_KEY]:
                rmsd_loc = os.path.join("{:02d}".format(step),
                                        os.path.basename(m_line[0]))
                m_file.write(rmsd_loc)
                m_file.write('\t')
                m_file.write('\t'.join(m_line[1:]))
                m_file.write('\n')
        print("Wrote file: {}".format(f_name))
Exemplo n.º 14
0
def rmsd_split(meta_file, steps, tpl_dir=DEF_TPL_DIR, overwrite=False, base_dir=None):
    """
    Reads the given meta file, fetches the RMSD files in the inventory, and creates a succession
    of directories that split the original RMSD files into a larger number of chunks for each step
    such that step 1 will create a split of 2 in 01_01 and 01_02, etc.

    :param meta_file: The initial meta file.
    :param steps: The number of averaging steps to perform.
    :param tpl_dir: The directory that contains the submit templates.
    :param overwrite: Whether to overwrite existing files.
    :param base_dir: The base directory to write to (defaults to the meta file's dir)
    """
    meta = read_meta(meta_file)
    rmsd = read_meta_rmsd(meta)
    sub_tpl_base = read_tpl(os.path.join(tpl_dir, DEF_BASE_SUBMIT_TPL))
    sub_tpl_line = read_tpl(os.path.join(tpl_dir, DEF_PART_LINE_SUBMIT_TPL))

    if not base_dir:
        base_dir = meta[DIR_KEY]
    for step in range(1, steps + 1):
        for rmsd_fname, data in rmsd.items():
            data_len = len(data)
            chunk_num = step + 1
            chunk_size = math.floor(data_len / chunk_num)
            logger.debug(STEP_DBG_MSG, step, data_len, rmsd_fname, chunk_num, chunk_size)

            rmsd_chunks = [ch for ch in chunk(data, chunk_size, list)]
            for step_part in range(1, chunk_num + 1):
                rmsd_tgt_dir = os.path.join(base_dir, SPLIT_DIR_FMT.
                                            format(step, step_part))
                if not os.path.exists(rmsd_tgt_dir):
                    os.makedirs(rmsd_tgt_dir)
                f_name = os.path.join(rmsd_tgt_dir, rmsd_fname)
                if allow_write(f_name, overwrite=overwrite):
                    write_rmsd(rmsd_chunks[step_part - 1], f_name)

        write_meta(base_dir, meta, step, overwrite)
        write_submit(base_dir, sub_tpl_base, sub_tpl_line, step, overwrite)