Comments (5)
Original comment by Carl Simon Adorf (Bitbucket: csadorf, GitHub: csadorf).
Can you elaborate on the second proposal? Maybe also with an example use case? I don't quite understand what you mean.
from garnett.
Original comment by Matthew Spellings (Bitbucket: mspells, GitHub: klarh).
Something like,
list_of_frames = [Frame(), ...]
writer = PosFileWriter()
output = open('dump.pos', 'w')
for frame in list_of_frames:
writer.write_frame(frame, output)
for the use case where you don't have an actual list of frames sitting around to make a Trajectory out of, but are generating them on-the-fly (i.e. what Kyle is doing with his plato.viz module).
from garnett.
Original comment by Carl Simon Adorf (Bitbucket: csadorf, GitHub: csadorf).
What about:
#!python
for frame in generated_frames():
writer.write([frame], output)
or alternatively:
#!python
writer.write(generated_frames(), output)
The reason why I'm hesitant to directly implement a write_frame()
method is, that it requires the assumption that it is actually possible to write the trajectory frame-by-frame, which may not be true for all formats.
In the first case, you ignore this complication and force the writer to simply write length-1 trajectories which may be possible or not based on the format. In this case it's the user's responsibility to make sure that this is ok. For POS-files that's ok.
In the second case we give the writer more freedom in arranging the frame data in a way that is suitable for the format. That might mean for example to cache them all in memory until there is knowledge about how many frames to write.
from garnett.
Original comment by Matthew Spellings (Bitbucket: mspells, GitHub: klarh).
That's probably fine, and like you say, it works fine for pos files, at least. If you're using file objects, you can't do this for GSD files for instance, though, right? Another option would be to throw an error for file backends that don't support such an api...
from garnett.
Original comment by Carl Simon Adorf (Bitbucket: csadorf, GitHub: csadorf).
No, this works also with file-objects, here is a demonstration:
#!python
#!/usr/bin/env python
import sys
import argparse
import logging
import glotzformats as gf
import numpy as np
from tqdm import tqdm
logger = logging.getLogger(__name__)
def map_to_center(frame):
frame.positions -= np.mean(frame.positions, axis=0)
return frame
def main(args):
pos_reader = gf.reader.PosFileReader()
pos_writer = gf.writer.PosFileWriter()
with open(args.posfile) as posfile:
with open(args.out, 'w') as outfile:
traj = pos_reader.read(posfile)
N = len(traj)
traj = (map_to_center(f) for f in traj)
for frame in tqdm(traj, total=N):
pos_writer.write([frame], outfile)
return 0
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="")
parser.add_argument('posfile')
parser.add_argument('out')
args = parser.parse_args()
logging.basicConfig(level=logging.WARNING)
sys.exit(main(args))
from garnett.
Related Issues (20)
- Refactor GSD into a hard/soft dependency HOT 7
- Host documentation on ReadTheDocs
- Enable installation through pip and conda HOT 2
- Add GitHub CODEOWNERS / PR, Issue templates
- Trajectory attribute for all box objects HOT 2
- Test for trajectory with varying number of particles per frame
- Old Links HOT 6
- Box regularization yields wrong orientations HOT 2
- __main__ entry point for file conversion HOT 3
- Enable/read user defined logged quantities from GSD files. HOT 4
- Add option to explicitly set number of dimensions on read/write (specific use case: DCD) HOT 2
- Use types and typeid properties consistent with HOOMD HOT 4
- Refactor and test hoomd snapshot functions in the Frame and Trajectory class
- Make FrameData private and merge _RawFrameData and FrameData
- Update GSD reader/writer for GSD 2.0 HOT 1
- Add badges for PyPI / conda-forge, etc.
- Modernize DCD Reader's use of NumPy
- Update usage of `read_frame` when reading hoomd trajectories
- CI deploy key not enabled for this repository
- Support GSD 3.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from garnett.