Beispiel #1
0
def get_environmentalKernels_singleprocess(atoms, nocenters=None, chem_channels=True, centerweight=1.0,
                                           gaussian_width=0.5, cutoff=3.5, cutoff_transition_width=0.5,
                                           nmax=8, lmax=6, chemicalKernelmat=None, chemicalKernel=None,
                                           chemicalProjection=None,
                                           nthreads=4, nprocess=0, nchunks=0,isDeltaKernel=True,
                                           dispbar=False,is_fast_average=False):
    if nocenters is None:
        nocenters = []

    # Chooses the function to use to compute the kernel between two frames
    get_envKernel = choose_envKernel_func(nthreads,isDeltaKernel)

    # Builds the kernel matrix from the species present in the frames and a specified chemical
    # kernel function
    if chemicalKernelmat is not None:
        pass
    elif chemicalProjection is not None:
        pass
    elif chemicalKernelmat is None and chemicalKernel is not None:
        chemicalKernelmat = Atoms2ChemicalKernelmat(atoms, chemicalKernel=chemicalKernel)
    else:
        raise ValueError('wrong chemicalKernelmat and/or chemicalKernel input')

    # get the soap for every local environement
    frames = get_Soaps(atoms, nocenters=nocenters, chem_channels=chem_channels, centerweight=centerweight,
                       gaussian_width=gaussian_width, cutoff=cutoff, cutoff_transition_width=cutoff_transition_width,
                       nmax=nmax, lmax=lmax, nprocess=nprocess,chemicalProjection=chemicalProjection,
                       dispbar=dispbar,is_fast_average=is_fast_average)

    # get the environmental kernels as a dictionary
    environmentalKernels = framesprod(frames, frameprodFunc=get_envKernel, chemicalKernelmat=chemicalKernelmat,
                                      dispbar=dispbar)


    return environmentalKernels
Beispiel #2
0
def framesprod_wrapper(kargs):
    keys = kargs.keys()
    get_envKernel = kargs.pop('frameprodFunc')
    queue = kargs.pop('queue')
    # to disable the progressbar
    dispbar = kargs.pop('dispbar')
    if 'fpointers1' in keys:
        fpointers1 = kargs.pop('fpointers1')
        fpointers2 = kargs.pop('fpointers2')
        atoms1 = [qp.Atoms(fpointer=fpointer1) for fpointer1 in fpointers1]

        chemicalKernelmat = kargs.pop('chemicalKernelmat')

        frames1 = get_Soaps(atoms1, dispbar=dispbar, **kargs)
        if fpointers2 is not None:
            atoms2 = [qp.Atoms(fpointer=fpointer2) for fpointer2 in fpointers2]
            frames2 = get_Soaps(atoms2, dispbar=dispbar, **kargs)
        else:
            frames2 = None

        kargs = {
            'frames1': frames1,
            'frames2': frames2,
            'chemicalKernelmat': chemicalKernelmat
        }

    elif 'atoms1' in keys:
        atoms1 = kargs.pop('atoms1')
        atoms2 = kargs.pop('atoms2')
        chemicalKernelmat = kargs.pop('chemicalKernelmat')

        frames1 = get_Soaps(atoms1, dispbar=dispbar, **kargs)
        if atoms2 is not None:
            frames2 = get_Soaps(atoms2, dispbar=dispbar, **kargs)
        else:
            frames2 = None

        kargs = {
            'frames1': frames1,
            'frames2': frames2,
            'chemicalKernelmat': chemicalKernelmat
        }

    return framesprod(queue=queue, frameprodFunc=get_envKernel, **kargs)
Beispiel #3
0
    def get(self):
        parser = flask_restful.reqparse.RequestParser()
        argument_names = [
            'atoms', 'nocenters', 'chem_channels', 'centerweight',
            'gaussian_width', 'spkitMax', 'chemicalProjection',
            'is_fast_average', 'cutoff', 'cutoff_transition_width', 'nmax',
            'lmax'
        ]
        for argument_name in argument_names:
            parser.add_argument(ARGUMENTS[argument_name])
        args = parser.parse_args(strict=True)
        if args['spkitMax']:
            args['spkitMax'] = json.loads(args['spkitMax'])
        args['atoms'] = json.loads(args['atoms'])
        args['atoms'] = [atoms_utils.loads(atoms) for atoms in args['atoms']]
        args['atoms'] = [ase2qp(atoms) for atoms in args['atoms']]
        soaps = get_Soaps(**args)
        soaps = [{key: value.tolist()
                  for key, value in soap.iteritems()} for soap in soaps]

        return flask.jsonify(soaps)
Beispiel #4
0
        'chem_channels': True,
        'nocenters': nocenters
    }

    # DELTA CHEMICAL KERNEL hard coded
    chemicalKernelmat = Atoms2ChemicalKernelmat(atoms1,
                                                atoms2=atoms2,
                                                chemicalKernel=deltaKernel)
    # Chooses the function to use to compute the kernel between two frames
    get_envKernel = choose_envKernel_func(nthreads, isDeltaKernel=True)

    ####################################################################################
    # get the soap for every local environement
    print 'Compute xSoap {} with {} process from {}'.format(
        xlim, nprocess, filename)
    frames1 = get_Soaps(atoms1, nprocess=nprocess, **soap_params)

    print 'Compute xSoap {} with {} process from {}: done {}'.format(
        xlim, nprocess, filename, s2hms(time.time() - st))
    if atoms2 is None:
        frames2 = None
        print 'no atoms 2, Computing upper triangular sub matrix'
    else:
        print 'Compute ySoap {} process from {}'.format(
            ylim, nprocess, filename)
        frames2 = get_Soaps(atoms2, nprocess=nprocess, **soap_params)
        print 'Compute ySoap {} process from {}: done {}'.format(
            ylim, nprocess, filename, s2hms(time.time() - st))

    ########################################################################################
    # get the environmental kernels as a dictionary
