예제 #1
0
def test_abinit_utils():
    """
    Tests (pychemia.code.abinit) [utils]                         :
    """
    if pychemia.HAS_SCIPY and pychemia.HAS_SCIENTIFIC:
        from pychemia.code.abinit import xyz2input, netcdf2dict, psp_name

        filename = "pychemia/test/data/abinit_05/abinit-o_OUT.nc"
        print(len(netcdf2dict(filename)))
        assert len(netcdf2dict(filename)) == 310
        assert psp_name(1, 'LDA', 'FHI') == '01-H.LDA.fhi'
        filename = "pychemia/test/data/abinit_05/abinit_DS11.xyz"
        assert xyz2input(filename).variables['natom'] == 2
예제 #2
0
def test_abinit_utils():
    """
    Tests (pychemia.code.abinit) [utils]                         :
    """
    if pychemia.HAS_SCIPY and pychemia.HAS_SCIENTIFIC:
        from pychemia.code.abinit import xyz2input, netcdf2dict, psp_name

        filename = "pychemia/test/data/abinit_01/abinit-o_OUT.nc"
        print(len(netcdf2dict(filename)))
        assert len(netcdf2dict(filename)) == 310
        assert psp_name(1, 'LDA', 'FHI') == '01-H.LDA.fhi'
        filename = "pychemia/test/data/abinit_01/abinit_DS11.xyz"
        assert xyz2input(filename).variables['natom'] == 2
예제 #3
0
def test_abinit_utils():
    """
    Test (pychemia.code.abinit) [utils]                         :
    """
    from pychemia.utils.netcdf import netcdf2dict
    from pychemia.code.abinit import xyz2input, psp_name

    filename = "tests/data/abinit_05/abinit-o_OUT.nc"
    print(len(netcdf2dict(filename)))
    assert len(netcdf2dict(filename)) == 45
    assert psp_name(1, 'LDA', 'FHI') == '01-H.LDA.fhi'
    filename = "tests/data/abinit_01/abinit_DS11.xyz"
    assert xyz2input(filename).variables['natom'] == 2
def test_abinit_utils():
    """
    Tests (pychemia.code.abinit) [utils]                         :
    """
    from pychemia.utils.netcdf import netcdf2dict
    from pychemia.code.abinit import xyz2input, psp_name

    filename = "tests/data/abinit_05/abinit-o_OUT.nc"
    print(len(netcdf2dict(filename)))
    assert len(netcdf2dict(filename)) == 45
    assert psp_name(1, 'LDA', 'FHI') == '01-H.LDA.fhi'
    filename = "tests/data/abinit_01/abinit_DS11.xyz"
    assert xyz2input(filename).variables['natom'] == 2
예제 #5
0
def get_all_psps(basedir, exchange, kind):
    directory = basedir + os.sep + exchange + '_' + kind
    if not os.path.isdir(directory):
        os.mkdir(directory)
    if kind == 'PAW':
        rpath = get_rpath_psp(kind, exchange)
        filename = rpath.split('/')[-1]
        if not os.path.isfile(directory + '/' + filename):
            u = urlopen(rpath)
            f = open(directory + os.sep + filename, 'wb')
            meta = u.info()
            file_size = int(meta.getheaders("Content-Length")[0])
            print("Downloading: %s Bytes: %s" % (filename, file_size))
            file_size_dl = 0
            block_sz = 8192
            while True:
                readed_buffer = u.read(block_sz)
                if not readed_buffer:
                    break
                file_size_dl += len(readed_buffer)
                f.write(readed_buffer)
                status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
                status += chr(8) * (len(status) + 1)
                print(status, end='')
            f.close()
            print('\n')
        try:
            tar = tarfile.open(directory + '/' + filename, 'r:gz')
            for item in tar:
                if not os.path.exists(item.name):
                    tar.extract(item, path=directory)
        except tarfile.ReadError:
            name = os.path.basename(filename)
            print(name[:name.rfind('.')], '<filename>')

    elif kind == 'HGH':
        while True:
            succeed = True
            ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
            ftp.login()  # user anonymous, passwd anonymous@
            ftp.cwd('pub/abinitio/Psps/LDA_HGH/')
            for filename in ftp.nlst():
                if not os.path.exists(directory + '/' + filename) or os.path.getsize(directory + '/' + filename) == 0:
                    print('Getting %s' % filename)
                    try:
                        ftp.retrbinary('RETR ' + filename, open(directory + '/' + filename, 'wb').write)
                    except ftplib.error_perm:
                        print('Failed to get ', filename)
                        succeed = False
            ftp.close()
            if succeed:
                break
    else:
        ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
        ftp.login()  # user anonymous, passwd anonymous@
        missing_psps = []
        for i in range(1, 113):
            if kind == 'GTH' and i > 17:
                continue
            if kind == 'CORE' and i not in [6, 7]:
                continue
            if kind == 'FHI' and exchange == 'LDA' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'TM' and exchange == 'LDA' and i in [104, 105, 106, 107, 108, 109, 110, 111, 112]:
                continue
            if kind == 'FHI' and exchange == 'GGA' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'AE' and exchange == 'DEN' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'GTH' and exchange == 'LDA' and i in [2, 10]:
                continue
            if kind == 'FC' and exchange == 'DEN' and i in [63, 65, 66, 67, 110, 111, 112]:
                continue
            filename = psp_name(i, exchange, kind)
            if not os.path.isfile(directory + '/' + filename) or os.path.getsize(directory + '/' + filename) == 0:
                print('Getting...' + filename)
                nofile = True
                while nofile:
                    retr = 'RETR ' + get_rpath_psp(kind, exchange, i) + filename
                    try:
                        ftp.retrbinary(retr, open(directory + '/' + filename, 'wb').write)
                        nofile = False
                        if os.path.getsize(directory + '/' + filename) == 0:
                            os.remove(directory + '/' + filename)
                    except ftplib.error_perm:
                        print('Could not download ' + retr)
                        missing_psps.append(i)
                        ftp.close()
                        time.sleep(5)
                        print('Reconnecting...')
                        if os.path.isfile(directory + '/' + filename):
                            os.remove(directory + '/' + filename)
                        ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
                        ftp.login()  # user anonymous, passwd anonymous@
                        nofile = False
        ftp.close()
        if len(missing_psps) > 0:
            print("kind == '%s' and exchange == '%s' and i in %s" % (kind, exchange, missing_psps))
def get_all_psps(basedir, exchange, kind):
    directory = basedir + os.sep + exchange + '_' + kind
    if not os.path.isdir(directory):
        os.mkdir(directory)
    if kind in ['PAW', 'ONC']:
        rpath = get_rpath_psp(kind, exchange)
        filename = rpath.split('/')[-1]
        if not os.path.isfile(directory + '/' + filename):
            u = urlopen(rpath)
            f = open(directory + os.sep + filename, 'wb')
            meta = u.info()
            file_size = int(meta.get("Content-Length"))
            print("Downloading: %s Bytes: %s" % (filename, file_size))
            file_size_dl = 0
            block_sz = 8192
            while True:
                readed_buffer = u.read(block_sz)
                if not readed_buffer:
                    break
                file_size_dl += len(readed_buffer)
                f.write(readed_buffer)
                status = r"%10d  [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
                status += chr(8) * (len(status) + 1)
                print(status, end='')
            f.close()
            print('\n')
        else:
            print('All files are downloaded')

        try:
            tar = tarfile.open(directory + '/' + filename, 'r:gz')
            for item in tar:
                if not os.path.exists(item.name):
                    tar.extract(item, path=directory)
        except tarfile.ReadError:
            name = os.path.basename(filename)
            print(name[:name.rfind('.')], '<filename>')

    elif kind == 'HGH':
        while True:
            succeed = True
            ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
            ftp.login()  # user anonymous, passwd anonymous@
            ftp.cwd('pub/abinitio/Psps/LDA_HGH/')
            for filename in ftp.nlst():
                if not os.path.exists(directory + '/' + filename) or os.path.getsize(directory + '/' + filename) == 0:
                    print('Getting %s' % filename)
                    try:
                        ftp.retrbinary('RETR ' + filename, open(directory + '/' + filename, 'wb').write)
                    except ftplib.error_perm:
                        print('Failed to get ', filename)
                        succeed = False
            ftp.close()
            if succeed:
                print('All files are downloaded')
                break
    else:
        files = []
        for i in range(1, 113):
            if kind == 'GTH' and i > 17:
                continue
            if kind == 'CORE' and i not in [6, 7]:
                continue
            if kind == 'FHI' and exchange == 'LDA' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'TM' and exchange == 'LDA' and i in [104, 105, 106, 107, 108, 109, 110, 111, 112]:
                continue
            if kind == 'FHI' and exchange == 'GGA' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'AE' and exchange == 'DEN' and i in [57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112]:
                continue
            if kind == 'GTH' and exchange == 'LDA' and i in [2, 10]:
                continue
            if kind == 'FC' and exchange == 'DEN' and i in [63, 65, 66, 67, 110, 111, 112]:
                continue
            filename = psp_name(i, exchange, kind)
            filepath = get_rpath_psp(kind, exchange, i)
            if not os.path.isfile(directory + '/' + filename) or os.path.getsize(directory + '/' + filename) == 0:
                files.append((filename, directory, filepath))

        if len(files) == 0:
            print("All files are downloaded")
        else:
            print("Downloading %d PSP files" % len(files))
        nth = 12
        pool = ThreadPoolExecutor(nth)
        index = 0
        p = nth * [None]
        while index < len(files):
            for i in range(nth):
                if index < len(files):
                    p[i] = pool.submit(worker, *(files[index]))
                    index += 1
            for i in range(nth):
                try:
                    p[i].result()
                except AttributeError:
                    print("Complete")

        if len(files) > 0:
            print("kind == '%s' and exchange == '%s'" % (kind, exchange))
            for i in files:
                print(" %s" % str(i))
예제 #7
0
def get_all_psps(basedir, exchange, kind):
    directory = basedir + os.sep + exchange + '_' + kind
    if not os.path.isdir(directory):
        os.mkdir(directory)
    if kind == 'PAW':
        rpath = get_rpath_psp(kind, exchange)
        filename = rpath.split('/')[-1]
        if not os.path.isfile(directory + '/' + filename):
            u = urlopen(rpath)
            f = open(directory + os.sep + filename, 'wb')
            meta = u.info()
            file_size = int(meta.get("Content-Length")[0])
            print("Downloading: %s Bytes: %s" % (filename, file_size))
            file_size_dl = 0
            block_sz = 8192
            while True:
                readed_buffer = u.read(block_sz)
                if not readed_buffer:
                    break
                file_size_dl += len(readed_buffer)
                f.write(readed_buffer)
                status = r"%10d  [%3.2f%%]" % (file_size_dl,
                                               file_size_dl * 100. / file_size)
                status += chr(8) * (len(status) + 1)
                print(status, end='')
            f.close()
            print('\n')
        else:
            print('All files are downloaded')

        try:
            tar = tarfile.open(directory + '/' + filename, 'r:gz')
            for item in tar:
                if not os.path.exists(item.name):
                    tar.extract(item, path=directory)
        except tarfile.ReadError:
            name = os.path.basename(filename)
            print(name[:name.rfind('.')], '<filename>')

    elif kind == 'HGH':
        while True:
            succeed = True
            ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
            ftp.login()  # user anonymous, passwd anonymous@
            ftp.cwd('pub/abinitio/Psps/LDA_HGH/')
            for filename in ftp.nlst():
                if not os.path.exists(directory + '/' +
                                      filename) or os.path.getsize(
                                          directory + '/' + filename) == 0:
                    print('Getting %s' % filename)
                    try:
                        ftp.retrbinary(
                            'RETR ' + filename,
                            open(directory + '/' + filename, 'wb').write)
                    except ftplib.error_perm:
                        print('Failed to get ', filename)
                        succeed = False
            ftp.close()
            if succeed:
                print('All files are downloaded')
                break
    else:
        files = []
        for i in range(1, 113):
            if kind == 'GTH' and i > 17:
                continue
            if kind == 'CORE' and i not in [6, 7]:
                continue
            if kind == 'FHI' and exchange == 'LDA' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'TM' and exchange == 'LDA' and i in [
                    104, 105, 106, 107, 108, 109, 110, 111, 112
            ]:
                continue
            if kind == 'FHI' and exchange == 'GGA' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'AE' and exchange == 'DEN' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'GTH' and exchange == 'LDA' and i in [2, 10]:
                continue
            if kind == 'FC' and exchange == 'DEN' and i in [
                    63, 65, 66, 67, 110, 111, 112
            ]:
                continue
            filename = psp_name(i, exchange, kind)
            filepath = get_rpath_psp(kind, exchange, i)
            if not os.path.isfile(directory + '/' +
                                  filename) or os.path.getsize(directory +
                                                               '/' +
                                                               filename) == 0:
                files.append((filename, directory, filepath))

        if len(files) == 0:
            print("All files are downloaded")
        else:
            print("Downloading %d PSP files" % len(files))
        nth = 12
        pool = ThreadPoolExecutor(nth)
        index = 0
        p = nth * [None]
        while index < len(files):
            for i in range(nth):
                if index < len(files):
                    p[i] = pool.submit(worker, *(files[index]))
                    index += 1
            for i in range(nth):
                try:
                    p[i].result()
                except AttributeError:
                    print("Complete")

        if len(files) > 0:
            print("kind == '%s' and exchange == '%s' and i in %s" %
                  (kind, exchange, files))
