Ejemplo n.º 1
0
def create_test_trj(uni, filename):
    """uses pyh5md library to write h5md file"""

    with pyh5md.File(filename, 'w', creator='create_h5md_data.py') as f:
        trajectory = f.particles_group('trajectory')
        obsv = f.require_group('observables')

        positions = pyh5md.element(trajectory, 'position', store='time',
                                   data=uni.trajectory.ts.positions,
                                   time=True)
        f['particles/trajectory/position/value'].attrs['unit'] = 'Angstrom'
        f['particles/trajectory/position/time'].attrs['unit'] = 'ps'

        velocities = pyh5md.element(trajectory, 'velocity',
                                    data=uni.trajectory.ts.velocities,
                                    step_from=positions,
                                    store='time', time=True)
        f['particles/trajectory/velocity/value'].attrs['unit'] = 'Angstrom ps-1'
        f['particles/trajectory/velocity/time'].attrs['unit'] = 'ps'

        forces = pyh5md.element(trajectory, 'force',
                                data=uni.trajectory.ts.forces,
                                step_from=positions,
                                store='time', time=True)
        f['particles/trajectory/force/value'].attrs['unit'] = 'kJ mol-1 Angstrom-1'
        f['particles/trajectory/force/time'].attrs['unit'] = 'ps'

        data_step = pyh5md.element(obsv, 'step',
                                   data=uni.trajectory.ts.data['step'],
                                   step_from=positions,
                                   store='time', time=True)
        data_lambda = pyh5md.element(obsv, 'lambda',
                                     data=uni.trajectory.ts.data['lambda'],
                                     step_from=positions,
                                     store='time', time=True)

        trajectory.create_box(dimension=3,
                              boundary=['periodic', 'periodic', 'periodic'],
                              store='time',
                              data=uni.trajectory.ts.triclinic_dimensions,
                              step_from=positions)
        f['particles/trajectory/box/edges/value'].attrs['unit'] = 'Angstrom'

        for ts in uni.trajectory:
            trajectory.box.edges.append(uni.trajectory.ts.triclinic_dimensions,
                                        ts.frame, time=ts.time)
            positions.append(uni.trajectory.ts.positions,
                             ts.frame, time=ts.time)
            velocities.append(uni.trajectory.ts.velocities,
                              ts.frame, time=ts.time)
            forces.append(uni.trajectory.ts.forces,
                          ts.frame, time=ts.time)
            data_step.append(uni.trajectory.ts.data['step'],
                             ts.frame, time=ts.time)
            data_lambda.append(uni.trajectory.ts.data['lambda'],
                               ts.frame, time=ts.time)
Ejemplo n.º 2
0
def write_configuration(r, species, filename, sigma, treshold, attrs=None):
    kwargs = {'author': 'Pierre de Buyl',
              'creator': os.path.basename(__file__)}
    with pyh5md.File(filename, mode='w', **kwargs) as b:
        cluster = b.particles_group('janus')
        edges = np.ones(3) * 2 * np.ceil(sigma + treshold + 1)
        r += edges.reshape((1, 3))/2
        cluster.create_box(dimension=3, boundary=['periodic']*3,
                           store='fixed', data=edges)
        pos = pyh5md.element(cluster, 'position', store='fixed', data=r)
        pyh5md.element(cluster, 'box/edges', store='fixed', data=edges)
        pyh5md.element(cluster, 'species', store='fixed', data=species)
        if attrs is not None:
            for k, v in attrs.items():
                pos.attrs[k] = v
