Skip to content

Instantly share code, notes, and snippets.

View mjhong0708's full-sized avatar

Minjoon Hong mjhong0708

  • Yonsei University
  • Seoul, Korea
View GitHub Profile
@mjhong0708
mjhong0708 / e0.go
Created December 20, 2023 15:25
Print E0 energy value from VASP calculations
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"regexp"
)
@mjhong0708
mjhong0708 / lineplot.py
Created October 12, 2023 10:41
Draw connected horizontal lines (like free energy diagram)
def lineplot(x, y, length=None, width=1, connection_style="--", ax=None, **kwargs):
if ax is None:
ax = plt.gca()
if length is None:
length = length or (max(x) - min(x)) / len(x) * 0.8
x, y = np.array(x), np.array(y)
xmin, xmax = x - length / 2, x + length / 2
lines = ax.hlines(y=y, xmin=xmin, xmax=xmax, **kwargs)
for i in range(len(x) - 1):
xs, ys = [xmax[i], xmin[i + 1]], [y[i], y[i + 1]]
@mjhong0708
mjhong0708 / msd_calc.py
Last active August 15, 2023 13:06
Fast computation of MSD using jax and jax_md
"""Calculate mean square displacement (MSD) of a given element in a trajectory.
Use jax_md to handle PBC.
"""
from typing import List
import jax
import jax.numpy as jnp
import numpy as np
from ase import Atoms
from jax_md import space
@mjhong0708
mjhong0708 / read_vasp.py
Created August 1, 2023 04:40
read vasp calc
import io
from pathlib import Path
import ase.io
import subprocess as sp
import numpy as np
from ase.calculators.singlepoint import SinglePointCalculator
import re
@mjhong0708
mjhong0708 / farthest_point_sampling.py
Last active April 18, 2023 03:07
Farthest point sampling (FPS) with numpy using arbitrary metric
import numpy as np
from numba import njit
from typing import Any, Callable, Sequence, TypeVar
Point_T = TypeVar("T")
Metric = Callable[[np.ndarray, np.ndarray], float]
@njit
def euclidean_distance(x: np.ndarray, y: np.ndarray) -> float:
dR = x - y
@mjhong0708
mjhong0708 / pycube.py
Created April 5, 2023 04:44
Basic Gaussian cube file handler
import os
import numpy as np
from ase import Atoms
class CubeData:
def __init__(
self,
atoms: Atoms,
origin:np.ndarray,
@mjhong0708
mjhong0708 / pack_molecules.py
Created March 30, 2023 12:16
pack molecules
import ase.build
import ase.data
import ase.geometry
import numpy as np
from ase import Atoms
def compute_radius(atoms: Atoms):
"""Compute the radius of an atom, assuming sphere."""
positions = atoms.get_positions()
@mjhong0708
mjhong0708 / log_fermi_constraint.py
Last active March 28, 2023 00:29
Log Fermi wall potential
import numpy as np
from ase import units
from numba import njit
@njit(fastmath=True)
def log_fermi(positions, radius, temperature, beta):
eps = 1e-9 # small number to avoid instability
dists = np.sqrt(np.sum(positions * positions, axis=1))
exp_term = np.exp(beta * (dists - radius))
@mjhong0708
mjhong0708 / rmsd.py
Last active December 12, 2023 10:07
RMSD by Kabsch algorithm
from typing import Tuple
import torch
Tensor = torch.Tensor
def find_alignment_kabsch(P: Tensor, Q: Tensor) -> Tuple[Tensor, Tensor]:
"""Find alignment using Kabsch algorithm between two sets of points P and Q.
@mjhong0708
mjhong0708 / ase_datapipes.py
Last active March 17, 2023 04:48
Datapipes for dealing with ASE Atoms with pyg
import os
from collections.abc import Sequence
import ase.io
import ase.neighborlist
import numpy as np
import torch
import ase.data
from torch_geometric.data import Data
from torch_geometric.nn import radius_graph