Ejemplo n.º 1
0
def main(topology,
         trajectories,
         insort=False,
         selection=None,
         maintain=None,
         top_output='_frame0.pdb',
         traj_output='nosol.dcd',
         **kwargs):
    """Execute main client logic."""
    log.info(T('Removing solvent'))

    trj = libmdt.load_traj(topology, trajectories, insort=insort)

    if selection:
        log.info(S('selecting {}', selection))
        atom_sel = trj.top.select(selection)
        trj.atom_slice(atom_sel, inplace=True)

    trj.remove_solvent(inplace=True, exclude=maintain)

    if top_output:
        fout = libio.parse_top_output(top_output, traj_output)
        trj[0].save(fout.str())
        log.info(S('first frame topology saved: {}', fout))

    log.info(T('saving trajectory'))
    log.info(S('destination: {}', traj_output))
    trj.save(traj_output)
    log.info(S('saved'))
Ejemplo n.º 2
0
def main(
        topology,
        trajectories,
        insort=False,
        traj_output='imaged.dcd',
        top_output=False,
        protocol=1,
        **kwargs
        ):
    """Execute main client logic."""
    log.info(T('Attempting image molecules'))

    log.info(T('loading input'))
    traj = libmdt.load_traj(topology, trajectories, insort=insort)

    protocols = {
        1: libmdt.imagemol_protocol1,
        2: libmdt.imagemol_protocol2,
        }

    reimaged = protocols[protocol](traj)

    log.info(T('saving the output'))
    reimaged.save(traj_output)
    log.info(S('saved trajectory: {}', traj_output))

    if top_output:
        fout = libio.parse_top_output(top_output, traj_output)
        reimaged[0].save(fout.str())
        log.info(S('saved frame 0 to: {}', fout.resolve()))

    return
Ejemplo n.º 3
0
def main(
    topology,
    trajectories,
    insort=None,
    start=None,
    stop=None,
    step=None,
    selection='all',
    traj_output='traj_out.dcd',
    top_output=None,
    unwrap=False,
    unwrap_reference=None,
    unwrap_compound='fragments',
    align=False,
    **kwargs,
):
    """Execute main client logic."""
    log.info(T('editing trajectory'))

    topology = Path(topology)
    trajectories = [Path(t) for t in trajectories]

    if insort:
        trajectories = libio.sort_numbered_input(*trajectories)

    u = libmda.load_universe(topology, *trajectories)

    if unwrap:
        log.info(T('unwrapping'))
        log.info(S('set to: {}', unwrap))
        log.info(S('reference: {}', unwrap_reference))
        log.info(S('compound: {}', unwrap_compound))

    if align:
        log.info(T('Alignment'))
        log.info(S('trajectory selection will be aligned to subselection:'))
        log.info(S('- {}', align, indent=2))
        align_reference = mda.Universe(Path(topology).str())

    log.info(T('transformation'))
    sliceObj = libio.frame_slice(start, stop, step)

    log.info(S('selecting: {}', selection))
    atom_selection = u.select_atoms(selection)
    log.info(S('with {} atoms', atom_selection.n_atoms, indent=2))

    log.info(T('saving trajectory'))
    traj_output = Path(traj_output)
    log.info(S('destination: {}', traj_output.resolve().str()))

    with mda.Writer(traj_output.str(), atom_selection.n_atoms) as W:
        for i, _ts in zip(
                range(len(u.trajectory))[sliceObj],
                u.trajectory[sliceObj],
        ):

            log.info(S('working on frame: {}', i))

            if unwrap:
                log.debug(S('unwrapping', indent=2))
                atom_selection.unwrap(
                    reference=unwrap_reference,
                    compound=unwrap_compound,
                )

            if align:
                try:
                    libmda.mdaalignto(u, align_reference, selection=align)
                except ZeroDivisionError:
                    _controlled_exit()

            W.write(atom_selection)

    log.info(S('trajectory saved'))

    if top_output:
        log.info(T('saving topology'))
        fout = libio.parse_top_output(top_output, traj_output)
        log.info(S('saving frame 0 to: {}', fout.resolve()))
        with mda.Writer(fout.str(), atom_selection.n_atoms) as W:
            for _ts in u.trajectory[sliceObj][0:1]:
                if unwrap:
                    log.debug(S('unwrapping for topology', indent=2))
                    atom_selection.unwrap(
                        reference=unwrap_reference,
                        compound=unwrap_compound,
                    )
                W.write(atom_selection)

    log.info(S('Done'))
    return
Ejemplo n.º 4
0
def test_parse_top_output(top, traj, expected):
    """Test parse topology output."""
    result = io.parse_top_output(top, traj_output=traj)
    assert isinstance(result, Path)
    assert result.name == expected