Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parser-gpaw
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is archived. Its data is
read-only
.
Show more breadcrumbs
nomad-lab
parser-gpaw
Commits
883c9a85
Commit
883c9a85
authored
Jan 28, 2016
by
Jens J. Mortensen
Browse files
Options
Downloads
Patches
Plain Diff
Tar file reader
parent
af38582e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
parser/parser-gpaw/tar.py
+61
-0
61 additions, 0 deletions
parser/parser-gpaw/tar.py
with
61 additions
and
0 deletions
parser/parser-gpaw/tar.py
0 → 100644
+
61
−
0
View file @
883c9a85
import
tarfile
import
xml.etree.ElementTree
as
ElementTree
import
numpy
as
np
class
Reader
:
def
__init__
(
self
,
name
):
self
.
dims
=
{}
self
.
shapes
=
{}
self
.
dtypes
=
{}
self
.
parameters
=
{}
self
.
tar
=
tarfile
.
open
(
name
,
'
r
'
)
f
=
self
.
tar
.
extractfile
(
'
info.xml
'
).
read
()
root
=
ElementTree
.
fromstring
(
f
)
self
.
byteswap
=
((
root
.
attrib
[
'
endianness
'
]
==
'
little
'
)
!=
np
.
little_endian
)
for
child
in
root
:
a
=
child
.
attrib
if
child
.
tag
==
'
parameter
'
:
try
:
value
=
eval
(
a
[
'
value
'
],
{})
except
(
SyntaxError
,
NameError
):
value
=
str
(
a
[
'
value
'
])
self
.
parameters
[
a
[
'
name
'
]]
=
value
elif
child
.
tag
==
'
array
'
:
name
=
a
[
'
name
'
]
self
.
dtypes
[
name
]
=
a
[
'
type
'
]
self
.
shapes
[
name
]
=
[]
for
dim
in
child
:
n
=
int
(
dim
.
attrib
[
'
length
'
])
self
.
shapes
[
name
].
append
(
n
)
self
.
dims
[
dim
.
attrib
[
'
name
'
]]
=
n
def
__getattr__
(
self
,
name
):
if
name
in
self
.
parameters
:
return
self
.
parameters
[
name
]
else
:
return
self
.
get_array
(
name
)
def
get_array
(
self
,
name
):
fileobj
=
self
.
tar
.
extractfile
(
name
)
shape
=
self
.
shapes
[
name
]
dtype
=
self
.
dtypes
[
name
]
dtype
=
np
.
dtype
({
'
int
'
:
'
int32
'
}.
get
(
dtype
,
dtype
))
size
=
np
.
prod
(
shape
)
*
dtype
.
itemsize
array
=
np
.
fromstring
(
fileobj
.
read
(
size
),
dtype
)
if
self
.
byteswap
:
array
=
array
.
byteswap
()
if
dtype
==
np
.
int32
:
array
=
np
.
asarray
(
array
,
int
)
array
.
shape
=
shape
return
array
def
close
(
self
):
self
.
tar
.
close
()
if
__name__
==
'
__main__
'
:
r
=
Reader
(
'
H2.gpw
'
)
print
(
r
.
Eigenvalues
,
r
.
FermiLevel
,
r
.
UnitCell
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment