This file contains hidden or 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
#!/usr/bin/env python3 | |
import gzip | |
from xml.etree import ElementTree as ET | |
from glob import glob | |
import numpy as np | |
import numpy.typing as npt | |
This file contains hidden or 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
// Credits to (Telegram): | |
// - @QC_Grove (zh) | blog.quarticcat.com (en/zh) | |
// - @bdbai_chat | |
trait Foo<T, U> { | |
type Output; | |
fn foo(a: T, b: U) -> Self::Output; | |
} | |
impl Foo<i32, f64> for () { |
This file contains hidden or 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
use std::fmt; | |
use std::fmt::{Debug, Display, Formatter}; | |
use nom::{ | |
branch::alt, | |
bytes::complete::tag, | |
character::complete::multispace0 as multispace, | |
number::complete::double, | |
combinator::map, | |
multi::many0, |
This file contains hidden or 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
#define STR2(x) #x | |
#define STR(x) STR2(x) | |
#ifdef __APPLE__ | |
#define USTR(x) "_" STR(x) | |
#else | |
#define USTR(x) STR(x) | |
#endif | |
#ifdef _WIN32 |
This file contains hidden or 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
# Let VER_STR be the version string | |
VER_STR="v1.14.514-rc-v1.919.810-tnok.." | |
# Use `sed` to extract the MAJOR, MINOR, PATCH number | |
echo $VER_STR | sed -nE 's/^v([0-9]+).([0-9]+).([0-9]+)(.*)$/\1 \2 \3/p' | |
# prints "1 14 514" | |
# Convert "1 14 514" to an array of ["1", "14", "514"] | |
VER=($(echo $VER_STR | sed -nE 's/^v([0-9]+).([0-9]+).([0-9]+)(.*)$/\1 \2 \3/p')) | |
echo ${VER[0]} # prints 1 |
This file contains hidden or 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
#!/usr/bin/env julia | |
using Printf: @printf; | |
function bc(x, L) | |
mod(x-1, L) + 1; | |
end | |
function totalEnergy(grid ::Matrix{Int64}) ::Float64 | |
(x, y) = size(grid); |
This file contains hidden or 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
FC = gfortran | |
FFLAGS = -O3 -fbounds-check -Wall -Wextra -ffree-form -ffree-line-length-none | |
test: main.x | |
./$< | |
main.x: main.f90 | |
$(FC) -o $@ $^ $(FFLAGS) | |
clean: |
This file contains hidden or 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
program main | |
use lapack_interfaces | |
implicit none | |
integer :: n = 2 | |
complex(8) :: h(2, 2) | |
integer :: lda = 2 | |
real(8) :: w(2) | |
complex(8) :: work(3) |
This file contains hidden or 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
&meta | |
ndim = 4 | |
/ | |
&matrix | |
H(1,:) = (1, 0), (2, 0), (3, 0), (1, 0), | |
H(2,:) = (3, 0), (2, 0), (9, 0), (1, 0), | |
H(3,:) = (8, 0), (2, 0), (2, 0), (1, 0), | |
H(4,:) = (9, 0), (2, 0), (0, 0), (1, 0), | |
/ |
This file contains hidden or 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
#!/usr/bin/env python3 | |
from ase.calculators.vasp import VaspChargeDensity | |
print("READING CHGCAR ...") | |
chgcar = VaspChargeDensity("CHGCAR") | |
assert chgcar.is_spin_polarized() | |
if len(chgcar.chgdiff) == 1: | |
spin_density = chgcar.chgdiff[0].copy() |