예제 #8
0
def get_all_psps(basedir, exchange, kind):
    directory = basedir + os.sep + exchange + '_' + kind
    if not os.path.isdir(directory):
        os.mkdir(directory)
    if kind == 'PAW':
        rpath = get_rpath_psp(kind, exchange)
        filename = rpath.split('/')[-1]
        if not os.path.isfile(directory + '/' + filename):
            u = urlopen(rpath)
            f = open(directory + os.sep + filename, 'wb')
            meta = u.info()
            file_size = int(meta.getheaders("Content-Length")[0])
            print("Downloading: %s Bytes: %s" % (filename, file_size))
            file_size_dl = 0
            block_sz = 8192
            while True:
                readed_buffer = u.read(block_sz)
                if not readed_buffer:
                    break
                file_size_dl += len(readed_buffer)
                f.write(readed_buffer)
                status = r"%10d  [%3.2f%%]" % (file_size_dl,
                                               file_size_dl * 100. / file_size)
                status += chr(8) * (len(status) + 1)
                print(status, end='')
            f.close()
            print('\n')
        try:
            tar = tarfile.open(directory + '/' + filename, 'r:gz')
            for item in tar:
                if not os.path.exists(item.name):
                    tar.extract(item, path=directory)
        except tarfile.ReadError:
            name = os.path.basename(filename)
            print(name[:name.rfind('.')], '<filename>')

    elif kind == 'HGH':
        while True:
            succeed = True
            ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
            ftp.login()  # user anonymous, passwd anonymous@
            ftp.cwd('pub/abinitio/Psps/LDA_HGH/')
            for filename in ftp.nlst():
                if not os.path.exists(directory + '/' +
                                      filename) or os.path.getsize(
                                          directory + '/' + filename) == 0:
                    print('Getting %s' % filename)
                    try:
                        ftp.retrbinary(
                            'RETR ' + filename,
                            open(directory + '/' + filename, 'wb').write)
                    except ftplib.error_perm:
                        print('Failed to get ', filename)
                        succeed = False
            ftp.close()
            if succeed:
                break
    else:
        ftp = ftplib.FTP('ftp.abinit.org')  # connect to host, default port
        ftp.login()  # user anonymous, passwd anonymous@
        missing_psps = []
        for i in range(1, 113):
            if kind == 'GTH' and i > 17:
                continue
            if kind == 'CORE' and i not in [6, 7]:
                continue
            if kind == 'FHI' and exchange == 'LDA' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'TM' and exchange == 'LDA' and i in [
                    104, 105, 106, 107, 108, 109, 110, 111, 112
            ]:
                continue
            if kind == 'FHI' and exchange == 'GGA' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'AE' and exchange == 'DEN' and i in [
                    57, 59, 63, 65, 66, 67, 90, 94, 102, 110, 111, 112
            ]:
                continue
            if kind == 'GTH' and exchange == 'LDA' and i in [2, 10]:
                continue
            if kind == 'FC' and exchange == 'DEN' and i in [
                    63, 65, 66, 67, 110, 111, 112
            ]:
                continue
            filename = psp_name(i, exchange, kind)
            if not os.path.isfile(directory + '/' +
                                  filename) or os.path.getsize(directory +
                                                               '/' +
                                                               filename) == 0:
                print('Getting...' + filename)
                nofile = True
                while nofile:
                    retr = 'RETR ' + get_rpath_psp(kind, exchange,
                                                   i) + filename
                    try:
                        ftp.retrbinary(
                            retr,
                            open(directory + '/' + filename, 'wb').write)
                        nofile = False
                        if os.path.getsize(directory + '/' + filename) == 0:
                            os.remove(directory + '/' + filename)
                    except ftplib.error_perm:
                        print('Could not download ' + retr)
                        missing_psps.append(i)
                        ftp.close()
                        time.sleep(5)
                        print('Reconnecting...')
                        if os.path.isfile(directory + '/' + filename):
                            os.remove(directory + '/' + filename)
                        ftp = ftplib.FTP(
                            'ftp.abinit.org')  # connect to host, default port
                        ftp.login()  # user anonymous, passwd anonymous@
                        nofile = False
        ftp.close()
        if len(missing_psps) > 0:
            print("kind == '%s' and exchange == '%s' and i in %s" %
                  (kind, exchange, missing_psps))