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
3038606e
Commit
3038606e
authored
1 year ago
by
Nathan Daelman
Browse files
Options
Downloads
Patches
Plain Diff
Add DB posting
parent
91b91ff7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
__main__.py
+24
-11
24 additions, 11 deletions
__main__.py
general_parser.py
+1
-1
1 addition, 1 deletion
general_parser.py
to_db.py
+27
-0
27 additions, 0 deletions
to_db.py
with
52 additions
and
12 deletions
__main__.py
+
24
−
11
View file @
3038606e
from
neomodel
import
config
from
pathlib
import
Path
import
yaml
from
to_db
import
post
from
general_parser
import
trace_files
from
maple_parser
import
handler_maple
maple_dir
=
"
maple
"
maple_files
=
[
"
gga_k_apbe.mpl
"
]
def
get_neo4j_settings
()
->
tuple
[
str
,
str
,
str
,
str
]:
with
open
(
"
config.yaml
"
,
"
r
"
)
as
file
:
config
=
yaml
.
safe_load
(
file
)
file
.
close
()
return
(
config
[
"
neo4j
"
][
"
user
"
],
config
[
"
neo4j
"
][
"
password
"
],
config
[
"
neo4j
"
][
"
host
"
],
config
[
"
neo4j
"
][
"
port
"
],
)
def
get_libxc_settings
()
->
tuple
[
str
,
str
]:
# Read the YAML file
with
open
(
"
config.yaml
"
,
"
r
"
)
as
file
:
config
=
yaml
.
safe_load
(
file
)
file
.
close
()
return
config
[
"
libxc
"
][
"
path
"
],
config
[
"
libxc
"
][
"
maple
"
]
def
__main__
():
# set up Neo4j connection
config
.
DATABASE_URL
=
"
bolt://{}:{}@{}:{}
"
.
format
(
*
get_neo4j_settings
())
# Parse the Maple files
maple_dir
=
"
{}/{}/
"
.
format
(
*
get_libxc_settings
())
maple_files
=
[
str
(
file
).
split
(
'
/
'
)[
-
1
]
for
file
in
Path
(
maple_dir
).
rglob
(
'
*.mpl
'
)]
maple_files
=
[
str
(
file
).
split
(
"
/
"
)[
-
1
]
for
file
in
Path
(
maple_dir
).
rglob
(
"
*.mpl
"
)]
for
maple_file
in
maple_files
:
triples
=
trace_files
(
maple_file
,
maple_dir
,
handler_maple
,
triples
=
set
()
)
triples
=
trace_files
(
maple_file
,
maple_dir
,
handler_maple
,
triples
=
set
())
for
triple
in
triples
:
if
triple
[
2
]
==
"
FileReference
"
:
print
(
f
"
Maple file
{
triple
[
0
]
}
references
{
triple
[
1
]
}
"
)
post
(
triple
)
# execute the main function
if
__name__
==
"
__main__
"
:
...
...
This diff is collapsed.
Click to expand it.
general_parser.py
+
1
−
1
View file @
3038606e
...
...
@@ -16,7 +16,7 @@ FileHandler = Callable[[FileName], set[Triple]]
def
file_path_to_name
(
file_path
:
str
)
->
str
:
return
file_path
.
split
(
"
/
"
)[
-
1
]
return
file_path
.
replace
(
'
//
'
,
'
/
'
).
split
(
"
/
"
)[
-
1
]
def
read_file
(
file_path
:
str
,
line_processor
:
Callable
[[
str
],
str
])
->
FileContents
:
with
open
(
file_path
,
"
r
"
)
as
file
:
...
...
This diff is collapsed.
Click to expand it.
to_db.py
0 → 100644
+
27
−
0
View file @
3038606e
from
neomodel
import
StructuredNode
,
StringProperty
,
RelationshipTo
from
general_parser
import
Triple
class
FileNode
(
StructuredNode
):
name
=
StringProperty
(
unique_index
=
True
,
required
=
True
)
# parameters defined?
references
=
RelationshipTo
(
"
FileNode
"
,
"
references
"
)
def
file_path_to_name
(
file_path
:
str
)
->
str
:
return
file_path
.
split
(
"
/
"
)[
-
1
]
def
post_file_reference
(
file_path_1
:
str
,
file_path_2
:
str
)
->
None
:
file_1
=
FileNode
.
get_or_create
(
{
"
path
"
:
file_path_1
,
"
name
"
:
file_path_to_name
(
file_path_1
)}
)[
0
]
file_2
=
FileNode
.
get_or_create
(
{
"
path
"
:
file_path_2
,
"
name
"
:
file_path_to_name
(
file_path_2
)}
)[
0
]
file_1
.
references
.
connect
(
file_2
)
def
post
(
triple
:
Triple
):
if
triple
[
2
]
==
"
FileReference
"
:
post_file_reference
(
triple
[
0
],
triple
[
1
])
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