@@ -257,34 +257,34 @@ def parse_stru_pos(pos_line):
257257
258258 return pos , move , velocity , magmom , angle1 , angle2 , constrain , lambda1
259259
260- def get_atom_mag_cartesian (atommag ,angle1 , angle2 ):
261- '''Transform atommag, angle1, angle2 to magmom in cartesian coordinates.
262-
260+
261+ def get_atom_mag_cartesian (atommag , angle1 , angle2 ):
262+ """Transform atommag, angle1, angle2 to magmom in cartesian coordinates.
263+
263264 Parameters
264265 ----------
265266 atommag : float/list of float/None
266267 Atom magnetic moment.
267268 angle1 : float/None
268269 value of angle1.
269270 angle2 : float/None
270- value of angle2.
271-
271+ value of angle2.
272272 ABACUS support defining mag, angle1, angle2 at the same time.
273273 angle1 is the angle between z-axis and real spin (in degrees).
274- angle2 is the angle between x-axis and real spin projection in xy-plane (in degrees).
274+ angle2 is the angle between x-axis and real spin projection in xy-plane (in degrees).
275275 If only mag is defined, then transfer it to magmom directly.
276276 And if mag, angle1, angle2 are defined, then mag is only the norm of magmom, and the direction is defined by angle1 and angle2.
277- '''
277+ """
278278 if atommag is None :
279279 return None
280280 if not (isinstance (atommag , list ) or isinstance (atommag , float )):
281281 raise RuntimeError (f"Invalid atommag: { atommag } " )
282-
282+
283283 if angle1 is None and angle2 is None :
284284 if isinstance (atommag , list ):
285285 return atommag
286286 else :
287- return [0 ,0 , atommag ]
287+ return [0 , 0 , atommag ]
288288 else :
289289 a1 = 0
290290 a2 = 0
@@ -296,10 +296,12 @@ def get_atom_mag_cartesian(atommag,angle1, angle2):
296296 mag_norm = np .linalg .norm (atommag )
297297 else :
298298 mag_norm = atommag
299- return [mag_norm * np .sin (np .radians (a1 ))* np .cos (np .radians (a2 )),
300- mag_norm * np .sin (np .radians (a1 ))* np .sin (np .radians (a2 )),
301- mag_norm * np .cos (np .radians (a1 ))]
302-
299+ return [
300+ mag_norm * np .sin (np .radians (a1 )) * np .cos (np .radians (a2 )),
301+ mag_norm * np .sin (np .radians (a1 )) * np .sin (np .radians (a2 )),
302+ mag_norm * np .cos (np .radians (a1 )),
303+ ]
304+
303305
304306def get_coords (celldm , cell , geometry_inlines , inlines = None ):
305307 coords_lines = get_stru_block (geometry_inlines , "ATOMIC_POSITIONS" )
@@ -319,7 +321,7 @@ def get_coords(celldm, cell, geometry_inlines, inlines=None):
319321 line_idx = 1 # starting line of first element
320322 for it in range (ntype ):
321323 atom_names .append (coords_lines [line_idx ].split ()[0 ])
322- atom_type_mag = float (coords_lines [line_idx + 1 ].split ()[0 ])
324+ atom_type_mag = float (coords_lines [line_idx + 1 ].split ()[0 ])
323325 line_idx += 2
324326 atom_numbs .append (int (coords_lines [line_idx ].split ()[0 ]))
325327 line_idx += 1
@@ -346,11 +348,11 @@ def get_coords(celldm, cell, geometry_inlines, inlines=None):
346348 velocity .append (ivelocity )
347349 sc .append (iconstrain )
348350 lambda_ .append (ilambda1 )
349-
351+
350352 # calculate the magnetic moment in cartesian coordinates
351353 mag = get_atom_mag_cartesian (imagmom , iangle1 , iangle2 )
352354 if mag is None :
353- mag = [0 ,0 , atom_type_mag ]
355+ mag = [0 , 0 , atom_type_mag ]
354356 mags .append (mag )
355357
356358 line_idx += 1
@@ -524,11 +526,12 @@ def get_frame(fname):
524526 outlines = fp .read ().split ("\n " )
525527
526528 celldm , cell = get_cell (geometry_inlines )
527- atom_names , natoms , types , coords , move , magmom = get_coords ( # here the magmom is the initial magnetic moment in STRU
528- celldm , cell , geometry_inlines , inlines
529+ atom_names , natoms , types , coords , move , magmom = (
530+ get_coords ( # here the magmom is the initial magnetic moment in STRU
531+ celldm , cell , geometry_inlines , inlines
532+ )
529533 )
530-
531-
534+
532535 magmom , magforce = get_mag_force (outlines )
533536 if len (magmom ) > 0 :
534537 magmom = magmom [- 1 :]
0 commit comments