This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function find_min_energy_map2(energy) | |
energy = transpose(energy) | |
row, col = size(energy) | |
dir_arr = [-1, 0, 1] | |
energy_map = zeros(row, col) | |
energy_map[:, end] = energy[:, end] | |
dirs = zeros(Int, row, col) | |
@inbounds for c = col-1:-1:1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compare_with_qe(result, qe_result, alat) | |
result = map(result * alat) do vec | |
map(v -> round(v; digits = 7), vec) | |
end | |
f(result) = sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z]) | |
g(result) = result[sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z])] | |
# result_df = sortperm(DataFrame(hcat(result...)', [:x, :y, :z]), [:x, :y, :z]) | |
# qe_df = sortperm(DataFrame(hcat(qe_result...)', [:x, :y, :z]), [:x, :y, :z]) | |
# result_df, qe_df | |
symdiff(result, qe_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
def irrmesh(mapping, grid, shift = [0, 0, 0]): | |
shift = np.array(list(map(lambda x: 0.5 if x == 1 else 0, shift))) | |
count = collections.Counter(mapping) | |
result = [] | |
for ir_gp_id, gp in zip(np.unique(mapping), grid[np.unique(mapping)]): | |
result.append(np.append((gp.astype(float) + shift) / mesh, count[ir_gp_id]).tolist()) | |
return np.array(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See https://github.com/JuliaLang/julia/issues/4648#issuecomment-761030051 | |
# ASSUMTION: `e1` and `e2` have the same run-time type | |
@generated structEqual(e1, e2) = begin | |
if fieldcount(e1) == 0 | |
return :(true) | |
end | |
mkEq = fldName -> :(e1.$fldName == e2.$fldName) | |
# generate individual equality checks | |
eqExprs = map(mkEq, fieldnames(e1)) | |
# construct &&-expression for chaining all checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Plots | |
# https://www.zhihu.com/question/22477205/answer/21521946 | |
earth(t) = (cos(2pi * t), sin(2pi * t)) | |
mercury(t) = 0.387 .* (cos(26.1t), sin(26.1t)) .- earth(t) | |
mercury2(t) = ( | |
(0.387cos(26.1t) - cos(2t * pi)) * cos(730t * pi) - | |
(0.387sin(26.1t) - sin(2t * pi)) * sin(730t * pi), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function merge(g, b) | |
a = copy(g) | |
add_vertices!(a, nv(b)) | |
for e in edges(h) | |
add_edge!(a, src(e) + nv(g), dst(e) + nv(g)) | |
end | |
return a | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://discourse.julialang.org/t/better-support-for-running-external-commands/44933/26 | |
function execute(cmd::Cmd) | |
out = Pipe() | |
err = Pipe() | |
process = run(pipeline(ignorestatus(cmd), stdout = out, stderr = err)) | |
close(out.in) | |
close(err.in) | |
stdout = @async String(read(out)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parametric types which add or delete fields | |
# from https://groups.google.com/forum/#!msg/julia-users/jUMu9A3QKQQ/qjgVWr7vAwAJ | |
using BenchmarkTools | |
struct Container1{T} | |
val::T | |
end | |
inc(::Int) = 1 | |
inc(::Float64) = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Suppressor | |
const version = v"3.1.1" | |
map(1:13) do i | |
ext = lpad(i, 2, "0") | |
file = cp( | |
"Casks/font-iosevka-ss14.rb", | |
"Casks/font-iosevka-ss$ext.rb", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"latex-workshop.latex.tools": [ | |
{ | |
"name": "XeLaTeXmk", | |
"command": "latexmk", | |
"args": [ | |
"-xelatex", | |
"-synctex=1", | |
"-shell-escape", | |
"-interaction=nonstopmode", |