/* C language code File HelixMorph.c, written by Steven Andrews, 2004 to 2007 This code is in the public domain. It is not copyrighted and may not be copyrighted. This code is supplementary material for an article that was been submitted to the Biophysical Journal titled "A mechanical explanation for cytoskeletal rings and helices in bacteria" by Steven S. Andrews and Adam P. Arkin. It was submitted in 2006 and resubmitted in 2007. This file is a free-standing C program that should be able to run as it is, although it also requires some of the standard C libraries. As written, the user is prompted to enter the standard yaw, pitch, and roll angles. These are the products of the preferred curvatures and the sphere or cylinder radius (the most interesting region of parameter space is: -0.75 < yaw < 0.75, -1.25 < pitch < 0.25, -0.75 < roll < 0.75). Output are the energy densities for the polymer on a sphere, cylinder, and rod-shaped cell and some additional properties for these structures (circle circumference, absolute helix angle, or loop length). These are found both for minimum total energy polymers and for minimum growing energy polymers (see the Biophys. J. paper). Likely more useful than this complete program are the two core functions called Morphology1 and Morphology2. They compute the results that are are accessed via the simple text interface. A little additional code makes it possible to compute phase diagrams or to search parameter space for particular morphologies. */ #include #include #include #define intrand(n) (rand()%(n)) #define unirand(lo,hi) ((float)rand()/RAND_MAX*((hi)-(lo))+(lo)) #define MOD2PI(A) ((A)<=-PI?(A)+2.0*PI:(A)>PI?(A)-2.0*PI:(A)) #define PI 3.14159265358979323846 #define sign(x) ((x==0)?0:(x>0)?1:-1) double FourierSum(double *a,double *b,int n,double l,double x); double AngleEnergy(int dim,double *ak,double *astd,double *a,double thk); double AngleCylForce(double *ak,double *astd,double yaw,double b,double thk,double lrratio); char Morphology1(double *ak,double *astd,double radius,double length,double *results,char surface,double bstep); char Morphology2(double *ak,double *astd,double radius,double *results,char surface,double bstep); /* This calculates the sum of a Fourier series for a function which is periodic on 2l (-l to l, or 0 to 2l, or any other interval). The sum is defined by: y = a_0/2 + Sum from j=1 to n-1 of [a_j*cos(j*PI*x/l) + b_j*(j*PI*x/l)] The parameters in the equation are exactly as they are in the function call. Note that b[0] is completely ignored and that the sum goes to n-1 rather than to n, where the latter is the standard math convention. */ double FourierSum(double *a,double *b,int n,double l,double x) { double sum; int j; sum=a[0]/2; for(j=1;j helix energyc=energybest; b=bbest; if(b>PI) b-=PI; valuec=b; } else { // F!=0 => loop numer=denom=0; for(b=bstep/2;b