Skip to content

Commit 5846956

Browse files
Merge pull request #686 from rmatsum836/fix_box_set
Switch order that box mins and maxs are set
2 parents 210df88 + 423033a commit 5846956

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

mbuild/compound.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,8 +2476,10 @@ def to_parmed(self, box=None, title='', residues=None, show_ports=False,
24762476
if not val:
24772477
box_vec_max[dim] += 0.25
24782478
box_vec_min[dim] -= 0.25
2479-
box.mins = np.asarray(box_vec_min)
2479+
# In rare cases `AssertionError` will be raised if `mins` is set before `maxs`
2480+
# As a result, set `maxs` before `mins`
24802481
box.maxs = np.asarray(box_vec_max)
2482+
box.mins = np.asarray(box_vec_min)
24812483

24822484
box_vector = np.empty(6)
24832485
if box.angles is not None:

mbuild/tests/test_box.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,20 @@ def test_sanity_checks(self):
113113
box.maxs[1] = box.mins[1] - 1
114114
with pytest.raises(AssertionError):
115115
box.lengths = -1
116+
117+
def test_compound_without_box(self, ethane):
118+
# Set coordinates to trigger the case where `box.mins`
119+
# coordinates can be less than [0, 0, 0]
120+
ethane.xyz = np.array([[0.31079999, 0.0653, -0.85259998],
121+
[0.459, 0.0674, -0.8132],
122+
[0.281, -0.0349, -0.8761],
123+
[0.251, 0.1015, -0.7710],
124+
[0.295, 0.1278, -0.9380],
125+
[0.474, 0.0049, -0.7277],
126+
[0.518, 0.0312, -0.8946],
127+
[0.488, 0.1676, -0.7896]])
128+
# Set periodicity
129+
ethane.periodicity = np.array([0.767, 0.703, 0.710])
130+
# Convert compound to pmd.structure to set Box info
131+
# Conversion should happen without error
132+
ethane.to_parmed()

0 commit comments

Comments
 (0)