forked from LeifSeute/grappa-data-creation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_progress.py
59 lines (50 loc) · 2.23 KB
/
get_progress.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
import argparse
from pathlib import Path
import numpy as np
def sum_shapes_and_calculate_ratio(directory):
# Paths to search for
positions_pattern = '**/positions.npy'
energies_pattern = '**/psi4_energies.npy'
# Initialize counters
total_positions = 0
total_energies = 0
total_molecules = 0
finished_molecules = 0
unfinished_num_states_left = {}
N_STATES = None
# Sum up shapes[0] for positions.npy files
for positions_file in directory.glob(positions_pattern):
data = np.load(positions_file)
if N_STATES is None:
N_STATES = data.shape[0]
else:
assert N_STATES == data.shape[0], f"Number of states in {positions_file} does not match the previous files."
total_positions += data.shape[0]
total_molecules += 1
# Sum up shapes[0] for psi4_energies.npy files
for energies_file in directory.glob(energies_pattern):
data = np.load(energies_file)
num_finite_energies = np.sum(np.isfinite(data))
total_energies += num_finite_energies
if num_finite_energies == N_STATES:
finished_molecules += 1
else:
unfinished_num_states_left[energies_file.parent.stem] = N_STATES-num_finite_energies
# Calculate and report the results
ratio = (total_energies / total_positions) * 100 if total_positions > 0 else 0
print(f"Total shape[0] of positions.npy files: {total_positions}")
print(f"Total shape[0] of psi4_energies.npy files: {total_energies}")
print(f"Ratio of energies to positions (in percent): {ratio:.2f}%")
print(f"Total molecules: {total_molecules}")
print(f"Finished molecules: {finished_molecules}")
print(f"States left: {unfinished_num_states_left}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Sum shapes of .npy files and calculate ratio.')
parser.add_argument('dir', type=str, help='Directory to search within.')
args = parser.parse_args()
# Convert the input argument to a Path object
directory = Path(args.dir)
if directory.exists() and directory.is_dir():
sum_shapes_and_calculate_ratio(directory)
else:
print("The specified directory does not exist or is not a directory.")