Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
parser-atk
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nomad-lab
parser-atk
Commits
05fee26f
Commit
05fee26f
authored
Sep 29, 2016
by
Mikkel Strange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaning up in names
parent
ce619eff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
56 deletions
+44
-56
parser/parser-atk/atkio.py
parser/parser-atk/atkio.py
+1
-1
parser/parser-atk/parser_configurations.py
parser/parser-atk/parser_configurations.py
+43
-55
No files found.
parser/parser-atk/atkio.py
View file @
05fee26f
from
scipy.io.netcdf
import
netcdf_file
from
configurations
import
conf_types
from
parser_configurations
2
import
parse_configuration
from
parser_configurations
import
parse_configuration
from
parser_calculator
import
parse_calculator
import
re
...
...
parser/parser-atk/parser_configurations.py
View file @
05fee26f
from
ase
import
Atom
s
from
ase.build
import
bulk
import
re
from
periodic_table
import
things
as
ptab_n
s
from
physical_quantities
import
things
as
physquan_ns
from
configurations
import
conf_types
,
things
as
confs_ns
Angstrom
=
1
Hydrogen
=
type
(
'Hydrogen'
,
(
object
,),
{})
Hydrogen
.
symbol
=
'H'
Helium
=
type
(
'Helium'
,
(
object
,),
{})
Helium
.
symbol
=
'H'
Lithium
=
type
(
'Lithium'
,
(
object
,),
{})
Lithium
.
symbol
=
'Si'
Oxygen
=
type
(
'Oxygen'
,
(
object
,),
{})
Oxygen
.
symbol
=
'O'
Silicon
=
type
(
'Silicon'
,
(
object
,),
{})
Silicon
.
symbol
=
'Si'
def
parse_configuration
(
fd
,
name
,
verbose
=
False
):
""" convert a nanolanguage python script into
ASE list of atoms.
class
UnitCell
:
def
__init__
(
self
,
a
,
b
,
c
,
origin
=
None
):
self
.
cell
=
[
a
,
b
,
c
]
Parameters:
class
FaceCenteredCubic
:
def
__init__
(
self
,
a
):
self
.
cell
=
bulk
(
'X'
,
crystalstructure
=
'fcc'
,
a
=
a
).
get_cell
()
fd: netcdf_file handle
name: str (i.e "BulkConfiguration_gID000")
class
BulkConfiguration
:
def
__init__
(
self
,
bravais_lattice
,
elements
,
cartesian_coordinates
=
None
,
fractional_coordinates
=
None
,
ghost_atoms
=
None
,
velocities
=
None
,
tag_data
=
None
,
fast_init
=
False
):
self
.
bulkconfiguration
=
True
symbols
=
[
e
.
symbol
for
e
in
elements
]
if
cartesian_coordinates
is
not
None
:
positions
=
cartesian_coordinates
scale_atoms
=
False
elif
fractional_coordinates
is
not
None
:
positions
=
fractional_coordinates
scale_atoms
=
True
else
:
positions
=
None
scale_atoms
=
False
pbc
=
True
atoms
=
Atoms
(
symbols
,
positions
,
pbc
=
pbc
)
atoms
.
set_cell
(
bravais_lattice
.
cell
,
scale_atoms
=
scale_atoms
)
self
.
ghost_atoms_indices
=
ghost_atoms
self
.
atoms
=
atoms
def
parse_configuration
(
fd
,
confname
,
verbose
=
False
):
code
=
fd
.
variables
[
confname
].
data
[:].
copy
()
"""
code
=
fd
.
variables
[
name
].
data
[:].
copy
()
code
=
code
.
tostring
().
decode
(
"utf-8"
)
s
=
re
.
search
(
'\s*(?P<name>[0-9a-zA-Z_]+)\s*=\s*BulkConfiguration\('
,
code
)
name
=
s
.
group
(
'name'
)
if
verbose
:
print
(
'
name:'
,
name
)
print
(
'
parsing code:
\n
------------'
)
print
(
code
)
exec
(
code
)
atoms
=
(
locals
()[
name
]).
atoms
return
atoms
things
=
ptab_ns
.
copy
()
things
.
update
(
physquan_ns
)
things
.
update
(
confs_ns
)
exec
(
code
,
{},
things
)
for
obj
in
things
.
values
():
for
conf_type
in
conf_types
:
if
isinstance
(
obj
,
confs_ns
[
conf_type
]):
return
obj
.
atoms
return
-
1
if
__name__
==
'__main__'
:
import
re
from
ase.visualize
import
view
from
scipy.io.netcdf
import
netcdf_file
fd
=
netcdf_file
(
'Water.nc'
,
'r'
)
atoms
=
parse_configuration
(
fd
,
'BulkConfiguration_gID000'
,
verbose
=
True
)
print
(
atoms
)
import
sys
fd
=
netcdf_file
(
sys
.
argv
[
1
],
'r'
)
name
=
'BulkConfiguration_gID000'
atoms
=
parse_configuration
(
fd
,
name
)
view
(
atoms
)
# configurations = {}
# fp_gids = fd.fingerprint_table[:].decode('utf-8').split('#')
# for c in fp_gids:
# if len(c) > 0:
# fingerprint, gID = c.split(':')[:2]
# gID.strip()
# for name in ['BulkConfiguration_' + gID,
# 'MoleculeConfiguration_' + gID]:
# if name in fd.variables.keys():
# configurations[name] = fingerprint
#
# for name, fingerprint in configurations.items():
# print(name+',', fingerprint)
# atoms = parse_configuration(fd, name)
# view(atoms)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment