Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92466497
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 20, 13:29
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Nov 22, 13:29 (2 d)
Engine
blob
Format
Raw Data
Handle
22445658
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__
())
return
*
line_read
,
lines
def
reformulate
(
self
,
outfname
,
nhl0_div
,
nhl1_div
):
with
open
(
outfname
)
as
fh
:
print
(
"
\t
{}
\t
{}
\t
{}
\t
{}"
.
format
(
self
.
nlayer
,
self
.
nsp
,
self
.
nhl0
/
nhl0_div
,
self
.
nhl1
/
nhl1_div
),
file
=
fh
)
for
i
in
range
(
self
.
nhl0
/
nhl0_div
):
print
(
self
.
lines
[
i
*
nhl0_div
],
file
=
fh
)
class
Params
:
def
__init__
(
self
,
fname
):
self
.
nb_comb
,
self
.
r1
,
self
.
r2
,
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
()))
n_comb
,
r1
,
r2
=
line_read
lines
=
[
line
for
line
in
fh
]
return
n_comb
,
r1
,
r2
,
lines
def
reformulate
(
self
,
outfname
,
nhl0_div
,
nhl1_div
):
with
open
(
outfname
)
as
fh
:
print
(
"
\t
{}
\t
{}
\t
{}"
.
format
(
self
.
nb_comb
/
nhl0_div
/
nhl1_div
,
self
.
r1
,
self
.
r2
),
file
=
fh
)
n0
=
self
.
nhl0
/
nhl0_div
n1
=
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
)
def
main
():
cfname
=
'in.const.NN'
pfname
=
'in.params.NN'
suffix
=
'_short'
ocfname
=
cfname
+
suffix
opfname
=
cpname
+
suffix
div0
=
5
div1
=
10
Const
(
cfname
)
.
reformulate
(
ocfname
,
div0
,
div1
)
Params
(
cpname
)
.
reformulate
(
opfname
,
div0
,
div1
)
if
__name__
==
"__main__"
:
main
()
Event Timeline
Log In to Comment