Coverage for /builds/ase/ase/ase/cli/db.py: 100.00%
38 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3# Note:
4# Try to avoid module level import statements here to reduce
5# import time during CLI execution
8class CLICommand:
9 """Manipulate and query ASE database.
11 Query is a comma-separated list of
12 selections where each selection is of the type "ID", "key" or
13 "key=value". Instead of "=", one can also use "<", "<=", ">=", ">"
14 and "!=" (these must be protected from the shell by using quotes).
15 Special keys:
17 * id
18 * user
19 * calculator
20 * age
21 * natoms
22 * energy
23 * magmom
24 * charge
26 Chemical symbols can also be used to select number of
27 specific atomic species (H, He, Li, ...). Selection examples:
29 calculator=nwchem
30 age<1d
31 natoms=1
32 user=alice
33 2.2<bandgap<4.1
34 Cu>=10
36 See also: https://wiki.fysik.dtu.dk/ase/ase/db/db.html.
37 """
39 @staticmethod
40 def add_arguments(parser):
41 add = parser.add_argument
42 add('database', help='SQLite3 file, JSON file or postgres URL.')
43 add('query', nargs='*', help='Query string.')
44 add('-v', '--verbose', action='store_true', help='More output.')
45 add('-q', '--quiet', action='store_true', help='Less output.')
46 add('-n', '--count', action='store_true',
47 help='Count number of selected rows.')
48 add('-l', '--long', action='store_true',
49 help='Long description of selected row')
50 add('-i', '--insert-into', metavar='db-name',
51 help='Insert selected rows into another database.')
52 add('-a', '--add-from-file', metavar='filename',
53 help='Add configuration(s) from file. '
54 'If the file contains more than one configuration then you can '
55 'use the syntax filename@: to add all of them. Default is to '
56 'only add the last.')
57 add('-k', '--add-key-value-pairs', metavar='key1=val1,key2=val2,...',
58 help='Add key-value pairs to selected rows. Values must '
59 'be numbers or strings and keys must follow the same rules as '
60 'keywords.')
61 add('-L', '--limit', type=int, default=-1, metavar='N',
62 help='Show only first N rows. Use --limit=0 '
63 'to show all. Default is 20 rows when listing rows and no '
64 'limit when --insert-into is used.')
65 add('--offset', type=int, default=0, metavar='N',
66 help='Skip first N rows. By default, no rows are skipped')
67 add('--delete', action='store_true',
68 help='Delete selected rows.')
69 add('--delete-keys', metavar='key1,key2,...',
70 help='Delete keys for selected rows.')
71 add('-y', '--yes', action='store_true',
72 help='Say yes.')
73 add('--explain', action='store_true',
74 help='Explain query plan.')
75 add('-c', '--columns', metavar='col1,col2,...',
76 help='Specify columns to show. Precede the column specification '
77 'with a "+" in order to add columns to the default set of '
78 'columns. Precede by a "-" to remove columns. Use "++" for all.')
79 add('-s', '--sort', metavar='column', default='id',
80 help='Sort rows using "column". Use "column-" for a descending '
81 'sort. Default is to sort after id.')
82 add('--cut', type=int, default=35, help='Cut keywords and key-value '
83 'columns after CUT characters. Use --cut=0 to disable cutting. '
84 'Default is 35 characters')
85 add('-p', '--plot', metavar='x,y1,y2,...',
86 help='Example: "-p x,y": plot y row against x row. Use '
87 '"-p a:x,y" to make a plot for each value of a.')
88 add('--csv', action='store_true',
89 help='Write comma-separated-values file.')
90 add('-w', '--open-web-browser', action='store_true',
91 help='Open results in web-browser.')
92 add('--no-lock-file', action='store_true', help="Don't use lock-files")
93 add('--analyse', action='store_true',
94 help='Gathers statistics about tables and indices to help make '
95 'better query planning choices.')
96 add('-j', '--json', action='store_true',
97 help='Write json representation of selected row.')
98 add('-m', '--show-metadata', action='store_true',
99 help='Show metadata as json.')
100 add('--set-metadata', metavar='something.json',
101 help='Set metadata from a json file.')
102 add('--strip-data', action='store_true',
103 help='Strip data when using --insert-into.')
104 add('--progress-bar', action='store_true',
105 help='Show a progress bar when using --insert-into.')
106 add('--show-keys', action='store_true',
107 help='Show all keys.')
108 add('--show-values', metavar='key1,key2,...',
109 help='Show values for key(s).')
111 @staticmethod
112 def run(args):
113 from ase.db.cli import main
115 main(args)