Skip to content

Commit 7cc189b

Browse files
committed
Simplified MBTR calculation.
1 parent 3c6334c commit 7cc189b

20 files changed

+306
-1409
lines changed

dscribe/descriptors/acsf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ def is_static():
169169

170170
return output
171171

172-
def create_single(self, system, centers=None):
172+
def create_single(self, system, centers=None, return_descriptor=True, return_derivatives=False):
173173
"""Creates the descriptor for the given system.
174174
175175
Args:
176176
system (:class:`ase.Atoms` | :class:`.System`): Input system.
177177
centers (iterable): Indices of the atoms around which the ACSF
178178
will be returned. If no centers defined, ACSF will be created
179179
for all atoms in the system.
180+
return_descriptor: Whether to return the descriptor
181+
return_derivatives: Whether to return the derivatives
180182
181183
Returns:
182184
np.ndarray: The ACSF output for the given system and centers. The

dscribe/descriptors/coulombmatrix.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ def create(self, system, n_jobs=1, only_physical_cores=False, verbose=False):
116116

117117
return output
118118

119-
def create_single(self, system):
119+
def create_single(self, system, return_descriptor=True, return_derivatives=False):
120120
"""
121121
Args:
122122
system (:class:`ase.Atoms`): Input system.
123+
return_descriptor: Whether to return the descriptor
124+
return_derivatives: Whether to return the derivatives
123125
124126
Returns:
125127
ndarray: The zero padded matrix as a flattened 1D array.
@@ -140,6 +142,8 @@ def create_single(self, system):
140142
atomic_numbers,
141143
cell,
142144
pbc,
145+
return_descriptor,
146+
return_derivatives,
143147
)
144148

145149
return out_des

dscribe/descriptors/descriptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def create_multiple(arguments, func, is_sparse, index, verbose):
307307
n_samples = len(arguments)
308308

309309
for i_sample, i_arg in enumerate(arguments):
310-
i_out = func(*i_arg, True, False)
310+
i_out = func(*i_arg, return_descriptor=True, return_derivatives=False)
311311
i_out = self.format_array(i_out)
312312

313313
# If the shape varies, just add result into a list

dscribe/descriptors/descriptormatrix.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ def get_matrix(self, system):
101101
np.ndarray: The final two-dimensional matrix for this descriptor.
102102
"""
103103

104-
def create_single(self, system):
104+
def create_single(self, system, return_descriptor=True, return_derivatives=False):
105105
"""
106106
Args:
107107
system (:class:`ase.Atoms` | :class:`.System`): Input system.
108+
return_descriptor: Whether to return the descriptor
109+
return_derivatives: Whether to return the derivatives
108110
109111
Returns:
110112
ndarray: The zero padded matrix either as a 1D array.

dscribe/descriptors/ewaldsummatrix.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def create(
177177

178178
return output
179179

180-
def create_single(self, system, accuracy=1e-5, w=1, r_cut=None, g_cut=None, a=None):
180+
def create_single(self, system, accuracy=1e-5, w=1, r_cut=None, g_cut=None, a=None, return_descriptor=True, return_derivaties=False):
181181
"""
182182
Args:
183183
system (:class:`ase.Atoms` | :class:`.System`): Input system.
@@ -198,6 +198,8 @@ def create_single(self, system, accuracy=1e-5, w=1, r_cut=None, g_cut=None, a=No
198198
Gaussians. If not provided, a default value of :math:`\\alpha =
199199
\\sqrt{\\pi}\\left(\\frac{N}{V^2}\\right)^{1/6}` is used.
200200
Corresponds to the standard deviation of the Gaussians.
201+
return_descriptor: Whether to return the descriptor
202+
return_derivatives: Whether to return the derivatives
201203
"""
202204
self.q = system.get_atomic_numbers()
203205
self.q_squared = self.q**2

dscribe/descriptors/lmbtr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ def create_single(
374374
self,
375375
system,
376376
centers=None,
377+
return_descriptor=True,
378+
return_derivaties=False
377379
):
378380
"""Return the local many-body tensor representation for the given
379381
system and centers.
@@ -386,6 +388,8 @@ def create_single(
386388
If cartesian positions are provided, new atoms are added at that
387389
position. If no centers are provided, all atoms in the system
388390
will be used as centers.
391+
return_descriptor: Whether to return the descriptor
392+
return_derivatives: Whether to return the derivatives
389393
390394
Returns:
391395
1D ndarray: The local many-body tensor representations of given

dscribe/descriptors/mbtr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ def create(self, system, n_jobs=1, only_physical_cores=False, verbose=False):
337337

338338
return output
339339

340-
def create_single(self, system, return_descriptor, return_derivatives):
340+
def create_single(self, system, return_descriptor=True, return_derivatives=False):
341341
"""Return the many-body tensor representation for the given system.
342342
343343
Args:
344344
system (:class:`ase.Atoms`): Input system.
345+
return_descriptor: Whether to return the descriptor
346+
return_derivatives: Whether to return the derivatives
345347
346348
Returns:
347349
np.ndarray | sparse.COO: The return type is

dscribe/descriptors/soap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ def is_static():
486486

487487
return output
488488

489-
def create_single(self, system, centers=None):
489+
def create_single(self, system, centers=None, return_descriptor=True, return_derivatives=False):
490490
"""Return the SOAP output for the given system and given centers.
491491
492492
Args:
@@ -495,6 +495,8 @@ def create_single(self, system, centers=None):
495495
specified, the SOAP spectrum will be created for these points.
496496
If no centers are defined, the SOAP output will be created
497497
for all atoms in the system.
498+
return_descriptor: Whether to return the descriptor
499+
return_derivatives: Whether to return the derivatives
498500
499501
Returns:
500502
np.ndarray | sparse.COO: The SOAP output for the

dscribe/ext/coulombmatrix.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,16 @@ CoulombMatrix::CoulombMatrix(
3939

4040
void CoulombMatrix::create(
4141
py::array_t<double> out,
42-
py::array_t<double> positions,
43-
py::array_t<int> atomic_numbers,
44-
py::array_t<double> cell,
42+
System &system,
4543
CellList cell_list,
4644
bool return_descriptor,
4745
bool return_derivatives
4846
)
4947
{
5048
// Calculate all pairwise distances.
5149
auto out_mu = out.mutable_unchecked<1>();
52-
auto atomic_numbers_u = atomic_numbers.unchecked<1>();
53-
auto positions_u = positions.unchecked<2>();
50+
auto atomic_numbers_u = system.atomic_numbers.unchecked<1>();
51+
auto positions_u = system.positions.unchecked<2>();
5452
int n_atoms = atomic_numbers_u.shape(0);
5553
MatrixXd matrix = distancesEigen(positions_u);
5654

dscribe/ext/coulombmatrix.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ class CoulombMatrix: public DescriptorGlobal {
4646
*/
4747
void create(
4848
py::array_t<double> out,
49-
py::array_t<double> positions,
50-
py::array_t<int> atomic_numbers,
51-
py::array_t<double> cell,
49+
System &system,
5250
CellList cell_list,
5351
bool return_descriptor,
5452
bool return_derivatives

0 commit comments

Comments
 (0)