-
Notifications
You must be signed in to change notification settings - Fork 34
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
Color the 3D structure by a property #303
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b711fc9
Color the 3D structure by a property.
MaximeScope de7e659
Fixed issues reported by Luthaf in last commit.
MaximeScope 0591d4d
Fixed the "wrong coloring".
MaximeScope 50e9142
Prettier code.
MaximeScope 73aa244
Added an example of color-coding of the atoms
ceriottm 096cdb1
Fixed bugs / suggestions from @Luthaf
MaximeScope 389e6ac
Merge branch '3dPropColor' of github.com:MaximeScope/chemiscope into …
MaximeScope 3c152f7
Cleanup _colorFunction
Luthaf 56c0d68
Create a single _colorValues function that computes the color values
Luthaf b0df74c
Cleanup _propertiesForStructure
Luthaf 512111b
Rename color.mode to color.transform
Luthaf 63c7e7e
Rename palettes
Luthaf cd08a85
Merge branch 'master' into 3dPropColor
Luthaf f5ae63b
Better commenting of the example
ceriottm fd005a7
Do not put data in ase.Atoms to immediately remove it
Luthaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
""" | ||
Atom property coloring in chemiscope | ||
==================================== | ||
|
||
This example demonstrates how to color atoms based on scalar | ||
properties. | ||
|
||
Note that the same parameters can be used with `chemiscope.show` | ||
to visualize an interactive widget in a Jupyter notebook. | ||
""" | ||
|
||
import ase.io | ||
import chemiscope | ||
import numpy as np | ||
|
||
# loads a dataset of structures | ||
frames = ase.io.read("data/alpha-mu.xyz", ":") | ||
|
||
# converts the arrays from the format they are stored in to an array | ||
# format that can be processed by the ASE utilities | ||
for a in frames: | ||
a.arrays["polarizability"] = np.array( | ||
[ | ||
(axx + ayy + azz) / 3 | ||
for (axx, ayy, azz) in zip( | ||
a.arrays["axx"], a.arrays["ayy"], a.arrays["azz"] | ||
) | ||
] | ||
) | ||
|
||
# one possible measure of anisotropy... | ||
a.arrays["alpha_eigenvalues"] = np.array( | ||
[ | ||
np.linalg.eigvalsh([[axx, axy, axz], [axy, ayy, ayz], [axz, ayz, azz]]) | ||
for (axx, ayy, azz, axy, axz, ayz) in zip( | ||
a.arrays["axx"], | ||
a.arrays["ayy"], | ||
a.arrays["azz"], | ||
a.arrays["axy"], | ||
a.arrays["axz"], | ||
a.arrays["ayz"], | ||
) | ||
] | ||
) | ||
|
||
a.arrays["anisotropy"] = ( | ||
a.arrays["alpha_eigenvalues"][:, 2] - a.arrays["alpha_eigenvalues"][:, 0] | ||
) | ||
|
||
chemiscope.write_input( | ||
"colors-example.json.gz", | ||
frames=frames, | ||
properties=chemiscope.extract_properties( | ||
frames, only=["polarizability", "anisotropy", "alpha_eigenvalues"] | ||
), | ||
settings={ # the write_input function also allows defining the default visualization settings | ||
"map": { | ||
"x": {"property": "alpha_eigenvalues[1]"}, | ||
"y": {"property": "alpha_eigenvalues[2]"}, | ||
"z": {"property": "alpha_eigenvalues[3]"}, | ||
"palette": "seismic", | ||
"color": {"property": "anisotropy"}, | ||
}, | ||
"structure": [ | ||
{ | ||
"spaceFilling": False, | ||
"atomLabels": False, | ||
"atoms": True, | ||
"axes": "off", | ||
"keepOrientation": False, | ||
"playbackDelay": 700, | ||
"environments": { | ||
"activated": True, | ||
"bgColor": "CPK", | ||
"bgStyle": "licorice", | ||
"center": False, | ||
"cutoff": 4, | ||
}, | ||
"color": {"property": "anisotropy", "min": 1, "max": 15}, | ||
} | ||
], | ||
}, | ||
environments=chemiscope.all_atomic_environments(frames), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this in the "atomic coloring" example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what you mean by that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, I thought it was better to avoid adding new data files, but we need scalar properties to display.
I'll add a comment so it's clear it's not like one needs to do this in order to use the coloring.