1010ry2ev = EnergyConversion ("rydberg" , "eV" ).value ()
1111kbar2evperang3 = PressureConversion ("kbar" , "eV/angstrom^3" ).value ()
1212
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+
1323
1424def CheckFile (ifile ):
1525 if not os .path .isfile (ifile ):
@@ -43,6 +53,29 @@ def get_block(lines, keyword, skip=0, nlines=None):
4353 return ret
4454
4555
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+
4679def get_geometry_in (fname , inlines ):
4780 geometry_path_in = os .path .join (fname , "STRU" )
4881 for line in inlines :
@@ -64,8 +97,8 @@ def get_path_out(fname, inlines):
6497
6598
6699def 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" )
69102
70103 celldm = float (celldm_lines [0 ].split ()[0 ]) * bohr2ang # lattice const is in Bohr
71104 cell = []
@@ -76,7 +109,7 @@ def get_cell(geometry_inlines):
76109
77110
78111def 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" )
80113 # assuming that ATOMIC_POSITIONS is at the bottom of the STRU file
81114 coord_type = coords_lines [0 ].split ()[0 ].lower () # cartisan or direct
82115 atom_names = [] # element abbr in periodic table
0 commit comments