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
6f706543
Commit
6f706543
authored
10 years ago
by
sjplimp
Browse files
Options
Downloads
Patches
Plain Diff
git-svn-id:
svn://svn.icms.temple.edu/lammps-ro/trunk@13233
f3b2605a-c512-4ea7-a41b-209d697bcdaa
parent
9f8c7a43
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/README
+5
-6
5 additions, 6 deletions
python/README
python/lammps.py
+36
-18
36 additions, 18 deletions
python/lammps.py
with
41 additions
and
24 deletions
python/README
+
5
−
6
View file @
6f706543
...
...
@@ -8,14 +8,13 @@ doc/Section_python.html and in doc/Section_start.html#start_5.
Basically you need to follow these steps in the src directory:
% make makeshlib # creates Makefile.shlib
% make -f Makefile.shlib g++ # build for whatever machine target you wish
% make g++ mode=shlib # build for whatever machine target you wish
% make install-python # may need to do this via sudo
You can replace the last step
with running the python/install.py
script directly to give you more control over where two relevant files
are installed, or by setting environment variables in your shell
script
. See doc/Section_python.html for details.
You can replace the last step
by a one-time setting of environment
variables in your shell script. Or you can run the python/install.py
script directly to give you more control over where the two relevant
files are installed
. See doc/Section_python.html for details.
You can then launch Python and instantiate an instance of LAMMPS:
...
...
This diff is collapsed.
Click to expand it.
python/lammps.py
+
36
−
18
View file @
6f706543
...
...
@@ -17,11 +17,11 @@ import sys,traceback,types
from
ctypes
import
*
class
lammps
:
def
__init__
(
self
,
name
=
""
,
cmdargs
=
None
):
def
__init__
(
self
,
name
=
""
,
cmdargs
=
None
,
ptr
=
None
):
# load liblammps.so by default
# if name = "g++", load liblammps_g++.so
try
:
if
not
name
:
self
.
lib
=
CDLL
(
"
liblammps.so
"
,
RTLD_GLOBAL
)
else
:
self
.
lib
=
CDLL
(
"
liblammps_%s.so
"
%
name
,
RTLD_GLOBAL
)
...
...
@@ -30,28 +30,39 @@ class lammps:
traceback
.
print_exception
(
type
,
value
,
tb
)
raise
OSError
,
"
Could not load LAMMPS dynamic library
"
# create an instance of LAMMPS
# don't know how to pass an MPI communicator from PyPar
# no_mpi call lets LAMMPS use MPI_COMM_WORLD
# cargs = array of C strings from args
# if no ptr provided, create an instance of LAMMPS
# don't know how to pass an MPI communicator from PyPar
# no_mpi call lets LAMMPS use MPI_COMM_WORLD
# cargs = array of C strings from args
# if ptr, then are embedding Python in LAMMPS input script
# ptr is the desired instance of LAMMPS
# just convert it to ctypes ptr and store in self.lmp
if
cmdargs
:
cmdargs
.
insert
(
0
,
"
lammps.py
"
)
narg
=
len
(
cmdargs
)
cargs
=
(
c_char_p
*
narg
)(
*
cmdargs
)
self
.
lmp
=
c_void_p
()
self
.
lib
.
lammps_open_no_mpi
(
narg
,
cargs
,
byref
(
self
.
lmp
))
if
not
ptr
:
self
.
opened
=
1
if
cmdargs
:
cmdargs
.
insert
(
0
,
"
lammps.py
"
)
narg
=
len
(
cmdargs
)
cargs
=
(
c_char_p
*
narg
)(
*
cmdargs
)
self
.
lmp
=
c_void_p
()
self
.
lib
.
lammps_open_no_mpi
(
narg
,
cargs
,
byref
(
self
.
lmp
))
else
:
self
.
lmp
=
c_void_p
()
self
.
lib
.
lammps_open_no_mpi
(
0
,
None
,
byref
(
self
.
lmp
))
# could use just this if LAMMPS lib interface supported it
# self.lmp = self.lib.lammps_open_no_mpi(0,None)
else
:
self
.
lmp
=
c_void_p
()
self
.
lib
.
lammps_open_no_mpi
(
0
,
None
,
byref
(
self
.
lmp
))
# could use just this if LAMMPS lib interface supported it
# self.lmp = self.lib.lammps_open_no_mpi(0,None)
self
.
opened
=
0
# magic to convert ptr to ctypes ptr
pythonapi
.
PyCObject_AsVoidPtr
.
restype
=
c_void_p
pythonapi
.
PyCObject_AsVoidPtr
.
argtypes
=
[
py_object
]
self
.
lmp
=
c_void_p
(
pythonapi
.
PyCObject_AsVoidPtr
(
ptr
))
def
__del__
(
self
):
if
self
.
lmp
:
self
.
lib
.
lammps_close
(
self
.
lmp
)
if
self
.
lmp
and
self
.
opened
:
self
.
lib
.
lammps_close
(
self
.
lmp
)
def
close
(
self
):
self
.
lib
.
lammps_close
(
self
.
lmp
)
if
self
.
opened
:
self
.
lib
.
lammps_close
(
self
.
lmp
)
self
.
lmp
=
None
def
file
(
self
,
file
):
...
...
@@ -142,6 +153,13 @@ class lammps:
return
result
return
None
# set variable value
# value is converted to string
# returns 0 for success, -1 if failed
def
set_variable
(
self
,
name
,
value
):
return
self
.
lib
.
lammps_set_variable
(
self
.
lmp
,
name
,
str
(
value
))
# return total number of atoms in system
def
get_natoms
(
self
):
...
...
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