Add widget for generic ACF#37
Conversation
- Add a new `SlidingWindowVACF` class that is O(n) for each window - Support to compute and display particle VACFs - Support for displaying running integral of VACF - Support for configuring selection, dimension type and normalization - Add new test trajectory data file that supports velocities
Documentation build overview
12 files changed ·
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
🚀 New features to boost your workflow:
|
- Add correct title, labels and units for both MSD and VACF
|
This looks great, @PardhavMaradani. If it is not too much, I would suggest you add some of the following features, if feasible:
Here, ii. Normalization usually involves normalizing the ACF by its variance or its value at
Finally, a related suggestion is to have an ACF function that takes in two selections and computes cross-correlations between them. I know this might involve a lot of code additions, so take your time and let me know if you have any questions/need any help with these code implementations. I would also be glad to contribute to some of these if you need any help! |
|
Hi @amruthesht, thanks for reviewing the changes.
Yes, this is feasible. I quickly tried this out, please see next section for some results...
I tried with this option by doing something like this: ...
current = getattr(self.ag, self.physical_property)[:, self._dim]
self.running_sum += current
self.running_count += 1
mu = self.running_sum / self.running_count
for i in range(n):
lag = n - 1 - i
_ = self.u.trajectory[i] # set trajectory to past frame
previous = getattr(self.ag, self.physical_property)
if self.centered:
corr = (current - mu) * (previous[:, self._dim] - mu)
else:
corr = current * previous[:, self._dim]
sum_corr = np.sum(corr, axis=-1)
self.acf_sums[lag] += np.mean(sum_corr)
self.acf_counts[lag] += 1
...I got plots that looked like this:
The plots labelled 'Centered' are the ones with the mean subtracted and the 'Normalized' ones are the normalized ACFs. All of them run through the same code pasted above. The VACF looks the same as before. But the ones for positions and forces don't seem right, but I don't know much and don't know if they are expected / correct. Could you please check and let me know.
Yes, this is already available for customization from the UI. Any attribute that shows up in the Here is an example (includes some of the changes suggested here):
We are currently dividing by the value at 0 as follows: ...
if normalized:
avg_acfs = avg_acfs / avg_acfs[0]
...
Could we add cross-correlations as a separate widget? The current one (if we rename as ACF instead of VACF) takes a single selection phrase. Adding another selection here might make it a bit confusing / complex code wise. A separate widget could make this a clean separation both in terms of what to expect and how we structure it? Could you please let me know if I should go ahead with the generic ACF (for velocities, positions, forces) and mean subtracted (centred) option based on your review of the plots above? (I didn't commit the changes because I wasn't sure if the plots are correct / expected) |
|
@PardhavMaradani - thanks for making the requested changes. The plots look pretty good and reasonable. But there are some issues that might need a little attention to detail. As for the current ACF implementation with centering, there might be an issue with how it's implemented. It looks good to subtract the mean in place, but since these are running updating means, doing so will bake the current value into the product and thus the overall ACF average. It would be more accurate thus to add the mean contribution separately as suggested here,-Here%2C). Now, as for the plots, could you share the input scripts of your test system so I can double-check the results—
I would leave that up to you.
Here, however, the convergence of both will slightly depend on how well the system is equilibrated, so maybe you can have it as an option as to how the user wants MSDs calculated (using correlation or explicit positional subtraction). Apologies for making this progressively more complex and suggesting different implementation approaches. I would leave the final decision to you on how you implement this overall. Whether as separate widgets/functions or otherwise. But great implementation and progress so far on all the correlation and lag-time-based analyses! Everything looks robust and well implemented to me, and I'm sure it will be super useful for real-world analysis use cases! |
|
just in case, I performed a reference calculation with a stored trajectory for the position, velocity and force ACF (without subtraction of the mean): The simulated system should be the same as in your tests: lysozyme with 1960 atoms in water + 150mM salt (all files in MD sub-directory). I stored coordinates, velocities and forces every 0.01 ps and the average atomic correlation functions for coordinates, velocities and forces (computed with 200 correlation steps, max correlation time = 1.99 ps) are in the files "acf_results.dat". I cross-checked the python code in acf.ipynb against a C-code that I wrote a while ago. The results looks pretty much like yours, which is great! Only the coordinate correlation functions look different, because I remove jumps across periodic boundary conditions. |
- supported physical properties: position, velocity, force - Add an option to center (mean subtracted) the ACF data
|
Hi @amruthesht, @HeydenLabASU, thank you both for additional details. They are very helpful. The artifact in the Postion ASF in my previous comment at the very beginning was because the running count was initialized to 1 (a carry over from the MSD code). I now fixed this and this looks much better. I am now using the system provided by MH in the comment above. I made minor modifications to stream that simulation to test with our dashboard. (Just for reference, I was so far using the sample gromacs sim from imd workshop 2025) In the dashboard, I changed the total steps to 10000 and the buffer size to 200 to get the 2ps lag. I got an exact match to the plots that MH had in
ACF's from
However, I got the above match only after removing the Update: After trying this out a bit more, I can confirm that the code in this PR is equivalent to MH's reference. The code in Here is the screenshot with all the three physical properties, with centering and normalization:
I didn't change the way centering was implemented from the previous comment. Based on the plots above, should I retain this as is or change? (The plots looked fairly consistent all through this shorter sim - after the window filled up)
I will use MH's sim going forward as it is something I can run till the end and also check with the trajectory file if needed for any future cases.
I am assuming this is no longer needed. If needed, please let me know and I can run this.
Please see above about what I ran into with 'no-jump' added/removed. Please let me know if there is anything you'd want me to check here.
I've for now updated the PR with the generic ACF changes (with centering support, etc). I will try out how best to add cross-correlations and see how it goes - I think I understood what is required. The changes to MSD to add an additional option on how it is calculated is something I can explore after that. Hope that is ok. Please let me know if there is anything else you want me to check. Thanks |
|
@PardhavMaradani, thank you for the new changes. They look great and are in the right direction in making the analysis more generic and robust! As for the nuances,
You should still change the centering to the modified mean subtraction, (with a note that the running-updated mean based on all data processed so far is used; and a small warning message on stats),-Here%2C) I suggested earlier. Here, the difference is not pronounced as the means are negligible in the simulation. However, in cases where it does matter, the difference might be more pronounced.
Let me get back to you on this. In my opinion, there might be something weird happening with the transformation.
This is completely alright! Great work again in making the changes—this looks in good shape and should be ready once the finer details are done! |
- Fix frame_dt computation from previous commit
I changed the centering to the modified mean subtraction as suggested and also added the note to the description of this input so that it shows up in the UI. Thanks |






Changes made in this Pull Request:
SlidingWindowVACFclass that is O(n) for each windowPR Checklist
Hi @orbeckst, @jeremyleung521, @amruthesht, @HeydenLabASU,
This PR adds a new 'VACF' widget as part of issue #34.
The code for
VACFfollows exactly the same lines as that ofMSDsupport added in PR #35. I used this reference from MDAnalysis/transport-analysis for the VACF computations.Here is an example showing VACF for 'all' and 'protein'. There is support to show normalized values and also particle VACFs if required as shown below:
Based on the reference, I also added an option to show the running integral if configured as shown below:
With PR #35 and this, we will have support for both the lag-time based computations mentioned in issue #34 .
Thanks