Skip to content

Instantly share code, notes, and snippets.

@yangyushi
yangyushi / simulate.py
Created October 11, 2018 09:37
Simulating Particle Image
def core_shell_gaussian(x, core, shell):
"""
since we're dealing with REAL image with normally uint8 float type
value < 1/255 --> value = 0
let zero = 1/256
"""
constant = shell ** 2 * 0.18033688011112042 # - shell^2 / ln(zero)
core_shell = np.exp(- (x - core) ** 2 / constant)
core_shell[x <= core] = 1.0 # construct core
core_shell[x >= (core + shell)] = 0.0 # trim 4 edges of the box
@yangyushi
yangyushi / rotation.py
Created October 12, 2018 16:41
Find the best rotation and dilatation between points, according to 10.1107/S0567739476001873
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from scipy.optimize import least_squares
def get_best_rotation(r1, r2):
"""
calculate the best rotation to relate two sets of vectors
DELETE FROM raw_image WHERE id NOT IN (SELECT raw_image_id FROM result);
DELETE FROM image WHERE id NOT IN (SELECT image_id FROM result);
DELETE FROM image_parameter WHERE id NOT IN (SELECT image_parameter_id FROM result);
DELETE FROM segment_parameter WHERE id NOT IN (SELECT segment_parameter_id FROM result);
DELETE FROM result_tag WHERE id_result NOT IN (SELECT id FROM result);
VACUUM;
def array_to_xyz(filename, array):
"""
Append many frames to the same xyz file that ovito can read
The file is overwritten everytime
array: [frame_1, frame_2, ...]
coordinate in one frame: (dimension, number_of_particles)
"""
if '.xyz' == filename[-4:]:
fname = filename
else:
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy import signal
a = np.ones((20, 20)) * 0
a[5, 5] = 1
a[10, 10] = 1
a[15, 15] = 1
import numpy as np
from scipy.optimize import minimize
def get_in_plane_dist_sqr(x, e1, e2):
gamma, delta = x
dist_sqr = gamma**2 + delta**2 - 2 * gamma * delta * (e1 @ e2)
return dist_sqr
def get_segment_dist(r1, r2, e1, e2, L1, L2):
"""
@yangyushi
yangyushi / n_queens.py
Created October 21, 2019 11:49
get all possible configurations in n queens problem
def conflict(conf):
for i in range(len(conf) - 1):
if conf[i] == conf[-1]:
return True
if len(conf) - i - 1 == conf[-1] - conf[i]:
return True
elif len(conf) - i - 1 == conf[i] - conf[-1]:
return True
return False
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
./configure\
--enable-optimizations\
--prefix=/usr/local\
--enable-shared\
--with-openssl=$(brew --prefix openssl)\
CPPFLAGS="-I/usr/local/opt/openssl/include"\
LDFLAGS="-L/usr/local/opt/openssl/lib"
@yangyushi
yangyushi / reform.py
Last active May 16, 2020 11:35
format the entry key names in your bib file to please your supervisor
#!/usr/bin/env python
import re
import sys
from textwrap import dedent
STOPWORDS = [ # common stop words from package nltk
"i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "you're", "you've", "you'll",
"you'd", "your", "yours", "yourself", "yourselves", "he", "him", "his", "himself", "she", "she's",
"her", "hers", "herself", "it", "it's", "its", "itself", "they", "them", "their", "theirs",
"themselves", "what", "which", "who", "whom", "this", "that", "that'll", "these", "those", "am",
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp=yes \
--enable-python3interp=yes \
--with-python3-config-dir=$(python3-config --configdir) \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-cscope \
--prefix=/usr/local