コード例 #1
0
 def test_determine_convergence(self):
     self.maxDiff = None
     xs = [1, 2, 3, 4, 5, 6]
     # a converging example:
     ys = [4, 5, 6, 6, 6, 6]
     self.assertEqual(
         determine_convergence(xs, ys, name="name", tol=0.1, plots=False),
         [True, 4, 6, 3, 6.0, 0.091269841269839724],
     )
     # another converging example
     ys = [1 / 1, 1 / 2, 1 / 3, 1 / 4, 1 / 5, 1 / 6]
     self.assertEqual(
         determine_convergence(xs, ys, name="name", tol=0.3, plots=False),
         [True, 3, 0.3333333333333333, 2, 0.0, -0.12813051146384496],
     )
     # a non converging example
     ys = [4, 5, 6, 7, 8, 9]
     self.assertEqual(
         determine_convergence(xs, ys, name="name", tol=0.01, plots=False),
         [False, numpy.inf, None, None, 14.607906815185412, None],
     )
     # another non converging example
     ys = [4, 5, 4, 5, 4, 5]
     self.assertEqual(
         determine_convergence(xs, ys, name="name", tol=0.01, plots=False),
         [False, numpy.inf, None, None, 11.368169147574115, None],
     )
コード例 #2
0
ファイル: datastructures.py プロジェクト: akakcolin/abipy
 def find_conv_pars(self, tol=0.0001):
     """
     find the pair of smallest values of ecuteps and nbands that give a gamma - gamma gap converged within tol
     positive tol ensures the dirivative is smaller than tol
     negative tol ensures the value is closer than -tol to the assymtotic limmit of a 'A + B / x ^ N' fit
     """
     ecuteps_l = False
     nbands_l = False
     ecuteps_c = 0
     nbands_c = 0
     ecuteps_d = 0
     nbands_d = 0
     gap = None
     y_conv = []
     z_conv = []
     y_conv_der = []
     extrapolated = []
     xs = self.get_var_range("nbands")
     ys = self.get_var_range("ecuteps")
     zd = self.get_data_array()
     for z in zd:
         print(z)
     # print 'plot "'+self.name+'condat'+'"'
     for x in xs:
         zs = []
         for y in ys:
             try:
                 zs.append(zd[x][y])
             except KeyError:
                 pass
         conv_data = determine_convergence(ys, zs, name=self.name, tol=tol, extra="ecuteps at " + str(x))
         extrapolated.append(conv_data[4])
         if conv_data[0]:
             y_conv.append(conv_data[1])
             y_conv_der.append(conv_data[5])
             z_conv.append(conv_data[2])
             ecuteps_l = conv_data[0]
         else:
             y_conv.append(None)
             z_conv.append(None)
     if ecuteps_l:
         conv_data = determine_convergence(xs, z_conv, name=self.name, tol=tol, extra="nbands")
         if conv_data[0]:
             nbands_l = conv_data[0]
             nbands_c = conv_data[1]
             gap = conv_data[2]
             ecuteps_c = y_conv[conv_data[3]]
             nbands_d = conv_data[5]
             ecuteps_d = y_conv_der[conv_data[3]]
     self.conv_res["control"].update({"ecuteps": ecuteps_l, "nbands": nbands_l})
     self.conv_res["values"].update({"ecuteps": ecuteps_c, "nbands": nbands_c, "gap": gap})
     self.conv_res["derivatives"].update({"ecuteps": ecuteps_d, "nbands": nbands_d})
     return determine_convergence(
         xs, extrapolated, name=self.name, tol=-0.05, extra="nbands at extrapolated ecuteps"
     )
コード例 #3
0
    def find_conv_pars(self, tol=0.0001, silent=False):
        """
        find the pair of smallest values of ecuteps and nbands that give a gamma - gamma gap converged within tol
        positive tol ensures the dirivative is smaller than tol
        negative tol ensures the value is closer than -tol to the assymtotic limmit of a 'A + B / x ^ N' fit
        """
        plots = False if silent else True
        ecuteps_l = False
        nbands_l = False
        ecuteps_c = 0
        nbands_c = 0
        ecuteps_d = 0
        nbands_d = 0
        gap = None
        y_conv = []
        z_conv = []
        y_conv_der = []
        extrapolated = []
        xs = self.get_var_range('nbands')
        ys = self.get_var_range('ecuteps')
        zd = self.get_data_array()
