Пример #1
0
def pair_avg(vals):
    """
    Returns a list of the average between pairs of numbers in the input list.  If there is an odd
    final input value, it is dropped.

    :param vals:  A list of floats to pair and average.
    :return: The average of adjacent pairs in the given input list.
    """
    results = []
    for pair in chunk(vals, 2, list):
        if len(pair) == 2:
            results.append(sum(pair) / 2)
        else:
            warning("'{}' is not a pair".format(pair))

    return results
Пример #2
0
def pair_avg(vals):
    """
    Returns a list of the average between pairs of numbers in the input list.  If there is an odd
    final input value, it is dropped.

    :param vals:  A list of floats to pair and average.
    :return: The average of adjacent pairs in the given input list.
    """
    results = []
    for pair in chunk(vals, 2, list):
        if len(pair) == 2:
            results.append(sum(pair) / 2)
        else:
            warning("'{}' is not a pair".format(pair))

    return results
Пример #3
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)
Пример #4
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)