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