Issue with quaternion and updating particle orientation

48 views
Skip to first unread message

Benjamin Sykes

unread,
Mar 31, 2023, 2:41:04 PM3/31/23
to hoomd-users
Hi,
I am attempting to change the particle orientation so that they face the point (0,0) in the center of my 2d box, but I am running into issues when y< 0. When y is less than 0, the particles orient toward the left side of the box rather than the center. It works correctly if y>0 which seems even stranger to me. I have attached the custom action I am using to accomplish this.
rereorient(2).py

Joshua Anderson

unread,
Apr 3, 2023, 9:27:14 AM4/3/23
to hoomd...@googlegroups.com
Benjamin,

The range of the arctangent is [-pi/2, pi/2]. Use arctan2: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html#numpy.arctan2
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan

On Mar 31, 2023, at 2:41 PM, Benjamin Sykes <bb...@email.unc.edu> wrote:

Hi,
I am attempting to change the particle orientation so that they face the point (0,0) in the center of my 2d box, but I am running into issues when y< 0. When y is less than 0, the particles orient toward the left side of the box rather than the center. It works correctly if y>0 which seems even stranger to me. I have attached the custom action I am using to accomplish this.

--
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/649a19af-8dfe-45ce-9bdf-74e0ca831d29n%40googlegroups.com.
<rereorient(2).py>

Message has been deleted
Message has been deleted

Joshua Anderson

unread,
Apr 12, 2023, 3:41:30 PM4/12/23
to hoomd...@googlegroups.com
Benjamin,

I don't know who told you to "point in the direction of the particle's orientation in a 2d sim". You should choose a natural direction for the force in the local reference frame (e.g. +x or +y) unless you have an anisotropic particle with a particular feature in in that direction (e.g. the vertex of a square).


Active computes an active force and torque on all particles selected by the filter:

\begin{split}\vec{F}_i = \mathbf{q}_i \vec{f}_i \mathbf{q}_i^* \\
\vec{\tau}_i = \mathbf{q}_i \vec{u}_i \mathbf{q}_i^*,\end{split}

where \vec{f}_i is the active force in the local particle coordinate system (set by `active_force`) and \vec{u}_i is the active torque in the local particle coordinate system (set by `active_torque`.

Given your numbers, the vector f (in the particle reference frame) is pointing up and to the right and you are rotating counterclockwise by ~90 degrees to get a force pointing up and to the left (in the system reference frame). This is the expected behavior given your input.

>>> import rowan
>>> import numpy
>>> v = [1/numpy.sqrt(3), 1/numpy.sqrt(3),0]
>>> q = [0.708042353482036, 0, 0, 0.7061699693952015]
>>> rowan.rotate(q,v)
array([-0.57581945,  0.57887704,  0.        ])
>>> rowan.to_axis_angle(q)
(array([[0., 0., 1.]]), array([1.56814838]))
------
Joshua A. Anderson, Ph.D.
Research Area Specialist, Chemical Engineering, University of Michigan
On Apr 11, 2023, at 11:53 AM, Benjamin Sykes <bb...@email.unc.edu> wrote:

Hi,
I've attached the main code I am using. I am getting the correct angle as far as I can tell but have issues with either the forces or the quaternion part of my code. I ran the sim with a single particle in the lower left and made the reorientation updater print out the [cos(theta),0,0, sin(theta)] part, and I was getting the quaternion 0.708042353482036 + 0i+ 0j+ 0.7061699693952015k which is pointing in the correct direction. My current active force is added as active.active_force['A'] = (mag/np.sqrt(3), mag/np.sqrt(3),0) as I was told that should point in the direction of the particle's orientation in a 2d sim. Could that be where my problem lies? Thanks for any help you can provide
Reply all
Reply to author
Forward
0 new messages