Esempio n. 1
0
def fill_db(filename, npoints):
    if exists_and_isfile(filename) is True:
        os.remove(filename)

    ho = HarmonicOscillator()
    model = PyrazineSala({'n_states': 3})
    nmodes = len(model.crd)
    nstates = 3
    db = PySurfDB.generate_database(filename,
                                    data=['crd', 'energy'],
                                    dimensions={
                                        'nmodes': nmodes,
                                        'nstates': nstates
                                    },
                                    model=True)
    x = (np.random.random((npoints, nmodes)) - 0.5) * 20
    y = []
    for r in x:
        db.append('crd', r)
        y += [
            model.get(Request(r, ['energy'],
                              [i for i in range(nstates)]))['energy']
        ]
        db.append(
            'energy',
            model.get(Request(r, ['energy'],
                              [i for i in range(nstates)]))['energy'])
        db.increase
    return db
Esempio n. 2
0
    def __init__(self, config):
        dbin = PySurfDB.load_database(config['db_in'], read_only=True)
        info = PySurfDB.info_database(config['db_in'])

        self.thresh = config['energy_threshold']
        self.trust_radius_general = config['trust_radius_general']
        self.trust_radius_ci = config['trust_radius_ci']
        self.crd_mode = config['crd_mode']

        if 'natoms' in info['dimensions']:
            model = False
        else:
            model = True
        dbout = PySurfDB.generate_database(config['db_out'],
                                           data=info['variables'],
                                           dimensions=info['dimensions'],
                                           model=model)

        self.crds = None
        for i, crd in enumerate(dbin['crd']):
            if self.crd_mode == 'internal':
                crd = internal(np.copy(crd))
            else:
                crd = np.copy(crd)
            if i % 1000 == 0:
                print(f"Processing point {i}")
            crd_shape = crd.shape
            crd.resize((1, crd.size))
            if self.crds is None:
                self.crds = crd.reshape((1, crd.size))
            else:
                diff = np.diff(dbin.get('energy', i))

                _, (trust_general, trust_ci) = within_trust_radius(
                    crd,
                    self.crds,
                    radius=self.trust_radius_general,
                    radius_ci=self.trust_radius_ci,
                    metric='euclidean')
                if np.min(diff) < self.thresh:
                    if trust_ci is True:
                        continue
                else:
                    if trust_general is True:
                        continue
                self.crds = np.concatenate((self.crds, crd))

            crd.resize(crd_shape)
            for prop in info['variables']:
                dbout.append(prop, dbin.get(prop, i))
            dbout.increase