Example #1
0
def test_mpi():
    comm = MPI.COMM_WORLD

    rank = comm.rank

    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    data = pt.pmap_mpi(pt.radgyr, traj, '*')

    frame_indices = range(10, 50)
    data_frame_indices = pt.pmap_mpi(pt.radgyr,
                                     traj,
                                     '*',
                                     frame_indices=frame_indices)
    data_frame_indices_cpp_style = pt.pmap_mpi([
        'radgyr nomax',
    ],
                                               traj,
                                               frame_indices=frame_indices)

    if rank == 0:
        saved_data = pt.radgyr(traj, '*')
        saved_data_frame_indices = pt.radgyr(traj,
                                             '*',
                                             frame_indices=frame_indices)
        aa_eq(data['RoG_00000'], saved_data)
        aa_eq(data_frame_indices['RoG_00000'], saved_data_frame_indices)
        aa_eq(data_frame_indices_cpp_style['RoG_00000'],
              saved_data_frame_indices)
Example #2
0
def main(argv):
    args = sys.argv
    scorefile = 'AmberScores.sc'

    decoy_list = glob( "{base}/5.AmberMinimize/min*.rst7".format( base=BASE_DIR ) )

    decoy_list = []
    for d in decoy_list_long:
        decoy_list.append(d.strip())
    print("Decoy List: " + str(len(decoy_list)))
    parmfile = "{base}/5.AmberMinimize/decoy.parm7".format( base=BASE_DIR )
    
    print("Making Traj.")
    traj = pt.iterload( decoy_list, parmfile )
    print("Getting energies...")
    energy_data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=8)
    print("done!")
    if energy_data:
        ekeys = energy_data.keys()
        ekeys.sort()

        print('Scorefile: ' + scorefile)
        with open(scorefile,'w') as myscorefile:

            header = 'description\t'
            for key in ekeys:
                header += key + '\t'
            myscorefile.write(header +"\n")

            for decoy in range(len(decoy_list)):
                scoreline = decoy_list[decoy]+'\t'
                for key in ekeys:
                    scoreline += "%s\t" % str(energy_data[key][decoy])
                myscorefile.write(scoreline+"\n")
Example #3
0
def test_mpi_cpptraj_style():
    comm = MPI.COMM_WORLD
    # end. you are free to update anything below here

    # split remd.x.000 to N cores and do calc_surf in parallel
    root_dir = "data/"
    traj_name = root_dir + "tz2.ortho.nc"
    parm_name = root_dir + "tz2.ortho.parm7"

    # load to TrajectoryIterator
    traj = pt.iterload(traj_name, parm_name)

    # save `total_arr` to rank=0
    # others: total_arr = None
    total_arr = pt.pmap_mpi(
        ['autoimage', 'center :2', 'distance :3 :7', 'angle :3 :7 :8'], traj)

    if comm.rank != 0:
        assert total_arr is None

    if comm.rank == 0:
        # assert to serial
        from pytraj.utils.tools import dict_to_ndarray
        arr = dict_to_ndarray(total_arr)

        t0 = pt.center(traj[:].autoimage(), ':2')
        aa_eq(pt.distance(t0, ':3 :7'), arr[0])
        aa_eq(pt.angle(t0, ':3 :7 :8'), arr[1])
Example #4
0
def test_mpi_hbond():
    rank = MPI.COMM_WORLD.rank

    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    hbond_data_serial = pt.search_hbonds(traj, dtype='dict')
    hbond_data_pmap_mpi = pt.pmap_mpi(pt.search_hbonds, traj)

    if rank == 0:
        assert sorted(hbond_data_serial.keys()) == sorted(
            hbond_data_pmap_mpi.keys())
        for key in hbond_data_serial.keys():
            aa_eq(hbond_data_serial[key], hbond_data_pmap_mpi[key])
Example #5
0
def test_mpi_use_reference():

    comm = MPI.COMM_WORLD

    rank = comm.rank

    traj = pt.iterload(fn('tz2.nc'), fn('tz2.parm7'))
    data_ref3 = pt.pmap_mpi(pt.rmsd, traj, '@CA', ref=3)
    # data_ref0 = pt.pmap_mpi(pt.rmsd, traj, '@CA')

    if rank == 0:
        # saved_data_ref0 = pt.rmsd(traj, '@CA')
        saved_data_ref3 = pt.rmsd(traj, '@CA', ref=3)

        # aa_eq(data_ref0['RMSD_00001'], saved_data_ref0)
        aa_eq(data_ref3['RMSD_00001'], saved_data_ref3)
