rigid body

320 views
Skip to first unread message

Yulin Luo

unread,
Aug 16, 2021, 11:57:53 PM8/16/21
to hoomd-users
Hi , Dear HOMMD-blue users, I am trying to use   hoomd.group.rigid() to simulate my systems,


my script looks like this:
import sys
import os
import hoomd, hoomd.md as md
from hoomd import *
from hoomd import deprecated

context.initialize("");
deprecated.init.read_xml("1-rigid.xml");

#WCA
nl = hoomd.md.nlist.cell()
lj = hoomd.md.pair.lj(r_cut=2**(1.0/10), nlist=nl);
lj.pair_coeff.set('A', 'A', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'B', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'C', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'D', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('B', 'B', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'C', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'D', epsilon=0, sigma=0.75, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'R', epsilon=0, sigma=0.75, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('C', 'C', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('C', 'D', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('C', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('D', 'D', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('D', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('R', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.set_params(mode="xplor") 

harmonic=hoomd.md.bond.harmonic();
harmonic.bond_coeff.set('C-C',k=30,r0=1.0)
harmonic.bond_coeff.set('C-D',k=30,r0=1.0)
nl.reset_exclusions(exclusions = []);

rigid = hoomd.group.rigid_center()
nonrigid = hoomd.group.nonrigid()
all = hoomd.group.all()

hoomd.md.integrate.mode_standard(dt=0.01);
nvt = hoomd.md.integrate.langevin(group=nonrigid, kT=0.2, seed=42)

lg1 = hoomd.md.integrate.langevin(group=rigid, kT=2.0, seed=42)
lg1.set_gamma('A', gamma=0.5)
lg1.set_gamma('B', gamma=0.5)
lg1.set_gamma('R', gamma=0.5)
hoomd.md.update.zero_momentum()
zeroer= hoomd.md.update.zero_momentum(period=500)

hoomd.analyze.log(filename="thermo.log", 
                  quantities=['potential_energy'],
                  period=100,
                  overwrite=True)
hoomd.dump.gsd("trajectory.gsd",
               period=100,
               group=all,
               overwrite=True)

hoomd.run(10000)

My initial configuration is obtained through “read_xml”, it includes a rigid sphere and two polymer chains.But the trajectory.gsd is very strange(see test.gif or gif below).test.gif
As you can see from the gif, the rigid sphere is not moving, only a  blue particle is moving. Hoomd regards the blue particle as the rigid_center, but the blue particle does not move with the rigid sphere as a whole.

I guess it may be due to the rigid_center settings, when I use the "read_xml" method to set the initial configuration, how should I use the "rigid = hoomd.group.rigid_center()"?
In other words, do I still need to specify the position of the rigid_center?

Could you please help me with this issue? Thanks in advance.

Best,

Yulin Luo
test.gif

Joshua Anderson

unread,
Aug 23, 2021, 8:01:05 AM8/23/21
to hoomd...@googlegroups.com
Yulin,

Your script is missing the hoomd.md.constrain.rigid object: https://hoomd-blue.readthedocs.io/en/v2.9.7/module-md-constrain.html#hoomd.md.constrain.rigid
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
> My initial configuration is obtained through “read_xml”, it includes a rigid sphere and two polymer chains.But the trajectory.gsd is very strange(see test.gif or gif below).<test.gif>
> As you can see from the gif, the rigid sphere is not moving, only a blue particle is moving. Hoomd regards the blue particle as the rigid_center, but the blue particle does not move with the rigid sphere as a whole.
>
> I guess it may be due to the rigid_center settings, when I use the "read_xml" method to set the initial configuration, how should I use the "rigid = hoomd.group.rigid_center()"?
> In other words, do I still need to specify the position of the rigid_center?
>
> Could you please help me with this issue? Thanks in advance.
>
> Best,
>
> Yulin Luo
>
> --
> 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/4207bebc-21ac-4f7a-a5c3-90209ca5898bn%40googlegroups.com.
> <test.gif><test.gif>

Yulin Luo

unread,
Aug 23, 2021, 10:09:24 AM8/23/21
to hoomd-users
Anderson:
Hi !Thanks for your suggestion!
As you suggested, I added  “hoomd.md.constrain.rigid ”  to my script, my script looks like this:

import numpy as np
import pandas as pd
import hoomd, hoomd.md as md
from hoomd import *
from hoomd import deprecated

context.initialize("");
system = deprecated.init.read_xml("1-rigid_with_R.xml");

system.particles[24].moment_inertia = [1, 1, 1]
system.particles[157].moment_inertia = [1, 1, 1]

num_particle = 2
par_pos =[]

for i in range(133*num_particle):
par_pos.append(system.particles[i+24].position)

par_type =[]
for i in range(133*num_particle):
par_type.append(system.particles[i+24].type)

rigid = hoomd.md.constrain.rigid();
for i in range(num_particle-1):
rigid.set_param('R',
types=par_type[1:133*(i+1)],
positions=par_pos[1:133*(i+1)])              
rigid.create_bodies()

#WCA
lj = hoomd.md.pair.lj(r_cut=2**(1.0/10), nlist=nl);
lj.pair_coeff.set('A', 'A', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'B', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'C', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'D', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('A', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('B', 'B', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'C', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'D', epsilon=0, sigma=0.75, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('B', 'R', epsilon=0, sigma=0.75, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('C', 'C', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('C', 'D', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('C', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('D', 'D', epsilon=1, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.pair_coeff.set('D', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);

lj.pair_coeff.set('R', 'R', epsilon=0, sigma=1, r_cut=2**(1.0/10), r_on=2.0);
lj.set_params(mode="xplor")  #the heart of wca ,make sure r_on>r_cut

harmonic=hoomd.md.bond.harmonic();
harmonic.bond_coeff.set('C-C',k=30,r0=1.0)
harmonic.bond_coeff.set('C-D',k=30,r0=1.0)
nl.reset_exclusions(exclusions = []);

rigid = hoomd.group.rigid_center()
nonrigid = hoomd.group.nonrigid()
all = hoomd.group.all()

hoomd.md.integrate.mode_standard(dt=0.01);
nvt = hoomd.md.integrate.nvt(group=nonrigid, tau=0.4, kT=0.5)
lg1 = hoomd.md.integrate.langevin(group=rigid, kT=0.5, seed=42)
lg1.set_gamma('A', gamma=0.5)
 lg1.set_gamma('B', gamma=0.5)
 lg1.set_gamma('R', gamma=0.5)


hoomd.analyze.log(filename="thermo.log", 
                  quantities=['potential_energy'],
                  period=100,
                  overwrite=True)
hoomd.dump.gsd("trajectory.gsd",
               period=100,
               group=all,
               overwrite=True)

hoomd.run(10000)

My initial configuration is obtained through “read_xml”,this xml file is shown in the "test_xml".
But the trajectory.gsd still very strange(see "test_gsd" or gif as below)test_gsd.gif
As you can see from the "test_xml",  the yellow particles  are located at the center of mass of the rigid sphere.
But in the "test_gsd",  HOOMD regards the yellow particles as the rigid_center,  but the  yellow particles  does not move with the rigid sphere as a whole.

Could you please help me with this issue? Thanks in advance.

Best,

Yulin Luo
test_gsd.gif
test_xml.png

Joshua Anderson

unread,
Aug 23, 2021, 4:19:05 PM8/23/21
to hoomd...@googlegroups.com
Yulin,

HOOMD-blue is performing the calculation you asked it to, as the constituent particles are moving with the center of mass particle. Perhaps you meant to translate the constituent particles so that they are centered on 0,0,0 in the local reference frame of the body given to set_param?
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

> But the trajectory.gsd still very strange(see "test_gsd" or gif as below)<test_gsd.gif>
> To view this discussion on the web visit https://groups.google.com/d/msgid/hoomd-users/0ae96d10-4e6b-469e-85c6-6df095339a32n%40googlegroups.com.
> <test_gsd.gif><test_gsd.gif><test_xml.png>

Reply all
Reply to author
Forward
0 new messages