def _aimd_wrapper(self, variables):
        traj_id, traj = variables

        ## multiprocessing doesn't support shared-memory
        ## load mode in each worker process here :(
        qm = QM(self.qm, keywords=self.keywords, id=self.iter)
        qm.load()

        ## prepare AIMD
        aimd = AIMD(trajectory=traj,
                    keywords=self.keywords,
                    qm=qm,
                    id=traj_id + 1,
                    dir=True)

        ## add dynamical errors
        aimd.maxerr_energy = self.dyn_e[traj_id]
        aimd.maxerr_grad = self.dyn_g[traj_id]
        aimd.maxerr_nac = self.dyn_n[traj_id]
        aimd.maxerr_soc = self.dyn_s[traj_id]

        ## run AIMD
        md_traj = aimd.run()
        md_hist = md_traj.history
        return traj_id, md_hist
Exemple #2
0
    def _machine_learning(self):
        train_data = self.keywords[self.qm]['train_data']
        pred_data = self.keywords[self.qm]['pred_data']
        data = Data()

        if self.jobtype == 'train':
            ## get training data
            data.load(train_data)
            data.stat()
            self.keywords[self.qm]['data'] = data

            ## create model
            model = QM(self.qm, keywords=self.keywords, id=None)
            model.train()

        elif self.jobtype == 'prediction' or self.jobtype == 'predict':
            ## get training data and prediction data
            data.load(train_data)
            data.load(pred_data, filetype='prediction')
            data.stat()
            self.keywords[self.qm]['data'] = data

            ## create model
            model = QM(self.qm, keywords=self.keywords, id=None)
            model.load()
            model.evaluate(None)

        return self
Exemple #3
0
    def _single_point(self):
        ## create a trajectory and method model
        traj = Trajectory(self.title, keywords=self.keywords)
        method = QM(self.qm, keywords=self.keywords, id=None)
        method.load()

        sp = SinglePoint(trajectory=traj,
                         keywords=self.keywords,
                         qm=method,
                         id=None,
                         dir=None)
        sp.run()
        return self
Exemple #4
0
    def _dynamics(self):
        ## get md info
        md = self.keywords['md']
        initcond = md['initcond']
        ninitcond = md['ninitcond']
        method = md['method']
        format = md['format']
        gl_seed = md['gl_seed']
        temp = md['temp']

        ## get molecule info
        if initcond == 0:
            mol = self.title
        else:
            ## use sampling method to generate intial condition
            mol = Sampling(self.title, ninitcond, gl_seed, temp, method,
                           format)[-1]
            ## save sampled geometry and velocity
            xyz, velo = ReadInitcond(mol)
            initxyz_info = '%d\n%s\n%s' % (
                len(xyz), '%s sampled geom %s at %s K' %
                (method, ninitcond, temp), PrintCoord(xyz))

            with open('%s.xyz' % (self.title), 'w') as initxyz:
                initxyz.write(initxyz_info)

            with open('%s.velo' % (self.title), 'w') as initvelo:
                np.savetxt(initvelo, velo, fmt='%30s%30s%30s')

        ## create a trajectory and method model
        if self.qm == 'nn':
            train_data = self.keywords[self.qm]['train_data']
            data = Data()
            data.load(train_data)
            data.stat()
            self.keywords[self.qm]['data'] = data

        traj = Trajectory(mol, keywords=self.keywords)
        method = QM(self.qm, keywords=self.keywords, id=None)
        method.load()
        aimd = AIMD(trajectory=traj,
                    keywords=self.keywords,
                    qm=method,
                    id=None,
                    dir=None)
        aimd.run()

        return self
    def _search_wrapper_seq(self, variables):
        grid_id, hypers = variables

        ## update hypers and add training data
        keywords, key = self._update_hypers(self.keywords, hypers)
        keywords[self.qm]['train_mode'] = 'training'
        keywords[self.qm]['data'] = self.data
        maindir = os.getcwd()
        calcdir = '%s/grid-search/NN-%s-%s' % (os.getcwd(), self.title, key)

        ## train on local machine
        if os.path.exists(calcdir) == False:
            os.makedirs(calcdir)

        os.chdir(calcdir)
        model = QM(self.qm, keywords=keywords)
        metrics = model.train()
        os.chdir(maindir)

        return grid_id, metrics
    def _abinit_wrapper(self, variables):
        geom_id, mol = variables
        xyz = np.concatenate((self.atoms, mol.coord), axis=1)

        ## aling geometry to pre-stored training data to correct NAC phase
        ## it is not necessary if NAC is not request. The code below is obselete
        ## geom_pool =
        ## choose = np.random.choice(np.arange(len(geom_pool)),np.amin([50,len(geom_pool)]),replace=False)
        ## geom_pool = np.array(geom_pool)[choose]
        ## similar, rmsd_min = AlignGeom(xyz, geom_pool)

        ## run QC calculation
        qc = QM(self.abinit, keywords=self.keywords, id=geom_id + 1)
        mol = qc.evaluate(mol)

        ## prepare qc results
        energy = mol.energy.tolist()
        grad = mol.grad.tolist()
        nac = mol.nac
        soc = mol.soc
        completion = mol.status

        return geom_id, xyz, energy, grad, nac, soc, completion
    def _train_wrapper(self, fake):
        model = QM(self.qm, keywords=self.keywords, id=self.iter)
        model.train()

        return self