Skip to content

Commit

Permalink
Support GSD 3 (#739)
Browse files Browse the repository at this point in the history
* fix mass value in from_parmed

* specify gsd version < 3.0

* add support for gsd >= 3.0

* revert convert_parmed changes

* change > to >=

* change Snapshot to Frame; update gsd minimum version

* use hoomd.Snapshot in isinstance

* remove gsd major version var

* Pin numpy to 1.24.2 to fix breaking string comparison to unyt array

---------

Co-authored-by: CalCraven <[email protected]>
  • Loading branch information
chrisjonesBSU and CalCraven authored Jun 27, 2023
1 parent e488a03 commit 4bac8e5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
- python>=3.8
- numpy
- numpy=1.24.2
- sympy
- unyt<=2.9.2
- boltons
Expand All @@ -15,7 +15,7 @@ dependencies:
- openbabel>=3.0.0
- foyer>=0.11.3
- forcefield-utilities>=0.2.1
- gsd>=2.0
- gsd>=2.9
- parmed>=3.4.3
- pytest-cov
- codecov
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
- python>=3.8
- numpy
- numpy=1.24.2
- sympy
- unyt<=2.9.2
- boltons
Expand Down
26 changes: 12 additions & 14 deletions gmso/external/convert_hoomd.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def to_gsd_snapshot(
Return
------
gsd_snapshot : gsd.hoomd.Snapshot
gsd_snapshot : gsd.hoomd.Frame
Converted hoomd Snapshot.
base_units : dict
Based units dictionary utilized during the conversion.
Expand All @@ -102,8 +102,7 @@ def to_gsd_snapshot(
read force field parameters from a Foyer XML file.
"""
base_units = _validate_base_units(base_units, top, auto_scale)

gsd_snapshot = gsd.hoomd.Snapshot()
gsd_snapshot = gsd.hoomd.Frame()

gsd_snapshot.configuration.step = 0
gsd_snapshot.configuration.dimensions = 3
Expand Down Expand Up @@ -202,7 +201,6 @@ def to_hoomd_snapshot(
read force field parameters from a Foyer XML file.
"""
base_units = _validate_base_units(base_units, top, auto_scale)

hoomd_snapshot = hoomd.Snapshot()

# Write box information
Expand Down Expand Up @@ -257,7 +255,7 @@ def _parse_particle_information(
Parameters
----------
snapshot : gsd.hoomd.Snapshot or hoomd.Snapshot
snapshot : gsd.hoomd.Frame or hoomd.Snapshot
The target Snapshot object.
top : gmso.Topology
Topology object holding system information.
Expand Down Expand Up @@ -313,7 +311,7 @@ def _parse_particle_information(
snapshot.particles.typeid[0:] = typeids
snapshot.particles.mass[0:] = masses
snapshot.particles.charge[0:] = charges / charge_factor
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.particles.N = top.n_sites
snapshot.particles.types = unique_types
snapshot.particles.position = xyz
Expand Down Expand Up @@ -360,7 +358,7 @@ def _parse_pairs_information(
snapshot.pairs.group[:] = np.reshape(pairs, (-1, 2))
snapshot.pairs.types = pair_types
snapshot.pairs.typeid[:] = pair_typeids
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.pairs.N = len(pairs)
snapshot.pairs.group = np.reshape(pairs, (-1, 2))
snapshot.pairs.types = pair_types
Expand All @@ -372,7 +370,7 @@ def _parse_bond_information(snapshot, top):
Parameters
----------
snapshot : gsd.hoomd.Snapshot or hoomd.Snapshot
snapshot : gsd.hoomd.Frame or hoomd.Snapshot
The target Snapshot object.
top : gmso.Topology
Topology object holding system information
Expand Down Expand Up @@ -406,7 +404,7 @@ def _parse_bond_information(snapshot, top):
snapshot.bonds.types = unique_bond_types
snapshot.bonds.typeid[0:] = bond_typeids
snapshot.bonds.group[0:] = bond_groups
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.bonds.types = unique_bond_types
snapshot.bonds.typeid = bond_typeids
snapshot.bonds.group = bond_groups
Expand All @@ -419,7 +417,7 @@ def _parse_angle_information(snapshot, top):
Parameters
----------
snapshot : gsd.hoomd.Snapshot or hoomd.Snapshot
snapshot : gsd.hoomd.Frame or hoomd.Snapshot
The target Snapshot object.
top : gmso.Topology
Topology object holding system information
Expand Down Expand Up @@ -453,7 +451,7 @@ def _parse_angle_information(snapshot, top):
snapshot.angles.types = unique_angle_types
snapshot.angles.typeid[0:] = angle_typeids
snapshot.angles.group[0:] = np.reshape(angle_groups, (-1, 3))
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.angles.types = unique_angle_types
snapshot.angles.typeid = angle_typeids
snapshot.angles.group = np.reshape(angle_groups, (-1, 3))
Expand All @@ -467,7 +465,7 @@ def _parse_dihedral_information(snapshot, top):
Parameters
----------
snapshot : gsd.hoomd.Snapshot or hoomd.Snapshot
snapshot : gsd.hoomd.Frame or hoomd.Snapshot
The target Snapshot object.
top : gmso.Topology
Topology object holding system information
Expand Down Expand Up @@ -499,7 +497,7 @@ def _parse_dihedral_information(snapshot, top):
snapshot.dihedrals.types = unique_dihedral_types
snapshot.dihedrals.typeid[0:] = dihedral_typeids
snapshot.dihedrals.group[0:] = np.reshape(dihedral_groups, (-1, 4))
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.dihedrals.types = unique_dihedral_types
snapshot.dihedrals.typeid = dihedral_typeids
snapshot.dihedrals.group = np.reshape(dihedral_groups, (-1, 4))
Expand Down Expand Up @@ -547,7 +545,7 @@ def _parse_improper_information(snapshot, top):
snapshot.impropers.types = unique_improper_types
snapshot.impropers.typeid[0:] = improper_typeids
snapshot.impropers.group[0:] = np.reshape(improper_groups, (-1, 4))
elif isinstance(snapshot, gsd.hoomd.Snapshot):
elif isinstance(snapshot, gsd.hoomd.Frame):
snapshot.impropers.types = unique_improper_types
snapshot.impropers.typeid = improper_typeids
snapshot.impropers.group = np.reshape(improper_groups, (-1, 4))
Expand Down
2 changes: 1 addition & 1 deletion gmso/formats/gsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def write_gsd(
shift_coords=shift_coords,
parse_special_pairs=write_special_pairs,
)[0]
with gsd.hoomd.open(filename, mode="wb") as gsd_file:
with gsd.hoomd.open(filename, mode="w") as gsd_file:
gsd_file.append(gsd_snapshot)

0 comments on commit 4bac8e5

Please sign in to comment.