Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
parser-molcas
Commits
b63f2e94
Commit
b63f2e94
authored
Oct 10, 2016
by
Ask Hjorth Larsen
Browse files
parse input positions, atom labels, in simple cases total energy
parent
1d840b18
Changes
2
Hide whitespace changes
Inline
Side-by-side
parser/parser-molcas/main.py
View file @
b63f2e94
...
...
@@ -23,18 +23,132 @@ metaInfoEnv, warnings = loadJsonFile(filePath=metaInfoPath,
parser_info
=
{
'name'
:
'molcas-parser'
,
'version'
:
'1.0'
}
class
MolcasContext
(
object
):
def
__init__
(
self
):
self
.
data
=
{}
def
startedParsing
(
self
,
fname
,
parser
):
pass
def
onClose_section_method
(
self
,
backend
,
gindex
,
section
):
pass
# DFT etc
def
onClose_section_system
(
self
,
backend
,
gindex
,
section
):
matrix
=
self
.
data
.
pop
(
'coordinates'
)
atom_labels
=
matrix
[:,
1
]
coords
=
matrix
[:,
2
:
5
].
astype
(
float
)
coords
=
convert_unit
(
coords
,
'bohr'
)
backend
.
addArrayValues
(
'atom_labels'
,
atom_labels
)
backend
.
addArrayValues
(
'atom_positions'
,
coords
)
backend
.
addArrayValues
(
'configuration_periodic_dimensions'
,
np
.
zeros
(
3
,
bool
))
# multi_sm copied from Siesta/GULP
def
multi_sm
(
self
,
name
,
startpattern
,
linepattern
,
endmatcher
=
None
,
conflict
=
'fail'
,
# 'fail', 'keep', 'overwrite'
*
args
,
**
kwargs
):
pat
=
re
.
compile
(
linepattern
)
# XXX how to get compiled pattern?
ngroups
=
pat
.
groups
allgroups
=
[]
def
addline
(
parser
):
line
=
parser
.
fIn
.
readline
()
match
=
pat
.
match
(
line
)
assert
match
is
not
None
thislinegroups
=
match
.
groups
()
assert
len
(
thislinegroups
)
==
ngroups
allgroups
.
append
(
thislinegroups
)
def
savearray
(
parser
):
arr
=
np
.
array
(
allgroups
,
dtype
=
object
)
del
allgroups
[:]
if
name
in
self
.
data
:
if
conflict
==
'fail'
:
raise
ValueError
(
'grrr %s %s'
%
(
name
,
self
.
data
[
name
]))
elif
conflict
==
'keep'
:
return
# Do not save array
elif
conflict
==
'overwrite'
:
pass
else
:
raise
ValueError
(
'Unknown keyword %s'
%
conflict
)
#if arr.size > 0:
if
arr
.
size
==
0
:
arr
.
shape
=
(
0
,
ngroups
)
self
.
data
[
name
]
=
arr
if
endmatcher
is
None
:
endmatcher
=
r
'.*'
if
hasattr
(
endmatcher
,
'swapcase'
):
endmatcher
=
SM
(
endmatcher
,
endReStr
=
''
,
forwardMatch
=
True
,
name
=
'%s-end'
%
name
,
adHoc
=
savearray
)
sm
=
SM
(
startpattern
,
name
=
name
,
subMatchers
=
[
SM
(
linepattern
,
name
=
'%s-line'
%
name
,
repeats
=
True
,
forwardMatch
=
True
,
required
=
True
,
adHoc
=
addline
),
endmatcher
,
],
**
kwargs
)
return
sm
context
=
MolcasContext
()
def
get_inputfile_echo_sm
():
m
=
SM
(
r
'\+\+\s*----+\s*Input file\s*---+'
,
endReStr
=
'--\s*-------+'
,
sections
=
[
'section_method'
],
name
=
'inputfile'
)
return
m
def
get_system_sm
():
m
=
SM
(
r
'\s*Molecular structure info:'
,
name
=
'structure'
,
sections
=
[
'section_system'
],
subMatchers
=
[
SM
(
r
'\s*\*+\s*Cartesian Coordinates / Bohr, Angstrom\s*\*+'
,
subMatchers
=
[
context
.
multi_sm
(
'coordinates'
,
r
'\s*Center\s*Label\s*x\s*y\s*z\s*x\s*y\s*z'
,
r
'\s*\d+\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)'
)
])
])
return
m
def
get_finalresults_sm
():
# Other modes than SCF/KS-DFT?
m
=
SM
(
r
'\s*\*\s*SCF/KS-DFT Program, Final results'
,
endReStr
=
'\s*Molecular Properties'
,
# No clue when to really stop matching this
sections
=
[
'section_single_configuration_calculation'
],
name
=
'results'
,
subMatchers
=
[
SM
(
r
'\s*Total SCF energy\s*(?P<energy_total__eV>\S+)'
,
name
=
'etot'
)
# XXX eV?
])
return
m
mainFileDescription
=
SM
(
name
=
'root'
,
weak
=
True
,
startReStr
=
''
,
fixedStartValues
=
{
'program_name'
:
'Molcas'
},
sections
=
[
'section_run'
],
subMatchers
=
[])
subMatchers
=
[
get_inputfile_echo_sm
(),
get_system_sm
(),
get_finalresults_sm
(),
SM
(
r
'x^'
,
# force parser to parse the whole file
name
=
'impossible'
)
])
def
main
(
**
kwargs
):
mainFunction
(
mainFileDescription
=
mainFileDescription
,
...
...
test/examples/.gitignore
0 → 100644
View file @
b63f2e94
*.json
*.annotate
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment