Skip to content

Instantly share code, notes, and snippets.

View ChrisDavi3s's full-sized avatar
🐢

Chris Davies ChrisDavi3s

🐢
View GitHub Profile
@ChrisDavi3s
ChrisDavi3s / lammpsrun.py
Last active June 18, 2024 16:45
Rewrite of the ase LAMMPS dat file parser to yield 50-100x speedup and properly implement lazy loading and indexing
# All rights for ase belong to the owners at https://gitlab.com/ase/ase
# this is a partial rewrite of the original lammpsrun.py found at:
# https://gitlab.com/ase/ase/-/blob/master/ase/io/lammpsrun.py?ref_type=heads
# Modifcations made by Chris Davies. See ase merge request
# https://gitlab.com/ase/ase/-/merge_requests/3354
import gzip
import struct
from os.path import splitext
@ChrisDavi3s
ChrisDavi3s / swap_duplicate_runs.r
Created June 25, 2024 23:36
Fix repeated flagged runs
# Step 1: Identify Binary and Rare Trials
bi_index <- which(curr_block$option_left == 2 | curr_block$option_right == 2) # Binary option trial indices
rare_index <- which(curr_block$is_rare == 1) # Rare outcome trial indices
# Step 2: Find Positions of Rare Outcomes within Binary Trials
idx_rare_in_bi <- match(rare_index, bi_index) # Positions of rare outcomes in binary trials
diff_rare_in_bi <- diff(idx_rare_in_bi) # Differences between consecutive rare outcomes
# Step 3: Identify Consecutive Rare Outcomes
if (any(diff_rare_in_bi == 1)) { # Check for consecutive rare outcomes
@ChrisDavi3s
ChrisDavi3s / phase_diagram.py
Created July 8, 2024 09:27
Configurable script to plot compositional phase diagrams
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon, FancyArrowPatch
from typing import List, Tuple, Optional
class Structure:
def __init__(self, name: str, composition: List[float], color: str = 'black',
show_label: bool = True, label_font_size: Optional[int] = None):
self.name = name
self.composition = composition