Exemple #1
0
    def set_final_dmat(self, entry_id, abinitout):
        abo = AbinitOutput(abinitout)
        if not abo.is_finished:
            return None

        dmatpawu = abo.get_dmatpawu()
        if dmatpawu is None:
            return None

        odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim)
        oparams = dmatpawu2params(odmatpawu, self.ndim)
        data = abo.get_energetics()
        if data is None:
            return None
        nres2 = data['nres2'][-1]
        etot = data['etot'][-1]

        if not np.all(
                np.sum(oparams['occupations'], axis=1) == np.array(
                    self.num_electrons_dftu)):
            print(
                'ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s'
                % entry_id)
            print('From the population      : %s ' % self.num_electrons_dftu)
            print('From %20s :    %s ' % (abinitout, oparams['occupations']))

        return self.pcdb.db.pychemia_entries.update({'_id': entry_id}, {
            '$set': {
                'properties.etot': etot,
                'properties.nres2': nres2,
                'properties.final_dmat': gs(oparams)
            }
        })
Exemple #2
0
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        """
        Move one candidate with identifier 'entry_id' in the direction of another candidate 'entry_jd'

        :param entry_id: Identifier of first entry (Origin)
        :param entry_jd: Identifier of second entry (Target)
        :param factor: Scale factor for change, 0 scale is the 'Origin' candidate, 1 is the 'Target' candidate
                        Intermediate values will change candidates accordingly
        :param in_place: If True the candidate is changed keeping the identifier unchanged
        :return:
        """

        if self.is_evaluated(entry_id):
            dmat1 = self.get_correlation_params(entry_id)
        else:
            dmat1 = self.get_correlation_params(entry_id, final=False)

        if self.is_evaluated(entry_id):
            dmat2 = self.get_correlation_params(entry_jd)
        else:
            dmat2 = self.get_correlation_params(entry_jd, final=False)

        euler_angles1 = dmat1['euler_angles']
        euler_angles2 = dmat2['euler_angles']

        euler_angles_new = np.zeros(
            (self.num_indep_matrices, int(self.ndim * (self.ndim - 1) / 2)))

        for i in range(self.num_indep_matrices):
            for j in range(int(self.ndim * (self.ndim - 1) / 2)):
                angle1 = euler_angles1[i][j]
                angle2 = euler_angles2[i][j]
                if angle1 < angle2:
                    if angle2 - angle1 < angle1 - angle2 + 2 * np.pi:
                        direction = 1  # Forward
                        angle = angle2 - angle1
                    else:
                        direction = -1  # Backward
                        angle = angle1 - angle2 + 2 * np.pi
                else:
                    if angle1 - angle2 < angle2 - angle1 + 2 * np.pi:
                        direction = -1  # Backward
                        angle = angle1 - angle2
                    else:
                        direction = 1
                        angle = angle2 - angle1 + 2 * np.pi

                euler_angles_new[i, j] = angle1 + direction * factor * angle
                if euler_angles_new[i, j] > np.pi:
                    euler_angles_new[i, j] -= -2 * np.pi
                if euler_angles_new[i, j] < -np.pi:
                    euler_angles_new[i, j] += -2 * np.pi

        newdata = dict(dmat1)
        newdata['euler_angles'] = gs(euler_angles_new)

        if in_place:
            return self.update_dmat_inplace(entry_id, newdata)
        else:
            return self.new_entry(newdata, active=False)