Ejemplo n.º 3
0
def create_test_trj(uni, filename):
    """uses pyh5md library to write h5md file"""

    with pyh5md.File(filename, 'w', creator='dcd_to_h5md.py') as f:
        trajectory = f.particles_group('trajectory')
        obsv = f.require_group('observables')

        ag = uni.select_atoms(
            "(resid 1:29 or resid 60:121 or resid 160:214) and name CA")
        indices = ag.indices

        positions = pyh5md.element(trajectory,
                                   'position',
                                   store='time',
                                   data=uni.trajectory.ts.positions[indices],
                                   time=True)
        f['particles/trajectory/position/value'].attrs['unit'] = 'Angstrom'
        f['particles/trajectory/position/time'].attrs['unit'] = 'ps'

        data_step = pyh5md.element(obsv,
                                   'step',
                                   data=uni.trajectory.ts.data['step'],
                                   step_from=positions,
                                   store='time',
                                   time=True)
        data_dt = pyh5md.element(obsv,
                                 'dt',
                                 data=uni.trajectory.ts.data['dt'],
                                 step_from=positions,
                                 store='time',
                                 time=True)

        trajectory.create_box(dimension=3,
                              boundary=['periodic', 'periodic', 'periodic'],
                              store='time',
                              data=uni.trajectory.ts.triclinic_dimensions,
                              step_from=positions)
        f['particles/trajectory/box/edges/value'].attrs['unit'] = 'Angstrom'

        for ts in uni.trajectory:
            trajectory.box.edges.append(ts.triclinic_dimensions,
                                        ts.frame,
                                        time=ts.time)
            positions.append(ts.positions[indices], ts.frame, time=ts.time)
            data_step.append(ts.data['step'], ts.frame, time=ts.time)
            data_dt.append(ts.data['dt'], ts.frame, time=ts.time)
Ejemplo n.º 4
0
def test_pyh5md_bench():
    u = mda.Universe(TPR_xvf, H5MD_xvf)
    ca = u.select_atoms("protein and name CA")
    indices = ca.indices
    with pyh5md.File(H5MD_xvf, 'r') as f:
        trajectory = f.particles_group('trajectory')
        for i in range(len(u.trajectory)):
            u.trajectory[i]
            assert_array_equal(
                ca.positions,
                pyh5md.element(trajectory, 'position').value[i, indices, :])
Ejemplo n.º 5
0
def test_fixed_element(tmpdir):
    f = pyh5md.File(str(tmpdir.join('test.h5')), mode='w',
                    author='Pierre de Buyl', creator='pyh5md test_create_file',
                    creator_version='N/A')
    name = 'atoms'
    N = 91
    particles_group = f.particles_group(name)
    mass = pyh5md.element(particles_group, 'mass', store='fixed',
                          data=np.ones(N))
    assert type(mass) is pyh5md.FixedElement
    assert mass.value.shape == (N,)
    f.close()
Ejemplo n.º 6
0
 def observe_quadruple(self, fql, name, particle_group='atoms'):
     if pmi.workerIsActive():
         self.cxxclass.observe_quadruple(self, fql)
         g = pyh5md.element(self.connectivity,
                            name,
                            store='time',
                            maxshape=(None, 4),
                            shape=(self.chunk_size, 4),
                            dtype=self.h5md_file.int_type,
                            fillvalue=-1)
         g.attrs['particle_group'] = particle_group
         self.quadruple_data[self.quadruple_index] = g
         self.quadruple_index += 1
Ejemplo n.º 7
0
def benchmark_pyh5md_rmsd(filename):
    with pyh5md.File(filename, 'r') as f:

        u = mda.Universe("testfiles/cobrotoxin.tpr", filename)
        indices = u.select_atoms("protein and name CA").indices

        trajectory = f.particles_group('trajectory')
        observables = f.require_group('observables')

        pos0 = pyh5md.element(trajectory, 'position').value[0, indices, :]
        x_ref = pos0.copy()
        n_frames = pyh5md.element(trajectory, 'position').value.shape[0]

        total_io = 0
        total_rmsd = 0
        total_loop = -time.time()
        for frame in range(n_frames):

            start_io = time.time()
            positions = pyh5md.element(trajectory, 'position').value[frame, indices]
            velocities = pyh5md.element(trajectory, 'velocity').value[frame, indices]
            forces = pyh5md.element(trajectory, 'force').value[frame, indices]
            box = pyh5md.element(trajectory, 'box/edges').value[frame]
            data_step = pyh5md.element(observables, 'step').value[frame]
            data_lambda = pyh5md.element(observables, 'lambda').value[frame]
            data_time = pyh5md.element(trajectory, 'position').time[frame]
            total_io += time.time() - start_io

            start_rmsd = time.time()
            result = rmsd(positions, x_ref, superposition=True)
            total_rmsd += time.time() - start_rmsd

        total_loop += time.time()

    return {"Loop": total_loop,
            "Loop_per_frame": (total_loop/n_frames),
            "I/O": total_io,
            "I/O_per_frame": (total_io/n_frames),
            "RMSD": total_rmsd,
            "RMSD_per_frame": (total_rmsd/n_frames),
            "Overhead": (total_loop - (total_io + total_rmsd)),
            "Overhead_per_frame": ((total_loop - (total_io + total_rmsd))/n_frames)}
