示例#1
0
def read_trajectory(dir='', unwrap_pbcs=True, xml_file='vasprun.xml',
        orig_file='traj_orig.h5', unwrapped_file='traj_unwrapped.h5',
        poscar_file='POSCAR'):
    """
    Convenience function for reading trajectory data from vasprun.xml.
    - The first time a trajectory is read, the trajectory data is read from
      vasprun.xml using lxml, and saved in a HDF5 binary file using PyTables. 
    - The next time the trajectory is read, the HDF5 file is read directly.
      This is much faster.

    If `unwrap_pbcs' is set to True, periodic boundary conditions (PBCs) will
    be unwrapped, using initial positions from a specified POSCAR file.
    Initial positions are taken from a POSCAR file instead of the initial
    positions in the vasprun.xml file, because the latter are wrapped into the
    cell, making visual comparison with the original structure difficult if the
    POSCAR file contained coordinates out of the cell, such as may result from
    a cell where the atoms were relaxed from initial positions at the edge of
    the cell.

    Parameters
    ----------
    dir : str
        Directory to read files from
        Default is current directory
    unwrap_pbcs : bool
        Set to True to unwrap the periodic boundary conditions (PBCs) or False to leave them.
        Default is True
    xml_file : str
        Name of the vasprun.xml file, default is "vasprun.xml"
    orig_file : str
        Name of the HDF5 file
    unwrapped_file : str
        Name of the HDF5 file containing unwrapped PBCs. 
        Only used if unwrap_pbcs is set to True

    """

    if not os.path.isfile(dir + orig_file):
        p = IterativeVasprunParser(dir + xml_file)
        traj = p.get_trajectory()
        traj.save(dir + orig_file)
        if not unwrap_pbcs:
            return traj
    elif not unwrap_pbcs:
        return Trajectory(filename = dir + orig_file)

    if os.path.isfile(dir + unwrapped_file):
        return Trajectory(filename = dir + unwrapped_file)
    else:
        poscar = PoscarParser(dir + poscar_file)
        pos = poscar.get_positions(coords = 'direct')
        try:
            t = traj
        except:
            t = Trajectory(filename = dir + orig_file)
        print "Unwrapping using initial pos from POSCAR"
        t.unwrap_pbc(init_pos = pos)
        t.save(dir + unwrapped_file)
        return t
 def read_trajectory(self, traj_dir = './', xml_file ='vasprun.xml', npz_pbc_file = 'trajectory_pbc.npz', npz_file = 'trajectory_nopbc.npz' ):
     if os.path.isfile(traj_dir + npz_pbc_file):
         traj = Trajectory(filename = traj_dir +npz_pbc_file)
     else:
         p = IterativeVasprunParser(traj_dir + xml_file)
         traj = p.get_all_trajectories()
         traj.save(traj_dir + npz_pbc_file)
         # we do NOT unwrap the PBCs
     return traj
 def read_trajectory(self,
                     traj_dir='./',
                     xml_file='vasprun.xml',
                     npz_pbc_file='trajectory_pbc.npz',
                     npz_file='trajectory_nopbc.npz'):
     if os.path.isfile(traj_dir + npz_pbc_file):
         traj = Trajectory(filename=traj_dir + npz_pbc_file)
     else:
         p = IterativeVasprunParser(traj_dir + xml_file)
         traj = p.get_all_trajectories()
         traj.save(traj_dir + npz_pbc_file)
         # we do NOT unwrap the PBCs
     return traj
def read_trajectory( dir = './', xml_file ='vasprun.xml', npz_pbc_file = 'trajectory_pbc.npz', npz_file = 'trajectory_nopbc.npz', POSCAR_file = '' ):
    if os.path.isfile(dir + npz_file):
        traj = Trajectory(filename = dir +npz_file)
    else:
        p = IterativeVasprunParser(dir + xml_file)
        traj = p.get_all_trajectories()
        traj.save(dir + npz_pbc_file)
        if POSCAR_file != '':
            poscar = PoscarParser(dir + POSCAR_file)
            pos = poscar.get_positions( coordinates = 'direct' )
            print "Unwrapping using given initial pos"
            traj.unwrap_pbc( init_pos = pos)
        else:
            traj.unwrap_pbc()
        traj.save(dir + npz_file)
    return traj
