File: octopus.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (32 lines) | stat: -rw-r--r-- 1,093 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
import os
from ase.calculators.octopus import parse_input_file, kwargs2atoms


def read_octopus(fileobj, get_kwargs=False):
    if isinstance(fileobj, str):  # This could be solved with decorators...
        fileobj = open(fileobj)

    names, values = parse_input_file(fileobj)

    # input files may contain internal references to other files such
    # as xyz or xsf.  We need to know the directory where the file
    # resides in order to locate those.  If fileobj is a real file
    # object, it contains the path and we can use it.  Else assume
    # pwd.
    #
    # Maybe this is ugly; maybe it can lead to strange bugs if someone
    # wants a non-standard file-like type.  But it's probably better than
    # failing 'ase-gui somedir/inp'
    try:
        fname = fileobj.name
    except AttributeError:
        directory = None
    else:
        directory = os.path.split(fname)[0]

    kwargs = dict(zip(names, values))
    atoms, remaining_kwargs = kwargs2atoms(kwargs, directory=directory)
    if get_kwargs:
        return atoms, remaining_kwargs
    else:
        return atoms