|
/*********************************************************************************************************************************************/
/* */
/* This C program is writted by Shaozheng Zhang in Quzhou University, Zhejiang. */
/* */
/*********************************************************************************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define pi 3.1415926
#define maxcell 100
#define debug 1
struct coordinate
{
char a,b;
float x,y,z;
};
int main()
{
//Input the basic parameters of the stripe and generating nanotube. xyz molecular format is accepted.
printf("Length and number of a stripe to construct one nanotube:\n");
float l_stripe,r_tube;
int n_stripe;
scanf("%f%d",&l_stripe,&n_stripe);
r_tube=n_stripe*l_stripe/(2.0*pi);
#ifdef debug
printf("the length of stripe and the number of stripe to construct one nanotube:%f %d\n",l_stripe,n_stripe);
printf("The diameter of the nanotube:%f\n",r_tube);
#endif
//输入纳米带的数据结构,采用.xyz文件的格式。
struct coordinate cell[maxcell];
printf("Input the location of xyz file:\n");
char structure[100];
scanf("%s",structure);
FILE *fp;
if((fp=fopen(structure,"r"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
int n_atom;
char description[100];
fscanf(fp,"%d\n",&n_atom);
fscanf(fp,"%s\n",description);
#ifdef debug
printf("the number of atoms in the stripe:%d\n",n_atom);
printf("Description of the system:%s\n",description);
#endif
int cycle;
for(cycle=0;cycle<n_atom;cycle++)
fscanf(fp,"%c%c%f%f%f\n",&(cell[cycle].a),&(cell[cycle].b),&(cell[cycle].x),&(cell[cycle].y),&(cell[cycle].z));
#ifdef debug
for(cycle=0;cycle<n_atom;cycle++)
printf("%c%c %f %f %f\n",cell[cycle].a,cell[cycle].b,cell[cycle].x,cell[cycle].y,cell[cycle].z);
#endif
fclose(fp);
//Output the structure of nanotube which rolls from the input stripe.
printf("Nanotube coordinate Section:\n");
printf("%d\n",n_atom*n_stripe);
printf("%s\n",description);
int roll;
float reradius,delta,re_x,re_y,re_z;
for(roll=0;roll<n_stripe;roll++)
for(cycle=0;cycle<n_atom;cycle++)
{
reradius=r_tube+cell[cycle].z;
delta=(cell[cycle].x+l_stripe*roll)/reradius;
re_x=reradius*sin(delta);
re_y=cell[cycle].y;
re_z=reradius*cos(delta);
printf("%c%c %f %f %f\n",cell[cycle].a,cell[cycle].b,re_x,re_y,re_z);
}
}
|
评分 Rate
-
查看全部评分 View all ratings
|