forked from deepmodeling/dpdata
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformat.py
More file actions
116 lines (90 loc) · 3.31 KB
/
Copy pathformat.py
File metadata and controls
116 lines (90 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Implement the format plugin system."""
import os
from collections import abc
from abc import ABC
from .plugin import Plugin
class Format(ABC):
__FormatPlugin = Plugin()
__FromPlugin = Plugin()
__ToPlugin = Plugin()
@staticmethod
def register(key):
return Format.__FormatPlugin.register(key)
@staticmethod
def register_from(key):
return Format.__FromPlugin.register(key)
@staticmethod
def register_to(key):
return Format.__ToPlugin.register(key)
@staticmethod
def get_formats():
return Format.__FormatPlugin.plugins
@staticmethod
def get_from_methods():
return Format.__FromPlugin.plugins
@staticmethod
def get_to_methods():
return Format.__ToPlugin.plugins
@staticmethod
def post(func_name):
def decorator(object):
if not isinstance(func_name, (list, tuple, set)):
object.post_func = (func_name,)
else:
object.post_func = func_name
return object
return decorator
def from_system(self, file_name, **kwargs):
"""System.from
Parameters
----------
file_name: str
file name
Returns
-------
data: dict
system data
"""
raise NotImplementedError("%s doesn't support System.from" %(self.__class__.__name__))
def to_system(self, data, *args, **kwargs):
"""System.to
Parameters
----------
data: dict
system data
"""
raise NotImplementedError("%s doesn't support System.to" %(self.__class__.__name__))
def from_labeled_system(self, file_name, **kwargs):
raise NotImplementedError("%s doesn't support LabeledSystem.from" %(self.__class__.__name__))
def to_labeled_system(self, data, *args, **kwargs):
return self.to_system(data, *args, **kwargs)
def from_bond_order_system(self, file_name, **kwargs):
raise NotImplementedError("%s doesn't support BondOrderSystem.from" %(self.__class__.__name__))
def to_bond_order_system(self, data, rdkit_mol, *args, **kwargs):
return self.to_system(data, *args, **kwargs)
class MultiModes:
"""File mode for MultiSystems
0 (default): not implemented
1: every directory under the top-level directory is a system
"""
NotImplemented = 0
Directory = 1
MultiMode = MultiModes.NotImplemented
def from_multi_systems(self, directory, **kwargs):
"""MultiSystems.from
Parameters
----------
directory: str
directory of system
Returns
-------
filenames: list[str]
list of filenames
"""
if self.MultiMode == self.MultiModes.Directory:
return [os.path.join(directory, name) for name in os.listdir(directory) if os.path.isdir(os.path.join(directory, name))]
raise NotImplementedError("%s doesn't support MultiSystems.from" %(self.__class__.__name__))
def to_multi_systems(self, formulas, directory, **kwargs):
if self.MultiMode == self.MultiModes.Directory:
return [os.path.join(directory, ff) for ff in formulas]
raise NotImplementedError("%s doesn't support MultiSystems.to" %(self.__class__.__name__))