From 47516d0a1cbedf11c56246a0ae78621a5c54102c Mon Sep 17 00:00:00 2001 From: Ziyang HU Date: Thu, 7 Sep 2023 09:34:44 +0800 Subject: [PATCH] Reformatted to confront with pre-commit --- chgnet/model/dynamics.py | 2 +- tests/test_md.py | 60 +++++++++++++++++++++------------------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/chgnet/model/dynamics.py b/chgnet/model/dynamics.py index 738cbdf2..7755e651 100644 --- a/chgnet/model/dynamics.py +++ b/chgnet/model/dynamics.py @@ -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, diff --git a/tests/test_md.py b/tests/test_md.py index a8f23f1c..b417a7f2 100644 --- a/tests/test_md.py +++ b/tests/test_md.py @@ -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 @@ -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 @@ -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() @@ -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() @@ -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) -