Skip to content

Instantly share code, notes, and snippets.

View andersx's full-sized avatar

Anders Steen Christensen andersx

View GitHub Profile
@andersx
andersx / jlge.py
Last active December 16, 2015 12:38
lennard jones gradient and energy
def calc_energy_and_gradient(X, Y):
""" Calculate the Lennard-Jones energy and
Energy gradient between particles.
X and Y are lists containing x and y
coordinates, respectively.
"""
# Holds the energy and the energy gradient
energy = 0.0
gradient = numpy.zeros((2, len(X)))
@andersx
andersx / solution2.py
Last active December 16, 2015 12:38
2D lennard jones simulation
import numpy
import random
from numba import double # Add this
from numba.decorators import autojit, jit # Add this
#@jit(argtypes=[double[:], double[:]]) # Add this if you want more speed than autojit
@autojit # Add this
def calc_energy_and_gradient(X, Y):
""" Calculate the Lennard-Jones energy and
@andersx
andersx / LJ.f
Created April 27, 2013 12:00
Lennard-Jones in Fortran//F2PY
C THE LENNARD-JONES POTENTIAL, GRADIENT AND THE VIRIAL
subroutine LennardJones(U,box,Epot,F,Vir,N)
cf2py intent(in) U
cf2py intent(in) box
cf2py intent(out) Epot
cf2py intent(out) F
cf2py intent(out) Vir
implicit none
double precision U,Epot,F,box,Vir
integer N
@andersx
andersx / lj.py
Last active December 16, 2015 17:49
Lennard-Jones with Numba and NumPy
import numpy
from numba import double, jit
rc2 = 6.25
rc2i=1.0/rc2
rc6i=rc2i*rc2i*rc2i
ecut=rc6i*(rc6i-1.0)
@jit(argtypes=[double[:,:], double[:]])
def lennardjones(U, box):
@andersx
andersx / Md_velo_verlet.py
Created April 27, 2013 12:06
MD//lennard-jones simulation
import numpy
from forces import lennardjones
# Initialize simulations (code not shown)
temperature = 2.0
n_atoms = 100
rho = 0.01
U = initialize_positions(n_atoms, rho)
box = initialize_box(n_atoms, rho)
#include <sys/time.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
static unsigned int g_seed;
inline int fastrand() {
g_seed = (214013*g_seed+2531011);
return (g_seed>>16)&0x7FFF;
@andersx
andersx / Emin.py
Last active December 20, 2015 03:09 — forked from jhjensen2/Emin.py
# A simple energy minimization program that uses steepest descent
# and a force field to minimize the energy of water in internal coordinates.
# Written by Jan H. Jensen, 2013
def Eandg(rOH,thetaHOH):
""""
Arguments: (internal coordinates of the water molecule)
@andersx
andersx / list.py
Created August 10, 2013 11:27
What bothers me about python
def implementation_1(P):
P = [1, 1]
def implementation_a(P):
P[0] = 1
P[1] = 1
@andersx
andersx / align.py
Last active February 13, 2024 15:27
How to align two PDB structures using the Bio.PDB module in Biopython
# The MIT License
#
# Copyright (c) 2010-2016 Anders S. Christensen
#
# 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:
import pylab
import numpy
import os
# Make a simple plot
x = numpy.arange(1, 100, 1)
y = x**2
pylab.plot(x, y)
# Define a filename (remember the .pdf)