diff options
author | Thomas White <taw@physics.org> | 2023-12-18 11:41:30 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2024-02-06 16:59:34 +0100 |
commit | e437e0465f07f66e188613da9568d7fa7f19dec5 (patch) | |
tree | 0436d2796660cea4d880cfb8597b7eaf4adccb97 | |
parent | e532c6dd7f5344fcdacfdca54bd2810f05d87b65 (diff) |
Julia: Add cell rotation
-rw-r--r-- | julia/CrystFEL/Manifest.toml | 13 | ||||
-rw-r--r-- | julia/CrystFEL/Project.toml | 1 | ||||
-rw-r--r-- | julia/CrystFEL/src/cell.jl | 28 | ||||
-rw-r--r-- | julia/alignment-test.jl | 7 |
4 files changed, 42 insertions, 7 deletions
diff --git a/julia/CrystFEL/Manifest.toml b/julia/CrystFEL/Manifest.toml index c59e01e9..e4ee3ce8 100644 --- a/julia/CrystFEL/Manifest.toml +++ b/julia/CrystFEL/Manifest.toml @@ -2,11 +2,22 @@ julia_version = "1.9.2" manifest_format = "2.0" -project_hash = "f604830d70fa58877def5710c5d1fa32dcb3f998" +project_hash = "4cf05e6854a627b02f001d01f38d3c0cbfcf00bd" [[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" +[[deps.Random]] +deps = ["SHA", "Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + [[deps.Unicode]] uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/julia/CrystFEL/Project.toml b/julia/CrystFEL/Project.toml index 6be52e40..8c81af0f 100644 --- a/julia/CrystFEL/Project.toml +++ b/julia/CrystFEL/Project.toml @@ -5,3 +5,4 @@ version = "0.1.0" [deps] Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/julia/CrystFEL/src/cell.jl b/julia/CrystFEL/src/cell.jl index 80250221..c098f8ca 100644 --- a/julia/CrystFEL/src/cell.jl +++ b/julia/CrystFEL/src/cell.jl @@ -1,5 +1,7 @@ module UnitCells +using Random + import ..CrystFEL: libcrystfel export UnitCell, LatticeType, CenteringType, UniqueAxis export TriclinicLattice, MonoclinicLattice, OrthorhombicLattice @@ -306,6 +308,8 @@ function Base.show(io::IO, uc::UnitCell) end +# This type is for talking to libcrystfel, and is named to avoid conflicting +# with other quaternion libraries. mutable struct CrystFELQuaternion w::Cdouble x::Cdouble @@ -313,6 +317,18 @@ mutable struct CrystFELQuaternion z::Cdouble end +function randomquat() + r = ()->2.0*rand(Float64)-1.0 + q = [r(), r(), r(), r()] + q ./ √(sum(q.^2)) +end + + +""" + rotatecell(uc::UnitCell, quaternion) + +Rotate a unit cell according to a quaternion (represented as a vector of 4 floats). +""" function rotatecell(uc, quat) q = CrystFELQuaternion(quat...) out = @ccall libcrystfel.cell_rotate(uc.internalptr::Ptr{InternalUnitCell}, @@ -323,4 +339,16 @@ function rotatecell(uc, quat) UnitCell(out) end + +""" + rotatecell(uc::UnitCell) + +Rotate a unit cell at random in three dimensions. Use this routine for +simulating serial crystallography datasets. + +Equivalent to CrystFEL routine `cell_rotate(uc, random_quaternion(<rng>))`. +""" +rotatecell(uc) = rotatecell(uc, randomquat()) + + end # of module diff --git a/julia/alignment-test.jl b/julia/alignment-test.jl index e6e1ab63..6fec3256 100644 --- a/julia/alignment-test.jl +++ b/julia/alignment-test.jl @@ -16,18 +16,13 @@ function sketch_pattern(image, cr) end -function randomrotation(cell) - rotatecell(cell, (1,0,0,0)) -end - - function simulate_and_index(cell, image_true, dtempl_moved, n) indexer = Indexer("asdf", dtempl_moved, cell, retry=false, multilattice=false, refine=true) for _ in 1:n - cr = Crystal(randomrotation(cell)) + cr = Crystal(rotatecell(cell)) peaklist = sketch_pattern(image_true, cr) image_moved = Image(dtempl_moved) |