@@ -60,44 +60,30 @@ def _evaluate_op_qualities(simulations) -> int:
6060 for lipidname , lipid in simulation .lipids .items ():
6161 md_lipid_ops = simulation .op_data [lipidname ]
6262
63+ # TODO: bb is merged into headgroup. But sn-s do not.. Cryptic rule.
64+ # TODO: What to do with other types of lipids?
6365 fragments = mollib .get_fragments (lipid .mapping_dict )
64- fragment_qual_dict = {}
65- data_dict = {}
66+ fragment_qual_perexp = {}
67+ lipid_quality_perexp = {}
68+ lipid_quality_perexp = {}
6669
6770 for expid in simulation ["EXPERIMENT" ]["ORDERPARAMETER" ].get (lipidname , []):
6871 print (f"OP quality of simulation data in { simulation ['path' ]} " )
6972 print (
7073 f".. evaluating { lipidname } lipid using experimental data from { expid } " ,
7174 )
72- OP_qual_data = {}
7375 exp_lipid_ops = opexps .loc (expid ).data [lipidname ]
74- exp_error = 0.02 # TODO: hardcoded error value, should be taken from experiment data when available
75-
76- for key , op_array_ in md_lipid_ops .items ():
77- OP_array = op_array_ .copy ()
78- if key not in exp_lipid_ops :
79- continue
80- OP_exp_val = exp_lipid_ops [key ][0 ]
81- if not np .isnan (OP_exp_val ):
82- op_quality = qq .prob_op_within_trustinterval (
83- op_exp = OP_exp_val ,
84- exp_error = exp_error ,
85- op_sim = OP_array [0 ],
86- op_sim_sd = OP_array [2 ],
87- )
88- OP_array += [OP_exp_val , exp_error , op_quality ]
89- OP_qual_data [key ] = OP_array
90-
9176 # save qualities of simulation-vs-experiment into a dictionary
92- data_dict [expid ] = OP_qual_data
77+ lipid_quality_perexp [expid ] = qq . atomic_quality ( exp_lipid_ops , md_lipid_ops )
9378
9479 # calculate quality for molecule fragments headgroup, sn-1, sn-2
95- # TODO: bb is merged into headgroup. But sn-s do not.. Cryptic rule.
96- # TODO: What to do with other types of lipids?
97- fragment_qual_dict [expid ] = qq .fragment_quality (fragments , exp_lipid_ops , md_lipid_ops )
80+ _frq = qq .atomic2fragment_quality (lipid_quality_perexp [expid ], fragments )
81+ _frw = qq .weights_of_fragments_in_data (fragments , exp_lipid_ops )
82+ # dot product [ qualities * weights ]
83+ fragment_qual_perexp [expid ] = {k : _frq [k ] * _frw [k ] for k in fragments }
9884
9985 # Experiment-merged fragment quality for the lipid
100- fragment_quality_merged = qq .fragment_quality_unite_multexp (lipidname , fragment_qual_dict , fragments )
86+ fragment_quality_merged = qq .fragment_quality_unite_multexp (lipidname , fragment_qual_perexp , fragments )
10187 system_quality [lipidname ] = fragment_quality_merged
10288
10389 # Write FQ for the lipid
@@ -116,9 +102,9 @@ def _evaluate_op_qualities(simulations) -> int:
116102
117103 # write into the OrderParameters_quality.json quality data file
118104 outfile1 = os .path .join (wdir , lipidname + "_OrderParameters_quality.json" )
119- _round_quality_values (data_dict )
105+ _round_quality_values (lipid_quality_perexp )
120106 with open (outfile1 , "w" ) as f :
121- json .dump (data_dict , f , cls = CompactJSONEncoder )
107+ json .dump (lipid_quality_perexp , f , cls = CompactJSONEncoder )
122108
123109 system_qual_output = qq .systemQuality (system_quality , simulation )
124110 # make system quality file
0 commit comments