diff --git a/samples/visualization_constraints.py b/samples/visualization_constraints.py index 51ada9ab1cc..e647d7de696 100644 --- a/samples/visualization_constraints.py +++ b/samples/visualization_constraints.py @@ -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() @@ -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 diff --git a/testsuite/scripts/samples/test_visualization_constraints.py b/testsuite/scripts/samples/test_visualization_constraints.py index 335b6cbaf8a..eb0764f5bf2 100644 --- a/testsuite/scripts/samples/test_visualization_constraints.py +++ b/testsuite/scripts/samples/test_visualization_constraints.py @@ -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()