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

Allow manual coloring of atoms #250

Merged
merged 5 commits into from
Nov 9, 2023
Merged

Allow manual coloring of atoms #250

merged 5 commits into from
Nov 9, 2023

Conversation

phohenberger
Copy link
Collaborator

Allows sending a manual coloring of atoms with the atoms.colors attribute

Allows sending a manual coloring of atoms with the atoms.colors attribute
@PythonFZ
Copy link
Member

I like the feature and it works nicely. But I'd suggest some changes:

I'd like to be able to access the colors when retrieving the atoms like:

from zndraw import ZnDraw
vis = ZnDraw(url="http://127.0.0.1:1234/")

print(vis[0].colors) # list

I think this also has to be a potential to be expanded by some general information.
Currently, we are limited to particles from the periodic system, but once e.g. coarse grained simulations are of interested, we might want to be able to parse additional informations (probably through atoms.info).

My suggestion would be to expand this to generally work with atoms.info and use atoms.info["colors"]: list instead of atoms.color.

from zndraw import ZnDraw
vis = ZnDraw(url="http://127.0.0.1:1234/")

atoms = ase.build.molecule("H2O")
atoms.info["colors"] = [None, "#FF3333", None] # None = fill color automatically
vis[0] = atoms

print(atoms.info["colors"]) # ["#FFFFFF", "#FF3333", "#FFFFFF"] # automatic color for hydrogens is  white.

Copy link
Member

@PythonFZ PythonFZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good, please consider my comment above.

@phohenberger
Copy link
Collaborator Author

This would definitely be a good addition. The info tag could also be used as a means to save information about future features such as vector-fields and obstacles. I will look into it.

@PythonFZ
Copy link
Member

PythonFZ commented Nov 2, 2023

or better use atoms.arrays["colors"]

@phohenberger
Copy link
Collaborator Author

Should work as intended now. Individual atoms can be manually colored before handing them to ZnDraw using
atoms.arrays["colors"] = ["#ffffff", "#000000", etc]

Copy link
Member

@PythonFZ PythonFZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2023

Codecov Report

Merging #250 (4449b41) into main (0d42690) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #250      +/-   ##
==========================================
+ Coverage   39.78%   39.89%   +0.10%     
==========================================
  Files          13       13              
  Lines        1106     1108       +2     
==========================================
+ Hits          440      442       +2     
  Misses        666      666              
Files Coverage Δ
zndraw/data.py 78.43% <100.00%> (+0.88%) ⬆️

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@PythonFZ PythonFZ merged commit a53affd into zincware:main Nov 9, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants