Random box deformations at constant volume

96 views
Skip to first unread message

oyin alabi

unread,
Jul 13, 2023, 6:42:03 PM7/13/23
to hoomd...@googlegroups.com

Hi,

 

I am working on a simulation that requires the simulation box to undergo random deformations at constant volume, I would like to inquire how to specify the box move types, specifically the aspect and shear at a fixed volume. I have looked at the documentation (https://hoomd-blue.readthedocs.io/en/v4.0.1/module-hpmc-update.html#hoomd.hpmc.update.BoxMC) , and I have included the BoxMC in my code.  Please find below a minimum version of the code.

I'd appreciate any suggestion.

 

Thanks,

Oyin

 

#minimum version of the code

# %% import packages

from __future__ import division

from __future__ import print_function

import hoomd

import gsd.hoomd

import math

import freud

import itertools

import numpy as np

from hoomd import hpmc

import coxeter

 

# %% startup parameters  

T =10000  

m= 4 

N_particles= 2* m**3 

seed = 1 

 

#setup initial spacing with no overlaps 

spacing = 1.2

K = math.ceil(N_particles**(1 / 3))

L = K * spacing

x = np.linspace(-L / 2, L / 2, K, endpoint=False)

position = list(itertools.product(x, repeat=3))

position = position[0:N_particles]

orientation = [(1, 0, 0, 0)] * N_particles

 

#define initial snapshot state 

snapshot = gsd.hoomd.Snapshot()

snapshot.particles.N = N_particles

snapshot.configuration.box = [L, L, L,0, 0, 0]

snapshot.particles.typeid = [0] * N_particles

snapshot.particles.types = ['cube']

snapshot.particles.position = position

snapshot.particles.orientation = orientation

with gsd.hoomd.open(name='lattice_c.gsd', mode='wb') as f:

    f.append(snapshot)

 

#define computation device to store the state   

cpu = hoomd.device.CPU()

sim = hoomd.Simulation(device=cpu,seed=seed)

 

 

verts = [[0.05, 0.05, 0.05], [0.05, -0.05, 0.05], [0.05, 0.05, -0.05], [0.05, -0.05, -0.05],[-0.05, 0.05, 0.05], [-0.05, -0.05, 0.05], [-0.05, 0.05, -0.05], [-0.05, -0.05, -0.05]]

shape = coxeter.shapes.ConvexPolyhedron(verts)

vol = shape.volume

 

#setup mc integrator  

mc = hoomd.hpmc.integrate.ConvexPolyhedron()

mc.shape['cube'] = dict(vertices=[

    (0.05, 0.05, 0.05),

    (0.05, -0.05, 0.05),

    (0.05, 0.05, -0.05),

    (0.05, -0.05, -0.05),

    (-0.05, 0.05, 0.05),

    (-0.05, -0.05, 0.05),

    (-0.05, 0.05, -0.05),

    (-0.05, -0.05, -0.05),

])

mc.d['cube'] = 0.15

mc.a['cube'] = 0.2

 

#read state file 

sim.create_state_from_gsd(filename='lattice_c.gsd')     

sim.operations.integrator = mc

 

logger = hoomd.logging.Logger()

logger.add(mc, quantities=['type_shapes'])           

 

sim.run(100) 

#box deformation      

Box_shape= hoomd.hpmc.update.BoxMC(trigger=hoomd.trigger.Periodic(10), betaP=hoomd.variant.Constant(1))

sim.operations.updaters.append(Box_shape)

 

#initial box volume

initial_volume_fraction = (sim.state.N_particles * vol/sim.state.box.volume)

print(initial_volume_fraction)

 

gsd_file.log=logger

gsd_file = hoomd.write.GSD(trigger=hoomd.trigger.Periodic(10),filename='Compression_c.gsd',mode='wb')      #added a file to just record compression and on

 sim.operations.writers.append(gsd_file)

 

 

#performs a quick compress 

initial_box = sim.state.box

final_box = hoomd.Box.from_box(initial_box)

final_volume_fraction = 0.55              

final_box.volume = sim.state.N_particles * vol / final_volume_fraction

 

 

compress = hoomd.hpmc.update.QuickCompress(trigger=hoomd.trigger.Periodic(10),target_box=final_box)

 

logger.add(compress)

#add compress operation to simulation

sim.operations.updaters.append(compress) 

 

 

tune = hoomd.hpmc.tune.MoveSize.scale_solver(moves=['a', 'd'],

                                             target=0.2,

                                             trigger= hoomd.trigger.Periodic(10),

                                             max_translation_move=0.2,

                                             max_rotation_move=0.2)

 

#append tune operation to simulation

sim.operations.tuners.append(tune)

sim.run(1000)

 

#check the compress.complete property if it is not true run for another 1000 steps

while not compress.complete and sim.timestep < 1e6:

 

    sim.run(1000)

Joshua Anderson

unread,
Jul 18, 2023, 2:10:45 PM7/18/23
to hoomd...@googlegroups.com
Oyin,

Set the aspect and shear attributes of Box_shape to enable these move types:

------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/CAEPx1DyNvoOT2%2BNQV1sAM29-b3hypVj4itYRFU_aAmBJMDjaXg%40mail.gmail.com.

oyin alabi

unread,
Jul 20, 2023, 4:49:27 PM7/20/23
to hoomd...@googlegroups.com

Hi,


Thank you for your response. I specified the aspect and shear moves, however I am getting this error "*Warning*: No move types with non-zero weight. UpdaterBoxMC has nothing to do. ".  

Please find below the code. I'd appreciate any suggestion. 

 

Thanks,

Oyin

 

 

# %% import packages

 

from __future__ import division

from __future__ import print_function

 

#import compress_helper

#from compress_helper import length_geom

import hoomd

import gsd.hoomd

import math

#from fresnel import render

#from fresnel import render_movie

import freud

#import matplotlib 

#sim.operations.writers.append(gsd)

 

logger = hoomd.logging.Logger()

logger.add(mc, quantities=['type_shapes'])           

 

sim.run(100) 

       

Box_shape= hoomd.hpmc.update.BoxMC(trigger=hoomd.trigger.Periodic(10), betaP=hoomd.variant.Constant(10.0))

aspect=Box_shape.aspect

aspect.weight= 0.8

aspect.delta=1.2

 

shear=Box_shape.shear

shear.weight= 0.8

shear.delta=1.2

shear.reduce=0.6 

print("shear moves", Box_shape.shear_moves) 

sim.operations.updaters.append(Box_shape)

print("aspect moves", Box_shape.aspect_moves)

print("shear moves", Box_shape.shear_moves) 

 

initial_volume_fraction = (sim.state.N_particles * vol/sim.state.box.volume)

print(initial_volume_fraction)

 

 

gsd_file = hoomd.write.GSD(trigger=hoomd.trigger.Periodic(10),filename='Compression_c.gsd',mode='wb')      #added a file to just record compression and on

gsd_file.log=logger 

sim.operations.writers.append(gsd_file)

 

 

#performs a quick compress 

initial_box = sim.state.box

final_box = hoomd.Box.from_box(initial_box)

final_volume_fraction = 0.55              

final_box.volume = sim.state.N_particles * vol / final_volume_fraction

 

 

compress = hoomd.hpmc.update.QuickCompress(trigger=hoomd.trigger.Periodic(10),target_box=final_box)

 

logger.add(compress)

#add compress operation to simulation

sim.operations.updaters.append(compress) 

 

 

tune = hoomd.hpmc.tune.MoveSize.scale_solver(moves=['a', 'd'],

                                             target=0.2,

                                             trigger= hoomd.trigger.Periodic(10),

                                             max_translation_move=0.2,

                                             max_rotation_move=0.2)

 

#add tune operation to simulation

Joshua Anderson

unread,
Jul 25, 2023, 8:08:33 AM7/25/23
to hoomd...@googlegroups.com
Oyin,

aspect and shear are dictionaries. You need to set them to dictionaries with the keys 'weight', 'delta', and 'reduce' as appropriate. Your code adds attributes by these names, which HOOMD-blue does not expect or examine.

------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

oyin alabi

unread,
Jul 28, 2023, 3:07:34 AM7/28/23
to hoomd...@googlegroups.com
Hi,

Thanks for the suggestion, it works now.

Thanks again,
Oyin

Reply all
Reply to author
Forward
0 new messages