Ejemplo n.º 1
0
gmx_neutron_atomic_structurefactors_t *gmx_neutronstructurefactors_init(const char *datfn)
{
    /* read nsfactor.dat */
    FILE    *fp;
    char     line[STRLEN];
    int      nralloc = 10;
    int      n, p;
    int      i, line_no;
    char     atomnm[8];
    double   slength;
    gmx_neutron_atomic_structurefactors_t   *gnsf;

    fp      = libopen(datfn);
    line_no = 0;
    /* allocate memory for structure */
    snew(gnsf, nralloc);
    snew(gnsf->atomnm, nralloc);
    snew(gnsf->p, nralloc);
    snew(gnsf->n, nralloc);
    snew(gnsf->slength, nralloc);

    gnsf->nratoms = line_no;

    while (get_a_line(fp, line, STRLEN))
    {
        i = line_no;
        if (sscanf(line, "%s %d %d %lf", atomnm, &p, &n, &slength) == 4)
        {
            gnsf->atomnm[i]  = strdup(atomnm);
            gnsf->n[i]       = n;
            gnsf->p[i]       = p;
            gnsf->slength[i] = slength;
            line_no++;
            gnsf->nratoms = line_no;
            if (line_no == nralloc)
            {
                nralloc++;
                srenew(gnsf->atomnm, nralloc);
                srenew(gnsf->p, nralloc);
                srenew(gnsf->n, nralloc);
                srenew(gnsf->slength, nralloc);
            }
        }
        else
        {
            fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n",
                    datfn, line_no);
        }
    }
    srenew(gnsf->atomnm, gnsf->nratoms);
    srenew(gnsf->p, gnsf->nratoms);
    srenew(gnsf->n, gnsf->nratoms);
    srenew(gnsf->slength, gnsf->nratoms);

    fclose(fp);

    return (gmx_neutron_atomic_structurefactors_t *) gnsf;
}
Ejemplo n.º 2
0
static void get_xlatoms(const char *fn,FILE *fp,
                        int *nptr,t_xlate_atom **xlptr)
{
    char filebase[STRLEN];
    char line[STRLEN];
    char rbuf[1024],abuf[1024],repbuf[1024],dumbuf[1024];
    char *_ptr;
    int  n,na,idum;
    t_xlate_atom *xl;

    fflib_filename_base(fn,filebase,STRLEN);

    n  = *nptr;
    xl = *xlptr;

    while (get_a_line(fp,line,STRLEN))
    {
        na = sscanf(line,"%s%s%s%s",rbuf,abuf,repbuf,dumbuf);
        /* Check if we are reading an old format file with the number of items
         * on the first line.
         */
        if (na == 1 && n == *nptr && sscanf(rbuf,"%d",&idum) == 1)
        {
            continue;
        }
        if (na != 3)
        {
            gmx_fatal(FARGS,"Expected a residue name and two atom names in file '%s', not '%s'",fn,line);
        }
        
        srenew(xl,n+1);
        xl[n].filebase = strdup(filebase);

        /* Use wildcards... */
        if (strcmp(rbuf,"*") != 0)
        {
            xl[n].res = strdup(rbuf);
        }
        else
        {
            xl[n].res = NULL;
        }
        
        /* Replace underscores in the string by spaces */
        while ((_ptr = strchr(abuf,'_')) != 0)
        {
            *_ptr = ' ';
        }
        
        xl[n].atom = strdup(abuf);
        xl[n].replace = strdup(repbuf);
        n++;
    }

    *nptr  = n;
    *xlptr = xl;
}
Ejemplo n.º 3
0
static int read_equiv(const char *eq_fn, t_equiv ***equivptr)
{
    FILE     *fp;
    char      line[STRLEN], resname[10], atomname[10], *lp;
    int       neq, na, n, resnr;
    t_equiv **equiv;

    fp    = gmx_ffopen(eq_fn, "r");
    neq   = 0;
    equiv = NULL;
    while (get_a_line(fp, line, STRLEN))
    {
        lp = line;
        /* this is not efficient, but I'm lazy */
        srenew(equiv, neq+1);
        equiv[neq] = NULL;
        na         = 0;
        if (sscanf(lp, "%s %n", atomname, &n) == 1)
        {
            lp += n;
            snew(equiv[neq], 1);
            equiv[neq][0].nname = gmx_strdup(atomname);
            while (sscanf(lp, "%d %s %s %n", &resnr, resname, atomname, &n) == 3)
            {
                /* this is not efficient, but I'm lazy (again) */
                srenew(equiv[neq], na+1);
                equiv[neq][na].set   = true;
                equiv[neq][na].rnr   = resnr-1;
                equiv[neq][na].rname = gmx_strdup(resname);
                equiv[neq][na].aname = gmx_strdup(atomname);
                if (na > 0)
                {
                    equiv[neq][na].nname = NULL;
                }
                na++;
                lp += n;
            }
        }
        /* make empty element as flag for end of array */
        srenew(equiv[neq], na+1);
        equiv[neq][na].set   = false;
        equiv[neq][na].rnr   = 0;
        equiv[neq][na].rname = NULL;
        equiv[neq][na].aname = NULL;

        /* next */
        neq++;
    }
    gmx_ffclose(fp);

    *equivptr = equiv;

    return neq;
}
Ejemplo n.º 4
0
static bool dsresult_for_clam(SOCKET &socket)
{
	char buff[BUFSIZ];
	get_a_line(socket, buff, sizeof(buff));

	if(!strstr(buff, "PONG"))
	{
		return false;
	}
			
	return true;
}
Ejemplo n.º 5
0
static gmx_bool read_atoms(FILE *in, char *line,
                           t_restp *r0, t_symtab *tab, gpp_atomtype_t atype)
{
    int    i, j, cg, maxentries;
    char   buf[256], buf1[256];
    double q;

    /* Read Atoms */
    maxentries   = 0;
    r0->atom     =     NULL;
    r0->atomname = NULL;
    r0->cgnr     =     NULL;
    i            = 0;
    while (get_a_line(in, line, STRLEN) && (strchr(line, '[') == NULL))
    {
        if (sscanf(line, "%s%s%lf%d", buf, buf1, &q, &cg) != 4)
        {
            return FALSE;
        }
        if (i >= maxentries)
        {
            maxentries += 100;
            srenew(r0->atom,     maxentries);
            srenew(r0->atomname, maxentries);
            srenew(r0->cgnr,     maxentries);
        }
        r0->atomname[i] = put_symtab(tab, buf);
        r0->atom[i].q   = q;
        r0->cgnr[i]     = cg;
        j               = get_atomtype_type(buf1, atype);
        if (j == NOTSET)
        {
            gmx_fatal(FARGS, "Atom type %s (residue %s) not found in atomtype "
                      "database", buf1, r0->resname);
        }
        r0->atom[i].type = j;
        r0->atom[i].m    = get_atomtype_massA(j, atype);
        i++;
    }
    r0->natom = i;
    srenew(r0->atom, i);
    srenew(r0->atomname, i);
    srenew(r0->cgnr, i);

    return TRUE;
}
Ejemplo n.º 6
0
gmx_bool read_bondeds(int bt, FILE *in, char *line, t_restp *rtp)
{
    char str[STRLEN];
    int  j, n, ni, maxrb;

    maxrb = rtp->rb[bt].nb;
    while (get_a_line(in, line, STRLEN) && (strchr(line, '[') == NULL))
    {
        if (rtp->rb[bt].nb >= maxrb)
        {
            maxrb += 100;
            srenew(rtp->rb[bt].b, maxrb);
        }
        n = 0;
        for (j = 0; j < btsNiatoms[bt]; j++)
        {
            if (sscanf(line+n, "%s%n", str, &ni) == 1)
            {
                rtp->rb[bt].b[rtp->rb[bt].nb].a[j] = gmx_strdup(str);
            }
            else
            {
                return FALSE;
            }
            n += ni;
        }
        for (; j < MAXATOMLIST; j++)
        {
            rtp->rb[bt].b[rtp->rb[bt].nb].a[j] = NULL;
        }
        while (isspace(line[n]))
        {
            n++;
        }
        rtrim(line+n);
        rtp->rb[bt].b[rtp->rb[bt].nb].s = gmx_strdup(line+n);
        rtp->rb[bt].nb++;
    }
    /* give back unused memory */
    srenew(rtp->rb[bt].b, rtp->rb[bt].nb);

    return TRUE;
}
Ejemplo n.º 7
0
int
gmx_residuetype_init(gmx_residuetype_t *prt)
{
    FILE *  db;
    char    line[STRLEN];
    char    resname[STRLEN],restype[STRLEN],dum[STRLEN];
    char *  p;
    int     i;
    struct gmx_residuetype *rt;
    
    snew(rt,1);
    *prt=rt;
    
    rt->n        = 0;
    rt->resname  = NULL;
    rt->restype = NULL;
    
    db=libopen("residuetypes.dat");
    
    while(get_a_line(db,line,STRLEN)) 
    {
        strip_comment(line);
        trim(line);
        if(line[0]!='\0')
        {
            if(sscanf(line,"%s %s %s",resname,restype,dum)!=2)
            {
                gmx_fatal(FARGS,"Incorrect number of columns (2 expected) for line in residuetypes.dat");
            }
            gmx_residuetype_add(rt,resname,restype);
        }
    }
    
    fclose(db);
    
    return 0;
}
Ejemplo n.º 8
0
bool MyMD::readInput() {
  char line[BLEN];
  if(get_a_line(stdin,line)) return 1;
  atoms->Init(atoi(line));
  fprintf(stderr, "%d", atoms->GetNAtoms());
  if(get_a_line(stdin,line)) return 1;
  atoms->SetMass(atof(line));
  if(get_a_line(stdin,line)) return 1;
  double epsilon=atof(line);
  if(get_a_line(stdin,line)) return 1;
  double sigma=atof(line);
  force->Init("PAIR", "LJ", epsilon, sigma);  
  if(get_a_line(stdin,line)) return 1;
  atoms->SetRadCut(atof(line));
  if(get_a_line(stdin,line)) return 1;
  atoms->SetBoxSize(atof(line));
  if(get_a_line(stdin,restfile)) return 1;
  if(get_a_line(stdin,trajfile)) return 1;
  if(get_a_line(stdin,ergfile)) return 1;
  if(get_a_line(stdin,line)) return 1;
  this->nsteps=atoi(line);
  if(get_a_line(stdin,line)) return 1;
  integrator->SetTimestep(atof(line));
  if(get_a_line(stdin,line)) return 1;
  this->nprint=atoi(line);
}
Ejemplo n.º 9
0
/* main */
int main(int argc, char **argv) 
{
    int nprint, i;
    char restfile[BLEN], trajfile[BLEN], ergfile[BLEN], line[BLEN];
    FILE *fp,*traj,*erg;
    mdsys_t sys;

#if defined(_OPENMP)
#pragma omp parallel
    {
        if(0 == omp_get_thread_num()) {
            sys.nthreads=omp_get_num_threads();
            printf("Running OpenMP version using %d threads\n", sys.nthreads);
        }
    }
#else
    sys.nthreads=1;
#endif

    /* read input file */
    if(get_a_line(stdin,line)) return 1;
    sys.natoms=atoi(line);
    if(get_a_line(stdin,line)) return 1;
    sys.mass=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.epsilon=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.sigma=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.rcut=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.box=atof(line);
    if(get_a_line(stdin,restfile)) return 1;
    if(get_a_line(stdin,trajfile)) return 1;
    if(get_a_line(stdin,ergfile)) return 1;
    if(get_a_line(stdin,line)) return 1;
    sys.nsteps=atoi(line);
    if(get_a_line(stdin,line)) return 1;
    sys.dt=atof(line);
    if(get_a_line(stdin,line)) return 1;
    nprint=atoi(line);

    /* allocate memory */
    sys.pos=(double *)malloc(3*sys.natoms*sizeof(double));
    sys.vel=(double *)malloc(3*sys.natoms*sizeof(double));
    sys.frc=(double *)malloc(sys.nthreads*3*sys.natoms*sizeof(double));

    /* read restart */
    fp=fopen(restfile,"r");
    if(fp) {
        int natoms;
        natoms=sys.natoms;
        
        for (i=0; i<natoms; ++i) {
            fscanf(fp,"%lf%lf%lf",sys.pos+i, sys.pos+natoms+i, sys.pos+2*natoms+i);
        }
        for (i=0; i<natoms; ++i) {
            fscanf(fp,"%lf%lf%lf",sys.vel+i, sys.vel+natoms+i, sys.vel+2*natoms+i);
        }
        fclose(fp);
        azzero(sys.frc, 3*sys.nthreads*sys.natoms);
    } else {
        perror("cannot read restart file");
        return 3;
    }

    /* initialize forces and energies.*/
    sys.nfi=0;
    sys.clist=NULL;
    sys.plist=NULL;
    updcells(&sys);
    force(&sys);
    ekin(&sys);
    
    erg=fopen(ergfile,"w");
    traj=fopen(trajfile,"w");

    printf("Starting simulation with %d atoms for %d steps.\n",sys.natoms, sys.nsteps);
    printf("     NFI            TEMP            EKIN                 EPOT              ETOT\n");
    output(&sys, erg, traj);

    /**************************************************/
    /* main MD loop */
    for(sys.nfi=1; sys.nfi <= sys.nsteps; ++sys.nfi) {

        /* write output, if requested */
        if ((sys.nfi % nprint) == 0) 
            output(&sys, erg, traj);

        /* propagate system and recompute energies */
        velverlet(&sys);
        ekin(&sys);

        /* update cell list */
        if ((sys.nfi % cellfreq) == 0) 
            updcells(&sys);
    }
    /**************************************************/

    /* clean up: close files, free memory */
    printf("Simulation Done.\n");
    fclose(erg);
    fclose(traj);
    free(sys.pos);
    free(sys.vel);
    free(sys.frc);
    free_cell_list(&sys);

    return 0;
}
Ejemplo n.º 10
0
void read_resall(char *rrdb, int *nrtpptr, t_restp **rtp,
                 gpp_atomtype_t atype, t_symtab *tab,
                 gmx_bool bAllowOverrideRTP)
{
    FILE         *in;
    char          filebase[STRLEN], line[STRLEN], header[STRLEN];
    int           i, nrtp, maxrtp, bt, nparam;
    int           dum1, dum2, dum3;
    t_restp      *rrtp, *header_settings;
    gmx_bool      bNextResidue, bError;
    int           firstrtp;

    fflib_filename_base(rrdb, filebase, STRLEN);

    in = fflib_open(rrdb);

    if (debug)
    {
        fprintf(debug, "%9s %5s", "Residue", "atoms");
        for (i = 0; i < ebtsNR; i++)
        {
            fprintf(debug, " %10s", btsNames[i]);
        }
        fprintf(debug, "\n");
    }
    snew(header_settings, 1);

    /* these bonded parameters will overwritten be when  *
     * there is a [ bondedtypes ] entry in the .rtp file */
    header_settings->rb[ebtsBONDS].type  = 1; /* normal bonds     */
    header_settings->rb[ebtsANGLES].type = 1; /* normal angles    */
    header_settings->rb[ebtsPDIHS].type  = 1; /* normal dihedrals */
    header_settings->rb[ebtsIDIHS].type  = 2; /* normal impropers */
    header_settings->rb[ebtsEXCLS].type  = 1; /* normal exclusions */
    header_settings->rb[ebtsCMAP].type   = 1; /* normal cmap torsions */

    header_settings->bKeepAllGeneratedDihedrals    = FALSE;
    header_settings->nrexcl                        = 3;
    header_settings->bGenerateHH14Interactions     = TRUE;
    header_settings->bRemoveDihedralIfWithImproper = TRUE;

    /* Column 5 & 6 aren't really bonded types, but we include
     * them here to avoid introducing a new section:
     * Column 5 : This controls the generation of dihedrals from the bonding.
     *            All possible dihedrals are generated automatically. A value of
     *            1 here means that all these are retained. A value of
     *            0 here requires generated dihedrals be removed if
     *              * there are any dihedrals on the same central atoms
     *                specified in the residue topology, or
     *              * there are other identical generated dihedrals
     *                sharing the same central atoms, or
     *              * there are other generated dihedrals sharing the
     *                same central bond that have fewer hydrogen atoms
     * Column 6: Number of bonded neighbors to exclude.
     * Column 7: Generate 1,4 interactions between two hydrogen atoms
     * Column 8: Remove proper dihedrals if centered on the same bond
     *           as an improper dihedral
     */
    get_a_line(in, line, STRLEN);
    if (!get_header(line, header))
    {
        gmx_fatal(FARGS, "in .rtp file at line:\n%s\n", line);
    }
    if (gmx_strncasecmp("bondedtypes", header, 5) == 0)
    {
        get_a_line(in, line, STRLEN);
        if ((nparam = sscanf(line, "%d %d %d %d %d %d %d %d",
                             &header_settings->rb[ebtsBONDS].type, &header_settings->rb[ebtsANGLES].type,
                             &header_settings->rb[ebtsPDIHS].type, &header_settings->rb[ebtsIDIHS].type,
                             &dum1, &header_settings->nrexcl, &dum2, &dum3)) < 4)
        {
            gmx_fatal(FARGS, "need 4 to 8 parameters in the header of .rtp file %s at line:\n%s\n", rrdb, line);
        }
        header_settings->bKeepAllGeneratedDihedrals    = (dum1 != 0);
        header_settings->bGenerateHH14Interactions     = (dum2 != 0);
        header_settings->bRemoveDihedralIfWithImproper = (dum3 != 0);
        get_a_line(in, line, STRLEN);
        if (nparam < 5)
        {
            fprintf(stderr, "Using default: not generating all possible dihedrals\n");
            header_settings->bKeepAllGeneratedDihedrals = FALSE;
        }
        if (nparam < 6)
        {
            fprintf(stderr, "Using default: excluding 3 bonded neighbors\n");
            header_settings->nrexcl = 3;
        }
        if (nparam < 7)
        {
            fprintf(stderr, "Using default: generating 1,4 H--H interactions\n");
            header_settings->bGenerateHH14Interactions = TRUE;
        }
        if (nparam < 8)
        {
            fprintf(stderr, "Using default: removing proper dihedrals found on the same bond as a proper dihedral\n");
            header_settings->bRemoveDihedralIfWithImproper = TRUE;
        }
    }
    else
    {
        fprintf(stderr,
                "Reading .rtp file without '[ bondedtypes ]' directive,\n"
                "Will proceed as if the entry was:\n");
        print_resall_header(stderr, header_settings);
    }
    /* We don't know the current size of rrtp, but simply realloc immediately */
    nrtp   = *nrtpptr;
    rrtp   = *rtp;
    maxrtp = nrtp;
    while (!feof(in))
    {
        if (nrtp >= maxrtp)
        {
            maxrtp += 100;
            srenew(rrtp, maxrtp);
        }

        /* Initialise rtp entry structure */
        rrtp[nrtp] = *header_settings;
        if (!get_header(line, header))
        {
            gmx_fatal(FARGS, "in .rtp file at line:\n%s\n", line);
        }
        rrtp[nrtp].resname  = gmx_strdup(header);
        rrtp[nrtp].filebase = gmx_strdup(filebase);

        get_a_line(in, line, STRLEN);
        bError       = FALSE;
        bNextResidue = FALSE;
        do
        {
            if (!get_header(line, header))
            {
                bError = TRUE;
            }
            else
            {
                bt = get_bt(header);
                if (bt != NOTSET)
                {
                    /* header is an bonded directive */
                    bError = !read_bondeds(bt, in, line, &rrtp[nrtp]);
                }
                else if (gmx_strncasecmp("atoms", header, 5) == 0)
                {
                    /* header is the atoms directive */
                    bError = !read_atoms(in, line, &(rrtp[nrtp]), tab, atype);
                }
                else
                {
                    /* else header must be a residue name */
                    bNextResidue = TRUE;
                }
            }
            if (bError)
            {
                gmx_fatal(FARGS, "in .rtp file in residue %s at line:\n%s\n",
                          rrtp[nrtp].resname, line);
            }
        }
        while (!feof(in) && !bNextResidue);

        if (rrtp[nrtp].natom == 0)
        {
            gmx_fatal(FARGS, "No atoms found in .rtp file in residue %s\n",
                      rrtp[nrtp].resname);
        }
        if (debug)
        {
            fprintf(debug, "%3d %5s %5d",
                    nrtp+1, rrtp[nrtp].resname, rrtp[nrtp].natom);
            for (i = 0; i < ebtsNR; i++)
            {
                fprintf(debug, " %10d", rrtp[nrtp].rb[i].nb);
            }
            fprintf(debug, "\n");
        }

        firstrtp = -1;
        for (i = 0; i < nrtp; i++)
        {
            if (gmx_strcasecmp(rrtp[i].resname, rrtp[nrtp].resname) == 0)
            {
                firstrtp = i;
            }
        }

        if (firstrtp == -1)
        {
            nrtp++;
            fprintf(stderr, "\rResidue %d", nrtp);
            fflush(stderr);
        }
        else
        {
            if (firstrtp >= *nrtpptr)
            {
                gmx_fatal(FARGS, "Found a second entry for '%s' in '%s'",
                          rrtp[nrtp].resname, rrdb);
            }
            if (bAllowOverrideRTP)
            {
                fprintf(stderr, "\n");
                fprintf(stderr, "Found another rtp entry for '%s' in '%s', ignoring this entry and keeping the one from '%s.rtp'\n",
                        rrtp[nrtp].resname, rrdb, rrtp[firstrtp].filebase);
                /* We should free all the data for this entry.
                 * The current code gives a lot of dangling pointers.
                 */
                clear_t_restp(&rrtp[nrtp]);
            }
            else
            {
                gmx_fatal(FARGS, "Found rtp entries for '%s' in both '%s' and '%s'. If you want the first definition to override the second one, set the -rtpo option of pdb2gmx.", rrtp[nrtp].resname, rrtp[firstrtp].filebase, rrdb);
            }
        }
    }
    gmx_ffclose(in);
    /* give back unused memory */
    srenew(rrtp, nrtp);

    fprintf(stderr, "\nSorting it all out...\n");
    qsort(rrtp, nrtp, (size_t)sizeof(rrtp[0]), comprtp);

    check_rtp(nrtp, rrtp, rrdb);

    *nrtpptr = nrtp;
    *rtp     = rrtp;
}
Ejemplo n.º 11
0
int read_ter_db(char *FF,char ter,t_hackblock **tbptr,gpp_atomtype_t atype)
{
    FILE       *in;
    char       inf[STRLEN],header[STRLEN],buf[STRLEN],line[STRLEN];
    t_hackblock *tb;
    int        i,j,n,ni,kwnr,nb,maxnb,nh;

    sprintf(inf,"%s-%c.tdb",FF,ter);
    in=libopen(inf);
    if (debug)
        fprintf(debug,"Opened %s\n",inf);

    tb=NULL;
    nb=-1;
    maxnb=0;
    kwnr=NOTSET;
    get_a_line(in,line,STRLEN);
    while (!feof(in)) {
        if (get_header(line,header)) {
            /* this is a new block, or a new keyword */
            kwnr=find_kw(header);

            if (kwnr == NOTSET) {
                nb++;
                /* here starts a new block */
                if ( nb >= maxnb ) {
                    maxnb+=100;
                    srenew(tb,maxnb);
                }
                clear_t_hackblock(&tb[nb]);
                tb[nb].name=strdup(header);
            }
        } else {
            if (nb < 0)
                gmx_fatal(FARGS,"reading termini database: "
                          "directive expected before line:\n%s\n"
                          "This might be a file in an old format.",line);
            /* this is not a header, so it must be data */
            if (kwnr >= ebtsNR) {
                /* this is a hack: add/rename/delete atoms */
                /* make space for hacks */
                if (tb[nb].nhack >= tb[nb].maxhack) {
                    tb[nb].maxhack+=10;
                    srenew(tb[nb].hack, tb[nb].maxhack);
                }
                nh=tb[nb].nhack;
                clear_t_hack(&(tb[nb].hack[nh]));
                for(i=0; i<4; i++)
                    tb[nb].hack[nh].a[i]=NULL;
                tb[nb].nhack++;

                /* get data */
                n=0;
                if ( kwnr==ekwRepl || kwnr==ekwDel ) {
                    if (sscanf(line, "%s%n", buf, &n) != 1)
                        gmx_fatal(FARGS,"Reading Termini Database: "
                                  "expected atom name on line\n%s",line);
                    tb[nb].hack[nh].oname = strdup(buf);
                    /* we only replace or delete one atom at a time */
                    tb[nb].hack[nh].nr = 1;
                } else if ( kwnr==ekwAdd ) {
                    read_ab(line, inf, &(tb[nb].hack[nh]));
                    get_a_line(in, line, STRLEN);
                } else
                    gmx_fatal(FARGS,"unimplemented keyword number %d (%s:%d)",
                              kwnr,__FILE__,__LINE__);
                if ( kwnr==ekwRepl || kwnr==ekwAdd ) {
                    snew(tb[nb].hack[nh].atom, 1);
                    read_atom(line+n, tb[nb].hack[nh].atom, atype,
                              &tb[nb].hack[nh].cgnr);
                    if (!tb[nb].hack[nh].nname) {
                        if (tb[nb].hack[nh].oname)
                            tb[nb].hack[nh].nname = strdup(tb[nb].hack[nh].oname);
                        else
                            gmx_fatal(FARGS,"Don't know which name the new atom should have");
                    }
                }
            } else if (kwnr >= 0 && kwnr < ebtsNR) {
                /* this is bonded data: bonds, angles, dihedrals or impropers */
                srenew(tb[nb].rb[kwnr].b,tb[nb].rb[kwnr].nb+1);
                n=0;
                for(j=0; j<btsNiatoms[kwnr]; j++) {
                    if ( sscanf(line+n, "%s%n", buf, &ni) == 1 )
                        tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = strdup(buf);
                    else
                        gmx_fatal(FARGS,"Reading Termini Database: expected %d atom names (found %d) on line\n%s", btsNiatoms[kwnr], j-1, line);
                    n+=ni;
                }
                for(   ; j<MAXATOMLIST; j++)
                    tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = NULL;
                strcpy(buf, "");
                sscanf(line+n, "%s", buf);
                tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = strdup(buf);
                tb[nb].rb[kwnr].nb++;
            } else
                gmx_fatal(FARGS,"Reading Termini Database: Expecting a header at line\n"
                          "%s",line);
        }
        get_a_line(in,line,STRLEN);
    }
    nb++;
    srenew(tb,nb);

    fclose(in);

    if (debug)
        print_ter_db(FF,ter,nb,tb,atype);

    *tbptr=tb;
    return nb;
}
Ejemplo n.º 12
0
void
choose_ff(const char *ffsel,
          char *forcefield, int ff_maxlen,
          char *ffdir, int ffdir_maxlen)
{
    int  nff;
    char **ffdirs,**ffs,**ffs_dir,*ptr;
    int  i,j,sel,cwdsel,nfound;
    char buf[STRLEN],**desc;
    FILE *fp;
    char *pret;
    
    nff = fflib_search_file_in_dirend(fflib_forcefield_itp(),
                                      fflib_forcefield_dir_ext(),
                                      &ffdirs);

    if (nff == 0)
    {
        gmx_fatal(FARGS,"No force fields found (files with name '%s' in subdirectories ending on '%s')",
                  fflib_forcefield_itp(),fflib_forcefield_dir_ext());
    }

    /* Replace with unix path separators */
    if(DIR_SEPARATOR!='/')
    {
        for(i=0;i<nff;i++)
        {
            while( (ptr=strchr(ffdirs[i],DIR_SEPARATOR))!=NULL )
            {
                *ptr='/';
            }
        }
    }
    
    /* Store the force field names in ffs */
    snew(ffs,nff);
    snew(ffs_dir,nff);
    for(i=0; i<nff; i++)
    {
        /* Remove the path from the ffdir name - use our unix standard here! */
        ptr = strrchr(ffdirs[i],'/');
        if (ptr == NULL)
        {
            ffs[i] = strdup(ffdirs[i]);
            ffs_dir[i] = low_gmxlibfn(ffdirs[i],FALSE,FALSE);
            if (ffs_dir[i] == NULL)
            {
                gmx_fatal(FARGS,"Can no longer find file '%s'",ffdirs[i]);
            }
        }
        else
        {
            ffs[i] = strdup(ptr+1);
            ffs_dir[i] = strdup(ffdirs[i]);
        }
        ffs_dir[i][strlen(ffs_dir[i])-strlen(ffs[i])-1] = '\0';
        /* Remove the extension from the ffdir name */
        ffs[i][strlen(ffs[i])-strlen(fflib_forcefield_dir_ext())] = '\0';
    }

    if (ffsel != NULL)
    {
        sel     = -1;
        cwdsel  = -1;
        nfound  = 0;
        for(i=0; i<nff; i++)
        {
            if ( strcmp(ffs[i],ffsel)==0 )
            {
                /* Matching ff name */
                sel = i;
                nfound++;
                
                if( strncmp(ffs_dir[i],".",1)==0 )
                {
                    cwdsel = i;
                }
            }
        }
        
        if(cwdsel != -1)
        {
            sel = cwdsel;
        }
        
        if(nfound>1)
        {
            if(cwdsel!=-1)
            {
                fprintf(stderr,
                        "Force field '%s' occurs in %d places. pdb2gmx is using the one in the\n"
                        "current directory. Use interactive selection (not the -ff option) if\n"
                        "you would prefer a different one.\n",ffsel,nfound);
            }
            else
            {
                gmx_fatal(FARGS,
                          "Force field '%s' occurs in %d places, but not in the current directory.\n"
                          "Run without the -ff switch and select the force field interactively.",ffsel,nfound);
            }
        }
        else if (nfound==0)
        {
            gmx_fatal(FARGS,"Could not find force field '%s' in current directory, install tree or GMXDATA path.",ffsel);
        }
    }
    else if (nff > 1)
    {
        snew(desc,nff);
        for(i=0; (i<nff); i++)
        {
            sprintf(buf,"%s%c%s%s%c%s",
                    ffs_dir[i],DIR_SEPARATOR,
                    ffs[i],fflib_forcefield_dir_ext(),DIR_SEPARATOR,
                    fflib_forcefield_doc());
            if (gmx_fexist(buf))
            {
                /* We don't use fflib_open, because we don't want printf's */
                fp = ffopen(buf,"r");
                snew(desc[i],STRLEN);
                get_a_line(fp,desc[i],STRLEN);
                ffclose(fp);
            }
            else
            {
                desc[i] = strdup(ffs[i]);
            }
        }
        /* Order force fields from the same dir alphabetically
         * and put deprecated force fields at the end.
         */
        for(i=0; (i<nff); i++)
        {
            for(j=i+1; (j<nff); j++)
            {
                if (strcmp(ffs_dir[i],ffs_dir[j]) == 0 &&
                    ((desc[i][0] == '[' && desc[j][0] != '[') ||
                     ((desc[i][0] == '[' || desc[j][0] != '[') &&
                      gmx_strcasecmp(desc[i],desc[j]) > 0)))
                {
                    swap_strings(ffdirs,i,j);
                    swap_strings(ffs   ,i,j);
                    swap_strings(desc  ,i,j);
                }
            }
        }

        printf("\nSelect the Force Field:\n");
        for(i=0; (i<nff); i++)
        {
            if (i == 0 || strcmp(ffs_dir[i-1],ffs_dir[i]) != 0)
            {
                if( strcmp(ffs_dir[i],".")==0 )
                {
                    printf("From current directory:\n");
                }
                else
                {
                    printf("From '%s':\n",ffs_dir[i]);
                }
            }
            printf("%2d: %s\n",i+1,desc[i]);
            sfree(desc[i]);
        }
        sfree(desc);

        do
        {
            pret = fgets(buf,STRLEN,stdin);
            
            if (pret != NULL)
            {
                sscanf(buf,"%d",&sel);
                sel--;
            }
        }
        while ( pret==NULL || (sel < 0) || (sel >= nff));
    }
    else
    {
        sel = 0;
    }

    if (strlen(ffs[sel]) >= (size_t)ff_maxlen)
    {
        gmx_fatal(FARGS,"Length of force field name (%d) >= maxlen (%d)",
                  strlen(ffs[sel]),ff_maxlen);
    }
    strcpy(forcefield,ffs[sel]);

    if (strlen(ffdirs[sel]) >= (size_t)ffdir_maxlen)
    {
        gmx_fatal(FARGS,"Length of force field dir (%d) >= maxlen (%d)",
                  strlen(ffdirs[sel]),ffdir_maxlen);
    }
    strcpy(ffdir,ffdirs[sel]);

    for(i=0; (i<nff); i++)
    {
        sfree(ffdirs[i]);
        sfree(ffs[i]);
        sfree(ffs_dir[i]);
    }
    sfree(ffdirs);
    sfree(ffs);
    sfree(ffs_dir);
}
Ejemplo n.º 13
0
void choose_watermodel(const char *wmsel,const char *ffdir,
                       char **watermodel)
{
    const char *fn_watermodels="watermodels.dat";
    char fn_list[STRLEN];
    FILE *fp;
    char buf[STRLEN];
    int  nwm,sel,i;
    char **model;
    char *pret;

    if (strcmp(wmsel,"none") == 0)
    {
        *watermodel = NULL;
        
        return;
    }
    else if (strcmp(wmsel,"select") != 0)
    {
        *watermodel = strdup(wmsel);

        return;
    }

    sprintf(fn_list,"%s%c%s",ffdir,DIR_SEPARATOR,fn_watermodels);
    
    if (!fflib_fexist(fn_list))
    {
        fprintf(stderr,"No file '%s' found, will not include a water model\n",
                fn_watermodels);
        *watermodel = NULL;
        
        return;
    }

    fp = fflib_open(fn_list);
    printf("\nSelect the Water Model:\n");
    nwm = 0;
    model = NULL;
    while (get_a_line(fp,buf,STRLEN))
    {
        srenew(model,nwm+1);
        snew(model[nwm],STRLEN);
        sscanf(buf,"%s%n",model[nwm],&i);
        if (i > 0)
        {
            ltrim(buf+i);
            fprintf(stderr,"%2d: %s\n",nwm+1,buf+i);
            nwm++;
        }
        else
        {
            sfree(model[nwm]);
        }
    }
    fclose(fp);
    fprintf(stderr,"%2d: %s\n",nwm+1,"None");

    do
    {
        pret = fgets(buf,STRLEN,stdin);
        
        if (pret != NULL)
        {
            sscanf(buf,"%d",&sel);
            sel--;
        }
    }
    while (pret == NULL || sel < 0 || sel > nwm);

    if (sel == nwm)
    {
        *watermodel = NULL;
    }
    else
    {
        *watermodel = strdup(model[sel]);
    }

    for(i=0; i<nwm; i++)
    {
        sfree(model[i]);
    }
    sfree(model);
}
Ejemplo n.º 14
0
/* main */
int main(int argc, char **argv) 
{

    omp_set_num_threads(MY_NUM_THREADS);
    
    clock_t start,end;  //timing variables
    double time_spent;

    int nprint, i;
    char restfile[BLEN], trajfile[BLEN], ergfile[BLEN], line[BLEN];
    FILE *fp,*traj,*erg;
    mdsys_t sys;

    /* read input file */
    if(get_a_line(stdin,line)) return 1;
    sys.natoms=atoi(line);
    if(get_a_line(stdin,line)) return 1;
    sys.mass=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.epsilon=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.sigma=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.rcut=atof(line);
    if(get_a_line(stdin,line)) return 1;
    sys.box=atof(line);
    if(get_a_line(stdin,restfile)) return 1;
    if(get_a_line(stdin,trajfile)) return 1;
    if(get_a_line(stdin,ergfile)) return 1;
    if(get_a_line(stdin,line)) return 1;
    sys.nsteps=atoi(line);
    if(get_a_line(stdin,line)) return 1;
    sys.dt=atof(line);
    if(get_a_line(stdin,line)) return 1;
    nprint=atoi(line);

    /* allocate memory */
    sys.rx=(double *)malloc(sys.natoms*sizeof(double));
    sys.ry=(double *)malloc(sys.natoms*sizeof(double));
    sys.rz=(double *)malloc(sys.natoms*sizeof(double));
    sys.vx=(double *)malloc(sys.natoms*sizeof(double));
    sys.vy=(double *)malloc(sys.natoms*sizeof(double));
    sys.vz=(double *)malloc(sys.natoms*sizeof(double));
    sys.fx=(double *)malloc(sys.natoms*sizeof(double));
    sys.fy=(double *)malloc(sys.natoms*sizeof(double));
    sys.fz=(double *)malloc(sys.natoms*sizeof(double));

    /* read restart */
    fp=fopen(restfile,"r");
    if(fp) {
        for (i=0; i<sys.natoms; ++i) {
            fscanf(fp,"%lf%lf%lf",sys.rx+i, sys.ry+i, sys.rz+i);
        }
        for (i=0; i<sys.natoms; ++i) {
            fscanf(fp,"%lf%lf%lf",sys.vx+i, sys.vy+i, sys.vz+i);
        }
        fclose(fp);
        azzero(sys.fx, sys.natoms);
        azzero(sys.fy, sys.natoms);
        azzero(sys.fz, sys.natoms);
    } else {
        perror("cannot read restart file");
        return 3;
    }

    /* initialize forces and energies.*/
    sys.nfi=0;
    force(&sys);
    ekin(&sys);
    
    erg=fopen(ergfile,"w");
    traj=fopen(trajfile,"w");

    printf("Starting simulation with %d atoms for %d steps.\n",sys.natoms, sys.nsteps);
    printf("     NFI            TEMP            EKIN                 EPOT              ETOT\n");
    output(&sys, erg, traj);

	//Start timing
	start = clock();

    /**************************************************/
    /* main MD loop */
    for(sys.nfi=1; sys.nfi <= sys.nsteps; ++sys.nfi) {

        /* write output, if requested */
        if ((sys.nfi % nprint) == 0)
            output(&sys, erg, traj);

        /* propagate system and recompute energies */

        velverlet1(&sys);	//Velocity verlet Part 1

	/* compute forces and potential energy */
	force(&sys);

        velverlet2(&sys);	//Velocity verlet Part 2

        ekin(&sys);
    }
    /**************************************************/
	end = clock();
	//end timing
    time_spent = (double) (end - start) / CLOCKS_PER_SEC;

    /* clean up: close files, free memory */
    printf("Simulation Done.\n");
    printf("Timing: %f Seconds.\n", time_spent);
    fclose(erg);
    fclose(traj);

    free(sys.rx);
    free(sys.ry);
    free(sys.rz);
    free(sys.vx);
    free(sys.vy);
    free(sys.vz);
    free(sys.fx);
    free(sys.fy);
    free(sys.fz);

    return 0;
}
Ejemplo n.º 15
0
static void read_ter_db_file(const char *fn,
                             int *ntbptr, t_hackblock **tbptr,
                             gpp_atomtype_t atype)
{
    char         filebase[STRLEN], *ptr;
    FILE        *in;
    char         header[STRLEN], buf[STRLEN], line[STRLEN];
    t_hackblock *tb;
    int          i, j, n, ni, kwnr, nb, maxnb, nh;

    fflib_filename_base(fn, filebase, STRLEN);
    /* Remove the C/N termini extension */
    ptr = strrchr(filebase, '.');
    if (ptr != nullptr)
    {
        ptr[0] = '\0';
    }

    in = fflib_open(fn);

    tb    = *tbptr;
    nb    = *ntbptr - 1;
    maxnb = 0;
    kwnr  = NOTSET;
    get_a_line(in, line, STRLEN);
    while (!feof(in))
    {
        if (get_header(line, header))
        {
            /* this is a new block, or a new keyword */
            kwnr = find_kw(header);

            if (kwnr == NOTSET)
            {
                nb++;
                /* here starts a new block */
                if (nb >= maxnb)
                {
                    maxnb = nb + 100;
                    srenew(tb, maxnb);
                }
                clear_t_hackblock(&tb[nb]);
                tb[nb].name     = gmx_strdup(header);
                tb[nb].filebase = gmx_strdup(filebase);
            }
        }
        else
        {
            if (nb < 0)
            {
                gmx_fatal(FARGS, "reading termini database: "
                          "directive expected before line:\n%s\n"
                          "This might be a file in an old format.", line);
            }
            /* this is not a header, so it must be data */
            if (kwnr >= ebtsNR)
            {
                /* this is a hack: add/rename/delete atoms */
                /* make space for hacks */
                if (tb[nb].nhack >= tb[nb].maxhack)
                {
                    tb[nb].maxhack += 10;
                    srenew(tb[nb].hack, tb[nb].maxhack);
                }
                nh = tb[nb].nhack;
                clear_t_hack(&(tb[nb].hack[nh]));
                for (i = 0; i < 4; i++)
                {
                    tb[nb].hack[nh].a[i] = nullptr;
                }
                tb[nb].nhack++;

                /* get data */
                n = 0;
                if (kwnr == ekwRepl || kwnr == ekwDel)
                {
                    if (sscanf(line, "%s%n", buf, &n) != 1)
                    {
                        gmx_fatal(FARGS, "Reading Termini Database '%s': "
                                  "expected atom name on line\n%s", fn, line);
                    }
                    tb[nb].hack[nh].oname = gmx_strdup(buf);
                    /* we only replace or delete one atom at a time */
                    tb[nb].hack[nh].nr = 1;
                }
                else if (kwnr == ekwAdd)
                {
                    read_ab(line, fn, &(tb[nb].hack[nh]));
                    get_a_line(in, line, STRLEN);
                }
                else
                {
                    gmx_fatal(FARGS, "unimplemented keyword number %d (%s:%d)",
                              kwnr, __FILE__, __LINE__);
                }
                if (kwnr == ekwRepl || kwnr == ekwAdd)
                {
                    snew(tb[nb].hack[nh].atom, 1);
                    read_atom(line+n, kwnr == ekwAdd,
                              &tb[nb].hack[nh].nname, tb[nb].hack[nh].atom, atype,
                              &tb[nb].hack[nh].cgnr);
                    if (tb[nb].hack[nh].nname == nullptr)
                    {
                        if (tb[nb].hack[nh].oname != nullptr)
                        {
                            tb[nb].hack[nh].nname = gmx_strdup(tb[nb].hack[nh].oname);
                        }
                        else
                        {
                            gmx_fatal(FARGS, "Reading Termini Database '%s': don't know which name the new atom should have on line\n%s", fn, line);
                        }
                    }
                }
            }
            else if (kwnr >= 0 && kwnr < ebtsNR)
            {
                /* this is bonded data: bonds, angles, dihedrals or impropers */
                srenew(tb[nb].rb[kwnr].b, tb[nb].rb[kwnr].nb+1);
                n = 0;
                for (j = 0; j < btsNiatoms[kwnr]; j++)
                {
                    if (sscanf(line+n, "%s%n", buf, &ni) == 1)
                    {
                        tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = gmx_strdup(buf);
                    }
                    else
                    {
                        gmx_fatal(FARGS, "Reading Termini Database '%s': expected %d atom names (found %d) on line\n%s", fn, btsNiatoms[kwnr], j-1, line);
                    }
                    n += ni;
                }
                for (; j < MAXATOMLIST; j++)
                {
                    tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].a[j] = nullptr;
                }
                strcpy(buf, "");
                sscanf(line+n, "%s", buf);
                tb[nb].rb[kwnr].b[tb[nb].rb[kwnr].nb].s = gmx_strdup(buf);
                tb[nb].rb[kwnr].nb++;
            }
            else
            {
                gmx_fatal(FARGS, "Reading Termini Database: Expecting a header at line\n"
                          "%s", line);
            }
        }
        get_a_line(in, line, STRLEN);
    }
    nb++;
    srenew(tb, nb);

    gmx_ffclose(in);

    *ntbptr = nb;
    *tbptr  = tb;
}
Ejemplo n.º 16
0
t_blocka *init_index(const char *gfile, char ***grpname)
{
  FILE     *in;
  t_blocka  *b;
  int      a,maxentries;
  int      i,j,ng,nread;
  char     line[STRLEN],*pt,str[STRLEN];

  in=gmx_fio_fopen(gfile,"r");
  snew(b,1);
  get_a_line(in,line,STRLEN);
  if ( line[0]=='[' ) {
    /* new format */
    b->nr=0;
    b->index=NULL;
    b->nra=0;
    b->a=NULL;
    *grpname=NULL;
    maxentries=0;
    do {
      if (get_header(line,str)) {
	b->nr++;
	srenew(b->index,b->nr+1);
	srenew(*grpname,b->nr);
	if (b->nr==1)
	  b->index[0]=0;
	b->index[b->nr]=b->index[b->nr-1];
	(*grpname)[b->nr-1]=strdup(str);
      } else {
	pt=line;
	while ((i=sscanf(pt,"%s",str)) == 1) {
	  i=b->index[b->nr];
	  if (i>=maxentries) {
	    maxentries+=1024;
	    srenew(b->a,maxentries);
	  }
	  b->a[i]=strtol(str, NULL, 10)-1;
	  b->index[b->nr]++;
	  (b->nra)++;
	  pt=strstr(pt,str)+strlen(str);
	}
      }
    } while (get_a_line(in,line,STRLEN));
  } 
  else {
    /* old format */
    sscanf(line,"%d%d",&b->nr,&b->nra);
    snew(b->index,b->nr+1);
    snew(*grpname,b->nr);
    b->index[0]=0;
    snew(b->a,b->nra);
    for (i=0; (i<b->nr); i++) {
      nread=fscanf(in,"%s%d",str,&ng);
      (*grpname)[i]=strdup(str);
      b->index[i+1]=b->index[i]+ng;
      if (b->index[i+1] > b->nra)
	gmx_fatal(FARGS,"Something wrong in your indexfile at group %s",str);
      for(j=0; (j<ng); j++) {
	nread=fscanf(in,"%d",&a);
	b->a[b->index[i]+j]=a;
      }
    }
  }
  gmx_fio_fclose(in);

  for(i=0; (i<b->nr); i++) {
    for(j=b->index[i]; (j<b->index[i+1]); j++) {
      if (b->a[j] < 0) 
	fprintf(stderr,"\nWARNING: negative index %d in group %s\n\n",
		b->a[j],(*grpname)[i]);
    }
  }
  
  return b;
}
Ejemplo n.º 17
0
void read_resall(char *rrdb, int *nrtpptr, t_restp **rtp, 
                 gpp_atomtype_t atype, t_symtab *tab,
                 gmx_bool bAllowOverrideRTP)
{
  FILE      *in;
  char      filebase[STRLEN],*ptr,line[STRLEN],header[STRLEN];
  int       i,nrtp,maxrtp,bt,nparam;
  int       dum1,dum2,dum3;
  t_restp   *rrtp;
  gmx_bool      bNextResidue,bError;
  int       bts[ebtsNR];
  gmx_bool      bAlldih;
  int       nrexcl;
  gmx_bool      HH14;
  gmx_bool      bRemoveDih;
  int       firstrtp;

  fflib_filename_base(rrdb,filebase,STRLEN);

  in = fflib_open(rrdb);
  
  if (debug) {
    fprintf(debug,"%9s %5s", "Residue", "atoms");
    for(i=0; i<ebtsNR; i++)
      fprintf(debug," %10s",btsNames[i]);
    fprintf(debug,"\n");
  }

  /* these bonded parameters will overwritten be when  *
   * there is a [ bondedtypes ] entry in the .rtp file */
  bts[ebtsBONDS]  = 1; /* normal bonds     */
  bts[ebtsANGLES] = 1; /* normal angles    */
  bts[ebtsPDIHS]  = 1; /* normal dihedrals */
  bts[ebtsIDIHS]  = 2; /* normal impropers */
  bts[ebtsEXCLS]  = 1; /* normal exclusions */
  bts[ebtsCMAP]   = 1; /* normal cmap torsions */

  bAlldih    = FALSE;
  nrexcl     = 3;
  HH14       = TRUE;
  bRemoveDih = TRUE;
  
  /* Column 5 & 6 aren't really bonded types, but we include
   * them here to avoid introducing a new section:
   * Column 5: 1 means generate all dihedrals, 0 not.
   * Column 6: Number of bonded neighbors to exclude.
   * Coulmn 7: Generate 1,4 interactions between pairs of hydrogens
   * Column 8: Remove impropers over the same bond as a proper dihedral
   */
  
  get_a_line(in,line,STRLEN);
  if (!get_header(line,header))
    gmx_fatal(FARGS,"in .rtp file at line:\n%s\n",line);
  if (gmx_strncasecmp("bondedtypes",header,5)==0) {
    get_a_line(in,line,STRLEN);
    if ((nparam=sscanf(line,"%d %d %d %d %d %d %d %d",
		       &bts[ebtsBONDS],&bts[ebtsANGLES],
		       &bts[ebtsPDIHS],&bts[ebtsIDIHS],
		       &dum1,&nrexcl,&dum2,&dum3)) < 4 )
    {
      gmx_fatal(FARGS,"need at least 4 (up to 8) parameters in .rtp file at line:\n%s\n",line);
    }
    bAlldih    = (dum1 != 0);
    HH14       = (dum2 != 0);
    bRemoveDih = (dum3 != 0);
    get_a_line(in,line,STRLEN);
    if(nparam<5) {
      fprintf(stderr,"Using default: not generating all possible dihedrals\n");
      bAlldih = FALSE;
    }
    if(nparam<6) {
      fprintf(stderr,"Using default: excluding 3 bonded neighbors\n");
      nrexcl = 3;
    }
    if(nparam<7) {
      fprintf(stderr,"Using default: generating 1,4 H--H interactions\n");
      HH14 = TRUE;
    }
    if(nparam<8) {
      fprintf(stderr,"Using default: removing impropers on same bond as a proper\n");
      bRemoveDih = TRUE;
    }
  } else {
    fprintf(stderr,
	    "Reading .rtp file without '[ bondedtypes ]' directive,\n"
	    "Will proceed as if the entry\n"
	    "\n"
	    "\n[ bondedtypes ]"
	    "\n; bonds  angles  dihedrals  impropers all_dihedrals nr_exclusions HH14 remove_dih"
	    "\n   %3d     %3d        %3d        %3d           %3d           %3d   %3d    %3d"
	    "\n"
	    "was present at the beginning of %s",
	    bts[0],bts[1],bts[2],bts[3], bAlldih ? 1 : 0,nrexcl,HH14,bRemoveDih,rrdb);
  }
  /* We don't know the current size of rrtp, but simply realloc immediately */
  nrtp = *nrtpptr;
  rrtp = *rtp;
  maxrtp = nrtp;
  while (!feof(in)) {
    if (nrtp >= maxrtp) {
      maxrtp+=100;
      srenew(rrtp,maxrtp);
    }
    clear_t_restp(&rrtp[nrtp]);
    if (!get_header(line,header))
      gmx_fatal(FARGS,"in .rtp file at line:\n%s\n",line);
    rrtp[nrtp].resname  = strdup(header);
    rrtp[nrtp].filebase = strdup(filebase);

    /* Set the bonded types */
    rrtp[nrtp].bAlldih    = bAlldih;
    rrtp[nrtp].nrexcl     = nrexcl;
    rrtp[nrtp].HH14       = HH14;
    rrtp[nrtp].bRemoveDih = bRemoveDih;
    for(i=0; i<ebtsNR; i++) {
      rrtp[nrtp].rb[i].type = bts[i];
    }

    get_a_line(in,line,STRLEN);
    bError=FALSE;
    bNextResidue=FALSE;
    do {
      if (!get_header(line,header)) {
	bError = TRUE;
      } else {
	bt = get_bt(header);
	if (bt != NOTSET) {
	  /* header is an bonded directive */
	  bError = !read_bondeds(bt,in,line,&rrtp[nrtp]);
	} else if (gmx_strncasecmp("atoms",header,5) == 0) {
	  /* header is the atoms directive */
	  bError = !read_atoms(in,line,&(rrtp[nrtp]),tab,atype);
	} else {
	  /* else header must be a residue name */
	  bNextResidue = TRUE;
	}
      }
      if (bError)
	gmx_fatal(FARGS,"in .rtp file in residue %s at line:\n%s\n",
		    rrtp[nrtp].resname,line);
    } while (!feof(in) && !bNextResidue);

    if (rrtp[nrtp].natom == 0)
      gmx_fatal(FARGS,"No atoms found in .rtp file in residue %s\n",
		  rrtp[nrtp].resname);
    if (debug) {
      fprintf(debug,"%3d %5s %5d",
	      nrtp+1,rrtp[nrtp].resname,rrtp[nrtp].natom);
      for(i=0; i<ebtsNR; i++)
	fprintf(debug," %10d",rrtp[nrtp].rb[i].nb);
      fprintf(debug,"\n");
    }
    
    firstrtp = -1;
    for(i=0; i<nrtp; i++) {
        if (gmx_strcasecmp(rrtp[i].resname,rrtp[nrtp].resname) == 0) {
            firstrtp = i;
        }
    }
    
    if (firstrtp == -1) {
        nrtp++;
        fprintf(stderr,"\rResidue %d",nrtp);
    } else {
        if (firstrtp >= *nrtpptr)
        {
            gmx_fatal(FARGS,"Found a second entry for '%s' in '%s'",
                      rrtp[nrtp].resname,rrdb);
        }
        if (bAllowOverrideRTP)
        {
            fprintf(stderr,"\n");
            fprintf(stderr,"Found another rtp entry for '%s' in '%s', ignoring this entry and keeping the one from '%s.rtp'\n",
                    rrtp[nrtp].resname,rrdb,rrtp[firstrtp].filebase);
            /* We should free all the data for this entry.
             * The current code gives a lot of dangling pointers.
             */
            clear_t_restp(&rrtp[nrtp]);
        }
        else
        {
            gmx_fatal(FARGS,"Found rtp entries for '%s' in both '%s' and '%s'. If you want the first definition to override the second one, set the -rtpo option of pdb2gmx.",rrtp[nrtp].resname,rrtp[firstrtp].filebase,rrdb);
        }
    }
  }
  ffclose(in);
  /* give back unused memory */
  srenew(rrtp,nrtp);
  
  fprintf(stderr,"\nSorting it all out...\n");
  qsort(rrtp,nrtp,(size_t)sizeof(rrtp[0]),comprtp);
  
  check_rtp(nrtp,rrtp,rrdb);

  *nrtpptr = nrtp;
  *rtp     = rrtp;
}
Ejemplo n.º 18
0
extern gmx_structurefactors_t *gmx_structurefactors_init(const char *datfn)
{

    /* Read the database for the structure factor of the different atoms */

    FILE                 *fp;
    char                  line[STRLEN];
    gmx_structurefactors *gsf;
    double                a1, a2, a3, a4, b1, b2, b3, b4, c;
    int                   p;
    int                   i;
    int                   nralloc = 10;
    int                   line_no;
    char                  atomn[32];
    fp      = libopen(datfn);
    line_no = 0;
    snew(gsf, 1);

    snew(gsf->atomnm, nralloc);
    snew(gsf->a, nralloc);
    snew(gsf->b, nralloc);
    snew(gsf->c, nralloc);
    snew(gsf->p, nralloc);
    gsf->n       = NULL;
    gsf->nratoms = line_no;
    while (get_a_line(fp, line, STRLEN))
    {
        i = line_no;
        if (sscanf(line, "%s %d %lf %lf %lf %lf %lf %lf %lf %lf %lf",
                   atomn, &p, &a1, &a2, &a3, &a4, &b1, &b2, &b3, &b4, &c) == 11)
        {
            gsf->atomnm[i] = strdup(atomn);
            gsf->p[i]      = p;
            snew(gsf->a[i], 4);
            snew(gsf->b[i], 4);
            gsf->a[i][0] = a1;
            gsf->a[i][1] = a2;
            gsf->a[i][2] = a3;
            gsf->a[i][3] = a4;
            gsf->b[i][0] = b1;
            gsf->b[i][1] = b2;
            gsf->b[i][2] = b3;
            gsf->b[i][3] = b4;
            gsf->c[i]    = c;
            line_no++;
            gsf->nratoms = line_no;
            if (line_no == nralloc)
            {
                nralloc += 10;
                srenew(gsf->atomnm, nralloc);
                srenew(gsf->a, nralloc);
                srenew(gsf->b, nralloc);
                srenew(gsf->c, nralloc);
                srenew(gsf->p, nralloc);
            }
        }
        else
        {
            fprintf(stderr, "WARNING: Error in file %s at line %d ignored\n",
                    datfn, line_no);
        }
    }

    srenew(gsf->atomnm, gsf->nratoms);
    srenew(gsf->a, gsf->nratoms);
    srenew(gsf->b, gsf->nratoms);
    srenew(gsf->c, gsf->nratoms);
    srenew(gsf->p, gsf->nratoms);

    fclose(fp);

    return (gmx_structurefactors_t *) gsf;

}
Ejemplo n.º 19
0
void metareader(int32 sd_id, char *type_of_meta, char *metastring, int32 *count, char *data)
{
#define XMAXLENGTH 1000
int32 i, ii, j, n_attr1, n_sets1, count1, number_type1, n_val;
int start,within,wasjustobject;
int obj_offset[10],n_obj;
char attrib[XMAXLENGTH], attrib1[XMAXLENGTH];
char *charattr;
char line[XMAXLENGTH], objs[XMAXLENGTH];
char lhs[XMAXLENGTH], rhs[XMAXLENGTH];
char uppers[XMAXLENGTH];
void get_a_line(char *text, int lengthoftext, int *start, char line[XMAXLENGTH]);

SDfileinfo(sd_id, &n_sets1, &n_attr1);
for (j=0;j<n_attr1;j++) {
     SDattrinfo(sd_id, j, attrib1, &number_type1, &count1);
     attrib[0] = '\0';  
     for (i=0;i<strlen(attrib1);i++) attrib[i] = toupper(attrib1[i]);  
     attrib[i] = '\0';  
     start = 0;
     if (strstr(attrib,type_of_meta)) {
         if ((charattr = (char *)malloc((count1+1)*sizeof(char))) == NULL) {
	         printf("Out of memory, array 'charattr'\n");
		 return;
	                                                                   }
         SDreadattr(sd_id, j, charattr);
         count1 = strlen(charattr);
         if (!strcmp(type_of_meta, metastring)) {  /* signal for no need to parse metadata */
	    strcpy(data, charattr);
	    return;
	    }


	 n_obj=0;
	 wasjustobject=0;
	 objs[0] = '\0';
	 do { 
	      line[0] = '\0';
	      get_a_line(charattr,count1+1,&start,line);

	      /* Get rid of whitespace, if not inside "..." characters. */
	      within=0;
              for (i=0,ii=0;i<strlen(line);i++) {
	          if (line[i] == '"') {
		     if (!within) within=1;
		     else if (within) within=0;
		     }
	          if (within) line[ii++] = line[i]; 
		  else {
		     if (line[i] != ' ') line[ii++] = line[i];  
		     }
		  }
	      line[ii] = '\0';

	      /* Get left-hand-side, rhs of equation */
	      lhs[0] = rhs[0] = '\0';
	      if (strchr(line,'=')) {
                 for (i=0,ii=0;i<(strchr(line,'=')-line);i++) {
		        lhs[ii++]=line[i];
	             }
	         lhs[ii] = '\0';
		 i++;
                 for (ii=0;i<strlen(line)-1;i++,ii++) {
		        rhs[ii]=line[i];
	             }
	         rhs[ii] = '\0';
		 }
	
	      if (!strcmp(lhs,"OBJECT")) {
	           wasjustobject=1;
	           obj_offset[n_obj++]=strlen(objs);
	           strcat(objs,rhs);
	          }
	      if (!strcmp(lhs,"GROUP")) wasjustobject=0;
	      if ((!strcmp(lhs,"CLASS"))&&(wasjustobject)) {
		   for (i=0;i<strlen(rhs)-1;i++) rhs[i]=rhs[i+1];
	           rhs[i-1] = '\0';
	           strcat(objs,rhs);
	          }
	      if (!strcmp(lhs,"END_OBJECT")) {
	           if (n_obj > 0)
	              objs[obj_offset[--n_obj]] = '\0';
	          }
	      if (!strcmp(lhs,"NUM_VAL")) {
	           n_val=atoi(rhs);
	          }
	      
	      if (!strcmp(lhs,"VALUE")) {
		     /*printf("!%s! %d *%s*%s*\n", objs,n_obj,lhs,rhs);*/
	         if (!strcmp(objs, metastring)) {
	             strcpy(data,rhs);
		     *count=n_val;
		     /*printf("!%s! %d *%s*%s*\n", objs,n_obj,lhs,rhs);*/
	                }
	            }
	      if ((!strcmp(lhs,"\0"))&&(wasjustobject)) {
		     /*printf("!%s! %d *%s*%s*\n", objs,n_obj,lhs,rhs);*/
	         if (!strcmp(objs, metastring)) {
	             strcat(data,line);
		     *count+=n_val;
		     /*printf("!%s! %d *%s*%s*\n", objs,n_obj,lhs,rhs);*/
	                }
	            }
		    
	      /* special case for StructMetadata */
	      if  ( (strstr(type_of_meta, "STRUCTMETADATA")) && ( strstr(lhs, metastring))  ) strcat(data, rhs);
	      	    
	    } while ( line[0] != '\0') ;
	 
	 
	 free(charattr);  
                                      }


                        }  /* for (j=0;j<n_attr1;j++) */

}