Skip to content

Instantly share code, notes, and snippets.

@bskinn
Created September 18, 2017 13:59
Show Gist options
  • Save bskinn/170f42e44ba1a48c15c7c27f5c3cfd01 to your computer and use it in GitHub Desktop.
Save bskinn/170f42e44ba1a48c15c7c27f5c3cfd01 to your computer and use it in GitHub Desktop.
Script by jevandezande for printing ORCA .gbw contents

From here

#!/usr/bin/env python3

import sys
import numpy as np

file_name = sys.argv[1]

with open(file_name, 'rb') as f:
    f.seek(24)
    offset = int.from_bytes(f.read(8), byteorder='little')
    f.seek(offset)
    operators = np.fromstring(f.read(4), dtype='<i4')[0]
    dimension = np.fromstring(f.read(4), dtype='<i4')[0]

    print('Offset: {}'.format(offset))
    print('Number of Operators: {}'.format(operators))
    print('Basis Dimension: {}'.format(dimension))

    for i in range(operators):
        print('\nOperator: {}'.format(i))
        coefficients = np.fromstring(f.read(8*dimension**2), dtype='<f8')
        occupations = np.fromstring(f.read(8*dimension), dtype='<f8')
        energies = np.fromstring(f.read(8*dimension), dtype='<f8')
        irreps = np.fromstring(f.read(4*dimension), dtype='<i4')
        cores = np.fromstring(f.read(4*dimension), dtype='<i4')

        print('Coefficients')
        for coef in coefficients:
            print('{:16.12f}'.format(coef))
        print('Occupations')
        for occupation in occupations:
            print('{:16.12f}'.format(occupation))
        print('Energies')
        for energy in energies:
            print('{:16.12f}'.format(energy))
        print('Irreps')
        for irrep in irreps:
            print('{}'.format(irrep))
        print('Core')
        for core in cores:
            print('{}'.format(core))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment