Skip to content

Commit f7a606f

Browse files
authored
Sample selection update to featomic (#105)
* featomic update ---------
1 parent 3b0ccec commit f7a606f

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

examples/sample-selection/environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ dependencies:
99
- chemiscope>=0.7
1010
- matplotlib
1111
- metatensor
12-
- rascaline @ git+https://github.com/Luthaf/rascaline@ca957642f512e141c7570e987aadc05c7ac71983
12+
- featomic
1313
- skmatter
1414
- equisolve @ git+https://github.com/lab-cosmo/equisolve.git@c858bedef4b2799eb445e4c92535ee387224089a

examples/sample-selection/sample-selection.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
:Authors: Davide Tisi `@DavideTisi <https://github.com/DavideTisi>`_
66
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
88
of structures using both the farthest-point sampling (FPS) and CUR algorithms
99
implemented in scikit-matter. Finally, we also generate a selection of
1010
the most important features using the same techniques.
@@ -19,8 +19,8 @@
1919
import metatensor
2020
import numpy as np
2121
from equisolve.numpy import feature_selection, sample_selection
22+
from featomic import SoapPowerSpectrum
2223
from matplotlib import pyplot as plt
23-
from rascaline import SoapPowerSpectrum
2424
from sklearn.decomposition import PCA
2525
from skmatter import feature_selection as skfeat_selection
2626

@@ -37,22 +37,25 @@
3737
frames = ase.io.read("input-fps.xyz", f":{n_frames}", format="extxyz")
3838

3939
# %%
40-
# Compute SOAP descriptors using rascaline
40+
# Compute SOAP descriptors using featomic
4141
# ----------------------------------------
4242
#
43-
# First, define the rascaline hyperparameters used to compute SOAP.
43+
# First, define the featomic hyperparameters used to compute SOAP.
4444

4545

46-
# rascaline hyperparameters
46+
# featomic hyperparameters
4747
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+
},
5659
}
5760

5861
# Generate a SOAP power spectrum
@@ -61,13 +64,13 @@
6164

6265

6366
# 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"])
6568

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"])
6770

6871
# Sum over atomic centers to compute structure features
6972
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"]
7174
)
7275

7376

@@ -119,13 +122,13 @@
119122
# Print the selected envs for each block
120123
print("atomic envs selected with FPS:\n")
121124
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)
123126

124127
selector_atomic_cur = sample_selection.CUR(n_to_select=n_envs).fit(atom_soap)
125128
# Print the selected envs for each block
126129
print("atomic envs selected with CUR:\n")
127130
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)
129132

130133

131134
# %%
@@ -134,7 +137,7 @@
134137
#
135138
# One can also select from a combined pool of atomic environments and
136139
# 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
138141
# such that our descriptor is a TensorMap consisting of a single block. Upon
139142
# sample selection, the most diverse atomic environments will be selected,
140143
# regardless of their chemical species.
@@ -155,7 +158,7 @@
155158
atom_soap_single_block
156159
)
157160
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",
159162
selector_atomic_fps.support.block(0).samples.values,
160163
)
161164

0 commit comments

Comments
 (0)