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

Added Jmol colors as defaults for atoms. #682

Merged
merged 1 commit into from
Feb 14, 2024
Merged

Conversation

pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Feb 14, 2024

I also ran black and modified some unrelated files 😅

src/sisl/nodes/tests/test_context.py Fixed Show fixed Hide fixed
src/sisl/geom/_composite.py Fixed Show fixed Hide fixed
src/sisl/nodes/syntax_nodes.py Fixed Show fixed Hide fixed
src/sisl/viz/types.py Fixed Show fixed Hide fixed
src/sisl/viz/processors/wavefunction.py Fixed Show fixed Hide fixed
src/sisl/geom/_composite.py Fixed Show fixed Hide fixed
@zerothi
Copy link
Owner

zerothi commented Feb 14, 2024

Could you update your black version, and run it with the newest one, as you can see the lint action fails, I noticed in ab45ef4 that black changed substantial things.

Copy link
Owner

@zerothi zerothi left a comment

Choose a reason for hiding this comment

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

Just a small question, I haven't looked at how you are using it, but perhaps a defaultdict would make this simpler?

@@ -66,15 +66,117 @@ def AtomNOrbitals(geometry, atoms=None):


class AtomDefaultColors(AtomData):
# Taken from Jmol (https://jmol.sourceforge.net/jscolors/)
_atoms_colors = {
Copy link
Owner

Choose a reason for hiding this comment

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

would it make sense to make this a defaultdict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used like this, right below the dictionary:

def function(self, geometry, atoms=None):
        return np.array(
            [
                self._atoms_colors.get(atom.symbol, self._atoms_colors["else"])
                for atom in geometry.sub(atoms).atoms
            ]
        )

Copy link
Owner

Choose a reason for hiding this comment

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

Ok, then it would just be:

self._atoms_colors[atom.symbol] ...

and on .get it will always be present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm but a defaultdict is meant to initialize objects when the key is not there. Isn't it a bit overkill for this?

Copy link
Owner

Choose a reason for hiding this comment

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

Not a problem then, it would make its use simpler since one shouldn't care if the key is there or not. I'll merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can convert it to something like self._atoms_colors.get( atom.symbol, self._fallback_color) if it looks better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a problem then, it would make its use simpler since one shouldn't care if the key is there or not. I'll merge.

Ok, anyway this can be modified whenever we want :)

@pfebrer
Copy link
Contributor Author

pfebrer commented Feb 14, 2024

Ok, done. Again, pre-commit would be a good idea because it specifies the version :)

@zerothi
Copy link
Owner

zerothi commented Feb 14, 2024

Ok, done. Again, pre-commit would be a good idea because it specifies the version :)

Yes, lets do this. :)

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 102 lines in your changes are missing coverage. Please review.

Comparison is base (4f73db8) 87.62% compared to head (09d1388) 86.14%.
Report is 22 commits behind head on main.

Files Patch % Lines
src/sisl/_core/_ufuncs_geometry.py 92.60% 33 Missing ⚠️
src/sisl/_core/_ufuncs_lattice.py 88.88% 16 Missing ⚠️
src/sisl/physics/_ufuncs_brillouinzone.py 70.58% 10 Missing ⚠️
src/sisl/physics/state.py 59.09% 9 Missing ⚠️
src/sisl/_core/_ufuncs_sparse_geometry.py 96.51% 7 Missing ⚠️
src/sisl/physics/_ufuncs_state.py 92.70% 7 Missing ⚠️
src/sisl/typing/_common.py 85.18% 4 Missing ⚠️
src/sisl/_core/_ufuncs_atom.py 98.31% 2 Missing ⚠️
src/sisl/_core/_ufuncs_grid.py 97.75% 2 Missing ⚠️
src/sisl/_ufuncs.py 96.61% 2 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #682      +/-   ##
==========================================
- Coverage   87.62%   86.14%   -1.48%     
==========================================
  Files         363      364       +1     
  Lines       48870    43511    -5359     
==========================================
- Hits        42820    37483    -5337     
+ Misses       6050     6028      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerothi zerothi merged commit fdf1fa4 into zerothi:main Feb 14, 2024
7 of 8 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.

2 participants