Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lammps
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
multiscale
lammps
Commits
cda82138
Commit
cda82138
authored
8 years ago
by
Richard Berger
Browse files
Options
Downloads
Patches
Plain Diff
Added Python matplotlib plot example
parent
ef940d22
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/examples/matplotlib_plot.py
+93
-0
93 additions, 0 deletions
python/examples/matplotlib_plot.py
with
93 additions
and
0 deletions
python/examples/matplotlib_plot.py
0 → 100755
+
93
−
0
View file @
cda82138
#!/usr/bin/env python -i
# preceding line should have path for Python on your machine
# matplotlib_plot.py
# Purpose: plot Temp of running LAMMPS simulation via matplotlib
# Syntax: plot.py in.lammps Nfreq Nsteps compute-ID
# in.lammps = LAMMPS input script
# Nfreq = plot data point every this many steps
# Nsteps = run for this many steps
# compute-ID = ID of compute that calculates temperature
# (or any other scalar quantity)
from
__future__
import
print_function
import
sys
sys
.
path
.
append
(
"
./pizza
"
)
import
matplotlib
matplotlib
.
use
(
'
tkagg
'
)
import
matplotlib.pyplot
as
plt
# parse command line
argv
=
sys
.
argv
if
len
(
argv
)
!=
5
:
print
(
"
Syntax: plot.py in.lammps Nfreq Nsteps compute-ID
"
)
sys
.
exit
()
infile
=
sys
.
argv
[
1
]
nfreq
=
int
(
sys
.
argv
[
2
])
nsteps
=
int
(
sys
.
argv
[
3
])
compute
=
sys
.
argv
[
4
]
me
=
0
# uncomment if running in parallel via Pypar
#import pypar
#me = pypar.rank()
#nprocs = pypar.size()
from
lammps
import
lammps
lmp
=
lammps
()
# run infile all at once
# assumed to have no run command in it
lmp
.
file
(
infile
)
lmp
.
command
(
"
thermo %d
"
%
nfreq
)
# initial 0-step run to generate initial 1-point plot
lmp
.
command
(
"
run 0 pre yes post no
"
)
value
=
lmp
.
extract_compute
(
compute
,
0
,
0
)
ntimestep
=
0
xaxis
=
[
ntimestep
]
yaxis
=
[
value
]
# create matplotlib plot
# just proc 0 handles plotting
if
me
==
0
:
fig
=
plt
.
figure
()
line
,
=
plt
.
plot
(
xaxis
,
yaxis
)
plt
.
xlim
([
0
,
nsteps
])
plt
.
title
(
compute
)
plt
.
xlabel
(
"
Timestep
"
)
plt
.
ylabel
(
"
Temperature
"
)
plt
.
show
(
block
=
False
)
# run nfreq steps at a time w/out pre/post, query compute, refresh plot
import
time
while
ntimestep
<
nsteps
:
lmp
.
command
(
"
run %d pre no post no
"
%
nfreq
)
ntimestep
+=
nfreq
value
=
lmp
.
extract_compute
(
compute
,
0
,
0
)
xaxis
.
append
(
ntimestep
)
yaxis
.
append
(
value
)
if
me
==
0
:
line
.
set_xdata
(
xaxis
)
line
.
set_ydata
(
yaxis
)
ax
=
plt
.
gca
()
ax
.
relim
()
ax
.
autoscale_view
(
True
,
True
,
True
)
fig
.
canvas
.
draw
()
lmp
.
command
(
"
run 0 pre no post yes
"
)
# uncomment if running in parallel via Pypar
#print("Proc %d out of %d procs has" % (me,nprocs), lmp)
#pypar.finalize()
if
sys
.
version_info
[
0
]
==
3
:
input
(
"
Press Enter to exit...
"
)
else
:
raw_input
(
"
Press Enter to exit...
"
)
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