Skip to content

Commit c24a7bb

Browse files
committed
Improved interface.
1 parent 475347e commit c24a7bb

23 files changed

+275
-87
lines changed

dscribe/descriptors/acsf.py

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

170170
return output
171171

172-
def create_single(self, system, centers=None):
172+
def create_single(
173+
self, system, centers=None, return_descriptor=True, return_derivatives=False
174+
):
173175
"""Creates the descriptor for the given system.
174176
175177
Args:
176178
system (:class:`ase.Atoms` | :class:`.System`): Input system.
177179
centers (iterable): Indices of the atoms around which the ACSF
178180
will be returned. If no centers defined, ACSF will be created
179181
for all atoms in the system.
182+
return_descriptor: Whether to return the descriptor
183+
return_derivatives: Whether to return the derivatives
180184
181185
Returns:
182186
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def create_parallel(
270270
"""
271271
# If single system given, skip the parallelization overhead
272272
if len(inp) == 1:
273-
return self.format_array(func(*inp[0]))
273+
return self.format_array(func(*inp[0], return_descriptor=True, return_derivatives=False))
274274

275275
# Determine the number of jobs
276276
if n_jobs < 0:
@@ -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)
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/descriptorglobal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def derivatives_numerical(
246246
i_pos = system_disturbed.get_positions()
247247
i_pos[i_atom, i_comp] += h * deltas[i_stencil]
248248
system_disturbed.set_positions(i_pos)
249-
d1 = self.create_single(system_disturbed)
249+
d1 = self.create_single(system_disturbed, return_descriptor=True, return_derivatives=False)
250250
derivatives_python[i_atom, i_comp, :] += coeffs[i_stencil] * d1 / h
251251

252252
i = 0
@@ -255,4 +255,5 @@ def derivatives_numerical(
255255
i += 1
256256

257257
if return_descriptor:
258-
np.copyto(c, self.create_single(system))
258+
np.copyto(c, self.create_single(system, return_descriptor=True, return_derivatives=False))
259+

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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,17 @@ 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(
181+
self,
182+
system,
183+
accuracy=1e-5,
184+
w=1,
185+
r_cut=None,
186+
g_cut=None,
187+
a=None,
188+
return_descriptor=True,
189+
return_derivatives=False,
190+
):
181191
"""
182192
Args:
183193
system (:class:`ase.Atoms` | :class:`.System`): Input system.
@@ -198,6 +208,8 @@ def create_single(self, system, accuracy=1e-5, w=1, r_cut=None, g_cut=None, a=No
198208
Gaussians. If not provided, a default value of :math:`\\alpha =
199209
\\sqrt{\\pi}\\left(\\frac{N}{V^2}\\right)^{1/6}` is used.
200210
Corresponds to the standard deviation of the Gaussians.
211+
return_descriptor: Whether to return the descriptor
212+
return_derivatives: Whether to return the derivatives
201213
"""
202214
self.q = system.get_atomic_numbers()
203215
self.q_squared = self.q**2
@@ -213,6 +225,7 @@ def create_single(self, system, accuracy=1e-5, w=1, r_cut=None, g_cut=None, a=No
213225
# specified, use the accuracy and the weighting w to determine default
214226
# similarly as in https://doi.org/10.1080/08927022.2013.840898
215227
if r_cut is None and g_cut is None:
228+
216229
f = np.sqrt(-np.log(accuracy))
217230
r_cut = f / a
218231
g_cut = 2 * a * f

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_derivatives=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
@@ -388,11 +388,13 @@ def create(self, system, n_jobs=1, only_physical_cores=False, verbose=False):
388388

389389
return output
390390

391-
def create_single(self, system):
391+
def create_single(self, system, return_descriptor=True, return_derivatives=False):
392392
"""Return the many-body tensor representation for the given system.
393393
394394
Args:
395395
system (:class:`ase.Atoms` | :class:`.System`): Input system.
396+
return_descriptor: Whether to return the descriptor
397+
return_derivatives: Whether to return the derivatives
396398
397399
Returns:
398400
np.ndarray | sparse.COO: A single concatenated output vector is

dscribe/descriptors/soap.py

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

487487
return output
488488

489-
def create_single(self, system, centers=None):
489+
def create_single(
490+
self, system, centers=None, return_descriptor=True, return_derivatives=False
491+
):
490492
"""Return the SOAP output for the given system and given centers.
491493
492494
Args:
@@ -495,6 +497,8 @@ def create_single(self, system, centers=None):
495497
specified, the SOAP spectrum will be created for these points.
496498
If no centers are defined, the SOAP output will be created
497499
for all atoms in the system.
500+
return_descriptor: Whether to return the descriptor
501+
return_derivatives: Whether to return the derivatives
498502
499503
Returns:
500504
np.ndarray | sparse.COO: The SOAP output for the

dscribe/ext/coulombmatrix.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +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-
CellList cell_list
42+
System &system,
43+
CellList cell_list,
44+
bool return_descriptor,
45+
bool return_derivatives
4546
)
4647
{
4748
// Calculate all pairwise distances.
4849
auto out_mu = out.mutable_unchecked<1>();
49-
auto atomic_numbers_u = atomic_numbers.unchecked<1>();
50-
auto positions_u = positions.unchecked<2>();
50+
auto atomic_numbers_u = system.atomic_numbers.unchecked<1>();
51+
auto positions_u = system.positions.unchecked<2>();
5152
int n_atoms = atomic_numbers_u.shape(0);
5253
MatrixXd matrix = distancesEigen(positions_u);
5354

0 commit comments

Comments
 (0)