Beispiel #5
0
def get_environmentalKernels_mt_mp_chunks(atoms,
                                          nocenters=None,
                                          chem_channels=True,
                                          centerweight=1.0,
                                          gaussian_width=0.5,
                                          cutoff=3.5,
                                          cutoff_transition_width=0.5,
                                          nmax=8,
                                          lmax=6,
                                          chemicalKernelmat=None,
                                          chemicalKernel=None,
                                          chemicalProjection=None,
                                          nthreads=4,
                                          nprocess=2,
                                          nchunks=2,
                                          islow_memory=False,
                                          isDeltaKernel=True,
                                          dispbar=False,
                                          is_fast_average=False):
    if nocenters is None:
        nocenters = []

    # Builds the kernel matrix from the species present in the frames and a specified chemical
    # kernel function

    if chemicalKernelmat is not None:
        pass
    elif chemicalProjection is not None:
        pass
    elif (chemicalKernelmat is None) and (chemicalKernel is not None):
        chemicalKernelmat = Atoms2ChemicalKernelmat(
            atoms, chemicalKernel=chemicalKernel)
    else:
        raise ValueError('wrong chemicalKernelmat and/or chemicalKernel input')

    Natoms = len(atoms)
    NenvKernels = Natoms * (Natoms + 1) / 2.

    # fpointers = [frame._fpointer.copy() for frame in atoms]
    # chunks1d, slices = chunk_list(fpointers, nchunks=nchunks)
    # cut atomsList in chunks
    if islow_memory:
        frames = get_Soaps(atoms,
                           nocenters=nocenters,
                           chem_channels=chem_channels,
                           centerweight=centerweight,
                           gaussian_width=gaussian_width,
                           cutoff=cutoff,
                           is_fast_average=is_fast_average,
                           chemicalProjection=chemicalProjection,
                           cutoff_transition_width=cutoff_transition_width,
                           nmax=nmax,
                           lmax=lmax,
                           nprocess=nprocess)
        chunks1d, slices = chunk_list(frames, nchunks=nchunks)

    else:
        chunks1d, slices = chunk_list(atoms, nchunks=nchunks)

    soap_params = {
        'centerweight': centerweight,
        'gaussian_width': gaussian_width,
        'cutoff': cutoff,
        'cutoff_transition_width': cutoff_transition_width,
        'nmax': nmax,
        'lmax': lmax,
        'chemicalKernelmat': chemicalKernelmat,
        'chemicalProjection': chemicalProjection,
        'chem_channels': chem_channels,
        'nocenters': nocenters,
        'is_fast_average': is_fast_average,
    }

    # create inputs for each block of the global kernel matrix
    chunks = chunks1d_2_chuncks2d(chunks1d, **soap_params)

    # new_atoms1 = {}
    # new_atoms2 = {}
    # for it,chunk in enumerate(chunks):
    #     atoms1 = chunk.pop('atoms1')
    #     atoms2 = chunk.pop('atoms2')
    #     # new_atoms1[it] = [qp.Atoms().copy_from(frame) for frame in atoms1]
    #     new_atoms1[it] = [frame.copy() for frame in atoms1]
    #     fpointers1 = [frame._fpointer.copy() for frame in new_atoms1[it]]
    #     if atoms2 is not None:
    #         # new_atoms2[it] = [qp.Atoms().copy_from(frame) for frame in atoms2]
    #         new_atoms2[it] = [frame.copy() for frame in atoms2]
    #         fpointers2 = [frame._fpointer.copy() for frame in new_atoms2[it]]
    #     else:
    #         fpointers2 = None
    #
    #     chunk.update(**{'fpointers1':fpointers1,'fpointers2':fpointers2})

    # get a list of environemental kernels
    pool = mp_framesprod(chunks,
                         nprocess,
                         nthreads,
                         NenvKernels,
                         isDeltaKernel=isDeltaKernel,
                         dispbar=dispbar)
    results = pool.run()
    # reorder the list of environemental kernels into a dictionary which keys are the (i,j) of the global kernel matrix
    environmentalKernels = join_envKernel(results, slices)

    return environmentalKernels
Beispiel #6
0
# atoms: [quippy.Atoms]
# nocenters: None or [Atomic numbers to ignore]
# chem_channels: bool (whether or not to include chemical combinations)
# centerweight: float (weight of gaussian on central atom)
# gaussian_width: float (sigma of gaussian)
# cutoff: float (integration cutoff distance)
# cutoff_transition_width: float (width of sigmoid used to smooth integration cutoff)
# nmax: int (number of radial basis functions)
# lmax: int (number of spherical harmonics)
# spkitMax: dict {atomic numbers: max. number of occurrences in a structure in the set atoms}
# nprocess: int (number of subprocesses spawned)
# chemicalProjection: ???
# dispbar: bool ???
# is_fast_average: None or bool (use fast averaging to calculate average soap; no average calculated if None)
soaps = get_Soaps(atoms=quippy_atoms,
                  nocenters=None,
                  chem_channels=False,
                  centerweight=1.0,
                  gaussian_width=0.5,
                  cutoff=2.0,
                  cutoff_transition_width=0.5,
                  nmax=16,
                  lmax=14,
                  spkitMax=None,
                  nprocess=8,
                  chemicalProjection=None,
                  dispbar=False,
                  is_fast_average=False)

# soaps should be a list of `OrderedDict`s keyed by the species symbols + an integer (e.g. keys = ["H0", "H1", "O0"])