Coverage for /builds/ase/ase/ase/cli/ulm.py: 58.82%

17 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2025-08-02 00:12 +0000

1# fmt: off 

2 

3# Note: 

4# Try to avoid module level import statements here to reduce 

5# import time during CLI execution 

6 

7 

8class CLICommand: 

9 """Manipulate/show content of ulm-file. 

10 

11 The ULM file format is used for ASE's trajectory files, 

12 for GPAW's gpw-files and other things. 

13 

14 Example (show first image of a trajectory file): 

15 

16 ase ulm abc.traj -n 0 -v 

17 """ 

18 

19 @staticmethod 

20 def add_arguments(parser): 

21 add = parser.add_argument 

22 add('filename', help='Name of ULM-file.') 

23 add('-n', '--index', type=int, 

24 help='Show only one index. Default is to show all.') 

25 add('-d', '--delete', metavar='key1,key2,...', 

26 help='Remove key(s) from ULM-file.') 

27 add('-v', '--verbose', action='store_true', help='More output.') 

28 

29 @staticmethod 

30 def run(args): 

31 import os 

32 

33 from ase.io.ulm import copy, print_ulm_info 

34 

35 if args.delete: 

36 exclude = {'.' + key for key in args.delete.split(',')} 

37 copy(args.filename, args.filename + '.temp', exclude) 

38 os.rename(args.filename + '.temp', args.filename) 

39 else: 

40 print_ulm_info(args.filename, args.index, verbose=args.verbose)