Skip to content

Commit a1c791c

Browse files
authored
Merge pull request #65 from LiuGroupHNU/devel
compatible siesta-4.0.2 and siesta-4.1-b4
2 parents 936659a + 7648533 commit a1c791c

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

dpdata/siesta/aiMD_output.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ def get_atom_types(fout, atomnums):
9090
atomtype.append(int(covert_type[i]) - 1)
9191
return atomtype
9292

93+
def get_atom_name(fout):
94+
file = open(fout, 'r')
95+
ret = []
96+
for value in file:
97+
if 'Species number:' in value:
98+
for j in range(len(value.split())):
99+
if value.split()[j] == 'Label:':
100+
ret.append(value.split()[j+1])
101+
break
102+
file.close()
103+
return ret
104+
93105
def get_atom_numbs(atomtypes):
94106
atom_numbs = []
95107
for i in set(atomtypes):
@@ -118,7 +130,7 @@ def covert_dimension(arr, num):
118130

119131
def get_aiMD_frame(fname):
120132
NumberOfSpecies = int(get_single_line_tail(fname, 'redata: Number of Atomic Species')[0])
121-
atom_names = extract_keyword(fname, 'initatom: Reading input for the pseudopotentials and atomic orbitals', NumberOfSpecies, 4, 5, 0, 8)[0].tolist()
133+
atom_names = get_atom_name(fname)
122134
tot_natoms = int(get_single_line_tail(fname, 'Number of atoms', 3)[0])
123135

124136
atom_types = get_atom_types(fname, tot_natoms)

dpdata/siesta/output.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ def extract_keyword(fout, keyword, down_line_num, begin_column, column_num):
3838
else:
3939
flag = 0
4040
continue
41-
for i in range(begin_column, column_num):
42-
if not value.split()[i].isalpha():
43-
ret.append(float(value.strip().split()[i]))
44-
else:
45-
ret.append(value.strip().split()[i])
46-
continue
41+
if len(value.split()) >= column_num:
42+
for i in range(begin_column, column_num):
43+
if not value.split()[i].isalpha():
44+
ret.append(float(value.strip().split()[i]))
45+
else:
46+
ret.append(value.strip().split()[i])
47+
## compatible siesta-4.0.2 and siesta-4.1-b4
48+
else:
49+
flag = 0
50+
idx = 0
4751
file.close()
4852
return ret
4953

@@ -55,6 +59,17 @@ def get_atom_types(fout, atomnums):
5559
atomtype.append(int(covert_type[i]) - 1)
5660
return atomtype
5761

62+
def get_atom_name(fout):
63+
file = open(fout, 'r')
64+
ret = []
65+
for value in file:
66+
if 'Species number:' in value:
67+
for j in range(len(value.split())):
68+
if value.split()[j] == 'Label:':
69+
ret.append(value.split()[j+1])
70+
break
71+
file.close()
72+
return ret
5873

5974
def get_atom_numbs(atomtypes):
6075
atom_numbs = []
@@ -79,12 +94,11 @@ def get_virial(fout, cells):
7994

8095
def obtain_frame(fname):
8196
NumberOfSpecies = int(get_single_line_tail(fname, 'redata: Number of Atomic Species')[0])
82-
atom_names = extract_keyword(fname, 'initatom: Reading input for the pseudopotentials and atomic orbitals', NumberOfSpecies, 4, 5)
97+
atom_names = get_atom_name(fname)
8398
tot_natoms = int(get_single_line_tail(fname, 'Number of atoms', 3)[0])
8499
atom_types = get_atom_types(fname, tot_natoms)
85100
atom_numbs = get_atom_numbs(atom_types)
86101
assert (max(atom_types) + 1 == NumberOfSpecies)
87-
88102
cell = extract_keyword(fname, 'outcell: Unit cell vectors (Ang):', 3, 0, 3)
89103
coord = extract_keyword(fname, 'outcoor: Atomic coordinates (Ang):', tot_natoms, 0, 3)
90104
energy = get_single_line_tail(fname, 'siesta: E_KS(eV) =')

0 commit comments

Comments
 (0)