Пример #1
0
def test_extension(tmpdir):
    file = tmpdir / 'file'
    pb.save(mock_data, file)
    assert mock_data == pb.load(tmpdir / 'file.pbz')

    file = tmpdir / 'file.ext'
    pb.save(mock_data, file)
    assert mock_data == pb.load(tmpdir / 'file.ext')
Пример #2
0
def test_pickle_round_trip(lattice, tmpdir):
    file_name = str(tmpdir.join('file.npz'))
    pb.save(lattice, file_name)
    from_file = pb.load(file_name)

    assert lattice.sub_name_map == from_file.sub_name_map
    assert lattice.hop_name_map == from_file.hop_name_map
    assert pytest.fuzzy_equal(lattice, from_file)
Пример #3
0
def test_pickle_round_trip(lattice, tmpdir):
    file_name = str(tmpdir.join('file.npz'))
    pb.save(lattice, file_name)
    from_file = pb.load(file_name)

    assert lattice.sub_name_map == from_file.sub_name_map
    assert lattice.hop_name_map == from_file.hop_name_map
    assert pytest.fuzzy_equal(lattice, from_file)
Пример #4
0
    def get_expected(result, group=''):
        file = path_from_fixture(request, prefix='baseline_data', ext='.pbz',
                                 override_group=group)

        if not request.config.getoption("--savebaseline") and file.exists():
            return pb.load(file)
        elif not request.config.getoption("--readonly"):
            if not file.parent.exists():
                file.parent.mkdir(parents=True)
            pb.save(result, file)
            return result
        else:
            raise RuntimeError("Missing baseline data: {}".format(file))
Пример #5
0
def test_path_type(tmpdir):
    # str
    file = str(tmpdir / 'file')
    assert round_trip(mock_data, file)

    # py.path.local object
    file = tmpdir / 'file'
    assert round_trip(mock_data, file)

    # pathlib object
    file = pathlib.Path(str(tmpdir)) / 'file'
    assert round_trip(mock_data, file)

    # file object
    file = str(tmpdir / 'file')
    with open(file, 'wb') as f:
        pb.save(mock_data, f)
    with open(file, 'rb') as f:
        assert mock_data == pb.load(f)
Пример #6
0
    return _x_coord, _y_coord, _z_coord, _atom_type, _l1, _l2, _l3


# WARNING: the calculation ran with parameters given here will run for at least 72h
# load an xyz file, relaxed or unrelaxed
name = 'relaxed_tblg_1.050.xyz'

# load coordinates, atom types and lattice vectors
x_coord, y_coord, z_coord, atom_type, l1, l2, l3 = load_ovito_lattice(name)
l1 = np.array(l1[0:2]) / 10.
l2 = np.array(l2[0:2]) / 10.
positions = np.column_stack((x_coord, y_coord, z_coord))
positions_to = copy.deepcopy(positions)

# load a PB lattice
complete_lattice = pb.load('lattice_' + name[:-4])
num_x = 1
num_y = 1
print('Done loading ', flush=True)
print('Making the model', flush=True)

# check for the bonds
model = pb.Model(
    complete_lattice, pb.force_double_precision(),
    pb.translational_symmetry(a1=num_x * np.linalg.norm(l1),
                              a2=num_y * np.linalg.norm(l2)))
model.eval()
print(model.report(), flush=True)
kpm = pb.kpm(model,
             kernel=pb.jackson_kernel(),
             matrix_format="CSR",
Пример #7
0
import kite

# define the angle
angle = 21.787
# define the name of the pb.Lattice object
name = 'lattice_twisted_bilayer/lattice_tblg_{:.3f}'.format(angle)
# number of decomposition parts in each direction of matrix. This divides the lattice into various sections,
# each of which is calculated in parallel
nx = 1
ny = 1
# number of unit cells in each direction.
l1 = l2 = 64 * nx, 64 * nx
# estimated scale for the Hamiltonian
energy_scale = 10
# load a predefined lattice object, the lattice can be saved with pb.save(lattice, name)
lattice = pb.load(name)
# make config object which caries info about
# - the number of decomposition parts [nx, ny],
# - lengths of structure [lx, ly]
# - boundary conditions, setting True as periodic boundary conditions, and False elsewise,
# - info if the exported hopping and onsite data should be complex,
# - info of the precision of the exported hopping and onsite data, 0 - float, 1 - double, and 2 - long double.
# - scaling, if None it's automatic, if present select spectrum_bound=[e_min, e_max]
configuration = kite.Configuration(divisions=[nx, ny],
                                   length=[l1, l2],
                                   boundaries=[True, True],
                                   is_complex=False,
                                   precision=1,
                                   spectrum_range=[-10, 10])
# require the calculation of DOS
num_moments = 1000
Пример #8
0
def round_trip(obj, file):
    pb.save(obj, file)
    return pb.load(file) == obj
Пример #9
0
def test_pickle_round_trip(solver, tmpdir):
    file_name = str(tmpdir.join('file.npz'))
    pb.save(solver, file_name)
    from_file = pb.load(file_name)

    assert pytest.fuzzy_equal(solver, from_file)
Пример #10
0
def test_pickle_round_trip(model, tmpdir):
    file_name = str(tmpdir.join('file.npz'))
    pb.save(model.system, file_name)
    from_file = pb.load(file_name)

    assert pytest.fuzzy_equal(model.system, from_file)
Пример #11
0
def test_pickle_round_trip(model, tmpdir):
    file_name = str(tmpdir.join('file.npz'))
    pb.save(model.system, file_name)
    from_file = pb.load(file_name)

    assert pytest.fuzzy_equal(model.system, from_file)