Enabling packages in LAMMPS Binary if LAMMPS has been installed via Conda

Hello! I am inquiring about the manner in which someone who has installed LAMMPS via Conda can go about enabling packages in (supposedly) their LAMMPS binary. In my case I am trying to run the code I have pasted below. I have also pasted the error output to the best of my ability. I am having most concern about the line, “ERROR: Unrecognized fix style ‘brownian/sphere’ is part of the BROWNIAN package which is not enabled in this LAMMPS binary. (src/modify.cpp:908).” Here are my computer specifications:

LAMMPS version 2021.9.29; macOS Monterey (version 12.4); MacBook Pro (13-inch, 2019) (Processor is a 1.4 GHz Quad-Core Intel Core i5)

Any help would be greatly appreciated. Please respond whenever it is most convenient for you.

CODE

import math
from lammps import lammps
from random import randint
lmp = lammps()

#------------- Initialization
sigma = 1.0
box_length = 30
z_width = 0.25
boltzmann_const = 8.617333262 / 10**(5) #eV/K
eta = 0.1
movie_length = 1
timestep = 0.005

def number_formatting(x):
return format(x, ‘.14f’)

def increment():

value = 1

while True:
    yield value
    value += 1  #

def execute(block):
try:
print(block)
lmp.commands_string(block)
except Exception as e:
print(“LAMMPS failed with error:”, e)

ID = increment()

