Appending a gsd file to another

182 views
Skip to first unread message

jude vishnu

unread,
May 11, 2022, 10:43:09 AM5/11/22
to hoomd-users
Dear all,
I would like to combine two gsd files, basically append one gsd file to another.  I have written the following code for this(see attachment). Is this the correct way to do it or is there a better way in which it can be done?

Kindly let me know.

Regards,
Jude

gsd_combine.py

Michael Howard

unread,
May 11, 2022, 12:34:28 PM5/11/22
to hoomd-users
Hi Jude,

I would use extend:


It works similarly to other python extend methods, something like:

traj1.extend(traj[start:25:step])

would work.

Regards,
Mike

jude vishnu

unread,
Jun 22, 2022, 11:09:31 AM6/22/22
to hoomd-users

Dear Mike,
Should I open file in ab mode for appending always?
Because the file I opened (with wb) just now got overwritten when I tried extend method.

Regards,
Jude

Michael Howard

unread,
Jun 22, 2022, 5:27:11 PM6/22/22
to hoomd-users
Yes, you would need to open the file you want to extend in append mode. It will be overwritten in write mode, which is the standard behavior of I/O modes.

Regards,
Mike

jude vishnu

unread,
Jun 23, 2022, 6:51:39 AM6/23/22
to hoomd-users
Hi Mike,
I am still getting an error saying 

traj1=gsd.hoomd.open(name=filename1, mode='ab')
  File "/gpfs/fs1/home/jvishnu/vhoomd/lib/python3.7/site-packages/gsd/hoomd.py", line 1085, in open
    return HOOMDTrajectory(gsdfileobj)
  File "/gpfs/fs1/home/jvishnu/vhoomd/lib/python3.7/site-packages/gsd/hoomd.py", line 679, in __init__
    raise ValueError('Append mode not yet supported')

I am using gsd version 2.5.3.
Do you know what might be causing this issue?

Regards,
Jude

Michael Howard

unread,
Jun 23, 2022, 4:17:00 PM6/23/22
to hoomd-users
Hi Jude,

I'm not sure why that would be the case based on the documentation:


so someone else will need to jump in on that.

Regards,
Mike

Joshua Anderson

unread,
Jun 23, 2022, 4:31:33 PM6/23/22
to hoomd...@googlegroups.com
The error message is correct. I did not implement the 'ab` mode in the `hoomd` layer of the Python API. Only HOOMD supports this mode in hoomd.write.GSD - it is a very efficient low memory usage mode to add frames to an existing GSD file.

Use `rb+`to open an existing file for both reading and writing with the GSD Python API.
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

-- 
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/fa6f2349-8843-4972-ae4d-9c71be56607an%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages