示例#1
0
def unitcell(h5file, vasp_dir, elements=None, poscar_equiv='POSCAR'):
    """POSCAR parser

    Reads lattice vectors and atom positions from POSCAR file and writes data to an HDF5 file.
    If no element symbols are given as an argument, the parser looks for them in the POTCAR file,
    or in POSCAR if no POTCAR file is found.
    If POSCAR uses cartesian coordinates, they will be transformed.
    If the given HDF5 file already contains unit cell data, nothing is parsed.

    Parameters
    ----------
    h5file : str
        Path to HDF5 file

    vasp_dir : str
        Path to directory containing POSCAR file

    elements : list of str
         (Default value = None)
        List of element symbols

    Returns
    -------
    bool
        True if POSCAR was parsed, False otherwise.
    """
    if os.path.isfile(h5file):
        with h5py.File(h5file, 'r') as h5:
            if "/UnitCell" in h5:
                print("Already parsed. Skipping.")
                return True
        
    try:
        # Parses lattice vectors and atom positions from POSCAR
        with open(os.path.join(vasp_dir,poscar_equiv), "r") as f:
            scaling_factor, basis = _parse_lattice(f)
            elements, atoms = _find_elements(f, elements, vasp_dir)
            coords_list = _parse_coordinates(
                f,
                sum(atoms),
                _cartesian(f),
                np.linalg.inv(basis)
            )
            _write_basis(h5file, basis)
            _write_scaling_factor(h5file, scaling_factor)
            _write_coordinates(
                h5file,
                atoms,
                coords_list,
                elements,
                '/UnitCell'
            )
            return True
    except FileNotFoundError:
        print("POSCAR file not found.")
        return False
示例#2
0
def unitcell_parser(h5file, ELK_dir):
    elements, number_of_atoms = find_elements(ELK_dir)
    scaling_factor, basis = parse_lattice(ELK_dir)
    coords_list = parse_coordinates(ELK_dir, number_of_atoms)
    #with open(os.path.join(ELK_dir,info_equiv), "r") as f:
    _write_basis(h5file, basis)
    _write_scaling_factor(h5file, scaling_factor=1)
    _write_coordinates(h5file, number_of_atoms, coords_list, elements,
                       '/UnitCell')
    return
示例#3
0
def parse_elf(h5file, ELK_dir):
    scaling_factor, basis = parse_lattice(ELK_dir)
    _write_basis(h5file, basis)
    _write_scaling_factor(h5file, scaling_factor=1)
    ELK_file = Path(ELK_dir).joinpath('ELF3D.OUT')
    with open(ELK_file, "r+") as f:
        for i in itertools.count():
            array, data_dim = parse_vol(f)
            if not _write_volume(h5file, i, array, data_dim, "ELF"):
                return False
            if not array:
                break
    return True
示例#4
0
def volume(h5file, hdfgroup, vasp_dir, vasp_file):
    """
	Reads volume data from  vasp_file, either CHG or ELFCAR, 
        and stores it in an HDF-file.

	Parameters
	----------
	h5file : str
		String that asserts which HDF-file to write to
	hdfgroup : str
		String that asserts which group to write to in HDF-file
	vasp_dir : str
		Path to directory containing volume file
	vasp_file : str
		String that asserts which file to open in the directory

	Returns
	-------
	bool
		True if volume file was parsed, False otherwise.
	"""

    if os.path.isfile(h5file):
        with h5py.File(h5file, 'r') as h5:
            if '/{}'.format(hdfgroup) in h5:
                print(vasp_file + ' already parsed. Skipping.')
                return False
    try:
        with open(os.path.join(vasp_dir, 'POSCAR'), 'r') as f:
            scaling_factor, basis = _parse_lattice(f)
            _write_basis(h5file, basis)
            _write_scaling_factor(h5file, scaling_factor)
    except FileNotFoundError:
        print("POSCAR file not in directory. Skipping.")
    try:
        with open(os.path.join(vasp_dir, vasp_file), "r") as f:
            for i in itertools.count():
                array, data_dim = parse_volume(f, hdfgroup)
                if not _write_volume(h5file, i, array, data_dim, hdfgroup):
                    return False
                if not array:
                    break
    except FileNotFoundError:
        print(vasp_file + ' file not in directory. Skipping.')
        return False
    print(vasp_file + ' was parsed successfully.')
    return True
示例#5
0
def parse_force_elk(h5file, elk_dir, inviwo=False, elements=None):
    elements, atoms = find_elements(elk_dir)
    coordinates = parse_coordinates(elk_dir, atoms)
    scaling_factor, basis = parse_lattice(elk_dir)
    force_tips = parse_force(elk_dir, coordinates)
    if os.path.isfile(h5file):
        with h5py.File(h5file, 'r') as h5:
            if "/UnitCell" not in h5:
                _write_basis(h5file, basis)
                _write_scaling_factor(h5file, scaling_factor=1)
                _write_coordinates(h5file, atoms, coordinates, elements,
                                   '/UnitCell')
        _write_forces(h5file, atoms, force_tips, '/Forces')
        return True
    else:
        _write_basis(h5file, basis)
        _write_scaling_factor(h5file, scaling_factor=1)
        _write_coordinates(h5file, atoms, coordinates, elements, '/UnitCell')
        _write_forces(h5file, atoms, force_tips, '/Forces')
        return True
示例#6
0
def force_parser(h5file,
                 vasp_dir,
                 inviwo=False,
                 elements=None,
                 poscar_equiv='POSCAR'):
    if has_been_parsed("force_parser", h5file, vasp_dir) and inviwo:
        print("Already Parsed, skipping")
        return True

    try:
        # Parses lattice vectors and atom positions from POSCAR
        with open(os.path.join(vasp_dir, poscar_equiv), "r") as f:
            scaling_factor, basis = _parse_lattice(f)
            elements, atoms = _find_elements(f, elements, vasp_dir)
            coords_list = _parse_coordinates(f, sum(atoms), _cartesian(f),
                                             np.linalg.inv(basis))
            force_list = _parse_forces(vasp_dir, True, coords_list)
            if os.path.isfile(h5file):
                with h5py.File(h5file, 'r') as h5:
                    if "/UnitCell" in h5:
                        h5.close()
                        _write_forces(h5file, atoms, force_list, '/Forces')
                        return True
                    else:
                        h5.close()
                        _write_basis(h5file, basis)
                        _write_scaling_factor(h5file, scaling_factor)
                        _write_coordinates(h5file, atoms, coords_list,
                                           elements, '/UnitCell')
            else:
                _write_basis(h5file, basis)
                _write_scaling_factor(h5file, scaling_factor)
                _write_coordinates(h5file, atoms, coords_list, elements,
                                   '/UnitCell')

            _write_forces(h5file, atoms, force_list, '/Forces')

            return True
    except FileNotFoundError:
        print("POSCAR file not found........")
        return False