77import argparse
88import configparser
99from itertools import product
10- from collections import OrderedDict
10+ from collections import OrderedDict , Counter
1111import matplotlib .pyplot as plt
1212
1313from chiq .h5bse import h5BSE
@@ -28,6 +28,13 @@ def _hermitianize(mat):
2828 return (mat + mat .conjugate ().T ) / 2
2929
3030
31+ def sort_by_abs (arr , ascending = True ):
32+ if ascending :
33+ return arr [np .argsort (np .abs (arr ))] # ascending order
34+ else :
35+ return arr [np .argsort (- np .abs (arr ))] # descending order
36+
37+
3138def _convert_to_matrix (block_matrix , n_block , n_inner ):
3239 assert isinstance (block_matrix , dict )
3340 dim = n_inner * n_block
@@ -209,10 +216,10 @@ def print_Ir(prms : dict):
209216 # -------------------------------------------------------------
210217 # R-loop
211218
212- print (f"\n Results are saved to 'I_r_site *.dat' (*=0~{ n_sites - 1 } )" )
219+ print (f"\n Results are saved to 'Ir_site *.dat' (*=0~{ n_sites - 1 } )" )
213220 fs = []
214221 for site in range (n_sites ):
215- filename = f"I_r_site { site } .dat"
222+ filename = f"Ir_site { site } .dat"
216223 fs .append (open (filename , 'w' ))
217224 print (f"# I(R=0, r_{ site } ; R, r_site)" , file = fs [- 1 ])
218225
@@ -265,7 +272,8 @@ def print_Ir(prms : dict):
265272 assert dists .shape [0 ] == data4plot .shape [0 ]
266273
267274 # Analyze distances
268- dists_unique = np .unique (np .round (dists , decimals = 10 )) # sorted in lexicographic order
275+ dists_round = np .round (dists , decimals = 10 )
276+ dists_unique = np .unique (dists_round ) # sorted in lexicographic order
269277 print ("\n Distances:" )
270278 print (dists_unique [:10 ])
271279 print (f" min: { dists_unique [1 ]:.6e} " )
@@ -278,11 +286,18 @@ def print_Ir(prms : dict):
278286 max_imag = np .max (np .abs (np .imag (data4plot )))
279287 print (f" max imag: { max_imag :.4e} " )
280288
281- data_unique = np .unique (np .round (np .real (data4plot ), decimals = 10 )) # sorted in lexicographic order
282- print ("\n Largest antiferroic (<0) values:" )
283- print (data_unique [:10 ]) # print first 12 values
284- print ("\n Largest ferroic (>0) values:" )
285- print (data_unique [:- 10 :- 1 ]) # print last 12 values
289+ print ("\n Largest absolute values:" )
290+ # Find largest absolute values in descending order
291+ data_round = np .round (np .real (data4plot ), decimals = 10 )
292+ data_unique = np .unique (data_round )
293+ data_sorted = sort_by_abs (data_unique , ascending = False ) # sort by absolute value in descending order
294+
295+ for val in data_sorted [:20 ]:
296+ # print largest values and their distances
297+ bools = np .any (data_round == val , axis = 1 )
298+ # print(f" {val:13.6e} dist={np.unique(dists_round[bools])}")
299+ c = Counter (dists_round [bools ])
300+ print (f" { val :13.6e} (dist, count)={ list (c .items ())} " )
286301
287302 # Plot
288303 print ("\n Plot" )
0 commit comments