diff --git a/gmso/external/convert_hoomd.py b/gmso/external/convert_hoomd.py index 41b51186..76a071c1 100644 --- a/gmso/external/convert_hoomd.py +++ b/gmso/external/convert_hoomd.py @@ -301,8 +301,10 @@ def _parse_particle_information( # Check for rigid molecules rigid_mols = any([site.molecule.isrigid for site in top.sites]) if rigid_mols: - rigid_ids = [site.molecule.number for site in top.sites] - rigid_ids_set = set(rigid_ids) + rigid_ids = [ + site.molecule.number if site.molecule.isrigid else -1 for site in top.sites + ] + rigid_ids_set = set([i for i in rigid_ids if i != -1]) n_rigid = len(rigid_ids_set) rigid_charges = np.zeros(n_rigid) * charges.units rigid_masses = np.zeros(n_rigid) * masses.units @@ -314,6 +316,8 @@ def _parse_particle_information( typeids = np.concatenate((np.array([0] * n_rigid), typeids + 1)) # Update mass list and position list of Frame for idx, _id in enumerate(rigid_ids_set): + if _id == 1: + continue group_indices = np.where(np.array(rigid_ids) == _id)[0] group_positions = xyz[group_indices] group_masses = masses[group_indices] diff --git a/gmso/tests/test_hoomd.py b/gmso/tests/test_hoomd.py index 49e1c12d..161448fd 100644 --- a/gmso/tests/test_hoomd.py +++ b/gmso/tests/test_hoomd.py @@ -106,6 +106,29 @@ def test_rigid_bodies(self): ): assert np.array_equal(np.array(group1), np.array(group2) + 2) + def test_rigid_bodies_mix(self): + ethane = mb.lib.molecules.Ethane() + ethane.name = "ethane" + benzene = mb.load("c1ccccc1", smiles=True) + benzene.name = "benzene" + box = mb.fill_box([benzene, ethane], n_compounds=[1, 1], box=[2, 2, 2]) + top = from_mbuild(box) + for site in top.sites: + if site.molecule.name == "benzene": + site.molecule.isrigid = True + + snapshot, refs = to_gsd_snapshot(top) + assert snapshot.particles.typeid[0] == 0 + assert snapshot.particles.N == top.n_sites + 1 + assert np.array_equal( + snapshot.particles.body[-ethane.n_particles :], + np.array([-1] * ethane.n_particles), + ) + assert np.array_equal( + snapshot.particles.body[1 : benzene.n_particles + 1], + np.array([0] * benzene.n_particles), + ) + @pytest.mark.skipif( int(hoomd_version[0]) < 4, reason="Unsupported features in HOOMD 3" )