コード例 #1
0
def _format_convert(input_filename, output_filename):
    """

    Examples
    --------
    import pytraj as pt
    pt.io._format_convert('test.cpp4', 'test.dx')
    """
    from pytraj.core.c_core import CpptrajState, Command

    state = CpptrajState()

    with Command() as command:
        command.dispatch(state,
                         'readdata {} name mydata'.format(input_filename))
        command.dispatch(state, 'writedata {} mydata '.format(output_filename))
コード例 #2
0
ファイル: __init__.py プロジェクト: shozebhaider/pytraj
def convert(input_filename, to):
    """convert datafile format (e.g .ccp4 to .dx, .dat to .xmgrace)

    Examples
    --------
    >>> import pytraj as pt
    >>> pt.datafiles.convert('test.cpp4', 'test.dx') # doctest: +SKIP
    """
    from pytraj.core.c_core import CpptrajState, Command

    state = CpptrajState()

    with Command() as command:
        command.dispatch(state,
                         'readdata {} name mydata'.format(input_filename))
        command.dispatch(state, 'writedata {} mydata '.format(to))
コード例 #3
0
def iterload_remd(filename, top=None, T="300.0"):
    """Load temperature remd trajectory for single temperature.
    e.g: Suppose you have replica trajectoris remd.x.00{1-4}.
    You want to load and extract only frames at 300 K, use this method

    Parameters
    ----------
    filename : str
    top : {str, Topology}
    T : {float, str}, default=300.0

    Returns
    -------
    pytraj.traj.TrajectoryCpptraj

    Notes
    -----

    """
    from pytraj.core.c_core import CpptrajState, Command

    state = CpptrajState()

    # add keyword 'remdtraj' to trick cpptraj
    trajin = ' '.join(('trajin', filename, 'remdtraj remdtrajtemp', str(T)))
    if isinstance(top, string_types):
        top = load_topology(top)
    else:
        top = top
    state.data.add('topology', 'remdtop')
    # set topology
    state.data['remdtop']._top = top

    # load trajin
    with Command() as cm:
        cm.dispatch(state, trajin)
        cm.dispatch(state, 'loadtraj name remdtraj')

    # state.data.remove_set(state.data['remdtop'])
    traj = state.data[-1]

    # assign state to traj to avoid memory free
    traj._base = state
    return traj
コード例 #4
0
def write_data(filename, data):
    """same as writedata in cpptraj. (this is work in progress, only support 1D-array for now)

    Parameters
    ----------
    filename : str
        output filename. File format is deteced by its name.
    data : ndarray
    dtype : str, {'double', 'float', 'grid_float', 'grid_double'}, default 'double'

    Examples
    --------
    >>> # xmgrace format
    >>> import pytraj as pt
    >>> traj = pt.datafiles.load_tz2()
    >>> rmsd_data = pt.rmsd(traj, ref=0)
    >>> pt.io.write_data('my.agr', rmsd_data)

    >>> # gnu format
    >>> pt.io.write_data('my.gnu', rmsd_data)
    """
    data = np.asarray(data, dtype='f8')

    dtype_map = {1: 'double', 3: 'grid_float'}

    from pytraj.core.c_core import CpptrajState, Command

    dtype = dtype_map[data.ndim]

    if data.ndim == 3:
        data = data.astype('f4')

    state = CpptrajState()
    dataset_name = 'my_data'
    d0 = state.data.add(dtype=dtype, name=dataset_name)
    d0.data = np.asarray(data)

    cm = 'writedata {filename} {dataset_name}'.format(
        filename=filename, dataset_name=dataset_name)

    with Command() as command:
        command.dispatch(state, cm)