Skip to content

Commit e948661

Browse files
authored
fix duplicated elements in vasp/xml (#575)
Fix #480. #250 doesn't handle this situation. --------- Signed-off-by: Jinzhe Zeng <[email protected]>
1 parent fb27e05 commit e948661

File tree

3 files changed

+1772
-7
lines changed

3 files changed

+1772
-7
lines changed

dpdata/vasp/xml.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def analyze_atominfo(atominfo_xml):
2222
check_name(atominfo_xml.find("array"), "atoms")
2323
eles = []
2424
types = []
25+
visited = set()
2526
for ii in atominfo_xml.find("array").find("set"):
26-
eles.append(ii.findall("c")[0].text.strip())
27-
types.append(int(ii.findall("c")[1].text))
28-
uniq_ele = []
29-
for ii in eles:
30-
if ii not in uniq_ele:
31-
uniq_ele.append(ii)
32-
return uniq_ele, types
27+
atom_type = int(ii.findall("c")[1].text)
28+
if atom_type not in visited:
29+
eles.append(ii.findall("c")[0].text.strip())
30+
visited.add(atom_type)
31+
types.append(atom_type)
32+
return eles, types
3333

3434

3535
def analyze_calculation(cc):

0 commit comments

Comments
 (0)