Skip to content

Commit f712ba9

Browse files
committed
Restoring OP quality functionality (still not working)
1 parent 649025b commit f712ba9

3 files changed

Lines changed: 15 additions & 16 deletions

File tree

src/fairmd/lipids/bin/evaluate_quality.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ def _evaluate_op_qualities(simulations) -> int:
6565
fragment_qual_dict = {}
6666
data_dict = {}
6767

68-
for expid in simulation["EXPERIMENT"]["ORDERPARAMETER"][lipid1]:
68+
for expid in simulation["EXPERIMENT"]["ORDERPARAMETER"].get(lipid1, []):
6969
print(
7070
f"Evaluating {lipid1} lipid using experimental data from {expid}",
7171
)
7272
OP_qual_data = {}
73-
exp_lipid_ops = opexps.loc(expid)
73+
exp_lipid_ops = opexps.loc(expid).data[lipid1]
7474
exp_error = 0.02
7575

7676
for key, op_array_ in md_lipid_ops.items():
7777
OP_array = op_array_.copy()
78-
try:
79-
OP_exp = exp_lipid_ops[key][0][0]
78+
try: # TODO: very bad! must remove TRY-EXCEPT BLOCK
79+
OP_exp = exp_lipid_ops[key][0]
8080
except KeyError:
8181
continue
8282
else:
@@ -144,7 +144,7 @@ def _evaluate_op_qualities(simulations) -> int:
144144
_round_quality_values(system_qual_output)
145145
with open(outfile2, "w") as f:
146146
json.dump(system_qual_output, f)
147-
print("Order parameter quality evaluated for " + simulation.idx_path)
147+
print("Order parameter quality evaluated for " + simulation["path"])
148148
counter += 1
149149
print()
150150
return counter
@@ -195,10 +195,10 @@ def _evaluate_ff_qualities(simulations) -> int:
195195
def evaluate_quality():
196196
simulations = qq.QualSimulation.load_all_paired()
197197

198-
# evaluated_op_counter = _evaluate_op_qualities(simulations)
198+
evaluated_op_counter = _evaluate_op_qualities(simulations)
199199
evaluated_ff_counter = _evaluate_ff_qualities(simulations)
200200

201-
# print("The number of systems with evaluated order parameters:", evaluated_op_counter)
201+
print("The number of systems with evaluated order parameters:", evaluated_op_counter)
202202
print("The number of systems with evaluated form factors:", evaluated_ff_counter)
203203

204204

src/fairmd/lipids/quality.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
TODO: remove code duplication and commented code
55
"""
66

7-
import decimal as dc
87
import re
98
import warnings
109

@@ -84,7 +83,7 @@ def prob_op_within_trustinterval(
8483

8584

8685
# quality of molecule fragments
87-
def get_fragments(mapping_dict: dict):
86+
def get_fragments(mapping_dict: dict) -> dict:
8887
fragments = {}
8988

9089
for key_m, value in mapping_dict.items():
@@ -124,7 +123,7 @@ def evaluated_percentage(fragments, exp_op_data):
124123
for key, value in exp_op_data.items():
125124
if key.split(" ")[0] in fragments[fragment_key]: # check if atom belongs to the fragment
126125
fragment_size += 1
127-
if not np.isnan(value[0][0]):
126+
if not np.isnan(value[0]):
128127
count_value += 1
129128
if fragment_size != 0:
130129
frag_percentage[fragment_key] = count_value / fragment_size
@@ -137,7 +136,7 @@ def evaluated_percentage(fragments, exp_op_data):
137136
return frag_percentage
138137

139138

140-
def fragmentQuality(fragments, exp_op_data, sim_op_data):
139+
def fragmentQuality(fragments: dict, exp_op_data: dict, sim_op_data: dict):
141140
# depends on the experiment file what fragments are in this dictionary
142141
p_F = evaluated_percentage(fragments, exp_op_data)
143142
exp_error = 0.02
@@ -156,8 +155,8 @@ def fragmentQuality(fragments, exp_op_data, sim_op_data):
156155
else:
157156
if p_F[fragment_key] != 0:
158157
for key_exp, value_exp in exp_op_data.items():
159-
if key_exp.split()[0] in fragments[fragment_key] and not np.isnan(value_exp[0][0]):
160-
OP_exp = value_exp[0][0]
158+
if key_exp.split()[0] in fragments[fragment_key] and not np.isnan(value_exp[0]):
159+
OP_exp = value_exp[0]
161160
try:
162161
OP_sim = sim_op_data[key_exp][0]
163162
except (KeyError, TypeError):
@@ -242,7 +241,7 @@ def fragmentQualityAvg(
242241

243242

244243
# fragments is different for each lipid ---> need to make individual dictionaries
245-
def systemQuality(system_fragment_qualities, simulation):
244+
def systemQuality(system_fragment_qualities, simulation: QualSimulation):
246245
system_dict = {}
247246
lipid_dict = {}
248247
w_nan = []
@@ -251,7 +250,7 @@ def systemQuality(system_fragment_qualities, simulation):
251250
# copy keys to new dictionary
252251
lipid_dict = dict.fromkeys(system_fragment_qualities[lipid].keys(), 0)
253252

254-
w = simulation.molar_fraction(lipid)
253+
w = simulation.membrane_composition(basis="molar")[lipid]
255254

256255
for key, value in system_fragment_qualities[lipid].items():
257256
if not np.isnan(value):

tests/test_quality.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# run only on sim2 mocking data
2020
pytestmark = [pytest.mark.nodata, pytest.mark.min]
2121

22+
2223
def test_prob_op_within_trustinterval():
2324
from fairmd.lipids.quality import prob_op_within_trustinterval
2425

@@ -47,4 +48,3 @@ def test_prob_op_within_trustinterval():
4748

4849
p2 = prob_op_within_trustinterval(op_exp, exp_error, op_sim, op_sim_sd)
4950
npt.assert_allclose(p2, [0.505148, np.nan, 0.526465], atol=1e-6)
50-

0 commit comments

Comments
 (0)