Skip to content

Commit

Permalink
Merge some minor changes to code from laptop with main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish Brown authored and Hamish Brown committed May 6, 2024
2 parents 8ecde71 + 0e59644 commit 8743f21
Show file tree
Hide file tree
Showing 13 changed files with 1,166 additions and 62 deletions.
802 changes: 802 additions & 0 deletions Demos/4D_STEM_workshop.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Demos/EFTEM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -129,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3-final"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions Demos/Multislice_fundamentals.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -153,7 +153,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions Demos/STEM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -274,7 +274,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.9.7"
}
},
"nbformat": 4,
Expand Down
194 changes: 194 additions & 0 deletions Demos/Structures/Bournonite_DW.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
Cu32 Sb32 Pb32 S96
7.8508870000000002 66.0262388867124628 9.0175350000000005
29 0.2549988946307309 0.0321998343556302 0.1737823872005961 1.0 0.076
29 0.7450011053692691 0.0321998343556302 0.1737823872005961 1.0 0.076
29 0.2400763309051968 0.0900957718020194 0.6554515705497224 1.0 0.076
29 0.7599236690948032 0.0900957718020194 0.6554515705497224 1.0 0.076
29 0.2582764286604302 0.1593574218186475 0.1468079926925085 1.0 0.076
29 0.7417235713395698 0.1593574218186475 0.1468079926925085 1.0 0.076
29 0.2408491992867425 0.2152452810329422 0.6414831666920975 1.0 0.076
29 0.7591508007132575 0.2152452810329422 0.6414831666920975 1.0 0.076
29 0.2591508007132575 0.2847547189670578 0.1414831666921046 1.0 0.076
29 0.7408491992867425 0.2847547189670578 0.1414831666921046 1.0 0.076
29 0.2417235713395698 0.3406425781813525 0.6468079926925085 1.0 0.076
29 0.7582764286604302 0.3406425781813525 0.6468079926925085 1.0 0.076
29 0.2599236690948032 0.4099042281979806 0.1554515705497224 1.0 0.076
29 0.7400763309051968 0.4099042281979806 0.1554515705497224 1.0 0.076
29 0.2450011053692691 0.4678001656443698 0.6737823872005961 1.0 0.076
29 0.7549988946307309 0.4678001656443698 0.6737823872005961 1.0 0.076
29 0.2549988946307309 0.5321998343556302 0.8262176127994039 1.0 0.076
29 0.7450011053692691 0.5321998343556302 0.8262176127994039 1.0 0.076
29 0.2400763309051968 0.5900957718020194 0.3445484294502776 1.0 0.076
29 0.7599236690948032 0.5900957718020194 0.3445484294502776 1.0 0.076
29 0.2582764286604302 0.6593574218186475 0.8531920073074915 1.0 0.076
29 0.7417235713395698 0.6593574218186475 0.8531920073074915 1.0 0.076
29 0.2408491992867425 0.7152452810329422 0.3585168333078954 1.0 0.076
29 0.7591508007132575 0.7152452810329422 0.3585168333078954 1.0 0.076
29 0.2591508007132575 0.7847547189670578 0.8585168333079025 1.0 0.076
29 0.7408491992867425 0.7847547189670578 0.8585168333079025 1.0 0.076
29 0.2417235713395698 0.8406425781813525 0.3531920073074915 1.0 0.076
29 0.7582764286604302 0.8406425781813525 0.3531920073074915 1.0 0.076
29 0.2599236690948032 0.9099042281979806 0.8445484294502776 1.0 0.076
29 0.7400763309051968 0.9099042281979806 0.8445484294502776 1.0 0.076
29 0.2450011053692691 0.9678001656443698 0.3262176127994039 1.0 0.076
29 0.7549988946307309 0.9678001656443698 0.3262176127994039 1.0 0.076
51 0.0000000000000000 0.0122267481353404 0.5530400412135563 1.0 0.076
51 0.0000000000000000 0.0595428582683724 0.9158388512261553 1.0 0.076
51 0.5000000000000000 0.0628118650072551 0.4111338669263347 1.0 0.076
51 0.5000000000000000 0.1158341111006180 0.0164786541061943 1.0 0.076
51 0.0000000000000000 0.1336514367816122 0.5148913920064686 1.0 0.076
51 0.0000000000000000 0.1859277089399924 0.9016812356007833 1.0 0.076
51 0.5000000000000000 0.1881659286336088 0.4023999131538005 1.0 0.076
51 0.5000000000000000 0.2410915156443210 0.0062207170260251 1.0 0.076
51 0.0000000000000000 0.2589084843556790 0.5062207170260251 1.0 0.076
51 0.0000000000000000 0.3118340713663912 0.9023999131538005 1.0 0.076
51 0.5000000000000000 0.3140722910600076 0.4016812356007833 1.0 0.076
51 0.5000000000000000 0.3663485632183878 0.0148913920064757 1.0 0.076
51 0.0000000000000000 0.3841658888993820 0.5164786541061943 1.0 0.076
51 0.0000000000000000 0.4371881349927449 0.9111338669263347 1.0 0.076
51 0.5000000000000000 0.4404571417316276 0.4158388512261553 1.0 0.076
51 0.5000000000000000 0.4877732518646596 0.0530400412135563 1.0 0.076
51 0.0000000000000000 0.5122267481353404 0.4469599587864437 1.0 0.076
51 0.0000000000000000 0.5595428582683724 0.0841611487738447 1.0 0.076
51 0.5000000000000000 0.5628118650072480 0.5888661330736653 1.0 0.076
51 0.5000000000000000 0.6158341111006180 0.9835213458938057 1.0 0.076
51 0.0000000000000000 0.6336514367816122 0.4851086079935243 1.0 0.076
51 0.0000000000000000 0.6859277089399924 0.0983187643992167 1.0 0.076
51 0.5000000000000000 0.6881659286336088 0.5976000868461995 1.0 0.076
51 0.5000000000000000 0.7410915156443210 0.9937792829739749 1.0 0.076
51 0.0000000000000000 0.7589084843556790 0.4937792829739749 1.0 0.076
51 0.0000000000000000 0.8118340713663912 0.0976000868461995 1.0 0.076
51 0.5000000000000000 0.8140722910600076 0.5983187643992167 1.0 0.076
51 0.5000000000000000 0.8663485632183878 0.9851086079935243 1.0 0.076
51 0.0000000000000000 0.8841658888993820 0.4835213458938057 1.0 0.076
51 0.0000000000000000 0.9371881349927520 0.0888661330736653 1.0 0.076
51 0.5000000000000000 0.9404571417316276 0.5841611487738447 1.0 0.076
51 0.5000000000000000 0.9877732518646596 0.9469599587864437 1.0 0.076
82 0.5000000000000000 0.0131024372194872 0.5980454469035479 1.0 0.076
82 0.5000000000000000 0.0551967309348242 0.8941404798603472 1.0 0.076
82 0.0000000000000000 0.0662367248380207 0.3829554713866443 1.0 0.076
82 0.0000000000000000 0.1153823422834108 0.0685052002658892 1.0 0.076
82 0.5000000000000000 0.1334653510911323 0.5645664789011278 1.0 0.076
82 0.5000000000000000 0.1810010466711276 0.8811988648952820 1.0 0.076
82 0.0000000000000000 0.1935194857923790 0.3816278298900855 1.0 0.076
82 0.0000000000000000 0.2409577900555746 0.0573520499982720 1.0 0.076
82 0.5000000000000000 0.2590422099444183 0.5573520499982720 1.0 0.076
82 0.5000000000000000 0.3064805142076210 0.8816278298900855 1.0 0.076
82 0.0000000000000000 0.3189989533288724 0.3811988648952891 1.0 0.076
82 0.0000000000000000 0.3665346489088677 0.0645664789011207 1.0 0.076
82 0.5000000000000000 0.3846176577165892 0.5685052002658892 1.0 0.076
82 0.5000000000000000 0.4337632751619793 0.8829554713866443 1.0 0.076
82 0.0000000000000000 0.4448032690651758 0.3941404798603472 1.0 0.076
82 0.0000000000000000 0.4868975627805128 0.0980454469035479 1.0 0.076
82 0.5000000000000000 0.5131024372194872 0.4019545530964521 1.0 0.076
82 0.5000000000000000 0.5551967309348242 0.1058595201396528 1.0 0.076
82 0.0000000000000000 0.5662367248380207 0.6170445286133557 1.0 0.076
82 0.0000000000000000 0.6153823422834108 0.9314947997341108 1.0 0.076
82 0.5000000000000000 0.6334653510911323 0.4354335210988793 1.0 0.076
82 0.5000000000000000 0.6810010466711205 0.1188011351047180 1.0 0.076
82 0.0000000000000000 0.6935194857923719 0.6183721701099145 1.0 0.076
82 0.0000000000000000 0.7409577900555746 0.9426479500017280 1.0 0.076
82 0.5000000000000000 0.7590422099444254 0.4426479500017280 1.0 0.076
82 0.5000000000000000 0.8064805142076281 0.1183721701099145 1.0 0.076
82 0.0000000000000000 0.8189989533288795 0.6188011351047180 1.0 0.076
82 0.0000000000000000 0.8665346489088677 0.9354335210988722 1.0 0.076
82 0.5000000000000000 0.8846176577165892 0.4314947997341108 1.0 0.076
82 0.5000000000000000 0.9337632751619793 0.1170445286133557 1.0 0.076
82 0.0000000000000000 0.9448032690651758 0.6058595201396528 1.0 0.076
82 0.0000000000000000 0.9868975627805128 0.9019545530964521 1.0 0.076
16 0.2689620644293171 0.0137874128407063 0.9561950661531213 1.0 0.076
16 0.7310379355706829 0.0137874128407063 0.9561950661531213 1.0 0.076
16 0.0000000000000000 0.0251730615346659 0.2933108302326346 1.0 0.076
16 0.5000000000000000 0.0280541802451140 0.3075684542015296 1.0 0.076
16 0.2652691685331092 0.0554896783436618 0.5893911555236215 1.0 0.076
16 0.7347308314668908 0.0554896783436618 0.5893911555236215 1.0 0.076
16 0.2348421708820609 0.0670300690197152 0.0940487892753268 1.0 0.076
16 0.7651578291179462 0.0670300690197152 0.0940487892753268 1.0 0.076
16 0.0000000000000000 0.0934552715052206 0.7983426467254304 1.0 0.076
16 0.5000000000000000 0.0956803414776388 0.7821511649999380 1.0 0.076
16 0.2351118622327846 0.1102908375143699 0.4433802785909648 1.0 0.076
16 0.7648881377672154 0.1102908375143699 0.4433802785909648 1.0 0.076
16 0.2622419402858256 0.1383456376049850 0.9376862868554312 1.0 0.076
16 0.7377580597141744 0.1383456376049850 0.9376862868554312 1.0 0.076
16 0.0000000000000000 0.1529483801855633 0.2747879838109810 1.0 0.076
16 0.5000000000000000 0.1542337752261318 0.2866255939828193 1.0 0.076
16 0.2648934021794602 0.1804285815430973 0.5790130917496370 1.0 0.076
16 0.7351065978205398 0.1804285815430973 0.5790130917496370 1.0 0.076
16 0.2348007474514731 0.1939440495259745 0.0780130644329091 1.0 0.076
16 0.7651992525485269 0.1939440495259745 0.0780130644329091 1.0 0.076
16 0.0000000000000000 0.2197611444083520 0.7829363351236225 1.0 0.076
16 0.5000000000000000 0.2213845835609902 0.7689066989036206 1.0 0.076
16 0.2363754836751966 0.2359151877354293 0.4309315410780741 1.0 0.076
16 0.7636245163248034 0.2359151877354293 0.4309315410780741 1.0 0.076
16 0.2636245163248034 0.2640848122645778 0.9309315410780741 1.0 0.076
16 0.7363754836751966 0.2640848122645778 0.9309315410780741 1.0 0.076
16 0.0000000000000000 0.2786154164390098 0.2689066989036206 1.0 0.076
16 0.5000000000000000 0.2802388555916480 0.2829363351236225 1.0 0.076
16 0.2651992525485269 0.3060559504740255 0.5780130644329091 1.0 0.076
16 0.7348007474514731 0.3060559504740255 0.5780130644329091 1.0 0.076
16 0.2351065978205398 0.3195714184569027 0.0790130917496370 1.0 0.076
16 0.7648934021794602 0.3195714184569027 0.0790130917496370 1.0 0.076
16 0.0000000000000000 0.3457662247738682 0.7866255939828193 1.0 0.076
16 0.5000000000000000 0.3470516198144367 0.7747879838109810 1.0 0.076
16 0.2377580597141744 0.3616543623950150 0.4376862868554312 1.0 0.076
16 0.7622419402858256 0.3616543623950150 0.4376862868554312 1.0 0.076
16 0.2648881377672154 0.3897091624856301 0.9433802785909648 1.0 0.076
16 0.7351118622327846 0.3897091624856301 0.9433802785909648 1.0 0.076
16 0.0000000000000000 0.4043196585223612 0.2821511649999451 1.0 0.076
16 0.5000000000000000 0.4065447284947794 0.2983426467254304 1.0 0.076
16 0.2651578291179391 0.4329699309802848 0.5940487892753268 1.0 0.076
16 0.7348421708820538 0.4329699309802848 0.5940487892753268 1.0 0.076
16 0.2347308314668908 0.4445103216563382 0.0893911555236215 1.0 0.076
16 0.7652691685331092 0.4445103216563382 0.0893911555236215 1.0 0.076
16 0.0000000000000000 0.4719458197548931 0.8075684542015296 1.0 0.076
16 0.5000000000000000 0.4748269384653341 0.7933108302326346 1.0 0.076
16 0.2310379355706829 0.4862125871592937 0.4561950661531213 1.0 0.076
16 0.7689620644293171 0.4862125871592937 0.4561950661531213 1.0 0.076
16 0.2689620644293171 0.5137874128407063 0.0438049338468787 1.0 0.076
16 0.7310379355706829 0.5137874128407063 0.0438049338468787 1.0 0.076
16 0.0000000000000000 0.5251730615346659 0.7066891697673654 1.0 0.076
16 0.5000000000000000 0.5280541802451069 0.6924315457984704 1.0 0.076
16 0.2652691685331092 0.5554896783436618 0.4106088444763785 1.0 0.076
16 0.7347308314668908 0.5554896783436618 0.4106088444763785 1.0 0.076
16 0.2348421708820609 0.5670300690197152 0.9059512107246732 1.0 0.076
16 0.7651578291179462 0.5670300690197152 0.9059512107246732 1.0 0.076
16 0.0000000000000000 0.5934552715052206 0.2016573532745696 1.0 0.076
16 0.5000000000000000 0.5956803414776388 0.2178488350000549 1.0 0.076
16 0.2351118622327846 0.6102908375143699 0.5566197214090352 1.0 0.076
16 0.7648881377672154 0.6102908375143699 0.5566197214090352 1.0 0.076
16 0.2622419402858256 0.6383456376049850 0.0623137131445688 1.0 0.076
16 0.7377580597141744 0.6383456376049850 0.0623137131445688 1.0 0.076
16 0.0000000000000000 0.6529483801855633 0.7252120161890190 1.0 0.076
16 0.5000000000000000 0.6542337752261318 0.7133744060171807 1.0 0.076
16 0.2648934021794602 0.6804285815430973 0.4209869082503630 1.0 0.076
16 0.7351065978205398 0.6804285815430973 0.4209869082503630 1.0 0.076
16 0.2348007474514731 0.6939440495259745 0.9219869355670909 1.0 0.076
16 0.7651992525485269 0.6939440495259745 0.9219869355670909 1.0 0.076
16 0.0000000000000000 0.7197611444083520 0.2170636648763775 1.0 0.076
16 0.5000000000000000 0.7213845835609902 0.2310933010963794 1.0 0.076
16 0.2363754836751966 0.7359151877354293 0.5690684589219259 1.0 0.076
16 0.7636245163248034 0.7359151877354293 0.5690684589219259 1.0 0.076
16 0.2636245163248034 0.7640848122645707 0.0690684589219259 1.0 0.076
16 0.7363754836751966 0.7640848122645707 0.0690684589219259 1.0 0.076
16 0.0000000000000000 0.7786154164390098 0.7310933010963794 1.0 0.076
16 0.5000000000000000 0.7802388555916480 0.7170636648763775 1.0 0.076
16 0.2651992525485269 0.8060559504740255 0.4219869355670909 1.0 0.076
16 0.7348007474514731 0.8060559504740255 0.4219869355670909 1.0 0.076
16 0.2351065978205398 0.8195714184569027 0.9209869082503630 1.0 0.076
16 0.7648934021794602 0.8195714184569027 0.9209869082503630 1.0 0.076
16 0.0000000000000000 0.8457662247738682 0.2133744060171807 1.0 0.076
16 0.5000000000000000 0.8470516198144367 0.2252120161890190 1.0 0.076
16 0.2377580597141744 0.8616543623950150 0.5623137131445688 1.0 0.076
16 0.7622419402858256 0.8616543623950150 0.5623137131445688 1.0 0.076
16 0.2648881377672154 0.8897091624856301 0.0566197214090352 1.0 0.076
16 0.7351118622327846 0.8897091624856301 0.0566197214090352 1.0 0.076
16 0.0000000000000000 0.9043196585223612 0.7178488350000620 1.0 0.076
16 0.5000000000000000 0.9065447284947794 0.7016573532745696 1.0 0.076
16 0.2651578291179391 0.9329699309802848 0.4059512107246732 1.0 0.076
16 0.7348421708820538 0.9329699309802848 0.4059512107246732 1.0 0.076
16 0.2347308314668908 0.9445103216563382 0.9106088444763785 1.0 0.076
16 0.7652691685331092 0.9445103216563382 0.9106088444763785 1.0 0.076
16 0.0000000000000000 0.9719458197548931 0.1924315457984704 1.0 0.076
16 0.5000000000000000 0.9748269384653341 0.2066891697673654 1.0 0.076
16 0.2310379355706829 0.9862125871592937 0.5438049338468787 1.0 0.076
16 0.7689620644293171 0.9862125871592937 0.5438049338468787 1.0 0.076
57 changes: 52 additions & 5 deletions Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def clean_temp_structure():
os.remove(scratch_cell_name)


