anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: mosdef-hub/gmso
Issue: Indexing bug in `from_mbuild`

When initializing a `Topology` from mBuild using `from_mbuild`, I noticed that the position array is different from when `Topology` is initialized without the use of mBuild.  

For example:

`topology = from_mbuild(system)` and `topology.site_list[0].position[0]` outputs: `unyt_array([2.0470509, 1.8087942, 0.4239625], 'nm')`

while

`topology = Topology()` and `topology.site_list[0].position[0]` outputs:
`unyt_quantity(1., 'nm')`

Changed files:
topology/external/convert_mbuild.py, topology/tests/test_site.py, topology/core/site.py

diff --git a/topology/core/site.py b/topology/core/site.py
index 91ea2f5..c49b715 100644
--- a/topology/core/site.py
+++ b/topology/core/site.py
@@ -90,7 +90,7 @@ def _validate_position(position):
     input_unit = position.units
 
     position = np.asarray(position, dtype=float, order='C')
-    np.reshape(position, newshape=(3, ), order='C')
+    position = np.reshape(position, newshape=(3, ), order='C')
 
     position *= input_unit
     position.convert_to_units(u.nm)
diff --git a/topology/external/convert_mbuild.py b/topology/external/convert_mbuild.py
index 559d5f1..c4abb43 100644
--- a/topology/external/convert_mbuild.py
+++ b/topology/external/convert_mbuild.py
@@ -8,12 +8,17 @@ def from_mbuild(compound):
     msg = ("Provided argument that is not an mbuild Compound")
     assert isinstance(compound, mb.Compound), msg
 
-    top = Topology(name=compound.name)
+    top = Topology()
+
+    # Keep the name if it is not the default mbuild Compound name
+    if compound.name != mb.Compound().name:
+        top.name = compound.name
+
     site_map = dict()
-    for child in compound.particles():
-        pos = child.xyz * u.nanometer
-        site = Site(name=child.name, position=pos)
-        site_map[child] = site
+    for particle in compound.particles():
+        pos = particle.xyz[0] * u.nanometer
+        site = Site(name=particle.name, position=pos)
+        site_map[particle] = site
         top.add_site(site)
 
     for b1, b2 in compound.bonds():
diff --git a/topology/tests/test_site.py b/topology/tests/test_site.py
index 2f5c288..7cedb24 100644
--- a/topology/tests/test_site.py
+++ b/topology/tests/test_site.py
@@ -1,5 +1,6 @@
 import numpy as np
 import unyt as u
+import pytest
 
 from topology.core.site import Site
 from topology.tests.base_test import BaseTest
@@ -15,3 +16,10 @@ class TestSite(BaseTest):
         assert site.position.dtype == float
         assert isinstance(site.position, u.unyt_array)
         assert isinstance(site.position, np.ndarray)
+
+    @pytest.mark.parametrize('position', [[0.0, 0.0],
+        [0.0, 0.0, 0.0, 0.0, 0.0], [[0.0, 0.0], [0.0, 0.0]],
+        ['a', 'b', 'c'], ['a', 1, 1]])
+    def test_bad_pos_input(self, position):
+        with pytest.raises(ValueError):
+            site = Site(name='site', position=u.nm*position)