Skip to content

Commit

Permalink
Reformatted to confront with pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ziyang HU committed Sep 7, 2023
1 parent c1ee5e8 commit 47516d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion chgnet/model/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def __init__(
see: https://gitlab.com/ase/ase/-/blob/master/ase/md/npt.py
ASE implementation currently only supports upper triangular lattice
"""
ptime=taup * units.fs
ptime = taup * units.fs
self.dyn = NPT(
atoms=self.atoms,
timestep=timestep * units.fs,
Expand Down
60 changes: 31 additions & 29 deletions tests/test_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pickle
from typing import TYPE_CHECKING, Literal

import numpy as np
import pytest
from ase import Atoms
from ase.md.nptberendsen import Inhomogeneous_NPTBerendsen
Expand All @@ -18,8 +19,6 @@
from chgnet.model.dynamics import CHGNetCalculator, EquationOfState, MolecularDynamics
from chgnet.model.model import CHGNet

import numpy as np

if TYPE_CHECKING:
from pathlib import Path

Expand Down Expand Up @@ -72,20 +71,22 @@ def test_md_nvt(
with open("md_out.log") as log_file:
next(log_file)
logs = log_file.read()
logs = np.fromstring(logs, dtype=float, sep=' ')
logs = np.fromstring(logs, dtype=float, sep=" ")
ref = np.fromstring(
"0.0000 -58.9727 -58.9727 0.0000 0.0\n"
"0.0200 -58.9723 -58.9731 0.0009 0.8\n"
"0.0400 -58.9672 -58.9727 0.0055 5.4\n"
"0.0600 -58.9427 -58.9663 0.0235 22.8\n"
"0.0800 -58.8605 -58.9352 0.0747 72.2\n"
"0.1000 -58.7651 -58.8438 0.0786 76.0\n"
"0.1200 -58.6684 -58.7268 0.0584 56.4\n"
"0.1400 -58.5703 -58.6202 0.0499 48.2\n"
"0.1600 -58.4724 -58.5531 0.0807 78.1\n"
"0.1800 -58.3891 -58.8077 0.4186 404.8\n"
"0.2000 -58.3398 -58.9244 0.5846 565.4\n",
dtype=float, sep=' ')
"0.0000 -58.9727 -58.9727 0.0000 0.0\n"
"0.0200 -58.9723 -58.9731 0.0009 0.8\n"
"0.0400 -58.9672 -58.9727 0.0055 5.4\n"
"0.0600 -58.9427 -58.9663 0.0235 22.8\n"
"0.0800 -58.8605 -58.9352 0.0747 72.2\n"
"0.1000 -58.7651 -58.8438 0.0786 76.0\n"
"0.1200 -58.6684 -58.7268 0.0584 56.4\n"
"0.1400 -58.5703 -58.6202 0.0499 48.2\n"
"0.1600 -58.4724 -58.5531 0.0807 78.1\n"
"0.1800 -58.3891 -58.8077 0.4186 404.8\n"
"0.2000 -58.3398 -58.9244 0.5846 565.4\n",
dtype=float,
sep=" ",
)
assert np.isclose(logs, ref, rtol=2.1e-3, atol=1e-8).all()


Expand Down Expand Up @@ -143,20 +144,22 @@ def test_md_npt_inhomogeneous_berendsen(tmp_path: Path, monkeypatch: MonkeyPatch
with open("md_out.log") as log_file:
next(log_file)
logs = log_file.read()
logs = np.fromstring(logs, dtype=float, sep=' ')
logs = np.fromstring(logs, dtype=float, sep=" ")
ref = np.fromstring(
"0.0000 -58.9727 -58.9727 0.0000 0.0\n"
"0.0200 -58.9723 -58.9731 0.0009 0.8\n"
"0.0400 -58.9672 -58.9727 0.0055 5.3\n"
"0.0600 -58.9427 -58.9663 0.0235 22.7\n"
"0.0800 -58.8605 -58.9352 0.0747 72.2\n"
"0.1000 -58.7652 -58.8438 0.0786 76.0\n"
"0.1200 -58.6686 -58.7269 0.0584 56.4\n"
"0.1400 -58.5707 -58.6205 0.0499 48.2\n"
"0.1600 -58.4731 -58.5533 0.0802 77.6\n"
"0.1800 -58.3897 -58.8064 0.4167 402.9\n"
"0.2000 -58.3404 -58.9253 0.5849 565.6\n",
dtype=float, sep=' ')
"0.0000 -58.9727 -58.9727 0.0000 0.0\n"
"0.0200 -58.9723 -58.9731 0.0009 0.8\n"
"0.0400 -58.9672 -58.9727 0.0055 5.3\n"
"0.0600 -58.9427 -58.9663 0.0235 22.7\n"
"0.0800 -58.8605 -58.9352 0.0747 72.2\n"
"0.1000 -58.7652 -58.8438 0.0786 76.0\n"
"0.1200 -58.6686 -58.7269 0.0584 56.4\n"
"0.1400 -58.5707 -58.6205 0.0499 48.2\n"
"0.1600 -58.4731 -58.5533 0.0802 77.6\n"
"0.1800 -58.3897 -58.8064 0.4167 402.9\n"
"0.2000 -58.3404 -58.9253 0.5849 565.6\n",
dtype=float,
sep=" ",
)
assert np.isclose(logs, ref, rtol=2.1e-3, atol=1e-8).all()


Expand Down Expand Up @@ -191,4 +194,3 @@ def test_md_crystal_feas_log(
assert crystal_feas[0][1] == approx(2.652704, rel=1e-5)
assert crystal_feas[10][0] == approx(1.4390125, rel=1e-5)
assert crystal_feas[10][1] == approx(2.6525214, rel=1e-5)

0 comments on commit 47516d0

Please sign in to comment.