Esempio n. 1
0
def download(command, file_name):

    base_url = 'http://www.quantum-machine.org/gdml/' + (
        'data/npz/' if command == 'dataset' else 'models/')
    request = urllib2.urlopen(base_url + file_name)
    file = open(file_name, 'wb')
    filesize = int(request.info().getheaders("Content-Length")[0])

    size = 0
    block_sz = 1024
    while True:
        buffer = request.read(block_sz)
        if not buffer:
            break
        size += len(buffer)
        file.write(buffer)
        ui.progr_bar(size,
                     filesize,
                     disp_str='Downloading: %s (%s bytes)' %
                     (file_name, filesize))
    print ''
    file.close()
Esempio n. 2
0
    sys.exit(
        ui.fail_str('[FAIL]') +
        ' Dataset \'%s\' already exists.' % dataset_file_name)

R = dataset['R']
z = dataset['z']
F = dataset['F']

lattice = dataset['lattice'] if 'lattice' in dataset else None

try:
    with open(dataset_file_name, 'w') as file:

        n = R.shape[0]
        for i, r in enumerate(R):

            e = np.squeeze(dataset['E'][i]) if 'E' in dataset else None
            f = dataset['F'][i, :, :]
            ext_xyz_str = io.generate_xyz_str(r, z, e=e, f=f,
                                              lattice=lattice) + '\n'

            file.write(ext_xyz_str)

            progr = float(i) / (n - 1)
            ui.progr_bar(i, n - 1, disp_str='Exporting %d data points...' % n)

except IOError:
    sys.exit("ERROR: Writing xyz file failed.")

print()