def Single_atom(Z=79, r=[0.5, 0.5, 0.5], R=[10.0, 10.0, 10.0]):
def Single_atom(Z=79, r=[0.5, 0.5, 0.5], R=[10.0, 10.0, 10.0],dwf = 0.0):
"""Single atom structure for testing."""
atoms = np.asarray(
[
[*r, Z, 1.0, 0.0],
[*r, Z, 1.0, dwf],
]
)
return pyms.structure(R, atoms[:, :4], dwf=atoms[:, 5])
Expand Down Expand Up @@ -493,6 +493,53 @@ def test_make_potential(self):
)
self.assertTrue(within_spec)

def test_atom_placement(self):
"""Test that the code places atoms in the correct location with correct
mean square vibration"""
nT = 128
gridshape = [128,128]
# Make single Silver atom
R = 10
dwf = 0.02
r = [0.25,0.25,0.25]
cell = Single_atom(r=r, Z=2, R=[R, R, 2],dwf=dwf)

pot = np.zeros([nT]+gridshape)
for i in range(nT):
pot[i] = cell.make_potential(gridshape).cpu().numpy()

# Calculate COM in fraction of unit cell
M = np.sum(pot,axis=(-2,-1))
COMx = np.sum(pot*np.arange(gridshape[-1])/gridshape[-1],axis=(-2,-1))/M
COMy = np.sum(pot*np.arange(gridshape[-2]).reshape([gridshape[-2],1])/gridshape[-2],axis=(-2,-1))/M
COM = np.stack([COMy,COMx],axis=0)
# fig,ax=plt.subplots(ncols=2)
# ax[0].imshow(np.sum(pot,axis=0),origin='lower')
# ax[1].plot(COMx,COMy,'bo')
# plt.show(block=True)

