-
Notifications
You must be signed in to change notification settings - Fork 1
/
molecule.py
45 lines (33 loc) · 1.25 KB
/
molecule.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
import numpy as np
class MolRepresentation:
def __init__(self, name: str):
self.name = name
self.header = None
self.buffer: np.array #= np.array
self.values: np.ndarray # = np.ndarray
self.is_normalized: bool = False
def __stats_calc(self): # mean and stddev calculation
self.header.mean = np.mean(self.buffer)
self.header.stddev = np.std(self.buffer)
def __normalize(self):
max_val = self.buffer.max()
min_val = self.buffer.min()
self.buffer -= min_val
self.buffer /= max_val - min_val
def re_normalize(self):
if self.is_normalized:
return
self.__normalize()
self.update_from_buffer(self.buffer)
self.__stats_calc()
self.is_normalized = True
def update_from_values(self, new_values: np.ndarray):
self.values = new_values
self.buffer = np.ravel(new_values)
self.is_normalized = False
def update_from_buffer(self, new_buffer: np.array):
self.buffer = new_buffer
header = self.header
self.values = np.ndarray((header.fields["NS"], header.fields["NR"], header.fields["NC"]), 'f4',
buffer=self.buffer)
self.is_normalized = False