.. _csd:

CSD-1000R
#########

This dataset, intended for model testing, contains the SOAP power spectrum
features and local NMR chemical shieldings for 100 environments selected
from CSD-1000r, originally published in [Ceriotti2019]_.

Function Call
-------------

.. function:: skmatter.datasets.load_csd_1000r

Data Set Characteristics
------------------------

    :Number of Instances: Each representation 100

    :Number of Features: Each representation 100

    The representations were computed with [C1]_ using the hyperparameters:

    :rascal hyperparameters:

    +---------------------------+------------+
    | key                       |   value    |
    +---------------------------+------------+
    | interaction_cutoff:       |    3.5     |
    +---------------------------+------------+
    | max_radial:               |      6     |
    +---------------------------+------------+
    | max_angular:              |      6     |
    +---------------------------+------------+
    | gaussian_sigma_constant": |     0.4    |
    +---------------------------+------------+
    | gaussian_sigma_type:      |  "Constant"|
    +---------------------------+------------+
    | cutoff_smooth_width:      |     0.5    |
    +---------------------------+------------+
    | normalize:                |    True    |
    +---------------------------+------------+

    Of the 2'520 resulting features, 100 were selected via FPS using [C2]_.

References
----------

.. [C1] https://github.com/lab-cosmo/librascal commit ade202a6
.. [C2] https://github.com/lab-cosmo/scikit-matter commit 4ed1d92

Reference Code
--------------

.. code-block:: python

        from skmatter.feature_selection import CUR
        from skmatter.preprocessing import StandardFlexibleScaler
        from skmatter.sample_selection import FPS
        
        # read all of the frames and book-keep the centers and species
        filename = "/path/to/CSD-1000R.xyz"
        frames = np.asarray(
                read(filename, ":"),
                dtype=object,
        )

        n_centers = np.array([len(frame) for frame in frames])
        center_idx = np.array([i for i, f in enumerate(frames) for p in f])
        n_env_accum = np.zeros(len(frames) + 1, dtype=int)
        n_env_accum[1:] = np.cumsum(n_centers)

        numbers = np.concatenate([frame.numbers for frame in frames])

        # compute radial soap vectors as first pass
        hypers = dict(
            soap_type="PowerSpectrum",
            interaction_cutoff=2.5,
            max_radial=6,
            max_angular=0,
            gaussian_sigma_type="Constant",
            gaussian_sigma_constant=0.4,
            cutoff_smooth_width=0.5,
            normalize=False,
            global_species=[1, 6, 7, 8],
            expansion_by_species_method="user defined",
        )
        soap = SOAP(**hypers)

        X_raw = StandardFlexibleScaler(column_wise=False).fit_transform(
            soap.transform(frames).get_features(soap)
        )

        # rank the environments in terms of diversity
        n_samples = 500
        i_selected = FPS(n_to_select=n_samples, initialize=0).fit(X_raw).selected_idx_

        # book-keep which frames these samples belong in
        f_selected = center_idx[i_selected]
        reduced_f_selected = list(sorted(set(f_selected)))
        frames_selected = frames[f_selected].copy()
        ci_selected = i_selected - n_env_accum[f_selected]

        properties_select = [
            frames[fi].arrays["CS_local"][ci] for fi, ci in zip(f_selected, ci_selected)
        ]
