Ejemplo n.º 1
0
def main():
    """
    Select frames from the supplied xyz file (fxyz) using one of the following algorithms:

    1. random: random selection
    2. fps: farthest point sampling selection. Need to supply a kernel matrix or descriptor matrix using -fmat
    4. CUR decomposition

    Parameters
    ----------
    fxyz: Path to xyz file.
    fmat: Path to the design matrix or name of the tags in ase xyz file
    prefix: Filename prefix, default is ASAP
    nkeep: The number of representative samples to select
    algorithm: 'the algorithm for selecting frames ([random], [fps], [cur])')
    fmat: Location of descriptor or kernel matrix file. Needed if you select [fps] or [cur].
    """

    fxyz = os.path.join(os.path.split(__file__)[0], 'small_molecules-SOAP.xyz')
    fmat = ['SOAP-n4-l3-c1.9-g0.23']
    nkeep = 10
    prefix = "test-frame-select"

    # read the xyz file
    asapxyz = ASAPXYZ(fxyz)
    # for both algo we read in the descriptor matrix
    desc, _ = asapxyz.get_descriptors(fmat)
    print("shape of the descriptor matrix: ", np.shape(desc),
          "number of descriptors: ", np.shape(desc[0]))

    for algorithm in ['random', 'cur', 'fps']:
        sparsifier = Sparsifier(algorithm)
        sbs = sparsifier.sparsify(desc, nkeep)
        # save
        selection = np.zeros(asapxyz.get_num_frames(), dtype=int)
        for i in sbs:
            selection[i] = 1
        np.savetxt(prefix + "-" + algorithm + "-n-" + str(nkeep) + '.index',
                   selection,
                   fmt='%d')
        asapxyz.write(prefix + "-" + algorithm + "-n-" + str(nkeep), sbs)
Ejemplo n.º 2
0
def select(ctx, fxyz, design_matrix, algorithm, nkeep, prefix, savexyz,
           savetxt):
    """
    Select a subset of frames using sparsification algorithms
    """

    if not fxyz and not design_matrix[0]:
        return

    if prefix is None: prefix = "ASAP-select-" + algorithm + "-n-" + str(nkeep)
    ctx.obj['asapxyz'], ctx.obj['design_matrix'], _ = read_xyz_n_dm(
        fxyz, design_matrix, False, False, False)

    from asaplib.compressor import Sparsifier
    sparsifier = Sparsifier(algorithm)
    sbs = sparsifier.sparsify(ctx.obj['design_matrix'], nkeep)
    # save
    if savetxt:
        selection = np.zeros(asapxyz.get_num_frames(), dtype=int)
        for i in sbs:
            selection[i] = 1
        np.savetxt(prefix + '.index', selection, fmt='%d')
    if savexyz: ctx.obj['asapxyz'].write(prefix, sbs)
Ejemplo n.º 3
0
#    fmat = ['SOAP-n4-l3-c1.9-g0.23']
fmat = ['*']
nkeep = args.number #50
prefix = "test-frame-select"

# read the xyz file
asapxyz = ASAPXYZ(fxyz)
# for both algo we read in the descriptor matrix
desc, _ = asapxyz.get_descriptors(fmat)
print("shape of the descriptor matrix: ", np.shape(desc), "number of descriptors: ", np.shape(desc[0]))


algorithm = args.method#'fps' # 3 options: 'random', 'cur', 'fps'
#algorithm = 'random' # 3 options: 'random', 'cur', 'fps'

sparsifier = Sparsifier(algorithm)
sbs = sparsifier.sparsify(desc, nkeep)
sbs.sort()
if args.stride is None:
    pass
else:
    sbs = sbs*args.stride
np.savetxt(prefix + "-" + algorithm + "-n-" + str(nkeep) + '.index', sbs, fmt='%d')
# save
#selection = np.zeros(asapxyz.get_num_frames(), dtype=int)
#for i in sbs:
#    selection[i] = 1
#np.savetxt(prefix + "-" + algorithm + "-n-" + str(nkeep) + '.index', selection, fmt='%d')
#asapxyz.write(prefix + "-" + algorithm + "-n-" + str(nkeep), sbs)