void ps_mat(char *outf,int nmat,t_matrix mat[],t_matrix mat2[], bool bFrame,bool bDiag,bool bFirstDiag, bool bTitle,bool bTitleOnce,bool bYonce,int elegend, real size,real boxx,real boxy,char *m2p,char *m2pout, int mapoffset) { char *libm2p; char buf[256],*legend; t_psdata out; t_psrec psrec,*psr; int W,H; int i,j,x,y,col,leg=0; real x0,y0,xx; real w,h,dw,dh; int nmap1=0,nmap2=0,leg_nmap; t_mapping *map1=NULL,*map2=NULL,*leg_map; bool bMap1,bNextMap1,bDiscrete; libm2p = m2p ? strdup(libfn(m2p)) : m2p; get_params(libm2p,m2pout,&psrec); psr=&psrec; if (psr->X.major <= 0 ) tick_spacing((mat[0].flags & MAT_SPATIAL_X) ? mat[0].nx + 1 : mat[0].nx, mat[0].axis_x, psr->X.offset, 'X', &(psr->X.major), &(psr->X.minor) ); if (psr->X.minor <= 0 ) psr->X.minor = psr->X.major / 2; if (psr->Y.major <= 0) tick_spacing((mat[0].flags & MAT_SPATIAL_Y) ? mat[0].ny + 1 : mat[0].ny, mat[0].axis_y, psr->Y.offset, 'Y', &(psr->Y.major), &(psr->Y.minor) ); if (psr->Y.minor <= 0) psr->Y.minor = psr->Y.major / 2; if (boxx>0) { psr->xboxsize=boxx; psr->yboxsize=boxx; } if (boxy>0) psr->yboxsize=boxy; if (psr->xboxsize==0) { psr->xboxsize = size/mat[0].nx; printf("Set the x-size of the box to %.3f\n",psr->xboxsize); } if (psr->yboxsize==0) { psr->yboxsize = size/mat[0].nx; printf("Set the y-size of the box to %.3f\n",psr->yboxsize); } nmap1=0; for (i=0; (i<nmat); i++) if (mat[i].nmap>nmap1) { nmap1=mat[i].nmap; map1=mat[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for display\n",leg); if (mat2) { nmap2=0; for (i=0; (i<nmat); i++) if (mat2[i].nmap>nmap2) { nmap2=mat2[i].nmap; map2=mat2[i].map; leg=i+1; } if (leg!=1) printf("Selected legend of matrix # %d for second display\n",leg); } if ( (mat[0].legend[0]==0) && psr->legend ) strcpy(mat[0].legend, psr->leglabel); bTitle = bTitle && mat[nmat-1].title[0]; bTitleOnce = bTitleOnce && mat[nmat-1].title[0]; psr->bTitle = bTitle; psr->bTitleOnce = bTitleOnce; psr->bYonce = bYonce; /* Set up size of box for nice colors */ box_dim(nmat,mat,mat2,psr,elegend,bFrame,&w,&h,&dw,&dh); /* Set up bounding box */ W=w+dw; H=h+dh; /* Start box at */ x0=dw; y0=dh; x = W+psr->xoffs; y = H+psr->yoffs; if (bFrame) { x += 5*DDD; y += 4*DDD; } out=ps_open(outf,0,0,x,y); ps_linewidth(out,psr->linewidth); ps_init_rgb_box(out,psr->xboxsize,psr->yboxsize); ps_init_rgb_nbox(out,psr->xboxsize,psr->yboxsize); ps_translate(out,psr->xoffs,psr->yoffs); if (bFrame) { ps_comment(out,"Here starts the BOX drawing"); draw_boxes(out,x0,y0,w,nmat,mat,psr); } for(i=0; (i<nmat); i++) { if (bTitle || (bTitleOnce && i==nmat-1) ) { /* Print title, if any */ ps_rgb(out,BLACK); ps_strfont(out,psr->titfont,psr->titfontsize); if (!mat2 || (strcmp(mat[i].title,mat2[i].title) == 0)) strcpy(buf,mat[i].title); else sprintf(buf,"%s / %s",mat[i].title,mat2[i].title); ps_ctext(out,x0+w/2,y0+box_height(&(mat[i]),psr)+psr->titfontsize, buf,eXCenter); } sprintf(buf,"Here starts the filling of box #%d",i); ps_comment(out,buf); for(x=0; (x<mat[i].nx); x++) { int nexty; int nextcol; xx=x0+x*psr->xboxsize; ps_moveto(out,xx,y0); y=0; bMap1 = (!mat2 || (x<y || (x==y && bFirstDiag))); if ((bDiag) || (x!=y)) col = mat[i].matrix[x][y]; else col = -1; for(nexty=1; (nexty<=mat[i].ny); nexty++) { bNextMap1 = (!mat2 || (x<nexty || (x==nexty && bFirstDiag))); /* TRUE: upper left -> map1 */ /* FALSE: lower right -> map2 */ if ((nexty==mat[i].ny) || (!bDiag && (x==nexty))) nextcol = -1; else nextcol=mat[i].matrix[x][nexty]; if ( (nexty==mat[i].ny) || (col!=nextcol) || (bMap1!=bNextMap1) ) { if (col >= 0) if (bMap1) ps_rgb_nbox(out,&(mat[i].map[col].rgb),nexty-y); else ps_rgb_nbox(out,&(mat2[i].map[col].rgb),nexty-y); else ps_moverel(out,0,psr->yboxsize); y=nexty; bMap1=bNextMap1; col=nextcol; } } } y0+=box_height(&(mat[i]),psr)+box_dh(psr)+box_dh_top(IS_ONCE,psr); } if (psr->X.lineatzero || psr->Y.lineatzero) { /* reset y0 for first box */ y0=dh; ps_comment(out,"Here starts the zero lines drawing"); draw_zerolines(out,x0,y0,w,nmat,mat,psr); } if (elegend!=elNone) { ps_comment(out,"Now it's legend time!"); ps_linewidth(out,psr->linewidth); if ( mat2==NULL || elegend!=elSecond ) { bDiscrete = mat[0].bDiscrete; legend = mat[0].legend; leg_nmap = nmap1; leg_map = map1; } else { bDiscrete = mat2[0].bDiscrete; legend = mat2[0].legend; leg_nmap = nmap2; leg_map = map2; } if (bDiscrete) leg_discrete(out,psr->legfontsize,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map); else { if ( elegend!=elBoth ) leg_continuous(out,x0+w/2,w/2,DDD,legend, psr->legfontsize,psr->legfont,leg_nmap,leg_map, mapoffset); else leg_bicontinuous(out,x0+w/2,w,DDD,mat[0].legend,mat2[0].legend, psr->legfontsize,psr->legfont,nmap1,map1,nmap2,map2); } ps_comment(out,"Were there, dude"); } ps_close(out); }
static char *insert_mols(char *mol_insrt,int nmol_insrt,int ntry,int seed, t_atoms *atoms,rvec **x,real **r,int ePBC,matrix box, gmx_atomprop_t aps,real r_distance,real rshell) { t_pbc pbc; static char *title_insrt; t_atoms atoms_insrt; rvec *x_insrt,*x_n; real *r_insrt; int ePBC_insrt; matrix box_insrt; int i,mol,onr; real alfa,beta,gamma; rvec offset_x; int try; set_pbc(&pbc,ePBC,box); /* read number of atoms of insert molecules */ get_stx_coordnum(mol_insrt,&atoms_insrt.nr); if (atoms_insrt.nr == 0) gmx_fatal(FARGS,"No molecule in %s, please check your input\n",mol_insrt); /* allocate memory for atom coordinates of insert molecules */ snew(x_insrt,atoms_insrt.nr); snew(r_insrt,atoms_insrt.nr); snew(atoms_insrt.resname,atoms_insrt.nr); snew(atoms_insrt.atomname,atoms_insrt.nr); snew(atoms_insrt.atom,atoms_insrt.nr); atoms_insrt.pdbinfo = NULL; snew(x_n,atoms_insrt.nr); snew(title_insrt,STRLEN); /* read residue number, residue names, atomnames, coordinates etc. */ fprintf(stderr,"Reading molecule configuration \n"); read_stx_conf(mol_insrt,title_insrt,&atoms_insrt,x_insrt,NULL, &ePBC_insrt,box_insrt); fprintf(stderr,"%s\nContaining %d atoms in %d residue\n", title_insrt,atoms_insrt.nr,atoms_insrt.nres); srenew(atoms_insrt.resname,atoms_insrt.nres); /* initialise van der waals arrays of insert molecules */ mk_vdw(&atoms_insrt,r_insrt,aps,r_distance); srenew(atoms->resname,(atoms->nres+nmol_insrt)); srenew(atoms->atomname,(atoms->nr+atoms_insrt.nr*nmol_insrt)); srenew(atoms->atom,(atoms->nr+atoms_insrt.nr*nmol_insrt)); srenew(*x,(atoms->nr+atoms_insrt.nr*nmol_insrt)); srenew(*r,(atoms->nr+atoms_insrt.nr*nmol_insrt)); try=mol=0; while ((mol < nmol_insrt) && (try < ntry*nmol_insrt)) { fprintf(stderr,"\rTry %d",try++); for (i=0;(i<atoms_insrt.nr);i++) { if (atoms_insrt.atom[i].resnr!=0) gmx_fatal(FARGS,"more then one residue in insert molecules\n" "program terminated\n"); copy_rvec(x_insrt[i],x_n[i]); } alfa=2*M_PI*rando(&seed); beta=2*M_PI*rando(&seed); gamma=2*M_PI*rando(&seed); rotate_conf(atoms_insrt.nr,x_n,NULL,alfa,beta,gamma); offset_x[XX]=box[XX][XX]*rando(&seed); offset_x[YY]=box[YY][YY]*rando(&seed); offset_x[ZZ]=box[ZZ][ZZ]*rando(&seed); gen_box(0,atoms_insrt.nr,x_n,box_insrt,offset_x,TRUE); if (!in_box(&pbc,x_n[0]) || !in_box(&pbc,x_n[atoms_insrt.nr-1])) continue; onr=atoms->nr; add_conf(atoms,x,NULL,r,FALSE,ePBC,box,TRUE, &atoms_insrt,x_n,NULL,r_insrt,FALSE,rshell,0); if (atoms->nr==(atoms_insrt.nr+onr)) { mol++; fprintf(stderr," success (now %d atoms)!",atoms->nr); } } srenew(atoms->resname, atoms->nres); srenew(atoms->atomname, atoms->nr); srenew(atoms->atom, atoms->nr); srenew(*x, atoms->nr); srenew(*r, atoms->nr); fprintf(stderr,"\n"); /* print number of molecules added */ fprintf(stderr,"Added %d molecules (out of %d requested) of %s\n", mol,nmol_insrt,*atoms_insrt.resname[0]); return title_insrt; } static void add_solv(char *fn,t_atoms *atoms,rvec **x,rvec **v,real **r, int ePBC,matrix box, gmx_atomprop_t aps,real r_distance,int *atoms_added, int *residues_added,real rshell,int max_sol) { int i,nmol; ivec n_box; char filename[STRLEN]; char title_solvt[STRLEN]; t_atoms *atoms_solvt; rvec *x_solvt,*v_solvt=NULL; real *r_solvt; int ePBC_solvt; matrix box_solvt; int onr,onres; strncpy(filename,libfn(fn),STRLEN); snew(atoms_solvt,1); get_stx_coordnum(filename,&(atoms_solvt->nr)); if (atoms_solvt->nr == 0) gmx_fatal(FARGS,"No solvent in %s, please check your input\n",filename); snew(x_solvt,atoms_solvt->nr); if (v) snew(v_solvt,atoms_solvt->nr); snew(r_solvt,atoms_solvt->nr); snew(atoms_solvt->resname,atoms_solvt->nr); snew(atoms_solvt->atomname,atoms_solvt->nr); snew(atoms_solvt->atom,atoms_solvt->nr); atoms_solvt->pdbinfo = NULL; fprintf(stderr,"Reading solvent configuration%s\n", v_solvt?" and velocities":""); read_stx_conf(filename,title_solvt,atoms_solvt,x_solvt,v_solvt, &ePBC_solvt,box_solvt); fprintf(stderr,"\"%s\"\n",title_solvt); fprintf(stderr,"solvent configuration contains %d atoms in %d residues\n", atoms_solvt->nr,atoms_solvt->nres); fprintf(stderr,"\n"); /* apply pbc for solvent configuration for whole molecules */ rm_res_pbc(atoms_solvt,x_solvt,box_solvt); /* initialise van der waals arrays of solvent configuration */ mk_vdw(atoms_solvt,r_solvt,aps,r_distance); /* calculate the box multiplication factors n_box[0...DIM] */ nmol=1; for (i=0; (i < DIM);i++) { n_box[i] = 1; while (n_box[i]*box_solvt[i][i] < box[i][i]) n_box[i]++; nmol*=n_box[i]; } fprintf(stderr,"Will generate new solvent configuration of %dx%dx%d boxes\n", n_box[XX],n_box[YY],n_box[ZZ]); /* realloc atoms_solvt for the new solvent configuration */ srenew(atoms_solvt->resname,atoms_solvt->nres*nmol); srenew(atoms_solvt->atomname,atoms_solvt->nr*nmol); srenew(atoms_solvt->atom,atoms_solvt->nr*nmol); srenew(x_solvt,atoms_solvt->nr*nmol); if (v_solvt) srenew(v_solvt,atoms_solvt->nr*nmol); srenew(r_solvt,atoms_solvt->nr*nmol); /* generate a new solvent configuration */ genconf(atoms_solvt,x_solvt,v_solvt,r_solvt,box_solvt,n_box); #ifdef DEBUG print_stat(x_solvt,atoms_solvt->nr,box_solvt); #endif #ifdef DEBUG print_stat(x_solvt,atoms_solvt->nr,box_solvt); #endif /* Sort the solvent mixture, not the protein... */ sort_molecule(&atoms_solvt,x_solvt,v_solvt,r_solvt); /* add the two configurations */ onr=atoms->nr; onres=atoms->nres; add_conf(atoms,x,v,r,TRUE,ePBC,box,FALSE, atoms_solvt,x_solvt,v_solvt,r_solvt,TRUE,rshell,max_sol); *atoms_added=atoms->nr-onr; *residues_added=atoms->nres-onres; sfree(x_solvt); sfree(r_solvt); fprintf(stderr,"Generated solvent containing %d atoms in %d residues\n", *atoms_added,*residues_added); }
static void add_solv(char *fn,t_atoms *atoms,rvec **x,rvec **v,real **r, int ePBC,matrix box, gmx_atomprop_t aps,real r_distance,int *atoms_added, int *residues_added,real rshell,int max_sol) { int i,nmol; ivec n_box; char filename[STRLEN]; char title_solvt[STRLEN]; t_atoms *atoms_solvt; rvec *x_solvt,*v_solvt=NULL; real *r_solvt; int ePBC_solvt; matrix box_solvt; int onr,onres; strncpy(filename,libfn(fn),STRLEN); snew(atoms_solvt,1); get_stx_coordnum(filename,&(atoms_solvt->nr)); if (atoms_solvt->nr == 0) gmx_fatal(FARGS,"No solvent in %s, please check your input\n",filename); snew(x_solvt,atoms_solvt->nr); if (v) snew(v_solvt,atoms_solvt->nr); snew(r_solvt,atoms_solvt->nr); snew(atoms_solvt->resinfo,atoms_solvt->nr); snew(atoms_solvt->atomname,atoms_solvt->nr); snew(atoms_solvt->atom,atoms_solvt->nr); atoms_solvt->pdbinfo = NULL; fprintf(stderr,"Reading solvent configuration%s\n", v_solvt?" and velocities":""); read_stx_conf(filename,title_solvt,atoms_solvt,x_solvt,v_solvt, &ePBC_solvt,box_solvt); fprintf(stderr,"\"%s\"\n",title_solvt); fprintf(stderr,"solvent configuration contains %d atoms in %d residues\n", atoms_solvt->nr,atoms_solvt->nres); fprintf(stderr,"\n"); /* apply pbc for solvent configuration for whole molecules */ rm_res_pbc(atoms_solvt,x_solvt,box_solvt); /* initialise van der waals arrays of solvent configuration */ mk_vdw(atoms_solvt,r_solvt,aps,r_distance); /* calculate the box multiplication factors n_box[0...DIM] */ nmol=1; for (i=0; (i < DIM);i++) { n_box[i] = 1; while (n_box[i]*box_solvt[i][i] < box[i][i]) n_box[i]++; nmol*=n_box[i]; } fprintf(stderr,"Will generate new solvent configuration of %dx%dx%d boxes\n", n_box[XX],n_box[YY],n_box[ZZ]); /* realloc atoms_solvt for the new solvent configuration */ srenew(atoms_solvt->resinfo,atoms_solvt->nres*nmol); srenew(atoms_solvt->atomname,atoms_solvt->nr*nmol); srenew(atoms_solvt->atom,atoms_solvt->nr*nmol); srenew(x_solvt,atoms_solvt->nr*nmol); if (v_solvt) srenew(v_solvt,atoms_solvt->nr*nmol); srenew(r_solvt,atoms_solvt->nr*nmol); /* generate a new solvent configuration */ genconf(atoms_solvt,x_solvt,v_solvt,r_solvt,box_solvt,n_box); #ifdef DEBUG print_stat(x_solvt,atoms_solvt->nr,box_solvt); #endif #ifdef DEBUG print_stat(x_solvt,atoms_solvt->nr,box_solvt); #endif /* Sort the solvent mixture, not the protein... */ sort_molecule(&atoms_solvt,x_solvt,v_solvt,r_solvt); /* add the two configurations */ onr=atoms->nr; onres=atoms->nres; add_conf(atoms,x,v,r,TRUE,ePBC,box,FALSE, atoms_solvt,x_solvt,v_solvt,r_solvt,TRUE,rshell,max_sol); *atoms_added=atoms->nr-onr; *residues_added=atoms->nres-onres; sfree(x_solvt); sfree(r_solvt); fprintf(stderr,"Generated solvent containing %d atoms in %d residues\n", *atoms_added,*residues_added); }