hoomd 2.9 array outputting

Skip to first unread message

Luke Langford

unread,
Sep 24, 2021, 12:23:44 AM9/24/21
to hoomd...@googlegroups.com
Hi,

I am trying to output the per-particle virial of a simulation to a GSD file. As discussed in a post from another user I made sure to flag hoomd to calculate the net_virial so it actually calculates the virial per particle.

In the documentation for hoomd.dump.gsd and under "User-defined log quantities" it says to "Associate a name with a callable python object that returns a numpy array in log, and gsd will save the data you provide on every frame." 

I tried adding a name 'particles/forces' to log via hoomd.analyze.log and then defining 'particles/forces' through the register_callback method. I associated 'particles/forces' with a function that returns an array of the virial of each particle using system.particles[i].net_virial and iterating over all particles. However, on each step that the quantities should be outputted, I receive the warning  "*Warning*: analyze.log: Log callback particles/forces returned invalid value, logging 0.

If I instead associate these names with functions that return scalars or 1x1 numpy arrays via set_callback, this warning disappears. Looking at the source code, it appears that the output of the callable python object is being cast into a "scalar" and printing that warning message if it cannot be cast into a scalar. 

Is it possible to log arrays of per-particle data, as the documentation in hoomd.dump.gsd suggests? If so, how can I do it?

Much thanks,
Luke

Joshua Anderson

unread,
Sep 24, 2021, 5:41:53 AM9/24/21
to hoomd...@googlegroups.com
Luke,

In HOOMD v2, `analyze.log` is capable of logging scalar quantities only. You cannot use it to log an array.

As you already found in the documentation, use `dump.gsd` to log an array:

```
gsd_writer = hoomd.dump.gsd(...)
gsd_writer.log['particles/my_quantity'] = function_that_returns_an_array
```

To do this in HOOMD v3, see this tutorial: https://hoomd-blue.readthedocs.io/en/latest/tutorial/02-Logging/02-Saving-Array-Quantities.html
------
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/CAG3J0z%2BkjXB3tUN03YGEnW%3D5M9n9CZm5cnV%3DqUGWEVBDv4P-0w%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages