Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: trajectory add/get_particle_info() not compatible with strings #46

Open
3 tasks
kay-ro opened this issue Jul 10, 2024 · 4 comments
Open
3 tasks

BUG: trajectory add/get_particle_info() not compatible with strings #46

kay-ro opened this issue Jul 10, 2024 · 4 comments
Assignees
Labels
bug Something isn't working module: trajectory release: patch Issues that need to be addressed in a patch release status: to do Issues that someone needs to work on

Comments

@kay-ro
Copy link

kay-ro commented Jul 10, 2024

Description:

When saving particle type info in the trajectory file, a string can be used as ptype. But when trying to get the info, an error occurs due to the reader expecting an int instead of a string.

Code for reproduction:

import amep
traj_particles=amep.load.traj(path_particles, reload=True)
traj_particles.add_particle_info(1, "key", "value")
traj_particles.add_particle_info("asdf", "key2", "value2")
traj_particles.get_particle_info()

Error message:


ValueError Traceback (most recent call last)
Cell In[27], line 1
----> 1 traj_particles.get_particle_info()

File ~/Documents/git_amep/amep/trajectory.py:233, in ParticleTrajectory.get_particle_info(self, ptype)
231 p = {}
232 for t in list(root['particles'].keys()):
--> 233 p[int(t)] = dict(a for a in root['particles'][t].attrs.items())
234 elif str(ptype) in list(root['particles'].keys()):
235 p = dict(a for a in root['particles'][str(ptype)].attrs.items())

ValueError: invalid literal for int() with base 10: 'asdf'

Python and AMEP versions:

1.0.2_dev (github version 10.7.2024), python 3.10

Additional information:

traj_particles.add_particle_info(ptype, key, value)
  • Allow only int-ptype.
  • Fix amep.trajectory.ParticleTrajectory
  • traj_particles.get_particle_info(ptype) should only return info for ptype=int.

How did you install AMEP?

None

@kay-ro kay-ro added bug Something isn't working release: patch Issues that need to be addressed in a patch release status: to do Issues that someone needs to work on module: trajectory labels Jul 10, 2024
@kay-ro kay-ro added this to the release v1.0.3 milestone Jul 10, 2024
@kay-ro
Copy link
Author

kay-ro commented Jul 10, 2024

Feature request: allow iterable of ptypes.

@kay-ro
Copy link
Author

kay-ro commented Jul 11, 2024

ptype might be a string ("CH2" for unified-atom models in MD simulations for example).

@kai-luca
Copy link
Contributor

It is not quite straight forward to make the readers work with strings as particletypes. Since strings are variable length we would need to allocate space that might or might not get used. We gonna have to talk this through again.

@kay-ro
Copy link
Author

kay-ro commented Jul 30, 2024

The GSD format stores the atom types as null terminated strings: https://gsd.readthedocs.io/en/stable/schema-hoomd.html#chunk-particles-types
GROMACS has different labels such as atom type, residue name, ... and allows the atom type to be a string as well https://manual.gromacs.org/current/reference-manual/topologies/particle-type.html But this is only stored in the topology (or .tpr/topology files), not the trajectory files.

Discussion points:

  • A solution for the h5amep file format might be to import all atom types and allocate the space according to the larges string.
  • One further issue is that the ptype functionality should still work with numbers and not just strings. If the atom type is 1, then the user should be able to access it as the integer 1 and not (just?) the string "1".
  • Question: should the user be able to access the ptype information in such a case as integer as well as string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module: trajectory release: patch Issues that need to be addressed in a patch release status: to do Issues that someone needs to work on
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants