Updating particle filters

135 views
Skip to first unread message

ADRIAN PINTO

unread,
Jul 30, 2023, 2:58:54 AM7/30/23
to hoomd-users
Hi,

I created a few stationary particles in my simulations using filters. Now, I want to update them at a later step. In the documentation page, there is an updater called FilterUpdater, but I'm unable to figure out how to use it exactly. I checked for example scripts to help me with the task, but found none.

This is what I am doing.

As an example script, I am initializing two particles. I'm creating two groups particle and stationary with hoomd.filters.Tags. Now, I instantiate filter updater with [stationary] as my parameter. But this doesn't help.

filter_update = hoomd.update.FilterUpdater(trigger = 100, filters = [stationary])

cpu = hoomd.device.CPU()
sim = hoomd.Simulation(cpu, seed = 100)
sim.create_state_from_gsd("lattice.gsd")
sim.operations.integrator = integrator
sim.operations.writers.append(gsd_writer)
# sim.operations.updaters.append(move_action)
sim.operations.updaters.append(filter_update)
Any help would be much appreciated.

Best regards,
Adrian

Joshua Anderson

unread,
Jul 31, 2023, 8:23:28 AM7/31/23
to hoomd...@googlegroups.com
Adrian,

When I run your script, I get `NameError: name 'hoomd' is not defined`. I don't understand what output you get compared to what you expect.
------
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/ac53be9a-2d56-439a-baa0-1d51d1616340n%40googlegroups.com.

ADRIAN PINTO

unread,
Jul 31, 2023, 8:29:30 AM7/31/23
to hoomd...@googlegroups.com
Hi Joshua,

That was just a snippet of the code. Here is the entire code. I want the stationary particle to get updated since I have used FilterUpdater. In my actual system, I want to update filters dynamically, that's why I have written this example script.

import numpy as np
import hoomd
import gsd.hoomd


L = 200
box_size = [L, L, L, 0, 0, 0]
xpos = np.zeros(2)
ypos = np.zeros(2)
zpos = np.zeros(2)

xpos[0] = 1
xpos[1] = 10

vx = np.zeros(2)
vy = np.zeros(2)
vz = np.zeros(2)

vx[0] = 0.1
vx[1] = -0.1


frame = gsd.hoomd.Frame()
frame.configuration.box = box_size
frame.particles.N = 2
frame.particles.position = list(zip(xpos, ypos, zpos))
frame.particles.velocity = list(zip(vx, vy, vz))
frame.particles.types = ['A']
frame.particles.typeid = [0]*2

particle1 = hoomd.filter.Tags([0])
stationary = hoomd.filter.Tags([1])

# class ExampleAction(hoomd.custom.Action):
# def act(self, timestep):
# self._state.snapshot.particles.position[1] = self._state.snapshot.particles.position[1] + 1

with gsd.hoomd.open(name='lattice.gsd', mode='w') as f:
f.append(frame)

nl = hoomd.md.nlist.Cell(buffer = 1)
nlist = hoomd.md.nlist.Tree(buffer=0.4, exclusions=('bond',), rebuild_check_delay=10, check_dist=True, mesh=None, default_r_cut=3)
fslj = hoomd.md.pair.ForceShiftedLJ(nlist=nlist, default_r_cut=3)
fslj.params[('A', 'A')] = dict(epsilon=1.0, sigma=0.8)

dt = 0.001
MTTK = hoomd.md.methods.thermostats.Berendsen(kT=1.0, tau=dt*100)
nvt = hoomd.md.methods.ConstantVolume(filter=particle1,
thermostat=MTTK)


integrator = hoomd.md.Integrator(dt = 0.001, methods=[nvt], forces = [fslj])



gsd_writer = hoomd.write.GSD(filename='molecular_trajectory_1.gsd',
trigger=hoomd.trigger.Periodic(10),
mode='wb')


class moveAction(hoomd.custom.Action):

def act(self, timestep):
pass

action_custom = moveAction()
# move_action = hoomd.update.CustomUpdater(trigger = 1000, action = action_custom)
filter_update = hoomd.update.FilterUpdater(trigger = 1, filters = [stationary])

cpu = hoomd.device.CPU()
sim = hoomd.Simulation(cpu, seed = 100)
sim.create_state_from_gsd("lattice.gsd")
sim.operations.integrator = integrator
sim.operations.writers.append(gsd_writer)
# sim.operations.updaters.append(move_action)
sim.operations.updaters.append(filter_update)

logger = hoomd.logging.Logger(categories=['scalar', 'string'])
logger.add(sim, quantities= ['timestep', 'tps'])
#table_file = hoomd.write.Table(output=file, trigger = hoomd.trigger.Periodic(period = 100000), logger = logger1)
table = hoomd.write.Table(trigger = hoomd.trigger.Periodic(period = 100000), logger = logger)
sim.operations.writers.append(table)
sim.run(10e5)



Best regards,
Adrian

You received this message because you are subscribed to a topic in the Google Groups "hoomd-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hoomd-users/zkJG_2NZFh4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hoomd-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/873686AE-E414-43E1-83DA-24D5EA751395%40umich.edu.

Joshua Anderson

unread,
Jul 31, 2023, 9:07:32 AM7/31/23
to hoomd...@googlegroups.com
Adrian,

I executed your script and get the output I expect. Particle 0 moves and particle 1 remains stationary. Particle 0 is selected by the filter `particle1` and integrated by the `nvt` integration method. Particle 1 remains stationary because it is selected by the `particle1` filter, not because it is in the unused `stationary` group.

Use `FilterUpdater` with a a dynamic filter, such as one that selects based on time or particle position, AND use the updated filter in the integration method to define the particles that you wish to be integrated. See `CustomFilter` for details on defining your own filters: https://hoomd-blue.readthedocs.io/en/v4.0.1/module-hoomd-filter.html#hoomd.filter.CustomFilter
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
Reply all
Reply to author
Forward
0 new messages