Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci_support/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies:
- aimsgb =1.1.0
- ase =3.22.1
- coverage
- dscribe =2.1.0
- matplotlib-base =3.8.2
- nglview =3.1.1
- notebook
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Documentation = "https://github.com/pyiron/structuretoolkit"
Repository = "https://github.com/pyiron/structuretoolkit"

[project.optional-dependencies]
dscribe = ["dscribe==2.1.0"]
grainboundary = [
"aimsgb==1.1.0",
"pymatgen==2024.2.8",
Expand Down
1 change: 1 addition & 0 deletions structuretoolkit/analyse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from structuretoolkit.analyse.distance import find_mic, get_distances_array
from structuretoolkit.analyse.dscribe import soap_descriptor_per_atom
from structuretoolkit.analyse.neighbors import get_neighborhood, get_neighbors
from structuretoolkit.analyse.phonopy import get_equivalent_atoms
from structuretoolkit.analyse.pyscal import (
Expand Down
44 changes: 44 additions & 0 deletions structuretoolkit/analyse/dscribe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def soap_descriptor_per_atom(
structure,
r_cut=None,
n_max=None,
l_max=None,
sigma=1.0,
rbf="gto",
weighting=None,
average="off",
compression={"mode": "off", "species_weighting": None},
species=None,
periodic=True,
sparse=False,
dtype="float64",
centers=None,
n_jobs=1,
only_physical_cores=False,
verbose=False,
):
from dscribe.descriptors import SOAP

if species is None:
species = list(set(structure.get_chemical_symbols()))
periodic_soap = SOAP(
r_cut=r_cut,
n_max=n_max,
l_max=l_max,
sigma=sigma,
rbf=rbf,
weighting=weighting,
average=average,
compression=compression,
species=species,
periodic=periodic,
sparse=sparse,
dtype=dtype,
)
return periodic_soap.create(
system=structure,
centers=centers,
n_jobs=n_jobs,
only_physical_cores=only_physical_cores,
verbose=verbose,
)
Comment on lines +38 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer

structure_soap_array = periodic_soap.create(...)

return structure_soap_array 

More explicit and clearer to someone who is trying to figure out what the function does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would actually integrate better with the workflow stuff too. There, we scrape the output channel label from whatever's after the return value -- giving it a nice variable like that keeps things extra tidy.

26 changes: 26 additions & 0 deletions tests/test_dscribe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.

import unittest
from ase.build import bulk
import numpy as np
import structuretoolkit as stk

try:
import dscribe

skip_dscribe_test = False
except ImportError:
skip_dscribe_test = True


@unittest.skipIf(
skip_dscribe_test, "dscribe is not installed, so the dscribe tests are skipped."
)
class Testdscribe(unittest.TestCase):
def test_soap_descriptor_per_atom(self):
structure = bulk('Cu', 'fcc', a=3.6, cubic=True)
soap = stk.analyse.soap_descriptor_per_atom(structure=structure, r_cut=6.0, n_max=8, l_max=6)
self.assertEqual(soap.shape, (4, 252))
self.assertTrue(np.isclose(soap.sum(), 39450.03009, atol=1.e-5))