num_types = int(input(’\nNumber of particle types: ‘))
approx_num_particles = int(input(’\nApproximate Number of particles: '))

data = {}

for k in range(num_types):

data[k] = {}

data[k]["temperature"] = float(input(f'\nEffective temperature of particle #{k + 1} (K): '))
data[k]["radius"] = float(input(f'\nRadius of particle #{k + 1} (m): '))

sum_particles = 0
for k in range(num_types - 1):

eval = float(input(f'\nApproximate Percentage of particles of type #{k+1} (X %): ')) * approx_num_particles / 100

if eval % 1 < 0.5:
    data[k]["particle count"] = math.floor(eval)

else:
    data[k]["particle count"] = math.ceil(eval)

sum_particles = sum_particles + data[k]["particle count"]

data[num_types-1][“particle count”] = abs(approx_num_particles - sum_particles)

sum_particles = sum([data[k][“particle count”] for k in range(num_types)])

for k in range(num_types):
data[k][“percentage”] = data[k][“particle count”]/sum_particles

execute(f’’’

------------- Initialization

units lj
dimension 2
atom_style atomic
boundary f f p
pair_style lj/cut 1.123
pair_modify shift yes

------------- System definition

region testbox block -{box_length} {box_length} -{box_length} {box_length} -{z_width} {z_width}

create_box 2 testbox

‘’’)
for k in range(num_types):
execute(f’’‘group {k+1} region testbox’’’)

for k in range(num_types):
execute(f’’‘create_atoms {k+1} random {data[k][“particle count”]} {randint(100000, 999999)} testbox’’’)

for k in range(num_types):
execute(f’’‘fix {next(ID)} {k+1} brownian/sphere {data[k][“temperature”]} {randint(10000000, 99999999)} rng gaussian’’’)

for k in range(num_types):
execute(f’’‘fix {next(ID)} {k+1} viscous {3math.pieta2data[k][“radius”]}’’’)

for j in range(num_types):
for k in range(num_types):
if j < k:
order = f"{j+1} {k+1}"
else:
order = f"{k+1} {j+1}"
execute(
f’’’
pair_coeff {order} {number_formatting(boltzmann_const * 1/2 * (data[j][“temperature”]+data[k][“temperature”]))} {number_formatting(sigma)} {number_formatting(1.12246152962189*sigma)}’’’)

execute(
f’’’
timestep {timestep}
run 1
dump m0 all movie {movie_length} movie.m4v type type size 200 200
‘’’)

############ ERROR OUTPUT

LAMMPS (29 Sep 2021)
OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98)
using 1 OpenMP thread(s) per MPI task
Number of particle types: >? 2
Approximate Number of particles: >? 10000
Effective temperature of particle #1 (K): >? 200
Radius of particle #1 (m): >? 1
Effective temperature of particle #2 (K): >? 500
Radius of particle #2 (m): >? 1
Approximate Percentage of particles of type #1 (X %): >? 50

------------- Initialization

units lj
dimension 2
atom_style atomic
boundary f f p
pair_style lj/cut 1.123
pair_modify shift yes

------------- System definition

region testbox block -30 30 -30 30 -0.25 0.25
create_box 2 testbox
Created orthogonal box = (-30.000000 -30.000000 -0.25000000) to (30.000000 30.000000 0.25000000)
1 by 1 by 1 MPI processor grid
group 1 region testbox
0 atoms in group 1
group 2 region testbox
0 atoms in group 2
create_atoms 1 random 5000 695763 testbox
Created 5000 atoms
using lattice units in orthogonal box = (-30.000000 -30.000000 -0.25000000) to (30.000000 30.000000 0.25000000)
create_atoms CPU = 0.002 seconds
create_atoms 2 random 5000 445815 testbox
Created 5000 atoms
using lattice units in orthogonal box = (-30.000000 -30.000000 -0.25000000) to (30.000000 30.000000 0.25000000)
create_atoms CPU = 0.001 seconds
fix 1 1 brownian/sphere 200.0 69238573 rng gaussian
ERROR: Unrecognized fix style ‘brownian/sphere’ is part of the BROWNIAN package which is not enabled in this LAMMPS binary. (src/modify.cpp:908)
Last command: fix 1 1 brownian/sphere 200.0 69238573 rng gaussian
LAMMPS failed with error: ERROR: Unrecognized fix style ‘brownian/sphere’ is part of the BROWNIAN package which is not enable
fix 2 2 brownian/sphere 500.0 64559715 rng gaussian
ERROR: Unrecognized fix style ‘brownian/sphere’ is part of the BROWNIAN package which is not enabled in this LAMMPS binary. (src/modify.cpp:908)
Last command: fix 2 2 brownian/sphere 500.0 64559715 rng gaussian
LAMMPS failed with error: ERROR: Unrecognized fix style ‘brownian/sphere’ is part of the BROWNIAN package which is not enable
fix 3 1 viscous 1.8849555921538759
fix 4 2 viscous 1.8849555921538759
pair_coeff 1 1 0.01723466652400 1.00000000000000 1.12246152962189
pair_coeff 1 2 0.03016066641700 1.00000000000000 1.12246152962189
pair_coeff 1 2 0.03016066641700 1.00000000000000 1.12246152962189
pair_coeff 2 2 0.04308666631000 1.00000000000000 1.12246152962189
timestep 0.005
run 1
dump m0 all movie 1 movie.m4v type type size 200 200

ERROR: Not all per-type masses are set (src/atom.cpp:768)
Last command: run 1
LAMMPS failed with error: ERROR: Not all per-type masses are set (src/atom.cpp:768)
import sys; print('Python %s on s' (sys.version, sys.platform))

Enabling a package requires compilation of a new LAMMPS binary. If you install LAMMPS via a system that distributes binaries, this is obviously not possible. You have two options:

  • ask the creators of the binary package to include the additional package in their distribution and wait for an update
  • learn how to build and install LAMMPS from source and build a custom LAMMPS binary with the packages you need on your own

Following up on this to ask about the next step: once you have a custom lammps binary (which I have been using for some time now and has all the packages I need to run my analyses), how does one direct the lammps package to take that particular binary? The lammps() function in the lammps module can take a C++ pointer, but I’m not aware of the particular way to force lammps() to interface with a particular lammps() installation. Is there a way to use a C++ pointer argument to access a custom lammps install? I have looked through the lammps documentation, but don’t see an example about it (2.3.4. Creating or deleting a LAMMPS object — LAMMPS documentation).

There is no example, because it is not a LAMMPS problem but a compiler/linker problem.

When you compile an object file, then it imports the interface from the corresponding .h files.
Then you link your executable. At that point the linker looks at the various object files and looks for the one with a main() function and that has a list of functions that it calls that are not part of the object file. The linker then looks for objects or libraries that contain these functions, adds them to the executable and checks the undefined functions from those new objects and so on until all dependencies are satisfied. This is specifically when happens when you have a static library.

However, you do not use that. Your main() function is the Python interpreter and you import LAMMPS functions at run time from a shared library object (liblammps.so or liblammps.dll or liblammps.dylib or similar). The LAMMPS Python module has the corresponding names of functions to call, but it has to figure out where to find them at run time. Also, you may have multiple copies of liblammps.so on your system and then you need to figure out which one you have loaded. There can be only one loaded at a time. This is determined by the shared linker configuration. There are some default locations (/lib/ or /usr/lib), then there is the LD_LIBRARY_PATH environment variable (or DYLD_LIBRARY_PATH on macOS, or PATH on Windows) which is consulted and finally the folder where the lammps python module is located.

To figure out which specific library is loaded in Python, you can use the following python code

from lammps import lammps
lmp = lammps()
lmp.command('info config')

and that should print out some information about the compile time settings, compiler and packages installed. Here is an example output from my desktop:

$ python 
Python 3.10.9 (main, Dec  7 2022, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lammps import lammps
>>> lmp = lammps()
LAMMPS (3 Nov 2022)
  using 1 OpenMP thread(s) per MPI task
>>> lmp.command("info config")

Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
Printed on Thu Feb 09 17:10:10 2023

LAMMPS version: 3 Nov 2022 / 20221103
Git info: collected-small-changes / patch_3Nov2022-119-g45c2d1f45d / 45c2d1f45d94c759c3ccf1114e57f40ff30e857e

OS information: Linux "Fedora Linux 36 (Thirty Six)" 6.1.8-100.fc36.x86_64 x86_64

sizeof(smallint): 32-bit
sizeof(imageint): 32-bit
sizeof(tagint):   32-bit
sizeof(bigint):   64-bit

Compiler: GNU C++ 12.2.1 20221121 (Red Hat 12.2.1-4) with OpenMP 4.5
C++ standard: C++14

Active compile time flags:

-DLAMMPS_GZIP
-DLAMMPS_PNG
-DLAMMPS_JPEG
-DLAMMPS_FFMPEG
-DLAMMPS_EXCEPTIONS
-DLAMMPS_SMALLBIG

Available compression formats:

Extension: .gz     Command: gzip
Extension: .bz2    Command: bzip2
Extension: .zst    Command: zstd
Extension: .xz     Command: xz
Extension: .lzma   Command: xz
Extension: .lz4    Command: lz4


Installed packages:

ASPHERE AWPMD BOCS BODY BPM BROWNIAN CG-DNA CG-SPICA CLASS2 COLLOID COLVARS 
COMPRESS CORESHELL DIELECTRIC DIFFRACTION DIPOLE DPD-BASIC DPD-MESO DPD-REACT 
DPD-SMOOTH DRUDE EFF ELECTRODE EXTRA-COMPUTE EXTRA-DUMP EXTRA-FIX 
EXTRA-MOLECULE EXTRA-PAIR FEP GPU GRANULAR INTERLAYER KIM KOKKOS KSPACE 
LATBOLTZ MACHDYN MANYBODY MC MDI MEAM MESONT MISC ML-IAP ML-PACE ML-RANN 
ML-SNAP MOFFF MOLECULE MOLFILE MPIIO OPENMP OPT ORIENT PERI PHONON PLUGIN 
POEMS PTM PYTHON QEQ QTB REACTION REAXFF REPLICA RIGID SHOCK SMTBQ SPH SPIN 
SRD TALLY UEF VORONOI YAFF 

Info-Info-Info-Info-Info-Info-Info-Info-Info-Info-Info
>>> 
1 Like