📄 misc.c
字号:
# include "process.h"
float Distance(float a[3], float b[3])
{
float d,tmpx,tmpy,tmpz;
tmpx=(a[0]-b[0])*(a[0]-b[0]);
tmpy=(a[1]-b[1])*(a[1]-b[1]);
tmpz=(a[2]-b[2])*(a[2]-b[2]);
d=sqrt((double)(tmpx+tmpy+tmpz));
return d;
}
float Distance2(float a[3], float b[3])
{
float d2,tmpx,tmpy,tmpz;
tmpx=(a[0]-b[0])*(a[0]-b[0]);
tmpy=(a[1]-b[1])*(a[1]-b[1]);
tmpz=(a[2]-b[2])*(a[2]-b[2]);
d2=tmpx+tmpy+tmpz;
return d2;
}
void Translate_Point(float start[3], float move[3], float end[3])
{
end[0]=start[0]+move[0];
end[1]=start[1]+move[1];
end[2]=start[2]+move[2];
return;
}
void Rotate_Point(float theta, float axis[3], float origin[3],
float start[3], float end[3])
{
float mat[3][3],p[3];
float a,b;
int i,j;
Unify_Vector(axis);
a=sin((double)(theta*3.1416/180.0));
b=cos((double)(theta*3.1416/180.0));
for(i=0;i<=2;i++) end[i]=start[i]-origin[i];
mat[0][0]=axis[0]*axis[0]+(1-axis[0]*axis[0])*b;
mat[1][0]=axis[0]*axis[1]*(1-b)-axis[2]*a;
mat[2][0]=axis[0]*axis[2]*(1-b)+axis[1]*a;
mat[0][1]=axis[0]*axis[1]*(1-b)+axis[2]*a;
mat[1][1]=axis[1]*axis[1]+(1-axis[1]*axis[1])*b;
mat[2][1]=axis[1]*axis[2]*(1-b)-axis[0]*a;
mat[0][2]=axis[0]*axis[2]*(1-b)-axis[1]*a;
mat[1][2]=axis[1]*axis[2]*(1-b)+axis[0]*a;
mat[2][2]=axis[2]*axis[2]+(1-axis[2]*axis[2])*b;
for(i=0;i<=2;i++)
{
p[i]=0.0;
for(j=0;j<=2;j++) p[i]+=(end[j]*mat[j][i]);
}
for(i=0;i<=2;i++) end[i]=p[i]+origin[i];
return;
}
void Cross_Multiply(float v1[3], float v2[3], float result[3])
{
result[0]=v1[1]*v2[2]-v2[1]*v1[2];
result[1]=v1[2]*v2[0]-v2[2]*v1[0];
result[2]=v1[0]*v2[1]-v2[0]*v1[1];
return;
}
float Point_Multiply(float v1[3], float v2[3])
{
float result;
result=v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
return result;
}
float Angle_Of_Two_Vectors(float v1[3], float v2[3])
{
float angle;
float l1,l2,tmp;
l1=sqrt((double)(v1[0]*v1[0]+v1[1]*v1[1]+v1[2]*v1[2]));
l2=sqrt((double)(v2[0]*v2[0]+v2[1]*v2[1]+v2[2]*v2[2]));
tmp=v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2];
angle=acos((double)(tmp/(l1*l2)));
angle=angle/3.1416*180.0;
return angle;
}
float Torsion_Angle(float p1[3], float p2[3], float p3[3], float p4[3])
{
int i;
float angle;
float v12[3],v23[3],v34[3],v1[3],v2[3],v3[3];
for(i=0;i<=2;i++)
{
v12[i]=p2[i]-p1[i];
v23[i]=p3[i]-p2[i];
v34[i]=p4[i]-p3[i];
}
Cross_Multiply(v12,v23,v1);
Cross_Multiply(v23,v34,v2);
angle=Angle_Of_Two_Vectors(v1,v2);
Cross_Multiply(v1,v2,v3);
if((v23[0]/v3[0]>0)||(v23[1]/v3[1]>0)||(v23[2]/v3[2])>0) return angle;
else return -angle;
}
void Unify_Vector(float vect[3])
{
int i;
float d;
d=sqrt((double)(vect[0]*vect[0]+vect[1]*vect[1]+vect[2]*vect[2]));
for(i=0;i<=2;i++) vect[i]/=d;
return;
}
void Set_Random_Number()
{
long seed;
struct tm *ptr;
time_t lt;
lt=time(NULL);
ptr=localtime(<);
seed=10000*ptr->tm_hour+100*ptr->tm_min+ptr->tm_sec;
srand48(seed); // Initialize drand48()
return;
}
char *Get_Time()
{
struct tm *ptr;
time_t lt;
lt=time(NULL);
ptr=localtime(<);
return asctime(ptr);
}
void Get_Sp3_Coordinates(float v1[3], float v2[3], float v3[3], float v4[3])
// v1 and v2 are known vectors while v3 and v4 are desired vectors.
// v1, v2, v3, and v4 are all unified vectors.
{
int i;
float anchor[3], axis[3];
for(i=0;i<3;i++)
{
axis[i]=-(v1[i]+v2[i]);
anchor[i]=0.000;
v3[i]=v4[i]=0.000;
}
Rotate_Point(90.0,axis,anchor,v1,v3);
Rotate_Point(90.0,axis,anchor,v2,v4);
for(i=0;i<3;i++)
{
v3[i]=-v3[i];
v4[i]=-v4[i];
}
return;
}
void Get_Sp2_Coordinates(float v1[3], float v2[3], float v3[3])
// v1 and v2 are known vectors and v3 is the desired vector.
// v1, v2, and v3 are all unified vectors.
{
int i;
for(i=0;i<3;i++)
{
v3[i]=-(v1[i]+v2[i]);
}
Unify_Vector(v3);
return;
}
int Pow(int x, int y)
{
int i,result;
if(y<=0) return 1;
result=1;
for(i=1;i<=y;i++) result*=x;
return result;
}
int Blank_Line_Check(char *line)
{
int i,mark;
int len=0;
len=strlen(line);
if(len<1) return TRUE; // blank line!
mark=0;
for(i=0;i<len;i++)
{
if(line[i]==' ') continue;
else if(line[i]=='\t') continue;
else if(line[i]=='\n') break;
else mark++;
}
if(mark==0) return TRUE; // blank line
else return FALSE; // not a blank line
}
void Memory_Allocation_Error()
{
printf("\n");
printf("Memory allocation error!\n");
printf("Maybe there is not enough memory to run the program.\n");
printf("So vote for another person as the President.\n");
printf("Hope he would increase the budget for education & science.\n");
exit(1);
}
void Openning_File_Error(char *filename)
{
printf("\n");
printf("Error: cannot open the file %s\n", filename);
printf("Please make sure it exists.\n");
exit(1);
}
void Reading_File_Error(char *filename)
{
printf("\n");
printf("Error: something wrong with %s\n", filename);
printf("It may not have the correct format.\n");
printf("Please check this file and try again.\n");
exit(1);
}
void PDB_Format_Error(char *filename)
{
printf("\n");
printf("Error: %s lacks necessary information.\n", filename);
printf("This file may not be in PDB format.\n");
printf("Please check it and try again.\n");
exit(1);
}
void Mol2_Format_Error(char *filename)
{
printf("\n");
printf("Error: %s lacks necessary information.\n", filename);
printf("This file may not be in Mol2 format.\n");
printf("Please check it and try again.\n");
exit(1);
}
void Lig_Format_Error(char *filename)
{
printf("\n");
printf("Error: %s lacks necessary information.\n", filename);
printf("This file may not be in Lig format.\n");
printf("Please check it and try again.\n");
exit(1);
}
void Missing_Parameter_Error(char *name)
{
printf("\n");
printf("Error: You have probably forgot telling me %s.\n", name);
return;
}
void Invalid_Parameter_Error(char *name)
{
printf("\n");
printf("Error: %s has an invalid value.\n", name);
return;
}
void Check_Directory(char *name)
// add the end of '/' to the directory name automatically
{
int len;
len=strlen(name);
if(name[len-1]!='/') strcat(name,"/");
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -