def choose_points(e, f, nneg, npos): # Choose first npo+nneg points, # than pick some points by hands # For testing purposes if (nneg + npos) % 2 != 0: print('Number of chosen points should be even!', nneg, npos, nneg + npos) npos += 1 q = nneg + npos # ee = np.zeros(q, dtype=mp.mpc) # ff = np.zeros((q, f.shape[1]), dtype=mp.mpc) ee = fp.zeros(q, 1) ff = fp.zeros(q, f.cols) for i in range(0, nneg): ee[i] = e.conj()[nneg - 1 - i] ff[i] = f.conj()[nneg - 1 - i] for i in range(nneg, nneg + npos - 6): ee[i] = e[i - nneg] ff[i] = f[i - nneg] ee[q - 6] = e[750] ff[q - 6] = f[750] ee[q - 5] = e[900] ff[q - 5] = f[900] ee[q - 4] = e[937] ff[q - 4] = f[937] ee[q - 3] = e[960] ff[q - 3] = f[960] ee[q - 2] = e[999] ff[q - 2] = f[999] ee[q - 1] = e[1000] ff[q - 1] = f[1000] return ee, ff
def make_f_prime(f, e, m): # F'(z) = z^3 * [F(z) - p_n/z - p'_n/z^2 - p''_n/z^3] r = len(e) fn = fp.zeros(r, 1) for i in range(0, r): fn[i] = (e[i]**3) * (f[i] - m[0] / e[i] - m[1] / (e[i]**2) - m[2] / (e[i]**3)) return fn
def choose_seq_points(e, f, nneg, npos): # Pick first nneg+npos points if (nneg + npos) % 2 != 0: print('Number of chosen points should be even!', nneg, npos, nneg + npos) npos += 1 q = nneg + npos # ee = np.zeros(q, dtype=mp.mpc) # ff = np.zeros((q, f.shape[1]), dtype=mp.mpc) ee = fp.zeros(q, 1) ff = fp.zeros(q, f.cols) for i in range(0, nneg): ee[i] = mp.conj(e[nneg - 1 - i]) ff[i] = mp.conj(f[nneg - 1 - i]) for i in range(nneg, nneg + npos): ee[i] = e[i - nneg] ff[i] = f[i - nneg] return ee, ff
def choose_prandom_points(e, f, nneg, npos): # Subroutine selects from input nneg+npos points # first nneg+npos-nrnd points are selected sequently, # then nrnd points are picked randomly # Number of randomly selected points nrnd is determined randomly in interval (4, 18) # e -- input complex array with energy points # f -- input complex array with values of function in points e[i] nrnd = random.randrange(4, 18, 2) if (nneg + npos) % 2 != 0: print('Number of chosen points should be even!', nneg, npos, nneg + npos) npos += 1 q = nneg + npos r = len(e) ee = fp.zeros(q, 1) ff = fp.zeros(q, f.cols) for i in range(0, nneg): ee[i] = mp.conj(e[nneg - 1 - i]) ff[i] = mp.conj(f[nneg - 1 - i]) for i in range(nneg, q - nrnd): ee[i] = e[i - nneg] ff[i] = f[i - nneg] # Make list of random points pp = random.sample(range(q - nrnd, r - 1), nrnd) # Sort them pp.sort() # Fix repeated points (if there are) for i in range(0, nrnd - 1): if pp[i] == pp[i + 1]: pp[i + 1] += 1 # The last two points should be sequential to fix diff at the tail of F(z). pp[nrnd - 1] = pp[nrnd - 2] + 1 # Construct for i in range(0, nrnd): ee[q - nrnd + i] = e[pp[i]] ff[q - nrnd + i] = f[pp[i]] return ee, ff
def choose_seq_points_plus(e, f, nneg, npos): # Choose first nneg+npos-2 and last two points if (nneg + npos) % 2 != 0: print('Number of chosen points should be even!', nneg, npos, nneg + npos) npos += 1 q = nneg + npos # ee = np.zeros(q, dtype=mp.mpc) # ff = np.zeros((q, f.shape[1]), dtype=mp.mpc) ee = fp.zeros(q, 1) ff = fp.zeros(q, f.cols) for i in range(0, nneg): ee[i] = e.conj()[nneg - 1 - i] ff[i] = f.conj()[nneg - 1 - i] for i in range(nneg, nneg + npos - 2): ee[i] = e[i - nneg] ff[i] = f[i - nneg] for i in range(-2, 0): ee[i] = e[i] ff[i] = f[i] return ee, ff
def readsigma(filename): # Read sigma from AMULET. print('Input file contains:') with open(filename, 'r') as f: data = f.readlines() # Analyze the file. # Number of lines. nlines = len(data) print(" Number of lines: %i " % nlines) # Count pairs of blank lines to determine number of datasets. # Each dataset should be ended by 2 blank lines. ndatasets = 0 for i in range(0, nlines - 1): if not data[i].split() and not data[i + 1].split(): ndatasets += 1 blank_lines_ending = 2 # If there are no blank lines at end of file if ndatasets == 0 and not data[-1].split(): ndatasets += 1 blank_lines_ending = 1 nlinesperblock = (nlines + 1) / ndatasets elif ndatasets == 0 and data[-1].split(): ndatasets += 1 nlinesperblock = (nlines + 2) / ndatasets else: nlinesperblock = nlines / ndatasets print(" Number of datasets: %i " % ndatasets) # nlinesperblock = nlines / ndatasets print(" Number of lines per block: %i " % nlinesperblock) # Take the last dataset from data file data = data[nlinesperblock * (ndatasets - 1):(nlinesperblock * ndatasets) - blank_lines_ending] nlines = len(data) s = data[0].split() # Structure of Sigma file: # first column -- energy, the next two column are Re and Im parts of sigma majority # last two column are Re and Im parts of sigma minority (if calc is spin-polarized) l = len(s) if l == 3: e = fp.zeros(nlines, 1) z = fp.zeros(nlines, 1) for i in range(0, nlines): s = data[i].split() e[i] = 1j * float(s[0]) z[i] = float(s[1]) + 1j * float(s[2]) elif l == 5: e = fp.zeros(nlines, 1) z = fp.zeros(nlines, 2) for i in range(0, nlines): s = data[i].split() e[i] = 1j * float(s[0]) z[i, 0] = float(s[1]) + 1j * float(s[2]) z[i, 1] = float(s[3]) + 1j * float(s[4]) else: print("unknown data format") return e, z