Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Dev #128

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion pyprocar/io/elk.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from ..core.dos import DensityOfStates
from pathlib import Path
from typing import Union, List, Tuple, Optional
from typing import Union, List, Tuple, Optional, Dict

def parse_dos_block(dos_block: str) -> Tuple[np.array, np.array]:
"""Parse the DOS block from elk output file.
Expand Down Expand Up @@ -86,6 +86,49 @@ def read_dos(path: Union[str, Path]) -> DensityOfStates:

return DensityOfStates(energies, dos_total, dos_projected)

def read_elkin(elkin_path: str = "elk.in") -> Dict[str, str]:
"""
Reads and parses the elk.in file.

Parameters
----------
elkin_path : str, optional
Path to the elk.in file, by default "elk.in"

Returns
-------
Dict[str, str]
A dictionary containing the parsed key-value pairs from the elk.in file.

Examples
--------
>>> parsed_data = read_elkin("path/to/elk.in")
>>> print(parsed_data['some_key'])
'some_value'
"""

# Initialize a dictionary to store the parsed data
parsed_data = {}

# Open the elk.in file for reading
with open(elkin_path, 'r') as rf:
# Iterate through each line in the file
for line in rf:
# Remove leading and trailing whitespace
line = line.strip()

# Skip empty lines or comments
if not line or line.startswith('#'):
continue

# Split the line into key and value
key, value = line.split('=')

# Store the key-value pair in the parsed_data dictionary
parsed_data[key.strip()] = value.strip()

return parsed_data


# class ElkParser:
# def __init__(self, elkin="elk.in", kdirect=True):
Expand Down