For instance, I've been simulating some graphitic crystallites and part of the analysis includes analyzing the motion of the individual crystallite planes.
This is how easy that is:
(Note: it appears the horizontal scroll bar for this code is hidden by default for OS X browsers.)
eigenvalues = require 'eigenvalues.js'
regressCoordinatesToNormal = (coords) ->
min = (array) ->
array.reduce ((x, y, i) -> if x.val < y then x else {index: i, val: y}), {index: null, val: Infinity}
centerOfMass = (coords) ->
coords.reduce ((x, y) -> (x[i] + (y[i] / coords.length) for v, i in y)), [0, 0, 0]
normalUnitVector = (coords) ->
c = centerOfMass coords
matrix = for row in [0..2]
for col in [0..2]
((coord[row] - c[row]) * (coord[col] - c[col]) for coord in coords).reduce (x, y) -> x + y
results = eigenvalues.calculateEigenvalues matrix
results.eigenvectors[min(results.real).index]
normalUnitVector coords
This code just takes in a list of coordinates and performs a linear plane regression on them to return the normal vector of the plane. Then if I want the vertical distance between two planes of atoms (these are circular planes that kind of wobble around), then it's just:
normals = (regressCoordinatesToNormal coords for coords in planes)
planeToPlaneVector = distanceVector planeCenterOfMass[0], planeCenterOfMass[1]
projectionDistance = dotProduct planeToPlaneVector, normals[0]
I left out some details, but you can get the gist of it.
I can't really comment on that actually. For some reason, of all the programming languages I know, I never bothered to learn Python. If you need to make sure your results are 100% accurate then I would recommend a library that has been designed and tested by others, so NumPy would probably be better than creating your own routines. I do really like the clean syntax and support for functional(-ish) programming that CoffeeScript provides though.
This is how easy that is:
(Note: it appears the horizontal scroll bar for this code is hidden by default for OS X browsers.)
This code just takes in a list of coordinates and performs a linear plane regression on them to return the normal vector of the plane. Then if I want the vertical distance between two planes of atoms (these are circular planes that kind of wobble around), then it's just: I left out some details, but you can get the gist of it.