Skip to content

Commit b0f1f7a

Browse files
committed
Merge branch 'ml-evs/fix-bad-entries' into ml-evs/smarts-prototyping
2 parents f97519d + 8bd9116 commit b0f1f7a

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ jobs:
5252

5353
steps:
5454
- uses: actions/checkout@v4
55-
with:
56-
submodules: true
57-
fetch-depth: 2
58-
59-
- uses: docker/setup-buildx-action@v3
60-
with:
61-
buildkitd-flags: --debug
6255

6356
- uses: docker/login-action@v3
6457
with:
@@ -75,6 +68,18 @@ jobs:
7568
sudo apt autoclean -y
7669
sudo rm -rf /swapfile /usr/share/dotnet /usr/local/lib/android /opt/ghc
7770
df -h
71+
sudo rm -rf "$AGENT_TOOLSDIRECTORY" \
72+
/opt/google/chrome \
73+
/opt/microsoft/msedge \
74+
/opt/microsoft/powershell \
75+
/opt/pipx \
76+
/usr/lib/mono \
77+
/usr/local/julia* \
78+
/usr/local/lib/node_modules \
79+
/usr/local/share/chromium \
80+
/usr/local/share/powershell \
81+
/usr/share/swift
82+
df -h
7883
7984
- name: Build latest changes
8085
uses: docker/bake-action@v6

src/csd_optimade/mappers.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math
55
import random
66
import string
7+
import warnings
78
from typing import TYPE_CHECKING
89

910
if TYPE_CHECKING:
@@ -38,6 +39,9 @@ def _reduce_csd_formula(formula: str) -> str:
3839
f"{e}{formula_dct[e] // reducer if formula_dct[e] != reducer else ''}"
3940
)
4041

42+
if not formula_str:
43+
raise RuntimeError(f"Unable to create formula for {formula}")
44+
4145
return formula_str
4246

4347

@@ -49,7 +53,15 @@ def from_csd_entry_directly(
4953
5054
"""
5155
asym_unit = entry.crystal.asymmetric_unit_molecule
56+
5257
elements = {d.atomic_symbol for d in asym_unit.atoms}
58+
59+
optimade_elements = elements.copy()
60+
# Replace deuterium with H
61+
if "D" in elements:
62+
optimade_elements.remove("D")
63+
optimade_elements.add("H")
64+
5365
try:
5466
positions = [
5567
[atom.coordinates.x, atom.coordinates.y, atom.coordinates.z]
@@ -110,6 +122,14 @@ def _get_citations(entry) -> list[ReferenceResource]:
110122
if not inchi.success:
111123
inchi = None
112124

125+
try:
126+
reduced_formula = _reduce_csd_formula(asym_unit.formula)
127+
except Exception:
128+
warnings.warn(
129+
f"Unable to reduce formula for {entry.identifier}: {entry.formula}"
130+
)
131+
reduced_formula = None
132+
113133
resource = StructureResource(
114134
**{
115135
"id": entry.identifier,
@@ -121,14 +141,19 @@ def _get_citations(entry) -> list[ReferenceResource]:
121141
"attributes": StructureResourceAttributes(
122142
last_modified=now,
123143
chemical_formula_descriptive=entry.formula,
124-
chemical_formula_reduced=_reduce_csd_formula(asym_unit.formula),
125-
elements=sorted(list(elements)),
144+
chemical_formula_reduced=reduced_formula,
145+
elements=sorted(list(optimade_elements)),
126146
dimension_types=(1, 1, 1),
127147
nperiodic_dimensions=3,
128-
nelements=len(elements),
148+
nelements=len(optimade_elements),
129149
nsites=len(positions) if positions else None,
150+
# Make sure the "D" is remapped to "H" in the species list, but continue using it in the sites list
130151
species=[
131-
Species(chemical_symbols=[e], name=e, concentration=[1.0])
152+
Species(
153+
chemical_symbols=[e if e != "D" else "H"],
154+
name=e,
155+
concentration=[1.0],
156+
)
132157
for e in elements
133158
]
134159
if positions

0 commit comments

Comments
 (0)