Closed StevenCHowell closed 1 year ago
No, the open_dcd_read method calls a C-method (via python) to grab a file pointer and header information and thus it is not applicable to use with open() ...
What I meant was could you use something like,
with mol.open_dcd_read(dcd_fname) as dcd_file:
n_frames = dcd_file[2]
n_atoms = mol.natoms()
dist = np.zeros([n_frames, n_atoms, n_atoms])
for i in xrange(n_frames):
mol.read_dcd_step(dcd_file, i)
# do stuff
One benefit is that it automatically would close the file at the end of the with statement (presumably by calling mol.close_dcd_read
). Also, by eliminating the need to directly call close_dcd_read
, it avoids the issue #44 raises.
Where strictly python calls are used with open() is now used.
When opening a file, the [recommended method]() is to use
with open
because it prevents forgetting to close files.If not it would be worth considering adding this functionality to sassie.
The current method is not intuitive