-
Notifications
You must be signed in to change notification settings - Fork 25
Add plot_structure_2d()
in new module ml_matrics/struct_vis.py
#20
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
Conversation
Great! Will give it a try |
35fb591
to
a05f7a8
Compare
a05f7a8
to
f30e914
Compare
Output seems suboptimal but maybe good enough for now across most of 20 random structures. I think the code can still be simplified quite a bit though so leaving WIP status. structs = [
(fname, Structure.from_file(fname))
for fname in glob(f"{ROOT}/data/structures/*.yml")
]
fig, axs = plt.subplots(4, 5, figsize=(20, 20))
for (fname, struct), ax in zip(structs, axs.flat):
ax = plot_structure_2d(struct, ax=ax)
mp_id = os.path.basename(fname).split(".")[0]
ax.set_title(f"{struct.formula}\n{mp_id}", fontsize=14)
fig.savefig(f"{ROOT}/assets/mp-structures-2d.svg", bbox_inches="tight") |
Maybe a key off to the side? So then it doesn't overlayer the labels? Does it give different colours to charge assigned elements? |
Could you be more specific?
It doesn't. Do you think that's an important feature? I feel like there already aren't enough colors to differentiate elements clearly. Maybe better to include oxidation state in site labels? |
@janosh if you decide to include it, I think as a site label might work. As a legend (e.g. blue: Ni, red: O) incorporating charge states is tough because of the color issue. |
b529f68
to
d0f2dca
Compare
ed7eeae
to
c9c2935
Compare
3150505
to
f82d02c
Compare
ml_matrics/struct_vis.py
with plot_structure_2d()
for 2d structure visualization
ml_matrics/struct_vis.py
with plot_structure_2d()
for 2d structure visualizationplot_structure_2d()
in new module ml_matrics/struct_vis.py
* add ml_matrics/struct_vis.py with ase-inspired plot_structure_2d() * fix test_get_crystal_sys_invalid() * plot_structure_2d() add annotate_sites: bool = True * add example structure plots to readme * fix GH workflow svgo compression * rename annotate_sites kwarg to site_labels, can be dict or list for custom labels * fix test_plot_structure_2d() * add plot_structure_2d() example with 20 random MP structures * plot_structure_2d() drop kwargs offset, bbox, maxwidth, simplifies function, add label_kwargs * assert matplotlib compare_images() passes in test_plot_structure_2d() * try fix compare_images() by setting explicit plt figsize * move save_fixture() to new tests/_helpers.py along with stuff in tests/__init__.py * add convenience root import for plot_structure_2d() + comment crediting ASE * readme display ![mp-structures-2d] full-width
Adds
ml_matrics/struct_vis.py
withase
-inspiredplot_structure_2d()
but works natively withpymatgen
Structure
s,matplotlib
being the only other dependency.Example
Aims to resemble output of
ase.visualize.plot.plot_atoms
with minor improvements, less conversion hassle and handling of disordered structures.pymatgen
is unable to convert disordered structures viaAseAtomsAdaptor().get_atoms(struct)
:which appears to be untrue. ASE does allow for disorder.
ASE Example
Disordered Example