Skip to content

jesperschmidthansen/molsim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

376 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

molsim - Molecular dynamics with GNU Octave

molsim supports simulations of

  • simple Lennard-Jones systems,
  • molecular systems with bond, angle, and torsion potentials,
  • confined flow systems, eg., Couette and Poiseuille flows,
  • charged systems using shifted force,
  • and more ...

Installation

At the Octave prompt simply use the command

 
  >> pkg install "https://github.com/jesperschmidthansen/molsim/archive/refs/tags/v<version>.tar.gz"
  

where <version> is the version number.

Examples

Checkout the project example folder

Contribution

I encourage anyone who uses or plans to use molsim to submit problematic issues - this includes issues regarding the documentation. I also welcome contributions to the code for the project, whether it is core features or post simulation data analysis programs.

Why MEX?

GNU Octave offers a great C++ interface with the dynamically linked functions (DLDs). However, my experience is that the pure C MEX interface to produces faster running binaries. This is perhaps due to DLD's call-by-value interface giving an additional copying overhead.

Test: The functions below shows a DLD and a MEX version of a function that calculates the sum of an array and updates the array with a number; this is a relevant task in molecular dynamics.

DLD msum_oct.cpp MEX msum_mex.c

#include <octave/oct.h>

DEFUN_DLD(msum_oct, args, ,""){
   octave_value_list retval;
   Matrix A(args(0).array_value());
   int nrows = A.dim1();
   int ncols = A.dim2();

   double *Aptr = A.fortran_vec();

   double sum=0.0f;
   for (int n=0; n<nrows; n++) {
     for (int m=0; m<ncols; m++) {
         int idx = m*nrows + n;
         sum += Aptr[idx];
         Aptr[idx] += 1.0;
      }
   }

   retval.append(sum);
   retval.append(A);
   return retval;
}

 #include "mex.h"
 
 void mexFunction(int nlhs, mxArray *plhs[], 
              int nrhs, const mxArray *prhs[]) {
 
     double *A = mxGetPr(prhs[0]);
     int nrows = mxGetM(prhs[0]);
     int ncols = mxGetN(prhs[0]);
 
     double sum=0.0f;
     for (int n=0; n<nrows; n++) {
        for (int m=0; m<ncols; m++) {
           int idx = m*nrows + n;
           sum += A[idx];
           A[idx] += 1.0;
        }
      }
 
      plhs[0] = mxCreateDoubleScalar(sum);
 }

 
 

The functions are compiled with or without -Ofast flag. Timing is done by


>> A=randn(1000, 1000); s=zeros(40, 1);
>> for n=1:40; tic(); [sumA A]= msum_oct(A); s(n) = toc(); end;
>> sum(s), mean(s), std(s)
>> for n=1:40; tic(); sumA = msum_oct(A); s(n) = toc(); end;
>> sum(s), mean(s), std(s)
This shows a speed-up of a factor of approximately 2 on the computers I have tried. The actual speed-up depends on the array size, hardware, optimization flags, etc.

Acknowledgement

John Donoghue for the post_install.m script.

To-do

Octave now supports object oriented programming. molsim is under complete reconstructed to benefit from this. Matlab compatibility is not a priority.
  • Feature: Barostate
  • Feature: Standard run time sample classes
  • Feature: Electrostatic interactions using the Wolf scheme
  • Feature: A set of molecular and atomic configurations
  • Feature: Molecular class for infrastructure (contained in molsim class)
  • Feature: DPD support (initiated)
  • Feature: A doc/ directory (initially just a reference to examples/ directory?)
  • Revision: Class properties access. Should these be different from public?
  • Revision: Define class constants with correct properties (Constant=true)
  • Revision: All classes should have a disp method
  • Revision: Consider whether methods should have specified properties
  • Revision: Naming conventions (at the moment none)
  • Revision: ms_molconfig is a mess...
  • Revision: Thermostating is hand-held at the moment, should be fixed

About

GNU Octave package for molecular dynamics simulations

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors