示例#1
0
def no_slurm( cmd: List[str],
              current_case_file: Path,
              current_sse: str,
              unimaster: Path,
              imaster: Path,
              unidata: Path ):
    """
    """
    # Search on MASTER
    result = []
    for com in cmd:
        TButil.plugin_bash(com)
        run(com, stdout=DEVNULL)
        outf = Path(com[-1])
        if outf.is_file():
            result.append(str(outf))
    result.insert(0, 'cat')
    TButil.plugin_filemaker('Unify matches at {0}'.format(unimaster))
    with unimaster.open('w') as fd:
        run(result, stdout=fd)
    result[0] = 'rm'
    run(result[:-2], stdout=DEVNULL)

    # Analyze
    createbash = 'python {0} -case {1} -master {2} -present {3} -out {4}'
    cmd = shlex.split(createbash.format(imaster, current_case_file, unimaster, current_sse, unidata))
    TButil.plugin_bash(cmd)
    run(cmd, stdout=DEVNULL)
示例#2
0
def make_mode_stats( df: pd.DataFrame, wdir: Path ) -> pd.DataFrame:
    """
    """
    data = {'close': [], 'mid': [], 'far': [], 'extreme': []}
    topi, midi, boti = [], [], []

    for angle in [x for x in df.columns if x.startswith('angles_') or x.startswith('points_')]:
        for part in ['close', 'mid', 'far', 'extreme']:
            dfp = df[df['bin'] == part]
            for lay in df.layer.unique():
                for sse in df.sse.unique():
                    dfs = dfp[(dfp['sse'] == sse) & (dfp['layer'] == lay)]
                    try:
                        kde = sc.stats.gaussian_kde(dfs[angle])
                        x = np.linspace(dfs[angle].min(), dfs[angle].max(), 200)
                        kde = kde(x)
                        mode = x[np.argsort(kde)[-1]]
                    except ValueError:
                        mode = 0
                    data[part].append(mode)
                    if part == 'close':
                        topi.append(angle)
                        midi.append(lay)
                        boti.append(sse)
    stats = pd.DataFrame(data, index=pd.MultiIndex.from_tuples(list(zip(*[topi, midi, boti])),
                                                               names=['measure', 'layer', 'sse']))
    stats.reset_index().to_csv(wdir.joinpath('mode_stats.csv'), index=False)
    TButil.plugin_filemaker('Mode stats stored at {}'.format(wdir.joinpath('mode_stats.csv')))
    return stats
示例#3
0
def execute(log: Logger, data: Dict, wpaths: Dict) -> Dict:
    """Run Rosetta.
    """
    if TBcore.get_option('slurm', 'use'):
        slurm_file = wpaths['main'].joinpath('submit_hybridize.sh')
        TButil.plugin_filemaker('Submission file at {}'.format(slurm_file))
        with slurm_file.open('w') as fd:
            fd.write(TButil.slurm_header() + '\n')
            for k in ['assembly', 'design']:
                cmd = [
                    'srun',
                ]
                cmd.extend(data['cmd'][k])
                fd.write(' '.join([str(x) for x in cmd]) + '\n')

        if TBcore.get_option('system', 'verbose'):
            sys.stdout.write(
                'Submiting jobs to SLURM... this might take a while\n')
        TButil.submit_slurm(slurm_file)
    else:
        for k in ['assembly', 'design']:
            log.notice(
                f'EXECTUE: {" ".join([str(x) for x in data["cmd"][k]])}')
            run([str(x) for x in data['cmd'][k]], stdout=DEVNULL)
    return data
示例#4
0
def with_slurm( cmd: List[str],
                current_case_file: Path,
                current_sse: str,
                unimaster: Path,
                imaster: Path,
                unidata: Path ):
    """
    """
    # Make bashfile
    bashcont = []
    createbash = 'python {0} -case {1} -master {2} -present {3} -out {4}'
    parts = math.ceil(len(cmd) / TBcore.get_option('slurm', 'array'))

    wwd = unimaster.parent.parent
    cwd = Path().cwd()
    os.chdir(str(wwd))

    for i, com in enumerate(cmd):
        cmd[i][2] = str(Path(com[2]).relative_to(wwd))
        cmd[i][-1] = str(Path(com[-1]).relative_to(wwd))

    for ii, cp in enumerate(cmd):
        cmd[ii][-1] = cp[-1] + '_${SLURM_ARRAY_TASK_ID}'
    for j, i in enumerate(range(0, len(cmd), parts)):
        sumfile = unimaster.parent.joinpath('_${SLURM_ARRAY_TASK_ID}.master').relative_to(wwd)
        datfile = unimaster.parent.joinpath('_${SLURM_ARRAY_TASK_ID}.geo').relative_to(wwd)
        bashcont.append('if (( ${{SLURM_ARRAY_TASK_ID}} == {} )); then'.format(j + 1))
        bashcont.extend([' '.join(x) for x in cmd[i:i + parts]])
        bashcont.append('cat {0} > {1}'.format(Path(cmd[-1][-1]).parent.joinpath('*_${SLURM_ARRAY_TASK_ID}'), sumfile))
        bashcont.append(createbash.format(imaster, current_case_file.relative_to(wwd),
                                          sumfile, current_sse, datfile))
        bashcont.append('fi')
    with unimaster.parent.joinpath('submit.sh').relative_to(wwd).open('w') as fd:
        fd.write(TButil.slurm_header())
        fd.write(TButil.slurm_pyenv())
        fd.write('\n'.join(bashcont))

    TButil.submit_slurm(unimaster.parent.joinpath('submit.sh').relative_to(wwd))
    TButil.plugin_filemaker('Creating geometric coordinate file {}'.format(unidata))
    allCSV = [str(x) for x in unimaster.parent.relative_to(wwd).glob('_*.geo.csv')]
    pd.concat([pd.read_csv(x) for x in allCSV]).to_csv(unidata.relative_to(wwd), index=False)
    TButil.plugin_filemaker('Creating MASTER search file {}'.format(unimaster))
    with unimaster.relative_to(wwd).open('w') as fd:
        for x in unimaster.parent.glob('_*.master'):
            with x.relative_to(wwd).open() as fi:
                fd.write(''.join(fi.readlines()))
    os.chdir(str(cwd))
示例#5
0
def cli_absolute_case():
    """Transform a relative :class:`.Case` to absolute.
    """
    # Parse Arguments
    parser = argparse.ArgumentParser(
        description=cli_case_template.__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('-case',
                        dest='case',
                        action='store',
                        help='Relative case file.',
                        required=True)
    parser.add_argument('-corrections',
                        dest='corrections',
                        action='store',
                        nargs='+',
                        help='Correction file for the case.',
                        default=None)
    parser.add_argument('-caseout',
                        dest='caseout',
                        action='store',
                        help='Output filename (optional).',
                        default=None)
    options = parser.parse_args()

    # Process naming system
    prefix = options.case.split('.')
    format = 'yaml' if prefix[-1] == 'yml' else 'json'
    if options.caseout is None:
        prefix[-1] = 'absolute'
        options.caseout = '.'.join(prefix)

    # Read, transform and write
    case = plugin_source.load_plugin('corrector').apply([
        Case(Path(options.case)),
    ], -1, options.corrections)[0]
    case = case.cast_absolute()
    outfile = case.write(options.caseout, format)
    TButil.plugin_filemaker('New case file created at: {}'.format(
        outfile.resolve()))
示例#6
0
def cli_case_template():
    """Generate a :class:`.Case`.
    """
    # Parse Arguments
    parser = argparse.ArgumentParser(
        description=cli_case_template.__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('-name',
                        dest='name',
                        action='store',
                        help='Job Name.',
                        required=True)

    group = parser.add_mutually_exclusive_group()
    group.add_argument('-architecture',
                       dest='architecture',
                       action='store',
                       help='Architecture string definition.',
                       default=None)
    group.add_argument('-topology',
                       dest='topology',
                       action='store',
                       help='Topology string definition.',
                       default=None)

    parser.add_argument('-format',
                        dest='format',
                        action='store',
                        choices=['json', 'yaml'],
                        help='Format for the case file.',
                        default='yaml')

    options = parser.parse_args()

    _, outfile = case_template(**vars(options))
    TButil.plugin_filemaker('New case file created at: {}'.format(
        os.path.abspath(outfile)))
示例#7
0
def execute(data: Dict, wpaths: Dict) -> Dict:
    """Run Rosetta.
    """
    if TBcore.get_option('slurm', 'use'):
        slurm_file = wpaths['main'].joinpath('submit_funfoldes.sh')
        TButil.plugin_filemaker('Submission file at {}'.format(slurm_file))
        with slurm_file.open('w') as fd:
            fd.write(TButil.slurm_header() + '\n')
            for k in ['folding', 'design']:
                cmd = [
                    'srun',
                ]
                cmd.extend(data['cmd'][k])
                fd.write(' '.join([str(x) for x in cmd]) + '\n')

        if TBcore.get_option('system', 'verbose'):
            sys.stdout.write(
                'Submiting jobs to SLURM... this might take a while\n')
        TButil.submit_slurm(slurm_file)
    else:
        for k in ['folding', 'design']:
            TButil.plugin_bash(data['cmd'][k])
            run([str(x) for x in data['cmd'][k]], stdout=DEVNULL)
    return data
示例#8
0
            kase.data['metadata']['corrections'].append(reload['corrections'])
            corrections.update(reload['corrections'])
            done_l.update(reload['layers'])
            # CKase = CKase.apply_corrections(corrections)
            continue

        # Apply corrections from previous steps and rebuild
        CKase = Case(kase).apply_corrections(corrections)
        with TBcore.on_option_value('system', 'overwrite', True):
            CKase = plugin_source.load_plugin('builder').case_apply(CKase, connectivity=True)

        # Generate structure query and get layer displacements
        layers = set(itemgetter(*step)(ascii_uppercase))
        sses = [sse for sse in CKase.ordered_structures if sse['id'][0] in layers]
        structure, cends = TButil.build_pdb_object(sses, 3)
        TButil.plugin_filemaker('Writing structure {0}'.format(query))
        structure.write(output_file=str(query), format='pdb', clean=True, force=True)

        flip = cycle([CKase['configuration.flip_first'], not CKase['configuration.flip_first']])
        counts = np.asarray([sse['length'] for sse in CKase.ordered_structures])
        cends = np.cumsum(counts)
        cstrs = cends - counts + 1

        rules = list(zip([sse['id'] for sse in CKase.ordered_structures],
                         list(zip(cstrs, cends)),
                         list(next(flip) for _ in range(len(CKase.ordered_structures)))))
        extras = TButil.pdb_geometry_from_rules(query, rules)

        # MASTER search
        createpds = TButil.createPDS(query)
        TButil.plugin_bash(createpds)