Beispiel #1
0
def test_get_pockets_segmentation(data):
    with pytest.raises(ValueError, match='data_handle must be set'):
        model = UNet(box_size=data.box_size,
                     input_channels=data.x_channels,
                     output_channels=data.y_channels,
                     l2_lambda=1e-7)
        model.pocket_density_from_grid('10gs')

    with pytest.raises(ValueError, match='scale must be set'):
        model = UNet(box_size=data.box_size,
                     input_channels=data.x_channels,
                     output_channels=data.y_channels,
                     l2_lambda=1e-7,
                     data_handle=data)
        model.scale = None
        model.pocket_density_from_grid('10gs')

    np.random.seed(42)
    model = UNet(box_size=data.box_size,
                 input_channels=data.x_channels,
                 output_channels=data.y_channels,
                 l2_lambda=1e-7,
                 data_handle=data)
    model.compile(optimizer=Adam(lr=1e-6), loss='binary_crossentropy')
    density, *_ = model.pocket_density_from_grid('10gs')

    with pytest.raises(ValueError, match='not supported'):
        model.get_pockets_segmentation(np.array([density] * 2), 0.6)

    pocket = model.get_pockets_segmentation(density, 0.6)
    assert pocket.shape == (data.box_size, ) * 3
    assert pocket.max() > 0
    assert len(np.unique(pocket)) - 1 <= pocket.max()
Beispiel #2
0
def test_save_pockets_cube(data):
    model = UNet(data_handle=data, l2_lambda=1e-7)
    model.compile(optimizer=Adam(lr=1e-6), loss='binary_crossentropy')
    density, origin, step = model.pocket_density_from_grid('10gs')

    with pytest.raises(ValueError, match='saving more than one prediction'):
        model.save_density_as_cube(np.concatenate((density, density)), origin,
                                   step)

    with pytest.raises(NotImplementedError, match='saving multichannel'):
        model.save_density_as_cube(density, origin, step)

    density = density[..., [0]]
    with tempfile.NamedTemporaryFile(suffix='.cube') as cmap_file:
        fname = cmap_file.name
        model.save_density_as_cube(density, origin, step, fname=fname)
        with open(fname, 'r') as f:
            # skip header
            for _ in range(7):
                f.readline()
            values = np.array(f.read().split()).reshape(density.shape)
            assert np.allclose(density, values.astype(float))
Beispiel #3
0
def test_save_pockets_cmap(data):
    model = UNet(data_handle=data, l2_lambda=1e-7)
    model.compile(optimizer=Adam(lr=1e-6), loss='binary_crossentropy')
    density, origin, step = model.pocket_density_from_grid('10gs')

    with pytest.raises(ValueError, match='saving more than one prediction'):
        model.save_density_as_cmap(np.concatenate((density, density)), origin,
                                   step)

    with tempfile.NamedTemporaryFile(suffix='.cmap') as cmap_file:
        fname = cmap_file.name
        model.save_density_as_cmap(density, origin, step, fname=fname)
        with h5py.File(fname, 'r') as f:
            assert 'Chimera' in f
            group = f['Chimera']
            assert len(group.keys()) == data.y_channels
            for i in range(data.y_channels):
                key = 'image%s' % (i + 1)
                assert key in group
                assert 'data_zyx' in group[key]
                dataset = group[key]['data_zyx'][:]
                assert np.allclose(density[0, ..., i].transpose([2, 1, 0]),
                                   dataset[:])