Skip to content

Instantly share code, notes, and snippets.

View pastewka's full-sized avatar

Lars Pastewka pastewka

View GitHub Profile
@pastewka
pastewka / bluetooth.sh
Last active September 20, 2021 15:56
Automatically import bluetooth keys from Windows to Linux
#! /bin/bash
WINDOWS_ROOT=$1
cd $WINDOWS_ROOT/Windows/System32/config
# Get MAC address of Bluetooth module
for mac in /var/lib/bluetooth/??:??:??:??:??:??; do
btmacwin=$(basename ${mac} | sed 's/://g' | awk '{print tolower($0)}')
btdir=${mac}
@pastewka
pastewka / gpc.py
Last active September 14, 2021 13:16
Simple Gaussian process classification example
"""Simple Gaussian process classification example (Laplacian approximation)"""
import numpy as np
import scipy.special
import matplotlib.pyplot as plt
class ProbitLikelihood:
"""
@pastewka
pastewka / gpr.py
Last active September 14, 2021 10:02
Simple Gaussian process regression example
"""Simple Gaussian process regression example"""
import numpy as np
import matplotlib.pyplot as plt
def kernel(x1, x2, length_scale=1, signal_variance=1):
return signal_variance*np.exp(-(x1-x2)**2 / (2*length_scale**2))
@pastewka
pastewka / install_packages.sh
Last active January 4, 2024 09:30
Fedora packages
sudo wget -qO /etc/yum.repos.d/enpass-yum.repo https://yum.enpass.io/enpass-yum.repo
sudo wget -qO /etc/yum.repos.d/softmaker.repo https://shop.softmaker.com/repo/softmaker.repo
sudo rpm -v --import https://packages.microsoft.com/keys/microsoft.asc
sudo rpm -v --import https://download.sublimetext.com/sublimehq-rpm-pub.gpg
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf install -y dnf-plugin-config-manager fedora-workstation-repositories
sudo dnf config-manager --set-enabled google-chrome
sudo dnf config-manager --add-repo https://download.sublimetext.com/rpm/stable/x86_64/sublime-text.repo
@pastewka
pastewka / read_xdmf.py
Last active September 3, 2019 08:20
Simple XDMF reader
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
@pastewka
pastewka / lammps_to_data.py
Last active April 10, 2019 14:06
Convert LAMMPS data files into NetCDF trajectory
import glob
import os
from ase.io import NetCDFTrajectory, read
fns = glob.glob('/work/ws/nemo/fr_rj1011-18.07.03-GAP_low_density-0/18.10.15-aC_GAP-quasistatic-bond_breaking_B/quasistatic-2.7_B_*.lammps')
nc = NetCDFTrajectory('quasistatic_2.7.nc', 'w')
fns = sorted(fns, key=lambda x: int(os.path.basename(x).replace('quasistatic-2.7_B_', '').replace('.lammps', '')))
for fn in fns:
@pastewka
pastewka / ncsparsify.cpp
Created September 13, 2017 15:11
Remove frames from AMBER NetCDF trajectory files.
/*
Copyright (c) 2017 Lars Pastewka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@pastewka
pastewka / png2mp4.sh
Created July 25, 2017 19:33
Encode sequence of pngs to mp4
ffmpeg -r 60 -f image2 -i vacancy_diffusion%04d.png -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4
@pastewka
pastewka / nc2data.cpp
Last active July 27, 2017 11:32
Convert AMBER NetCDF trajectory to LAMMPS data file
/*
Copyright (c) 2017 Lars Pastewka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@pastewka
pastewka / extract_thermo.sh
Created July 16, 2017 11:38
Extract "thermo" output section from a LAMMPS log file
#! /bin/sh
cat log.lammps | sed -n "/Step/,/Loop time/p" | head -n-1 > thermo.out