#        for z in zd:
#            print(z)
        # print 'plot "'+self.name+'condat'+'"'
        for x in xs:
            zs = []
            for y in ys:
                try:
                    zs.append(zd[x][y])
                except KeyError as ex:
                    print(ex.message)
            conv_data = determine_convergence(ys, zs, name=self.name, tol=tol, extra='ecuteps at '+str(x), plots=plots)
            extrapolated.append(conv_data[4])
            if conv_data[0]:
                y_conv.append(conv_data[1])
                y_conv_der.append(conv_data[5])
                z_conv.append(conv_data[2])
                ecuteps_l = conv_data[0]
            else:
                y_conv.append(None)
                z_conv.append(None)
        if ecuteps_l:
            conv_data = determine_convergence(xs, z_conv, name=self.name, tol=tol, extra='nbands', plots=plots)
            if conv_data[0]:
                nbands_l = conv_data[0]
                nbands_c = conv_data[1]
                gap = conv_data[2]
                ecuteps_c = y_conv[conv_data[3]]
                nbands_d = conv_data[5]
                ecuteps_d = y_conv_der[conv_data[3]]
        self.conv_res['control'].update({'ecuteps': ecuteps_l, 'nbands': nbands_l})
        self.conv_res['values'].update({'ecuteps': ecuteps_c, 'nbands': nbands_c, 'gap': gap})
        self.conv_res['derivatives'].update({'ecuteps': ecuteps_d, 'nbands': nbands_d})
        return determine_convergence(xs, extrapolated, name=self.name, tol=-0.05,
                                     extra='nbands at extrapolated ecuteps', plots=plots)
コード例 #4
0
 def find_conv_pars(self, tol=0.0001):
     """
     find the pair of smallest values of ecuteps and nbands that give a gamma - gamma gap converged within tol
     positive tol ensures the dirivative is smaller than tol
     negative tol ensures the value is closer than -tol to the assymtotic limmit of a 'A + B / x ^ N' fit
     """
     ecuteps_l = False
     nbands_l = False
     ecuteps_c = 0
     nbands_c = 0
     ecuteps_d = 0
     nbands_d = 0
     gap = None
     y_conv = []
     z_conv = []
     y_conv_der = []
     extrapolated = []
     xs = self.get_var_range('nbands')
     ys = self.get_var_range('ecuteps')
     zd = self.get_data_array()
     for z in zd:
         print(z)
     # print 'plot "'+self.name+'condat'+'"'
     for x in xs:
         zs = []
         for y in ys:
             try:
                 zs.append(zd[x][y])
             except KeyError:
                 pass
         conv_data = determine_convergence(ys, zs, name=self.name, tol=tol, extra='ecuteps at '+str(x))
         extrapolated.append(conv_data[4])
         if conv_data[0]:
             y_conv.append(conv_data[1])
             y_conv_der.append(conv_data[5])
             z_conv.append(conv_data[2])
             ecuteps_l = conv_data[0]
         else:
             y_conv.append(None)
             z_conv.append(None)
     if ecuteps_l:
         conv_data = determine_convergence(xs, z_conv, name=self.name, tol=tol, extra='nbands')
         if conv_data[0]:
             nbands_l = conv_data[0]
             nbands_c = conv_data[1]
             gap = conv_data[2]
             ecuteps_c = y_conv[conv_data[3]]
             nbands_d = conv_data[5]
             ecuteps_d = y_conv_der[conv_data[3]]
     self.conv_res['control'].update({'ecuteps': ecuteps_l, 'nbands': nbands_l})
     self.conv_res['values'].update({'ecuteps': ecuteps_c, 'nbands': nbands_c, 'gap': gap})
     self.conv_res['derivatives'].update({'ecuteps': ecuteps_d, 'nbands': nbands_d})
     return determine_convergence(xs, extrapolated, name=self.name, tol=-0.05, extra='nbands at extrapolated ecuteps')
