Skip to content

Commit c9cc927

Browse files
committed
MultiSystems.from_dir support wildcard
1 parent 2964c8f commit c9cc927

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ The following commands relating to `Class dpdata.MultiSystems` may be useful.
6565
# load data
6666

6767
xyz_multi_systems = dpdata.MultiSystems.from_file(file_name='tests/xyz/xyz_unittest.xyz',fmt='quip/gap/xyz')
68-
vasp_multi_systems = dpdata.MultiSystems.from_dir(dir_name='./mgal_outcar', file_name='OUTCAR', fmt='vasp/outcar')
68+
vasp_multi_systems = dpdata.MultiSystems.from_dir(dir_name='./mgal_outcar', file_name='OUTCAR', fmt='vasp/outcar')
69+
70+
# use wildcard
71+
vasp_multi_systems = dpdata.MultiSystems.from_dir(dir_name='./mgal_outcar', file_name='*OUTCAR', fmt='vasp/outcar')
6972

7073
# print the multi_system infomation
7174
print(xyz_multi_systems)

dpdata/system.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#%%
22
import os
3+
import glob
34
import numpy as np
45
import dpdata.lammps.lmp
56
import dpdata.lammps.dump
@@ -954,11 +955,7 @@ def from_file(cls,file_name,fmt):
954955
@classmethod
955956
def from_dir(cls,dir_name, file_name, fmt='auto'):
956957
multi_systems = cls()
957-
target_file_list = []
958-
for ii in os.walk(dir_name):
959-
if file_name in ii[2]:
960-
target_file = os.path.join(ii[0], file_name)
961-
target_file_list.append(target_file)
958+
target_file_list = glob.glob('./{}/**/{}'.format(dir_name, file_name), recursive=True)
962959
for target_file in target_file_list:
963960
multi_systems.append(LabeledSystem(file_name=target_file, fmt=fmt))
964961
return multi_systems

0 commit comments

Comments
 (0)