Example #6
0
#!/usr/bin/env python

import pytraj as pt
from pytraj.testing import aa_eq
from mpi4py import MPI

comm = MPI.COMM_WORLD

rank = comm.rank

traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")
data_ref3 = pt.pmap_mpi(pt.rmsd, traj, '@CA', ref=3)
# data_ref0 = pt.pmap_mpi(pt.rmsd, traj, '@CA')

if rank == 0:
    # saved_data_ref0 = pt.rmsd(traj, '@CA')
    saved_data_ref3 = pt.rmsd(traj, '@CA', ref=3)

    # aa_eq(data_ref0['RMSD_00001'], saved_data_ref0)
    aa_eq(data_ref3['RMSD_00001'], saved_data_ref3)
Example #7
0
def get_energy_term( traj, term ):

    energy_data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=8)
    return energy_data[term];
Example #8
0
def get_energies( traj, igb_value ):

    #energy_data = pt.energy_decomposition(traj, igb=8)
    energy_data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=igb_value )
    return energy_data;
Example #9
0
# load pytraj and mpi4py
import pytraj as pt
from mpi4py import MPI

# create mpi handler to get cpu rank
comm = MPI.COMM_WORLD 

# load trajectory
# create filenames (could be a single filename or a list of filenames that cpptraj supported)
# (restart file, pdb, netcdf, mdcrd, dcd, ...)
# check more: http://amber-md.github.io/pytraj/latest/trajectory_exercise.html 

filenames = ['fn1.pdb', 'fn2.pdb',]
topology_name = 'fn1.parm7'

traj = pt.iterload(filenames, top=topology_name)

# perform parallel calculation
data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=8)

# data is a Python dict, it's up to you to save the data
# you can use pt.to_pickle to save the dict to disk and then use pt.read_pickle to reload the dict

# use rank == 0 since pytraj sends output to first cpu.
if comm.rank == 0:
    #print(data)
    pt.to_pickle(data, 'my_data.pk')

# reload for another analysis
# data = pt.read_pickle('my_data.pk')
Example #10
0
# import MPI to get rank
from mpi4py import MPI
import pytraj as pt
from pytraj.testing import aa_eq

try:
    import sander
    comm = MPI.COMM_WORLD
    # end. you are free to update anything below here

    # split remd.x.000 to N cores and do calc_surf in parallel
    root_dir = "../../tests/data/"
    traj_name = root_dir + "tz2.nc"
    parm_name = root_dir + "tz2.parm7"

    # load to TrajectoryIterator
    traj = pt.iterload(traj_name, parm_name)
    inp = sander.gas_input(8)

    # gather the data
    # if rank != 0: data is None
    data = pt.pmap_mpi(pt.energy_decomposition, traj, mm_options=inp)

    if comm.rank == 0:
        # make sure to reproduce serial output
        serial_data = pt.energy_decomposition(traj, mm_options=inp)
        aa_eq(pt.tools.dict_to_ndarray(data), pt.tools.dict_to_ndarray(serial_data))
except ImportError:
    print('does not have sander. skip this example')
Example #11
0
# always add those lines to your code
import numpy as np
from mpi4py import MPI
import pytraj as pt
from pytraj.testing import aa_eq

comm = MPI.COMM_WORLD
# end. you are free to update anything below here

# split remd.x.000 to N cores and do calc_surf in parallel
root_dir = "../../tests/data/"
traj_name = root_dir + "tz2.ortho.nc"
parm_name = root_dir + "tz2.ortho.parm7"

# load to TrajectoryIterator
traj = pt.iterload(traj_name, parm_name)
# print(traj)

# mapping different chunk of `traj` in N cores
# need to provide `comm`
# save `total_arr` to rank=0
# others: total_arr = None
out_parallel = pt.pmap_mpi(pt.calc_molsurf, traj, "!:WAT", top=traj.top)

if comm.rank != 0:
    assert out_parallel is None

if comm.rank == 0:
    out_serial = pt.calc_molsurf(traj, "!:WAT", dtype='ndarray')
    aa_eq(out_serial, out_parallel['MSURF_00000'])
Example #12
0
#!/usr/bin/env python

