Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate stk as a structure provider, and generate shapes for custom bonds #366

Merged
merged 35 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7868faa
Write example script.
andrewtarzia Sep 20, 2024
f37c99e
Write bonds to shape function, add to init.
andrewtarzia Sep 20, 2024
d81dd4f
Save outputs.
andrewtarzia Sep 20, 2024
0f572e9
Add dependancy for tests.
andrewtarzia Sep 24, 2024
bb7eb92
Add example to README.
andrewtarzia Sep 24, 2024
52ceea1
Move function.
andrewtarzia Sep 24, 2024
cb1ef91
Update example function.
andrewtarzia Sep 24, 2024
b0bb1e6
Update tests.
andrewtarzia Sep 24, 2024
ac40440
Minor formatting.
andrewtarzia Sep 24, 2024
fccaf60
Handle properties not in stk.
andrewtarzia Sep 24, 2024
86f2bf4
Import necessary code.
andrewtarzia Sep 24, 2024
77029ba
Write all stk handling functions.
andrewtarzia Sep 24, 2024
acb01ab
Add example output.
andrewtarzia Sep 24, 2024
d649250
Shift handling to stk functions.
andrewtarzia Sep 24, 2024
af545bb
Fix lint.
andrewtarzia Sep 24, 2024
be13c12
Add more detail.
andrewtarzia Sep 24, 2024
db8f7bb
Update requirements.
andrewtarzia Sep 25, 2024
5222fa0
Change typing to work with Python 3.9.
andrewtarzia Sep 25, 2024
3c86f2f
Bug fix.
andrewtarzia Sep 25, 2024
9dd4f45
Add stko dependancy for docs, remove use of __file__ for doc tests.
andrewtarzia Sep 25, 2024
93ee3ed
Handle Python 3.9 typing.
andrewtarzia Sep 25, 2024
7eeb798
Minor.
andrewtarzia Sep 25, 2024
3e72ec1
Provide stricter requirements for rdkit and stko.
andrewtarzia Sep 25, 2024
a32eedc
For tests, use Python 3.10 stk,stko.
andrewtarzia Sep 26, 2024
4f0ad7a
WIP: Move docs to python 3.11.
andrewtarzia Sep 26, 2024
6761b5f
Rename file with new number.
andrewtarzia Sep 27, 2024
f16914b
Back to Python 3.11.
andrewtarzia Sep 27, 2024
f132c4a
Add to autofunction.
andrewtarzia Sep 27, 2024
5694ede
Update example comments.
andrewtarzia Sep 27, 2024
59b1966
Add comment about pins.
andrewtarzia Oct 3, 2024
c9191b6
Update README.
andrewtarzia Oct 3, 2024
4fa814d
Clean up import.
andrewtarzia Oct 3, 2024
850b2ca
Update example.
andrewtarzia Oct 3, 2024
995f6ac
Move type check.
andrewtarzia Oct 3, 2024
859351f
Remove unnecessary files.
andrewtarzia Oct 3, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
cache: 'npm'
- uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
- name: configure access to git repositories in package-lock.json
run: git config --global url."https://github.com/".insteadOf ssh://[email protected]
- name: install npm dependencies
Expand Down
6 changes: 6 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ numpy
ipywidgets
matplotlib
ase==3.22.1
# These three pins are to avoid rdkit version 2024.3.5. Once a later version
# is available, the latest version (assuming Python >= 3.11) of all three
# should be ok.
rdkit==2023.9.5
stk==2024.9.23.1
stko==2024.8.29.1
Luthaf marked this conversation as resolved.
Show resolved Hide resolved

# required for the examples of chemiscope.explore
mace-torch
Expand Down
2 changes: 2 additions & 0 deletions docs/src/python/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
.. autofunction:: chemiscope.explore

.. autofunction:: chemiscope.metatensor_featurizer

.. autofunction:: chemiscope.convert_stk_bonds_as_shapes
4 changes: 4 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import chemiscope
import ase.io

# read frames using ase
# frames can also be stk objets, e.g.
# frames = [stk.BuildingBlock(smiles="NCCN")]
frames = ase.io.read("structures.xyz", ":")

# add additional properties to display
Expand All @@ -44,6 +46,8 @@ import chemiscope
import ase.io

# read frames using ase
# frames can also be stk objets, e.g.
# frames = [stk.BuildingBlock(smiles="NCCN")]
frames = ase.io.read("structures.xyz", ":")

