File: ulm.py

package info (click to toggle)
python-ase 3.26.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (40 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download
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
# fmt: off

# Note:
# Try to avoid module level import statements here to reduce
# import time during CLI execution


class CLICommand:
    """Manipulate/show content of ulm-file.

    The ULM file format is used for ASE's trajectory files,
    for GPAW's gpw-files and other things.

    Example (show first image of a trajectory file):

        ase ulm abc.traj -n 0 -v
    """

    @staticmethod
    def add_arguments(parser):
        add = parser.add_argument
        add('filename', help='Name of ULM-file.')
        add('-n', '--index', type=int,
            help='Show only one index.  Default is to show all.')
        add('-d', '--delete', metavar='key1,key2,...',
            help='Remove key(s) from ULM-file.')
        add('-v', '--verbose', action='store_true', help='More output.')

    @staticmethod
    def run(args):
        import os

        from ase.io.ulm import copy, print_ulm_info

        if args.delete:
            exclude = {'.' + key for key in args.delete.split(',')}
            copy(args.filename, args.filename + '.temp', exclude)
            os.rename(args.filename + '.temp', args.filename)
        else:
            print_ulm_info(args.filename, args.index, verbose=args.verbose)