Skip to content

Commit

Permalink
Fix broken visualization sample and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Feb 21, 2020
1 parent ee764c1 commit 7747cab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 11 additions & 9 deletions samples/visualization_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
group.add_argument("--wall", action="store_const", dest="shape", const="Wall",
default="Wall")
for shape in ("Sphere", "Ellipsoid", "Cylinder", "SpheroCylinder",
"Stomatocyte", "SimplePore", "SlitPore", "HollowConicalFrustum"):
"Stomatocyte", "SimplePore", "Slitpore", "HollowConicalFrustum"):
group.add_argument("--" + shape.lower(), action="store_const",
dest="shape", const=shape)
args = parser.parse_args()
Expand Down Expand Up @@ -62,51 +62,53 @@
dist=20, normal=[0.1, 0.0, 1]),
particle_type=0, penetrable=True)

if args.shape == "Sphere":
elif args.shape == "Sphere":
system.constraints.add(shape=espressomd.shapes.Sphere(
center=[25, 25, 25], radius=15, direction=1),
particle_type=0, penetrable=True)

if args.shape == "Ellipsoid":
elif args.shape == "Ellipsoid":
system.constraints.add(shape=espressomd.shapes.Ellipsoid(
center=[25, 25, 25], a=25, b=15, direction=1),
particle_type=0, penetrable=True)

if args.shape == "Cylinder":
elif args.shape == "Cylinder":
system.constraints.add(shape=espressomd.shapes.Cylinder(
center=[25] * 3, axis=[1, 0, 0], direction=1, radius=10, length=30),
particle_type=0,
penetrable=True)

if args.shape == "SpheroCylinder":
elif args.shape == "SpheroCylinder":
system.constraints.add(
shape=espressomd.shapes.SpheroCylinder(center=[25] * 3, axis=[1, 0, 0],
direction=1, radius=10, length=30),
particle_type=0,
penetrable=True)

if args.shape == "Stomatocyte":
elif args.shape == "Stomatocyte":
system.constraints.add(shape=espressomd.shapes.Stomatocyte(
inner_radius=3, outer_radius=7, axis=[1.0, 0.0, 0.0], center=[25] * 3,
layer_width=3, direction=1), particle_type=0, penetrable=True)

if args.shape == "SimplePore":
elif args.shape == "SimplePore":
system.constraints.add(shape=espressomd.shapes.SimplePore(
center=[25, 25, 25], axis=[1, 0, 0], length=15, radius=12.5,
smoothing_radius=2), particle_type=0, penetrable=True)

if args.shape == "Slitpore":
elif args.shape == "Slitpore":
system.constraints.add(shape=espressomd.shapes.Slitpore(
channel_width=15, lower_smoothing_radius=3, upper_smoothing_radius=3,
pore_length=20, pore_mouth=30, pore_width=5), particle_type=0,
penetrable=True)

if args.shape == "HollowConicalFrustum":
elif args.shape == "HollowConicalFrustum":
system.constraints.add(shape=espressomd.shapes.HollowConicalFrustum(
r1=12, r2=8, length=15.0, thickness=3,
axis=[0.0, 0.0, 1.0], center=[25, 25, 25], direction=1),
particle_type=0, penetrable=True)

else:
raise ValueError("Unknown shape '{}'".format(args.shape))

for i in range(100):
rpos = np.random.random(3) * box_l
Expand Down
5 changes: 5 additions & 0 deletions testsuite/scripts/samples/test_visualization_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def disable_GUI(code):
class Sample(ut.TestCase):
system = sample.system

def test_has_constraint(self):
self.assertEqual(len(self.system.constraints), 1)
constraint_name = type(self.system.constraints[0].shape).__name__
self.assertEqual(constraint_name, sample.args.shape)


if __name__ == "__main__":
ut.main()

0 comments on commit 7747cab

Please sign in to comment.