int gmx_bond(int argc,char *argv[]) { static char *desc[] = { "g_bond makes a distribution of bond lengths. If all is well a", "gaussian distribution should be made when using a harmonic potential.", "bonds are read from a single group in the index file in order i1-j1", "i2-j2 thru in-jn.[PAR]", "[TT]-tol[tt] gives the half-width of the distribution as a fraction", "of the bondlength ([TT]-blen[tt]). That means, for a bond of 0.2", "a tol of 0.1 gives a distribution from 0.18 to 0.22.[PAR]", "Option [TT]-d[tt] plots all the distances as a function of time.", "This requires a structure file for the atom and residue names in", "the output. If however the option [TT]-averdist[tt] is given (as well", "or separately) the average bond length is plotted instead." }; static char *bugs[] = { "It should be possible to get bond information from the topology." }; static real blen=-1.0,tol=0.1; static bool bAver=TRUE,bAverDist=TRUE; t_pargs pa[] = { { "-blen", FALSE, etREAL, {&blen}, "Bond length. By default length of first bond" }, { "-tol", FALSE, etREAL, {&tol}, "Half width of distribution as fraction of blen" }, { "-aver", FALSE, etBOOL, {&bAver}, "Average bond length distributions" }, { "-averdist", FALSE, etBOOL, {&bAverDist}, "Average distances (turns on -d)" } }; FILE *fp; char *grpname,*fdist; int gnx; atom_id *index; char title[STRLEN]; t_topology top; int ePBC=-1; rvec *x; matrix box; t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efNDX, NULL, NULL, ffREAD }, { efTPS, NULL, NULL, ffOPTRD }, { efXVG, "-o", "bonds", ffWRITE }, { efLOG, NULL, "bonds", ffOPTWR }, { efXVG, "-d", "distance", ffOPTWR } }; #define NFILE asize(fnm) CopyRight(stderr,argv[0]); parse_common_args(&argc,argv,PCA_CAN_VIEW | PCA_CAN_TIME | PCA_BE_NICE , NFILE,fnm,asize(pa),pa,asize(desc),desc,asize(bugs),bugs); if (bAverDist) fdist = opt2fn("-d",NFILE,fnm); else { fdist = opt2fn_null("-d",NFILE,fnm); if (fdist) read_tps_conf(ftp2fn(efTPS,NFILE,fnm),title,&top,&ePBC,&x,NULL,box, FALSE); } rd_index(ftp2fn(efNDX,NFILE,fnm),1,&gnx,&index,&grpname); if ( !even(gnx) ) fprintf(stderr,"WARNING: odd number of atoms (%d) in group!\n",gnx); fprintf(stderr,"Will gather information on %d bonds\n",gnx/2); if (!bAver) fp = ftp2FILE(efLOG,NFILE,fnm,"w"); else fp = NULL; do_bonds(fp,ftp2fn(efTRX,NFILE,fnm),opt2fn("-o",NFILE,fnm),fdist,gnx,index, blen,tol,bAver,&top,ePBC,bAverDist); do_view(opt2fn("-o",NFILE,fnm),"-nxy"); do_view(opt2fn_null("-d",NFILE,fnm),"-nxy"); thanx(stderr); return 0; }
int main() { char coordinate_input[BUFSIZ]; char ammp_output[BUFSIZ]; char dictionary[BUFSIZ]; char work[1000],keep[1000]; char atype[20],aname[20]; char *fgets(); float sigma,emin; int ifile,i,imreading,ii,myres; FILE *in1,*dict,*output,*fopen(); printf(" atom definition file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } /* now read in the atoms */ dict = fopen( dictionary, "r"); if( dict == NULL) { fprintf(stderr," sorry i can't open %s\n",dictionary); exit(0);} inkinds = 0; while ( fgets( work,256, dict) != NULL) { sscanf( work,"%s %f %f %f %f %f %f %f %f %f %f %f %f %f \n", &kinds[inkinds].type[0], &kinds[inkinds].r , &kinds[inkinds].theta , &sigma , &emin , &kinds[inkinds].Z , &kinds[inkinds].angle_inc, &kinds[inkinds].X , &kinds[inkinds].jaa , &kinds[inkinds].mass , &kinds[inkinds].charge , &kinds[inkinds].V, &kinds[inkinds].U , &kinds[inkinds].hybrid ); /* kinds[inkinds].theta *= 3.14159265/180.; */ sigma = sigma*sigma; sigma = sigma*sigma*sigma; /* kinds[inkinds].b = sqrt( 4.*emin*sigma*sigma); kinds[inkinds].a = sqrt( 4.*emin*sigma); */ kinds[inkinds].b = sqrt( emin*sigma*sigma); kinds[inkinds].a = sqrt( 2*emin*sigma); inkinds ++; if( inkinds > MAX_ATOM) { fprintf( stderr," too many kinds of atoms in dictionary\n"); exit(0); } } fclose( dict); printf(" Residue dictionary directory:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; dictionary[ifile -i ] = work[ifile]; dictionary[ifile -i +1 ] = '\0'; } ifile = ifile -i ; if( ifile == 0 ){ dictionary[ifile++] = '.'; dictionary[ifile] = '\0'; } if( dictionary[ifile-1] != '/') { ifile++; dictionary[ifile-1] = '/'; dictionary[ifile] = '\0';} printf(" atom input coordinate file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; coordinate_input[ifile -i ] = work[ifile]; coordinate_input[ifile -i +1 ] = '\0'; } printf(" AMMP file:>\n"); /* strip out the file name and put it in the right place for opening */ fgets( work,80,stdin ); for(i= 0; i<80; i++) if( work[i] != ' ') break; for( ifile = i; ifile < 80 ; ifile++) { if( work[ifile] == ' ' ) break; if( work[ifile] == '\0' ) break; if( work[ifile] == '\n' ) break; ammp_output[ifile -i ] = work[ifile]; ammp_output[ifile -i +1 ] = '\0'; } in1 = fopen( coordinate_input, "r"); output = fopen( ammp_output, "w"); if (in1 == NULL) goto NO_IN1_FILE; /* read in the first residue * stuff is read into work when the residue number changes then * work is copied into keep, so the first atom of any residue is * going to be in the keep buffer. to initialize we read the * first atom into keep */ keep[0] = '\0'; while( !(keep[0] == 'A' && keep[1] == 'T' && keep[2] == 'O' && keep[3] == 'M') && !(keep[0] == 'H'&& keep[1] == 'E' && keep[1] == 'T'&& keep[1] == 'A'&& keep[1] == 'T' ) ) { if( fgets(keep,90,in1) == NULL) { fprintf(stderr," no atoms in input file ? \n") ; NO_IN1_FILE: printf(" enter the dictionary name >\n"); fgets( keep, 90, stdin); i=0; while( (keep[i] == ' ' || keep[i] == '\t') && keep[i] != '\0') i++; for( imreading = 0; imreading < 3; imreading++) { aname[imreading] = toupper( keep[i + imreading] ); } aname[3] = '\0'; goto NO_ATOMS; } } imreading = 0; while( imreading == 0) {/* begining of imreading loop */ inres = 0; for(i=0; i< MAX_RES; i++) { mykind[i] = -1; defined[i] = -1; name[i][0] = '\0'; x[i] = 0.; y[i] = 0.; z[i] = 0.; } sscanf( &keep[22],"%d",&myres); sscanf(&keep[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&keep[11],"%s",&atype[0]); sscanf(&keep[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; for( inres = 1; inres < MAX_RES; inres ++) { /* start of reading an atom loop */ if( fgets( work,90,in1) == NULL) { imreading = 1; break; } if( work[0] != 'A' && work[0] != 'H') { imreading = 1; break; } /* printf("%s\n",work); printf("%d\n",inres); */ sscanf( &work[22],"%d",&ii); if( ii != myres ) {ii = 0; while( work[ii] != '\0'){ keep[ii] = work[ii] ; ii++;} /* inres += 1; */ break; } sscanf(&work[29],"%f %f %f",&x[inres],&y[inres],&z[inres]); sscanf(&work[11],"%s",&atype[0]); sscanf(&work[17],"%s",&aname[0]); serial[inres] = 100*myres + inres; ii = 0; for( i=0; i< 3; i++ ) { if( aname[i] == '\0') break; name[inres][ii++] = (char)tolower(aname[i]); } name[inres][ii++] = '.'; for(i=0; i< 4; i++) { if( atype[i] == '\0' ) break; name[inres][ii++] = (char)tolower(atype[i]); } name[inres][ii] = '\0'; a[inres] = 0.; b[inres] = 0.; q[inres] = 0.; mass[inres] = 1.; defined[inres] = 0; }/* end of reading an atom loop */ /* for( i=0; i< inres; i++) printf(">%s<\n",&name[i][0]); */ /* if here then all of the atoms in the residue are read in */ /* now we have to open and read the dictionary file * there could be atoms in either the residue or dictionary which * are not there i.e. oxt for a residue or a missing H */ /* prepare the filename */ NO_ATOMS: i = 0; while(dictionary[i] != '\0') { work[i] = dictionary[i]; i++;} ii = 0; while(aname[ii] != '\0') {work[i] = aname[ii]; i++; ii++;} work[i++] = '\0'; dict = fopen(work,"r"); if( dict == NULL ){ fprintf(stderr," dictionary %s not found \n", work); write_atoms(output); goto DONE; } /* read the number of atoms */ if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&natoms); read_atoms( dict,natoms ); write_atoms(output); if(fgets( work,80,dict)==NULL) { fprintf(stderr,"BAD DICTIONARY %s\n",aname); exit(0);} sscanf(work,"%d",&nbond); do_bonds( dict,nbond,output); inbondlist = nbond; nangle = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nangle); do_angle(dict,nangle,output); nhybrid = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&nhybrid); do_hybrid(dict,nhybrid,output); ntorsion = 0; if(fgets( work,80,dict)!=NULL) sscanf(work,"%d",&ntorsion); do_torsion(dict,ntorsion,output); DONE: fclose( dict ); }/* end of imreading loop */ }/* end of module main */
int main (int argc, char *argv[]) { static char usage[] = { "Calculate positions of pseudo-atoms in a model for a transmembrane channel and\n" "write output to FILE or pore.pdb and pore.itp.\n\n" " -h\t\t show help\n" " -v\t\t be verbose (= -debuglevel 30 )\n" " -debug <NUM>\t set debuglevel (0..100)\n" " -spec <NUM>\t default species id\n" " -showspec\t show hard coded species\n\n" " -o FILE\t pdb coordinate file\n" " -s FILE\t itp topology file\n" "\n" " -f <file>\t read pore description from file (see below)\n" " -R <r>\t Outer radius of the model\n" " -P <r> <l>\t Pore region: inner radius and length\n" " -M <r> <l>\t Mouth region: largest inner radius and length\n" " -b dmin dmax g_min g_max (repeatable)\n" "\t\tform bonds with angle gamma when atoms are no further apart\n" "\t\tthan dmax Ang and g_min <= gamma <= g_max, g from [0°..90°] )\n" " -c\t\t only write connectivity to output, no bond length or kB, kA\n" " -x\t\t neither connectivity nor bond length to output (isolated atoms)\n" " -kB <c>\t Force constant of bonds, in kJ mol^-1 nm^-2\n" " -kA <c>\t Force constant of angles, in kJ mol^-1 rad^-2\n" " -cc\t\t Center ccordinates on cavitybox, not on unitcell\n" "\n" "Pore volume calculation (setting any of these switches on profile calculation):\n" "In order to enable volume calculation, set -volume explicitly!\n" "ATTENTION: all these LENGTHs are in NANO METRE not Angstrom !\n" " -profile [<file>] calculate the profile in addition to the volume\n" " -z1, -z2 <z> profile between z1 and z2\n" " -Rmax <r> integrate out to Rmax (also use for the total volume\n" " integration if -profile is set)\n" " -npoints <N> number of points per dimension in the integrals\n" " -T temp Temperature in Kelvin [300]\n" " -wca If set, only use the repulsive part of the Lennard-Jones\n" " potential (split after Weeks, Chandler & Andersen [1971])\n" " -plot xfarbe output of the potential in z slices\n" " -nzplot number of plot slices \n" "\nDescription of the input file:\n" "------------------------------\n" "Instead of using -R (RADIUS), -M (MOUTH), and -P (PORE) one can describe the system\n" "in a more flexible manner with a geometry in put file. It can contain up to " "MAXDOMAINS domains (i.e. MOUTH and PORE lines). Allowed lines:\n" "# comment (skipped)\n" "# RADIUS is the global outer radius (in Angstrom) of the cylinder\n" "RADIUS r_outer\n" "# domain type and radius at the upper and lower end of the domain;\n" "# r_lower of domain i and r_upper of domain i+1 are typically identical\n" "MOUTH r_upper r_lower length [species]\n" "PORE r_upper r_lower length [species]\n" }; int i, n_atoms, n_bonds, n_angles, n_bc; int error; real vol; FILE *fp; /* segmentation fault if arrays to large --->> now that I have learned to calloc I should rewrite this on purely aesthetical grounds ! <<---- */ struct pdb_ATOM model[TOTALSITES]; struct itp_bond bonds[MAXBONDS]; struct itp_angle angles[MAXANGLES]; struct geom geometry; struct std_input in; struct potpars potential = { NULL, TEMPERATURE, NFREEDOM_SPC, CSIX_OW_MTH, CTWELVE_OW_MTH, 0.0, 0, NULL, NULL, N_GAUSSLEG }; struct pprofile profile = { "LJprofile.dat", FALSE, FALSE, POT_PLOT_SLICES, NULL, NZPROF, 1.5, -2,2, NULL }; /* argument processing */ /* *** no sanity checks *** */ n_atoms = 0; /* number of sites ('atoms') in the model */ n_bonds = 0; /* number of bonds */ n_angles = 0; /* number of angles between bonds */ n_bc = 0; /* number of constraint conditions for generating bonds */ if (argc < 2) { printf("Running with default values.\n\nType %s -h for help.\n", argv[0]); debuglevel = IMPORTANT; }; /* initialize defaults */ in = default_input (); potential.u1 = vljcyl; /* use the full Lennard-Jones potential in the configurational volume calculations by default */ profile.pp = &potential; /* rudimentary opt-processing.. yarch */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-debug")) { debuglevel = atoi(argv[++i]); } else if (!strcmp(argv[i], "-v")) { debuglevel = VERBOSE; } else if (!strcmp(argv[i], "-h")) { print_usage(argv[0],usage); exit(1); } else if (!strcmp(argv[i], "-showspec")) { print_species (); exit(1); } else if (!strcmp(argv[i], "-o")) { in.coordfile = argv[++i]; } else if (!strcmp(argv[i], "-s")) { in.topofile = argv[++i]; } else if (!strcmp(argv[i], "-f")) { in.datafile = argv[++i]; } else if (!strcmp(argv[i], "-R")) { in.r_outer = atof(argv[++i]); } else if (!strcmp(argv[i], "-M")) { in.r_mouth = atof(argv[++i]); in.l_mouth = atof(argv[++i]); } else if (!strcmp(argv[i], "-P")) { in.r_pore = atof(argv[++i]); in.l_pore = atof(argv[++i]); } else if (!strcmp(argv[i], "-spec")) { in.specid = atoi(argv[++i]); } else if (!strcmp(argv[i], "-b")) { if (n_bc > MAXBONDCONSTRAINTS) { fatal_error (1, "Error: too many bond constraints, maximum is %d.\n", MAXBONDCONSTRAINTS); } in.bc[n_bc].serial = n_bc; in.bc[n_bc].dmin = atof(argv[++i]); in.bc[n_bc].dmax = atof(argv[++i]); in.bc[n_bc].gamma_min = atof(argv[++i]); in.bc[n_bc].gamma_max = atof(argv[++i]); in.n_bc = ++n_bc; } else if (!strcmp(argv[i], "-c")) { in.connectonly = TRUE; } else if (!strcmp(argv[i], "-x")) { in.atomsonly = TRUE; } else if (!strcmp(argv[i], "-cc")) { in.shiftcbox = TRUE; } else if (!strcmp(argv[i], "-kB")) { in.k_bond = atof(argv[++i]); } else if (!strcmp(argv[i], "-kA")) { in.k_angle = atof(argv[++i]); } else if (!strcmp(argv[i], "-volume")) { profile.bSet = TRUE; } else if (!strcmp(argv[i], "-z1")) { profile.bSet = TRUE; profile.z1 = atof(argv[++i]); } else if (!strcmp(argv[i], "-z2")) { profile.bSet = TRUE; profile.z2 = atof(argv[++i]); } else if (!strcmp(argv[i], "-Rmax")) { profile.bSet = TRUE; profile.Rmax = atof(argv[++i]); } else if (!strcmp(argv[i], "-profile")) { profile.bSet = TRUE; if (i < argc-1 && argv[i+1][0] != '-') strncpy(profile.fn,argv[++i],STRLEN); } else if (!strcmp(argv[i], "-npoints")) { potential.ngaussleg = atof(argv[++i]); } else if (!strcmp(argv[i], "-T")) { potential.Temp = atof(argv[++i]); } else if (!strcmp(argv[i], "-wca")) { potential.u1 = vRljcyl; } else if (!strcmp(argv[i], "-plot")) { profile.bPlot = TRUE; } else if (!strcmp(argv[i], "-nzplot")) { profile.bPlot = TRUE; profile.nzplot = atoi(argv[++i]); } else { mesg(OFF,"Unknown option: %s",argv[i]); }; }; mesg (ALL, "TOTALSITES %d\n", TOTALSITES); mesg (ALL, "MAXBONDS %d\nsizeof struct bond %d, sizeof bonds[] %d\n", MAXBONDS, sizeof (struct itp_bond), sizeof (bonds)); mesg (ALL, "MAXANGLES %d\nsizeof struct angle %d, sizeof angles[] %d\n", MAXANGLES, sizeof (struct itp_angle), sizeof (angles)); error = input_geom (&in, &geometry); setup_domain (&geometry); unitcell (&geometry); cavitybox (&geometry); n_atoms = do_coordinates (model, &geometry); if (!geometry.atomsonly) { n_bonds = do_bonds (bonds, model, &geometry); n_angles = do_angles (angles, bonds, &geometry); } else { n_bonds = n_angles = 0; } print_geom (&geometry); mesg (WARN, "\nNumber of sites: %d", n_atoms); if (!geometry.atomsonly) { mesg (WARN, "Number of bonds: %d within max cut-off %5.2f Ang (no double-counting)", n_bonds, find_dmax (geometry.bc, geometry.nbc)); mesg (WARN, "Number of angles: %d (no double-counting)\n", n_angles); } center (model, &geometry); error = write_topology (model, bonds, angles, &geometry); error = write_pdb (model, bonds, &geometry); /* calculate pore volume, based on J. S. Rowlinson, J Chem Soc, Faraday Trans. 2, 82 (1986), 1801, (which didnt really work), and discussion with Andrew Horsefield. */ if (profile.bSet) { vol = volume(&potential,model,geometry.domain[1],&profile); /* pore profile (already calculated in volume ) */ fp=fopen(profile.fn,"w"); if (fp) { for(i=0;i<NZPROF;i++) { fprintf(fp,"%f %f\n",profile.r[i][0],profile.r[i][1]); } fclose(fp); } free(profile.r); } return error < 0 ? 1 : 0; };