Skip to content

Commit

Permalink
Add setter for colors property (#58)
Browse files Browse the repository at this point in the history
* set a heigh multiplier

* only use hidden height factor attr in default height method

* fix camera position buffer

* remove buffer from camera position

* add unit test for camera pos

* simplify colors property

* add unit test for setting colors

* test setter
  • Loading branch information
chrisjonesBSU authored Sep 19, 2023
1 parent d13ab94 commit 6b83bc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions cmeutils/tests/test_visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def test_color_dict(self, p3ht_fresnel):
)
p3ht_fresnel.view()

def test_camera_position(self, p3ht_fresnel):
init_pos = p3ht_fresnel.camera_position
p3ht_fresnel.view_axis = (1, 1, 0)
assert not all(np.not_equal(init_pos, p3ht_fresnel.camera_position))
box = p3ht_fresnel.snapshot.configuration.box[:3]
assert np.array_equal(
p3ht_fresnel.camera_position, box * np.array([1, 1, 0])
)
camera = p3ht_fresnel.camera()
assert np.array_equal(camera.position, box * np.array([1, 1, 0]))

def test_set_color_no_type(self, p3ht_fresnel):
with pytest.raises(ValueError):
p3ht_fresnel.set_type_color("ca", (0.1, 0.1, 0.1))
Expand All @@ -65,6 +76,12 @@ def test_set_bad_unwrap_pos(self, p3ht_fresnel):
with pytest.raises(ValueError):
p3ht_fresnel.unwrap_positions = "true"

def set_set_colors(self, p3ht_fresnel):
colors = np.zeros_like(p3ht_fresnel.positions)
colors[:] = np.array([0.5, 0.5, 0.5])
p3ht_fresnel.colors = colors
assert all(np.array_equal(colors, p3ht_fresnel.colors))

def test_unwrap_positions(self, p3ht_fresnel):
assert p3ht_fresnel.unwrap_positions is False
p3ht_fresnel.unwrap_positions = True
Expand Down
7 changes: 6 additions & 1 deletion cmeutils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(
self._frame = 0
self.frame = frame
self._color_dict = color_dict
self._colors = np.array([0.5, 0.25, 0.5])
self._diameter_scale = diameter_scale
self._height = height
self._device = device
Expand Down Expand Up @@ -312,7 +313,11 @@ def colors(self):
if self.color_dict:
return np.array([self.color_dict[i] for i in self.particle_types])
else:
return np.array([0.5, 0.25, 0.5])
return self._colors

@colors.setter
def colors(self, value):
self._colors = value

@property
def box_length(self):
Expand Down

0 comments on commit 6b83bc5

Please sign in to comment.