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

17 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1# Note: 

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

3# import time during CLI execution 

4 

5 

6class CLICommand: 

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

8 

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

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

11 

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

13 

14 ase ulm abc.traj -n 0 -v 

15 """ 

16 

17 @staticmethod 

18 def add_arguments(parser): 

19 add = parser.add_argument 

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

21 add( 

22 '-n', 

23 '--index', 

24 type=int, 

25 help='Show only one index. Default is to show all.', 

26 ) 

27 add( 

28 '-d', 

29 '--delete', 

30 metavar='key1,key2,...', 

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

32 ) 

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

34 

35 @staticmethod 

36 def run(args): 

37 import os 

38 

39 from ase.io.ulm import copy, print_ulm_info 

40 

41 if args.delete: 

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

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

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

45 else: 

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