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 Jan 13, 2025
1 parent 79f74f3 commit b6d7db9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions dpdata/abacus/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def get_coords_from_dump(dumplines, natoms):
if "VIRIAL" in dumplines[6]:
calc_stress = True
check_line = 10
assert (
"POSITION" in dumplines[check_line]
), "keywords 'POSITION' cannot be found in the 6th line. Please check."
assert "POSITION" in dumplines[check_line], (
"keywords 'POSITION' cannot be found in the 6th line. Please check."
)
if "FORCE" in dumplines[check_line]:
calc_force = True

Expand Down
6 changes: 3 additions & 3 deletions dpdata/deepmd/mixed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def to_system_data(folder, type_map=None, labels=True):
if type_map is not None:
assert isinstance(type_map, list)
missing_type = [i for i in old_type_map if i not in type_map]
assert (
not missing_type
), f"These types are missing in selected type_map: {missing_type} !"
assert not missing_type, (
f"These types are missing in selected type_map: {missing_type} !"
)
index_map = np.array([type_map.index(i) for i in old_type_map])
data["atom_names"] = type_map.copy()
else:
Expand Down
18 changes: 9 additions & 9 deletions dpdata/plugins/n2p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,18 @@ def from_labeled_system(self, file_name: FileType, **kwargs):
energy = None
elif line.lower() == "end":
# If we are at the end of a section, process the section
assert (
len(coord) == len(atype) == len(force)
), "Number of atoms, atom types, and forces must match."
assert len(coord) == len(atype) == len(force), (
"Number of atoms, atom types, and forces must match."
)

# Check if the number of atoms is consistent across all frames
natom = len(coord)
if natom0 is None:
natom0 = natom
else:
assert (
natom == natom0
), "The number of atoms in all frames must be the same."
assert natom == natom0, (
"The number of atoms in all frames must be the same."
)

# Check if the number of atoms of each type is consistent across all frames
atype = np.array(atype)
Expand All @@ -108,9 +108,9 @@ def from_labeled_system(self, file_name: FileType, **kwargs):
if natoms0 is None:
natoms0 = natoms
else:
assert (
natoms == natoms0
), "The number of atoms of each type in all frames must be the same."
assert natoms == natoms0, (
"The number of atoms of each type in all frames must be the same."
)
if atom_types0 is None:
atom_types0 = atype
atom_order = match_indices(atom_types0, atype)
Expand Down
12 changes: 6 additions & 6 deletions dpdata/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class ErrorsBase(metaclass=ABCMeta):
SYSTEM_TYPE = object

def __init__(self, system_1: SYSTEM_TYPE, system_2: SYSTEM_TYPE) -> None:
assert isinstance(
system_1, self.SYSTEM_TYPE
), f"system_1 should be {self.SYSTEM_TYPE.__name__}"
assert isinstance(
system_2, self.SYSTEM_TYPE
), f"system_2 should be {self.SYSTEM_TYPE.__name__}"
assert isinstance(system_1, self.SYSTEM_TYPE), (
f"system_1 should be {self.SYSTEM_TYPE.__name__}"
)
assert isinstance(system_2, self.SYSTEM_TYPE), (
f"system_2 should be {self.SYSTEM_TYPE.__name__}"
)
self.system_1 = system_1
self.system_2 = system_2

Expand Down
6 changes: 3 additions & 3 deletions dpdata/vasp/outcar.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ def analyze_block(lines, ntot, nelm, ml=False):
not lines[idx + in_kB_index].split()[0:2] == ["in", "kB"]
):
in_kB_index += 1
assert idx + in_kB_index < len(
lines
), 'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.'
assert idx + in_kB_index < len(lines), (
'ERROR: "in kB" is not found in OUTCAR. Unable to extract virial.'
)
tmp_v = [float(ss) for ss in lines[idx + in_kB_index].split()[2:8]]
virial = np.zeros([3, 3])
virial[0][0] = tmp_v[0]
Expand Down
6 changes: 3 additions & 3 deletions dpdata/vasp/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@


def check_name(item, name):
assert (
item.attrib["name"] == name
), "item attrib '{}' dose not math required '{}'".format(item.attrib["name"], name)
assert item.attrib["name"] == name, (
"item attrib '{}' dose not math required '{}'".format(item.attrib["name"], name)
)


def get_varray(varray):
Expand Down
24 changes: 12 additions & 12 deletions tests/comp_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ def _make_comp_ms_test_func(comp_sys_test_func):
"""

def comp_ms_test_func(iobj):
assert hasattr(iobj, "ms_1") and hasattr(
iobj, "ms_2"
), "Multi-system objects must be present"
assert hasattr(iobj, "ms_1") and hasattr(iobj, "ms_2"), (
"Multi-system objects must be present"
)
iobj.assertEqual(len(iobj.ms_1), len(iobj.ms_2))
keys = [ii.formula for ii in iobj.ms_1]
keys_2 = [ii.formula for ii in iobj.ms_2]
assert sorted(keys) == sorted(
keys_2
), f"Keys of two MS are not equal: {keys} != {keys_2}"
assert sorted(keys) == sorted(keys_2), (
f"Keys of two MS are not equal: {keys} != {keys_2}"
)
for kk in keys:
iobj.system_1 = iobj.ms_1[kk]
iobj.system_2 = iobj.ms_2[kk]
Expand Down Expand Up @@ -197,17 +197,17 @@ def test_is_nopbc(self):

class MSAllIsPBC:
def test_is_pbc(self):
assert hasattr(self, "ms_1") and hasattr(
self, "ms_2"
), "Multi-system objects must be present and iterable"
assert hasattr(self, "ms_1") and hasattr(self, "ms_2"), (
"Multi-system objects must be present and iterable"
)
self.assertTrue(all([not ss.nopbc for ss in self.ms_1]))
self.assertTrue(all([not ss.nopbc for ss in self.ms_2]))


class MSAllIsNoPBC:
def test_is_nopbc(self):
assert hasattr(self, "ms_1") and hasattr(
self, "ms_2"
), "Multi-system objects must be present and iterable"
assert hasattr(self, "ms_1") and hasattr(self, "ms_2"), (
"Multi-system objects must be present and iterable"
)
self.assertTrue(all([ss.nopbc for ss in self.ms_1]))
self.assertTrue(all([ss.nopbc for ss in self.ms_2]))

0 comments on commit b6d7db9

Please sign in to comment.