Skip to content
Merged
57 changes: 57 additions & 0 deletions .ci_support/condamerge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import argparse
import sys
import yaml


def read_file(path):
with open(path) as f:
return yaml.safe_load(f)


def parse_args(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('--base', dest='base', help='base environment.yml file')
parser.add_argument('--add', dest='add', help='addon environment.yml file')
return parser.parse_args(argv)


def merge_dependencies(env_base, env_add):
base_dict = {f.split()[0]: f for f in env_base}
add_dict = {f.split()[0]: f for f in env_add}
for k,v in add_dict.items():
if k not in base_dict.keys():
base_dict[k] = v
return list(base_dict.values())


def merge_channels(env_base, env_add):
for c in env_add:
if c not in env_base:
env_base.append(c)
return env_base


def merge_env(env_base, env_add):
return {
"channels": merge_channels(
env_base=env_base['channels'],
env_add=env_add['channels']
),
'dependencies': merge_dependencies(
env_base=env_base['dependencies'],
env_add=env_add['dependencies']
)
}


if __name__ == '__main__':
arguments = parse_args(argv=None)
yaml.dump(
merge_env(
env_base=read_file(arguments.base),
env_add=read_file(arguments.add)
),
sys.stdout,
indent=2,
default_flow_style=False
)
4 changes: 4 additions & 0 deletions .ci_support/environment-dscribe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
channels:
- conda-forge
dependencies:
- dscribe =2.1.0
11 changes: 9 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Setup environment
run: cp .ci_support/environment.yml environment.yml
- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
Expand All @@ -57,6 +55,15 @@ jobs:
channel-priority: strict
activate-environment: my-env
use-mamba: true
- name: Setup environment (windows)
if: matrix.operating-system == 'windows-latest'
run: cp .ci_support/environment.yml environment.yml
- name: Setup environment (unix)
if: matrix.operating-system != 'windows-latest'
shell: bash -l {0}
run: |
mamba install -y pyyaml
python .ci_support/condamerge.py --base .ci_support/environment.yml --add .ci_support/environment-dscribe.yml > environment.yml
- name: Update environment
run: mamba env update -n my-env -f environment.yml
- name: Setup
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'scipy==1.11.2', # ase already requires scipy
],
extras_require={
"dscribe": ["dscribe==2.1.0"],
"grainboundary": ['aimsgb==1.0.3', 'pymatgen==2023.9.10'],
"pyscal": ['pyscal2==2.10.18'],
"nglview": ['nglview==3.0.6'],
Expand All @@ -44,7 +45,7 @@
"symmetry": ['spglib==2.0.2'],
"surface": ['spglib==2.0.2', 'pymatgen==2023.9.10'],
"phonopy": ['phonopy==2.20.0', 'spglib==2.0.2'],
"pyxtal": ['pyxtal==0.6.0']
"pyxtal": ['pyxtal==0.6.0'],
},
cmdclass=versioneer.get_cmdclass(),
)
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 calculate_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 calculate_soap_descriptor_per_atom(
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I'd just go with stk.analyse.soap_descriptor_per_atom as I'm not convinced calculate_ really adds any information

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_calc_soap_descriptor_per_atom(self):
structure = bulk('Cu', 'fcc', a=3.6, cubic=True)
soap = stk.analyse.calculate_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))