-
Notifications
You must be signed in to change notification settings - Fork 0
JuliaSpect/XRD.jl
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# XRD.jl\n",
"\n",
"Convenience functions for working with X-ray diffraction data."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module Reexport.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module StaticArrays.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module RecipesBase.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module PlotUtils.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module PlotThemes.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module Showoff.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module StatsBase.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module NaNMath.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module Measures.\n",
"\u001b[39m\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module Requires.\n",
"\u001b[39m"
]
}
],
"source": [
"using Plots"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mRecompiling stale cache file /home/juser/.julia/lib/v0.6/Cubature.ji for module Cubature.\n",
"\u001b[39m"
]
},
{
"data": {
"text/plain": [
"XRD"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"include(\"xrd.jl\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Structural statistics\n",
"\n",
"Often one needs to report average bond lengths \n",
"\n",
"Take, for example, the following compound [10.1021/acs.orglett.6b00577](http://pubs.acs.org/doi/suppl/10.1021/acs.orglett.6b00577)\n",
""
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"r\"^\\s([a-z][a-z]?\\d+)\\s+([a-z][a-z]?\\d+)\\s+(\\d+\\.\\d+)\\((\\d+)\\).*\"im"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"length_regex = r\"^\\s([a-z][a-z]?\\d+)\\s+([a-z][a-z]?\\d+)\\s+(\\d+\\.\\d+)\\((\\d+)\\).*\"mi"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING: ColorTypes.U16 is deprecated, use FixedPointNumbers.Normed{UInt16, 16} instead.\n",
" likely near In[7]:1\n",
"WARNING: ColorTypes.U8 is deprecated, use FixedPointNumbers.Normed{UInt8, 8} instead.\n",
" likely near In[7]:1\n",
"WARNING: ColorTypes.U16 is deprecated, use FixedPointNumbers.Normed{UInt16, 16} instead.\n",
" likely near In[7]:1\n",
"WARNING: ColorTypes.U8 is deprecated, use FixedPointNumbers.Normed{UInt8, 8} instead.\n",
" likely near In[7]:1\n",
"WARNING: ColorTypes.U16 is deprecated, use FixedPointNumbers.Normed{UInt16, 16} instead.\n",
" likely near In[7]:1\n",
"WARNING: ColorTypes.U8 is deprecated, use FixedPointNumbers.Normed{UInt8, 8} instead.\n",
" likely near In[7]:1\n"
]
},
{
"data": {
"text/html": [
"25-element Array{Method,1}:<ul><li> ==(a::<b>Regex</b>, b::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L370\" target=\"_blank\">regex.jl:370</a><li> apropos(io::<b>IO</b>, needle::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/docs/utils.jl#L447\" target=\"_blank\">docs/utils.jl:447</a><li> eachmatch(re::<b>Regex</b>, str::<b>AbstractString</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L365\" target=\"_blank\">regex.jl:365</a><li> eachmatch(re::<b>Regex</b>, str::<b>AbstractString</b>, ovr::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L362\" target=\"_blank\">regex.jl:362</a><li> hash(r::<b>Regex</b>, h::<b>UInt64</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L376\" target=\"_blank\">regex.jl:376</a><li> ismatch(r::<b>Regex</b>, s::<b>SubString</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L151\" target=\"_blank\">regex.jl:151</a><li> ismatch(r::<b>Regex</b>, s::<b>SubString</b>, offset::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L151\" target=\"_blank\">regex.jl:151</a><li> ismatch(r::<b>Regex</b>, s::<b>AbstractString</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L145\" target=\"_blank\">regex.jl:145</a><li> ismatch(r::<b>Regex</b>, s::<b>AbstractString</b>, offset::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L145\" target=\"_blank\">regex.jl:145</a><li> match(re::<b>Regex</b>, str::<b>Union{String, SubString{String}}</b>, idx::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L159\" target=\"_blank\">regex.jl:159</a><li> match(re::<b>Regex</b>, str::<b>Union{String, SubString{String}}</b>, idx::<b>Integer</b>, add_opts::<b>UInt32</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L159\" target=\"_blank\">regex.jl:159</a><li> match(r::<b>Regex</b>, s::<b>AbstractString</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L173\" target=\"_blank\">regex.jl:173</a><li> match(r::<b>Regex</b>, s::<b>AbstractString</b>, i::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L174\" target=\"_blank\">regex.jl:174</a><li> matchall(re::<b>Regex</b>, str::<b>String</b>, overlap::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L179\" target=\"_blank\">regex.jl:179</a><li> matchall(re::<b>Regex</b>, str::<b>String</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L179\" target=\"_blank\">regex.jl:179</a><li> matchall(re::<b>Regex</b>, str::<b>SubString</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L212\" target=\"_blank\">regex.jl:212</a><li> matchall(re::<b>Regex</b>, str::<b>SubString</b>, overlap::<b>Bool</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L212\" target=\"_blank\">regex.jl:212</a><li> search(str::<b>Union{String, SubString}</b>, re::<b>Regex</b>, idx::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L216\" target=\"_blank\">regex.jl:216</a><li> search(s::<b>AbstractString</b>, r::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L227\" target=\"_blank\">regex.jl:227</a><li> search(s::<b>AbstractString</b>, r::<b>Regex</b>, idx::<b>Integer</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L224\" target=\"_blank\">regex.jl:224</a><li> serialize(s::<b>AbstractSerializer</b>, r::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/serialize.jl#L302\" target=\"_blank\">serialize.jl:302</a><li> show(io::<b>IO</b>, re::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/regex.jl#L86\" target=\"_blank\">regex.jl:86</a><li> whos(pat::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/interactiveutil.jl#L729\" target=\"_blank\">interactiveutil.jl:729</a><li> whos(m::<b>Module</b>, pat::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/interactiveutil.jl#L728\" target=\"_blank\">interactiveutil.jl:728</a><li> whos(io::<b>IO</b>, m::<b>Module</b>, pattern::<b>Regex</b>) at <a href=\"https://github.com/JuliaLang/julia/tree/903644385b91ed8d95e5e3a5716c089dd1f1b08a/base/interactiveutil.jl#L686\" target=\"_blank\">interactiveutil.jl:686</a></ul>"
],
"text/plain": [
"25-element Array{Method,1}:\n",
" ==(a::Regex, b::Regex) in Base at regex.jl:370 \n",
" apropos(io::IO, needle::Regex) in Base.Docs at docs/utils.jl:447 \n",
" eachmatch(re::Regex, str::AbstractString) in Base at regex.jl:365 \n",
" eachmatch(re::Regex, str::AbstractString, ovr::Bool) in Base at regex.jl:362 \n",
" hash(r::Regex, h::UInt64) in Base at regex.jl:376 \n",
" ismatch(r::Regex, s::SubString) in Base at regex.jl:151 \n",
" ismatch(r::Regex, s::SubString, offset::Integer) in Base at regex.jl:151 \n",
" ismatch(r::Regex, s::AbstractString) in Base at regex.jl:145 \n",
" ismatch(r::Regex, s::AbstractString, offset::Integer) in Base at regex.jl:145 \n",
" match(re::Regex, str::Union{String, SubString{String}}, idx::Integer) in Base at regex.jl:159 \n",
" match(re::Regex, str::Union{String, SubString{String}}, idx::Integer, add_opts::UInt32) in Base at regex.jl:159\n",
" match(r::Regex, s::AbstractString) in Base at regex.jl:173 \n",
" match(r::Regex, s::AbstractString, i::Integer) in Base at regex.jl:174 \n",
" matchall(re::Regex, str::String, overlap::Bool) in Base at regex.jl:179 \n",
" matchall(re::Regex, str::String) in Base at regex.jl:179 \n",
" matchall(re::Regex, str::SubString) in Base at regex.jl:212 \n",
" matchall(re::Regex, str::SubString, overlap::Bool) in Base at regex.jl:212 \n",
" search(str::Union{String, SubString}, re::Regex, idx::Integer) in Base at regex.jl:216 \n",
" search(s::AbstractString, r::Regex) in Base at regex.jl:227 \n",
" search(s::AbstractString, r::Regex, idx::Integer) in Base at regex.jl:224 \n",
" serialize(s::AbstractSerializer, r::Regex) in Base.Serializer at serialize.jl:302 \n",
" show(io::IO, re::Regex) in Base at regex.jl:86 \n",
" whos(pat::Regex) in Base at interactiveutil.jl:729 \n",
" whos(m::Module, pat::Regex) in Base at interactiveutil.jl:728 \n",
" whos(io::IO, m::Module, pattern::Regex) in Base at interactiveutil.jl:686 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"methodswith(typeof(length_regex))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data = readstring(\"mm257.cif\");"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Dict{Set{SubString{String}},Tuple{Float64,Int64}} with 21 entries:\n",
" Set(SubString{String}[\"C13\", \"N3\"]) => (1.327, 3)\n",
" Set(SubString{String}[\"C1\", \"C2\"]) => (1.456, 3)\n",
" Set(SubString{String}[\"O3\", \"C5\"]) => (1.247, 3)\n",
" Set(SubString{String}[\"N1\", \"C9\"]) => (1.468, 4)\n",
" Set(SubString{String}[\"C8\", \"N1\"]) => (1.455, 4)\n",
" Set(SubString{String}[\"C10\", \"N2\"]) => (1.315, 3)\n",
" Set(SubString{String}[\"O1\", \"C1\"]) => (1.262, 3)\n",
" Set(SubString{String}[\"C11\", \"N2\"]) => (1.463, 3)\n",
" Set(SubString{String}[\"C2\", \"C3\"]) => (1.474, 3)\n",
" Set(SubString{String}[\"C3\", \"O2\"]) => (1.25, 3)\n",
" Set(SubString{String}[\"C12\", \"N2\"]) => (1.463, 3)\n",
" Set(SubString{String}[\"C14\", \"N3\"]) => (1.459, 3)\n",
" Set(SubString{String}[\"C3\", \"C4\"]) => (1.455, 3)\n",
" Set(SubString{String}[\"C2\", \"C7\"]) => (1.397, 4)\n",
" Set(SubString{String}[\"C1\", \"C6\"]) => (1.46, 4)\n",
" Set(SubString{String}[\"C4\", \"C5\"]) => (1.459, 3)\n",
" Set(SubString{String}[\"C10\", \"C4\"]) => (1.403, 3)\n",
" Set(SubString{String}[\"C6\", \"C5\"]) => (1.468, 3)\n",
" Set(SubString{String}[\"N1\", \"C7\"]) => (1.318, 3)\n",
" Set(SubString{String}[\"C6\", \"C13\"]) => (1.394, 3)\n",
" Set(SubString{String}[\"C15\", \"N3\"]) => (1.47, 3)"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Dict(Set([m.captures[1],m.captures[2]]) => (float(m.captures[3]),parse(Int,m.captures[4])) for m in eachmatch(length_regex, data))"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"RegexMatch(\" O1 C1 1.262(3) . ?\\r\", 1=\"O1\", 2=\"C1\", 3=\"1.262(3)\")"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x=match(length_regex,data)"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"SubString{String}"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"typeof(x.captures[1])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 0.6.0",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.0"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
About
Utility functions for working with X-ray diffraction data
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published