File: demon_io.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (35 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from ase.calculators.calculator import ReadError
import os.path as op
import numpy as np
from ase.units import Hartree


def parse_xray(filename):
    #filename = self.label + '/deMon.xry'
    if op.isfile(filename):
        with open(filename, 'r') as fd:
            lines = fd.readlines()
            
        mode = lines[0].split()[0]
        ntrans = int(lines[0].split()[1])

        E_trans = []
        osc_strength = []
        trans_dip = []
        for i in range(1, ntrans + 1):
            tokens = lines[i].split()            

            E_trans.append(float(tokens[0]))
            osc_strength.append(
                float(tokens[1].replace('D', 'e')))
            
            dip1 = float(tokens[3].replace('D', 'e'))
            dip2 = float(tokens[4].replace('D', 'e'))
            dip3 = float(tokens[5].replace('D', 'e'))
            trans_dip.append([dip1, dip2, dip3])

        return mode, ntrans, np.array(E_trans) * Hartree, np.array(osc_strength), np.array(trans_dip)
    
    else:
        raise ReadError('The file {0} does not exist'
                        .format(filename))