コード例 #5
0
ファイル: test_convergence.py プロジェクト: ExpHP/pymatgen
 def test_determine_convergence(self):
     self.maxDiff = None
     xs = [1, 2, 3, 4, 5, 6]
     # a converging example:
     ys = [4, 5, 6, 6, 6, 6]
     self.assertEqual(determine_convergence(xs, ys, name='name', tol=0.1, plots=False),
                      [True, 4, 6, 3, 6.0, 0.091269841269839724])
     #self.assertTrue(os.path.isfile('name.fitdat'))
     #self.assertTrue(os.path.isfile('plot-fits'))
     # another converging example
     ys = [1/1, 1/2, 1/3, 1/4, 1/5, 1/6]
     self.assertEqual(determine_convergence(xs, ys, name='name', tol=0.3, plots=False),
                      [True, 3, 0.3333333333333333, 2, 0.0, -0.12813051146384496])
     # a non converging example
     ys = [4, 5, 6, 7, 8, 9]
     self.assertEqual(determine_convergence(xs, ys, name='name', tol=0.01, plots=False),
                      [False, numpy.inf, None, None, 14.607906815185412, None])
     # another non converging example
     ys = [4, 5, 4, 5, 4, 5]
     self.assertEqual(determine_convergence(xs, ys, name='name', tol=0.01, plots=False),
                      [False, numpy.inf, None, None, 11.368169147574115, None])
コード例 #6
0
ファイル: datastructures.py プロジェクト: akakcolin/abipy
 def find_conv_pars_scf(self, x_name, y_name, tol=0.0001):
     xs = self.get_var_range(x_name)
     ys = []
     # print self.get_data_array_2d(x_name, y_name)
     for x in xs:
         ys.append(self.get_data_array_2d(x_name, y_name)[x])
     conv_data = determine_convergence(xs, ys, name=self.name, tol=tol, extra=x_name)
     # print conv_data, {x_name: conv_data[0]}, {x_name: conv_data[1]}, {x_name: conv_data[5]}
     self.conv_res["control"].update({x_name: conv_data[0]})
     self.conv_res["values"].update({x_name: conv_data[1]})
     self.conv_res["derivatives"].update({x_name: conv_data[5]})
     return conv_data
コード例 #7
0
 def find_conv_pars_scf(self, x_name, y_name, tol=0.0001):
     xs = self.get_var_range(x_name)
     ys = []
     #print self.get_data_array_2d(x_name, y_name)
     for x in xs:
         ys.append(self.get_data_array_2d(x_name, y_name)[x])
     conv_data = determine_convergence(xs, ys, name=self.name, tol=tol, extra=x_name)
     #print conv_data, {x_name: conv_data[0]}, {x_name: conv_data[1]}, {x_name: conv_data[5]}
     self.conv_res['control'].update({x_name: conv_data[0]})
     self.conv_res['values'].update({x_name: conv_data[1]})
     self.conv_res['derivatives'].update({x_name: conv_data[5]})
     return conv_data
コード例 #8
0
 def test_convergence(self):
     xs = sorted(self.df_data.keys())
     #print xs
     ys = []
     for x in xs:
         ys.append(self.df_data[x])
     #print ys
     for tol in [-10, -3.0, -1.0, -0.3, -0.1]:
         test_res = determine_convergence(xs, ys, 'df'+str(abs(tol)), tol=tol, verbose=False, mode='extra_noise')
         self.results.update({abs(tol): test_res[1]})
         self.df_extra = test_res[4]
     pprint.pprint(self.results)
     self.pseudo.dojo_report.update({'hints': {'high': self.results[1.0], 'medium': self.results[3.0],
                                               'low': self.results[10], 'based_on': 'delta_factor'}})
コード例 #9
0
ファイル: condf.py プロジェクト: ebousq/pseudo_dojo
 def test_convergence(self):
     xs = sorted(self.df_data.keys())
     #print xs
     ys = []
     for x in xs:
         ys.append(self.df_data[x])
     #print ys
     for tol in [-10, -3.0, -1.0, -0.3, -0.1]:
         test_res = determine_convergence(xs, ys, 'df'+str(abs(tol)), tol=tol, verbose=False, mode='extra_noise')
         self.results.update({abs(tol): test_res[1]})
         self.df_extra = test_res[4]
     pprint.pprint(self.results)
     self.pseudo.dojo_report.update({'hints': {'high': self.results[1.0], 'medium': self.results[3.0],
                                               'low': self.results[10], 'based_on': 'delta_factor'}})
コード例 #10
0
 def find_conv_pars_scf(self, x_name, y_name, tol=0.0001, silent=False):
     xs = self.get_var_range(x_name)
     ys = []
     # print self.get_data_array_2d(x_name, y_name)
     for x in xs:
         ys.append(self.get_data_array_2d(x_name, y_name)[x])
     conv_data = determine_convergence(xs, ys, name=self.name, tol=tol, extra=x_name, plots=not silent)
     # print conv_data, {x_name: conv_data[0]}, {x_name: conv_data[1]}, {x_name: conv_data[5]}
     self.conv_res['control'].update({x_name: conv_data[0]})
     factor = 1/eV_to_Ha if x_name == 'ecut' and self.code_interface.hartree_parameters else 1
     self.conv_res['values'].update({x_name: conv_data[1]*factor})
     print(conv_data[1])
     self.conv_res['derivatives'].update({x_name: conv_data[5]})
     return conv_data
コード例 #11
0
 def find_conv_pars_scf(self, x_name, y_name, tol=0.0001, silent=False):
     xs = self.get_var_range(x_name)
     ys = []
     # print self.get_data_array_2d(x_name, y_name)
     for x in xs:
         ys.append(self.get_data_array_2d(x_name, y_name)[x])
     conv_data = determine_convergence(xs,
                                       ys,
                                       name=self.name,
                                       tol=tol,
                                       extra=x_name,
                                       plots=not silent)
     # print conv_data, {x_name: conv_data[0]}, {x_name: conv_data[1]}, {x_name: conv_data[5]}
     self.conv_res['control'].update({x_name: conv_data[0]})
     factor = 1 / eV_to_Ha if x_name == 'ecut' and self.code_interface.hartree_parameters else 1
     self.conv_res['values'].update({x_name: conv_data[1] * factor})
     print(conv_data[1])
     self.conv_res['derivatives'].update({x_name: conv_data[5]})
     return conv_data
コード例 #12
0
    def conv_plots(self, query=None, silent=False, title=None):
        """
        plot the convergence plots for all entries in query
        """
        if query is None:
            query = {}
        for item in self.col.find(query):
            if not silent:
                print('System    : ', item['system'])
                print('Ps        : ', item['ps'])
                print('extra     : ', item['extra_vars'])
                print('gwresults : ', item['gw_results'])
            try:
                if not silent:
                    print('data  : ', item['data_file'])
                if True:  # isinstance(item['data_file'], ObjectId):
                    f = self.gfs.get(item['data_file'])
                    data = f.read()
                    xx = []
                    yy = []
                    x = []
                    y = []
                    z = []
                    for line in data.splitlines():
                        if len(line) > 1 and 'data' not in line:
                            x.append(float(line.split()[0]))
                            y.append(float(line.split()[1]))
                            z.append(float(line.split()[2]))
                            # collect the gap vs ecuteps curve for calculating the interpolated ecuteps
                            if abs(float(line.split()[0]) - item['gw_results']['nbands']) < 20:
                                xx.append(float(line.split()[1]))
                                yy.append(float(line.split()[2]))
                    tol = 0.05
                    convres = determine_convergence(xs=xx, ys=yy, name='test', tol=-tol)
                    n = convres[3]
                    if n > 0:
                        dx = abs(xx[n] - xx[n-1])
                        dy = abs(yy[n] - yy[n-1])
                        print(n, dx, dy)
                        if convres[2] < convres[4]:
                            m = convres[4] - tol
                            f = (m - yy[n-1]) / dy
                        else:
                            m = convres[4] + tol
                            f = (yy[n-1] - m) / dy
                        print('extrapol: %s, border: %s, factor %s ' % (convres[4],  m, f))
                        ecuteps_interpol = xx[n-1] + f * dx
                    else:
                        ecuteps_interpol = convres[1]
                    ecuteps_interpol = ecuteps_interpol if ecuteps_interpol < 500000 else None
                    item['gw_results']['ecuteps_interpol'] = ecuteps_interpol
                    print('interpolated ecuteps: %s' % ecuteps_interpol)
                    self.col.save(item)
                    if title is None:
                        t = item['system']
                    else:
                        t = title
                    try:
                        p = ConvTest(title=t, x=x, y=y, z=z)
                        p.show()
                    except ValueError:
                        print('bad data')

            except (KeyError, NoFile):
                print('no convergence plot in DataBase')

        return p.return_fig_ax()