|
4 | 4 |
|
5 | 5 | :Authors: Davide Tisi `@DavideTisi <https://github.com/DavideTisi>`_ |
6 | 6 |
|
7 | | -In this tutorial we generate descriptors using rascaline, then select a subset |
| 7 | +In this tutorial we generate descriptors using featomic, then select a subset |
8 | 8 | of structures using both the farthest-point sampling (FPS) and CUR algorithms |
9 | 9 | implemented in scikit-matter. Finally, we also generate a selection of |
10 | 10 | the most important features using the same techniques. |
|
19 | 19 | import metatensor |
20 | 20 | import numpy as np |
21 | 21 | from equisolve.numpy import feature_selection, sample_selection |
| 22 | +from featomic import SoapPowerSpectrum |
22 | 23 | from matplotlib import pyplot as plt |
23 | | -from rascaline import SoapPowerSpectrum |
24 | 24 | from sklearn.decomposition import PCA |
25 | 25 | from skmatter import feature_selection as skfeat_selection |
26 | 26 |
|
|
37 | 37 | frames = ase.io.read("input-fps.xyz", f":{n_frames}", format="extxyz") |
38 | 38 |
|
39 | 39 | # %% |
40 | | -# Compute SOAP descriptors using rascaline |
| 40 | +# Compute SOAP descriptors using featomic |
41 | 41 | # ---------------------------------------- |
42 | 42 | # |
43 | | -# First, define the rascaline hyperparameters used to compute SOAP. |
| 43 | +# First, define the featomic hyperparameters used to compute SOAP. |
44 | 44 |
|
45 | 45 |
|
46 | | -# rascaline hyperparameters |
| 46 | +# featomic hyperparameters |
47 | 47 | hypers = { |
48 | | - "cutoff": 6.0, |
49 | | - "max_radial": 8, |
50 | | - "max_angular": 6, |
51 | | - "atomic_gaussian_width": 0.3, |
52 | | - "cutoff_function": {"ShiftedCosine": {"width": 0.5}}, |
53 | | - "radial_basis": {"Gto": {"accuracy": 1e-6}}, |
54 | | - "radial_scaling": {"Willatt2018": {"exponent": 4, "rate": 1, "scale": 3.5}}, |
55 | | - "center_atom_weight": 1.0, |
| 48 | + "cutoff": {"radius": 6.0, "smoothing": {"type": "ShiftedCosine", "width": 0.5}}, |
| 49 | + "density": { |
| 50 | + "type": "Gaussian", |
| 51 | + "width": 0.3, |
| 52 | + "scaling": {"type": "Willatt2018", "exponent": 4, "rate": 1, "scale": 3.5}, |
| 53 | + }, |
| 54 | + "basis": { |
| 55 | + "type": "TensorProduct", |
| 56 | + "max_angular": 6, |
| 57 | + "radial": {"type": "Gto", "max_radial": 7}, |
| 58 | + }, |
56 | 59 | } |
57 | 60 |
|
58 | 61 | # Generate a SOAP power spectrum |
|
61 | 64 |
|
62 | 65 |
|
63 | 66 | # Makes a dense block |
64 | | -atom_soap = rho2i.keys_to_properties(["species_neighbor_1", "species_neighbor_2"]) |
| 67 | +atom_soap = rho2i.keys_to_properties(["neighbor_1_type", "neighbor_2_type"]) |
65 | 68 |
|
66 | | -atom_soap_single_block = atom_soap.keys_to_samples(keys_to_move=["species_center"]) |
| 69 | +atom_soap_single_block = atom_soap.keys_to_samples(keys_to_move=["center_type"]) |
67 | 70 |
|
68 | 71 | # Sum over atomic centers to compute structure features |
69 | 72 | struct_soap = metatensor.sum_over_samples( |
70 | | - atom_soap_single_block, sample_names=["center", "species_center"] |
| 73 | + atom_soap_single_block, sample_names=["atom", "center_type"] |
71 | 74 | ) |
72 | 75 |
|
73 | 76 |
|
|
119 | 122 | # Print the selected envs for each block |
120 | 123 | print("atomic envs selected with FPS:\n") |
121 | 124 | for key, block in selector_atomic_fps.support.items(): |
122 | | - print("species_center:", key, "\n(struct_idx, atom_idx)\n", block.samples.values) |
| 125 | + print("center_type:", key, "\n(struct_idx, atom_idx)\n", block.samples.values) |
123 | 126 |
|
124 | 127 | selector_atomic_cur = sample_selection.CUR(n_to_select=n_envs).fit(atom_soap) |
125 | 128 | # Print the selected envs for each block |
126 | 129 | print("atomic envs selected with CUR:\n") |
127 | 130 | for key, block in selector_atomic_cur.support.items(): |
128 | | - print("species_center:", key, "\n(struct_idx, atom_idx)\n", block.samples.values) |
| 131 | + print("center_type:", key, "\n(struct_idx, atom_idx)\n", block.samples.values) |
129 | 132 |
|
130 | 133 |
|
131 | 134 | # %% |
|
134 | 137 | # |
135 | 138 | # One can also select from a combined pool of atomic environments and |
136 | 139 | # structures, instead of selecting an equal number of atomic environments for |
137 | | -# each chemical species. In this case, we can move the 'species_center' key to samples |
| 140 | +# each chemical species. In this case, we can move the 'center_type' key to samples |
138 | 141 | # such that our descriptor is a TensorMap consisting of a single block. Upon |
139 | 142 | # sample selection, the most diverse atomic environments will be selected, |
140 | 143 | # regardless of their chemical species. |
|
155 | 158 | atom_soap_single_block |
156 | 159 | ) |
157 | 160 | print( |
158 | | - "atomic envs selected with FPS: \n (struct_idx, atom_idx, species_center) \n", |
| 161 | + "atomic envs selected with FPS: \n (struct_idx, atom_idx, center_type) \n", |
159 | 162 | selector_atomic_fps.support.block(0).samples.values, |
160 | 163 | ) |
161 | 164 |
|
|
0 commit comments