Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 18, 2023
1 parent 87c30c1 commit 656044f
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions cmeutils/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ def __init__(
metal=0,
view_axis=(1, 0, 0),
height=10,
device=fresnel.Device()
device=fresnel.Device(),
):
self.scene = fresnel.Scene()
self.gsd_file = gsd_file
with gsd.hoomd.open(gsd_file) as traj:
self._n_frames = len(traj)
self._unwrap_positions = False
self._snapshot = None
self._frame = 0
self._frame = 0
self.frame = frame
self._height = height
self._height = height
self._color_dict = color_dict
self._diameter_scale = diameter_scale
self._device = device
Expand All @@ -46,9 +46,7 @@ def frame(self):
@frame.setter
def frame(self, frame):
if frame > self._n_frames - 1:
raise ValueError(
f"The GSD file only has {self._n_frames} frames."
)
raise ValueError(f"The GSD file only has {self._n_frames} frames.")
self._frame = frame
with gsd.hoomd.open(self.gsd_file) as f:
self._snapshot = f[frame]

Check warning on line 52 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L46-L52

Added lines #L46 - L52 were not covered by tests
Expand All @@ -73,15 +71,15 @@ def color_dict(self):
def color_dict(self, value):
if not isinstance(value, dict):
raise ValueError(

Check warning on line 73 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L70-L73

Added lines #L70 - L73 were not covered by tests
"Pass in a dicitonary with "
"keys of particle type, values of color"
"Pass in a dicitonary with "
"keys of particle type, values of color"
)
self._color_dict = value

Check warning on line 77 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L77

Added line #L77 was not covered by tests

def set_type_color(self, particle_type, color):
if not particle_type in set(self.particle_types):
raise ValueError(

Check warning on line 81 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L79-L81

Added lines #L79 - L81 were not covered by tests
f"Particle type of {particle_type} is not in the Snapshot"
f"Particle type of {particle_type} is not in the Snapshot"
)
self._color_dict[particle_type] = color

Check warning on line 84 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L84

Added line #L84 was not covered by tests

Expand All @@ -95,7 +93,7 @@ def unwrap_positions(self, value):
raise ValueError(

Check warning on line 93 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L90-L93

Added lines #L90 - L93 were not covered by tests
"Set to True or False where "
"True uses unwrapped particle positions"
)
)
self._unwrap_positions = value

Check warning on line 97 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L97

Added line #L97 was not covered by tests

@property
Expand Down Expand Up @@ -144,7 +142,7 @@ def view_axis(self):

@view_axis.setter
def view_axis(self, value):

Check warning on line 144 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L143-L144

Added lines #L143 - L144 were not covered by tests
#TODO Assert is 1,3 array
# TODO Assert is 1,3 array
self._view_axis = np.asarray(value)

Check warning on line 146 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L146

Added line #L146 was not covered by tests

@property
Expand All @@ -169,37 +167,35 @@ def camera_position(self):

@property
def look_at(self):
return self.snapshot.configuration.box[:3] * -self.view_axis
return self.snapshot.configuration.box[:3] * -self.view_axis

Check warning on line 170 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L168-L170

Added lines #L168 - L170 were not covered by tests

@property
def positions(self):
if self.unwrap_positions:
pos = self.snapshot.particles.position
imgs = self.snapshot.particles.image
box_lengths = self.snapshot.configuration.box[:3]
return pos + (imgs * box_lengths)
pos = self.snapshot.particles.position
imgs = self.snapshot.particles.image
box_lengths = self.snapshot.configuration.box[:3]
return pos + (imgs * box_lengths)

Check warning on line 178 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L172-L178

Added lines #L172 - L178 were not covered by tests
else:
return self.snapshot.particles.position

Check warning on line 180 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L180

Added line #L180 was not covered by tests

@property
def radius(self):
return self.snapshot.particles.diameter * self.diameter_scale
return self.snapshot.particles.diameter * self.diameter_scale

Check warning on line 184 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L182-L184

Added lines #L182 - L184 were not covered by tests

@property
def particle_types(self):
return np.array(

Check warning on line 188 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L186-L188

Added lines #L186 - L188 were not covered by tests
[
self.snapshot.particles.types[i] for
i in self.snapshot.particles.typeid
]
[
self.snapshot.particles.types[i]
for i in self.snapshot.particles.typeid
]
)

@property
def colors(self):
if self.color_dict:
return np.array(
[self.color_dict[i] for i in self.particle_types]
)
return np.array([self.color_dict[i] for i in self.particle_types])

Check warning on line 198 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L195-L198

Added lines #L195 - L198 were not covered by tests
else:
return np.array([0.5, 0.25, 0.5])

Check warning on line 200 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L200

Added line #L200 was not covered by tests

Expand All @@ -215,43 +211,44 @@ def geometry(self):

def material(self):
material = fresnel.material.Material(

Check warning on line 213 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L212-L213

Added lines #L212 - L213 were not covered by tests
primitive_color_mix=1,
solid=self.solid,
roughness=self.roughness,
specular=self.specular,
spec_trans=self.specular_trans,
metal=self.metal
primitive_color_mix=1,
solid=self.solid,
roughness=self.roughness,
specular=self.specular,
spec_trans=self.specular_trans,
metal=self.metal,
)
return material

Check warning on line 221 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L221

Added line #L221 was not covered by tests

def camera(self):
camera=fresnel.camera.Orthographic(
position=self.camera_position,
look_at=self.look_at,
up=self.up,
height=self.height
camera = fresnel.camera.Orthographic(

Check warning on line 224 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L223-L224

Added lines #L223 - L224 were not covered by tests
position=self.camera_position,
look_at=self.look_at,
up=self.up,
height=self.height,
)
return camera

Check warning on line 230 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L230

Added line #L230 was not covered by tests


def view(self, width=300, height=300):
self.scene.camera = self.camera()
self.scene.geometry = [self.geometry()]
return fresnel.preview(scene=self.scene, w=width, h=height)

Check warning on line 235 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L232-L235

Added lines #L232 - L235 were not covered by tests

def path_trace(self, width=300, height=300, samples=64, light_samples=1):
self.scene.camera = self.camera()
self.scene.geometry = [self.geometry()]
return fresnel.pathtrace(

Check warning on line 240 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L237-L240

Added lines #L237 - L240 were not covered by tests
scene=self.scene,
w=width,
h=height,
samples=samples,
light_samples=light_samples
scene=self.scene,
w=width,
h=height,
samples=samples,
light_samples=light_samples,
)

def trace(self, width=300, height=300, n_samples=1):
self.scene.camera = self.camera()
self.scene.geometry = [self.geometry()]
tracer = fresnel.tracer.Preview(device=self.scene.device, w=width, h=height)
tracer = fresnel.tracer.Preview(

Check warning on line 251 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L248-L251

Added lines #L248 - L251 were not covered by tests
device=self.scene.device, w=width, h=height
)
return tracer.render(self.scene)

Check warning on line 254 in cmeutils/visualize.py

View check run for this annotation

Codecov / codecov/patch

cmeutils/visualize.py#L254

Added line #L254 was not covered by tests

0 comments on commit 656044f

Please sign in to comment.