Beispiel #1
0
# -*- coding: utf-8 -*-
# Copyright 2012-2013 Pierre de Buyl
# Copyright 2013 Felix Hoëfling
#
# This file is part of pyh5md
#
# pyh5md is free software and is licensed under the modified BSD license (see
# LICENSE file).

import numpy as np
import matplotlib.pyplot as plt
import pyh5md

# Open a H5MD file
f = pyh5md.H5MD_File('walk_1d.h5', 'r')
f.check()

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

# Open trajectory position data element in the trajectory group
part_pos = part.trajectory('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]))
Beispiel #2
0
import numpy as np
import pyh5md
import matplotlib.pyplot as plt

f = pyh5md.H5MD_File('particles_3d.h5', 'r')

rn = f.observable('random_number')
print rn[()]

com = f.observable('center_of_mass')
plt.plot(com.time, com.value)
plt.show()
Beispiel #3
0
# -*- coding: utf-8 -*-
# Copyright 2012-2013 Pierre de Buyl
# Copyright 2013 Felix Hoëfling
#
# This file is part of pyh5md
#
# pyh5md is free software and is licensed under the modified BSD license (see
# LICENSE file).

import numpy as np
import pyh5md

# Open a H5MD file
f = pyh5md.H5MD_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.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 = part.trajectory('position', r.shape, r.dtype)

# Create an observable
obs_com = f.observable('center_of_mass', (), np.float64)
Beispiel #4
0
# Copyright 2012-2013 Pierre de Buyl
#
# This file is part of pyh5md
#
# pyh5md is free software and is licensed under the modified BSD license (see
# LICENSE file).

import numpy as np
import pyh5md

f = pyh5md.H5MD_File('particles_3d.h5', 'w', creator='run_h5md', creator_version='0', author='Pierre de Buyl')

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

# Creating position data
r = np.zeros((100,3), dtype=np.float64)
at_pos = at.trajectory('position', r.shape, r.dtype)

# Creating species
s = np.ones(r.shape[:1])
at_s = at.trajectory('species', data=s, time=False)

# Creating velocity data
v = np.zeros((100,3), dtype=np.float64)
at_v = at.trajectory('velocity', v.shape, v.dtype)

# Create an observable
obs_com = f.observable('center_of_mass', r.shape[-1:], r.dtype)
# Create a scalar time independent observable
obs_fixed = f.observable('random_number', data=np.random.random(), time=False)
def DumpH5MD(filename, system, integrator, author, author_email=None, edges=None, edges_time=False, n_states=None):
    espresso.Version().info()
    f = pyh5md.H5MD_File(filename, 'w', creator='espressopp', creator_version=espresso.Version().info(), author=author, author_email=author_email)
    atoms = f.particles_group('atoms')
    maxParticleID = int(espresso.analysis.MaxPID(system).compute())
    pos = atoms.trajectory('position', (maxParticleID+1,3), np.float64)
    species = atoms.trajectory('species', (maxParticleID+1,), np.int32)
    state = atoms.trajectory('state', (maxParticleID+1,), np.int32)
    if edges_time:
        f.box = atoms.box(dimension=3, boundary=['periodic', 'periodic', 'periodic'], edges=edges, time=True)
    else:
        f.box = atoms.box(dimension=3, boundary=['periodic', 'periodic', 'periodic'], edges=edges)
    f.NPart = espresso.analysis.NPart(system).compute()
    f.observable('particle_number', data=int(f.NPart), time=False)
    f.f['observables'].attrs['dimension']=3
    obs_dict = {}
    f.n_states = n_states
    state_tuple = (('statecount', (n_states,), np.int32),) if n_states is not None else ()
    for o in (
            ('temperature', (), np.float64), ('kinetic_energy', (), np.float64),
            ('pressure', (), np.float64), ('pressure_tensor', (6,), np.float64),
            ('potential_energy', (), np.float64),('internal_energy', (), np.float64),
            ('lennard_jones', (), np.float64),
            ('mirror_lennard_jones', (), np.float64),
    ) + state_tuple:
        obs_dict[o[0]] = f.observable(*o)
    def dump():
        step = integrator.step
        time = integrator.step*integrator.dt
        maxParticleID = int(espresso.analysis.MaxPID(system).compute())
        if maxParticleID>pos.value.shape[1]:
            raise ValueError('System too large for dataset')
        r = np.array(
            [[x for x in system.storage.getParticle(pid).pos] for pid in range(maxParticleID+1)]
            )
        pos.append(r, step, time)
        del r
        species.append(
            np.array([system.storage.getParticle(pid).type for pid in range(maxParticleID+1)]),
            step, time)
        state.append(
            np.array([system.storage.getParticle(pid).state for pid in range(maxParticleID+1)]),
            step, time)
    f.dump = dump
    def analyse():
        step = integrator.step
        time = integrator.step*integrator.dt
        T = espresso.analysis.Temperature(system).compute()
        obs_dict['temperature'].append(T, step, time)
        P      = espresso.analysis.Pressure(system).compute()
        obs_dict['pressure'].append(P, step, time)
        Pij    = espresso.analysis.PressureTensor(system).compute()
        obs_dict['pressure_tensor'].append(Pij, step, time)
        Ek     = (3.0/2.0) * T
        obs_dict['kinetic_energy'].append(Ek, step, time)
        LJ = system.getInteraction(0).computeEnergy()/f.NPart
        obs_dict['lennard_jones'].append(LJ, step, time)
        MirrorLJ = system.getInteraction(1).computeEnergy()/f.NPart
        obs_dict['mirror_lennard_jones'].append(MirrorLJ, step, time)
        potential = LJ+MirrorLJ
        obs_dict['potential_energy'].append(potential, step, time)
        obs_dict['internal_energy'].append(Ek+potential, step, time)
        if f.n_states is not None:
            obs_dict['statecount'].append(np.bincount(np.array([system.storage.getParticle(pid).state for pid in range(maxParticleID+1)]), minlength=f.n_states), step, time)
    f.analyse = analyse
    return f
Beispiel #6
0
# Copyright 2012-2013 Pierre de Buyl
#
# This file is part of pyh5md
#
# pyh5md is free software and is licensed under the modified BSD license (see
# LICENSE file).

import numpy as np
import pyh5md
from pyh5md.core import is_h5md
import h5py

with pyh5md.H5MD_File('particles_3d.h5', 'r') as f:
    f.check()