Skip to content

Instantly share code, notes, and snippets.

@kwyn
Created May 9, 2016 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwyn/ca6e47876d61837263ec76c66f3235da to your computer and use it in GitHub Desktop.
Save kwyn/ca6e47876d61837263ec76c66f3235da to your computer and use it in GitHub Desktop.
Carve a nanospring out of a 3d point file
BEGIN{
#define PI for program
PI=3.14159;
#define radius of spring form, helical body radius
r=6;
#define pitch
p=7;
b= p/(2*PI);
#define diameter of spring wire and radius, cross-sectional thickness
d=4;
radius=d/2;
print "Atoms"
}
#the following is a search function without a defined search term
#this creates a function that will check every record in the target file
#First we will define a function with which you want the spring to follow in terms of x and y dependent on z ($3).
#In this case we will use a simple spring which follows the parameters defined int he BEGIN section
{
t=$5/b;
x=r*cos(t);
y=r*sin(t);
#this checks the target points distance from the function point at target locations z value.
#if it is less than or equal to the desired radius, then we keep the point for the new file
if( dist(x,y,$3,$4) <= radius )
{
if( $2 == 1 )
{
printf("%s %f %f %f\n", "Si", ($3+10)*7.16, ($4+10)*7.16, ($5+10)*7.16);
}
else if ( $2 == 2 )
{
printf("%s %f %f %f\n", "O", ($3+10)*7.16, ($4+10)*7.16, ($5+10)*7.16);
}
}
}
function dist(x1,y1,x2,y2) { return sqrt( (x1-x2)^2 + (y1-y2)^2 ) }
function atan(x) {return atan2(x,1)}
@kwyn
Copy link
Author

kwyn commented Jul 27, 2017

From that one time when I was a grad student and didn't know that python existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment