Skip to content

Commit

Permalink
fix write modes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjonesBSU committed Sep 21, 2023
1 parent a0cf15b commit 5f559d7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmeutils/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def msd_from_gsd(
Choose from "window" or "direct". See Freud for the differences
https://freud.readthedocs.io/en/latest/modules/msd.html#freud.msd.MSD
"""
with gsd.hoomd.open(gsdfile, "rb") as trajectory:
with gsd.hoomd.open(gsdfile, "r") as trajectory:
init_box = trajectory[start].configuration.box
final_box = trajectory[stop].configuration.box
assert all(
Expand Down
6 changes: 3 additions & 3 deletions cmeutils/gsd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _validate_inputs(gsd_file, snap, gsd_frame):
if gsd_file:
assert isinstance(gsd_frame, int)
try:
with gsd.hoomd.open(name=gsd_file, mode="rb") as f:
with gsd.hoomd.open(name=gsd_file, mode="r") as f:
snap = f[gsd_frame]
except Exception as e:
print("Unable to open the gsd_file")
Expand Down Expand Up @@ -307,7 +307,7 @@ def ellipsoid_gsd(gsd_file, new_file, lpar, lperp):
Value of lperp of the ellipsoids
"""
with gsd.hoomd.open(new_file, "wb") as new_t:
with gsd.hoomd.open(new_file, "w") as new_t:
with gsd.hoomd.open(gsd_file) as old_t:
for snap in old_t:
snap.particles.type_shapes = [
Expand Down Expand Up @@ -352,7 +352,7 @@ def xml_to_gsd(xmlfile, gsdfile):
overwrite=True,
)
hoomd.util.unquiet_status()
with gsd.hoomd.open(f.name) as t, gsd.hoomd.open(gsdfile, "wb") as newt:
with gsd.hoomd.open(f.name) as t, gsd.hoomd.open(gsdfile, "w") as newt:
snap = t[0]
bonds = snap.bonds.group
bonds = bonds[np.lexsort((bonds[:, 1], bonds[:, 0]))]
Expand Down
14 changes: 7 additions & 7 deletions cmeutils/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def angle_distribution(
elif degrees and theta_max is None:
theta_max = 180

trajectory = gsd.hoomd.open(gsd_file, mode="rb")
trajectory = gsd.hoomd.open(gsd_file, mode="r")
name = "-".join([A_name, B_name, C_name])
name_rev = "-".join([C_name, B_name, A_name])

Expand Down Expand Up @@ -179,7 +179,7 @@ def bond_distribution(
If histogram is True, returns a 2D array of bin centers and bin heights.
"""
trajectory = gsd.hoomd.open(gsd_file, mode="rb")
trajectory = gsd.hoomd.open(gsd_file, mode="r")
name = "-".join([A_name, B_name])
name_rev = "-".join([B_name, A_name])

Expand Down Expand Up @@ -273,7 +273,7 @@ def dihedral_distribution(
If histogram is True, returns a 2D array of bin centers and bin heights.
"""
trajectory = gsd.hoomd.open(gsd_file, mode="rb")
trajectory = gsd.hoomd.open(gsd_file, mode="r")
name = "-".join([A_name, B_name, C_name, D_name])
name_rev = "-".join([D_name, C_name, B_name, A_name])

Expand Down Expand Up @@ -413,7 +413,7 @@ def gsd_rdf(
-------
(freud.density.RDF, float)
"""
with gsd.hoomd.open(gsdfile, mode="rb") as trajectory:
with gsd.hoomd.open(gsdfile, mode="r") as trajectory:
snap = trajectory[0]

if r_max is None:
Expand Down Expand Up @@ -482,8 +482,8 @@ def get_centers(gsdfile, new_gsdfile):
new_gsdfile : str
Filename of new GSD for centers.
"""
with gsd.hoomd.open(new_gsdfile, "wb") as new_traj, gsd.hoomd.open(
gsdfile, "rb"
with gsd.hoomd.open(new_gsdfile, "w") as new_traj, gsd.hoomd.open(
gsdfile, "r"
) as traj:
snap = traj[0]
cluster_idx = gsd_utils.get_molecule_cluster(snap=snap)
Expand Down Expand Up @@ -640,7 +640,7 @@ def all_atom_rdf(
-------
freud.density.RDF
"""
with gsd.hoomd.open(gsdfile, mode="rb") as trajectory:
with gsd.hoomd.open(gsdfile, mode="r") as trajectory:
snap = trajectory[start]
if r_max is None:
# Use a value just less than half the maximum box length.
Expand Down
6 changes: 3 additions & 3 deletions cmeutils/tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def gsdfile_images(self, tmp_path):

@pytest.fixture
def snap(self, gsdfile):
with gsd.hoomd.open(name=gsdfile, mode="rb") as f:
with gsd.hoomd.open(name=gsdfile, mode="r") as f:
snap = f[-1]
return snap

@pytest.fixture
def snap_bond(self, gsdfile_bond):
with gsd.hoomd.open(name=gsdfile_bond, mode="rb") as f:
with gsd.hoomd.open(name=gsdfile_bond, mode="r") as f:
snap = f[-1]
return snap

Expand Down Expand Up @@ -93,7 +93,7 @@ def create_frame(i, add_bonds, images, seed=42):


def create_gsd(filename, add_bonds=False, images=False):
with gsd.hoomd.open(name=filename, mode="wb") as f:
with gsd.hoomd.open(name=filename, mode="w") as f:
f.extend(
[
create_frame(i, add_bonds=add_bonds, images=images)
Expand Down
2 changes: 1 addition & 1 deletion cmeutils/tests/test_gsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class TestGSD(BaseTest):
def test_ellipsoid_gsd(self, butane_gsd):
ellipsoid_gsd(butane_gsd, "ellipsoid.gsd", 0.5, 1.0)
with gsd.hoomd.open(name="ellipsoid.gsd", mode="rb") as f:
with gsd.hoomd.open(name="ellipsoid.gsd", mode="r") as f:
snap = f[-1]
assert snap.particles.type_shapes[0]["type"] == "Ellipsoid"

Expand Down

0 comments on commit 5f559d7

Please sign in to comment.