structure-clustering 1.1.0__tar.gz
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.
- structure_clustering-1.1.0/.github/workflows/wheels.yml +99 -0
- structure_clustering-1.1.0/.gitignore +144 -0
- structure_clustering-1.1.0/CMakeLists.txt +13 -0
- structure_clustering-1.1.0/LICENSE +21 -0
- structure_clustering-1.1.0/PKG-INFO +149 -0
- structure_clustering-1.1.0/README.md +120 -0
- structure_clustering-1.1.0/pyproject.toml +42 -0
- structure_clustering-1.1.0/src/Atom.hpp +30 -0
- structure_clustering-1.1.0/src/Machine.cpp +144 -0
- structure_clustering-1.1.0/src/Machine.hpp +32 -0
- structure_clustering-1.1.0/src/Result.cpp +74 -0
- structure_clustering-1.1.0/src/Result.hpp +28 -0
- structure_clustering-1.1.0/src/Structure.cpp +70 -0
- structure_clustering-1.1.0/src/Structure.hpp +40 -0
- structure_clustering-1.1.0/src/constants.hpp +138 -0
- structure_clustering-1.1.0/src/main.cpp +44 -0
- structure_clustering-1.1.0/src/structure_clustering/__init__.py +8 -0
- structure_clustering-1.1.0/src/structure_clustering/__main__.py +128 -0
- structure_clustering-1.1.0/src/structure_clustering/import_multi_xyz.py +70 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
name: Wheels
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- main
|
|
8
|
+
release:
|
|
9
|
+
types:
|
|
10
|
+
- published
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build_sdist:
|
|
18
|
+
name: Build SDist
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
with:
|
|
23
|
+
submodules: true
|
|
24
|
+
|
|
25
|
+
- name: Build SDist
|
|
26
|
+
run: pipx run build --sdist
|
|
27
|
+
|
|
28
|
+
- name: Check metadata
|
|
29
|
+
run: pipx run twine check dist/*
|
|
30
|
+
|
|
31
|
+
- uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: cibw-sdist
|
|
34
|
+
path: dist/*.tar.gz
|
|
35
|
+
|
|
36
|
+
build_wheels:
|
|
37
|
+
name: Wheels on ${{ matrix.os }}
|
|
38
|
+
runs-on: ${{ matrix.os }}
|
|
39
|
+
strategy:
|
|
40
|
+
fail-fast: false
|
|
41
|
+
matrix:
|
|
42
|
+
os: [ubuntu-latest]
|
|
43
|
+
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
with:
|
|
47
|
+
submodules: true
|
|
48
|
+
|
|
49
|
+
- uses: yezz123/setup-uv@v4
|
|
50
|
+
|
|
51
|
+
- uses: pypa/cibuildwheel@v2.20
|
|
52
|
+
env:
|
|
53
|
+
CIBW_BUILD: "cp37-* cp38-* cp39-* cp310-* cp311-* cp312-*" # https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
|
|
54
|
+
CIBW_SKIP: "*-win32 *-musllinux_x86_64 *_i686" # Skip 32 bit architectures, musllinux, and i686
|
|
55
|
+
CIBW_BEFORE_ALL_LINUX: >
|
|
56
|
+
yum install -y wget &&
|
|
57
|
+
cd / && mkdir boost && cd boost &&
|
|
58
|
+
wget --no-check-certificate 'https://sourceforge.net/projects/boost/files/boost/1.86.0/boost_1_86_0.tar.bz2' &&
|
|
59
|
+
tar xf boost_1_86_0.tar.bz2 &&
|
|
60
|
+
mv boost_1_86_0 boost
|
|
61
|
+
CIBW_BEFORE_ALL_WINDOWS: >
|
|
62
|
+
cd / && mkdir boost && cd boost &&
|
|
63
|
+
curl -L -o boost_1_86_0.zip https://sourceforge.net/projects/boost/files/boost/1.86.0/boost_1_86_0.zip/download &&
|
|
64
|
+
tar xf boost_1_86_0.zip &&
|
|
65
|
+
ren boost_1_86_0 boost
|
|
66
|
+
|
|
67
|
+
- name: Verify clean directory
|
|
68
|
+
run: git diff --exit-code
|
|
69
|
+
shell: bash
|
|
70
|
+
|
|
71
|
+
- uses: actions/upload-artifact@v4
|
|
72
|
+
with:
|
|
73
|
+
name: cibw-wheels-${{ matrix.os }}
|
|
74
|
+
path: wheelhouse/*.whl
|
|
75
|
+
|
|
76
|
+
upload_all:
|
|
77
|
+
name: Upload if release
|
|
78
|
+
needs: [build_wheels, build_sdist]
|
|
79
|
+
runs-on: ubuntu-latest
|
|
80
|
+
if: github.event_name == 'release' && github.event.action == 'published'
|
|
81
|
+
environment: pypi
|
|
82
|
+
permissions:
|
|
83
|
+
id-token: write
|
|
84
|
+
|
|
85
|
+
steps:
|
|
86
|
+
- uses: actions/setup-python@v5
|
|
87
|
+
with:
|
|
88
|
+
python-version: "3.x"
|
|
89
|
+
|
|
90
|
+
- uses: actions/download-artifact@v4
|
|
91
|
+
with:
|
|
92
|
+
pattern: cibw-*
|
|
93
|
+
merge-multiple: true
|
|
94
|
+
path: dist
|
|
95
|
+
|
|
96
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
97
|
+
with:
|
|
98
|
+
verbose: true
|
|
99
|
+
print-hash: true
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Using https://github.com/github/gitignore/blob/master/Python.gitignore
|
|
2
|
+
|
|
3
|
+
# Byte-compiled / optimized / DLL files
|
|
4
|
+
__pycache__/
|
|
5
|
+
*.py[cod]
|
|
6
|
+
*$py.class
|
|
7
|
+
|
|
8
|
+
# C extensions
|
|
9
|
+
*.so
|
|
10
|
+
|
|
11
|
+
# Distribution / packaging
|
|
12
|
+
.Python
|
|
13
|
+
build/
|
|
14
|
+
develop-eggs/
|
|
15
|
+
dist/
|
|
16
|
+
downloads/
|
|
17
|
+
eggs/
|
|
18
|
+
.eggs/
|
|
19
|
+
lib/
|
|
20
|
+
lib64/
|
|
21
|
+
parts/
|
|
22
|
+
sdist/
|
|
23
|
+
var/
|
|
24
|
+
wheels/
|
|
25
|
+
share/python-wheels/
|
|
26
|
+
*.egg-info/
|
|
27
|
+
.installed.cfg
|
|
28
|
+
*.egg
|
|
29
|
+
MANIFEST
|
|
30
|
+
|
|
31
|
+
# PyInstaller
|
|
32
|
+
# Usually these files are written by a python script from a template
|
|
33
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
34
|
+
*.manifest
|
|
35
|
+
*.spec
|
|
36
|
+
|
|
37
|
+
# Installer logs
|
|
38
|
+
pip-log.txt
|
|
39
|
+
pip-delete-this-directory.txt
|
|
40
|
+
|
|
41
|
+
# Unit test / coverage reports
|
|
42
|
+
htmlcov/
|
|
43
|
+
.tox/
|
|
44
|
+
.nox/
|
|
45
|
+
.coverage
|
|
46
|
+
.coverage.*
|
|
47
|
+
.cache
|
|
48
|
+
nosetests.xml
|
|
49
|
+
coverage.xml
|
|
50
|
+
*.cover
|
|
51
|
+
*.py,cover
|
|
52
|
+
.hypothesis/
|
|
53
|
+
.pytest_cache/
|
|
54
|
+
cover/
|
|
55
|
+
|
|
56
|
+
# Translations
|
|
57
|
+
*.mo
|
|
58
|
+
*.pot
|
|
59
|
+
|
|
60
|
+
# Django stuff:
|
|
61
|
+
*.log
|
|
62
|
+
local_settings.py
|
|
63
|
+
db.sqlite3
|
|
64
|
+
db.sqlite3-journal
|
|
65
|
+
|
|
66
|
+
# Flask stuff:
|
|
67
|
+
instance/
|
|
68
|
+
.webassets-cache
|
|
69
|
+
|
|
70
|
+
# Scrapy stuff:
|
|
71
|
+
.scrapy
|
|
72
|
+
|
|
73
|
+
# Sphinx documentation
|
|
74
|
+
docs/_build/
|
|
75
|
+
docs/_generate/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
101
|
+
__pypackages__/
|
|
102
|
+
|
|
103
|
+
# Celery stuff
|
|
104
|
+
celerybeat-schedule
|
|
105
|
+
celerybeat.pid
|
|
106
|
+
|
|
107
|
+
# SageMath parsed files
|
|
108
|
+
*.sage.py
|
|
109
|
+
|
|
110
|
+
# Environments
|
|
111
|
+
.env
|
|
112
|
+
.venv
|
|
113
|
+
env/
|
|
114
|
+
venv/
|
|
115
|
+
ENV/
|
|
116
|
+
env.bak/
|
|
117
|
+
venv.bak/
|
|
118
|
+
|
|
119
|
+
# Spyder project settings
|
|
120
|
+
.spyderproject
|
|
121
|
+
.spyproject
|
|
122
|
+
|
|
123
|
+
# Rope project settings
|
|
124
|
+
.ropeproject
|
|
125
|
+
|
|
126
|
+
# mkdocs documentation
|
|
127
|
+
/site
|
|
128
|
+
|
|
129
|
+
# mypy
|
|
130
|
+
.mypy_cache/
|
|
131
|
+
.dmypy.json
|
|
132
|
+
dmypy.json
|
|
133
|
+
|
|
134
|
+
# Pyre type checker
|
|
135
|
+
.pyre/
|
|
136
|
+
|
|
137
|
+
# pytype static type analyzer
|
|
138
|
+
.pytype/
|
|
139
|
+
|
|
140
|
+
# Cython debug symbols
|
|
141
|
+
cython_debug/
|
|
142
|
+
|
|
143
|
+
_skbuild/
|
|
144
|
+
.pyodide-xbuildenv/
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.15...3.29)
|
|
2
|
+
|
|
3
|
+
project(_core LANGUAGES CXX)
|
|
4
|
+
|
|
5
|
+
set(PYBIND11_FINDPYTHON ON)
|
|
6
|
+
find_package(pybind11 CONFIG REQUIRED)
|
|
7
|
+
|
|
8
|
+
include_directories("/boost/boost")
|
|
9
|
+
|
|
10
|
+
file(GLOB CPP_FILES src/*.cpp)
|
|
11
|
+
pybind11_add_module(_core ${CPP_FILES})
|
|
12
|
+
|
|
13
|
+
install(TARGETS _core DESTINATION structure_clustering)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Michael Gatt.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: structure_clustering
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Python package to cluster molecular structures into groups of similar ones.
|
|
5
|
+
Author: Gabriel Schöpfer, Milan Ončák
|
|
6
|
+
Author-Email: Michael Gatt <Michael.Gatt@student.uibk.ac.at>
|
|
7
|
+
Maintainer-Email: Michael Gatt <Michael.Gatt@student.uibk.ac.at>
|
|
8
|
+
License: MIT License
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
21
|
+
Project-URL: Documentation, https://github.com/photophys/structure_clustering/blob/master/README.md
|
|
22
|
+
Project-URL: Repository, https://github.com/photophys/structure_clustering
|
|
23
|
+
Project-URL: Issues, https://github.com/photophys/structure_clustering/issues
|
|
24
|
+
Requires-Python: >=3.7
|
|
25
|
+
Requires-Dist: argparse
|
|
26
|
+
Requires-Dist: toml
|
|
27
|
+
Requires-Dist: numpy
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# structure_clustering
|
|
31
|
+
|
|
32
|
+
**structure_clustering is a Python package to cluster molecular structures into groups of similar ones.** It provides a command-line interface to perform clustering of a multi-xyz file, or you can use it within your Python code.
|
|
33
|
+
|
|
34
|
+
<img src="https://github.com/user-attachments/assets/fef206d6-e039-49ce-911d-627068841853" width="50%" />[^1]
|
|
35
|
+
|
|
36
|
+
[^1]: The figure shows exemplary clusters from Ag⁺(H₂O)₄ structures.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
You can install structure_clustering via pip:
|
|
42
|
+
```bash
|
|
43
|
+
pip install structure_clustering
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
For most platforms, prebuilt wheels are available. If you need (or prefer) to compile and build the wheel yourself, ensure that the [Boost Graph Library](https://www.boost.org/doc/libs/release/libs/graph/doc/index.html) is available system-wide.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Using the Command-Line interface
|
|
50
|
+
You can invoke the structure_clustering script using the `structure_clustering` command.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
usage: structure_clustering <xyz_file> [--config CONFIG] [--output OUTPUT] [--disconnected]
|
|
54
|
+
|
|
55
|
+
Cluster molecular structures into groups.
|
|
56
|
+
|
|
57
|
+
positional arguments:
|
|
58
|
+
xyz_file path of the multi-xyz-file containing the structures
|
|
59
|
+
|
|
60
|
+
options:
|
|
61
|
+
--config CONFIG path of the config TOML file
|
|
62
|
+
--output OUTPUT path of the resulting output file, defaults to <xyz_file>.sc.dat
|
|
63
|
+
--disconnected if you want to include disconnected graphs
|
|
64
|
+
-h, --help show this help message and exit
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For example, to cluster your xyz file:
|
|
68
|
+
```bash
|
|
69
|
+
structure_clustering my_structures.xyz
|
|
70
|
+
```
|
|
71
|
+
To specify a "special" distance for recognising O-H connectivity (see the next section), use:
|
|
72
|
+
```bash
|
|
73
|
+
structure_clustering my_structures.xyz --config sc_config.toml
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In both cases, a file named `my_structures.xyz.sc.dat` will be created, which you can import at <a href="https://photophys.github.io/cluster-vis/"><img src="https://raw.githubusercontent.com/photophys/MOLGA.jl/refs/heads/main/docs/src/assets/logo.svg" height="15px" /> https://photophys.github.io/cluster-vis/</a> to visualise the results of your clustering process.
|
|
77
|
+
|
|
78
|
+
The terminal output will look like this:
|
|
79
|
+
```
|
|
80
|
+
Loading configuration from demo_config.toml
|
|
81
|
+
Using covalent radius of 1.59 for Ag
|
|
82
|
+
Using pair distance of 2.3 for O-H
|
|
83
|
+
Clustering does not include disconnected graphs
|
|
84
|
+
|
|
85
|
+
Using 437 structures from structures.xyz
|
|
86
|
+
Clustering finished <structure_clustering._core.Result object at 0x7f7c949c37b0>
|
|
87
|
+
14 clusters (total 318 structures)
|
|
88
|
+
13 unique single structures
|
|
89
|
+
132 (30.21%) structures sorted out (305 remaining)
|
|
90
|
+
cluster size: Avg=22.7 Med=4.5 Q1=2.2 Q3=23.5
|
|
91
|
+
connections/structure: Avg=12.2 Med=12.0 Q1=12.0 Q3=12.0 (all 437)
|
|
92
|
+
connections/structure: Avg=12.4 Med=12.0 Q1=12.0 Q3=12.0 (remaining 305)
|
|
93
|
+
Writing output file to structures.xyz.sc.dat ...
|
|
94
|
+
|
|
95
|
+
🚀 Open https://photophys.github.io/cluster-vis/ to visualize your results
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
## Config File
|
|
100
|
+
You can use a TOML file to configure the behaviour of the command-line interface.
|
|
101
|
+
```toml
|
|
102
|
+
[covalent]
|
|
103
|
+
He = 0.9
|
|
104
|
+
Ag = 1.59
|
|
105
|
+
|
|
106
|
+
[pair]
|
|
107
|
+
O-H = 2.3
|
|
108
|
+
|
|
109
|
+
[options]
|
|
110
|
+
only_connected_graphs = true
|
|
111
|
+
```
|
|
112
|
+
All settings are optional. Distances are given in Angstrom. Elements are case-sensitive. If you specify `only_connected_graphs` in the config file, this will overwrite your setting from the command-line switch.
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## Demo Code
|
|
116
|
+
```py
|
|
117
|
+
import structure_clustering
|
|
118
|
+
from structure_clustering import Structure, Atom
|
|
119
|
+
|
|
120
|
+
sc_machine = structure_clustering.Machine()
|
|
121
|
+
|
|
122
|
+
sc_machine.setCovalentRadius(1, 0.42) # change hydrogen covalent radius to 0.42
|
|
123
|
+
sc_machine.addPairDistance(8, 1, 2.3) # extend max distance for O-H pairs to 2.3 Ang
|
|
124
|
+
|
|
125
|
+
sc_machine.setOnlyConnectedGraphs(True) # only include fully connected graphs (default)
|
|
126
|
+
|
|
127
|
+
# you will need some structures
|
|
128
|
+
population = structure_clustering.import_multi_xyz("structs.xyz")
|
|
129
|
+
|
|
130
|
+
# you can also create your structures programmatically
|
|
131
|
+
structure = Structure()
|
|
132
|
+
structure.addAtom(Atom(8, -1.674872668, 0.0, -0.984966492))
|
|
133
|
+
structure.addAtom(Atom(1, -1.674872668, 0.759337, -0.388923492))
|
|
134
|
+
structure.addAtom(Atom(1, -1.674872668, -0.759337, -0.388923492))
|
|
135
|
+
population += [structure] # add this structure to our population
|
|
136
|
+
|
|
137
|
+
sc_result = sc_machine.cluster(population)
|
|
138
|
+
|
|
139
|
+
print("clusters", sc_result.clusters)
|
|
140
|
+
print("singles", sc_result.singles)
|
|
141
|
+
|
|
142
|
+
# Output (indices from the original structure list):
|
|
143
|
+
# clusters [[0, 11], [1, 2, 4, 6, 12, 13, 14, 15, 19], [3, 17, 18, 23]]
|
|
144
|
+
# singles [9, 16, 22]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
structure_clustering is licensed under the MIT License. See the [LICENSE file](LICENSE) for more details.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# structure_clustering
|
|
2
|
+
|
|
3
|
+
**structure_clustering is a Python package to cluster molecular structures into groups of similar ones.** It provides a command-line interface to perform clustering of a multi-xyz file, or you can use it within your Python code.
|
|
4
|
+
|
|
5
|
+
<img src="https://github.com/user-attachments/assets/fef206d6-e039-49ce-911d-627068841853" width="50%" />[^1]
|
|
6
|
+
|
|
7
|
+
[^1]: The figure shows exemplary clusters from Ag⁺(H₂O)₄ structures.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
You can install structure_clustering via pip:
|
|
13
|
+
```bash
|
|
14
|
+
pip install structure_clustering
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For most platforms, prebuilt wheels are available. If you need (or prefer) to compile and build the wheel yourself, ensure that the [Boost Graph Library](https://www.boost.org/doc/libs/release/libs/graph/doc/index.html) is available system-wide.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Using the Command-Line interface
|
|
21
|
+
You can invoke the structure_clustering script using the `structure_clustering` command.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
usage: structure_clustering <xyz_file> [--config CONFIG] [--output OUTPUT] [--disconnected]
|
|
25
|
+
|
|
26
|
+
Cluster molecular structures into groups.
|
|
27
|
+
|
|
28
|
+
positional arguments:
|
|
29
|
+
xyz_file path of the multi-xyz-file containing the structures
|
|
30
|
+
|
|
31
|
+
options:
|
|
32
|
+
--config CONFIG path of the config TOML file
|
|
33
|
+
--output OUTPUT path of the resulting output file, defaults to <xyz_file>.sc.dat
|
|
34
|
+
--disconnected if you want to include disconnected graphs
|
|
35
|
+
-h, --help show this help message and exit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For example, to cluster your xyz file:
|
|
39
|
+
```bash
|
|
40
|
+
structure_clustering my_structures.xyz
|
|
41
|
+
```
|
|
42
|
+
To specify a "special" distance for recognising O-H connectivity (see the next section), use:
|
|
43
|
+
```bash
|
|
44
|
+
structure_clustering my_structures.xyz --config sc_config.toml
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
In both cases, a file named `my_structures.xyz.sc.dat` will be created, which you can import at <a href="https://photophys.github.io/cluster-vis/"><img src="https://raw.githubusercontent.com/photophys/MOLGA.jl/refs/heads/main/docs/src/assets/logo.svg" height="15px" /> https://photophys.github.io/cluster-vis/</a> to visualise the results of your clustering process.
|
|
48
|
+
|
|
49
|
+
The terminal output will look like this:
|
|
50
|
+
```
|
|
51
|
+
Loading configuration from demo_config.toml
|
|
52
|
+
Using covalent radius of 1.59 for Ag
|
|
53
|
+
Using pair distance of 2.3 for O-H
|
|
54
|
+
Clustering does not include disconnected graphs
|
|
55
|
+
|
|
56
|
+
Using 437 structures from structures.xyz
|
|
57
|
+
Clustering finished <structure_clustering._core.Result object at 0x7f7c949c37b0>
|
|
58
|
+
14 clusters (total 318 structures)
|
|
59
|
+
13 unique single structures
|
|
60
|
+
132 (30.21%) structures sorted out (305 remaining)
|
|
61
|
+
cluster size: Avg=22.7 Med=4.5 Q1=2.2 Q3=23.5
|
|
62
|
+
connections/structure: Avg=12.2 Med=12.0 Q1=12.0 Q3=12.0 (all 437)
|
|
63
|
+
connections/structure: Avg=12.4 Med=12.0 Q1=12.0 Q3=12.0 (remaining 305)
|
|
64
|
+
Writing output file to structures.xyz.sc.dat ...
|
|
65
|
+
|
|
66
|
+
🚀 Open https://photophys.github.io/cluster-vis/ to visualize your results
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## Config File
|
|
71
|
+
You can use a TOML file to configure the behaviour of the command-line interface.
|
|
72
|
+
```toml
|
|
73
|
+
[covalent]
|
|
74
|
+
He = 0.9
|
|
75
|
+
Ag = 1.59
|
|
76
|
+
|
|
77
|
+
[pair]
|
|
78
|
+
O-H = 2.3
|
|
79
|
+
|
|
80
|
+
[options]
|
|
81
|
+
only_connected_graphs = true
|
|
82
|
+
```
|
|
83
|
+
All settings are optional. Distances are given in Angstrom. Elements are case-sensitive. If you specify `only_connected_graphs` in the config file, this will overwrite your setting from the command-line switch.
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## Demo Code
|
|
87
|
+
```py
|
|
88
|
+
import structure_clustering
|
|
89
|
+
from structure_clustering import Structure, Atom
|
|
90
|
+
|
|
91
|
+
sc_machine = structure_clustering.Machine()
|
|
92
|
+
|
|
93
|
+
sc_machine.setCovalentRadius(1, 0.42) # change hydrogen covalent radius to 0.42
|
|
94
|
+
sc_machine.addPairDistance(8, 1, 2.3) # extend max distance for O-H pairs to 2.3 Ang
|
|
95
|
+
|
|
96
|
+
sc_machine.setOnlyConnectedGraphs(True) # only include fully connected graphs (default)
|
|
97
|
+
|
|
98
|
+
# you will need some structures
|
|
99
|
+
population = structure_clustering.import_multi_xyz("structs.xyz")
|
|
100
|
+
|
|
101
|
+
# you can also create your structures programmatically
|
|
102
|
+
structure = Structure()
|
|
103
|
+
structure.addAtom(Atom(8, -1.674872668, 0.0, -0.984966492))
|
|
104
|
+
structure.addAtom(Atom(1, -1.674872668, 0.759337, -0.388923492))
|
|
105
|
+
structure.addAtom(Atom(1, -1.674872668, -0.759337, -0.388923492))
|
|
106
|
+
population += [structure] # add this structure to our population
|
|
107
|
+
|
|
108
|
+
sc_result = sc_machine.cluster(population)
|
|
109
|
+
|
|
110
|
+
print("clusters", sc_result.clusters)
|
|
111
|
+
print("singles", sc_result.singles)
|
|
112
|
+
|
|
113
|
+
# Output (indices from the original structure list):
|
|
114
|
+
# clusters [[0, 11], [1, 2, 4, 6, 12, 13, 14, 15, 19], [3, 17, 18, 23]]
|
|
115
|
+
# singles [9, 16, 22]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
structure_clustering is licensed under the MIT License. See the [LICENSE file](LICENSE) for more details.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["scikit-build-core", "pybind11"]
|
|
3
|
+
build-backend = "scikit_build_core.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "structure_clustering"
|
|
7
|
+
version = "1.1.0"
|
|
8
|
+
description = " Python package to cluster molecular structures into groups of similar ones."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Michael Gatt", email = "Michael.Gatt@student.uibk.ac.at" },
|
|
12
|
+
{ name = "Gabriel Schöpfer" },
|
|
13
|
+
{ name = "Milan Ončák" },
|
|
14
|
+
]
|
|
15
|
+
maintainers = [
|
|
16
|
+
{ name = "Michael Gatt", email = "Michael.Gatt@student.uibk.ac.at" },
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.7"
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 5 - Production/Stable",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.7",
|
|
24
|
+
"Programming Language :: Python :: 3.8",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Intended Audience :: Science/Research",
|
|
30
|
+
"Topic :: Scientific/Engineering :: Chemistry",
|
|
31
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
32
|
+
]
|
|
33
|
+
dependencies = ["argparse", "toml", "numpy"]
|
|
34
|
+
license = { text = "MIT License" }
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Documentation = "https://github.com/photophys/structure_clustering/blob/master/README.md"
|
|
38
|
+
Repository = "https://github.com/photophys/structure_clustering"
|
|
39
|
+
Issues = "https://github.com/photophys/structure_clustering/issues"
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
structure_clustering = "structure_clustering.__main__:main"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef __ATOM__
|
|
2
|
+
#define __ATOM__
|
|
3
|
+
|
|
4
|
+
#include <iostream>
|
|
5
|
+
|
|
6
|
+
class Position {
|
|
7
|
+
double _x, _y, _z;
|
|
8
|
+
|
|
9
|
+
public:
|
|
10
|
+
Position(const double x, const double y, const double z) : _x(x), _y(y), _z(z) {}
|
|
11
|
+
double x() const { return _x; }
|
|
12
|
+
double y() const { return _y; }
|
|
13
|
+
double z() const { return _z; }
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class Atom {
|
|
17
|
+
int _atomicNumber;
|
|
18
|
+
Position _position;
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
Atom(const int &atomType, const Position &position)
|
|
22
|
+
: _atomicNumber(atomType), _position(position) {}
|
|
23
|
+
Atom(const int &atomType, const double x, const double y, const double z)
|
|
24
|
+
: _atomicNumber(atomType), _position(Position(x, y, z)) {}
|
|
25
|
+
|
|
26
|
+
int atomicNumber() const { return _atomicNumber; }
|
|
27
|
+
Position position() const { return _position; }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#endif
|