示例#1
0
def test_param():
    """Test param plot."""
    p = Path('param.pdf')
    lplt.param(
        list(range(10)),
        list(range(10)),
        filename='param.pdf',
    )
    assert p.exists()
    p.unlink()
示例#2
0
def test_label_dots():
    """Test label_dots plot."""
    p = Path('label_dots.pdf')
    lplt.param(
        ['a', 'b', 'c'],
        list(range(3)),
        filename='label_dots.pdf',
    )
    assert p.exists()
    p.unlink()
示例#3
0
def main(topology,
         trajectories,
         plane_selection,
         aunit='degrees',
         ref_frame=0,
         start=None,
         stop=None,
         step=None,
         export=False,
         plot=False,
         plotvars=None,
         **kwargs):
    """Execute main client logic."""
    log.info(T('calculating angles'))

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

    u = libmda.load_universe(topology, *trajectories)

    frame_slice = libio.frame_slice(
        start=start,
        stop=stop,
        step=step,
    )
    log.info(S('for slice {}', frame_slice))

    log.info(T('calculating plane eq. for reference frame'))
    log.info(S('using frame: {}', ref_frame))
    u.trajectory[ref_frame]
    reference_point_1 = u.select_atoms(plane_selection[0]).center_of_geometry()
    reference_point_2 = u.select_atoms(plane_selection[1]).center_of_geometry()
    reference_point_3 = u.select_atoms(plane_selection[2]).center_of_geometry()

    ra, rb, rc, rd = libcalc.calc_plane_eq(
        reference_point_1,
        reference_point_2,
        reference_point_3,
    )
    log.info(S('the equation is {}x + {}y + {}z = {}', ra, rb, rc, rd))

    log.info(T('Calculating angles'))
    angles = []
    for _ts in u.trajectory[frame_slice]:

        point1 = u.select_atoms(plane_selection[0]).center_of_geometry()
        point2 = u.select_atoms(plane_selection[1]).center_of_geometry()
        point3 = u.select_atoms(plane_selection[2]).center_of_geometry()

        a, b, c, d = libcalc.calc_plane_eq(point1, point2, point3)

        angles.append(
            libcalc.calc_planes_angle(
                ra,
                rb,
                rc,
                a,
                b,
                c,
                aunit=aunit,
            ))

    log.info(S('calculated a total of {} angles.', len(angles)))

    if export:
        libio.export_data_to_file(
            list(range(len(u.trajectory))[frame_slice]),
            angles,
            fname=export,
            header=('# Angular oscillation between a plane representatives\n'
                    '# topology: {}\n'
                    '# trajectories: {}\n'
                    '# selections: {}\n'
                    '# frame,angle({})\n').format(
                        topology,
                        ', '.join(t.resolve().str() for t in trajectories),
                        plane_selection,
                        aunit,
                    ),
        )

    if plot:
        plotvars = plotvars or dict()
        plotvars.setdefault(
            'labels',
            'plane: {}'.format(' and '.join(plane_selection)),
        )

        log.info(T('plot params:'))
        for k, v in plotvars.items():
            log.info(S('{} = {!r}', k, v))

        libplot.param(
            list(range(len(u.trajectory))[frame_slice]),
            angles,
            **plotvars,
        )

    log.info(S('done'))
    return
示例#4
0
def main(
        topology,
        trajectories,
        insort=False,
        start=None,
        stop=None,
        step=None,
        ref_frame=0,
        selections=None,
        export=False,
        plot=False,
        plotvars=None,
        **kwargs
        ):
    """Execute main client logic."""
    log.info(T('starting'))

    u = libmda.load_universe(topology, *trajectories, insort=insort)

    frame_slice = libio.frame_slice(
        start=start,
        stop=stop,
        step=step,
        )

    if selections is None:
        selections = ['all']

    rmsds = []
    for selection in selections:
        rmsds.append(
            libcalc.mda_rmsd(
                u,
                frame_slice=frame_slice,
                selection=selection,
                ref_frame=ref_frame,
                )
            )
    if export:
        libio.export_data_to_file(
            list(range(len(u.trajectory))[frame_slice]),
            *rmsds,
            fname=export,
            delimiter=',',
            header=(
                "# Date: {}\n'"
                "# Topology: {}\n"
                "# Trajectories : {}\n"
                "# ref frame: {}\n"
                "# frame number,{}\n"
                ).format(
                    datetime.now(),
                    Path(topology).resolve(),
                    ', '.join(f.resolve().str() for f in trajectories),
                    ref_frame,
                    ','.join(selections),
                    ),
            )

    if plot:
        plotvars = plotvars or dict()
        plotvars.setdefault('labels', selections)

        log.info(T('plot params:'))
        for k, v in plotvars.items():
            log.info(S('{} = {!r}', k, v))

        libplot.param(
            list(range(len(u.trajectory))[frame_slice]),
            rmsds,
            **plotvars,
            )

    return
示例#5
0
def main(topology,
         trajectories,
         insort=False,
         sel1='all',
         sel2='all',
         start=None,
         stop=None,
         step=None,
         export=False,
         plot=False,
         plotvars=None,
         **kwargs):
    """Execute main client logic."""
    log.info(T('measuring distances'))

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

    u = libmda.load_universe(topology, *trajectories, insort=insort)

    frame_slice = libio.frame_slice(
        start=start,
        stop=stop,
        step=step,
    )

    log.info(T('defining atom seletions'))
    log.info(S('atom selection #1: {}', sel1))
    log.info(S('atom selection #2: {}', sel2))
    atom_sel1 = u.select_atoms(sel1)
    atom_sel2 = u.select_atoms(sel2)

    distances = np.ones(len(u.trajectory[frame_slice]), dtype=np.float32)

    log.info(T('Calculating distances'))
    # https://www.mdanalysis.org/MDAnalysisTutorial/atomgroups.html
    # https://www.mdanalysis.org/docs/documentation_pages/core/groups.html#MDAnalysis.core.groups.AtomGroup.center_of_geometry

    with libcli.ProgressBar(distances.size, suffix='frames') as pb:
        for i, _ts in enumerate(u.trajectory[frame_slice]):

            distances[i] = np.linalg.norm(
                np.subtract(
                    atom_sel1.center_of_geometry(),
                    atom_sel2.center_of_geometry(),
                ))
            pb.increment()

    log.info(S('calculated a total of {} distances.', len(distances)))

    if export:
        libio.export_data_to_file(
            list(range(len(u.trajectory))[frame_slice]),
            distances,
            fname=export,
            header=('# Distances between two selections centers of geomemtry\n'
                    '# topology: {}\n'
                    '# trajectories: {}\n'
                    '# selection #1: {}\n'
                    '# selection #2: {}\n'
                    '# frame,distance\n').format(
                        topology,
                        ', '.join(t.resolve().str() for t in trajectories),
                        sel1,
                        sel2,
                    ),
        )

    if plot:
        plotvars = plotvars or dict()
        plotvars.setdefault('labels', '{} dist {}'.format(sel1, sel2))

        log.info(T('plot params:'))
        for k, v in plotvars.items():
            log.info(S('{} = {!r}', k, v))

        libplot.param(
            list(range(len(u.trajectory))[frame_slice]),
            distances,
            **plotvars,
        )

    log.info(S('done'))
    return