Skip to content

Commit

Permalink
Fix bug related to get_boundingbox() (#1059)
Browse files Browse the repository at this point in the history
* Increase comparison tolerance when determining missing_dimension in get_bounbindingbox()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
daico007 and pre-commit-ci[bot] authored Nov 29, 2022
1 parent 846e18e commit 671572f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 3 additions & 2 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,8 @@ def get_boundingbox(self, pad_box=None):
has_dimension = [True, True, True]
if not is_one_particle:
missing_dimensions = np.all(
np.isclose(self.xyz, self.xyz[0, :]), axis=0
np.isclose(self.xyz, self.xyz[0, :], atol=1e-2),
axis=0,
)
for i, truthy in enumerate(missing_dimensions):
has_dimension[i] = not truthy
Expand All @@ -1468,7 +1469,7 @@ def get_boundingbox(self, pad_box=None):
# handle any missing dimensions (planar molecules)
for i, dim in enumerate(has_dimension):
if not dim:
vecs[i][i] = 1.0
vecs[i][i] = 0.1

if pad_box is not None:
if isinstance(pad_box, (int, float, str, Sequence)):
Expand Down
15 changes: 10 additions & 5 deletions mbuild/tests/test_compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,19 +1789,24 @@ def test_get_boundingbox_extrema(self):
h2.pos = [0.07590747, -0.00182889, -0.00211742]
container = mb.Compound([h1, h2])
distances = container.maxs - container.mins
with pytest.raises(
MBuildError, match=r"The vectors to define the box are co\-linear\,"
):
container.get_boundingbox()
# Behavior changed due to new co-linear tolerance define in Compound.get_boundingbox()
assert container.get_boundingbox()

distance_list = [val for val in distances]
distance_list = [val + 1.0 for val in distance_list]
for i in range(len(distance_list)):
if np.isclose(distance_list[i], 0, atol=1e-2):
distance_list[i] = 0.1
distance_list = [val + 1 for val in distance_list]
np.testing.assert_almost_equal(
container.get_boundingbox(pad_box=1.0).lengths,
distance_list,
decimal=6,
)

distance_list = [val for val in distances]
for i in range(len(distance_list)):
if np.isclose(distance_list[i], 0, atol=1e-2):
distance_list[i] = 0.1
distance_list[0] = distance_list[0] + 1.0
distance_list[1] = distance_list[1] + 2.0
distance_list[2] = distance_list[2] + 3.0
Expand Down

0 comments on commit 671572f

Please sign in to comment.