import pytraj as pt
from pytraj.testing import aa_eq
from mpi4py import MPI

comm = MPI.COMM_WORLD

rank = comm.rank

traj = pt.iterload("./data/tz2.nc", "./data/tz2.parm7")
data = pt.pmap_mpi(pt.radgyr, traj, '*')

frame_indices = range(10, 50)
data_frame_indices = pt.pmap_mpi(pt.radgyr,
                                 traj,
                                 '*',
                                 frame_indices=frame_indices)
data_frame_indices_cpp_style = pt.pmap_mpi(
    ['radgyr nomax', ],
    traj,
    frame_indices=frame_indices)

if rank == 0:
    saved_data = pt.radgyr(traj, '*')
    saved_data_frame_indices = pt.radgyr(traj,
                                         '*',
                                         frame_indices=frame_indices)
    aa_eq(data['RoG_00000'], saved_data)
    aa_eq(data_frame_indices['RoG_00000'], saved_data_frame_indices)
    aa_eq(data_frame_indices_cpp_style['RoG_00000'], saved_data_frame_indices)
Example #13
0
import pytraj as pt
from pytraj.testing import aa_eq

comm = MPI.COMM_WORLD
# end. you are free to update anything below here

# split remd.x.000 to N cores and do calc_surf in parallel
root_dir = "data/"
traj_name = root_dir + "tz2.ortho.nc"
parm_name = root_dir + "tz2.ortho.parm7"

# load to TrajectoryIterator
traj = pt.iterload(traj_name, parm_name)

# save `total_arr` to rank=0
# others: total_arr = None
total_arr = pt.pmap_mpi(
    ['autoimage', 'center :2', 'distance :3 :7', 'angle :3 :7 :8'], traj)

if comm.rank != 0:
    assert total_arr is None

if comm.rank == 0:
    # assert to serial
    from pytraj.tools import dict_to_ndarray
    arr = dict_to_ndarray(total_arr)

    t0 = pt.center(traj[:].autoimage(), ':2')
    aa_eq(pt.distance(t0, ':3 :7'), arr[0])
    aa_eq(pt.angle(t0, ':3 :7 :8'), arr[1])
Example #14
0
# import MPI to get rank
from mpi4py import MPI
import pytraj as pt
from pytraj.testing import aa_eq

try:
    import sander
    comm = MPI.COMM_WORLD
    # end. you are free to update anything below here

    # split remd.x.000 to N cores and do calc_surf in parallel
    root_dir = "../../tests/data/"
    traj_name = root_dir + "tz2.nc"
    parm_name = root_dir + "tz2.parm7"

    # load to TrajectoryIterator
    traj = pt.iterload(traj_name, parm_name)
    inp = sander.gas_input(8)

    # gather the data
    # if rank != 0: data is None
    data = pt.pmap_mpi(pt.energy_decomposition, traj, mm_options=inp)

    if comm.rank == 0:
        # make sure to reproduce serial output
        serial_data = pt.energy_decomposition(traj, mm_options=inp)
        aa_eq(pt.tools.dict_to_ndarray(data),
              pt.tools.dict_to_ndarray(serial_data))
except ImportError:
    print('does not have sander. skip this example')
Example #15
0
# create filenames (could be a single filename or a list of filenames that cpptraj supported)
# (restart file, pdb, netcdf, mdcrd, dcd, ...)
# check more: http://amber-md.github.io/pytraj/latest/trajectory_exercise.html 

# get all minimized rst7 files
filenames = glob('min*rst7')
topology_name = '../1fna.parm7'

# load native struture
nat = pt.iterload('../../../Natives/1fna_0001.clean.pdb')

# create trajectory. Note: use iterload to save memory
traj = pt.iterload(filenames, top=topology_name)

# perform parallel calculation with igb=8: energy
data = pt.pmap_mpi(pt.energy_decomposition, traj, igb=8)

# perform parallel calculation: rmsd, use @CA mask
data_rmsd = pt.pmap_mpi(pt.rmsd, traj, ref=nat, mask='@CA')

# data is a Python dict, it's up to you to save the data
# you can use pt.to_pickle to save the dict to disk and then use pt.read_pickle to reload the dict

# use rank == 0 since pytraj sends output to first cpu.
if comm.rank == 0:
    #print(data)
    # add rmsd to data dict
    data.update(data_rmsd)
    pt.to_pickle(data, 'my_data.pk')

# reload for another analysis