def read_trajectory( dir = './', xml_file ='vasprun.xml', npz_pbc_file = 'trajectory_pbc.npz', npz_file = 'trajectory_nopbc.npz', POSCAR_file = '' ):
    if os.path.isfile(dir + npz_file):
        traj = Trajectory(filename = dir +npz_file)
    else:
        p = IterativeVasprunParser(dir + xml_file)
        traj = p.get_all_trajectories()
        traj.save(dir + npz_pbc_file)
        if POSCAR_file != '':
            poscar = PoscarParser(dir + POSCAR_file)
            pos = poscar.get_positions( coordinates = 'direct' )
            print "Unwrapping using given initial pos"
            traj.unwrap_pbc( init_pos = pos)
        else:
            traj.unwrap_pbc()
        traj.save(dir + npz_file)
    return traj
示例#6
0

#############################################################################
# (1) Extract data

wdir = './'

basename = os.path.splitext(os.path.basename(sys.argv[0]))[0]
fig_filename = wdir + basename + '.pdf'
xml = wdir + 'vasprun.xml'
npz = wdir + 'trajectory_pbc.npz'

if os.path.isfile(npz):
    traj = Trajectory(filename=npz)
else:
    p = IterativeVasprunParser(xml)
    traj = p.get_all_trajectories()
    traj.save(npz)

fac = 8 * 2 * np.pi
nsteps = traj.length
natoms = traj.num_atoms

lambda_x = np.zeros((nsteps))
lambda_y = np.zeros((nsteps))
lambda_z = np.zeros((nsteps))

### <!-- Test begin -->
from oppvasp.vasp.parsers import PoscarParser

