Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error when ellipsoid axis is zero #1785

Merged
merged 8 commits into from
May 29, 2024
Merged
5 changes: 5 additions & 0 deletions hoomd/hpmc/ShapeEllipsoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ struct EllipsoidParams : ShapeParams
x = v["a"].cast<ShortReal>();
y = v["b"].cast<ShortReal>();
z = v["c"].cast<ShortReal>();

if (x <= 0.0f || y <= 0.0f || z <= 0.0f)
{
throw std::domain_error("All semimajor axes must be nonzero!");
}
}

/// Convert parameters to a python dictionary
Expand Down
10 changes: 10 additions & 0 deletions hoomd/hpmc/pytest/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_invalid_shape_params(invalid_args):
mc.shape["A"] = args


@pytest.mark.parametrize("c", [0.0, -0.5])
def test_ellipsoid_semimajor_axis(c):
cpp_shape = hoomd.hpmc._hpmc.EllipsoidParams
args = {'a': 0.125, 'b': 0.375, 'c': c}
with pytest.raises(ValueError) as err:
cpp_shape({"ignore_statistics": False} | args)

assert ("All semimajor axes must be nonzero!" in str(err))


def test_shape_attached(simulation_factory, two_particle_snapshot_factory,
valid_args):
integrator = valid_args[0]
Expand Down