@@ -27,6 +27,26 @@ def shared_data_base():
2727 }
2828
2929
30+ @pytest .fixture ()
31+ def shared_groups ():
32+ frag = MagicMock ()
33+ frag .residues = [MagicMock (resname = "RES" )]
34+ ru = MagicMock ()
35+ ru .atoms .fragments = [frag ]
36+
37+ return {
38+ "run_manager" : MagicMock (),
39+ "args" : SimpleNamespace (temperature = 298.0 , combined_forcetorque = False ),
40+ "groups" : {5 : [0 ]},
41+ "levels" : {0 : ["united_atom" ]},
42+ "reduced_universe" : ru ,
43+ "force_covariances" : {"ua" : {}, "res" : [], "poly" : []},
44+ "torque_covariances" : {"ua" : {}, "res" : [], "poly" : []},
45+ "n_frames" : 5 ,
46+ "reporter" : MagicMock (),
47+ }
48+
49+
3050def test_united_atom_branch_logs_and_stores (shared_data_base , monkeypatch ):
3151 node = VibrationalEntropyNode ()
3252
@@ -172,3 +192,175 @@ def test_polymer_branch_executes(shared_data, monkeypatch):
172192 assert "vibrational_entropy" in out
173193 assert out ["vibrational_entropy" ][0 ]["polymer" ]["trans" ] == 1.0
174194 assert out ["vibrational_entropy" ][0 ]["polymer" ]["rot" ] == 1.0
195+
196+
197+ def test_run_skips_empty_mol_ids_group ():
198+ node = VibrationalEntropyNode ()
199+
200+ shared_groups = {
201+ "run_manager" : MagicMock (),
202+ "args" : SimpleNamespace (temperature = 298.0 , combined_forcetorque = False ),
203+ "groups" : {0 : []},
204+ "levels" : {0 : ["united_atom" ]},
205+ "reduced_universe" : MagicMock (atoms = MagicMock (fragments = [])),
206+ "force_covariances" : {"ua" : {}, "res" : [], "poly" : []},
207+ "torque_covariances" : {"ua" : {}, "res" : [], "poly" : []},
208+ "n_frames" : 5 ,
209+ "reporter" : None ,
210+ }
211+
212+ out = node .run (shared_groups )
213+ assert "vibrational_entropy" in out
214+ assert out ["vibrational_entropy" ][0 ] == {}
215+
216+
217+ def test_get_ua_frame_counts_falls_back_to_empty_when_shape_wrong ():
218+ node = VibrationalEntropyNode ()
219+ assert node ._get_ua_frame_counts ({"frame_counts" : "not-a-dict" }) == {}
220+
221+
222+ def test_compute_united_atom_entropy_logs_residue_data_when_reporter_present ():
223+ node = VibrationalEntropyNode ()
224+ ve = MagicMock ()
225+
226+ node ._compute_force_torque_entropy = MagicMock (return_value = EntropyPair (1.0 , 2.0 ))
227+
228+ reporter = MagicMock ()
229+ residues = [SimpleNamespace (resname = "A" ), SimpleNamespace (resname = "B" )]
230+
231+ out = node ._compute_united_atom_entropy (
232+ ve = ve ,
233+ temp = 298.0 ,
234+ group_id = 7 ,
235+ residues = residues ,
236+ force_ua = {},
237+ torque_ua = {},
238+ ua_frame_counts = {(7 , 0 ): 3 , (7 , 1 ): 4 },
239+ reporter = reporter ,
240+ n_frames_default = 10 ,
241+ highest = True ,
242+ )
243+
244+ assert out == EntropyPair (trans = 2.0 , rot = 4.0 )
245+ assert reporter .add_residue_data .call_count == 4
246+
247+
248+ def test_compute_force_torque_entropy_success_calls_vibrational_engine ():
249+ node = VibrationalEntropyNode ()
250+ ve = MagicMock ()
251+ ve .vibrational_entropy_calculation .side_effect = [10.0 , 20.0 ]
252+
253+ out = node ._compute_force_torque_entropy (
254+ ve = ve ,
255+ temp = 298.0 ,
256+ fmat = np .eye (3 ),
257+ tmat = np .eye (3 ),
258+ highest = False ,
259+ )
260+
261+ assert out == EntropyPair (trans = 10.0 , rot = 20.0 )
262+ assert ve .vibrational_entropy_calculation .call_count == 2
263+
264+
265+ def test_compute_ft_entropy_success_calls_vibrational_engine_for_trans_and_rot ():
266+ node = VibrationalEntropyNode ()
267+ ve = MagicMock ()
268+ ve .vibrational_entropy_calculation .side_effect = [1.5 , 2.5 ]
269+
270+ out = node ._compute_ft_entropy (ve = ve , temp = 298.0 , ftmat = np .eye (6 ))
271+
272+ assert out == EntropyPair (trans = 1.5 , rot = 2.5 )
273+ assert ve .vibrational_entropy_calculation .call_count == 2
274+
275+
276+ def test_log_molecule_level_results_returns_when_reporter_none ():
277+ VibrationalEntropyNode ._log_molecule_level_results (
278+ reporter = None ,
279+ group_id = 1 ,
280+ level = "residue" ,
281+ pair = EntropyPair (1.0 , 2.0 ),
282+ use_ft_labels = False ,
283+ )
284+
285+
286+ def test_log_molecule_level_results_writes_trans_and_rot_labels ():
287+ reporter = MagicMock ()
288+ VibrationalEntropyNode ._log_molecule_level_results (
289+ reporter = reporter ,
290+ group_id = 1 ,
291+ level = "residue" ,
292+ pair = EntropyPair (3.0 , 4.0 ),
293+ use_ft_labels = False ,
294+ )
295+
296+ reporter .add_results_data .assert_any_call (1 , "residue" , "Transvibrational" , 3.0 )
297+ reporter .add_results_data .assert_any_call (1 , "residue" , "Rovibrational" , 4.0 )
298+
299+
300+ def test_get_group_id_to_index_builds_from_groups (shared_groups ):
301+ node = VibrationalEntropyNode ()
302+ gid2i = node ._get_group_id_to_index (shared_groups )
303+ assert gid2i == {5 : 0 }
304+
305+
306+ def test_get_ua_frame_counts_returns_empty_when_missing (shared_groups ):
307+ node = VibrationalEntropyNode ()
308+ assert node ._get_ua_frame_counts (shared_groups ) == {}
309+
310+
311+ def test_compute_force_torque_entropy_returns_zero_when_missing_matrix (shared_groups ):
312+ node = VibrationalEntropyNode ()
313+ ve = MagicMock ()
314+ pair = node ._compute_force_torque_entropy (
315+ ve = ve , temp = 298.0 , fmat = None , tmat = np .eye (3 ), highest = True
316+ )
317+ assert pair == EntropyPair (trans = 0.0 , rot = 0.0 )
318+
319+
320+ def test_compute_force_torque_entropy_returns_zero_when_filter_removes_all (monkeypatch ):
321+ node = VibrationalEntropyNode ()
322+ ve = MagicMock ()
323+
324+ monkeypatch .setattr (
325+ node ._mat_ops , "filter_zero_rows_columns" , lambda a , atol : np .array ([])
326+ )
327+
328+ pair = node ._compute_force_torque_entropy (
329+ ve = ve , temp = 298.0 , fmat = np .eye (3 ), tmat = np .eye (3 ), highest = True
330+ )
331+ assert pair == EntropyPair (trans = 0.0 , rot = 0.0 )
332+
333+
334+ def test_compute_ft_entropy_returns_zero_when_none ():
335+ node = VibrationalEntropyNode ()
336+ ve = MagicMock ()
337+ assert node ._compute_ft_entropy (ve = ve , temp = 298.0 , ftmat = None ) == EntropyPair (
338+ trans = 0.0 , rot = 0.0
339+ )
340+
341+
342+ def test_log_molecule_level_results_ft_labels_branch ():
343+ node = VibrationalEntropyNode ()
344+ reporter = MagicMock ()
345+
346+ node ._log_molecule_level_results (
347+ reporter , 1 , "residue" , EntropyPair (1.0 , 2.0 ), use_ft_labels = True
348+ )
349+
350+ reporter .add_results_data .assert_any_call (
351+ 1 , "residue" , "FTmat-Transvibrational" , 1.0
352+ )
353+ reporter .add_results_data .assert_any_call (1 , "residue" , "FTmat-Rovibrational" , 2.0 )
354+
355+
356+ def test_get_indexed_matrix_out_of_range_returns_none ():
357+ node = VibrationalEntropyNode ()
358+ assert node ._get_indexed_matrix ([np .eye (3 )], 5 ) is None
359+
360+
361+ def test_run_unknown_level_raises (shared_groups ):
362+ node = VibrationalEntropyNode ()
363+ shared_groups ["levels" ] = {0 : ["nope" ]}
364+
365+ with pytest .raises (ValueError ):
366+ node .run (shared_groups )
0 commit comments