Пример #1
0
/******************* get_alt_rms_res(residue *r, int xs, int xt) *****************/
double get_alt_rms_res(residue *r, int xs, int xt){
int ai=0;
double RMS=0;
coord_3D c;

if(xt<0){mywhine("get_alt_rms_res: target coord cannot be main set");}
if(xs<0){mywhine("get_alt_rms_res: main set source coords not written yet");}
for(ai=0;ai<r[0].na;ai++){
	c=subtract_coord(r[0].a[ai].xa[xs],r[0].a[ai].xa[xt]);
	RMS+=c.i*c.i+c.j*c.j+c.k*c.k;
	}
RMS/=r[0].na;
RMS=sqrt(RMS);
return RMS;
}
Пример #2
0
void set_residue_atom_nodes_from_bonds(residue *r)
{
int ai,finished=0;
char ensisame='y';
r[0].aT=(atom_node*)calloc(r[0].na,sizeof(atom_node));
for(ai=0;ai<r[0].na;ai++) 
    { 
    r[0].a[ai].rTi=-ai-1;
    r[0].aT[ai].isorigin='N';
    r[0].aT[ai].ID=copy_moli_to_ensi(r[0].a[ai].moli);
    r[0].aT[ai].ID.i=ai;
    if(ai>0)
        {
        ensisame=is_consistent_ensi_ensi(r[0].aT[ai].ID,r[0].aT[ai-1].ID);
        if(ensisame!='n')
            {
            mywhine("The atom molindexes are not unique in set_residue_atom_nodes_from_bonds.\n");
            }
        }
    }
r[0].aT[0].isorigin='Y';
if(r[0].na==1) 
    {
    r[0].a[0].rTi=0;
    return;
    }
// r[0].aT[0].isorigin='Y'; OG moved it up.
//printf("Set r[0].aT[0].isorigin='Y' for residue %d\n",r[0].n);
finished = follow_residue_atom_nodes_from_bonds(r, 0, &r[0].a[0]);
return;
}
Пример #3
0
/*
    The  next two functions set the connection tree (m.rT) at the
        residue level (sets bonding between residues).  It uses r.rb
        so see also set_molecule_residue_molbonds().
*/
void set_molecule_residue_nodes_from_bonds(molecule *m)
{
int ri,finished;
char ensisame='y';
m[0].rT=(residue_node*)calloc(m[0].nr,sizeof(residue_node));
for(ri=0;ri<m[0].nr;ri++) 
    { 
    m[0].r[ri].mTi=-ri-1;
    //printf("m[0].r[%d].mTi=%d,m[[0].r[%d].n=%d\n",ri, m[0].r[ri].mTi,ri,m[0].r[ri].n);
    //printf("m[0][0].r[%d].nrb=%d,m[0][0].r[%d].n=%d\n",ri,m[0].r[ri].nrb,ri,m[0].r[ri].n);
    m[0].rT[ri].isorigin='N';
    m[0].rT[ri].ID=copy_moli_to_ensi(m[0].r[ri].moli);
    m[0].rT[ri].ID.i=ri;
    if(ri>0)
        {
        ensisame=is_consistent_ensi_ensi(m[0].rT[ri].ID,m[0].rT[ri-1].ID);
        if(ensisame!='n')
            {
            mywhine("The residue molindexes are not unique in set_molecule_residue_nodes_from_bonds.\n");
            }
        }
    }
if(m[0].nr==1) 
    {
    m[0].r[0].mTi=0;
    return;
    }
m[0].rT[0].isorigin='Y';
finished = follow_molecule_residue_nodes_from_bonds(m, 0, &m[0].r[0]);
return;
}
Пример #4
0
/******************* get_alt_rms_mol(molecule *m, int xs, int xt) *****************/
double get_alt_rms_mol(molecule *m, int xs, int xt){
int ai=0,ri=0,nat=0;
double RMS=0;
coord_3D c;

if(xt<0){mywhine("get_alt_rms_mol: target coord cannot be main set");}
if(xs<0){mywhine("get_alt_rms_mol: main set source coords not written yet");}

for(ri=0;ri<m[0].nr;ri++){
	nat+=m[0].r[ri].na;
	for(ai=0;ai<m[0].r[ri].na;ai++){
		c=subtract_coord(m[0].r[ri].a[ai].xa[xs],m[0].r[ri].a[ai].xa[xt]);
		RMS+=c.i*c.i+c.j*c.j+c.k*c.k;
	}}
RMS/=nat;
RMS=sqrt(RMS);
return RMS;
}
Пример #5
0
/** The purpose of this function is to follow atoms recursively through
 * atom-level bonding until all are seen. 
 */
