コード例 #1
0
def info_plugins() -> pd.DataFrame:
    """
    """
    data = {
        'name': [],
        'description': [],
        'argument': [],
        'argument_type': [],
        'source': []
    }
    basedir = Path(topobuilder.__file__).parent
    for plugin in plugin_source.list_plugins():
        afunc = plugin_source.load_plugin(plugin).apply
        thisdir = Path(plugin_source.load_plugin(plugin).__file__).parent
        annot = inspect.getfullargspec(afunc)[-1]
        for a in annot:
            if a == 'return':
                continue
            data['name'].append(plugin)
            data['description'].append(afunc.__doc__.split('\n')[0])
            data['argument'].append(a)
            if thisdir == Path().home().joinpath('.topobuilder'):
                data['source'].append('HOMEPLUGIN')
            try:
                if thisdir.relative_to(basedir):
                    data['source'].append('BASEPLUGIN')
            except ValueError:
                data['source'].append('ENVPLUGIN')
            at = str(annot[a]).replace('<class \'', '').replace('\'>', '')
            at = re.sub(r'[a-zA-Z\.]*\.', '', at)
            data['argument_type'].append(at)
    return pd.DataFrame(data).set_index(
        ['source', 'name', 'description', 'argument']).sort_index(level=[0, 1])
コード例 #2
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()))
コード例 #3
0
ファイル: main.py プロジェクト: ZeroDesigner/topobuilder
        query = stepfolder.joinpath('imaster.query{:02d}.pdb'.format(i + 1))
        checkpoint = stepfolder.joinpath('checkpoint.json')

        reload = TButil.checkpoint_in(checkpoint)
        if reload is not None:
            kase.data['metadata']['imaster'].setdefault('step{:02d}'.format(i + 1), reload)
            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)),
コード例 #4
0

def case_apply(case: Case, pds_list: Path, loop_range: int, top_loops: int,
               rmsd_cut: float, abego: pd.DataFrame, harpins_2: bool,
               fragfiles: pd.DataFrame) -> str:
    """
    """
    # Loop MASTER is only applied to a Case with one single connectivity and already reoriented
    if case.connectivity_count > 1:
        raise ValueError(
            'Loop MASTER can only be applied to one connectivity.')

    # We will need the coordinates of the secondary structures to execute this one
    # This will already cast it to absolute
    with TBcore.on_option_value('system', 'overwrite', False):
        case = plugin_source.load_plugin('builder').case_apply(
            case, connectivity=True)

    # Generate the folder tree for a single connectivity.
    folders = case.connectivities_paths[0].joinpath('loop_master')
    folders.mkdir(parents=True, exist_ok=True)

    # Find steps: Each pair of secondary structure.
    it = case.connectivities_str[0].split('.')
    steps = [it[i:i + 2] for i in range(0, len(it) - 1)]
    loop_step = case.cast_absolute(
    )['configuration.defaults.distance.loop_step']
    lengths = case.connectivity_len[0]
    start = 1

    for i, sse in enumerate(steps):
コード例 #5
0
    if protocols is None and protocol is None:
        raise AttributeError('There are no protocols to run')
    if protocol is not None and protocols is not None:
        raise AttributeError('Protocols are provided both through file and in the Case. '
                             'Pick one.')
    if protocol is not None:
        protocol = str(Path(protocol).resolve())
        try:
            protocols = json.loads("".join([x.strip() for x in open(protocol).readlines()]))
            case_format = 'json'
        except json.JSONDecodeError:
            protocols = yaml.load(open(protocol))
            case_format = 'yaml'

    # Check requested plugins (avoid time is something is wrong)
    for i, ptcl in enumerate(protocols):
        if 'name' not in ptcl:
            raise ValueError('All protocols require a "name" field')
        if ptcl['name'] not in plugin_source.list_plugins():
            raise ValueError('Requested protocol {} cannot be found.'.format(ptcl['name']))
        protocols[i].setdefault('status', False)

    cases = [c.assign_protocols(protocols), ]
    for i, ptcl in enumerate(protocols):
        if not ptcl['status']:
            cases = plugin_source.load_plugin(ptcl['name']).apply(cases, prtid=i, **ptcl)

    for c in cases:
        c.write(format=case_format)
    return cases