moving_average = np.cumsum(COM,axis=1)/(np.arange(nT)+1)
moving_ms = np.cumsum(COMx**2+COMy**2)/(np.arange(nT)+1)/2 - np.average(moving_average**2,axis=0)
moving_ms*= R**2

# fig,ax = plt.subplots(ncols=2)
# ax[0].plot(COMx,COMy,'bo')
# ax[1].plot(moving_ms)
# from matplotlib.patches import Circle
# ax[0].add_patch(Circle(r[:2],radius=np.sqrt(dwf)/R))
# plt.show(block=True)

meanCOM = np.sum(COM,axis=1)/nT
# 5 Sigma test, ie. 1/3.5 million probability of failing assuming correct functioning
fiveSigma = dwf/nT*5**2
sigmaofvariance = dwf*np.sqrt(2/(nT-1))
muwithinspec = np.sum((meanCOM-r[0])**2) < fiveSigma
sigmawithinspec = np.abs(moving_ms[-1]-dwf) < 5*sigmaofvariance

withinspec = sigmawithinspec and muwithinspec
self.assertTrue(withinspec)


def test_resize(self):
"""Test the structure resize routine for cropping and padding with vaccuum."""
unitcell = [5.0, 5.0, 5.0]
Expand Down Expand Up @@ -1324,7 +1371,7 @@ def test_DPC(self):
# plt.show(block=True)
# print(sumsqr_diff(convolved_phase, reconstructed_phase,norm=True) )
self.assertTrue(
sumsqr_diff(convolved_phase, reconstructed_phase,norm=True)
sumsqr_diff(convolved_phase, reconstructed_phase,norm=True)
< 1e-1
)

Expand Down Expand Up @@ -1983,7 +2030,7 @@ def test_amplitude(self):
if __name__ == "__main__":
# test = Test_util_Methods()
# test.test_crop_tobandwidthlimit()

# test = Test_py_multislice_Methods()
# test.test_DPC()
# import sys; sys.exit()
Expand All @@ -2002,7 +2049,7 @@ def test_amplitude(self):
# suite.run()
# test.run()
# test = Test_Structure_Methods()
# test.test_multilayer_objects()
# test.test_atom_placement()

# test.test_electron_scattering_factor()
# test.test_make_potential()
Expand Down
Loading

0 comments on commit 8743f21

Please sign in to comment.