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

Pretty clusters #181

Merged
merged 18 commits into from
Apr 8, 2022
Merged

Pretty clusters #181

merged 18 commits into from
Apr 8, 2022

Conversation

lbluque
Copy link
Collaborator

@lbluque lbluque commented Apr 5, 2022

Summary

Improvements for printing and visualizing smol objects

  • ClusterSubspace, ClusterExpansion, Orbit, Cluster have much nicer repr and str methods.
  • Cluster as a subclass of pymatgen SiteCollection
  • Allow cluster visualization using crystaltoolkit and includes an example notebook. (this required a little bit of refactoring, but should not really affect users)

TODO (if any)

  • Implement str and repr for missing classes
    • StructureWrangler
    • Processors
    • Ensembles
    • Kernel
    • Sampler and SampleContainer

Checklist

@lbluque lbluque marked this pull request as draft April 5, 2022 00:25
@lbluque lbluque changed the title [WIP] Pretty clusters Pretty clusters Apr 7, 2022
@lbluque lbluque marked this pull request as ready for review April 7, 2022 04:13
@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

This addresses #93 by leveraging crystal-toolkit for jupyter notebooks.

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

A ClusterExpansion instance is printed as:

Basis/Orthogonal/Orthonormal : indicator/False/{self.basis_orthonormal}
       Unit Cell Composition : Mo5+0.33333333 Co2+0.33333333 Li+0.33333333 O2-0.5 F-0.5
            Number of Orbits : 34
No. of Correlation Functions : 82
             Cluster Cutoffs : 2: 6.96, 3: 3.64, 4: 3.64
              External Terms : [EwaldTerm(total)]
ECI-based Property : mean=-5.5733  std=4.9130
Fit Summary
EwaldTerm(total)=0.050
 ---------------------------------------------------------
 |  ID    Orbit ID    Degree    Cluster Diameter    ECI  |
 |   0       0          0              NA        -5.573  |
 |  1        1          1            0.0000       -0.593 |
 |  2        1          1            0.0000       -2.666 |
 |  3        2          1            0.0000       -3.241 |
 |  4        3          2            2.1000        0.002 |
 |  5        3          2            2.1000        0.222 |
 |  6        4          2            2.9698       -0.361 |
 |  7        4          2            2.9698       -0.138 |
 |  8        4          2            2.9698        0.046 |
 |  9        5          2            2.9698        0.094 |
....

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

A ClusterSubspace:

Basis/Orthogonal/Orthonormal : indicator/False/{self.basis_orthonormal}
       Unit Cell Composition : Mo5+0.33333333 Co2+0.33333333 Li+0.33333333 O2-0.5 F-0.5
            Number of Orbits : 34
No. of Correlation Functions : 82
             Cluster Cutoffs : 2: 6.96, 3: 3.64, 4: 3.64
              External Terms : [EwaldTerm(total)]
Orbit Summary
 ------------------------------------------------------------------------
 |  ID     Degree    Cluster Diameter    Multiplicity    No. Functions  |
 |   0       0             NA                 0                1        |
 |   1       1            0.0000              1                2        |
 |   2       1            0.0000              1                1        |
 |   3       2            2.1000              6                2        |
 |   4       2            2.9698              6                3        |
 |   5       2            2.9698              6                1        |
 |   6       2            3.6373              8                2        |
 |   7       2            4.2000              3                3        |
 |   8       2            4.2000              3                1        |
 |   9       2            4.6957              24               2        |
 |  10       2            5.1439              12               3        |
 |  11       2            5.1439              12               1        |

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

An Orbit:

Orbit  33
    Multiplicity : 12  
   No. functions : 3   
No. symmetry ops : 4   
Function ids : [79, 80, 81]
Base Cluster : 
  | Diameter : 3.6373
  |   Charge : 2.333333333333333
  | Centroid :    -1.714643     0.606218    -0.000000  ->     0.250000     0.250000     0.250000
  | Sites (4)
  | ----------------------------------------------------------------------------------------------------------------------
  | 0 Li+:0.333, Co2+:0.333, Mo5+:0.333    -1.714643     2.424871     0.000000   ->     0.000000    -0.000000     1.000000
  | 1 O2-:0.500, F-:0.500    -3.429286     1.212436    -0.000000   ->     0.500000     0.500000     0.500000
  | 2 Li+:0.333, Co2+:0.333, Mo5+:0.333     0.000000     0.000000     0.000000   ->     0.000000     0.000000     0.000000
  | 3 O2-:0.500, F-:0.500    -1.714643    -1.212436    -0.000000   ->     0.500000     0.500000    -0.500000

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

a Cluster

Diameter : 3.6373
  Charge : 2.333333333333333
Centroid :    -1.714643     0.606218    -0.000000  ->     0.250000     0.250000     0.250000
Sites (4)
----------------------------------------------------------------------------------------------------------------------
0 Li+:0.333, Co2+:0.333, Mo5+:0.333    -1.714643     2.424871     0.000000   ->     0.000000    -0.000000     1.000000
1 O2-:0.500, F-:0.500    -3.429286     1.212436    -0.000000   ->     0.500000     0.500000     0.500000
2 Li+:0.333, Co2+:0.333, Mo5+:0.333     0.000000     0.000000     0.000000   ->     0.000000     0.000000     0.000000
3 O2-:0.500, F-:0.500    -1.714643    -1.212436    -0.000000   ->     0.500000     0.500000    -0.500000

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

And we can visualize clusters in jupyter super easy using crystal-toolkit!

from monty.serialization import loadfn
import crytal_toolkit

subspace = loadfn("co2mo5.mson")
subspace.orbits[-1].base_cluster

gives:
image

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 7, 2022

I won't do the __str__ and __repr__ for the missing classes in this PR.

@lbluque lbluque requested a review from qchempku2017 April 7, 2022 17:20
lbluque and others added 3 commits April 7, 2022 12:53
# Conflicts:
#	tests/test_cofe/test_cluster.py
#	tests/test_cofe/test_orbit.py
@lbluque lbluque added the enhancement New feature or request label Apr 7, 2022
@lbluque lbluque linked an issue Apr 7, 2022 that may be closed by this pull request
@qchempku2017
Copy link
Collaborator

And we can visualize clusters in jupyter super easy using crystal-toolkit!

from monty.serialization import loadfn
import crytal_toolkit

subspace = loadfn("co2mo5.mson")
subspace.orbits[-1].base_cluster

gives: image

I think it would be more useful if we can also plot out the decorated orbit that each correlation function corresponds to.

@qchempku2017
Copy link
Collaborator

A ClusterExpansion instance is printed as:

Basis/Orthogonal/Orthonormal : indicator/False/{self.basis_orthonormal}
       Unit Cell Composition : Mo5+0.33333333 Co2+0.33333333 Li+0.33333333 O2-0.5 F-0.5
            Number of Orbits : 34
No. of Correlation Functions : 82
             Cluster Cutoffs : 2: 6.96, 3: 3.64, 4: 3.64
              External Terms : [EwaldTerm(total)]
ECI-based Property : mean=-5.5733  std=4.9130
Fit Summary
EwaldTerm(total)=0.050
 ---------------------------------------------------------
 |  ID    Orbit ID    Degree    Cluster Diameter    ECI  |
 |   0       0          0              NA        -5.573  |
 |  1        1          1            0.0000       -0.593 |
 |  2        1          1            0.0000       -2.666 |
 |  3        2          1            0.0000       -3.241 |
 |  4        3          2            2.1000        0.002 |
 |  5        3          2            2.1000        0.222 |
 |  6        4          2            2.9698       -0.361 |
 |  7        4          2            2.9698       -0.138 |
 |  8        4          2            2.9698        0.046 |
 |  9        5          2            2.9698        0.094 |
....

In here I suggest printing out the species corresponding to each decorated orbit (correlation function as well.)

@qchempku2017
Copy link
Collaborator