Ejemplo n.º 8
0
 def add_static_quadruple(self, fql, name, particle_group='atoms'):
     if pmi.workerIsActive():
         quadruplets = fql.getQuadruples()
         NMaxLocal = np.array(len(quadruplets), 'i')
         NMaxGlobal = np.array(0, 'i')
         MPI.COMM_WORLD.Allreduce(NMaxLocal, NMaxGlobal, op=MPI.MAX)
         size_per_cpu = (
             (NMaxGlobal // self.chunk_size) + 1) * self.chunk_size
         total_size = MPI.COMM_WORLD.size * size_per_cpu
         g = pyh5md.element(self.connectivity,
                            name,
                            store='fixed',
                            dtype=self.h5md_file.int_type,
                            fillvalue=-1,
                            shape=(total_size, 4))
         g.attrs['particle_group'] = particle_group
         idx_0 = MPI.COMM_WORLD.rank * size_per_cpu
         idx_1 = idx_0 + NMaxLocal
         g[idx_0:idx_1] = quadruplets
Ejemplo n.º 9
0
 def add_static_tuple(self, fpl, name, particle_group='atoms'):
     if pmi.workerIsActive():
         bonds = fpl.getBonds()
         NMaxLocal = np.array(len(bonds), 'i')
         NMaxGlobal = np.array(0, 'i')
         MPI.COMM_WORLD.Allreduce(NMaxLocal, NMaxGlobal, op=MPI.MAX)
         size_per_cpu = (
             (NMaxGlobal // self.chunk_size) + 1) * self.chunk_size
         total_size = MPI.COMM_WORLD.size * size_per_cpu
         # Prepares Dataset.
         g = pyh5md.element(self.connectivity,
                            name,
                            store='fixed',
                            dtype=self.h5md_file.int_type,
                            fillvalue=-1,
                            shape=(total_size, 2))
         g.attrs['particle_group'] = particle_group
         # Calculates index per cpu.
         idx_0 = MPI.COMM_WORLD.rank * size_per_cpu
         idx_1 = idx_0 + NMaxLocal
         # Writes data.
         g[idx_0:idx_1] = bonds
Ejemplo n.º 10
0
        return float(split[0])/float(split[1])
    else:
        raise ValueError("Bad value for scale")

# read
# select clusters
# align to z


if __name__ == '__main__':
    args = parse_args()
    assert args.file[-3:] == '.h5'

    with pyh5md.File(args.file, 'r') as a:
        colloids = a.particles_group(args.group)
        all_r = pyh5md.element(colloids, 'position')
        edges = colloids['box/edges'][:]
        n_colloids = all_r.value.shape[1]
        mass_bead = args.rho * 4/3*np.pi*args.sigma**3
        I_target = n_colloids * mass_bead * 2/5 * args.treshold**2
        step = 0
        configurations = []
        for r in all_r.value:
            r = center_cluster(r, edges)
            I = mass_bead*inertia_tensor(r).diagonal()
            ratio = np.std(I)/np.mean(I)
            radius = np.sqrt(np.sum(r**2, axis=1))
            transform(r)
            I_trans = mass_bead*inertia_tensor(r).diagonal()
            r *= np.sqrt(I_target / I_trans[2])
            Ip = mass_bead*inertia_tensor(r).diagonal()
Ejemplo n.º 11
0
import pyh5md
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import TRR

# Open an H5MD file to read
with pyh5md.File('TRR3.h5', 'r') as f:

    # extract particles group
    particles = f.particles_group('particles')

    # extract particle postitions and velocities with pyh5md.element function
    part_pos = pyh5md.element(particles, 'position')
    part_vel = pyh5md.element(particles, 'velocity')

    # extract observables data from f group
    com = pyh5md.element(f, 'observables/center_of_mass')
    mean_vel = pyh5md.element(f, 'observables/mean_velocity')
Ejemplo n.º 12
0
    def __init__(self,
                 system,
                 filename,
                 store_position=True,
                 store_species=True,
                 store_state=False,
                 store_velocity=False,
                 store_force=False,
                 store_charge=False,
                 store_lambda=False,
                 store_res_id=True,
                 store_mass=True,
                 static_box=True,
                 is_adress=False,
                 group_name='atoms',
                 author='xxx',
                 email='xxx',
                 chunk_size=256,
                 is_single_prec=False,
                 do_sort=True):
        """
        Args:
            system: The system object.
            filename: The name of hdf file name.
            group_name: The name of atom groups. (default: 'atoms').
            store_position: If set to True then position will be stored. (default: True)
            store_species: If set to True then species will be stored. (default: True)
            store_state: If set to True then state will be stored. (default: False)
            store_velocity: If set to True then velocity will be stored. (default: False)
            store_force: If set to True then force will be stored. (default: False)
            store_charge: If set to True then charge will be stored. (default: False)
            store_lambda: If set to True then lambda (AdResS) will be stored. (default: False)
            store_res_id: If set to True then store res_id. (default: False)
            store_mass: If set to True then store mass. (default: True)
            static_box: If set to True then box is static (like in NVT ensemble) (default: True)
            is_adress: If set to True then AdResS particles will be save instead of
                coarse-grained.
            author: The name of author of the file. (default: xxx)
            email: The e-mail to author of that file. (default: xxx)
            chunk_size: The size of data chunk. (default: 128)
            is_single_prec: Use single precision instead of double.
            do_sort: If set to True then HDF5 will be sorted on close.
        """
        if not pmi.workerIsActive():
            return
        cxxinit(self, io_DumpH5MD, system, is_adress)

        self.filename = filename
        self.group_name = group_name
        self.store_position = store_position
        self.store_species = store_species
        self.store_state = store_state
        self.store_velocity = store_velocity
        self.store_force = store_force
        self.store_charge = store_charge
        self.store_lambda = store_lambda
        self.store_res_id = store_res_id
        self.store_mass = store_mass
        self.static_box = static_box
        self.chunk_size = chunk_size
        self.do_sort = do_sort
        self.single_prec = is_single_prec

        self.system = system

        if pmi.isController:
            if os.path.exists(filename):
                basename = os.path.basename(filename)
                dirname = os.path.dirname(filename)
                new_filename = '{}/{}_{}'.format(dirname, int(py_time.time()),
                                                 os.path.basename(filename))
                os.rename(filename, new_filename)
                print('File {} exists, moved to {}'.format(
                    filename, new_filename))

        try:
            self.file = pyh5md.File(
                filename,
                'w',
                creator='espressopp',
                creator_version=espressopp.VersionLocal().info(),
                author=author,
                author_email=email,
                driver='mpio',
                comm=MPI.COMM_WORLD)
        except AttributeError:
            self.file = pyh5md.File(
                filename,
                'w',
                creator='espressopp',
                creator_version=espressopp.VersionLocal().info(),
                author=author,
                author_email=email)

        self._system_data()

        self.float_type = np.float32 if is_single_prec else np.float64
        self.int_type = np.int32 if is_single_prec else np.int

        part = self.file.particles_group(self.group_name)
        self.particle_group = part

        if self.static_box:
            self.box = part.create_box(
                dimension=3,
                boundary=['periodic', 'periodic', 'periodic'],
                store='fixed',
                data=np.array([ed_i for ed_i in self.system.bc.boxL],
                              dtype=self.float_type))
        else:
            self.box = part.box(dimension=3,
                                boundary=['periodic', 'periodic', 'periodic'],
                                store='time',
                                time=True,
                                data=np.zeros(3, dtype=self.float_type))

        self.id_e = pyh5md.element(part,
                                   'id',
                                   store='time',
                                   time=True,
                                   shape=(self.chunk_size, ),
                                   maxshape=(None, ),
                                   dtype=self.int_type,
                                   fillvalue=-1)
        if store_mass:
            self.mass = pyh5md.element(part,
                                       'mass',
                                       store='time',
                                       time=True,
                                       maxshape=(None, ),
                                       shape=(self.chunk_size, ),
                                       dtype=self.float_type,
                                       fillvalue=-1)
        if self.store_position:
            self.position = pyh5md.element(part,
                                           'position',
                                           store='time',
                                           time=True,
                                           maxshape=(None, 3),
                                           shape=(self.chunk_size, 3),
                                           dtype=self.float_type)
            self.image = pyh5md.element(part,
                                        'image',
                                        store='time',
                                        time=True,
                                        maxshape=(None, 3),
                                        shape=(self.chunk_size, 3),
                                        dtype=self.float_type)
        if self.store_species:
            self.species = pyh5md.element(part,
                                          'species',
                                          store='time',
                                          time=True,
                                          maxshape=(None, ),
                                          shape=(self.chunk_size, ),
                                          dtype=self.int_type,
                                          fillvalue=-1)
        if self.store_state:
            self.state = pyh5md.element(part,
                                        'state',
                                        store='time',
                                        time=True,
                                        maxshape=(None, ),
                                        shape=(self.chunk_size, ),
                                        dtype=self.int_type,
                                        fillvalue=-1)
        if self.store_velocity:
            self.velocity = pyh5md.element(part,
                                           'velocity',
                                           store='time',
                                           time=True,
                                           maxshape=(None, 3),
                                           shape=(self.chunk_size, 3),
                                           dtype=self.float_type)
        if self.store_force:
            self.force = pyh5md.element(part,
                                        'force',
                                        store='time',
                                        time=True,
                                        maxshape=(None, 3),
                                        shape=(self.chunk_size, 3),
                                        dtype=self.float_type)
        if self.store_charge:
            self.charge = pyh5md.element(part,
                                         'charge',
                                         store='time',
                                         time=True,
                                         maxshape=(None, ),
                                         shape=(self.chunk_size, ),
                                         dtype=self.float_type,
                                         fillvalue=-1)
        if self.store_lambda:
            self.lambda_adr = pyh5md.element(part,
                                             'lambda_adr',
                                             store='time',
                                             time=True,
                                             maxshape=(None, ),
                                             shape=(self.chunk_size, ),
                                             dtype=self.float_type,
                                             fillvalue=-1)
        if self.store_res_id:
            self.res_id = pyh5md.element(part,
                                         'res_id',
                                         store='time',
                                         time=True,
                                         maxshape=(None, ),
                                         shape=(self.chunk_size, ),
                                         dtype=self.int_type,
                                         fillvalue=-1)
        self._system_data()

        self.commTimer = 0.0
        self.updateTimer = 0.0
        self.writeTimer = 0.0
        self.flushTimer = 0.0
        self.closeTimer = 0.0
        self.resizeCounter = 0
Ejemplo n.º 13
0
import numpy as np
from pyh5md import File, element

N = 32
DT = 0.1

with File('example_for_1.1.h5', 'w',author='Pierre', creator='run.py') as f:

    f.observables = f.require_group('observables')
    f.connectivity = f.require_group('connectivity')
    v_e = element(f.observables, 'v', store='linear', data=1, step=10, step_offset=10, time=5., time_offset=5.)

    f.all = f.particles_group('all')

    f.all.create_box(dimension=3, boundary=['periodic']*3,
                     store='time', shape=(3,), dtype=np.float64)

    pos = np.zeros((N, 3))
    pos_e = element(f.all, 'position', store='time', data=pos, step_from=f.all.box.edges)

    vel = np.random.random(pos.shape)-0.5
    vel_e = element(f.all, 'velocity', store='time', data=vel)

    force = np.random.random(pos.shape)-0.5
    force_e = element(f.all, 'force', store='time', data=force, time=True)

    mass = np.ones((N,))*100.0
    element(f.all, 'mass', store='fixed', data=mass)

    idx_all = np.arange(N)
    idx_list = np.random.choice(idx_all, 5)
Ejemplo n.º 14
0
parser.add_argument('--plot',
                    action='store_true',
                    help='Display the result graphically')
parser.add_argument('--no-q',
                    action='store_true',
                    help='Do not use quaternion data')
args = parser.parse_args()

import numpy as np
import matplotlib.pyplot as plt
from transforms3d import quaternions
import pyh5md

with pyh5md.File(args.file, 'r') as f:
    obs = f['observables']
    u = pyh5md.element(obs, 'u').value[:]
    if 'q' in obs:
        q = pyh5md.element(obs, 'q').value[:]
    else:
        q = None
    janus_vel = pyh5md.element(obs, 'janus_vel')
    dt = janus_vel.time
    janus_vel = janus_vel.value[:]

one_z = np.array([0., 0., 1.])

# Change of quaternion storage convention
if q is not None and not args.no_q:
    tmp_s = q[:, 3].copy()
    tmp_v = q[:, :3].copy()
    q[:, 1:4] = tmp_v
Ejemplo n.º 15
0
import numpy as np
import h5py
import pyh5md
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import TPR_xvf, TRR_xvf

u = mda.Universe(TPR_xvf, TRR_xvf)

# open h5 file:
f = pyh5md.File('cobrotoxin.h5md', 'r')
# extract particles group
atoms = f.particles_group('trajectory')

# extract datasets from .h5 file with pyh5md.element function 
box = pyh5md.element(atoms['box'], 'edges').value[:]
positions = pyh5md.element(atoms, 'positions').value[:]
velocities = pyh5md.element(atoms, 'velocities').value[:]
forces = pyh5md.element(atoms, 'forces').value[:]
n_atoms = pyh5md.element(atoms, 'n_atoms').value[()]



#TESTS
print('Box Dimensions test (True=Pass False=Fail):')
for ts, x in zip(u.trajectory, box):
    print('Timestep', u.trajectory.ts.frame, np.allclose(u.trajectory.ts.triclinic_dimensions, x))
    
print('Positions test (True=Pass False=Fail):')
for ts, x in zip(u.trajectory, positions):
    print('Timestep', u.trajectory.ts.frame, np.allclose(u.atoms.positions, x))
    
Ejemplo n.º 16
0
positions = u.atoms.positions

# Open a H5MD file to write
with pyh5md.File('TRR3.h5', 'w', author='Edis') as f:

    ts = u.trajectory.ts
    step_from = mda.lib.util.Namespace(step=ts.frame, time=ts.time)

    # Add a trajectory group
    particles = f.particles_group('particles')

    # Add the position data element in the trajectory group
    part_pos = pyh5md.element(particles,
                              'position',
                              step_from=step_from,
                              store='time',
                              shape=positions.shape,
                              dtype=positions.dtype,
                              time=True)
    # Add the velocity data element into the trajectory group
    part_vel = pyh5md.element(particles,
                              'velocity',
                              step_from=step_from,
                              store='time',
                              shape=positions.shape,
                              dtype=positions.dtype,
                              time=True)

    # Add observable groups
    # Center of mass:
    com = u.atoms.center_of_geometry()
Ejemplo n.º 17
0
#
# pyh5md is free software and is licensed under the modified BSD license (see
# LICENSE file).

import numpy as np
import matplotlib.pyplot as plt
from pyh5md import File, element

# Open a H5MD file
f = File('walk_1d.h5', 'r')

# Open a trajectory group
part = f.particles_group('particles')

# Open trajectory position data element in the trajectory group
part_pos = element(part, 'position')

# Get data and time
r = part_pos.value
r_time = part_pos.time

# Compute the time-averaged mean-square displacement,
# drop large correlation times due to insufficient statistics
T = r.shape[0]
msd = np.empty((T//4, r.shape[1]))
time = r_time[:T//4]
for n in range(T//4):
    # the sum over "axis=2" is over the spatial components of the positions
    msd[n] = np.mean(np.sum(pow(r[n:] - r[:T-n], 2), axis=2), axis=0)

# Compute mean and standard error of mean (particle- and component-wise)
Ejemplo n.º 18
0
import numpy as np
from pyh5md import File, element

f = File('particles_3d.h5', 'w', author='Pierre de Buyl', creator='run_h5md', creator_version='N/A')

# Creating atom group
at = f.particles_group('atoms')

# Creating position data
r = np.zeros((100,3), dtype=np.float64)
at_pos = element(at,'position', store='time', data=r, time=True)

# Creating species
s = np.ones(r.shape[:1])
element(at, 'species', data=s, store='fixed')

# Creating velocity data
v = np.zeros((100,3), dtype=np.float64)
at_v = element(at, 'velocity', store='time', data=v, step_from=at_pos, time=True)

# Create an observable
com = r.mean(axis=0)
obs_com = element(f, 'observables/center_of_mass', store='linear', data=com, step=10)
# Create a scalar time independent observable
element(f, 'observables/random_number', data=np.random.random(), store='fixed')

edges = (1.,1.,1.)
box = at.create_box(dimension=3, boundary=['none', 'none', 'none'], store='time',
                    data=edges, step_from=at_pos)

DT = 0.1
Ejemplo n.º 19
0
import numpy as np
from pyh5md import File, element

# Open a H5MD file
f = File('walk_1d.h5', 'w', creator='pyh5md examples/jump_process.py', creator_version='0', author='Pierre de Buyl')

# Add a trajectory group
part = f.particles_group('particles')
part.create_box(dimension=1, boundary=['none'])

# Create the trajectory data
r = np.zeros((30,1), dtype=np.int32)

# Add the trajectory position data element in the trajectory group
part_pos = element(part, 'position', store='time', shape=r.shape, dtype=r.dtype, time=True)

# Create an observable
f.observables = f.require_group('observables')
obs_com = element(f.observables, 'center_of_mass', shape=(), dtype=np.float64, store='time', time=True)

# Run a simulation
step=0
time=0.
for i in range(800):
    step+=1
    time+=.1
    r += -1 + 2*np.random.random_integers(0,1,r.shape)
    # Append the current position data to the H5MD file.
    part_pos.append(r, step, time)
    obs_com.append(r[:,0].mean(), step, time)
Ejemplo n.º 20
0
import pyh5md
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import TPR_xvf, TRR_xvf

u = mda.Universe(TPR_xvf, TRR_xvf)

# Open a H5MD file to write
with pyh5md.File('cobrotoxin.h5md', 'w', creator='write_h5md.py') as f:

    # Add a trajectory group into particles group
    trajectory = f.particles_group('trajectory')

    # Add the positions, velocities, forces, masses, n_atoms groups into the trajectory group
    trajectory_positions = pyh5md.element(trajectory,
                                          'positions',
                                          store='time',
                                          data=u.trajectory.ts.positions,
                                          time=True)
    trajectory_velocities = pyh5md.element(trajectory,
                                           'velocities',
                                           data=u.trajectory.ts.velocities,
                                           step_from=trajectory_positions,
                                           store='time',
                                           time=True)
    trajectory_forces = pyh5md.element(trajectory,
                                       'forces',
                                       data=u.trajectory.ts.forces,
                                       step_from=trajectory_positions,
                                       store='time',
                                       time=True)
    trajectory_n_atoms = pyh5md.element(trajectory,