void follow_molecule_atom_molbonds_for_contree(molecule *m, molindex mi){
int t=m[0].r[mi.r].a[mi.a].mTi, /* the tree index */
	ii=0, /* local molbond index of incoming atom */
	rbi=0, /* convenience holder for local rbi */
	mbi=0; /* counter for molbonds */ 
molindex fi; /* convenience molindex to follow */

/* If this atom has been seen in the tree, just go back. */
if(m[0].aT[t].rbi!=-1){return;};

/* Mark this atom seen in tree */
if(m[0].aT[t].ni>0){/* if there is an incoming bond */
	rbi=m[0].aT[t].rbi=m[0].aT[t].i[0].i; /* set the index to the first one */
	/* Identify the incoming bond */
	ii=-1;
	for(mbi=0;mbi<m[0].r[mi.r].a[mi.a].nmb;mbi+++){
		fi=m[0].r[mi.r].a[mi.a].mb[mbi].t;
		if(m[0].r[fi.r].a[fi.a].moli.m!=m[0].aT[t].ensi.m){
			mywhine("molecule indices do not match in follow_molecule_atom_molbonds_for_contree");}
		if((fi.r==m[0].aT[rbi].ensi.r)&&(fi.a==m[0].aT[rbi].ensi.a)){ii=mbi;}
		}
	if(ii==-1){mywhine("did not find bond match in follow_molecule_atom_molbonds_for_contree.");}
	} 
Пример #6
0
void read_prep(molecule *M, fileset F, types *TYP){
int rpa=0,stopflag=1,rpuse=0,rpsz=0,rpbins=0;
char line[501];
ambermprepinfo *amp;
fpos_t f_linestart;

M[0].nVP=1;
amp=(ambermprepinfo*)calloc(1,sizeof(ambermprepinfo));
F.F=myfreopen(F.N,"r",F.F); // don't depend on calling function to have opened
amp[0].FN=strdup(F.N);
fgets(line,500,F.F);
sscanf(line,"%d %d %d",&amp[0].IDBGEN,&amp[0].IREST,&amp[0].ITYPF);
fgets(line,500,F.F);
amp[0].NAMDBF=strdup(line);
M[0].VP=amp;

rpuse=malloc_usable_size(M[0].r);
rpsz=sizeof(residue);
rpbins=rpuse/rpsz;
if(rpbins<1){mywhine("read_prep: no space in residue -- is molecule not initialized?");}

//printf("about to read through the file. Current line is\n\t>>%s<<\n",line);
fgetpos(F.F,&f_linestart);// get current position
while(fgets(line,500,F.F)!=NULL){// while not end of file
//printf("\treading a line ...  line is\n>>%s<<\n",line);
	stopflag=1;
	for(rpa=0;rpa<strlen(line);rpa++){// if the first word is not "STOP" (and only that??)
		if((line[rpa]!='\t')&&(line[rpa]!=' ')){
//printf("rpa is %d and line[rpa] is >>%c<< and strlen(line) is %d\n",rpa,line[rpa],strlen(line));
			if(rpa+4>strlen(line)){break;}
			else{ 
				if((line[rpa]=='S')&&(line[rpa+1]=='T')&&(line[rpa+2]=='O')&&(line[rpa+3]=='P')){ 
					stopflag=0;
					}
				break;
				}
			}
		}
//printf("stopflag is %d\n",stopflag);
	if(stopflag==0){break;} // break loop
//printf("about to allocate space for the residue...\n");
	M[0].nr++;// allocate new memory for a residue
	M[0].r=(residue*)realloc(M[0].r,M[0].nr*sizeof(residue));
	fsetpos(F.F,&f_linestart); // rewind to start of line
	M[0].r[M[0].nr-1]=read_prepres(F,TYP);// call read_prepres to read in the residue information
	fgetpos(F.F,&f_linestart);// get current position 
	} // end while not end of file
return;
}
Пример #7
0
/*
    This function sets molbonds at the residue level (r.rb).
*/
void set_molecule_residue_molbonds(molecule *m)
{
int ri,ai,bi,this_b;

for(ri=0;ri<m[0].nr;ri++)
    {
    /*
    Count the number of interresidue bonds.
    */
    m[0].r[ri].nrb=0;
    for(ai=0;ai<m[0].r[ri].na;ai++)
        {
        for(bi=0;bi<m[0].r[ri].a[ai].nmb;bi++)
            {
            if(m[0].r[ri].a[ai].mb[bi].s.r!=m[0].r[ri].a[ai].mb[bi].t.r) {
	        m[0].r[ri].nrb++;
               // printf("incremented m[0].r[%d].nrb=%d\n",ri,m[0].r[ri].nrb);
		}
            }
        }
    m[0].r[ri].rb=(molbond*)calloc(m[0].r[ri].nrb,sizeof(molbond));
    this_b=0;
    for(ai=0;ai<m[0].r[ri].na;ai++)
        {
//printf("This atom is %s\n",m[0].r[ri].a[ai].N);
        for(bi=0;bi<m[0].r[ri].a[ai].nmb;bi++)
            {
/*printf("\tm[0].r[%d].a[%d].mb[%d].s.r = %d\n",ri,ai,bi,m[0].r[ri].a[ai].mb[bi].s.r);*/
/*printf("\tm[0].r[%d].a[%d].mb[%d].t.r = %d\n",ri,ai,bi,m[0].r[ri].a[ai].mb[bi].t.r);*/
            if(m[0].r[ri].a[ai].mb[bi].s.r!=m[0].r[ri].a[ai].mb[bi].t.r)
                {
                m[0].r[ri].rb[this_b]=m[0].r[ri].a[ai].mb[bi];
/*printf("\t this_b is %d\n",this_b);*/
/*printf("\tfound molbond for %s from %d-%d-%d-%d to %d-%d-%d-%d\n",m[0].r[ri].N,\
m[0].r[ri].a[ai].mb[bi].s.i,m[0].r[ri].a[ai].mb[bi].s.m,m[0].r[ri].a[ai].mb[bi].s.r,m[0].r[ri].a[ai].mb[bi].s.a,\
m[0].r[ri].a[ai].mb[bi].t.i,m[0].r[ri].a[ai].mb[bi].t.m,m[0].r[ri].a[ai].mb[bi].t.r,m[0].r[ri].a[ai].mb[bi].t.a);*/
/*printf("\tsetting it to residue level as %d-%d-%d-%d to %d-%d-%d-%d\n",\
m[0].r[ri].rb[this_b].s.i,m[0].r[ri].rb[this_b].s.m,m[0].r[ri].rb[this_b].s.r,m[0].r[ri].rb[this_b].s.a,\
m[0].r[ri].rb[this_b].t.i,m[0].r[ri].rb[this_b].t.m,m[0].r[ri].rb[this_b].t.r,m[0].r[ri].rb[this_b].t.a);*/
                this_b++;

                }
            }
        if(this_b>m[0].r[ri].nrb){mywhine("this_b>m[0].r[ri].nrb in set_molecule_residue_molbonds.");}
        }
    }

return;
}
Пример #8
0
void set_molecule_atom_nodes_from_bonds(molecule *m)
{
int ri,ai,na=0,aai,finished=0;
char ensisame='y'; 

for(ri=0;ri<m[0].nr;ri++)
    {
    na+=m[0].r[ri].na;
    }
if((m[0].na>0)&&(m[0].na!=na))
    {
    printf("\nWarning:  m.na != sum of all r.na in set_molecule_atom_nodes_from_bonds\n");
    printf("            Setting those to be equal.  Hope that\'s ok.\n");
    }
m[0].na=na;
m[0].aT=(atom_node*)calloc(m[0].na,sizeof(atom_node));
aai=0;
for(ri=0;ri<m[0].nr;ri++) 
    { 
for(ai=0;ai<m[0].r[ri].na;ai++) 
    { 
    m[0].r[ri].a[ai].mTi=-aai-1;
    m[0].aT[aai].isorigin='N';
    m[0].aT[aai].ID=copy_moli_to_ensi(m[0].r[ri].a[ai].moli);
    m[0].aT[aai].ID.i=aai;
    /*  The following isn't a comprehensive check.  Just a spot-check. */
    if(aai>0)
        {
        ensisame=is_consistent_ensi_ensi(m[0].aT[aai].ID,m[0].aT[aai-1].ID);
        if(ensisame!='n')
            {
            mywhine("The atom molindexes are not unique in set_molecule_atom_nodes_from_bonds.\n");
            }
        }
    aai++;
    }
    }
m[0].aT[0].isorigin='Y'; // OG put here for ROH. May alter later function instead
if(m[0].na==1) 
    {
    m[0].r[0].a[0].mTi=0;
    return;
    }
//m[0].aT[0].isorigin='Y';
finished = follow_molecule_atom_nodes_from_bonds(m, 0, &m[0].r[0].a[0]);
return;
}
Пример #9
0
atom read_prepatom(const char *line, types *TYP){
amberaprepinfo *aap;
atom A;
char N[21],T[21],C[21]; // if any entry is longer than 21 chars, something is wrong...
char whinetext[201]; // error message text
int raa=0;

// Most of this will go into an amberaprepinfo structure.
// Some bits also go into an atom structure
// Here is a typical prep-file atom line:
//	>> 4 C1   CG  M  3  2  1  1.400   113.9      60.0     0.4780<<
// 	   1  2   3   4  5  6  7    8      9          10       11
//	The atom structure bits:
//	1: A.n
//	2: A.N=strdup(2)
//	3: A.T=strdup(3)  --and-- A.t=number for type 3

aap=(amberaprepinfo*)calloc(1,sizeof(amberaprepinfo));

sscanf(line,"%d %s %s %s %d %d %d %lf %lf %lf %lf",\
	&aap[0].I,N,T,C,&aap[0].NA,&aap[0].NB,&aap[0].NC,&aap[0].R,&aap[0].THETA,&aap[0].PHI,&aap[0].CHG);
A.N=strdup(N);
aap[0].IGRAPH=strdup(N);
A.T=strdup(T);
aap[0].ISYMBL=strdup(T);
aap[0].ITREE=strdup(C);
A.n=aap[0].I-3; 
// set the atom's type according to the data in TYP
A.t=-1;
for(raa=0;raa<TYP[0].na;raa++){
//printf("TYP[0].a[raa].N is >>%s<< ; A.T is >>%s<<\n",TYP[0].a[raa].N,A.T);
	if(strcmp(TYP[0].a[raa].N,A.T)==0){ 
		A.t=raa; 
		break;} }
if(A.t==-1){
	sprintf(whinetext,"read_prepatom:\n\tMatch not found for atom type %s.  The prep file line follows:\n\n%s\n\n",A.T,line);
	mywhine(whinetext);
	}
//printf("The entire line is:\n");
/*printf("%d %s %s %s %d %d %d %f %f %f %f\n",aap[0].I,aap[0].IGRAPH,aap[0].ISYMBL,\
        aap[0].ITREE,aap[0].NA,aap[0].NB,aap[0].NC,aap[0].R,aap[0].THETA,aap[0].PHI,aap[0].CHG);*/
//
A.nVP=1;
A.VP=aap;

return A;
}
Пример #10
0
dockinfo *load_dlg_mol(fileset F,types *T){

int a=0,b=0,ndock=0,ai=0,di=0,ri=0,ti=0,distVer=0,startRanking=0;
int runNum[1], dumi[1];
int *AI,nat=0,localdebug=1;
char line[501],dum1[50]; // maybe no lines longer than 500...
char whinetext[501]; char* ptr;
double xl=0,xh=0,yl=0,yh=0,zl=0,zh=0,fullVer=0;
double dumd[1];
atype* AT = T[0].a;
dockinfo *D;
fileslurp sl;
molecule alt;
//dumd=(double*)calloc(1,sizeof(double));
//dumi=(int*)calloc(1,sizeof(int));
//runNum=(int*)calloc(1,sizeof(int));
//First, the function determines which version of Autodock generated the file
while(fgets(line,500,F.F)!=NULL){
	//Find the line with the Autodock version on is
	if(strstr(line,"AutoDock")!=NULL){
		ptr = strstr(line,"AutoDock");
                ptr = ptr+9;
		distVer = sscanf(ptr,"%lf",&fullVer);
		if(distVer!=1){read_eek("location of Autodock version",F.N);}
		distVer = floor(fullVer);
		break;
	}
}
//If this version has not been taken into account, then throw an error
if(distVer != 3 && distVer != 4){
	mywhine("Docking log file does not match known versions.  Must be either version 3.X or 4.X");}

if(localdebug>0){printf("load_dlg_mol: At top.\n");}
//Initialize the dockinfo, and find the input pdb in the file
D=(dockinfo*)calloc(1,sizeof(dockinfo));
D[0].DOCK_PROGRAM = strdup("Autodock");	//Set autodock as the name of the docking program
D[0].VERSION = (char*)calloc(5,sizeof(char));
D[0].numClusters=0;
sprintf(D[0].VERSION,"%.2lf",fullVer);	//Set the version number
rewind(F.F);
sl = slurp_file(F);			//Called from fileslurp.c
sl = isolateInputPDB(sl);		//Called from load_pdb.c
D[0].M = load_pdb_from_slurp(sl);	//Called from load_pdb.c
//Set the boundaries for the box to the values of the first atom
//So comparisons can be made later
xl=xh=D[0].M.r[0].a[0].x.i;
yl=yh=D[0].M.r[0].a[0].x.j;
zl=zh=D[0].M.r[0].a[0].x.k;
for(ri = 0; ri < D[0].M.nr; ri++){
	for(ai = 0; ai < D[0].M.r[ri].na; ai++){
		for(ti = 0; ti < T[0].na; ti++)//For finding the atype that matches
			if(D[0].M.r[ri].a[ai].N[0]==AT[ti].NT[0])//the atom
				break;
		//For finding the boundaries of the box
		if(xl>D[0].M.r[ri].a[ai].x.i){xl=D[0].M.r[ri].a[ai].x.i;}
		if(xh<D[0].M.r[ri].a[ai].x.i){xh=D[0].M.r[ri].a[ai].x.i;}
		if(yl>D[0].M.r[ri].a[ai].x.j){yl=D[0].M.r[ri].a[ai].x.j;}
		if(yh<D[0].M.r[ri].a[ai].x.j){yh=D[0].M.r[ri].a[ai].x.j;}
		if(zl>D[0].M.r[ri].a[ai].x.k){zl=D[0].M.r[ri].a[ai].x.k;}
		if(zh<D[0].M.r[ri].a[ai].x.k){zh=D[0].M.r[ri].a[ai].x.k;}
		D[0].M.r[ri].a[ai].t = ti;
		D[0].M.r[ri].m+=AT[ti].m; // add to residue MW
		D[0].M.r[ri].COM.i+=D[0].M.r[ri].a[ai].x.i*AT[ti].m; // residue COM
		D[0].M.r[ri].COM.j+=D[0].M.r[ri].a[ai].x.j*AT[ti].m;
		D[0].M.r[ri].COM.k+=D[0].M.r[ri].a[ai].x.k*AT[ti].m;
		D[0].M.m+=AT[ti].m; // add to molecule MW
		D[0].M.COM.i+=D[0].M.r[ri].a[ai].x.i*AT[ti].m; // molecule COM
		D[0].M.COM.j+=D[0].M.r[ri].a[ai].x.j*AT[ti].m;
		D[0].M.COM.k+=D[0].M.r[ri].a[ai].x.k*AT[ti].m;
	}//End loop through all atoms in this residue
	nat += D[0].M.r[ri].na;//Generates overall atom total
}//End loop through all residues in this molecule



// ONE DAY:  add in any missing atoms
// -- open the prep database
// -- scan for the residue name
// -- record number/name/type of atoms
// -- mark as present or not, etc...
//
if(localdebug>0){printf("load_dlg_mol: About to start COM calc.\n");}
// finish COM calculation for molecule
D[0].M.COM.i/=D[0].M.m;
D[0].M.COM.j/=D[0].M.m;
D[0].M.COM.k/=D[0].M.m;
//printf("center of mass (MW=%20.12e) is at: %20.12e %20.12e %20.12e \n",D[0].M.COM.i,D[0].M.COM.j,D[0].M.COM.k);
// also for the residues -- plus record atom number correlation
if(localdebug>0){printf("load_dlg_mol: continuing residue-level COM calc.\n");}
AI=(int*)calloc(nat,sizeof(int));
for(a=0;a<D[0].M.nr;a++){ 
	if(D[0].M.r[a].na==0){
		sprintf(whinetext,"lack of atoms in residue >>%s<<, number %d",D[0].M.r[a].N,(a+1));
		read_eek(whinetext,F.N);
		}
	D[0].M.r[a].COM.i/=D[0].M.r[a].m;
	D[0].M.r[a].COM.j/=D[0].M.r[a].m;
	D[0].M.r[a].COM.k/=D[0].M.r[a].m;
if(localdebug>0){printf("\tload_dlg_mol: about to set ai indices.\n");}
	for(b=0;b<D[0].M.r[a].na;b++){
		if(D[0].M.r[a].a[b].n>nat){mywhine("problem counting atoms (n) in load_dlg");}
		AI[D[0].M.r[a].a[b].n-1]=b;
		}
	}

if(localdebug>0){printf("load_dlg_mol: Scanning to dockings.\n");}
// read in the alternate coordinate sets
while(fgets(line,500,F.F)!=NULL){
	if(strstr(line,"Number of requested LGA dockings")!=NULL){
if(localdebug>3){printf("load_dlg_mol: line is >>%s<<\n",line);} 
		sscanf(line,"Number of requested LGA dockings = %d ",&ndock);
if(localdebug>0){printf("load_dlg_mol: ndock is >>%d<<\n",ndock);} 
		break; }}
// allocate the memory -- use the internal ring coordinates to hold
// the extra centers of mass
if(localdebug>0){printf("load_dlg_mol: About to allocate; ndock is %d.\n",ndock);}
D[0].i=0;
D[0].n=ndock;
D[0].TR=(coord_3D*)calloc(ndock,sizeof(coord_3D));//translation for docked structure
D[0].Q=(vectormag_3D*)calloc(ndock,sizeof(vectormag_3D));// Quaternion x,y,z,w
D[0].QN=(vectormag_3D*)calloc(ndock,sizeof(vectormag_3D));// Quaternion nx,ny,nz,angle
D[0].QN0=(vectormag_3D*)calloc(ndock,sizeof(vectormag_3D));// quat0 nx,ny,nz,angle
D[0].eFEB=(double*)calloc(ndock,sizeof(double));// Est. Free Energy of Binding, kcal/mol [=(1)+(3)]
D[0].eKi=(double*)calloc(ndock,sizeof(double));// Est. Inhibition Const. Ki 
D[0].Tmp=(double*)calloc(ndock,sizeof(double));// temperature, Kelvin
D[0].fDE=(double*)calloc(ndock,sizeof(double));// Final Docked Energy, kcal/mol [=(1)+(2)]
D[0].fIE=(double*)calloc(ndock,sizeof(double));// (1) Final Intermolecular Energy
D[0].fIEL=(double*)calloc(ndock,sizeof(double));// (2) Final Internal Energy of Ligand
D[0].TFE=(double*)calloc(ndock,sizeof(double));// (3) Torsional Free Energy 
D[0].USE=(double*)calloc(ndock,sizeof(double));// (4) Unbound System's Energy
D[0].M.nrc=ndock;
D[0].M.rc=(coord_3D*)calloc(ndock,sizeof(coord_3D)); // for alt struct mol COM's
D[0].clusterRank=(int*)calloc(ndock,sizeof(int));// Cluster Rank for the corresponding run
for(a=0;a<D[0].M.nr;a++){
	D[0].M.r[a].nrc=ndock;
	D[0].M.r[a].rc=(coord_3D*)calloc(ndock,sizeof(coord_3D)); // for alt struct res COM's
	for(b=0;b<D[0].M.r[a].na;b++){
		D[0].M.r[a].a[b].nalt=ndock;
		D[0].M.r[a].a[b].xa=(coord_3D*)calloc(ndock,sizeof(coord_3D));
		}
	}

//  This part of the function finds the energies for each run, as well as the
//  coordinates for each run, and store it in the dockinfo molecule
di = 0;
while(fgets(line,500,F.F)!=NULL){
	if(strstr(line,"FINAL LAMARCKIAN GENETIC ALGORITHM DOCKED STATE")!=NULL){
		//Call functions, based on which version of Autodock, to get energies 
		if(distVer == 3){findAD3Energies(F,D,di);}
		else if(distVer == 4){findAD4Energies(F,D,di);}
		for(a=0; a<sl.n; a++)	//Free up the memory taken up by the fileslurp
			free(sl.L[a]);
		sl.n = 0;
		//Read in lines from the file, extract any info that is here, then
		//dump all of the lines into the fileslurp
		while(strstr(line,"____________________________________________________________________")==NULL){
			fgets(line,500,F.F);
			//First check for possible data
			if((strstr(line,"NEWDPF about")!=NULL)&&(di==0)){
				sscanf(line,"%s %s %s %s %lf %lf %lf",dum1,dum1,dum1,dum1,\
					&D[0].RC.i,&D[0].RC.j,&D[0].RC.k); 
			}
			if(strstr(line,"NEWDPF tran0 ")!=NULL){
				sscanf(line,"%s %s %s %s %lf %lf %lf",dum1,dum1,dum1,dum1,\
					&D[0].TR[di].i,&D[0].TR[di].j,&D[0].TR[di].k);
			}
			if(strstr(line,"NEWDPF quat0")!=NULL){
				sscanf(line,"%s %s %s %s %lf %lf %lf %lf",dum1,dum1,dum1,dum1,\
					&D[0].QN0[di].i,&D[0].QN0[di].j,&D[0].QN0[di].k,&D[0].QN0[di].d); 
			}
			//Then add the line to the fileslurp
			sl.n++;
			sl.L=(char**)realloc(sl.L,sl.n*sizeof(char*));
			sl.L[sl.n-1]=strdup(line);
		}
		//Now Process the fileslurp lines to remove excess information...
		sl = isolateDockedPDB(sl);
		//...and extract the pdb data from it
		alt = load_pdb_from_slurp(sl);
		for(ri = 0; ri < D[0].M.nr; ri++){
			for(ai = 0; ai < D[0].M.r[ri].na; ai++){
				//For finding the boundaries of the box
				if(xl>alt.r[ri].a[ai].x.i){xl=alt.r[ri].a[ai].x.i;}
				if(xh<alt.r[ri].a[ai].x.i){xh=alt.r[ri].a[ai].x.i;}
				if(yl>alt.r[ri].a[ai].x.j){yl=alt.r[ri].a[ai].x.j;}
				if(yh<alt.r[ri].a[ai].x.j){yh=alt.r[ri].a[ai].x.j;}
				if(zl>alt.r[ri].a[ai].x.k){zl=alt.r[ri].a[ai].x.k;}
				if(zh<alt.r[ri].a[ai].x.k){zh=alt.r[ri].a[ai].x.k;}
				//Assign the alternate data
				D[0].M.r[ri].a[ai].xa[di].i=alt.r[ri].a[ai].x.i;
				D[0].M.r[ri].a[ai].xa[di].j=alt.r[ri].a[ai].x.j;
				D[0].M.r[ri].a[ai].xa[di].k=alt.r[ri].a[ai].x.k;
				ti=D[0].M.r[ri].a[ai].t; // for convenience
				// add to the COM determinations
				D[0].M.rc[di].i+=D[0].M.r[ri].a[ai].xa[di].i*AT[ti].m; // molecule COM
				D[0].M.rc[di].j+=D[0].M.r[ri].a[ai].xa[di].j*AT[ti].m;
				D[0].M.rc[di].k+=D[0].M.r[ri].a[ai].xa[di].k*AT[ti].m;
				D[0].M.r[ri].rc[di].i+=D[0].M.r[ri].a[ai].xa[di].i*AT[ti].m; // residue COM
				D[0].M.r[ri].rc[di].j+=D[0].M.r[ri].a[ai].xa[di].j*AT[ti].m;
				D[0].M.r[ri].rc[di].k+=D[0].M.r[ri].a[ai].xa[di].k*AT[ti].m;

			}//End loop through atoms
		// also for the residues -- plus record atom number correlation
			D[0].M.r[ri].rc[di].i/=D[0].M.r[ri].m;
			D[0].M.r[ri].rc[di].j/=D[0].M.r[ri].m;
			D[0].M.r[ri].rc[di].k/=D[0].M.r[ri].m;
		}//End loop through residues
		// finish COM calculation for molecule
		D[0].M.rc[di].i/=D[0].M.m;
		D[0].M.rc[di].j/=D[0].M.m;
		D[0].M.rc[di].k/=D[0].M.m;
		deallocateMolecule(&alt);//Free the memory allocated in alt
		di++; 			//and incriment to the next alternate set
	}
	if(strstr(line,"CLUSTER ANALYSIS OF CONFORMATIONS") != NULL){
		for(a=0; a<sl.n; a++)	//Free all of the data in the fileslurp
			free(sl.L[a]);	//since it isn't used again
		free(sl.L); sl.n = 0;		
		break;
	}
}

//Now deal with all of the state variables
di = 0;//Reset the alternate place holder
while(fgets(line,500,F.F)!=NULL){
	if(strstr(line,"STATE VARIABLES:") != NULL){
		while(strstr(line,"Torsions") == NULL){
			fgets(line,500,F.F);
			if(strstr(line,"Quaternion nx,ny,nz,angle")!=NULL){
				sscanf(line,"%s %s %s %lf %lf %lf %lf",dum1,dum1,dum1,\
					&D[0].QN[di].i,&D[0].QN[di].j,&D[0].QN[di].k,&D[0].QN[di].d); 
				}
			if(strstr(line,"Quaternion x,y,z,w ")!=NULL){
				sscanf(line,"%s %s %s %lf %lf %lf %lf",dum1,dum1,dum1,\
					&D[0].Q[di].i,&D[0].Q[di].j,&D[0].Q[di].k,&D[0].Q[di].d); 
				}
		}
		di++;
	}
	if(strstr(line,"RMSD TABLE") != NULL){
		while(strstr(line,"_____|_") == NULL){
		fgets(line,500,F.F);
		}
		startRanking=1;
	}
	if(startRanking==1){
		startRanking++;
		fgets(line,500,F.F);
		sscanf(line,"%d %lf %d %lf %lf %lf %s",dumi,dumd,runNum,dumd,dumd,dumd,dum1);
		D[0].clusterRank[runNum[0]-1]=dumi[0];
//printf("load_dlg_mol: 1.) Run %d: Cluster Rank: %d\n",runNum[0],D[0].clusterRank[runNum[0]-1]);
		while(strstr(line,"_______") == NULL){
			fgets(line,500,F.F);
			sscanf(line,"%d %lf %d %lf %lf %lf %s",dumi,dumd,runNum,dumd,dumd,dumd,dum1);
	                D[0].clusterRank[runNum[0]-1]=dumi[0];
//printf("load_dlg_mol: 2.) Run %d: Cluster Rank: %d\n",runNum[0],D[0].clusterRank[runNum[0]-1]);
		}
	}
	}

/// Add BOX information to the molecule structure.
D[0].M.nBOX=1;
D[0].M.BOX=(boxinfo*)calloc(1,sizeof(boxinfo));
D[0].M.BOX[0].STYPE=strdup("non-periodic");
D[0].M.BOX[0].GTYPE=strdup("rectangular, defined by minimum and maximum x,y,z coordinate values");
D[0].M.BOX[0].nC=D[0].M.BOX[0].nCD=2; 
D[0].M.BOX[0].C=(coord_nD*)calloc(D[0].M.BOX[0].nC,sizeof(coord_nD));
D[0].M.BOX[0].CD=(char**)calloc(D[0].M.BOX[0].nCD,sizeof(char*));
D[0].M.BOX[0].C[0].nD=D[0].M.BOX[0].C[1].nD=3;
D[0].M.BOX[0].C[0].D=(double*)calloc(3,sizeof(double));
D[0].M.BOX[0].C[1].D=(double*)calloc(3,sizeof(double));
D[0].M.BOX[0].CD[0]=strdup("Lowest x, y and z values in the data set.");
D[0].M.BOX[0].C[0].D[0]=xl;
D[0].M.BOX[0].C[0].D[1]=yl;
D[0].M.BOX[0].C[0].D[2]=zl;
D[0].M.BOX[0].CD[1]=strdup("Highest x, y and z values in the data set.");
D[0].M.BOX[0].C[1].D[0]=xh;
D[0].M.BOX[0].C[1].D[1]=yh;
D[0].M.BOX[0].C[1].D[2]=zh;

if(localdebug==2){dXprint_molecule(&D[0].M,5);}
if(localdebug>2){dXprint_molecule(&D[0].M,150);}

if(localdebug>1){
printf("Molecule COM (main) is %20.15e %20.15e %20.15e\n",D[0].M.COM.i,D[0].M.COM.j,D[0].M.COM.k);
printf("\tThere are %d alternate COM's:\n",D[0].M.nrc);
for(b=0;b<D[0].M.nrc;b++){
printf("\t\tCOM (alt %d) is %20.15e %20.15e %20.15e\n",b,D[0].M.rc[b].i,D[0].M.rc[b].j,D[0].M.rc[b].k);
}
printf("\tThere are %d Residues:\n",D[0].M.nr); 
for(a=0;a<D[0].M.nr;a++){
printf("\t\tmain COM (RES %d) is %20.15e %20.15e %20.15e\n",a,D[0].M.r[a].COM.i,D[0].M.r[a].COM.j,D[0].M.r[a].COM.k);
}
printf("\t ...each with %d alternate COM's:\n",D[0].M.nrc); 
for(a=0;a<D[0].M.nr;a++){
for(b=0;b<D[0].M.r[a].nrc;b++){
printf("\t\tres %d alt %d : %20.15e %20.15e %20.15e\n",a,b,D[0].M.r[a].rc[b].i,D[0].M.r[a].rc[b].j,D[0].M.r[a].rc[b].k); 
}
}
}
return D;
}
Пример #11
0
molindex_set find_molecule_residues_by_n(molecule *m, int number)
{
molindex_set moli_set;
mywhine("The function find_molecule_residues_by_n has not been written yet.\n"); 
return moli_set;
}
Пример #12
0
/*
Find atoms numbered n -- searches for a.n
*/
molindex_set find_residue_atoms_by_n(residue *r, int number)
{
molindex_set moli_set;
mywhine("The function find_residue_atoms_by_n has not been written yet.\n"); 
return moli_set;
}
Пример #13
0
molindex_set find_assembly_top_level_atoms_by_N(assembly *A, const char *name)
{
molindex_set moli_set;
mywhine("The function find_assembly_top_level_atoms_by_N has not been written yet.\n"); 
return moli_set;
}
Пример #14
0
molindex_set find_molecule_residues_by_N(molecule *m, const char *name)
{
molindex_set moli_set;
mywhine("The function find_molecule_residues_by_N has not been written yet.\n"); 
return moli_set;
}
Пример #15
0
void add_to_moiety_selection(moiety_selection *M, const char *SEL){
int 	aa=0, ///< counter
	ab=0, ///< counter
	ac=0, ///< counter
	posneg=0, ///< flag for negative selection
	number=0; ///< number of designations in the list
char 	*tp, ///< Temporary pointer
	*ts, ///< Temporary string
	*S, ///< The trimmed selection
	*class, ///< The class
	*des, ///< The designation
	**d; ///< The designation_list

/// Make sure there is no leading or trailing whitespace in S to cause confusion
S=strdup(prune_string_whitespace(SEL));

/// grab three items, place into number, class and designation
tp=S; // use a temporary pointer (tp) to move around in S.

// Get Integer
aa=strcspn(tp," \t\n\v\r\f"); ///< Find length of first word -- this should be the integer
if(aa==0){return;} ///< If the string S is empty, return without complaint
ts=(char*)calloc(aa+1,sizeof(char));
strncpy(ts,tp,aa); 
ts[aa]='\0';
ab=sscanf(ts,"%d",&number); ///< Scan in the first integer
if(ab==0){mywhine("add_to_moiety_selection: Initial item in SEL not an integer");}
free(ts);

// Get Class
tp+=aa; // move the pointer past the first item
aa=strspn(tp," \t\n\v\r\f");
tp+=aa; // move past the whitespace
aa=strcspn(tp," \t\n\v\r\f"); ///< Find length of second word -- this should be the class
class=(char*)calloc((aa+1),sizeof(char));
strncpy(class,tp,aa); 
class[aa]='\0';



// Get Designation
tp+=aa; // move the pointer past the second item
aa=strspn(tp," \t\n\v\r\f");
tp+=aa; // move past the whitespace
aa=strcspn(tp," \t\n\v\r\f"); ///< Find length of third word -- this should be the designation
des=(char*)calloc((aa+1),sizeof(char));
strncpy(des,tp,aa); 
des[aa]='\0';

// See if there is an Optional -NOT-
ts=strstr(tp,"-NOT-"); 
if(ts!=NULL){ // if a not entry was found
	posneg=-1;
	tp=ts+5; // move the tp pointer past the "-NOT-"
	}
else{posneg=+1;}

if((M[0].posneg!=0)&&(M[0].posneg!=posneg)){mywhine("add_to_moiety_selection: positive/negative mismatch with SEL and M.");}
M[0].posneg=posneg; // In case it was zero

// separate the designation_list by scanning for non-whitespace
d=(char**)calloc(number,sizeof(char*));
for(ab=0;ab<number;ab++){
	aa=strspn(tp," \t\n\v\r\f");
	tp+=aa; // move past the whitespace
	aa=strcspn(tp," \t\n\v\r\f"); ///< Find length of the ab'th item in the designation_list
	d[ab]=(char*)calloc((aa+1),sizeof(char));
	strncpy(d[ab],tp,aa); 
	d[ab][aa]='\0'; 
	}

// add the string entries to the appropriate parts of the moiety_selection
switch(class[0]){ ///< First letter of class differentiates molecule, residue or atom
	case 'M':
	case 'm':
		switch(des[1]){ ///< Second letter of designation differentiates name, number or index
			case 'A':
			case 'a':
				ab=M[0].nmN;
				M[0].nmN+=number;
				M[0].mN=(char**)realloc(M[0].mN,M[0].nmN*sizeof(char*));
				for(aa=0;aa<number;aa++){M[0].mN[aa+ab]=strdup(d[aa]);}
				break;
			case 'U':
			case 'u':
				ab=M[0].nmn;
				M[0].nmn+=number;
				M[0].mn=(int*)realloc(M[0].mn,M[0].nmn*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].mn[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for des-number, got something else");}}
				break;
			case 'N':
			case 'n':
				ab=M[0].nmi;
				M[0].nmi+=number;
				M[0].mi=(int*)realloc(M[0].mi,M[0].nmi*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].mi[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for index, got something else");}}
				break;
			default:
				mywhine("add_to_moiety_selection: unrecognized moiety-designation");
			}
		break;
	case 'R':
	case 'r': 
		switch(des[1]){ ///< Second letter of designation differentiates name, number or index
			case 'A':
			case 'a':
				ab=M[0].nrN;
				M[0].nrN+=number;
				M[0].rN=(char**)realloc(M[0].rN,M[0].nrN*sizeof(char*));
				for(aa=0;aa<number;aa++){M[0].rN[aa+ab]=strdup(d[aa]);}
				break;
			case 'U':
			case 'u':
				ab=M[0].nrn;
				M[0].nrn+=number;
				M[0].rn=(int*)realloc(M[0].rn,M[0].nrn*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].rn[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for des-number, got something else");}}
				break;
			case 'N':
			case 'n':
				ab=M[0].nri;
				M[0].nri+=number;
				M[0].ri=(int*)realloc(M[0].ri,M[0].nri*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].ri[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for index, got something else");}}
				break;
			default:
				mywhine("add_to_moiety_selection: unrecognized moiety-designation");
			}
		break;
	case 'A':
	case 'a': 
		switch(des[1]){ ///< Second letter of designation differentiates name, number or index
			case 'A':
			case 'a':
				ab=M[0].naN;
				M[0].naN+=number;
				M[0].aN=(char**)realloc(M[0].aN,M[0].naN*sizeof(char*));
				for(aa=0;aa<number;aa++){M[0].aN[aa+ab]=strdup(d[aa]);}
				break;
			case 'U':
			case 'u':
				ab=M[0].nan;
				M[0].nan+=number;
				M[0].an=(int*)realloc(M[0].an,M[0].nan*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].an[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for des-number, got something else");}}
				break;
			case 'N':
			case 'n':
				ab=M[0].nai;
				M[0].nai+=number;
				M[0].ai=(int*)realloc(M[0].ai,M[0].nai*sizeof(int));
				for(aa=0;aa<number;aa++){ac=sscanf(d[aa],"%d",&M[0].ai[aa+ab]);
					if(ac!=1){mywhine("add_to_moiety_selection: expected integer for index, got something else");}}
				break;
			default:
				mywhine("add_to_moiety_selection: unrecognized moiety-designation");
			}
		break;
	default:
		mywhine("add_to_moiety_selection: unrecognized moiety-size-class");
	}

free(ts);
free(class);
free(des);
for(aa=0;aa<number;aa++){free(d[aa]);}
free(d);

return;
}
Пример #16
0
int  follow_molecule_atom_nodes_from_bonds(molecule *m, int iTree, atom *a)
{
char is_incoming='n';
int bi,ni,oi,finished=0;
atom *at;
/* 
    This function doesn't choose where to start.  It just follows. 

    At this point, the value of rTi should be negative 
*/
if(a[0].mTi>=0){mywhine("unexpected init of a[0].mTi in follow_molecule_atom_nodes_from_bonds.");}

/* 
0.  Declare space for outgoing bonds 
*/
if(m[0].aT[iTree].ni<0){mywhine("Unexpected init of aT[].ni in follow_molecule_atom_nodes_from_bonds");}
m[0].aT[iTree].no=a[0].nmb-m[0].aT[iTree].ni;
/* 
    If this is the end of a list, go find any unseen or bail.
*/

if(m[0].aT[iTree].no<=0)
    {
    a[0].mTi=-(a[0].mTi+1);
    for(ni=0;ni<m[0].na;ni++)
        {
        at=&m[0].r[m[0].aT[ni].ID.r].a[m[0].aT[ni].ID.a];
        if(at[0].mTi<0) 
           { 
           finished = follow_molecule_atom_nodes_from_bonds(m,ni,at);
           }
        if(finished==-1) break;
        }
    if (finished == -1) { return -1;}
    if (ni==m[0].na) { return -1;}
    else { return -2;}
    } 

m[0].aT[iTree].o=(ensindex**)calloc(m[0].aT[iTree].no,sizeof(ensindex*));
for(oi=0;oi<m[0].aT[iTree].no;oi++)
    {
    m[0].aT[iTree].o[oi]=(ensindex*)calloc(1,sizeof(ensindex));
    }

/* 
1.  Set each bond that is not an incoming bond as an outgoing bond 
*/

oi=0;
for(bi=0;bi<a[0].nmb;bi++)
    {
    /*
    If the two atoms are not part of the same molecule, complain, and don't bother.
    */
    if(a[0].mb[bi].s.m!=a[0].mb[bi].t.m) 
        {
        m[0].aT[iTree].no--;
        continue;
        }
    /*
    Check to see if the current bond is one of the incoming bonds.
    */
    is_incoming='n';
    for(ni=0;ni<m[0].aT[iTree].ni;ni++)
        {
        if(is_consistent_ensi_moli(m[0].aT[iTree].i[ni][0],a[0].mb[bi].t)!='n') is_incoming='y';
        }
    /*
    If not, then set this as outgoing.
    */
    if(is_incoming=='n') 
        {
        m[0].aT[iTree].o[oi][0]=copy_moli_to_ensi(a[0].mb[bi].t);
        oi++;
        }
    if(oi>m[0].aT[iTree].no){mywhine("overstepped outgoing bonds in follow_molecule_atom_nodes_from_bonds.");}
    }

/* 
2.  Set the current atom's state as seen.  Assumes a.rTi is initialized negative. 
*/
a[0].mTi = -(a[0].mTi + 1); /* make positive and add one*/

/*
3.  Identify the current atom as incoming to each outgoing atom. 
*/
for(oi=0;oi<m[0].aT[iTree].no;oi++)
    {
    /* 
    get target atom 
    */
    at=&m[0].r[m[0].aT[iTree].o[oi][0].r].a[m[0].aT[iTree].o[oi][0].a]; 
    /* 
    record location in contree 
    */
    if(at[0].mTi>=0) { continue; } 
    else{bi=-(at[0].mTi+1);}
    m[0].aT[iTree].o[oi][0].i=bi;
    /* 
    identify current atom as incoming to the target atom
    */
    m[0].aT[bi].ni++; 
    if(m[0].aT[bi].ni==1) { m[0].aT[bi].i=(ensindex**)calloc(1,sizeof(ensindex*)); }
    else { m[0].aT[bi].i=(ensindex**)realloc(m[0].aT[bi].i,m[0].aT[bi].ni*sizeof(ensindex*));}
    m[0].aT[bi].i[m[0].aT[bi].ni-1]=(ensindex*)calloc(1,sizeof(ensindex));
    m[0].aT[bi].i[m[0].aT[bi].ni-1][0]=m[0].aT[iTree].ID;
    }

/* 
4.  Call each outgoing atom, in order, with this function 
*/
for(oi=0;oi<m[0].aT[iTree].no;oi++)
    { 
    /* 
    get target atom 
    */
    at=&m[0].r[m[0].aT[iTree].o[oi][0].r].a[m[0].aT[iTree].o[oi][0].a]; 
    /* 
    record location in contree 
    */ 
    if(at[0].mTi>=0) { continue; } 
    else{bi=-(at[0].mTi+1);}
    finished = follow_molecule_atom_nodes_from_bonds(m, bi, at);
    }

return finished;
}
//START HERE -- change name to get_moiety_selection_assembly_from_ensemble
// Make similar called get_moiety_selection_assembly_from_assembly
assembly get_moiety_selection_assembly(ensemble *E, int nMS, moiety_selection *MS){
int 	am=0,ar=0,aa=0,ai=0,ams=0, ///< counters
	aflag=0, ///< Flag used for setting negative selections
	numM=0, ///< Number of molecule pointers needed for assembly
	numR=0, ///< Number of residue pointers needed for assembly
	numA=0; ///< Number of atom pointers needed for assembly
assembly A; ///< the assembly to return
ensemble_tree_index IA; ///< the indices for holding selections

// Set up the tree of indices (IA) analogous to the m,r,a structure in E
//	initialize them all to be 0
IA.nm=E[0].nm;
IA.mi=(int*)calloc(IA.nm,sizeof(int));
IA.m=(molecule_tree_index*)calloc(IA.nm,sizeof(molecule_tree_index));
for(am=0;am<IA.nm;am++){ // for each molecule
	IA.m[am].nr=E[0].m[am].nr;
	IA.m[am].ri=(int*)calloc(IA.m[am].nr,sizeof(int));
	IA.m[am].r=(residue_tree_index*)calloc(IA.m[am].nr,sizeof(residue_tree_index));
	for(ar=0;ar<IA.m[am].nr;ar++){ // for each residue 
		IA.m[am].r[ar].na=E[0].m[am].r[ar].na;
		IA.m[am].r[ar].ai=(int*)calloc(IA.m[am].r[ar].na,sizeof(int));
		}
	}


/** Walk through each m, r, a of the ensemble.  Look for matches.  
*
* If there is a match, change the corresponding index in IA to equal one.  
* Don't check to see whether it is already one -- that doesn't matter. */

for(ams=0;ams<nMS;ams++){

/// For each positive moiety_selection passed to the function
if(MS[ams].posneg==1){ 
	// Molecules
	// For each molecule index specified
	for(ai=0;ai<MS[ams].nmi;ai++){ IA.mi[MS[ams].mi[ai]]=1; }
	// Check each molecule for names and numbers
	for(am=0;am<IA.nm;am++){ 
		// For each name specified
		for(ai=0;ai<MS[ams].nmN;ai++){ if((E[0].m[am].N!=NULL)&&(strcmp(E[0].m[am].N,MS[ams].mN[ai])==0)){IA.mi[am]=1;} }
		// For each number specified
		for(ai=0;ai<MS[ams].nmn;ai++){ if(E[0].m[am].n==MS[ams].mn[ai]){IA.mi[am]=1;} }	
	
		// Residues
		// For each index specified
		for(ai=0;ai<MS[ams].nri;ai++){ IA.m[am].ri[MS[ams].ri[ai]]=1; }
		// Now, check each residue for names and numbers 
		for(ar=0;ar<IA.m[am].nr;ar++){ 
			// For each name specified
			for(ai=0;ai<MS[ams].nrN;ai++){ if((E[0].m[am].r[ar].N!=NULL)&&(strcmp(E[0].m[am].r[ar].N,MS[ams].rN[ai])==0)){IA.m[am].ri[ar]=1;} }
			// For each number specified
			for(ai=0;ai<MS[ams].nrn;ai++){ if(E[0].m[am].r[ar].n==MS[ams].rn[ai]){IA.m[am].ri[ar]=1;} }	

			// Atoms
			// For each index specified
			for(ai=0;ai<MS[ams].nai;ai++){ IA.m[am].r[ar].ai[MS[ams].ai[ai]]=1; }
			// Now, check each residue for names and numbers 
			for(aa=0;aa<IA.m[am].r[ar].na;aa++){ 
// For each atom name specified
for(ai=0;ai<MS[ams].naN;ai++){ if((E[0].m[am].r[ar].a[aa].N!=NULL)&&(strcmp(E[0].m[am].r[ar].a[aa].N,MS[ams].aN[ai])==0)){IA.m[am].r[ar].ai[aa]=1;} }
// For each atom number specified
for(ai=0;ai<MS[ams].nan;ai++){ if(E[0].m[am].r[ar].a[aa].n==MS[ams].an[ai]){IA.m[am].r[ar].ai[aa]=1;} } 
				} // close aa loop
			} // close ar loop
		} // close am loop
	} // close if positive MS condition

/// For each negative moiety_selection passed to the function
if(MS[ams].posneg==1){ 
	// Molecules
	// Check each molecule for names and numbers
	for(am=0;am<IA.nm;am++){ 
		// For each molecule index specified
		aflag=1;
		for(ai=0;ai<MS[ams].nmi;ai++){ if(am==MS[ams].mi[ai]) aflag=0; }
		if(aflag==1) { IA.mi[am]=1; }
		// For each name specified
		aflag=1;
		for(ai=0;ai<MS[ams].nmN;ai++){ if((E[0].m[am].N!=NULL)&&(strcmp(E[0].m[am].N,MS[ams].mN[ai])==0)){aflag=0;} }
		if(aflag==1) { IA.mi[am]=1; }
		// For each number specified
		aflag=1;
		for(ai=0;ai<MS[ams].nmn;ai++){ if(E[0].m[am].n==MS[ams].mn[ai]){aflag=0;} }	
		if(aflag==1) { IA.mi[am]=1; }
	
		// Residues
		// Now, check each residue for names and numbers 
		for(ar=0;ar<IA.m[am].nr;ar++){ 
			// For each index specified
			aflag=1;
			for(ai=0;ai<MS[ams].nri;ai++){ if(ar==MS[ams].ri[ai]) aflag=0; }
			if(aflag==1) { IA.m[am].ri[ar]=1; }
			// For each name specified
			aflag=1;
			for(ai=0;ai<MS[ams].nrN;ai++){ if((E[0].m[am].r[ar].N!=NULL)&&(strcmp(E[0].m[am].r[ar].N,MS[ams].rN[ai])==0)){aflag=0;} }
			if(aflag==1) { IA.m[am].ri[ar]=1; }
			// For each number specified
			aflag=1;
			for(ai=0;ai<MS[ams].nrn;ai++){ if(E[0].m[am].r[ar].n==MS[ams].rn[ai]){aflag=0;} }	
			if(aflag==1) { IA.m[am].ri[ar]=1; }

			// Atoms
			// Now, check each residue for names and numbers 
			for(aa=0;aa<IA.m[am].r[ar].na;aa++){ 
// For each index specified
aflag=1;
for(ai=0;ai<MS[ams].nai;ai++){ if(aa==MS[ams].ai[ai]) aflag=0; }
if(aflag==1) { IA.m[am].r[ar].ai[aa]=1; } 
// For each atom name specified
aflag=1;
for(ai=0;ai<MS[ams].naN;ai++){ if((E[0].m[am].r[ar].a[aa].N!=NULL)&&(strcmp(E[0].m[am].r[ar].a[aa].N,MS[ams].aN[ai])==0)){aflag=0;} }
if(aflag==1) { IA.m[am].r[ar].ai[aa]=1; } 
// For each atom number specified
aflag=1;
for(ai=0;ai<MS[ams].nan;ai++){ if(E[0].m[am].r[ar].a[aa].n==MS[ams].an[ai]){aflag=0;} } 
if(aflag==1) { IA.m[am].r[ar].ai[aa]=1; } 
				} // close aa loop
			} // close ar loop
		} // close am loop
	} // close if negative MS condition

	} // close ams loop

// after all the indices are set for selection, count, in IA, the number of
// 	m, r and a pointers the assembly will need and allocate them.
numM=numR=numA=0;
for(am=0;am<IA.nm;am++){ if(IA.mi[am]>0) numM++;
	for(ar=0;ar<IA.m[am].nr;ar++){ if(IA.m[am].ri[ar]>0) numR++;
		for(aa=0;aa<IA.m[am].r[ar].na;am++){ if(IA.m[am].r[ar].ai[aa]==1) numA++;
			}
		}
	}
A.nm=numM;
A.m=(molecule**)calloc(A.nm,sizeof(molecule*));
A.nr=numR;
A.r=(residue**)calloc(A.nr,sizeof(residue*)); 
A.na=numA;
A.a=(atom**)calloc(A.na,sizeof(atom*)); 

// Walk through IA and set an appropriate pointer whenever a "1" is encountered
numM=numR=numA=0;
for(am=0;am<IA.nm;am++){ 
	if(IA.mi[am]>0){
		A.m[numM]=&E[0].m[am];
		numM++;
		if(numM>A.nm){mywhine("get_moiety_selection_assembly: memory allocation issue in A.nm/numM");}
		}
	for(ar=0;ar<IA.m[am].nr;ar++){ 
		if(IA.m[am].ri[ar]>0){
			A.r[numR]=&E[0].m[am].r[ar];
			numR++;
			if(numR>A.nr){mywhine("get_moiety_selection_assembly: memory allocation issue in A.nr/numR");}
			}
		for(aa=0;aa<IA.m[am].r[ar].na;am++){ 
			if(IA.m[am].r[ar].ai[aa]==1){
				A.a[numA]=&E[0].m[am].r[ar].a[aa];
				numA++;
				if(numA>A.na){mywhine("get_moiety_selection_assembly: memory allocation issue in A.na/numA");}
				}
			}
		}
	}

return A;
}
Пример #18
0
int follow_molecule_residue_nodes_from_bonds(molecule *m, int iTree, residue *r)
{
char is_incoming='n';
int bi,ni,oi,finished=0;
residue *rt;
/* This function doesn't choose where to start.  It just follows. */

/* And, the value of mTi should be negative */
if(r[0].mTi>=0){mywhine("unexpected init of r[0].mTi in follow_molecule_residue_nodes_from_bonds.");}

/* 
0.  If this is not the end of a list, declare space for outgoing bonds 
*/
//printf("m[0].rT[%d].nmbi=%d\n",iTree,m[0].rT[iTree].nmbi);
if(m[0].rT[iTree].nmbi<0)
  {
  mywhine("Unexpected init of rT[].nmbi in follow_molecule_residue_nodes_from_bonds.");
  }
//printf("r[0].nrb=%d\n",r[0].nrb);
m[0].rT[iTree].nmbo=(r[0].nrb)-(m[0].rT[iTree].nmbi); // This is dodgy OG
//printf("m[0].rT[%d].nmbo=%d\n",iTree,m[0].rT[iTree].nmbo);
/* 
    If this is the end of a list, go find any unseen or bail.
*/
if(m[0].rT[iTree].nmbo<=0)
    {
    r[0].mTi=-(r[0].mTi+1);
    for(ni=0;ni<m[0].nr;ni++)
        {
        if(m[0].r[ni].mTi<0) 
           { 
           finished = follow_molecule_residue_nodes_from_bonds(m,ni,&m[0].r[ni]);
           }
        if(finished==-1) break;
        }
    if (finished == -1) { return -1;}
    if (ni==m[0].nr) { return -1;}
    else { return -2;}
    }

m[0].rT[iTree].mbo=(molbond**)calloc(m[0].rT[iTree].nmbo,sizeof(molbond*));
for(oi=0;oi<m[0].rT[iTree].nmbo;oi++)
    {
    m[0].rT[iTree].mbo[oi]=(molbond*)calloc(1,sizeof(molbond));
    }

/*
1.  Set each bond that is not an incoming bond as an outgoing bond 
*/
oi=0;
for(bi=0;bi<r[0].nrb;bi++)
    {
    /*
    If the two atoms are not part of the same molecule, complain, and don't bother.
    */
    if(r[0].rb[bi].s.m!=r[0].rb[bi].t.m) 
        {
        printf("Found bond between two molecules in follow_molecule_residue_nodes_from_bonds.\n");
        printf("Ignoring that bond.\n");
        m[0].rT[iTree].nmbo--;
        continue;
        }
    /*
    Check to see if the current bond is one of the incoming bonds.
    */
    is_incoming='n';
    for(ni=0;ni<m[0].rT[iTree].nmbi;ni++)
        {
        if(is_consistent_molbond_molbond_inverse(m[0].rT[iTree].mbi[ni][0],r[0].rb[bi])!='n') is_incoming='y';
        }
    /*
    If not, then set this as outgoing.
    */
    if(is_incoming=='n') 
        {
        m[0].rT[iTree].mbo[oi][0]=r[0].rb[bi];
        oi++;
        }
    if(oi>m[0].rT[iTree].nmbo){mywhine("overstepped outgoing bonds in follow_molecule_residue_nodes_from_bonds.");}
    }

/* 
2.  Set the current atom's state as seen.  Assumes a.rTi is initialized negative. 
*/
r[0].mTi = -(r[0].mTi + 1); /* make positive and add one*/

/*
3.  Identify the current atom as incoming to each outgoing atom. 
*/
for(oi=0;oi<m[0].rT[iTree].nmbo;oi++)
    {
    /* 
    get target residue
    */
    rt=&m[0].r[m[0].rT[iTree].mbo[oi][0].t.r]; 
    /* 
    record location in contree 
    */
    //printf("rt[0].mTi=%d\n",rt[0].mTi);
    if(rt[0].mTi>=0) 
        {
        printf("\nTarget residue mTi is nonnegative in follow_molecule_residue_nodes_from_bonds.\n");
        printf("This might be a problem.\n");
        bi=rt[0].mTi;
        } 
    else{bi=-(rt[0].mTi+1);}
    m[0].rT[iTree].mbo[oi][0].i=bi;
    /* 
    identify current residue as incoming to the target atom
    */
    m[0].rT[bi].nmbi++; 
    if(m[0].rT[bi].nmbi==1) { m[0].rT[bi].mbi=(molbond**)calloc(1,sizeof(molbond*)); }
    else { m[0].rT[bi].mbi=(molbond**)realloc(m[0].rT[bi].mbi,m[0].rT[bi].nmbi*sizeof(molbond*));}
    m[0].rT[bi].mbi[m[0].rT[bi].nmbi-1]=(molbond*)calloc(1,sizeof(molbond));
    m[0].rT[bi].mbi[m[0].rT[bi].nmbi-1][0]=m[0].rT[iTree].mbo[oi][0];
    }

/* 
4.  Call each outgoing atom, in order, with this function 
*/
for(oi=0;oi<m[0].rT[iTree].nmbo;oi++)
    { 
    /* 
    get target residue
    */
    rt=&m[0].r[m[0].rT[iTree].mbo[oi][0].t.r]; 
    /* 
    record location in contree 
    */
    if(rt[0].mTi>=0) { continue; } 
    else{bi=-(rt[0].mTi+1);}
    finished = follow_molecule_residue_nodes_from_bonds(m, bi, rt);
    }

return finished;
}
Пример #19
0
void set_atom_element_best_guess(atom *a)
{
mywhine("the function set_atom_element_best_guess has not been written yet");
return;
}
Пример #20
0
/*********************** crdsnaps(const char cstop, const char cscrd) *******************/
int crdsnaps(const char *cstop,const char *cscrd,int csdot){
int csa=0,csnat=0,csnsnp=0,csstat=0,cssig=0;
char cstst[501];
double csEa=0,csEb=0,csEc=0;
FILE *CST,*CSC;

// Probe top file for number of atoms
CST=myfopen(cstop,"r");
csstat=fscanf(CST,"%s",cstst);
if(csstat!=1) mywhine("Error reading topology file");
//printf("cstst is >>>%s<<<\n",cstst);
while(csstat==1){
	//printf("\t in loop cstst is >>>%s<<<\n",cstst);
	if(strcmp(cstst,"POINTERS")==0){
		csstat=fscanf(CST,"%s",cstst);
//printf("cstst is >>>%s<<<\n",cstst);
		if(csstat!=1) mywhine("Error reading topology file"); 
		csstat=fscanf(CST,"%d",&csnat);
//printf("csnat is >>>%d<<<\n",csnat);
		if(csstat!=1) mywhine("Error reading number of atoms in topology file."); 
		//break;
		}
	if(strcmp(cstst,"BOX_DIMENSIONS")==0) csnat++;
	//if(csnat!=0) break; 
	csstat=fscanf(CST,"%s",cstst);
	}
if(csnat==0) mywhine("Got zero for number of atoms.");
//printf("crdsnaps after CST loop\n");
fclose(CST);
//printf("crdsnaps after close CST\n");
// Probe crd file for total number of snapshots 
//printf("crdsnaps opening CSC\n");
CSC=myfopen(cscrd,"r");
//printf("crdsnaps fgets CSC\n");
fgets(cstst,201,CSC);
//printf("cstst is >>>%s<<<\n",cstst);
if(cstst==NULL) mywhine("Error reading coordinate file."); 
//if(strlen(cstst)==0) mywhine("Error reading coordinate file."); 
//printf("cstst about to fscanf \n");
csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc);;
//printf("cstst after fscanf  csstat is >>>%d<<<\n",csstat);
// START HERE -- fix this for loop structure
printf(" ");
while(csstat==3){
	csa=1;
	while(csa<csnat){
		csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc);
//printf("csa is %d; csnat is %d, csstat is %d\n",csa,csnat,csstat);
		if(csstat!=3) break;
		csa++;
		//switch(cssig){	
			//case 0:	printf("\b-");
				//cssig=1;
				//break;
			//case 1:	printf("\b\\");
				//cssig=2;
				//break;
			//case 2:	printf("\b|");
				//cssig=3;
				//break;
			//case 3:	printf("\b/");
				//cssig=0;
				//break;
			//default: mywhine("something wrong in cssig in crdsnaps.c");
			//}
		} 
	if(csa==csnat){csnsnp++;}
	else if (csa!=1){mywhine("Mismatch between NATOMs in top and crd files.\n\
\tPerhaps there is a mismatch between BOX info in crd and top."); }
//printf("csa is %d; csnat is %d; csnsnp is %d\n",csa,csnat,csnsnp);
	csstat=fscanf(CSC,"%lf %lf %lf",&csEa,&csEb,&csEc);
	if((csnsnp%csdot)==0){printf("%d  ",csnsnp);}
	switch(cssig){	
		case 0:	printf("\b-");
			cssig=1;
			break;
		case 1:	printf("\b\\");
			cssig=2;
			break;
		case 2:	printf("\b|");
			cssig=3;
			break;
		case 3:	printf("\b/");
			cssig=0;
			break;
		default: mywhine("something wrong in cssig in crdsnaps.c");
		}
//printf("csstat is %d\n",csstat);
	}
printf("\n");
return csnsnp;
}