Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dft_graph_database
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nomad-lab
dft_graph_database
Commits
b0685276
Commit
b0685276
authored
1 year ago
by
Nathan Daelman
Browse files
Options
Downloads
Patches
Plain Diff
Extend further to libxc
parent
14fdec45
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
__main__.py
+1
-22
1 addition, 22 deletions
__main__.py
general_parser.py
+23
-1
23 additions, 1 deletion
general_parser.py
libxc_c_parser.py
+49
-6
49 additions, 6 deletions
libxc_c_parser.py
to_db.py
+8
-0
8 additions, 0 deletions
to_db.py
with
81 additions
and
29 deletions
__main__.py
+
1
−
22
View file @
b0685276
...
...
@@ -2,33 +2,12 @@ from neomodel import config # type: ignore # pylint: disable=import-error,missi
from
pathlib
import
Path
import
resource
import
sys
import
yaml
from
to_db
import
Neo4jOperation
from
general_parser
import
get_neo4j_settings
,
get_libxc_settings
from
maple_parser
import
maple_main
from
libxc_c_parser
import
libxc_main
,
trampoline
def
get_neo4j_settings
()
->
tuple
[
str
,
str
,
str
,
str
]:
with
open
(
"
config.yaml
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
yaml_config
=
yaml
.
safe_load
(
file
)
return
(
yaml_config
[
"
neo4j
"
][
"
user
"
],
yaml_config
[
"
neo4j
"
][
"
password
"
],
yaml_config
[
"
neo4j
"
][
"
host
"
],
yaml_config
[
"
neo4j
"
][
"
port
"
],
)
def
get_libxc_settings
()
->
tuple
[
str
,
str
,
str
]:
with
open
(
"
config.yaml
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
yaml_config
=
yaml
.
safe_load
(
file
)
return
(
yaml_config
[
"
libxc
"
][
"
path
"
],
yaml_config
[
"
libxc
"
][
"
maple
"
],
yaml_config
[
"
libxc
"
][
"
src
"
],
)
def
__main__
():
sys
.
setrecursionlimit
(
1000
)
resource
.
setrlimit
(
resource
.
RLIMIT_STACK
,
(
2
**
25
,
-
1
))
...
...
This diff is collapsed.
Click to expand it.
general_parser.py
+
23
−
1
View file @
b0685276
import
os
from
typing
import
IO
,
Callable
,
Optional
,
Any
from
neomodel
import
StructuredNode
,
RelationshipTo
# type: ignore # pylint: disable=import-error,missing-module-docstring
import
yaml
Triple
=
tuple
[
tuple
[
type
[
StructuredNode
],
dict
[
str
,
Any
]],
# (ModelClass, Properties) for source node
tuple
[
type
[
StructuredNode
],
dict
[
str
,
Any
]],
# (ModelClass, Properties) for target node
type
[
RelationshipTo
]
# Relationship class
Optional
[
type
[
RelationshipTo
]
]
# Relationship class
]
def
get_neo4j_settings
()
->
tuple
[
str
,
str
,
str
,
str
]:
with
open
(
"
config.yaml
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
yaml_config
=
yaml
.
safe_load
(
file
)
return
(
yaml_config
[
"
neo4j
"
][
"
user
"
],
yaml_config
[
"
neo4j
"
][
"
password
"
],
yaml_config
[
"
neo4j
"
][
"
host
"
],
yaml_config
[
"
neo4j
"
][
"
port
"
],
)
def
get_libxc_settings
()
->
tuple
[
str
,
str
,
str
]:
with
open
(
"
config.yaml
"
,
"
r
"
,
encoding
=
"
utf-8
"
)
as
file
:
yaml_config
=
yaml
.
safe_load
(
file
)
return
(
yaml_config
[
"
libxc
"
][
"
path
"
],
yaml_config
[
"
libxc
"
][
"
maple
"
],
yaml_config
[
"
libxc
"
][
"
src
"
],
)
def
read_next
(
file
:
IO
[
str
],
previous_text
:
str
,
cleaner
:
Optional
[
Callable
[[
str
],
str
]]
=
None
)
->
Optional
[
tuple
[
IO
[
str
],
str
,
str
]]:
...
...
This diff is collapsed.
Click to expand it.
libxc_c_parser.py
+
49
−
6
View file @
b0685276
from
functools
import
partial
from
neomodel
import
RelationshipTo
# type: ignore # pylint: disable=import-error,missing-module-docstring
import
re
from
typing
import
IO
,
Callable
,
Union
from
typing
import
IO
,
Any
,
Callable
,
Union
from
general_parser
import
(
Triple
,
flush_text
,
...
...
@@ -8,7 +9,7 @@ from general_parser import (
file_path_to_name
,
read_next
,
)
from
to_db
import
FileNode
from
to_db
import
FileNode
,
FunctionalNode
# matching functions
...
...
@@ -16,11 +17,11 @@ def is_file_reference(line: str) -> bool:
return
line
.
startswith
(
"
#include
"
)
def
is_
descrip
tion_start
(
line
:
str
)
->
bool
:
def
is_
func
tion
al
_start
(
line
:
str
)
->
bool
:
return
line
.
startswith
(
"
const xc_func_info_type
"
)
def
is_
descrip
tion_end
(
line
:
str
)
->
bool
:
def
is_
func
tion
al
_end
(
line
:
str
)
->
bool
:
return
line
.
endswith
(
"
};
"
)
...
...
@@ -41,7 +42,7 @@ def trampoline(func: Callable[..., Union[tuple, Callable]], *args, **kwargs):
# Adjusted process_file_reference to return a function or partial function
def
process_file_reference
(
file
:
IO
[
str
],
text
:
str
,
posts
:
list
[
Triple
]):
def
process_file_reference
(
file
:
IO
[
str
],
text
:
str
,
posts
:
list
[
Triple
])
->
partial
:
"""
Return to the main maple branch after processing a file reference
"""
match
=
re
.
search
(
r
'
#include\s+
"
(.*)
"'
,
text
)
if
match
:
...
...
@@ -60,8 +61,41 @@ def process_file_reference(file: IO[str], text: str, posts: list[Triple]):
return
partial
(
libxc_main
,
*
flush_text
(
file
,
text
,
posts
))
def
filter_out_null
(
x
:
str
)
->
list
[
str
]:
"""
Filter out NULL values from a string
"""
return
[
y
for
y
in
x
.
split
(
"
,
"
)
if
y
!=
"
NULL
"
]
def
process_functional
(
file
:
IO
[
str
],
text
:
str
,
posts
:
list
[
Triple
])
->
partial
:
""""""
post
=
posts
[
-
1
]
functional_attributes
=
post
[
1
][
1
]
if
is_functional_end
(
text
):
post
[
2
]
=
FileNode
.
defines
return
partial
(
libxc_main
,
*
flush_text
(
file
,
text
,
posts
))
if
"
name
"
not
in
functional_attributes
:
match
=
re
.
search
(
r
"
\s+(XC_\w+),
"
,
text
)
if
match
:
functional_attributes
[
"
name
"
]
=
match
.
group
(
1
)
elif
"
citations
"
not
in
functional_attributes
:
match
=
re
.
search
(
r
"
\s+{([\w+,&])}
"
,
text
)
if
match
:
functional_attributes
[
"
citation
"
]
=
filter_out_null
(
match
.
group
(
1
))
elif
"
properties
"
not
in
functional_attributes
:
match
=
re
.
search
(
r
"
\s+{([\w+,])}
"
,
text
)
if
match
:
functional_attributes
[
"
properties
"
]
=
match
.
group
(
1
).
split
(
"
,
"
)[
3
]
elif
"
initiliazer
"
not
in
functional_attributes
:
match
=
re
.
search
(
r
"
\s+([\w+,])
"
,
text
)
if
match
:
functional_attributes
[
"
initializer
"
]
=
filter_out_null
(
match
.
group
(
1
))
return
partial
(
process_functional
,
*
flush_text
(
file
,
text
,
posts
))
# Adjust libxc_main to work with trampoline
def
libxc_main
(
file
:
IO
[
str
],
text
:
str
,
posts
:
list
[
Triple
]):
def
libxc_main
(
file
:
IO
[
str
],
text
:
str
,
posts
:
list
[
Triple
])
->
partial
:
"""
Start on the main maple branch
"""
next_line
=
read_next
(
file
,
text
,
clean_line
)
if
next_line
is
None
:
...
...
@@ -71,5 +105,14 @@ def libxc_main(file: IO[str], text: str, posts: list[Triple]):
if
is_file_reference
(
incoming_text
):
# Return a partial function for trampoline to call
return
partial
(
process_file_reference
,
file
,
new_text
,
posts
)
elif
is_functional_start
(
incoming_text
):
posts
.
append
(
(
(
FileNode
,
{
"
name
"
:
file_path_to_name
(
file
.
name
)}),
(
FunctionalNode
,
{}),
None
,
)
)
return
partial
(
process_functional
,
file
,
new_text
,
posts
)
# Return a partial function for trampoline to continue
return
partial
(
libxc_main
,
file
,
new_text
,
posts
)
This diff is collapsed.
Click to expand it.
to_db.py
+
8
−
0
View file @
b0685276
...
...
@@ -44,9 +44,17 @@ class FileNode(StructuredNode):
name
=
StringProperty
(
unique_index
=
True
,
required
=
True
)
references
=
RelationshipTo
(
"
FileNode
"
,
"
references
"
)
defines
=
RelationshipTo
(
"
FormulaNode
"
,
"
defines
"
)
cites
=
RelationshipTo
(
"
PublicationNode
"
,
"
cites
"
)
class
FormulaNode
(
StructuredNode
):
name
=
StringProperty
(
required
=
True
)
parameters
=
ArrayProperty
(
StringProperty
(),
default
=
[])
function_refs
=
ArrayProperty
(
StringProperty
(),
default
=
[])
class
FunctionalNode
(
StructuredNode
):
name
=
StringProperty
(
required
=
True
)
citations
=
ArrayProperty
(
StringProperty
(),
default
=
[])
properties
=
ArrayProperty
(
StringProperty
(),
default
=
[])
initializer
=
ArrayProperty
(
StringProperty
(),
default
=
[])
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
register
or
sign in
to comment