diff --git a/src/dcore/interaction.py b/src/dcore/interaction.py index 782c2c8d..e021ff74 100644 --- a/src/dcore/interaction.py +++ b/src/dcore/interaction.py @@ -418,10 +418,16 @@ def _generate_umat_file(p: Dict): try: if os.path.splitext(file)[1] == ".npy": umat = numpy.load(file) - assert umat.shape == u_shape, f"inconsistent shape: require {u_shape}, but {umat.shape} is given" + assert umat.shape == u_shape, f"inconsistent shape: require {u_shape}, but {umat.shape} is given." else: umat_1d = numpy.loadtxt(file) - umat = umat_1d.reshape(u_shape) + if umat_1d.shape == (numpy.prod(u_shape),): # real U + umat = umat_1d.reshape(u_shape) + elif umat_1d.shape == (numpy.prod(u_shape), 2): # complex U + # float (norb^4, 2) -> complex (norb^4, 1) -> complex (norb,norb,norb,norb) + umat = umat_1d.view(complex).reshape(u_shape) + else: + raise Exception(f"inconsisten shape: require {(numpy.prod(u_shape),)} for real U or {(numpy.prod(u_shape), 2)} for complex U, but {umat_1d.shape} is given.") except Exception as e: print(f"\nError in reading file '{file}' for ish={ish}", file=sys.stderr) print(e, file=sys.stderr)