10
10
ry2ev = EnergyConversion ("rydberg" , "eV" ).value ()
11
11
kbar2evperang3 = PressureConversion ("kbar" , "eV/angstrom^3" ).value ()
12
12
13
+ ABACUS_STRU_KEYS = [
14
+ "ATOMIC_SPECIES" ,
15
+ "NUMERICAL_ORBITAL" ,
16
+ "LATTICE_CONSTANT" ,
17
+ "LATTICE_VECTORS" ,
18
+ "ATOMIC_POSITIONS" ,
19
+ "NUMERICAL_DESCRIPTOR" ,
20
+ "PAW_FILES" ,
21
+ ]
22
+
13
23
14
24
def CheckFile (ifile ):
15
25
if not os .path .isfile (ifile ):
@@ -43,6 +53,29 @@ def get_block(lines, keyword, skip=0, nlines=None):
43
53
return ret
44
54
45
55
56
+ def get_stru_block (lines , keyword ):
57
+ # return the block of lines after keyword in STRU file, and skip the blank lines
58
+
59
+ def clean_comment (line ):
60
+ return re .split ("[#]" , line )[0 ]
61
+
62
+ ret = []
63
+ found = False
64
+ for i in range (len (lines )):
65
+ if clean_comment (lines [i ]).strip () == keyword :
66
+ found = True
67
+ for j in range (i + 1 , len (lines )):
68
+ if clean_comment (lines [j ]).strip () == "" :
69
+ continue
70
+ elif clean_comment (lines [j ]).strip () in ABACUS_STRU_KEYS :
71
+ break
72
+ else :
73
+ ret .append (clean_comment (lines [j ]))
74
+ if not found :
75
+ return None
76
+ return ret
77
+
78
+
46
79
def get_geometry_in (fname , inlines ):
47
80
geometry_path_in = os .path .join (fname , "STRU" )
48
81
for line in inlines :
@@ -64,8 +97,8 @@ def get_path_out(fname, inlines):
64
97
65
98
66
99
def get_cell (geometry_inlines ):
67
- cell_lines = get_block (geometry_inlines , "LATTICE_VECTORS" , skip = 0 , nlines = 3 )
68
- celldm_lines = get_block (geometry_inlines , "LATTICE_CONSTANT" , skip = 0 , nlines = 1 )
100
+ cell_lines = get_stru_block (geometry_inlines , "LATTICE_VECTORS" )
101
+ celldm_lines = get_stru_block (geometry_inlines , "LATTICE_CONSTANT" )
69
102
70
103
celldm = float (celldm_lines [0 ].split ()[0 ]) * bohr2ang # lattice const is in Bohr
71
104
cell = []
@@ -76,7 +109,7 @@ def get_cell(geometry_inlines):
76
109
77
110
78
111
def get_coords (celldm , cell , geometry_inlines , inlines = None ):
79
- coords_lines = get_block (geometry_inlines , "ATOMIC_POSITIONS" , skip = 0 )
112
+ coords_lines = get_stru_block (geometry_inlines , "ATOMIC_POSITIONS" )
80
113
# assuming that ATOMIC_POSITIONS is at the bottom of the STRU file
81
114
coord_type = coords_lines [0 ].split ()[0 ].lower () # cartisan or direct
82
115
atom_names = [] # element abbr in periodic table
0 commit comments