dscribe 2.1.2__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dscribe/__init__.py +17 -0
- dscribe/core/__init__.py +18 -0
- dscribe/core/lattice.py +202 -0
- dscribe/core/system.py +276 -0
- dscribe/descriptors/__init__.py +24 -0
- dscribe/descriptors/acsf.py +402 -0
- dscribe/descriptors/coulombmatrix.py +191 -0
- dscribe/descriptors/descriptor.py +658 -0
- dscribe/descriptors/descriptorglobal.py +267 -0
- dscribe/descriptors/descriptorlocal.py +376 -0
- dscribe/descriptors/descriptormatrix.py +288 -0
- dscribe/descriptors/ewaldsummatrix.py +403 -0
- dscribe/descriptors/lmbtr.py +909 -0
- dscribe/descriptors/mbtr.py +955 -0
- dscribe/descriptors/sinematrix.py +142 -0
- dscribe/descriptors/soap.py +1215 -0
- dscribe/descriptors/valleoganov.py +81 -0
- dscribe/ext/acsf.cpp +261 -0
- dscribe/ext/acsf.h +82 -0
- dscribe/ext/celllist.cpp +164 -0
- dscribe/ext/celllist.h +86 -0
- dscribe/ext/coulombmatrix.cpp +148 -0
- dscribe/ext/coulombmatrix.h +82 -0
- dscribe/ext/descriptor.cpp +27 -0
- dscribe/ext/descriptor.h +43 -0
- dscribe/ext/descriptorglobal.cpp +160 -0
- dscribe/ext/descriptorglobal.h +110 -0
- dscribe/ext/descriptorlocal.cpp +344 -0
- dscribe/ext/descriptorlocal.h +121 -0
- dscribe/ext/ext.cpp +139 -0
- dscribe/ext/geometry.cpp +282 -0
- dscribe/ext/geometry.h +117 -0
- dscribe/ext/mbtr.cpp +826 -0
- dscribe/ext/mbtr.h +206 -0
- dscribe/ext/soap.cpp +261 -0
- dscribe/ext/soap.h +148 -0
- dscribe/ext/soapGTO.cpp +2755 -0
- dscribe/ext/soapGTO.h +67 -0
- dscribe/ext/soapGeneral.cpp +2148 -0
- dscribe/ext/soapGeneral.h +66 -0
- dscribe/ext/weighting.cpp +74 -0
- dscribe/ext/weighting.h +46 -0
- dscribe/ext.cp313-win_amd64.pyd +0 -0
- dscribe/kernels/__init__.py +18 -0
- dscribe/kernels/averagekernel.py +48 -0
- dscribe/kernels/localsimilaritykernel.py +195 -0
- dscribe/kernels/rematchkernel.py +131 -0
- dscribe/utils/__init__.py +15 -0
- dscribe/utils/dimensionality.py +38 -0
- dscribe/utils/geometry.py +225 -0
- dscribe/utils/species.py +80 -0
- dscribe/utils/stats.py +82 -0
- dscribe-2.1.2.dist-info/METADATA +333 -0
- dscribe-2.1.2.dist-info/RECORD +57 -0
- dscribe-2.1.2.dist-info/WHEEL +5 -0
- dscribe-2.1.2.dist-info/licenses/LICENSE +201 -0
- dscribe-2.1.2.dist-info/top_level.txt +1 -0
dscribe/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Copyright 2019 DScribe developers
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from dscribe.core.system import System
|
dscribe/core/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Copyright 2019 DScribe developers
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from dscribe.core.system import System
|
|
18
|
+
from dscribe.core.lattice import Lattice
|
dscribe/core/lattice.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Copyright 2019 DScribe developers
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Lattice(object):
|
|
21
|
+
"""
|
|
22
|
+
A lattice object. Essentially a matrix with conversion matrices. In
|
|
23
|
+
general, it is assumed that length units are in Angstroms and angles are in
|
|
24
|
+
degrees unless otherwise stated.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, matrix):
|
|
28
|
+
"""
|
|
29
|
+
Create a lattice from any sequence of 9 numbers. Note that the sequence
|
|
30
|
+
is assumed to be read one row at a time. Each row represents one
|
|
31
|
+
lattice vector.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
matrix: Sequence of numbers in any form. Examples of acceptable
|
|
35
|
+
input.
|
|
36
|
+
i) An actual numpy array.
|
|
37
|
+
ii) [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
|
|
38
|
+
iii) [1, 0, 0 , 0, 1, 0, 0, 0, 1]
|
|
39
|
+
iv) (1, 0, 0, 0, 1, 0, 0, 0, 1)
|
|
40
|
+
Each row should correspond to a lattice vector.
|
|
41
|
+
E.g., [[10, 0, 0], [20, 10, 0], [0, 0, 30]] specifies a lattice
|
|
42
|
+
with lattice vectors [10, 0, 0], [20, 10, 0] and [0, 0, 30].
|
|
43
|
+
"""
|
|
44
|
+
m = np.array(matrix, dtype=np.float64).reshape((3, 3))
|
|
45
|
+
lengths = np.sqrt(np.sum(m**2, axis=1))
|
|
46
|
+
self._lengths = lengths
|
|
47
|
+
self._matrix = m
|
|
48
|
+
self._inv_matrix = None
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def matrix(self):
|
|
52
|
+
"""Copy of matrix representing the Lattice"""
|
|
53
|
+
return np.copy(self._matrix)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def inv_matrix(self):
|
|
57
|
+
"""
|
|
58
|
+
Inverse of lattice matrix.
|
|
59
|
+
"""
|
|
60
|
+
if self._inv_matrix is None:
|
|
61
|
+
self._inv_matrix = np.linalg.inv(self._matrix)
|
|
62
|
+
return self._inv_matrix
|
|
63
|
+
|
|
64
|
+
def get_cartesian_coords(self, fractional_coords):
|
|
65
|
+
"""
|
|
66
|
+
Returns the cartesian coordinates given fractional coordinates.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
fractional_coords (3x1 array): Fractional coords.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Cartesian coordinates
|
|
73
|
+
"""
|
|
74
|
+
return np.dot(fractional_coords, self._matrix)
|
|
75
|
+
|
|
76
|
+
def get_fractional_coords(self, cart_coords):
|
|
77
|
+
"""
|
|
78
|
+
Returns the fractional coordinates given cartesian coordinates.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
cart_coords (3x1 array): Cartesian coords.
|
|
82
|
+
|
|
83
|
+
Returns:
|
|
84
|
+
Fractional coordinates.
|
|
85
|
+
"""
|
|
86
|
+
return np.dot(cart_coords, self.inv_matrix)
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def lengths(self):
|
|
90
|
+
if self._lengths is None:
|
|
91
|
+
lengths = np.linalg.norm(self._matrix, axis=1)
|
|
92
|
+
self._lengths = lengths
|
|
93
|
+
return self._lengths
|
|
94
|
+
|
|
95
|
+
@property
|
|
96
|
+
def abc(self):
|
|
97
|
+
"""
|
|
98
|
+
Lengths of the lattice vectors, i.e. (a, b, c)
|
|
99
|
+
"""
|
|
100
|
+
return tuple(self.lengths)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def reciprocal_lattice(self):
|
|
104
|
+
"""
|
|
105
|
+
Return the reciprocal lattice. Note that this is the standard
|
|
106
|
+
reciprocal lattice used for solid state physics with a factor of 2 *
|
|
107
|
+
pi. If you are looking for the crystallographic reciprocal lattice,
|
|
108
|
+
use the reciprocal_lattice_crystallographic property.
|
|
109
|
+
The property is lazily generated for efficiency.
|
|
110
|
+
"""
|
|
111
|
+
try:
|
|
112
|
+
return self._reciprocal_lattice
|
|
113
|
+
except AttributeError:
|
|
114
|
+
v = self.inv_matrix.T
|
|
115
|
+
self._reciprocal_lattice = Lattice(v * 2 * np.pi)
|
|
116
|
+
return self._reciprocal_lattice
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def reciprocal_lattice_crystallographic(self):
|
|
120
|
+
"""
|
|
121
|
+
Returns the *crystallographic* reciprocal lattice, i.e., no factor of
|
|
122
|
+
2 * pi.
|
|
123
|
+
"""
|
|
124
|
+
return Lattice(self.reciprocal_lattice.matrix / (2 * np.pi))
|
|
125
|
+
|
|
126
|
+
def get_points_in_sphere(self, frac_points, center, r, zip_results=True):
|
|
127
|
+
"""
|
|
128
|
+
Find all points within a sphere from the point taking into account
|
|
129
|
+
periodic boundary conditions. This includes sites in other periodic
|
|
130
|
+
images.
|
|
131
|
+
|
|
132
|
+
Algorithm:
|
|
133
|
+
|
|
134
|
+
1. place sphere of radius r in crystal and determine minimum supercell
|
|
135
|
+
(parallelpiped) which would contain a sphere of radius r. for this
|
|
136
|
+
we need the projection of a_1 on a unit vector perpendicular
|
|
137
|
+
to a_2 & a_3 (i.e. the unit vector in the direction b_1) to
|
|
138
|
+
determine how many a_1"s it will take to contain the sphere.
|
|
139
|
+
|
|
140
|
+
Nxmax = r * length_of_b_1 / (2 Pi)
|
|
141
|
+
|
|
142
|
+
2. keep points falling within r.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
frac_points: All points in the lattice in fractional coordinates.
|
|
146
|
+
center: Cartesian coordinates of center of sphere.
|
|
147
|
+
r: radius of sphere.
|
|
148
|
+
zip_results (bool): Whether to zip the results together to group by
|
|
149
|
+
point, or return the raw fcoord, dist, index arrays
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
if zip_results:
|
|
153
|
+
[(fcoord, dist, index) ...] since most of the time, subsequent
|
|
154
|
+
processing requires the distance.
|
|
155
|
+
else:
|
|
156
|
+
fcoords, dists, inds
|
|
157
|
+
"""
|
|
158
|
+
# TODO: refactor to use lll matrix (nmax will be smaller)
|
|
159
|
+
recp_len = np.array(self.reciprocal_lattice.abc) / (2 * np.pi)
|
|
160
|
+
nmax = float(r) * recp_len + 0.01
|
|
161
|
+
|
|
162
|
+
pcoords = self.get_fractional_coords(center)
|
|
163
|
+
center = np.array(center)
|
|
164
|
+
|
|
165
|
+
n = len(frac_points)
|
|
166
|
+
fcoords = np.array(frac_points) % 1
|
|
167
|
+
indices = np.arange(n)
|
|
168
|
+
|
|
169
|
+
mins = np.floor(pcoords - nmax)
|
|
170
|
+
maxes = np.ceil(pcoords + nmax)
|
|
171
|
+
arange = np.arange(start=mins[0], stop=maxes[0])
|
|
172
|
+
brange = np.arange(start=mins[1], stop=maxes[1])
|
|
173
|
+
crange = np.arange(start=mins[2], stop=maxes[2])
|
|
174
|
+
arange = arange[:, None] * np.array([1, 0, 0])[None, :]
|
|
175
|
+
brange = brange[:, None] * np.array([0, 1, 0])[None, :]
|
|
176
|
+
crange = crange[:, None] * np.array([0, 0, 1])[None, :]
|
|
177
|
+
images = arange[:, None, None] + brange[None, :, None] + crange[None, None, :]
|
|
178
|
+
|
|
179
|
+
shifted_coords = fcoords[:, None, None, None, :] + images[None, :, :, :, :]
|
|
180
|
+
|
|
181
|
+
cart_coords = self.get_cartesian_coords(fcoords)
|
|
182
|
+
cart_images = self.get_cartesian_coords(images)
|
|
183
|
+
coords = cart_coords[:, None, None, None, :] + cart_images[None, :, :, :, :]
|
|
184
|
+
coords -= center[None, None, None, None, :]
|
|
185
|
+
coords **= 2
|
|
186
|
+
d_2 = np.sum(coords, axis=4)
|
|
187
|
+
|
|
188
|
+
within_r = np.where(d_2 <= r**2)
|
|
189
|
+
if zip_results:
|
|
190
|
+
return list(
|
|
191
|
+
zip(
|
|
192
|
+
shifted_coords[within_r],
|
|
193
|
+
np.sqrt(d_2[within_r]),
|
|
194
|
+
indices[within_r[0]],
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
else:
|
|
198
|
+
return (
|
|
199
|
+
shifted_coords[within_r],
|
|
200
|
+
np.sqrt(d_2[within_r]),
|
|
201
|
+
indices[within_r[0]],
|
|
202
|
+
)
|
dscribe/core/system.py
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Copyright 2019 DScribe developers
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from ase import Atoms
|
|
18
|
+
import ase.geometry
|
|
19
|
+
import numpy as np
|
|
20
|
+
import dscribe.utils.geometry
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class System(Atoms):
|
|
24
|
+
"""Represents atomic systems that are used internally by the package.
|
|
25
|
+
Inherits from the ase.Atoms class, but adds the possibility to cache
|
|
26
|
+
various time-consuming quantities that can be shared when creating multiple
|
|
27
|
+
descriptors.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self,
|
|
32
|
+
symbols=None,
|
|
33
|
+
positions=None,
|
|
34
|
+
numbers=None,
|
|
35
|
+
tags=None,
|
|
36
|
+
momenta=None,
|
|
37
|
+
masses=None,
|
|
38
|
+
magmoms=None,
|
|
39
|
+
charges=None,
|
|
40
|
+
scaled_positions=None,
|
|
41
|
+
cell=None,
|
|
42
|
+
pbc=None,
|
|
43
|
+
celldisp=None,
|
|
44
|
+
constraint=None,
|
|
45
|
+
calculator=None,
|
|
46
|
+
info=None,
|
|
47
|
+
wyckoff_positions=None,
|
|
48
|
+
equivalent_atoms=None,
|
|
49
|
+
):
|
|
50
|
+
super().__init__(
|
|
51
|
+
symbols,
|
|
52
|
+
positions,
|
|
53
|
+
numbers,
|
|
54
|
+
tags,
|
|
55
|
+
momenta,
|
|
56
|
+
masses,
|
|
57
|
+
magmoms,
|
|
58
|
+
charges,
|
|
59
|
+
scaled_positions,
|
|
60
|
+
cell,
|
|
61
|
+
pbc,
|
|
62
|
+
celldisp,
|
|
63
|
+
constraint,
|
|
64
|
+
calculator,
|
|
65
|
+
info,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
self.wyckoff_positions = wyckoff_positions
|
|
69
|
+
self.equivalent_atoms = equivalent_atoms
|
|
70
|
+
self._cell_inverse = None
|
|
71
|
+
self._displacement_tensor = None
|
|
72
|
+
self._distance_matrix = None
|
|
73
|
+
self._inverse_distance_matrix = None
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def from_atoms(atoms):
|
|
77
|
+
"""Creates a System object from ASE.Atoms object."""
|
|
78
|
+
|
|
79
|
+
try:
|
|
80
|
+
constraints = atoms._get_constraints()
|
|
81
|
+
except AttributeError:
|
|
82
|
+
# ASE 3.26 replaced `_get_constraints` to `constraints` property (#160)
|
|
83
|
+
constraints = atoms.constraints
|
|
84
|
+
system = System(
|
|
85
|
+
symbols=atoms.get_chemical_symbols(),
|
|
86
|
+
positions=atoms.get_positions(),
|
|
87
|
+
tags=atoms.get_tags(),
|
|
88
|
+
momenta=atoms.get_momenta(),
|
|
89
|
+
masses=atoms.get_masses(),
|
|
90
|
+
magmoms=atoms.get_initial_magnetic_moments(),
|
|
91
|
+
charges=atoms.get_initial_charges(),
|
|
92
|
+
cell=atoms.get_cell(),
|
|
93
|
+
pbc=atoms.get_pbc(),
|
|
94
|
+
celldisp=atoms.get_celldisp(),
|
|
95
|
+
constraint=constraints,
|
|
96
|
+
calculator=atoms.get_calculator(),
|
|
97
|
+
info=atoms.info,
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
return system
|
|
101
|
+
|
|
102
|
+
def get_cell_inverse(self):
|
|
103
|
+
"""Get the matrix inverse of the lattice matrix."""
|
|
104
|
+
if self._cell_inverse is None:
|
|
105
|
+
self._cell_inverse = np.linalg.inv(self.get_cell())
|
|
106
|
+
return self._cell_inverse
|
|
107
|
+
|
|
108
|
+
def to_scaled(self, positions, wrap=False):
|
|
109
|
+
"""Used to transform a set of positions to the basis defined by the
|
|
110
|
+
cell of this system.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
positions (numpy.ndarray): The positions to scale
|
|
114
|
+
wrap (numpy.ndarray): Whether the positions should be wrapped
|
|
115
|
+
inside the cell.
|
|
116
|
+
|
|
117
|
+
Returns:
|
|
118
|
+
numpy.ndarray: The scaled positions
|
|
119
|
+
"""
|
|
120
|
+
fractional = np.linalg.solve(self.get_cell().T, positions.T).T
|
|
121
|
+
|
|
122
|
+
if wrap:
|
|
123
|
+
for i, periodic in enumerate(self.pbc):
|
|
124
|
+
if periodic:
|
|
125
|
+
# Yes, we need to do it twice.
|
|
126
|
+
fractional[:, i] %= 1.0
|
|
127
|
+
fractional[:, i] %= 1.0
|
|
128
|
+
|
|
129
|
+
return fractional
|
|
130
|
+
|
|
131
|
+
def to_cartesian(self, scaled_positions, wrap=False):
|
|
132
|
+
"""Used to transform a set of relative positions to the cartesian basis
|
|
133
|
+
defined by the cell of this system.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
positions (numpy.ndarray): The positions to scale
|
|
137
|
+
wrap (numpy.ndarray): Whether the positions should be wrapped
|
|
138
|
+
inside the cell.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
numpy.ndarray: The cartesian positions
|
|
142
|
+
"""
|
|
143
|
+
if wrap:
|
|
144
|
+
for i, periodic in enumerate(self.pbc):
|
|
145
|
+
if periodic:
|
|
146
|
+
# Yes, we need to do it twice.
|
|
147
|
+
scaled_positions[:, i] %= 1.0
|
|
148
|
+
scaled_positions[:, i] %= 1.0
|
|
149
|
+
|
|
150
|
+
cartesian_positions = np.dot(scaled_positions, self.get_cell())
|
|
151
|
+
return cartesian_positions
|
|
152
|
+
|
|
153
|
+
def get_displacement_tensor(self):
|
|
154
|
+
"""A matrix where the entry A[i, j, :] is the vector
|
|
155
|
+
self.cartesian_pos[j] - self.cartesian_pos[i].
|
|
156
|
+
|
|
157
|
+
For periodic systems the distance of an atom from itself is the
|
|
158
|
+
smallest displacement of an atom from one of it's periodic copies, and
|
|
159
|
+
the distance of two different atoms is the distance of two closest
|
|
160
|
+
copies.
|
|
161
|
+
|
|
162
|
+
Returns:
|
|
163
|
+
np.array: 3D matrix containing the pairwise distance vectors.
|
|
164
|
+
"""
|
|
165
|
+
if self._displacement_tensor is None:
|
|
166
|
+
D, D_len = ase.geometry.geometry.get_distances(
|
|
167
|
+
self.get_positions(), cell=self.get_cell(), pbc=self.get_pbc()
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Figure out the smallest basis vector and set it as
|
|
171
|
+
# displacement for diagonal
|
|
172
|
+
if self.get_pbc().any():
|
|
173
|
+
cell = self.get_cell()
|
|
174
|
+
basis_lengths = np.linalg.norm(cell, axis=1)
|
|
175
|
+
min_index = np.argmin(basis_lengths)
|
|
176
|
+
min_basis = cell[min_index]
|
|
177
|
+
diag_indices = np.diag_indices(len(D))
|
|
178
|
+
D[diag_indices] = min_basis
|
|
179
|
+
diag_indices = np.diag_indices(len(D_len))
|
|
180
|
+
D_len[diag_indices] = basis_lengths[min_index]
|
|
181
|
+
|
|
182
|
+
self._displacement_tensor = D
|
|
183
|
+
self._distance_matrix = D_len
|
|
184
|
+
|
|
185
|
+
return self._displacement_tensor
|
|
186
|
+
|
|
187
|
+
def get_distance_matrix(self):
|
|
188
|
+
"""Calculates the distance matrix A defined as:
|
|
189
|
+
|
|
190
|
+
.. math::
|
|
191
|
+
|
|
192
|
+
A_{ij} = \lvert \mathbf{r}_i - \mathbf{r}_j \\rvert
|
|
193
|
+
|
|
194
|
+
For periodic systems the distance of an atom from itself is the
|
|
195
|
+
smallest displacement of an atom from one of it's periodic copies, and
|
|
196
|
+
the distance of two different atoms is the distance of two closest
|
|
197
|
+
copies.
|
|
198
|
+
|
|
199
|
+
Returns:
|
|
200
|
+
np.array: Symmetric 2D matrix containing the pairwise distances.
|
|
201
|
+
"""
|
|
202
|
+
if self._distance_matrix is None:
|
|
203
|
+
self.get_displacement_tensor()
|
|
204
|
+
return self._distance_matrix
|
|
205
|
+
|
|
206
|
+
def get_distance_matrix_within_radius(
|
|
207
|
+
self, radius, pos=None, output_type="coo_matrix"
|
|
208
|
+
):
|
|
209
|
+
"""Calculates a sparse distance matrix by only considering distances
|
|
210
|
+
within a certain cutoff. Uses a k-d tree to reach O(n log(N)) time
|
|
211
|
+
complexity.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
radius(float): The cutoff radius within which distances are
|
|
215
|
+
calculated. Distances outside this radius are not included.
|
|
216
|
+
output_type(str): Which container to use for output data. Options:
|
|
217
|
+
"dok_matrix", "coo_matrix", "dict", or "ndarray". Default:
|
|
218
|
+
"dok_matrix".
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
dok_matrix | np.array | coo_matrix | dict: Symmetric sparse 2D
|
|
222
|
+
matrix containing the pairwise distances.
|
|
223
|
+
"""
|
|
224
|
+
dmat = dscribe.utils.geometry.get_adjacency_matrix(
|
|
225
|
+
radius, self.get_positions(), pos2=pos, output_type=output_type
|
|
226
|
+
)
|
|
227
|
+
return dmat
|
|
228
|
+
|
|
229
|
+
def get_inverse_distance_matrix(self):
|
|
230
|
+
"""Calculates the inverse distance matrix A defined as:
|
|
231
|
+
|
|
232
|
+
.. math::
|
|
233
|
+
|
|
234
|
+
A_{ij} = \\frac{1}{\lvert \mathbf{r}_i - \mathbf{r}_j \\rvert }
|
|
235
|
+
|
|
236
|
+
For periodic systems the distance of an atom from itself is the
|
|
237
|
+
smallest displacement of an atom from one of it's periodic copies, and
|
|
238
|
+
the distance of two different atoms is the distance of two closest
|
|
239
|
+
copies.
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
np.array: Symmetric 2D matrix containing the pairwise inverse
|
|
243
|
+
distances.
|
|
244
|
+
"""
|
|
245
|
+
if self._inverse_distance_matrix is None:
|
|
246
|
+
distance_matrix = self.get_distance_matrix()
|
|
247
|
+
with np.errstate(divide="ignore"):
|
|
248
|
+
inv_distance_matrix = np.reciprocal(distance_matrix)
|
|
249
|
+
self._inverse_distance_matrix = inv_distance_matrix
|
|
250
|
+
return self._inverse_distance_matrix
|
|
251
|
+
|
|
252
|
+
def set_positions(self, newpositions, apply_constraint=True):
|
|
253
|
+
self._reset_structure()
|
|
254
|
+
super().set_positions(newpositions, apply_constraint)
|
|
255
|
+
|
|
256
|
+
def set_scaled_positions(self, scaled):
|
|
257
|
+
self._reset_structure()
|
|
258
|
+
super().set_scaled_positions(scaled)
|
|
259
|
+
|
|
260
|
+
def set_pbc(self, pbc):
|
|
261
|
+
self._reset_structure()
|
|
262
|
+
super().set_pbc(pbc)
|
|
263
|
+
|
|
264
|
+
def set_cell(self, cell, scale_atoms=False):
|
|
265
|
+
self._reset_structure()
|
|
266
|
+
super().set_cell(cell, scale_atoms)
|
|
267
|
+
|
|
268
|
+
def _reset_structure(self):
|
|
269
|
+
"""Resets the common structural information that is cached by this
|
|
270
|
+
object. The caching is done in order to share common structural
|
|
271
|
+
quantities that are needed by multiple descriptors.
|
|
272
|
+
"""
|
|
273
|
+
self._cell_inverse = None
|
|
274
|
+
self._displacement_tensor = None
|
|
275
|
+
self._distance_matrix = None
|
|
276
|
+
self._inverse_distance_matrix = None
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Copyright 2019 DScribe developers
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from dscribe.descriptors.acsf import ACSF
|
|
18
|
+
from dscribe.descriptors.mbtr import MBTR
|
|
19
|
+
from dscribe.descriptors.valleoganov import ValleOganov
|
|
20
|
+
from dscribe.descriptors.lmbtr import LMBTR
|
|
21
|
+
from dscribe.descriptors.ewaldsummatrix import EwaldSumMatrix
|
|
22
|
+
from dscribe.descriptors.coulombmatrix import CoulombMatrix
|
|
23
|
+
from dscribe.descriptors.sinematrix import SineMatrix
|
|
24
|
+
from dscribe.descriptors.soap import SOAP
|