# add additional properties to display
Expand Down
1 change: 1 addition & 0 deletions python/chemiscope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ellipsoid_from_tensor,
extract_properties,
librascal_atomic_environments,
convert_stk_bonds_as_shapes,
)
from .explore import explore, metatensor_featurizer # noqa: F401
from .version import __version__ # noqa: F401
Expand Down
3 changes: 3 additions & 0 deletions python/chemiscope/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Generate JSON input files for the default chemiscope visualizer.
"""

import gzip
import json
import os
Expand Down Expand Up @@ -282,6 +283,7 @@ def create_input(
data["structures"] = frames_to_json(frames)
n_structures = len(data["structures"])
n_atoms = sum(s["size"] for s in data["structures"])

else:
n_atoms = 0

Expand Down Expand Up @@ -378,6 +380,7 @@ def create_input(
# should be removed in version 0.6 of chemiscope.
if frames is not None:
found_one_from_frame = False

atom_properties = _list_atom_properties(frames)
for name in atom_properties:
if name in data["properties"]:
Expand Down
2 changes: 1 addition & 1 deletion python/chemiscope/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def show_input(path, mode="default"):
try:
meta = dict_input["meta"]

if meta is {"name": " "}:
if meta == {"name": " "}:
Luthaf marked this conversation as resolved.
Show resolved Hide resolved
has_metadata = False
else:
has_metadata = True
Expand Down
32 changes: 32 additions & 0 deletions python/chemiscope/structures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
ase_tensors_to_ellipsoids,
ase_vectors_to_arrows,
)
from ._stk import ( # noqa: F401
_stk_valid_structures,
_stk_to_json,
convert_stk_bonds_as_shapes,
_stk_all_atomic_environments,
_stk_composition_properties,
_stk_list_atom_properties,
_stk_list_structure_properties,
)


def _guess_adapter(frames):
Expand All @@ -32,6 +41,10 @@ def _guess_adapter(frames):
if use_ase:
return ase_frames, "ASE"

stk_frames, use_stk = _stk_valid_structures(frames)
if use_stk:
return stk_frames, "stk"

raise Exception(f"unknown frame type: '{frames[0].__class__.__name__}'")


Expand All @@ -48,6 +61,8 @@ def frames_to_json(frames):

if adapter == "ASE":
return [_ase_to_json(frame) for frame in frames]
elif adapter == "stk":
return [_stk_to_json(frame) for frame in frames]
else:
raise Exception("reached unreachable code")

Expand All @@ -62,6 +77,9 @@ def _list_atom_properties(frames):

if adapter == "ASE":
return _ase_list_atom_properties(frames)
elif adapter == "stk":
return _stk_list_atom_properties(frames)

else:
raise Exception("reached unreachable code")

Expand All @@ -76,6 +94,8 @@ def _list_structure_properties(frames):

if adapter == "ASE":
return _ase_list_structure_properties(frames)
elif adapter == "stk":
return _stk_list_structure_properties(frames)
else:
raise Exception("reached unreachable code")

Expand All @@ -96,6 +116,12 @@ def extract_properties(frames, only=None, environments=None):

if adapter == "ASE":
return _ase_extract_properties(frames, only, environments)

elif adapter == "stk":
raise RuntimeError(
"stk molecules do not contain properties, you must manually provide them"
)

else:
raise Exception("reached unreachable code")

Expand All @@ -119,6 +145,10 @@ def composition_properties(frames, environments=None):

if adapter == "ASE":
return _ase_composition_properties(frames, environments)

elif adapter == "stk":
return _stk_composition_properties(frames, environments)

else:
raise Exception("reached unreachable code")

Expand All @@ -137,6 +167,8 @@ def all_atomic_environments(frames, cutoff=3.5):

if adapter == "ASE":
return _ase_all_atomic_environments(frames, cutoff)
elif adapter == "stk":
return _stk_all_atomic_environments(frames, cutoff)
else:
raise Exception("reached unreachable code")

Expand Down
6 changes: 5 additions & 1 deletion python/chemiscope/structures/_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@


def _ase_valid_structures(frames):
frames_list = list(frames)
try:
frames_list = list(frames)
except TypeError:
return [], False

if HAVE_ASE and isinstance(frames_list[0], ase.Atoms):
for frame in frames_list:
assert isinstance(frame, ase.Atoms)
Expand Down
Loading
Loading