Exemple #3
0
    def get_final_properties(self, path):

        outputfile = get_final_abinit_out(path)
        if outputfile is None:
            raise ValueError("Not such dir: %s" % path)

        # Reading the OUTPUT
        abo = AbinitOutput(outputfile)
        dmatpawu = abo.get_dmatpawu()
        odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim)
        oparams = dmatpawu2params(odmatpawu, self.ndim)

        if not abo.is_finished:
            print('This output is not finished')
            return None, None

        data = abo.get_energetics()
        nres2 = data['nres2'][-1]
        etot = data['etot'][-1]

        final_properties = None
        if etot is not None and oparams is not None:
            final_properties = {
                'etot': etot,
                'nres2': nres2,
                'final_dmat': gs(oparams)
            }

        return final_properties, etot
    def get_final_properties(self, path):

        outputfile = get_final_abinit_out(path)
        if outputfile is None:
            raise ValueError("Not such dir: %s" % path)

        # Reading the OUTPUT
        abo = AbinitOutput(outputfile)        
        dmatpawu = abo.get_dmatpawu()
        odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim)
        oparams = dmatpawu2params(odmatpawu, self.ndim)

        if not abo.is_finished:
            print('This output is not finished')
            return None, None

        data = abo.get_energetics()
        nres2 = data['nres2'][-1]
        etot = data['etot'][-1]

        final_properties = None
        if etot is not None and oparams is not None:
            final_properties = {'etot': etot,
                                'nres2': nres2,
                                'final_dmat': gs(oparams)}

        return final_properties, etot
    def move(self, entry_id, entry_jd, factor=0.2, in_place=False):
        """
        Move one candidate with identifier 'entry_id' in the direction of another candidate 'entry_jd'

        :param entry_id: Identifier of first entry (Origin)
        :param entry_jd: Identifier of second entry (Target)
        :param factor: Scale factor for change, 0 scale is the 'Origin' candidate, 1 is the 'Target' candidate
                        Intermediate values will change candidates accordingly
        :param in_place: If True the candidate is changed keeping the identifier unchanged
        :return:
        """

        if self.is_evaluated(entry_id):
            dmat1 = self.get_correlation_params(entry_id)
        else:
            dmat1 = self.get_correlation_params(entry_id, final=False)

        if self.is_evaluated(entry_id):
            dmat2 = self.get_correlation_params(entry_jd)
        else:
            dmat2 = self.get_correlation_params(entry_jd, final=False)

        euler_angles1 = dmat1['euler_angles']
        euler_angles2 = dmat2['euler_angles']

        euler_angles_new = np.zeros((self.num_indep_matrices, int(self.ndim*(self.ndim-1)/2)))

        for i in range(self.num_indep_matrices):
            for j in range(int(self.ndim*(self.ndim-1)/2)):
                angle1 = euler_angles1[i][j]
                angle2 = euler_angles2[i][j]
                if angle1 < angle2:
                    if angle2 - angle1 < angle1 - angle2 + 2*np.pi:
                        direction = 1  # Forward
                        angle = angle2 - angle1
                    else:
                        direction = -1  # Backward
                        angle = angle1 - angle2 + 2*np.pi
                else:
                    if angle1 - angle2 < angle2 - angle1 + 2*np.pi:
                        direction = -1  # Backward
                        angle = angle1 - angle2
                    else:
                        direction = 1
                        angle = angle2 - angle1 + 2*np.pi

                euler_angles_new[i, j] = angle1 + direction*factor*angle
                if euler_angles_new[i, j] > np.pi:
                    euler_angles_new[i, j] -= -2*np.pi
                if euler_angles_new[i, j] < -np.pi:
                    euler_angles_new[i, j] += -2*np.pi

        newdata = dict(dmat1)
        newdata['euler_angles'] = gs(euler_angles_new)

        if in_place:
            return self.update_dmat_inplace(entry_id, newdata)
        else:
            return self.new_entry(newdata, active=False)
    def set_final_dmat(self, entry_id, abinitout):
        abo = AbinitOutput(abinitout)
        if not abo.is_finished:
            return None

        dmatpawu = abo.get_dmatpawu()
        if dmatpawu is None:
            return None

        odmatpawu = np.array(dmatpawu).reshape(-1, self.ndim, self.ndim)
        oparams = dmatpawu2params(odmatpawu, self.ndim)
        data = abo.get_energetics()
        if data is None:
            return None
        nres2 = data['nres2'][-1]
        etot = data['etot'][-1]

        if not np.all(np.sum(oparams['occupations'], axis=1) == np.array(self.num_electrons_dftu)):
            print('ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s' % entry_id)
            print('From the population      : %s ' % self.num_electrons_dftu)
            print('From %20s :    %s ' % (abinitout, oparams['occupations']))

        return self.pcdb.db.pychemia_entries.update({'_id': entry_id},
                                                    {'$set': {'properties.etot': etot,
                                                              'properties.nres2': nres2,
                                                              'properties.final_dmat': gs(oparams)}})