From ee3d4cc0bf4fd6566b5d2df2e6c457047a1c78f3 Mon Sep 17 00:00:00 2001 From: Brady Johnston Date: Tue, 11 Jun 2024 14:24:16 +0800 Subject: [PATCH 1/3] fix typo in MDA Universe loading --- molecularnodes/io/md.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/molecularnodes/io/md.py b/molecularnodes/io/md.py index ec931687..8e431473 100644 --- a/molecularnodes/io/md.py +++ b/molecularnodes/io/md.py @@ -82,7 +82,9 @@ def load( custom_selections: dict = {}, in_memory: bool = False, ): - universe = mda.Universe(topology=path_resolve(top), coordinate=path_resolve(traj)) + top = path_resolve(top) + traj = path_resolve(traj) + universe = mda.Universe(top, traj) if in_memory: universe.transfer_to_memory(start=start, step=step, stop=stop) From 363bd1dc44db5731967577de3afe0538719eb6d6 Mon Sep 17 00:00:00 2001 From: Brady Johnston Date: Tue, 11 Jun 2024 14:38:28 +0800 Subject: [PATCH 2/3] add test that would previous fail Test would fail if trajectory doesn't update positions --- tests/test_ops.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/test_ops.py b/tests/test_ops.py index 13fc1f98..6ce5d36d 100644 --- a/tests/test_ops.py +++ b/tests/test_ops.py @@ -2,7 +2,7 @@ import pytest import numpy as np import molecularnodes as mn -from molecularnodes.blender.obj import ObjectTracker +from molecularnodes.blender.obj import ObjectTracker, get_attribute from .utils import sample_attribute, NumpySnapshotExtension from .constants import data_dir, codes, attributes @@ -90,10 +90,21 @@ def test_op_api_mda(snapshot_custom: NumpySnapshotExtension): name = "NewTrajectoryInMemory" obj_2, universe = mn.io.md.load(topo, traj, name="test", style="ribbon") - frames_coll = bpy.data.collections.get(f"{obj_2.name}_frames") - assert not frames_coll + # test the 'frames' collection doesn't exist, as it should only be created when reading + # into memory + assert not bpy.data.collections.get(f"{obj_2.name}_frames") for mol in [obj_1, obj_2]: for att in attributes: assert snapshot_custom == sample_attribute(mol, att) + + # capture positions, change the frame number and test that the positions have updated + # and cahnged + pos_1, pos_2 = [get_attribute(x, "position") for x in [obj_1, obj_2]] + bpy.context.scene.frame_set(4) + + assert not np.allclose(get_attribute(obj_1, "position"), pos_1) + assert np.allclose( + get_attribute(obj_1, "position"), get_attribute(obj_2, "position") + ) From da09aa0540155b541c3fc8dfc4da59cbaf844013 Mon Sep 17 00:00:00 2001 From: Brady Johnston Date: Tue, 11 Jun 2024 14:43:56 +0800 Subject: [PATCH 3/3] update snapshot --- tests/__snapshots__/test_ops.ambr | 108 +++++++++++++++--------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/tests/__snapshots__/test_ops.ambr b/tests/__snapshots__/test_ops.ambr index c21447af..e74455fa 100644 --- a/tests/__snapshots__/test_ops.ambr +++ b/tests/__snapshots__/test_ops.ambr @@ -2970,12 +2970,12 @@ # --- # name: test_op_api_mda.14 [[0.5 0.5 0.3] - [1.2 0.3 0.8] - [0.9 0.3 0.5] + [1.2 0.2 0.7] + [0.9 0.2 0.5] [0.6 0.3 0.5] [0.4 0.3 0.5] [0.7 0.5 0.6] - [1.3 0.4 0.7] + [1.3 0.3 0.7] [1.0 0.6 0.5] [1.0 0.4 0.4] [0.4 0.2 0.4] @@ -2988,9 +2988,9 @@ [1.0 0.3 0.5] [0.6 0.5 0.4] [1.1 0.6 0.7] - [1.0 0.4 0.4] + [1.0 0.5 0.3] [0.7 0.5 0.5] - [1.1 0.6 0.5] + [1.1 0.6 0.4] [1.2 0.5 0.6] [0.9 0.2 0.6] [1.3 0.5 0.7] @@ -3000,14 +3000,14 @@ [0.8 0.5 0.4] [0.6 0.3 0.3] [0.7 0.3 0.7] - [1.2 0.6 0.4] - [1.2 0.3 0.7] + [1.1 0.6 0.4] + [1.1 0.3 0.7] [0.7 0.4 0.8] [1.0 0.4 0.5] [0.5 0.4 0.5] [0.5 0.3 0.4] - [1.1 0.6 0.4] - [1.0 0.2 0.6] + [1.1 0.5 0.4] + [0.9 0.2 0.6] [1.1 0.5 0.7] [1.0 0.3 0.4] [1.2 0.5 0.4] @@ -3016,12 +3016,12 @@ [1.4 0.3 0.6] [0.7 0.4 0.7] [0.6 0.5 0.5] - [1.0 0.3 0.5] + [1.0 0.2 0.5] [0.9 0.3 0.3] [0.7 0.4 0.8] [1.1 0.5 0.5] [1.2 0.2 0.7] - [0.8 0.3 0.8] + [0.8 0.3 0.7] [0.6 0.6 0.6] [0.9 0.4 0.7] [0.6 0.2 0.5] @@ -3029,45 +3029,45 @@ [0.6 0.5 0.7] [0.5 0.2 0.5] [1.1 0.4 0.4] - [1.0 0.3 0.3] - [1.0 0.5 0.6] - [1.1 0.6 0.5] + [1.0 0.3 0.4] + [1.0 0.5 0.5] + [1.1 0.5 0.5] [1.2 0.6 0.5] - [0.9 0.3 0.4] + [0.9 0.4 0.4] [0.8 0.6 0.5] [1.2 0.3 0.6] [0.4 0.4 0.3] [0.9 0.5 0.7] [1.2 0.5 0.7] - [1.1 0.6 0.6] + [1.1 0.7 0.6] [0.7 0.5 0.4] - [1.3 0.4 0.7] - [1.0 0.2 0.6] + [1.3 0.5 0.7] + [0.9 0.2 0.6] [0.6 0.5 0.4] [1.3 0.4 0.7] - [1.3 0.4 0.8] - [1.1 0.5 0.5] + [1.3 0.5 0.8] + [1.1 0.6 0.5] [0.6 0.5 0.4] [1.1 0.5 0.6] - [1.1 0.6 0.8] - [1.3 0.4 0.7] + [1.1 0.5 0.8] + [1.4 0.3 0.7] [1.0 0.3 0.4] [1.2 0.5 0.6] - [0.6 0.5 0.5] + [0.5 0.5 0.5] [0.8 0.4 0.8] - [1.0 0.3 0.5] - [1.2 0.4 0.8] + [0.9 0.3 0.5] + [1.2 0.4 0.7] [1.2 0.3 0.7] [0.7 0.4 0.7] [0.5 0.2 0.5] [0.4 0.2 0.4] [0.7 0.6 0.5] [0.9 0.2 0.6] - [1.1 0.5 0.4] + [1.1 0.6 0.4] [0.8 0.4 0.8] [0.8 0.2 0.6] [0.5 0.4 0.5] - [1.2 0.4 0.8] + [1.2 0.4 0.7] [1.1 0.4 0.4]] # --- # name: test_op_api_mda.15 @@ -3318,12 +3318,12 @@ # --- # name: test_op_api_mda.38 [[0.5 0.5 0.3] - [1.2 0.3 0.8] - [0.9 0.3 0.5] + [1.2 0.2 0.7] + [0.9 0.2 0.5] [0.6 0.3 0.5] [0.4 0.3 0.5] [0.7 0.5 0.6] - [1.3 0.4 0.7] + [1.3 0.3 0.7] [1.0 0.6 0.5] [1.0 0.4 0.4] [0.4 0.2 0.4] @@ -3336,9 +3336,9 @@ [1.0 0.3 0.5] [0.6 0.5 0.4] [1.1 0.6 0.7] - [1.0 0.4 0.4] + [1.0 0.5 0.3] [0.7 0.5 0.5] - [1.1 0.6 0.5] + [1.1 0.6 0.4] [1.2 0.5 0.6] [0.9 0.2 0.6] [1.3 0.5 0.7] @@ -3348,14 +3348,14 @@ [0.8 0.5 0.4] [0.6 0.3 0.3] [0.7 0.3 0.7] - [1.2 0.6 0.4] - [1.2 0.3 0.7] + [1.1 0.6 0.4] + [1.1 0.3 0.7] [0.7 0.4 0.8] [1.0 0.4 0.5] [0.5 0.4 0.5] [0.5 0.3 0.4] - [1.1 0.6 0.4] - [1.0 0.2 0.6] + [1.1 0.5 0.4] + [0.9 0.2 0.6] [1.1 0.5 0.7] [1.0 0.3 0.4] [1.2 0.5 0.4] @@ -3364,12 +3364,12 @@ [1.4 0.3 0.6] [0.7 0.4 0.7] [0.6 0.5 0.5] - [1.0 0.3 0.5] + [1.0 0.2 0.5] [0.9 0.3 0.3] [0.7 0.4 0.8] [1.1 0.5 0.5] [1.2 0.2 0.7] - [0.8 0.3 0.8] + [0.8 0.3 0.7] [0.6 0.6 0.6] [0.9 0.4 0.7] [0.6 0.2 0.5] @@ -3377,45 +3377,45 @@ [0.6 0.5 0.7] [0.5 0.2 0.5] [1.1 0.4 0.4] - [1.0 0.3 0.3] - [1.0 0.5 0.6] - [1.1 0.6 0.5] + [1.0 0.3 0.4] + [1.0 0.5 0.5] + [1.1 0.5 0.5] [1.2 0.6 0.5] - [0.9 0.3 0.4] + [0.9 0.4 0.4] [0.8 0.6 0.5] [1.2 0.3 0.6] [0.4 0.4 0.3] [0.9 0.5 0.7] [1.2 0.5 0.7] - [1.1 0.6 0.6] + [1.1 0.7 0.6] [0.7 0.5 0.4] - [1.3 0.4 0.7] - [1.0 0.2 0.6] + [1.3 0.5 0.7] + [0.9 0.2 0.6] [0.6 0.5 0.4] [1.3 0.4 0.7] - [1.3 0.4 0.8] - [1.1 0.5 0.5] + [1.3 0.5 0.8] + [1.1 0.6 0.5] [0.6 0.5 0.4] [1.1 0.5 0.6] - [1.1 0.6 0.8] - [1.3 0.4 0.7] + [1.1 0.5 0.8] + [1.4 0.3 0.7] [1.0 0.3 0.4] [1.2 0.5 0.6] - [0.6 0.5 0.5] + [0.5 0.5 0.5] [0.8 0.4 0.8] - [1.0 0.3 0.5] - [1.2 0.4 0.8] + [0.9 0.3 0.5] + [1.2 0.4 0.7] [1.2 0.3 0.7] [0.7 0.4 0.7] [0.5 0.2 0.5] [0.4 0.2 0.4] [0.7 0.6 0.5] [0.9 0.2 0.6] - [1.1 0.5 0.4] + [1.1 0.6 0.4] [0.8 0.4 0.8] [0.8 0.2 0.6] [0.5 0.4 0.5] - [1.2 0.4 0.8] + [1.2 0.4 0.7] [1.1 0.4 0.4]] # --- # name: test_op_api_mda.39