1
|
|
|
"""Script for regenerating data found in the tests/data directory. |
2
|
|
|
""" |
3
|
|
|
|
4
|
|
|
import numpy as np |
5
|
|
|
import amd |
6
|
|
|
import pickle |
7
|
|
|
import pathlib |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
parent = pathlib.Path(__file__).absolute().parent |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
def regenerate(name, generator): |
14
|
|
|
"""Regenerate and overwrite ``PeriodicSet``s, AMDs and PDDs for a |
15
|
|
|
testing dataset from a ``generator`` of ``PeriodicSet``s. |
16
|
|
|
""" |
17
|
|
|
|
18
|
|
|
data = [] |
19
|
|
|
for s in generator: |
20
|
|
|
pdd = amd.PDD(s, 100) |
21
|
|
|
data.append( |
22
|
|
|
{ |
23
|
|
|
'PeriodicSet': s, |
24
|
|
|
'AMD100': amd.PDD_to_AMD(pdd), |
25
|
|
|
'PDD100': pdd |
26
|
|
|
} |
27
|
|
|
) |
28
|
|
|
|
29
|
|
|
with open(str(parent / f'{name}.pkl'), 'wb') as f: |
30
|
|
|
pickle.dump(data, f) |
31
|
|
|
if len(data) > 1: |
32
|
|
|
cdm = amd.PDD_pdist([d['PDD100'] for d in data]) |
33
|
|
|
np.savez_compressed(str(parent / f'{name}_cdm.npz'), cdm=cdm) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def regenerate_cifs_test_data(): |
37
|
|
|
"""Regenerate and overwrite all test data using cifs in tests/data. |
38
|
|
|
Does not apply to test data extracted with ``csd-python-api``. |
39
|
|
|
""" |
40
|
|
|
for name in ('cubic', 'T2_experimental'): |
41
|
|
|
path = (parent / f'{name}.cif') |
42
|
|
|
regenerate(name, amd.CifReader(path, show_warnings=False)) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def regenerate_CSD_families_test_data(): |
46
|
|
|
"""Regenerate and overwrite all test data for 'CSD_families' using |
47
|
|
|
``csd-python-api``. |
48
|
|
|
""" |
49
|
|
|
csd_families = ['DEBXIT', 'GLYCIN', 'HXACAN', 'ACSALA'] |
50
|
|
|
reader = amd.CSDReader(csd_families, families=True, show_warnings=False) |
51
|
|
|
regenerate('CSD_families', reader) |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
if __name__ == '__main__': |
55
|
|
|
regenerate_cifs_test_data() |
56
|
|
|
regenerate_CSD_families_test_data() |
57
|
|
|
|