Skip to content

Commit 8c70129

Browse files
committed
from_file for gap/xyz
1 parent 56a36e4 commit 8c70129

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ Now Class dpdata.MultiSystems Only support gap/quip xyz format file.
5959
The following commands relating to `Class dpdata.MultiSystems` may be useful.
6060
```python
6161
# load data
62-
# note that the prefix 'file_name=' and 'fmt=' can NOT be omitted
63-
xyz_multi_systems = dpdata.MultiSystems(file_name='xyz_unittest.xyz', fmt='gap/xyz')
62+
# note that in the second case the prefix 'file_name=' and 'fmt=' can NOT be omitted
63+
xyz_multi_systems = dpdata.MultiSystems.from_file('tests/xyz/xyz_unittest.xyz','gap/xyz')
64+
xyz_multi_systems = dpdata.MultiSystems(file_name='tests/syz/xyz_unittest.xyz', fmt='gap/xyz')
6465

6566
# print the multi_system infomation
6667
print(xyz_multi_systems)

dpdata/system.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def sort_atom_types(self):
905905
class MultiSystems:
906906
'''A set containing several systems.'''
907907

908-
def __init__(self, *systems, type_map=None,file_name=None, fmt=None):
908+
def __init__(self, *systems,file_name=None, fmt=None,type_map=None):
909909
"""
910910
Parameters
911911
----------
@@ -914,9 +914,6 @@ def __init__(self, *systems, type_map=None,file_name=None, fmt=None):
914914
type_map : list of str
915915
Maps atom type to name
916916
"""
917-
if all(type(ii)==str for ii in systems) and len(systems)>0:
918-
raise RuntimeError("the prefix 'file_name=' and 'fmt=' can not be omitted"
919-
"for example MultiSystems(file_name='water.xyz', fmt='gap/xyz')" )
920917
self.systems = {}
921918
if type_map is not None:
922919
self.atom_names = type_map
@@ -956,6 +953,10 @@ def __add__(self, others) :
956953
elif isinstance(others, list):
957954
return self.__class__(self, *others)
958955
raise RuntimeError("Unspported data structure")
956+
957+
@classmethod
958+
def from_file(cls,file_name,fmt,type_map=None):
959+
return cls(file_name=file_name, fmt=fmt,type_map=type_map)
959960

960961
def get_nframes(self) :
961962
"""Returns number of frames in all systems"""
@@ -1018,6 +1019,7 @@ def from_gap_xyz_file(self,filename):
10181019
system=LabeledSystem(data=info_dict)
10191020
self.append(system)
10201021

1022+
10211023
def to_deepmd_raw(self, folder) :
10221024
"""
10231025
Dump systems in deepmd raw format to `folder` for each system.

tests/test_gap_xyz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TestGapxyz(unittest.TestCase, CompLabeledSys):
88
def setUp (self) :
9-
self.multi_systems = dpdata.MultiSystems(file_name='xyz/xyz_unittest.xyz', fmt='gap/xyz')
9+
self.multi_systems = dpdata.MultiSystems.from_file('xyz/xyz_unittest.xyz','gap/xyz')
1010
self.system_1 = self.multi_systems.systems['B1C9']
1111
self.system_2 = dpdata.LabeledSystem('xyz/B1C9', fmt='deepmd')
1212
self.places = 6

0 commit comments

Comments
 (0)