Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MIT_MAHE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
2022 Competition
Software Tools
MIT_MAHE
Commits
c7326e78
Commit
c7326e78
authored
2 years ago
by
Ashrith Sagar Yedlapalli
Browse files
Options
Downloads
Patches
Plain Diff
Update bals2csv.py
parent
ad24e509
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#29569
canceled
2 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bals2csv.py
+85
-0
85 additions, 0 deletions
bals2csv.py
with
85 additions
and
0 deletions
bals2csv.py
0 → 100644
+
85
−
0
View file @
c7326e78
"""
.bals to .csv converter
"""
import
argparse
from
json
import
dumps
as
json_dumps
import
pandas
as
pd
def
_main
():
# For the command line parser.
parser
=
argparse
.
ArgumentParser
(
description
=
'
.bals to .csv converter
'
)
parser
.
add_argument
(
'
input_file
'
,
type
=
str
,
help
=
'
Input .bals file
'
)
parser
.
add_argument
(
'
-o
'
,
'
--output
'
,
dest
=
'
output_file
'
,
type
=
str
,
help
=
'
Output filename
'
)
args
=
parser
.
parse_args
()
with
open
(
args
.
input_file
,
"
r
"
)
as
file
:
contents
=
file
.
readlines
()
json_contents
=
{
"
Index
"
:
[],
"
Number
"
:
[],
"
Name
"
:
[],
"
Chain
"
:
[],
"
InterDG
"
:
[],
"
InterDDG
"
:
[],
"
NormTerDDG
"
:
[],
"
IntraDG
"
:
[],
"
IntraDDG
"
:
[],
"
NormTraDDG
"
:
[],
"
ChainAtoms
"
:
[]
}
for
line
in
contents
:
if
line
.
startswith
(
"
#
"
):
continue
value
=
line
[
0
:
6
].
strip
()
try
:
json_contents
[
"
Index
"
].
append
(
int
(
value
))
except
:
pass
value
=
line
[
6
:
13
].
strip
()
try
:
json_contents
[
"
Number
"
].
append
(
int
(
value
))
except
:
pass
value
=
line
[
13
:
18
].
strip
()
try
:
json_contents
[
"
Name
"
].
append
(
str
(
value
))
except
:
pass
value
=
line
[
18
:
24
].
strip
()
try
:
json_contents
[
"
Chain
"
].
append
(
str
(
value
))
except
:
pass
value
=
line
[
24
:
36
].
strip
()
try
:
json_contents
[
"
InterDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
36
:
48
].
strip
()
try
:
json_contents
[
"
InterDDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
48
:
60
].
strip
()
try
:
json_contents
[
"
NormTerDDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
60
:
72
].
strip
()
try
:
json_contents
[
"
IntraDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
72
:
84
].
strip
()
try
:
json_contents
[
"
IntraDDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
84
:
96
].
strip
()
try
:
json_contents
[
"
NormTraDDG
"
].
append
(
str
(
round
(
float
(
value
),
4
)))
except
:
pass
value
=
line
[
96
:
107
].
strip
()
try
:
json_contents
[
"
ChainAtoms
"
].
append
(
int
(
value
))
except
:
pass
json_contents
=
json_dumps
(
json_contents
)
# Save as .json
json_file
=
args
.
input_file
.
replace
(
"
.bals
"
,
"
.json
"
)
file
=
open
(
json_file
,
"
w
"
)
file
.
write
(
str
(
json_contents
))
# Save as .csv
with
open
(
json_file
,
encoding
=
'
utf-8
'
)
as
file
:
df
=
pd
.
read_json
(
file
)
csv_file
=
args
.
input_file
.
replace
(
"
.bals
"
,
"
.csv
"
)
df
.
to_csv
(
csv_file
,
encoding
=
'
utf-8
'
,
index
=
False
)
if
__name__
==
"
__main__
"
:
_main
()
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