Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F93230679
potential_shortening.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 27, 05:03
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Nov 29, 05:03 (2 d)
Engine
blob
Format
Raw Data
Handle
22599967
Attached To
rLAMMPS lammps
potential_shortening.py
View Options
import
numpy
as
np
from
collections
import
defaultdict
class
Consts
:
def
__init__
(
self
,
fname
):
self
.
nlayer
,
self
.
nsp
,
self
.
nhl0
,
self
.
nhl1
,
self
.
lines
=
self
.
read
(
fname
)
def
read
(
self
,
fname
):
with
open
(
fname
)
as
fh
:
line
=
fh
.
__next__
()
line_read
=
tuple
((
int
(
item
)
for
item
in
line
.
split
()))
nlayer
,
nsp
,
nhl0
,
nhl1
=
line_read
lines
=
[]
for
i
in
range
(
nhl0
):
lines
.
append
(
fh
.
__next__
()
.
rstrip
())
return
nlayer
,
nsp
,
nhl0
,
nhl1
,
lines
def
reformulate
(
self
,
outfname
,
nhl0_div
,
nhl1_div
):
with
open
(
outfname
,
'w'
)
as
fh
:
print
(
" {} {} {} {}"
.
format
(
self
.
nlayer
,
self
.
nsp
,
int
(
self
.
nhl0
/
nhl0_div
),
int
(
self
.
nhl1
/
nhl1_div
)),
file
=
fh
)
for
i
in
range
(
int
(
self
.
nhl0
/
nhl0_div
)):
print
(
self
.
lines
[
i
*
nhl0_div
],
file
=
fh
)
class
Params
:
def
__init__
(
self
,
fname
,
nhl0
,
nhl1
):
self
.
nb_comb
,
self
.
r1
,
self
.
r2
,
self
.
lines
=
self
.
read
(
fname
)
self
.
nhl0
=
nhl0
self
.
nhl1
=
nhl1
def
read
(
self
,
fname
):
with
open
(
fname
)
as
fh
:
line
=
fh
.
__next__
()
ls
=
line
.
split
()
n_comb
,
r1
,
r2
=
int
(
ls
[
0
]),
float
(
ls
[
1
]),
float
(
ls
[
2
])
lines
=
[
line
.
rstrip
()
for
line
in
fh
]
return
n_comb
,
r1
,
r2
,
lines
def
reformulate
(
self
,
outfname
,
nhl0_div
,
nhl1_div
):
with
open
(
outfname
,
'w'
)
as
fh
:
print
(
" {} {} {}"
.
format
(
int
((
self
.
nhl0
/
nhl0_div
+
1
)
*
self
.
nhl1
/
nhl1_div
),
self
.
r1
,
self
.
r2
),
file
=
fh
)
n0
=
int
(
self
.
nhl0
/
nhl0_div
)
n1
=
int
(
self
.
nhl1
/
nhl1_div
)
for
i0
in
range
(
n0
):
for
i1
in
range
(
n1
):
print
(
self
.
lines
[
i0
*
nhl0_div
*
self
.
nhl1
+
i1
*
nhl1_div
],
file
=
fh
)
for
i1
in
range
(
n1
):
print
(
self
.
lines
[
self
.
nhl0
*
self
.
nhl1
+
i1
*
nhl1_div
],
file
=
fh
)
def
main
():
cfname
=
'in.const.NN'
pfname
=
'in.params.NN'
suffix
=
'_short'
ocfname
=
cfname
+
suffix
opfname
=
pfname
+
suffix
div0
=
5
div1
=
10
c
=
Consts
(
cfname
)
c
.
reformulate
(
ocfname
,
div0
,
div1
)
Params
(
pfname
,
c
.
nhl0
,
c
.
nhl1
)
.
reformulate
(
opfname
,
div0
,
div1
)
if
__name__
==
"__main__"
:
main
()
Event Timeline
Log In to Comment