-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
59 lines (43 loc) · 1.48 KB
/
helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Helper functions
"""
from pathlib import Path
import numpy as np
def read_xvg_files(file_path: str):
"""
Read data from xvg files.
"""
data = []
with open(file_path, 'r', encoding='utf8') as file:
for line in file:
if line.startswith('#') or line.startswith('@'):
continue
values = [float(val) for val in line.strip().split()]
data.append(values)
data_array = np.array(data, dtype=float)
return data_array
def create_folder(path: str, folder_name: str = "results") -> None:
"""
Create a new folder at the specified path.
Args:
path (str): The path where the new folder should be created.
folder_name (str, optional): The name of the new folder. Defaults to "results".
Returns:
None
"""
# Specify the path of the new folder
folder_path = Path(f'{path}/{folder_name}')
# Use the mkdir method to create the folder
folder_path.mkdir(parents=True, exist_ok=True)
def find_files_with_same_pattern(path: Path, pattern: str) -> list[str]:
"""
Find files in the given path that match the specified pattern.
Args:
path (Path): The path to search for files.
pattern (str): The pattern to match against file names.
Returns:
list[str]: A list of file paths that match the specified pattern.
"""
search_directory = Path(path)
search_pattern = sorted(search_directory.glob(pattern))
return list(search_pattern)