A ClusterSubspace:

Basis/Orthogonal/Orthonormal : indicator/False/{self.basis_orthonormal}
       Unit Cell Composition : Mo5+0.33333333 Co2+0.33333333 Li+0.33333333 O2-0.5 F-0.5
            Number of Orbits : 34
No. of Correlation Functions : 82
             Cluster Cutoffs : 2: 6.96, 3: 3.64, 4: 3.64
              External Terms : [EwaldTerm(total)]
Orbit Summary
 ------------------------------------------------------------------------
 |  ID     Degree    Cluster Diameter    Multiplicity    No. Functions  |
 |   0       0             NA                 0                1        |
 |   1       1            0.0000              1                2        |
 |   2       1            0.0000              1                1        |
 |   3       2            2.1000              6                2        |
 |   4       2            2.9698              6                3        |
 |   5       2            2.9698              6                1        |
 |   6       2            3.6373              8                2        |
 |   7       2            4.2000              3                3        |
 |   8       2            4.2000              3                1        |
 |   9       2            4.6957              24               2        |
 |  10       2            5.1439              12               3        |
 |  11       2            5.1439              12               1        |

Same suggestion as with ClusterExpansion printing. With these, illustrating ECIs in a paper's SI will be infinitely easier!!

@qchempku2017
Copy link
Collaborator

I won't do the __str__ and __repr__ for the missing classes in this PR.

We can do them in an independent PR.

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 8, 2022

A ClusterExpansion instance is printed as:

Basis/Orthogonal/Orthonormal : indicator/False/{self.basis_orthonormal}
       Unit Cell Composition : Mo5+0.33333333 Co2+0.33333333 Li+0.33333333 O2-0.5 F-0.5
            Number of Orbits : 34
No. of Correlation Functions : 82
             Cluster Cutoffs : 2: 6.96, 3: 3.64, 4: 3.64
              External Terms : [EwaldTerm(total)]
ECI-based Property : mean=-5.5733  std=4.9130
Fit Summary
EwaldTerm(total)=0.050
 ---------------------------------------------------------
 |  ID    Orbit ID    Degree    Cluster Diameter    ECI  |
 |   0       0          0              NA        -5.573  |
 |  1        1          1            0.0000       -0.593 |
 |  2        1          1            0.0000       -2.666 |
 |  3        2          1            0.0000       -3.241 |
 |  4        3          2            2.1000        0.002 |
 |  5        3          2            2.1000        0.222 |
 |  6        4          2            2.9698       -0.361 |
 |  7        4          2            2.9698       -0.138 |
 |  8        4          2            2.9698        0.046 |
 |  9        5          2            2.9698        0.094 |
....

In here I suggest printing out the species corresponding to each decorated orbit (correlation function as well.)

I considered this (we had something along those lines before) however I think that makes the print out way too long. Users can simply print out an orbit to get that information, and if they want to see all species for all orbits then simply print out in a loop:

for orbit in subspace.orbits:
    print(orbit)

@lbluque
Copy link
Collaborator Author

lbluque commented Apr 8, 2022

I think it would be more useful if we can also plot out the decorated orbit that each correlation function corresponds to.

I'm not sure I fully understand what you mean? Do you mean getting the species decorations corresponding to a site indicator correlation function?

If that's the case then that would only apply to the indicator basis scenario. Even so I am not so sure how to visualize that exactly. Perhaps by visualizing a specific correlation function? This would be require a slightly different set of code and again only for an indicator case.

Copy link
Collaborator

@qchempku2017 qchempku2017 left a comment

Choose a reason for hiding this comment

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

Review done, nice job! Go ahead and merge if test pass.

Copy link
Collaborator

@qchempku2017 qchempku2017 left a comment

Choose a reason for hiding this comment

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

Please merge.

@lbluque lbluque merged commit cb304af into CederGroupHub:main Apr 8, 2022
@lbluque lbluque deleted the pretty_clusters branch April 8, 2022 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clusters visualization?
2 participants