cmelab / grits

A toolkit for working with coarse-grain systems
https://grits.readthedocs.io
GNU General Public License v3.0
5 stars 9 forks source link

Populate `snapshot.bonds.types` and `snapshot.bonds.typeid` #46

Closed chrisjonesBSU closed 2 years ago

chrisjonesBSU commented 2 years ago

This PR ensures that both snapshot.bonds.types and snapshot.bonds.typeid are populated. All of the work to identify bonds is pretty much done, this just iterates through the existing information to populate these fields of the snapshot.

So far it seems to work on a simple system (PEKK) where there are 2 kinds of beads. I sitll need to add unit tests and try it out a system that has some kind of branching (p3ht)

codecov[bot] commented 2 years ago

Codecov Report

Merging #46 (8e26bed) into main (f4c844b) will increase coverage by 0.11%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #46      +/-   ##
==========================================
+ Coverage   96.50%   96.62%   +0.11%     
==========================================
  Files           4        4              
  Lines         372      385      +13     
==========================================
+ Hits          359      372      +13     
  Misses         13       13              
Impacted Files Coverage Δ
grits/coarsegrain.py 98.19% <100.00%> (+0.11%) :arrow_up:
chrisjonesBSU commented 2 years ago

Now that I'm thinking about this some more, if the bonds aren't changing throughout the trajectory (which is probably safe to assume), we only have to create the bond.groups, bond.types and bond.typeid arrays once, then apply it to each snapshot after. This would be applicable to things like snap.particles.types and snap.particles.typeid and snap.particles.mass if the numbers and types of particles isn't changing either.

It seems pretty fast now, so I'm not sure if it's better to be safe (don't assume bonds and particles are constant) rather than try to improve performance.

chrisjonesBSU commented 2 years ago

Now that I'm thinking about this some more, if the bonds aren't changing throughout the trajectory (which is probably safe to assume), we only have to create the bond.groups, bond.types and bond.typeid arrays once, then apply it to each snapshot after. This would be applicable to things like snap.particles.types and snap.particles.typeid and snap.particles.mass if the numbers and types of particles isn't changing either.

It seems pretty fast now, so I'm not sure if it's better to be safe (don't assume bonds and particles are constant) rather than try to improve performance.

Actually, I don't think GRiTS would really work as is if the bonds and particle types were changing. These attributes are set based on the first frame only and used over again when coarse-graining the trajectory.