dpdata
dpdata copied to clipboard
[BUG] LabeledSystem from OUTCAR not working
Summary
The generation of a LabeledSystem from an OUTCAR file is not working (anymore, since version 0.2.6).
Running on CentOS 8 with python 3.7.9.
Steps to Reproduce
dsys = dpdata.LabeledSystem('OUTCAR.out', fmt='vasp/outcar')
Command works until version 0.2.5, with >=0.2.6 getting an error, here evaluated for version 0.2.8:
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-2-d285c09cc64a> in <module>
----> 1 dsys = dpdata.LabeledSystem('OUTCAR.out', fmt='vasp/outcar')
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/system.py in __init__(self, file_name, fmt, type_map, begin, step, data, **kwargs)
225 if file_name is None :
226 return
--> 227 self.from_fmt(file_name, fmt, type_map=type_map, begin= begin, step=step, **kwargs)
228
229 if type_map is not None:
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/system.py in from_fmt(self, file_name, fmt, **kwargs)
251 if fmt == 'auto':
252 fmt = os.path.basename(file_name).split('.')[-1].lower()
--> 253 return self.from_fmt_obj(load_format(fmt), file_name, **kwargs)
254
255 def from_fmt_obj(self, fmtobj, file_name, **kwargs):
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/system.py in from_fmt_obj(self, fmtobj, file_name, **kwargs)
1011
1012 def from_fmt_obj(self, fmtobj, file_name, **kwargs):
-> 1013 data = fmtobj.from_labeled_system(file_name, **kwargs)
1014 if data:
1015 if isinstance(data, (list, tuple)):
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/plugins/vasp.py in from_labeled_system(self, file_name, begin, step, **kwargs)
75 vol = np.linalg.det(np.reshape(data['cells'][ii], [3, 3]))
76 data['virials'][ii] *= v_pref * vol
---> 77 data = uniq_atom_names(data)
78 return data
79
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/utils.py in uniq_atom_names(data)
87 data['atom_names'] = unames
88 tmp_type = list(data['atom_types']).copy()
---> 89 data['atom_types'] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int)
90 data['atom_numbs'] = [sum( ii == data['atom_types'] ) for ii in range(len(data['atom_names'])) ]
91 return data
/opt/python/python-3.7.9/lib/python3.7/site-packages/dpdata/utils.py in <listcomp>(.0)
87 data['atom_names'] = unames
88 tmp_type = list(data['atom_types']).copy()
---> 89 data['atom_types'] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int)
90 data['atom_numbs'] = [sum( ii == data['atom_types'] ) for ii in range(len(data['atom_names'])) ]
91 return data
IndexError: list index out of range
Please provide your file.
https://github.com/deepmodeling/dpdata/blob/master/dpdata/vasp/outcar.py#L10
There is no "TITLE" in this OUTCAR.out, so atoms are failed to be extracted...
data = dpdata.LabeledSystem("OUTCAR") Traceback (most recent call last): File "
", line 1, in File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 183, in init self.from_fmt( File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 220, in from_fmt return self.from_fmt_obj(load_format(fmt), file_name, **kwargs) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 1113, in from_fmt_obj data = fmtobj.from_labeled_system(file_name, **kwargs) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/plugins/vasp.py", line 94, in from_labeled_system data = uniq_atom_names(data) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/utils.py", line 97, in uniq_atom_names data["atom_types"] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/utils.py", line 97, in data["atom_types"] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int) IndexError: list index out of range data = dpdata.LabeledSystem("OUTCAR") Traceback (most recent call last): File " ", line 1, in File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 183, in init self.from_fmt( File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 220, in from_fmt return self.from_fmt_obj(load_format(fmt), file_name, **kwargs) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/system.py", line 1113, in from_fmt_obj data = fmtobj.from_labeled_system(file_name, **kwargs) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/plugins/vasp.py", line 94, in from_labeled_system data = uniq_atom_names(data) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/utils.py", line 97, in uniq_atom_names data["atom_types"] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int) File "/vol01/homes/hy38185/miniconda3/lib/python3.10/site-packages/dpdata/utils.py", line 97, in data["atom_types"] = np.array([uidxmap[jj] for jj in tmp_type], dtype=int) IndexError: list index out of range
This is useful ! =(https://github.com/deepmodeling/dpdata/pull/361)