Skip to content

Commit 4e5a96e

Browse files
authored
enable convert_nan API (#690)
* enable `convert_nan` API * fix lock
1 parent 51bbd71 commit 4e5a96e

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

poetry.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ celery = "^5"
2323
sqlalchemy = "^2"
2424
redis = "^5"
2525
splines = "^0.3"
26-
znsocket = "^0.2.6"
26+
znsocket = "^0.2.7"
2727
znjson = "^0.2.4"
2828

2929

zndraw/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class FileIO:
9898
step: int = 1
9999
remote: str | None = None
100100
rev: str | None = None
101+
convert_nan: bool = False
101102

102103
def to_dict(self):
103104
return dataclasses.asdict(self)

zndraw/tasks/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def read_file(fileio: dict) -> None:
122122
r=current_app.extensions["redis"],
123123
url=current_app.config["SERVER_URL"],
124124
token="default",
125+
convert_nan=file_io.convert_nan,
125126
)
126127
bonds_calculator = ASEComputeBonds()
127128
if current_app.config.get("COMPUTE_BONDS", False):

zndraw/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def upload(
2525
"""Upload a file to ZnDraw."""
2626
if token is None:
2727
token = str(uuid.uuid4())
28-
vis = ZnDraw(url=url, token=token)
28+
vis = ZnDraw(url=url, token=token, convert_nan=fileio.convert_nan)
2929
typer.echo(f"Uploading to: {url}/token/{vis.token}")
3030

3131
if not append:

zndraw/zndraw.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class ZnDraw(ZnDrawBase):
146146
)
147147
)
148148
verify: bool | str = True
149+
convert_nan: bool = False
149150

150151
max_atoms_per_call: int = dataclasses.field(default=1000, repr=False)
151152
# number of `ase.Atom` to send per call
@@ -256,6 +257,7 @@ def __setitem__(
256257
converter=[ASEConverter],
257258
socket=self._refresh_client,
258259
max_commands_per_call=100,
260+
convert_nan=self.convert_nan,
259261
)
260262
if not self.r.exists(f"room:{self.token}:frames") and self.r.exists(
261263
"room:default:frames"
@@ -345,6 +347,7 @@ def insert(self, index: int, value: ase.Atoms):
345347
f"room:{self.token}:frames",
346348
converter=[ASEConverter],
347349
socket=self._refresh_client,
350+
convert_nan=self.convert_nan,
348351
)
349352
if not self.r.exists(f"room:{self.token}:frames") and self.r.exists(
350353
"room:default:frames"
@@ -392,6 +395,7 @@ def extend(self, values: list[ase.Atoms]):
392395
converter=[ASEConverter],
393396
socket=self._refresh_client,
394397
max_commands_per_call=100,
398+
convert_nan=self.convert_nan,
395399
)
396400
# TODO: why is there no copy action here?
397401
show_tbar = (len(values[0]) * len(values)) > self.max_atoms_per_call
@@ -463,6 +467,7 @@ def log(self, message: str) -> None:
463467
f"room:{self.token}:chat",
464468
socket=self._refresh_client,
465469
max_commands_per_call=100,
470+
convert_nan=self.convert_nan,
466471
).append(msg)
467472

468473
@property

zndraw_app/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def main(
124124
plots: list[str] = typer.Option(
125125
None, "--plots", "-p", help="List of plots to be shown in the ZnDraw GUI."
126126
),
127+
convert_nan: bool = typer.Option(
128+
False,
129+
help="Convert NaN values to None. This is slow and experimental, but if your file contains NaN/inf values, it is required.",
130+
envvar="ZNDRAW_CONVERT_NAN",
131+
),
127132
):
128133
"""Start the ZnDraw server.
129134
@@ -187,6 +192,7 @@ def main(
187192
start=start,
188193
stop=stop,
189194
step=step,
195+
convert_nan=convert_nan,
190196
)
191197

192198
if url is not None:

0 commit comments

Comments
 (0)