Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: v0.0.243
rev: v0.0.262
hooks:
- id: ruff
args: ["--fix"]
Expand Down
2 changes: 1 addition & 1 deletion dpdata/plugins/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def from_multi_systems(
yield from frames

def to_system(self, data, **kwargs):
"""convert System to ASE Atom obj."""
"""Convert System to ASE Atom obj."""
from ase import Atoms

structures = []
Expand Down
2 changes: 1 addition & 1 deletion dpdata/plugins/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@Format.register("list")
class ListFormat(Format):
def to_system(self, data, **kwargs):
"""convert system to list, usefull for data collection."""
"""Convert system to list, usefull for data collection."""
from dpdata import LabeledSystem, System

if "forces" in data:
Expand Down
6 changes: 3 additions & 3 deletions dpdata/plugins/pymatgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Format.register("pymatgen/structure")
class PyMatgenStructureFormat(Format):
def to_system(self, data, **kwargs):
"""convert System to Pymatgen Structure obj."""
"""Convert System to Pymatgen Structure obj."""
structures = []
try:
from pymatgen.core import Structure
Expand Down Expand Up @@ -40,7 +40,7 @@ def from_system(self, file_name, **kwargs):
return dpdata.pymatgen.molecule.to_system_data(file_name)

def to_system(self, data, **kwargs):
"""convert System to Pymatgen Molecule obj."""
"""Convert System to Pymatgen Molecule obj."""
molecules = []
try:
from pymatgen.core import Molecule
Expand All @@ -61,7 +61,7 @@ def to_system(self, data, **kwargs):
@Format.register_to("to_pymatgen_ComputedStructureEntry")
class PyMatgenCSEFormat(Format):
def to_labeled_system(self, data, *args, **kwargs):
"""convert System to Pymagen ComputedStructureEntry obj."""
"""Convert System to Pymagen ComputedStructureEntry obj."""
try:
from pymatgen.entries.computed_entries import ComputedStructureEntry
except ModuleNotFoundError as e:
Expand Down
19 changes: 8 additions & 11 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def check(self, system: "System"):
pass
elif not isinstance(data, self.dtype):
raise DataError(
"Type of %s is %s, but expected %s"
% (self.name, type(data).__name__, self.dtype.__name__)
f"Type of {self.name} is {type(data).__name__}, but expected {self.dtype.__name__}"
)
# check shape
if self.shape is not None:
Expand All @@ -126,8 +125,7 @@ def check(self, system: "System"):
if isinstance(data, np.ndarray):
if data.size and shape != data.shape:
raise DataError(
"Shape of %s is %s, but expected %s"
% (self.name, data.shape, shape)
f"Shape of {self.name} is {data.shape}, but expected {shape}"
)
elif isinstance(data, list):
if len(shape) and shape[0] != len(data):
Expand Down Expand Up @@ -381,7 +379,7 @@ def __len__(self):
return self.get_nframes()

def __add__(self, others):
"""magic method "+" operation."""
"""Magic method "+" operation."""
self_copy = self.copy()
if isinstance(others, System):
other_copy = others.copy()
Expand All @@ -396,7 +394,7 @@ def __add__(self, others):
return self.__class__.from_dict({"data": self_copy.data})

def dump(self, filename, indent=4):
"""dump .json or .yaml file."""
"""Dump .json or .yaml file."""
dumpfn(self.as_dict(), filename, indent=indent)

def map_atom_types(self, type_map=None) -> np.ndarray:
Expand Down Expand Up @@ -439,7 +437,7 @@ def map_atom_types(self, type_map=None) -> np.ndarray:

@staticmethod
def load(filename):
"""rebuild System obj. from .json or .yaml file."""
"""Rebuild System obj. from .json or .yaml file."""
return loadfn(filename)

def as_dict(self):
Expand Down Expand Up @@ -527,8 +525,7 @@ def append(self, system):
return False
if system.uniq_formula != self.uniq_formula:
raise RuntimeError(
"systems with inconsistent formula could not be append: %s v.s. %s"
% (self.uniq_formula, system.uniq_formula)
f"systems with inconsistent formula could not be append: {self.uniq_formula} v.s. {system.uniq_formula}"
)
if system.data["atom_names"] != self.data["atom_names"]:
# allow to append a system with different atom_names order
Expand Down Expand Up @@ -1193,7 +1190,7 @@ def __str__(self):
return ret

def __add__(self, others):
"""magic method "+" operation."""
"""Magic method "+" operation."""
self_copy = self.copy()
if isinstance(others, LabeledSystem):
other_copy = others.copy()
Expand Down Expand Up @@ -1389,7 +1386,7 @@ def __str__(self):
)

def __add__(self, others):
"""magic method "+" operation."""
"""Magic method "+" operation."""
self_copy = deepcopy(self)
if isinstance(others, System) or isinstance(others, MultiSystems):
return self.__class__(self, others)
Expand Down