Skip to content
Merged
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
16 changes: 16 additions & 0 deletions dpdata/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,20 @@ def pick_atom_idx(self, idx, nopbc=None):
new_sys.append(ss.pick_atom_idx(idx, nopbc=nopbc))
return new_sys

def get_cls_name(cls: object) -> str:
"""Returns the fully qualified name of a class, such as `np.ndarray`.

Parameters
----------
cls : object
the class

Returns
-------
str
the fully qualified name of a class
"""
return ".".join([cls.__module__, cls.__name__])

def add_format_methods():
"""Add format methods to System, LabeledSystem, and MultiSystems.
Expand All @@ -1237,6 +1251,7 @@ def get_func(ff):
# ff is not initized when defining from_format so cannot be polluted
def from_format(self, file_name, **kwargs):
return self.from_fmt_obj(ff(), file_name, **kwargs)
from_format.__doc__ = "Read data from :class:`%s` format." % (get_cls_name(ff))
return from_format

setattr(System, method, get_func(formatcls))
Expand All @@ -1247,6 +1262,7 @@ def from_format(self, file_name, **kwargs):
def get_func(ff):
def to_format(self, *args, **kwargs):
return self.to_fmt_obj(ff(), *args, **kwargs)
to_format.__doc__ = "Dump data to :class:`%s` format." % (get_cls_name(ff))
return to_format

setattr(System, method, get_func(formatcls))
Expand Down