Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 14, 2023
1 parent 22ead58 commit 0b6f4ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 15 additions & 5 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
from dpdata.driver import Driver, Minimizer
from dpdata.format import Format
from dpdata.plugin import Plugin
from dpdata.utils import add_atom_names, elements_index_map, remove_pbc, sort_atom_names, utf8len
from dpdata.utils import (
add_atom_names,
elements_index_map,
remove_pbc,
sort_atom_names,
utf8len,
)


def load_format(fmt):
Expand Down Expand Up @@ -566,13 +572,15 @@ def uniq_formula(self):
@property
def short_formula(self) -> str:
"""Return the short formula of this system. Elements with zero number
will be removed."""
will be removed.
"""
return "".join(
[
f"{symbol}{numb}"
for symbol, numb in zip(
self.data["atom_names"], self.data["atom_numbs"]
) if numb
)
if numb
]
)

Expand All @@ -587,7 +595,7 @@ def short_name(self) -> str:
the following order:
- formula
- short_formula
- formula_hash
- formula_hash.
"""
formula = self.formula
if utf8len(formula) <= 255:
Expand Down Expand Up @@ -1282,7 +1290,9 @@ def from_fmt_obj(self, fmtobj, directory, labeled=True, **kwargs):
def to_fmt_obj(self, fmtobj, directory, *args, **kwargs):
if not isinstance(fmtobj, dpdata.plugins.deepmd.DeePMDMixedFormat):
for fn, ss in zip(
fmtobj.to_multi_systems([ss.short_name for ss in self.systems.values()], directory, **kwargs),
fmtobj.to_multi_systems(
[ss.short_name for ss in self.systems.values()], directory, **kwargs
),
self.systems.values(),
):
ss.to_fmt_obj(fmtobj, fn, *args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion dpdata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def uniq_atom_names(data):

def utf8len(s: str) -> int:
"""Return the byte length of a string."""
return len(s.encode('utf-8'))
return len(s.encode("utf-8"))
6 changes: 3 additions & 3 deletions tests/test_multisystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from itertools import permutations

import numpy as np

from comp_sys import CompLabeledSys, IsNoPBC, MultiSystems
from context import dpdata

Expand Down Expand Up @@ -206,7 +205,7 @@ def setUp(self):
class TestLongFilename(unittest.TestCase):
def test_long_filename1(self):
system = dpdata.System(
data = {
data={
"atom_names": [f"TYPE{ii}" for ii in range(200)],
"atom_numbs": [1] + [0 for _ in range(199)],
"atom_types": np.arange(1),
Expand All @@ -221,7 +220,7 @@ def test_long_filename1(self):

def test_long_filename2(self):
system = dpdata.System(
data = {
data={
"atom_names": [f"TYPE{ii}" for ii in range(200)],
"atom_numbs": [1 for _ in range(200)],
"atom_types": np.arange(200),
Expand All @@ -234,5 +233,6 @@ def test_long_filename2(self):
with tempfile.TemporaryDirectory() as tmpdir:
ms.to_deepmd_npy(tmpdir)


if __name__ == "__main__":
unittest.main()

0 comments on commit 0b6f4ee

Please sign in to comment.