Skip to content

Commit 52ebae5

Browse files
authored
Modify apl storage (#467)
* change apl.json storage format * added get_density API. Refactor APIs via _get_2d_array
1 parent 2046184 commit 52ebae5

7 files changed

Lines changed: 2648 additions & 2599 deletions

File tree

src/fairmd/lipids/api.py

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@
4141

4242
logger = logging.getLogger(__name__)
4343

44+
__all__ = [
45+
"UniverseConstructError",
46+
"UniverseConstructor",
47+
"get_ApL_data",
48+
"get_FF",
49+
"get_OP",
50+
"get_eqtimes",
51+
"get_mean_ApL",
52+
"get_thickness",
53+
"get_total_area",
54+
"mda_gen_selection_mols",
55+
"mda_read_trj_tilt_angles",
56+
]
57+
4458

4559
def get_thickness(system: System) -> float:
4660
"""
@@ -124,17 +138,17 @@ def get_OP(system: System) -> dict: # noqa: N802 (API name)
124138
return sim_op_data
125139

126140

127-
def get_FF(system: System) -> np.ndarray: # noqa: N802 (API name)
128-
"""
129-
Get numpy table of FormFactor curve.
141+
def _get_2d_array(system: System, fname: str) -> np.ndarray:
142+
"""Get whatever 2D array stored in the DB.
130143
131144
:param system: Simulation object
132-
:return: (q,FF,err) numpy table
145+
:param fname: Filename (str)
146+
:return: numpy table
133147
"""
134148
fn = os.path.join(
135149
FMDL_SIMU_PATH,
136150
system["path"],
137-
"FormFactor.json",
151+
fname,
138152
)
139153
try:
140154
with open(fn) as json_file:
@@ -148,6 +162,33 @@ def get_FF(system: System) -> np.ndarray: # noqa: N802 (API name)
148162
return np.array(sim_ff_data)
149163

150164

165+
def get_FF(system: System) -> np.ndarray: # noqa: N802 (API name)
166+
"""
167+
Get numpy table of FormFactor curve.
168+
169+
:param system: Simulation object
170+
:return: (q,FF,err) numpy table
171+
"""
172+
return _get_2d_array(system, "FormFactor.json")
173+
174+
175+
def get_density(system: System, domain: str = "total") -> np.ndarray:
176+
"""Get numpy table of electron density.
177+
178+
:param system: Simulation object
179+
:param domain: total|water|lipids
180+
:return: (z,edens,err) array
181+
"""
182+
if domain == "total":
183+
return _get_2d_array(system, "TotalDensity.json")
184+
if domain == "lipids":
185+
return _get_2d_array(system, "LipidDensity.json")
186+
if domain == "water":
187+
return _get_2d_array(system, "WaterDensity.json")
188+
msg = f"get_density supports only total/lipids/water for domain. Got {domain}!"
189+
raise ValueError(msg)
190+
191+
151192
def get_quality(
152193
system: System,
153194
*,
@@ -228,22 +269,7 @@ def get_ApL_data(system: System, blocksize: float | None = None) -> np.ndarray:
228269
229270
:return: Array (t, value) with blocksize step.
230271
"""
231-
path = os.path.join(FMDL_SIMU_PATH, system["path"], "apl.json")
232-
try:
233-
with open(path) as f:
234-
data = json.load(f)
235-
except FileNotFoundError as e:
236-
msg = "Area per lipid data is absent for system #{}".format(system["ID"])
237-
raise FileNotFoundError(msg) from e
238-
except json.JSONDecodeError as e:
239-
msg = "Area per lipid data for system #{} in {} is invalid.".format(system["ID"], path)
240-
raise ValueError(msg) from e
241-
df = np.vstack(
242-
[
243-
np.array(list(data.keys()), dtype=float),
244-
np.array(list(data.values()), dtype=float),
245-
]
246-
).T
272+
df = _get_2d_array(system, "apl.json")
247273
if blocksize is not None:
248274
df = block_average_time_series(df, blocksize)
249275
return df
@@ -501,6 +527,3 @@ def _calc_angle(atoms, com) -> float:
501527
total_std_error = np.std(res_aver_angles) / np.sqrt(n_res)
502528

503529
return angles, res_aver_angles, total_average, total_std_error
504-
505-
506-
# -------------------------------------- SEPARATED PART (??) ----------------------
Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
{
2-
"60000.0": 62.3387,
3-
"61000.0": 60.6071,
4-
"62000.0": 60.7738,
5-
"63000.0": 59.056,
6-
"64000.0": 61.4985,
7-
"65000.0": 60.831,
8-
"66000.0": 61.8798,
9-
"67000.0": 64.3751,
10-
"68000.0": 63.6739,
11-
"69000.0": 63.2019,
12-
"70000.0": 60.8984,
13-
"71000.0": 61.4965,
14-
"72000.0": 63.0552,
15-
"73000.0": 59.8782,
16-
"74000.0": 61.5304,
17-
"75000.0": 60.3324,
18-
"76000.0": 61.3011,
19-
"77000.0": 61.1636,
20-
"78000.0": 62.4852,
21-
"79000.0": 62.0598,
22-
"80000.0": 59.6043,
23-
"81000.0": 60.5554,
24-
"82000.0": 62.8882,
25-
"83000.0": 61.6771,
26-
"84000.0": 62.433,
27-
"85000.0": 60.9198,
28-
"86000.0": 62.0261,
29-
"87000.0": 60.7963,
30-
"88000.0": 61.5493,
31-
"89000.0": 61.2126,
32-
"90000.0": 63.1706,
33-
"91000.0": 62.6851,
34-
"92000.0": 65.1915,
35-
"93000.0": 65.3858,
36-
"94000.0": 63.5872,
37-
"95000.0": 63.9936,
38-
"96000.0": 60.5771,
39-
"97000.0": 61.287,
40-
"98000.0": 65.9468,
41-
"99000.0": 63.2794,
42-
"100000.0": 62.5221,
43-
"101000.0": 64.232,
44-
"102000.0": 63.3142,
45-
"103000.0": 62.0184,
46-
"104000.0": 59.7271,
47-
"105000.0": 62.6882,
48-
"106000.0": 62.7182,
49-
"107000.0": 62.3648,
50-
"108000.0": 62.0113,
51-
"109000.0": 61.7691,
52-
"110000.0": 61.9481,
53-
"111000.0": 61.9454,
54-
"112000.0": 61.1225,
55-
"113000.0": 63.7765,
56-
"114000.0": 62.4307,
57-
"115000.0": 62.0906,
58-
"116000.0": 63.5254,
59-
"117000.0": 61.5683,
60-
"118000.0": 66.3872,
61-
"119000.0": 65.4874,
62-
"120000.0": 63.9594
63-
}
1+
[
2+
[60000, 62.3387],
3+
[61000, 60.6071],
4+
[62000, 60.7738],
5+
[63000, 59.056],
6+
[64000, 61.4985],
7+
[65000, 60.831],
8+
[66000, 61.8798],
9+
[67000, 64.3751],
10+
[68000, 63.6739],
11+
[69000, 63.2019],
12+
[70000, 60.8984],
13+
[71000, 61.4965],
14+
[72000, 63.0552],
15+
[73000, 59.8782],
16+
[74000, 61.5304],
17+
[75000, 60.3324],
18+
[76000, 61.3011],
19+
[77000, 61.1636],
20+
[78000, 62.4852],
21+
[79000, 62.0598],
22+
[80000, 59.6043],
23+
[81000, 60.5554],
24+
[82000, 62.8882],
25+
[83000, 61.6771],
26+
[84000, 62.433],
27+
[85000, 60.9198],
28+
[86000, 62.0261],
29+
[87000, 60.7963],
30+
[88000, 61.5493],
31+
[89000, 61.2126],
32+
[90000, 63.1706],
33+
[91000, 62.6851],
34+
[92000, 65.1915],
35+
[93000, 65.3858],
36+
[94000, 63.5872],
37+
[95000, 63.9936],
38+
[96000, 60.5771],
39+
[97000, 61.287],
40+
[98000, 65.9468],
41+
[99000, 63.2794],
42+
[100000, 62.5221],
43+
[101000, 64.232],
44+
[102000, 63.3142],
45+
[103000, 62.0184],
46+
[104000, 59.7271],
47+
[105000, 62.6882],
48+
[106000, 62.7182],
49+
[107000, 62.3648],
50+
[108000, 62.0113],
51+
[109000, 61.7691],
52+
[110000, 61.9481],
53+
[111000, 61.9454],
54+
[112000, 61.1225],
55+
[113000, 63.7765],
56+
[114000, 62.4307],
57+
[115000, 62.0906],
58+
[116000, 63.5254],
59+
[117000, 61.5683],
60+
[118000, 66.3872],
61+
[119000, 65.4874],
62+
[120000, 63.9594]
63+
]

0 commit comments

Comments
 (0)