|
1 |
| -xamples |
| 1 | +Examples |
2 | 2 | --------
|
3 | 3 |
|
4 | 4 | Generating representations using the ``Compound`` class
|
@@ -132,12 +132,14 @@ The easiest way to calculate the kernel matrix using an explicit, local represen
|
132 | 132 |
|
133 | 133 | (3, 7101, 7101)
|
134 | 134 |
|
| 135 | +Note that ``mol.representation`` is just a 1D numpy array. |
| 136 | + |
135 | 137 |
|
136 | 138 | Generating the SLATM representation
|
137 | 139 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
138 | 140 |
|
139 | 141 | The Spectrum of London and Axillrod-Teller-Muto potential (SLATM) representation requires additional input to reduce the size of the representation.
|
140 |
| -This input (the types of many-body terms) is generate via the ``get_slatm_mbtypes()`` function. The function takes a list of the nuclearges for each molecule in the dataset as input. E.g.: |
| 142 | +This input (the types of many-body terms) is generate via the ``get_slatm_mbtypes()`` function. The function takes a list of the nuclear charges for each molecule in the dataset as input. E.g.: |
141 | 143 |
|
142 | 144 |
|
143 | 145 | .. code:: python
|
@@ -171,64 +173,142 @@ The ``local`` keyword in this example specifies that a local representation is p
|
171 | 173 | # Generate one representation
|
172 | 174 | rep = generate_slatm(coordinates, nuclear_charges, mbtypes)
|
173 | 175 |
|
174 |
| -Generating the ARAD representation and kernels |
| 176 | +Here ``coordinates`` is an Nx3 numpy array, and ``nuclear_charges`` is simply a list of charges. |
| 177 | + |
| 178 | +Generating the FCHL representation |
175 | 179 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
176 |
| -The ARAD representation does not have an explicit representation in the form of a vector, and the L2-distance must be calculated analytically in a separate kernel function. |
177 |
| -The syntax is analogous to the explicit representations (e.g. Coulomb matrix, BoB, SLATM, etc), but is handled by kernels from the separate ``qml.arad`` module. |
| 180 | +The FCHL representation does not have an explicit representation in the form of a vector, and the kernel elements must be calculated analytically in a separate kernel function. |
| 181 | +The syntax is analogous to the explicit representations (e.g. Coulomb matrix, BoB, SLATM, etc), but is handled by kernels from the separate ``qml.fchl`` module. |
178 | 182 |
|
179 |
| -.. code:: python |
| 183 | +The code below show three ways to create the input representations for the FHCL kernel functions. |
180 | 184 |
|
181 |
| - from qml.arad import get_local_kernels_arad |
| 185 | +First using the ``Compound`` class: |
182 | 186 |
|
183 |
| - # Assume the QM7 dataset is loaded into a list of Compound() |
184 |
| - for compound in qm7: |
| 187 | +.. code:: python |
185 | 188 |
|
186 |
| - # Generate the desired representation for each compound |
187 |
| - compound.generate_arad_representation(size=23) |
| 189 | + # Assume the dataset is loaded into a list of Compound() |
| 190 | + for compound in mols: |
| 191 | +
|
| 192 | + # Generate the desired representation for each compound, cut off in angstrom |
| 193 | + compound.generate_fchl_representation(size=23, cut_off=10.0) |
188 | 194 |
|
189 |
| - # Make Numpy array of the representation |
190 |
| - X = np.array([c.representation for c in qm7]) |
| 195 | + # Make Numpy array of the representation, which can be parsed to the kernel |
| 196 | + X = np.array([c.representation for c in mols]) |
191 | 197 |
|
192 |
| - # List of kernel-widths |
193 |
| - sigmas = [50.0, 100.0, 200.0] |
| 198 | +
|
| 199 | +The dimensions of the array should be ``(number_molecules, size, 5, size)``, where ``size`` is the |
| 200 | +size keyword used when generating the representations. |
| 201 | + |
| 202 | +In addition to using the ``Compound`` class to generate the representations, FCHL representations can also be generated via the ``qml.fchl.generate_fchl_representation()`` function, using similar notation to the functions in the ``qml.representations.*`` functions. |
| 203 | + |
| 204 | + |
| 205 | +.. code:: python |
| 206 | +
|
| 207 | + from qml.fchl import generate_representation |
| 208 | +
|
| 209 | + # Dummy coordinates for a water molecule |
| 210 | + coordinates = np.array([[1.464, 0.707, 1.056], |
| 211 | + [0.878, 1.218, 0.498], |
| 212 | + [2.319, 1.126, 0.952]]) |
| 213 | +
|
| 214 | + # Oxygen, Hydrogen, Hydrogen |
| 215 | + nuclear_charges = np.array([8, 1, 1]) |
| 216 | +
|
| 217 | + rep = generate_representation(coordinates, nuclear_charges) |
| 218 | +
|
| 219 | +To create the representation for a crystal, the notation is as follows: |
| 220 | + |
| 221 | + |
| 222 | +.. code:: python |
| 223 | +
|
| 224 | + from qml.fchl import generate_representation |
| 225 | +
|
| 226 | + # Dummy fractional coordinates |
| 227 | + fractional_coordinates = np.array( |
| 228 | + [[ 0. , 0. , 0. ], |
| 229 | + [ 0.75000042, 0.50000027, 0.25000015], |
| 230 | + [ 0.15115386, 0.81961403, 0.33154037], |
| 231 | + [ 0.51192691, 0.18038651, 0.3315404 ], |
| 232 | + [ 0.08154025, 0.31961376, 0.40115401], |
| 233 | + [ 0.66846017, 0.81961403, 0.48807366], |
| 234 | + [ 0.08154025, 0.68038678, 0.76192703], |
| 235 | + [ 0.66846021, 0.18038651, 0.84884672], |
| 236 | + [ 0.23807355, 0.31961376, 0.91846033], |
| 237 | + [ 0.59884657, 0.68038678, 0.91846033], |
| 238 | + [ 0.50000031, 0. , 0.50000031], |
| 239 | + [ 0.25000015, 0.50000027, 0.75000042]] |
| 240 | + ) |
| 241 | +
|
| 242 | + # Dummy nuclear charges |
| 243 | + nuclear_charges = np.array( |
| 244 | + [58, 58, 8, 8, 8, 8, 8, 8, 8, 8, 23, 23] |
| 245 | + ) |
| 246 | +
|
| 247 | + # Dummy unit cell |
| 248 | + unit_cell = np.array( |
| 249 | + [[ 3.699168, 3.699168, -3.255938], |
| 250 | + [ 3.699168, -3.699168, 3.255938], |
| 251 | + [-3.699168, -3.699168, -3.255938]] |
| 252 | + ) |
| 253 | +
|
| 254 | + # Generate the representation |
| 255 | + rep = generate_representation(fractional_coordinates, nuclear_charges, |
| 256 | + cell=unit_cell, neighbors=100, cut_distance=7.0) |
| 257 | +
|
| 258 | +
|
| 259 | +The neighbors keyword is the max number of atoms with the cutoff-distance |
| 260 | + |
| 261 | +Generating the FCHL kernel |
| 262 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 263 | + |
| 264 | +The following example demonstrates how to calculate the local FCHL kernel elements between FCHL representations. ``X1`` and ``X2`` are numpy arrays with the shape ``(number_compounds,max_size, 5,neighbors)``, as generated in one of the previous examples. You MUST use the same cut-off distance to generate the representation and calculate the kernel. |
| 265 | + |
| 266 | + |
| 267 | +.. code:: python |
| 268 | +
|
| 269 | + from qml.fchl import get_local_kernels |
| 270 | +
|
| 271 | + # You can get kernels for multiple kernel-widths |
| 272 | + sigmas = [2.5, 5.0, 10.0] |
194 | 273 |
|
195 | 274 | # Calculate the kernel-matrices for each sigma
|
196 |
| - K = get_local_kernels_arad(X, X, sigmas) |
| 275 | + K = get_local_kernels(X1, X2, sigmas, cut_distance=10.0) |
197 | 276 |
|
198 | 277 | print(K.shape)
|
199 | 278 |
|
200 |
| -.. code:: |
201 | 279 |
|
202 |
| - (3, 7101, 7101) |
| 280 | +As output you will get a kernel for each kernel-width. |
203 | 281 |
|
204 |
| -The dimensions of the input should be ``(number_molecules, size, 5, size)``, where ``size`` is the |
205 |
| -size keyword used when generating the representations. |
| 282 | +.. code:: |
| 283 | +
|
| 284 | + (3, 100, 200) |
206 | 285 |
|
207 |
| -In addition to using the ``Compound`` class to generate the representations, ARAD representations can also be generated via the ``qml.arad.generate_arad_representation()`` function, using similar notation to the functions in the ``qml.representations.*`` functions. |
208 | 286 |
|
209 |
| -In case the two datasets used to calculate the kernel matrix are identical |
210 |
| -- resulting in a symmetric kernel matrix - it is possible use a faster kernel, |
211 |
| -since only half of the kernel elements must be calculated explicitly: |
| 287 | +In case ``X1`` and ``X2`` are identical, K will be symmetrical. This is handled by a separate function with exploits this symmetry (thus being twice as fast). |
212 | 288 |
|
213 | 289 | .. code:: python
|
| 290 | + |
| 291 | + from qml.fchl import get_local_symmetric_kernels |
214 | 292 |
|
215 |
| - from qml.arad import get_local_symmetric_kernels_arad |
| 293 | + # You can get kernels for multiple kernel-widths |
| 294 | + sigmas = [2.5, 5.0, 10.0] |
216 | 295 |
|
217 | 296 | # Calculate the kernel-matrices for each sigma
|
218 |
| - K = get_local_symmetric_kernels_arad(X, sigmas) |
| 297 | + K = get_local_kernels(X1, sigmas, cut_distance=10.0) |
219 | 298 |
|
220 | 299 | print(K.shape)
|
221 | 300 |
|
| 301 | +
|
222 | 302 | .. code::
|
223 | 303 |
|
224 |
| - (3, 7101, 7101) |
| 304 | + (3, 100, 100) |
225 | 305 |
|
226 |
| -In addition to the local kernel, the ARAD module also provides kernels for atomic properties (e.g. chemical shifts, partial charges, etc). These have the name "atomic", rather than "local". |
| 306 | +In addition to the local kernel, the FCHL module also provides kernels for atomic properties (e.g. chemical shifts, partial charges, etc). These have the name "atomic", rather than "local". |
227 | 307 |
|
228 | 308 | .. code:: python
|
229 | 309 |
|
230 |
| - from qml.arad import get_atomic_kernels_arad |
231 |
| - from qml.arad import get_atomic_symmetric_kernels_arad |
| 310 | + from qml.fchl import get_atomic_kernels |
| 311 | + from qml.fchl import get_atomic_symmetric_kernels |
232 | 312 |
|
233 | 313 | The only difference between the local and atomic kernels is the shape of the input.
|
234 | 314 | Since the atomic kernel outputs kernels with atomic resolution, the atomic input has the shape ``(number_atoms, 5, size)``.
|
0 commit comments