This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def implementation_1(P): | |
P = [1, 1] | |
def implementation_a(P): | |
P[0] = 1 | |
P[1] = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
OlderNewer