Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Germain Clavier
python-tools
Commits
149d6417
Commit
149d6417
authored
1 month ago
by
Germain Clavier
Browse files
Options
Downloads
Patches
Plain Diff
Corrected bugs, refactored part of the code
parent
08a7e92c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lammps/plot_forces.py
+41
-28
41 additions, 28 deletions
lammps/plot_forces.py
with
41 additions
and
28 deletions
lammps/plot_forces.py
+
41
−
28
View file @
149d6417
...
...
@@ -12,6 +12,8 @@ import logging
import
sys
from
matplotlib
import
pyplot
as
plt
logger
=
logging
.
getLogger
(
__name__
)
def
compute_energy
(
tp
):
r
=
tp
[
0
]
...
...
@@ -26,14 +28,14 @@ def compute_energy(tp):
return
e
units
=
{
"
lj
"
:
{
"
Energy
"
:
"
Reduced units
"
,
"
Force
"
:
"
Reduced units
"
,
"
kb
"
:
1
},
"
real
"
:
{
"
Energy
"
:
"
kcal/mol
"
,
"
Force
"
:
"
kcal/mol/A
"
,
"
kb
"
:
0.001985875
},
"
metal
"
:
{
"
Energy
"
:
"
eV
"
,
"
Force
"
:
"
eV/A
"
,
"
kb
"
:
8.6173332e-5
},
"
si
"
:
{
"
Energy
"
:
"
J
"
,
"
Force
"
:
"
N
"
,
"
kb
"
:
1.380649e-23
},
"
cgs
"
:
{
"
Energy
"
:
"
ergs
"
,
"
Force
"
:
"
dynes
"
,
"
kb
"
:
1.3806504e-16
},
"
electron
"
:
{
"
Energy
"
:
"
Hartrees
"
,
"
Force
"
:
"
Hartree/Bohr
"
,
"
kb
"
:
3.16681534e-6
},
"
micro
"
:
{
"
Energy
"
:
"
pg·um^2/us^2
"
,
"
Force
"
:
"
pg·um/us^2
"
,
"
kb
"
:
1.3806504e-8
},
"
nano
"
:
{
"
Energy
"
:
"
ag·nm^2/ns^2
"
,
"
Force
"
:
"
ag·nm/ns^2
"
,
"
kb
"
:
0.013806504
},
"
lj
"
:
{
"
Distance
"
:
"
Reduced units
"
,
"
Energy
"
:
"
Reduced units
"
,
"
Force
"
:
"
Reduced units
"
,
"
kb
"
:
1
},
"
real
"
:
{
"
Distance
"
:
"
[A]
"
,
"
Energy
"
:
"
[
kcal/mol
]
"
,
"
Force
"
:
"
[
kcal/mol/A
]
"
,
"
kb
"
:
0.001985875
},
"
metal
"
:
{
"
Distance
"
:
"
[A]
"
,
"
Energy
"
:
"
[
eV
]
"
,
"
Force
"
:
"
[
eV/A
]
"
,
"
kb
"
:
8.6173332e-5
},
"
si
"
:
{
"
Distance
"
:
"
[m]
"
,
"
Energy
"
:
"
[J]
"
,
"
Force
"
:
"
[N]
"
,
"
kb
"
:
1.380649e-23
},
"
cgs
"
:
{
"
Distance
"
:
"
[cm]
"
,
"
Energy
"
:
"
[
ergs
]
"
,
"
Force
"
:
"
[
dynes
]
"
,
"
kb
"
:
1.3806504e-16
},
"
electron
"
:
{
"
Distance
"
:
"
[Bohr]
"
,
"
Energy
"
:
"
[
Hartrees
]
"
,
"
Force
"
:
"
[
Hartree/Bohr
]
"
,
"
kb
"
:
3.16681534e-6
},
"
micro
"
:
{
"
Distance
"
:
"
[um]
"
,
"
Energy
"
:
"
[
pg·um^2/us^2
]
"
,
"
Force
"
:
"
[
pg·um/us^2
]
"
,
"
kb
"
:
1.3806504e-8
},
"
nano
"
:
{
"
Distance
"
:
"
[nm]
"
,
"
Energy
"
:
"
[
ag·nm^2/ns^2
]
"
,
"
Force
"
:
"
[
ag·nm/ns^2
]
"
,
"
kb
"
:
0.013806504
},
}
def
main
():
...
...
@@ -43,9 +45,9 @@ def main():
)
parser
.
add_argument
(
"
-u
"
,
"
--units
"
dest
=
"
units
"
default
=
"
real
"
"
--units
"
,
dest
=
"
units
"
,
default
=
"
real
"
,
help
=
"
Units of the file (LAMMPS units system)
"
,
)
parser
.
add_argument
(
...
...
@@ -86,17 +88,26 @@ def main():
help
=
"
Extract the forces in separate files
"
,
)
args
=
parser
.
parse_args
()
logging
.
basicConfig
(
level
=
logging
.
INFO
)
##########
# Manage arguments
uenergy
=
units
(
args
.
units
)[
"
Energy
"
]
uforce
=
units
(
args
.
units
)[
"
Force
"
]
kb
=
units
(
args
.
units
)[
"
kb
"
]
udistance
=
units
[
args
.
units
][
"
Distance
"
]
uenergy
=
units
[
args
.
units
][
"
Energy
"
]
uforce
=
units
[
args
.
units
][
"
Force
"
]
kb
=
units
[
args
.
units
][
"
kb
"
]
rlabel
=
'
'
.
join
([
"
Rij
"
,
udistance
])
elabel
=
'
'
.
join
([
"
E
"
,
uenergy
])
flabel
=
'
'
.
join
([
"
F
"
,
uforce
])
etitle
=
"
Energy
"
ftitle
=
"
Force
"
font
=
"
DejaVu Sans
"
fontsize
=
30
infile
=
args
.
infile
if
not
os
.
path
.
isfile
(
infile
):
logg
ing
.
error
(
"
Input file not found
"
)
logg
er
.
error
(
"
Input file not found
"
)
sys
.
exit
(
1
)
toplot
=
[]
...
...
@@ -110,7 +121,7 @@ def main():
tok
=
[]
while
not
tok
:
tok
=
next
(
lines
).
partition
(
'
#
'
)[
0
].
rstrip
()
logg
ing
.
info
(
"
Found {} token
"
.
format
(
tok
))
logg
er
.
info
(
"
Found {} token
"
.
format
(
tok
))
infos
=
next
(
lines
).
split
()
npoints
=
int
(
infos
[
1
])
next
(
lines
)
...
...
@@ -128,6 +139,7 @@ def main():
except
StopIteration
:
break
if
args
.
recompute
:
etitle
=
"
Estimated energy
"
for
tp
in
toplot
:
tp
[
1
]
=
compute_energy
(
tp
)
...
...
@@ -143,9 +155,10 @@ def main():
if
args
.
temp
>
0
:
hmin
,
hmax
=
axes
[
0
].
get_xlim
()
axes
[
0
].
hlines
(
kb
*
args
.
temp
,
hmin
,
hmax
,
color
=
"
orange
"
,
label
=
r
'
$k_BT$
'
,
linewidth
=
3
,
linestyles
=
"
dashdot
"
)
logging
.
info
(
"
KbT value= {:e}
"
.
format
(
kb
*
args
.
temp
))
axes
[
0
].
text
(
hmax
/
2.
,
kb
*
args
.
temp
,
'
KbT
'
,
fontsize
=
0.7
*
fontsize
)
logger
.
info
(
"
KbT value= {:e} {:s}
"
.
format
(
kb
*
args
.
temp
,
uenergy
))
else
:
logg
ing
.
info
(
"
Invalid temperature value: {:e}
"
.
format
(
args
.
temp
))
logg
er
.
info
(
"
Invalid temperature value: {:e}
"
.
format
(
args
.
temp
))
if
args
.
xrange
:
xmin
,
xmax
=
list
(
map
(
float
,
args
.
xrange
.
split
(
"
:
"
)))
...
...
@@ -156,30 +169,30 @@ def main():
axes
[
0
].
set_ylim
(
ymin
,
ymax
)
axes
[
1
].
set_ylim
(
ymin
,
ymax
)
font
=
"
DejaVu Sans
"
fontsize
=
30
# Setting axes 0
axes
[
0
].
set_title
(
"
Estimated energy
"
,
fontsize
=
fontsize
)
axes
[
0
].
set_title
(
etitle
,
fontsize
=
fontsize
)
# axes[0].legend(frameon=False, fontsize=fontsize) # Fat font, no frame
axes
[
0
].
set_xlabel
(
"
r [A]
"
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
0
].
set_ylabel
(
"
E [kcal/mol]
"
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
0
].
set_xlabel
(
rlabel
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
0
].
set_ylabel
(
elabel
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
0
].
tick_params
(
axis
=
'
both
'
,
which
=
'
major
'
,
labelsize
=
fontsize
)
# Biggers ticks, bigger ticks label!
# Setting axes 1
axes
[
1
].
set_title
(
"
Tabulated force
"
,
fontsize
=
fontsize
)
axes
[
1
].
set_title
(
ftitle
,
fontsize
=
fontsize
)
axes
[
1
].
legend
(
frameon
=
False
,
fontsize
=
fontsize
)
# Fat font, no frame
axes
[
1
].
set_xlabel
(
"
r [A]
"
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
1
].
set_ylabel
(
"
F [kcal/mol/A]
"
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
1
].
set_xlabel
(
rlabel
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
1
].
set_ylabel
(
flabel
,
fontname
=
font
,
fontsize
=
fontsize
)
# ylabel name, font is Hack, size 30pts
axes
[
1
].
tick_params
(
axis
=
'
both
'
,
which
=
'
major
'
,
labelsize
=
fontsize
)
# Biggers ticks, bigger ticks label!
plt
.
subplots_adjust
(
wspace
=
0.3
)
figManager
=
plt
.
get_current_fig_manager
()
figManager
.
window
.
showMaximized
()
plt
.
show
()
if
args
.
extract
:
for
tp
in
toplot
:
outfile
=
""
.
join
([
tp
[
3
],
'
.plot
'
])
logg
ing
.
info
(
"
Writing file {}
"
.
format
(
outfile
))
logg
er
.
info
(
"
Writing file {}
"
.
format
(
outfile
))
with
open
(
outfile
,
'
w
'
)
as
f
:
f
.
write
(
"
# {} force extracted from {}
\n
"
.
format
(
tp
[
3
],
infile
))
f
.
write
(
"
# {:^20} {:^20} {:^20}
\n
"
.
format
(
'
r
'
,
'
energy
'
,
'
force
'
))
...
...
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