|
/* converter from .dat file, from CSD to .pdb file
Francois Savary, University of Geneva
*/
#include
#include
#include
#include
#include
FILE *open_file(char buffer[101],char type[5]);
char* get_name(char text[]);
char buffer[101],dumm[101],refcode[9],txtinfo[101],symetrypos[101],
radiusvalue[101],nomat[100][6];
long sys,adat,nopr,nrad,nat,nsat,year,cella,cellb,cellc,cellA,cellB,cellC
,preca,precb,precc,precA,precB,precC,nline,nbat;
float x[100],y[100],z[100];
void ortho(float x[100],float y[100],float z[100],long cella,long cellb,
long cellc,long cellA,long cellB,long cellC, long nbat);
void writepdb(char nomat[100][6],float x[100],float y[100],
float z[100], char refcode[9]);
void main(void)
{
register int i,j,k;
char blank[21];
FILE *inp;
strcpy(buffer,get_name("nom input file : "));
inp=open_file(buffer,"r");
strcpy(blank," ");
while (fgets(buffer,100,inp))
{
sscanf(buffer,"%1c",dumm);
if(!(strncmp(dumm,"#",1)))
{
sscanf(buffer+1,"%8c",refcode);
sscanf(buffer+9,"%1c",dumm);
sscanf(dumm,"%ld",&sys);strcpy(dumm,blank);
sscanf(buffer+11,"%6c",dumm);
sscanf(dumm,"%ld",&adat);strcpy(dumm,blank);
sscanf(buffer+38,"%3c",dumm);
sscanf(dumm,"%ld",&nopr);strcpy(dumm,blank);
sscanf(buffer+41,"%3c",dumm);
sscanf(dumm,"%ld",&nrad);strcpy(dumm,blank);
sscanf(buffer+44,"%3c",dumm);
sscanf(dumm,"%ld",&nat);strcpy(dumm,blank);
sscanf(buffer+47,"%3c",dumm);
sscanf(dumm,"%ld",&nsat);strcpy(dumm,blank);
sscanf(buffer+78,"%2c",dumm);
sscanf(dumm,"%ld",&year);strcpy(dumm,blank);
fgets(buffer,100,inp);
sscanf(buffer,"%6c",dumm);
sscanf(dumm,"%ld",&cella);strcpy(dumm,blank);
sscanf(buffer+6,"%6c",dumm);
sscanf(dumm,"%ld",&cellb);strcpy(dumm,blank);
sscanf(buffer+12,"%6c",dumm);
sscanf(dumm,"%ld",&cellc);strcpy(dumm,blank);
sscanf(buffer+18,"%6c",dumm);
sscanf(dumm,"%ld",&cellA);strcpy(dumm,blank);
sscanf(buffer+24,"%6c",dumm);
sscanf(dumm,"%ld",&cellB);strcpy(dumm,blank);
sscanf(buffer+30,"%6c",dumm);
sscanf(dumm,"%ld",&cellC);strcpy(dumm,blank);
sscanf(buffer+36,"%1c",dumm);
sscanf(dumm,"%d",&preca);strcpy(dumm,blank);
sscanf(buffer+37,"%1c",dumm);
sscanf(dumm,"%d",&precb);strcpy(dumm,blank);
sscanf(buffer+38,"%1c",dumm);
sscanf(dumm,"%d",&precc);strcpy(dumm,blank);
sscanf(buffer+39,"%1c",dumm);
sscanf(dumm,"%d",&precA);strcpy(dumm,blank);
sscanf(buffer+40,"%1c",dumm);
sscanf(dumm,"%d",&precB);strcpy(dumm,blank);
sscanf(buffer+41,"%1c",dumm);
sscanf(dumm,"%d",&precC);strcpy(dumm,blank);
fgets(txtinfo,100,inp);
fgets(symetrypos,100,inp);
fgets(radiusvalue,100,inp);
nbat = nat + nsat;
nline = nbat % 3;
if (nline !=0)
{
k= (nbat / 3) + 1;
for (i=0;i < k;i++)
{
j= 3*i;
fgets(buffer,100,inp);
sscanf(buffer,"%5c",nomat+j);
sscanf(buffer+5,"%7c",dumm);
sscanf(dumm,"%f",x+j);strcpy(dumm,blank);
sscanf(buffer+12,"%7c",dumm);
sscanf(dumm,"%f",y+j);strcpy(dumm,blank);
sscanf(buffer+19,"%7c",dumm);
sscanf(dumm,"%f",z+j);strcpy(dumm,blank);
sscanf(buffer+27,"%5c",nomat+j+1);
sscanf(buffer+32,"%7c",dumm);
sscanf(dumm,"%f",x+j+1);strcpy(dumm,blank);
sscanf(buffer+39,"%7c",dumm);
sscanf(dumm,"%f",y+j+1);strcpy(dumm,blank);
sscanf(buffer+46,"%7c",dumm);
sscanf(dumm,"%f",z+j+1);strcpy(dumm,blank);
sscanf(buffer+54,"%5c",nomat+j+2);
sscanf(buffer+59,"%7c",dumm);
sscanf(dumm,"%f",x+j+2);strcpy(dumm,blank);
sscanf(buffer+66,"%7c",dumm);
sscanf(dumm,"%f",y+j+2);strcpy(dumm,blank);
sscanf(buffer+73,"%7c",dumm);
sscanf(dumm,"%f",z+j+2);strcpy(dumm,blank);
}
}
else
{
k= (nbat / 3);
for (i=0;i < k;i++)
{
j= 3*i;
fgets(buffer,100,inp);
sscanf(buffer,"%5c",nomat+j);
sscanf(buffer+5,"%7c",dumm);
sscanf(dumm,"%f",x+j);strcpy(dumm,blank);
sscanf(buffer+12,"%7c",dumm);
sscanf(dumm,"%f",y+j);strcpy(dumm,blank);
sscanf(buffer+19,"%7c",dumm);
sscanf(dumm,"%f",z+j);strcpy(dumm,blank);
sscanf(buffer+27,"%5c",nomat+j+1);
sscanf(buffer+32,"%7c",dumm);
sscanf(dumm,"%f",x+j+1);strcpy(dumm,blank);
sscanf(buffer+39,"%7c",dumm);
sscanf(dumm,"%f",y+j+1);strcpy(dumm,blank);
sscanf(buffer+46,"%7c",dumm);
sscanf(dumm,"%f",z+j+1);strcpy(dumm,blank);
sscanf(buffer+54,"%5c",nomat+j+2);
sscanf(buffer+59,"%7c",dumm);
sscanf(dumm,"%f",x+j+2);strcpy(dumm,blank);
sscanf(buffer+66,"%7c",dumm);
sscanf(dumm,"%f",y+j+2);strcpy(dumm,blank);
sscanf(buffer+73,"%7c",dumm);
sscanf(dumm,"%f",z+j+2);strcpy(dumm,blank);
}
}
ortho(x,y,z,cella,cellb,cellc,cellA,cellB,cellC,nbat);
writepdb(nomat ,x,y,z,refcode);
}
}
fclose(inp);
}
void ortho(float x[100],float y[100],float z[100],long cella,long cellb,
long cellc,long cellA,long cellB,long cellC, long nbat)
{
register int i;
float alp,bet,gam,cosa,cosb,cosg,sing,q,p,degrad,precaf,precbf,preccf;
degrad = 1/57.29578;
alp = cellA*exp(precA*log(10)*-1)*degrad;
bet = cellB*degrad*exp(precB*log(10)*-1);
gam = cellC*degrad*exp(precC*log(10)*-1);
cosa = cos(alp);
cosb = cos(bet);
cosg = cos(gam);
sing = sin(gam);
q = (cosa-cosb*cosg) / sing;
p = sqrt(1.-cosb*cosb-q*q);
precaf=exp(preca*(-1*log(10)));
precbf=exp(precb*(-1*log(10)));
preccf=exp(precc*(-1*log(10)));
for (i=0;i
|