1
|
|
|
"""The command line interface for average-minimum-distance. |
2
|
|
|
""" |
3
|
|
|
|
4
|
|
|
import argparse |
5
|
|
|
from .compare import compare |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
def main(): |
|
|
|
|
9
|
|
|
|
10
|
|
|
parser = argparse.ArgumentParser(description='Compare crystals by PDD or AMD from the command line.') |
11
|
|
|
|
12
|
|
|
parser.add_argument('path_or_refcodes', type=str, nargs='+', |
13
|
|
|
help='path to a file or folder, or collection of refcodes (csd-python-api only).') |
|
|
|
|
14
|
|
|
parser.add_argument('--output', '-o', type=str, default='output', |
|
|
|
|
15
|
|
|
help='name of the output file.') |
|
|
|
|
16
|
|
|
parser.add_argument('--format', '-f', type=str, default='csv', |
|
|
|
|
17
|
|
|
help='format of the output file, default csv.') |
|
|
|
|
18
|
|
|
|
19
|
|
|
# args of amd.compare |
20
|
|
|
parser.add_argument('--by', '-b', type=str, default='AMD', choices=['AMD', 'PDD'], |
21
|
|
|
help='whether to use AMD or PDD to compare crystals.') |
|
|
|
|
22
|
|
|
parser.add_argument('--k', '-k', type=int, default=100, help='k value to use for AMD/PDD.') |
23
|
|
|
|
24
|
|
|
# reading args |
25
|
|
|
parser.add_argument('--reader', '-r', type=str, default='ase', |
|
|
|
|
26
|
|
|
choices=['ase', 'ccdc', 'pycodcif'], |
|
|
|
|
27
|
|
|
help='backend package used for parsing files, default ase.') |
|
|
|
|
28
|
|
|
parser.add_argument('--remove_hydrogens', default=False, action='store_true', |
29
|
|
|
help='remove Hydrogen atoms from the crystals.') |
|
|
|
|
30
|
|
|
parser.add_argument('--disorder', type=str, default='skip', |
|
|
|
|
31
|
|
|
choices=['skip', 'ordered_sites', 'all_sites'], |
|
|
|
|
32
|
|
|
help='control how disordered structures are handled.') |
|
|
|
|
33
|
|
|
parser.add_argument('--heaviest_component', default=False, action='store_true', |
34
|
|
|
help='remove all but the heaviest molecule in the asymmetric unit, intended for removing solvents (csd-python-api only).') |
|
|
|
|
35
|
|
|
parser.add_argument('--molecular_centres', default=False, action='store_true', |
36
|
|
|
help='uses the centres of molecules for comparisons instead of atoms (csd-python-api only).') |
|
|
|
|
37
|
|
|
parser.add_argument('--supress_warnings', default=False, action='store_true', |
38
|
|
|
help='do not show warnings encountered during reading.') |
|
|
|
|
39
|
|
|
parser.add_argument('--families', default=False, action='store_true', |
40
|
|
|
help='interpret strings given as refcode families (csd-python-api only).') |
|
|
|
|
41
|
|
|
|
42
|
|
|
# pdd args |
43
|
|
|
parser.add_argument('--collapse_tol', type=float, default=1e-4, |
44
|
|
|
help='tolerance for collapsing rows of PDDs.') |
|
|
|
|
45
|
|
|
|
46
|
|
|
# compare args |
47
|
|
|
parser.add_argument('--metric', type=str, default='chebyshev', |
48
|
|
|
help='metric used to compare AMDs/rows of PDDs.') |
|
|
|
|
49
|
|
|
parser.add_argument('--n_jobs', type=int, default=1, |
50
|
|
|
help='number of cores to use for multiprocessing.') |
|
|
|
|
51
|
|
|
parser.add_argument('--verbose', type=int, default=0, |
52
|
|
|
help='tolerance for collapsing rows of PDDs.') |
|
|
|
|
53
|
|
|
parser.add_argument('--low_memory', default=False, action='store_true', |
54
|
|
|
help='use an alternative algorithm with lower memory usage.') |
|
|
|
|
55
|
|
|
|
56
|
|
|
args = parser.parse_args() |
57
|
|
|
kwargs = vars(args) |
58
|
|
|
path_or_refcodes = kwargs.pop('path_or_refcodes') |
59
|
|
|
outpath = kwargs.pop('output', 'output') |
60
|
|
|
ext = kwargs.pop('format', 'csv') |
61
|
|
|
kwargs['show_warnings'] = not kwargs['supress_warnings'] |
62
|
|
|
kwargs.pop('supress_warnings', None) |
63
|
|
|
|
64
|
|
|
crystals = path_or_refcodes[0] |
65
|
|
|
crystals_ = None |
66
|
|
|
if len(path_or_refcodes) > 2: |
|
|
|
|
67
|
|
|
raise ValueError('amd.compare: one or two collections of crystals are allowed for comparison.') |
68
|
|
|
elif len(path_or_refcodes) == 2: |
69
|
|
|
crystals_ = path_or_refcodes[1] |
70
|
|
|
|
71
|
|
|
df = compare(crystals, crystals_, **kwargs) |
72
|
|
|
if kwargs['verbose']: |
73
|
|
|
print(df) |
74
|
|
|
|
|
|
|
|
75
|
|
|
if not outpath.endswith('.' + ext): |
76
|
|
|
outpath += '.' + ext |
77
|
|
|
|
78
|
|
|
try: |
79
|
|
|
output_func = getattr(df, 'to_' + ext) |
80
|
|
|
output_func(outpath) |
81
|
|
|
except AttributeError: |
82
|
|
|
print(f'Cannot output format {ext}, using csv instead.') |
83
|
|
|
df.to_csv(outpath + '.csv') |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
86
|
|
|
if __name__ == '__main__': |
87
|
|
|
main() |
|
|
|
|