Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for writing to NamedStream StringIO buffer #4583

Open
hmacdope opened this issue May 1, 2024 · 0 comments
Open

Add example for writing to NamedStream StringIO buffer #4583

hmacdope opened this issue May 1, 2024 · 0 comments
Assignees

Comments

@hmacdope
Copy link
Member

hmacdope commented May 1, 2024

We have plenty of examples of how to read a file from a StringIO buffer or similar using a NamedStream, but no examples of how to write to a StringIO buffer using a similar methodology. We should add a simple example like the following.

import MDAnalysis as mda
from io import StringIO

u = mda.Universe("pdb.pdb")
buf  = StringIO()
prot = u.select_atoms("protein")
with mda.Writer(mda.lib.util.NamedStream(buf, "prot.xyz"), prot.n_atoms) as w:
   w.write(prot)
   
buf.getvalue()
>>> # xyz file
@hmacdope hmacdope self-assigned this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant