From NetCDF to XYZ コメントは受け付けていません。
Posted on
11月 09, 2009 by
kimi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #!/usr/bin/env python import os import tempfile from optparse import OptionParser from Dacapo import Dacapo from ASE.Trajectories.NetCDFTrajectory import NetCDFTrajectory from ASE.IO.xyz import WriteXYZ cmd = OptionParser(usage = '%prog [-r R1 R2 R3] input_nc_file output_xyz_file') cmd.add_option('-r', '--repeat', type = 'int', nargs = 3, help = 'Repeat R1, R2, R3 times along the three axes', metavar = 'R1 R2 R3') (opt, argv) = cmd.parse_args() if len(argv) != 2: cmd.print_help() raise SystemExit ncfile = argv[0] xyzfile = argv[1] try: model = Dacapo.ReadAtoms(ncfile, index = 1) trajectory = True except IndexError: trajectory = False if not trajectory: model = Dacapo.ReadAtoms(ncfile) WriteXYZ(xyzfile, atoms = model, repeat = opt.repeat, id = ncfile) else: model = Dacapo.ReadAtoms(ncfile, index = 0) model.SetCalculator(None) tmpfile = tempfile.mktemp() xyzpath = NetCDFTrajectory(tmpfile, model) xyzpath.Update() frame = 0 error = False while not error: frame += 1 try: atoms = Dacapo.ReadAtoms(ncfile, index = frame) model.SetCartesianPositions(atoms.GetCartesianPositions()) xyzpath.Update() except IndexError: error = True xyzpath.Close() xyzpath = NetCDFTrajectory(tmpfile) WriteXYZ(xyzfile, trajectory = xyzpath, repeat = opt.repeat, id = ncfile) os.remove(tmpfile) |