Skip to content

Instantly share code, notes, and snippets.

View larsbratholm's full-sized avatar

Lars Andersen Bratholm larsbratholm

View GitHub Profile
@larsbratholm
larsbratholm / make_phaistos.sh
Created August 14, 2021 19:56
compile phaistos
#!/usr/bin/env bash
export BOOST_ROOT_DIR=/home/lab/opt/boost-1.58_gcc-1.61
export BOOST_ROOT=$BOOST_ROOT_DIR
export LD_LIBRARY_PATH=$BOOST_ROOT_DIR/lib #:/usr/lib64:$LD_LIBRARY_PATH
export CC=gcc-6; export CXX=g++-6
mkdir $1
cd $1
def dice_example_l():
"""
Example with a biased dice with a previously observed mean
The lagrange multiplier l is optimized rather than p
"""
def entropy(l, *args):
"""
Entropy of p
"""
p = analytical(l)
if metric == 'rmse':
metric_fun = lambda x: np.std(x, axis=1)
elif metric == 'mae':
metric_fun = lambda x: np.mean(abs(x), axis=1)
@larsbratholm
larsbratholm / rmsdlol.py
Last active January 31, 2020 13:35
fix xyz reader
tokens = line.split()
try:
atom = tokens[0].upper()
numbers = np.asarray(tokens[1:4], dtype=float)
except:
exit("Reading the .xyz file failed in line {0}. Please check the format.".format(lines_read + 2))
V.append(numbers)
atoms.append(atom)
@larsbratholm
larsbratholm / kde_example.py
Last active January 23, 2020 09:25
Example of 1d KDE using scipy and sklearn
import scipy.stats
import matplotlib.pyplot as plt
import sklearn.model_selection
import sklearn.neighbors
def kde_scipy(x, x_grid):
"""
Using heuristic for bandwidth
"""
kde = scipy.stats.gaussian_kde(x)
15
N -0.1805406906 1.4242349529 -0.0108675046
C 0.0495047193 0.0416229792 0.0372221139
N -1.0209269792 -0.7454454085 0.1001912635
H -1.9045501495 -0.2501680795 0.1747475728
C -1.1035482774 -2.0851342296 0.0629959263
C -2.1858877347 -2.9591823159 0.1129706520
N -1.7728257655 -4.2139610664 0.0327337682
C -0.3907063555 -4.1580119412 -0.069503388
@larsbratholm
larsbratholm / interpolate.py
Last active November 8, 2019 14:59
nmr interpolation
import sklearn.neighbors
import sklearn.ensemble
import itertools
def create_lookup_table(angles, cs, lookup_table_filename, granularity_degree=20):
"""
Creates lookup tables for procs15
"""
# convert everything to numpy arrays
@larsbratholm
larsbratholm / store_cs.py
Created November 6, 2019 11:23
parsing cs and angles
import numpy as np
if __name__ == "__main__":
# parse angles to get an array like
x = [
[160, 90],
[80, 120]
]
# save the parsed data
for i in range(100000):
# get 6 random angles
ang1, ang2, ang3, ang4, ang5, ang6 = np.random.randint(0,360,size=6)
# set angles here
# write gaussian constrained optimization (PM6) where all the angles are part of the filename
@larsbratholm
larsbratholm / fchl_plot.py
Created July 31, 2019 12:03
fchl 2-body term
import numpy as np
import matplotlib.pyplot as plt
if __name__ == "__main__":
w = 0.41
N2 = 2.4
x = np.linspace(0.5,6,1000)
s2 = np.log(1+w/x**2)
s = np.sqrt(s2)
mu = np.log(x/np.sqrt(1+w/x**2))