Setting bonds between particles using python

481 views
Skip to first unread message

Yan

unread,
Feb 11, 2011, 9:08:10 AM2/11/11
to hoomd-users
Hi,

I'm (very) new to HOOMD, and just trying out some simple simulations,
so apologies if I've misunderstood anything here. I'm trying to do a
few basic tests without reading in xml files, and I can't work out how
to specify bonds between particles once the particles have been
created with system=init.create_empty(...).

For example, when I look at system.particles[0], I can only see the
following variables: tag, position, image, velocity, acceleration,
charge, mass, diameter, type, typeid. To bond this particle to (say)
particle [1], do I simply have to place them closely enough together?
Or is there some magic incantation I have to use?

I can't find a reference to this anywhere in the docs, so once I get
it working, maybe I could submit the file as an example script? In
case anyone's interested, I'm trying to simulate simple formation of a
(very) crude lipid bilayer in 2D.

Cheers

Yan

Carolyn Phillips

unread,
Feb 11, 2011, 9:12:57 AM2/11/11
to hoomd...@googlegroups.com
There's no magic!

See

For an example of creating a system with bonds that doesn't use an init file.

-Carolyn

--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To post to this group, send email to hoomd...@googlegroups.com.
To unsubscribe from this group, send email to hoomd-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hoomd-users?hl=en.




Joshua A. Anderson

unread,
Feb 11, 2011, 9:28:38 AM2/11/11
to hoomd...@googlegroups.com
You aren't missing anything. The particle data access methods from within python are only half complete, so there is currently no officially supported way to create bonds dynamically within a script from an init.create_empty. Carolyn's link to the polymer generator will work if the random generator can be convinced to do what you want (it is very flexible).

Adding a way to create and change bonds within python is one of the last things on the TODO list for the soon to be released 0.9.2. No promises on when I'll get to working on it though. It actually requires some subtle changes throughout the data structures, as I need to provide some way for you to name your bond types.

Your best option right now is to not use init.create_empty and instead write a python script that outputs an XML file and then use init.read_xml.

unofficially, the following lines of code might work you but they might not, I offer no guarantee (i.e., I haven't tested them). They may also fail to work with the next version of hoomd. Plus, I don't even have a clue what the bond type gets named if you do this - it could end up being uninitialized memory.

init.create_empty(N=whatever, box=(x,y,z), n_bond_types=1)
globals.system_definition.getBondData().addBond(hoomd.Bond(0, i, j))
# should add a bond between particles i and j
--------
Joshua A. Anderson, Ph.D.
Chemical Engineering Department, University of Michigan

Yan

unread,
Feb 11, 2011, 12:41:05 PM2/11/11
to hoomd-users
Thanks both. I want to have a mix of simple polymers and individual
particles, but after Carolyn's comment, I guess I could just use
init.create_random_polymers() with one "polymer" consisting of a
single particle. I'll try that.

Cheers,

Yan

Yan

unread,
Feb 11, 2011, 1:04:57 PM2/11/11
to hoomd-users
Ah - just tried this, and I get

***Error! Polymer specification missing bond

It might seem silly, but I wonder if it would be possible to allow
"polymers" of 1 particle in the create_random_polymers() code?

Regardless, for my purposes, it might be just as easy to create an xml
file, as I can't see any way to force create_random_polymers() to
place the polymers on a 2D plane, other than manually zeroing the z
dimension afterwards, which leads to lots of overlapping particles.

Yan

unread,
Feb 12, 2011, 7:16:35 AM2/12/11
to hoomd-users
On Feb 11, 6:04 pm, Yan <y...@pixie.org.uk> wrote:
> Ah - just tried this, and I get
>
> ***Error! Polymer specification missing bond

Apologies - my fault. I needed to specify bond="linear" (or whatever),
even for polymers of a single particle. This now works fine.

Carolyn Phillips

unread,
Feb 12, 2011, 8:33:25 AM2/12/11
to hoomd...@googlegroups.com
Glad you figured it out!

Reply all
Reply to author
Forward
0 new messages