ps = PoscarParser(
示例#7
0
             RotatingMarker, ReverseBar, SimpleProgress

from oppvasp.vasp.parsers import IterativeVasprunParser, PoscarParser
from oppvasp.md import Trajectory

xml_filename = 'vasprun.xml'
npz_filename = 'trajectory.npz'
vtf_filename = 'trajectory.vtf'

if len(sys.argv) > 1:
    npz_filename = sys.argv[1]

if os.path.isfile(npz_filename):
    traj = Trajectory(filename = npz_filename)
else:
    p = IterativeVasprunParser(xml_filename)
    traj = p.get_all_trajectories()
    traj.save(npz_filename)

basis = traj.basis
atoms = traj.atoms
nsteps = traj.length # NSW
nions = traj.num_atoms
positions = traj.positions
forces = traj.forces
total_energy = traj.total_energy

f = open(vtf_filename,'w')

# A bond is formed whenever two atoms are within (R1 + R2) x 0.6 of each other, 
# where R1 and R2 are the respective radii of candidate atoms.
示例#8
0
def read_trajectory(dir='',
                    unwrap_pbcs=True,
                    xml_file='vasprun.xml',
                    orig_file='traj_orig.h5',
                    unwrapped_file='traj_unwrapped.h5',
                    poscar_file='POSCAR'):
    """
    Convenience function for reading trajectory data from vasprun.xml.
    - The first time a trajectory is read, the trajectory data is read from
      vasprun.xml using lxml, and saved in a HDF5 binary file using PyTables. 
    - The next time the trajectory is read, the HDF5 file is read directly.
      This is much faster.

    If `unwrap_pbcs' is set to True, periodic boundary conditions (PBCs) will
    be unwrapped, using initial positions from a specified POSCAR file.
    Initial positions are taken from a POSCAR file instead of the initial
    positions in the vasprun.xml file, because the latter are wrapped into the
    cell, making visual comparison with the original structure difficult if the
    POSCAR file contained coordinates out of the cell, such as may result from
    a cell where the atoms were relaxed from initial positions at the edge of
    the cell.

    Parameters
    ----------
    dir : str
        Directory to read files from
        Default is current directory
    unwrap_pbcs : bool
        Set to True to unwrap the periodic boundary conditions (PBCs) or False to leave them.
        Default is True
    xml_file : str
        Name of the vasprun.xml file, default is "vasprun.xml"
    orig_file : str
        Name of the HDF5 file
    unwrapped_file : str
        Name of the HDF5 file containing unwrapped PBCs. 
        Only used if unwrap_pbcs is set to True

    """

    if not os.path.isfile(dir + orig_file):
        p = IterativeVasprunParser(dir + xml_file)
        traj = p.get_trajectory()
        traj.save(dir + orig_file)
        if not unwrap_pbcs:
            return traj
    elif not unwrap_pbcs:
        return Trajectory(filename=dir + orig_file)

    if os.path.isfile(dir + unwrapped_file):
        return Trajectory(filename=dir + unwrapped_file)
    else:
        poscar = PoscarParser(dir + poscar_file)
        pos = poscar.get_positions(coords='direct')
        try:
            t = traj
        except:
            t = Trajectory(filename=dir + orig_file)
        print "Unwrapping using initial pos from POSCAR"
        t.unwrap_pbc(init_pos=pos)
        t.save(dir + unwrapped_file)
        return t
示例#9
0
#!/usr/bin/env python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# vim:fenc=utf-8:et:sw=4:ts=4:sts=4:tw=0

import numpy as np
from oppvasp.vasp.parsers import IterativeVasprunParser

vp = IterativeVasprunParser('vasprun.xml')
nsteps = vp.get_num_ionic_steps()  # NSW
nions = vp.get_num_atoms()
atoms = vp.get_atoms()
data = vp.get_all_trajectories()
ndsteps = data['length']  # number of steps actually calculated

f = open('movie.xyz', 'w')
for i in range(ndsteps):
    f.write("%d\n" % (nions))
    f.write("Energy: %.3f\n" % data['e_fr_energy'][i])
    basis = data['basis'][i]
    for j in range(nions):
        # convert to cartesian (Angstrom):
        at_pos = np.dot(data['atoms'][j]['trajectory'][i], basis)
        f.write(atoms[j] + '    ' + "%.8f    %.8f    %.8f\n" % tuple(at_pos))
f.close()

# Print final position of the first two atoms in direct coordinates:
print data['atoms'][0]['trajectory'][ndsteps - 1]
print data['atoms'][1]['trajectory'][ndsteps - 1]
示例#10
0
#!/usr/bin/env python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 
# vim:fenc=utf-8:et:sw=4:ts=4:sts=4:tw=0

import numpy as np
from oppvasp.vasp.parsers import IterativeVasprunParser

vp = IterativeVasprunParser('vasprun.xml')
nsteps = vp.get_num_ionic_steps() # NSW
nions = vp.get_num_atoms()
atoms = vp.get_atoms()
data = vp.get_all_trajectories()
ndsteps = data['length'] # number of steps actually calculated

f = open('movie.xyz','w')
for i in range(ndsteps):
    f.write("%d\n" % (nions)) 
    f.write("Energy: %.3f\n" % data['e_fr_energy'][i])
    basis = data['basis'][i]
    for j in range(nions):
        # convert to cartesian (Angstrom):
        at_pos = np.dot(data['atoms'][j]['trajectory'][i], basis)
        f.write(atoms[j] + '    ' + "%.8f    %.8f    %.8f\n" % tuple(at_pos))
f.close()

# Print final position of the first two atoms in direct coordinates:
print data['atoms'][0]['trajectory'][ndsteps-1]
print data['atoms'][1]['trajectory'][ndsteps-1]