Skip to content

Instantly share code, notes, and snippets.

View lan496's full-sized avatar

Kohei Shinohara lan496

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lan496
lan496 / dist_kdtree.py
Created February 13, 2019 05:42
attempt to calculate distance via KDtree
import math
import itertools
import numpy as np
from scipy.spatial import KDTree
from pymatgen.core.sites import PeriodicSite
def get_kdtree(structure, cutoff):
recp_len = np.array(structure.lattice.reciprocal_lattice.abc)
from itertools import product
import numpy as np
def enumerate_ANX(oxi_states, max_ratio=8):
ret = []
for anx in product(range(1, max_ratio + 1), repeat=len(oxi_states)):
if np.sum(np.array(oxi_states) * np.array(anx)) == 0:
ret.append(anx)
return ret
@lan496
lan496 / bop.py
Last active April 8, 2019 09:16
reduced third-order invariant of BOP
# Copyright (c) Pymatgen Development Team.
from math import acos, sqrt
import numpy as np
from scipy.special import sph_harm
from sympy.physics.wigner import wigner_3j
from pymatgen.analysis.local_env import CrystalNN
def get_neighbor_sites(structure, n, cutoff):
from functools import lru_cache
from itertools import product
from scipy.special import binom
def polya_counting(permutation_group, num_color):
cnt = 0
for perm in permutation_group:
type_of_perm = get_type_of_permutation(perm)
@lan496
lan496 / sanitize_disorder.py
Last active May 16, 2019 03:51
sanitize disorder structure to get prototype structure
from pymatgen.core import Structure, DummySpecie
from pymatgen.core.sites import PeriodicSite
def unique_species(structure: Structure):
list_species = [site.species for site in structure if not site.is_ordered]
uniqued = []
for sp in list_species:
flag = True
for sp2 in uniqued:
@lan496
lan496 / joblib_time.py
Created May 19, 2019 07:50
parallel computation with timeout handling
from time import sleep
from joblib import Parallel, delayed
from timeout_decorator import timeout, TimeoutError
@timeout(10, use_signals=False)
def f(n):
if n == 0:
sleep(42)
@lan496
lan496 / unionfind.jl
Created May 24, 2019 07:38
implementation of union find with julia
"""
refs.
- https://atc001.contest.atcoder.jp/tasks/unionfind_a
- https://github.com/phil-mansfield/UnionFind.jl
- https://github.com/spaghetti-source/algorithm/blob/master/data_structure/union_find.cc
"""
mutable struct UnionFind{T <: Integer}
parent:: Vector{T} # parent[root] is the negative of the size
function UnionFind{T}(nodes::T) where T<:Integer
import pulp
class SudokuSolver:
# ref: https://pythonhosted.org/PuLP/CaseStudies/a_sudoku_problem.html
def __init__(self, cell_initial):
self.cell_initial = cell_initial
self.rows = [i for i in range(1, 9 + 1)]
self.cols = [i for i in range(1, 9 + 1)]
@lan496
lan496 / rss_mathjax.js
Created September 30, 2019 07:58
User script for Tampermonkey that renders TeX symbols
// ==UserScript==
// @name Enable MathJax
// @namespace http://tampermonkey.net/
// @version 0.1
// @description enable MathJax in inoreader pages
// @author lan496
// @match https://www.inoreader.com/*
// @grant none
// ==/UserScript==